Skip to content

Instantly share code, notes, and snippets.

@agail
Created October 8, 2021 21:08
Show Gist options
  • Save agail/820f2505038b17acecb5f36e81855a41 to your computer and use it in GitHub Desktop.
Save agail/820f2505038b17acecb5f36e81855a41 to your computer and use it in GitHub Desktop.
Verify SMTP TLS with openssl

Verify SMTP TLS

OpenSSL

openssl s_client -starttls smtp -connect smtp-server:port

If you get dh key too small* append --cipher 'DEFAULT:!DH'

Add -quiet to turn of verbose output

* consider to upgrading your smtp certificate https://www.openssl.org/docs/man1.1.1/man3/SSL_CTX_get_security_level.html

Authentication

Authentication string needs to be base64 encoded

echo -ne "\0userid\0passwd" | base64 which gives AHVzZXJpZABwYXNzd2Q= encoded

Authentication is done by entering AUTH PLAIN AHVzZXJpZABwYXNzd2Q=

One-liner which saves user input to $str

read -rp "uid: " uid; read -rsp "pwd: " pwd; str=$(echo -e "\nEHLO server\nAUTH PLAIN $(echo -ne "\0${uid}\0${pwd}" | base64)\nquit\n"); echo; unset uid pwd

Putting it all together

openssl s_client -starttls smtp -connect smtp-server:port < <( echo -e "${str}" )

depth=2 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert Global Root CA
verify return:1
depth=1 C = US, O = DigiCert Inc, CN = DigiCert SHA2 Secure Server CA
verify return:1
depth=0 C = Country, L = City, O = Company, OU = A, CN = *.localdomain.local
verify return:1
250 STARTTLS
250-smtp.local
250-8BITMIME
250-SIZE 21495808
250-AUTH PLAIN LOGIN
250 AUTH=PLAIN LOGIN
235 #2.0.0 OK Authenticated
221 smtp.local

Final words

Leave a comment if you found it useful ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment