brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: openssl s_client -starttls smtp checks the certificate of a mail server

Openssl
~/tips/tip-security-openssl-s-client-starttls-smtp

openssl s_client -starttls smtp -connect mail.example.com:587 -servername mail.example.com -brief

Opens a STARTTLS session to a mail server and shows the certificate and TLS details.

Mail servers often start in plain text and switch to TLS afterwards, so a plain TLS check against port 587 just hangs. OpenSSL knows the handshake.

The -starttls option of openssl s_client sends the protocol-specific messages needed to switch to TLS. The documented protocols are smtp, pop3, imap, ftp, xmpp, xmpp-server, irc, postgres, mysql, lmtp, nntp, sieve and ldap.

openssl s_client -starttls smtp -connect mail.example.com:587 -servername mail.example.com -brief

-connect gives host and port. -servername sets the SNI name, and when you leave it out, it is taken from the -connect host if that looks like a DNS name. -brief prints a short summary of the connection parameters instead of the full output.

Other protocols work the same way:

openssl s_client -starttls imap -connect mail.example.com:143 -brief

After the summary, the command waits for input. Type Q to end the connection, or press Ctrl-D, because end of input closes it too. To read only the certificate dates, close stdin with </dev/null and pass the output to openssl x509:

openssl s_client -starttls smtp -connect mail.example.com:587 </dev/null 2>/dev/null | openssl x509 -noout -dates

Port 465 usually starts TLS right away, so leave -starttls out there. Some home networks also block outgoing port 25, so for a quick test from home, 587 or 143 is more likely to answer.

Further reading: openssl-s_client

More Openssl tips openssl s_client -connect 203.0.113.10:443 -servername example.com </dev/null | openssl x509 -noout -subject openssl x509 -in cert.pem -days 365 -signkey key.pem -out cert-new.pem printf %s hello | openssl dgst -sha256 -hmac secret openssl pkcs12 -legacy -in old.pfx -nokeys echo 'aGVsbG8gd29ybGQ=' | openssl base64 -d All Openssl tips (34) All topics

Link