Given that typical mail servers don't rotate their keys very often, it's not too cumbersome to hardcode their fingerprints and prevent your mail software from connecting to them should the certificate change. This is similar to how most people use ssh: assume that the certificate is valid on the first connection, but be careful if the certificate changes afterwards.
Fetchmail
Here's how to specify a certificate for a POP/IMAP server (Gmail in this example).First of all, you need to download the server certificate:
openssl s_client -connect pop.gmail.com:995 -showcerts
openssl s_client -connect imap.gmail.com:993 -showcertsThen copy the output of that command to a file, say gmail.out, and extract its md5 fingerprint:
openssl x509 -fingerprint -md5 -noout -in gmail.outOnce you have the fingerprint, add it to your ~/.fetchmailrc:
poll pop.gmail.com protocol pop3 user "remoteusername" is "localusername" password "mypassword" fetchall ssl sslproto ssl3 sslfingerprint "12:34:AB:CD:56:78:EF:12:34:AB:CD:56:78:EF:12:34"Postfix
Similarly, to detect changes to the certificate on your outgoing mail server (used as a smarthost on your local postfix instance), extract its sha1 fingerprint:openssl s_client -connect mail.yourisp.net:465 -showcerts
openssl x509 -fingerprint -sha1 -noout -in isp.outThen add the fingerprint to /etc/postfix/main.cf:
relayhost = mail.isp.net
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = fingerprint
smtp_tls_mandatory_ciphers = high
smtp_tls_mandatory_protocols = !SSLv2, !SSLv3
smtp_tls_fingerprint_digest = sha1
smtp_tls_fingerprint_cert_match =
12:34:AB:CD:56:78:EF:90:12:AB:CD:34:56:EF:78:90:AB:CD:12:34



2 comments:
Thanks for this, it was really helpful.
Just for reference, if you want to check the fingerprint on an SMTP server that uses TLS instead of SSL, then do this:
openssl s_client -connect your.smtp.server:587 -starttls smtp -showcerts
Category worth reading!
Thanks to your article and Paul's comment, I could get the TLS cert from German T-Online ISP:
# openssl s_client -connect securesmtp.t-online.de:587 -starttls smtp -showcerts
- Sedat -
Post a Comment