Transport Layer Security (TLS, formerly called SSL) with Postfix
It provides:
An encrypted session protects the information that is transmitted:
TLS is based on OpenSSL
In order to use TLS, the Postfix SMTP server needs a certificate and a private key.
You can create them with certbot
For instance if you use OVH as your domain provider, you could ask a certificate like that:
certbot certonly \
--dns-ovh \
--dns-ovh-credentials /root/.secrets/certbot/ovh.ini \
--dns-ovh-propagation-seconds 60 \
-n \
--agree-tos \
-m your_email \
-d your.server.name # for instace server01.example.com
The Postfix SMTP server certificate must be usable as SSL server certificate and hence pass the verify test:
# example
cd /etc/letsencrypt/live/<your.server>/
openssl verify -untrusted chain.pem -verbose -purpose sslserver fullchain.pem
fullchain.pem: OK
To know more about this command, see Check a certificate and its intermediate certificate chain.
smtpd_tls_cert_file = /etc/letsencrypt/live/<your.server>/fullchain.pem
smtpd_tls_key_file = /etc/letsencrypt/live/<your.server>/privkey.pem
To verify a remote SMTP client certificate, the Postfix SMTP server needs to trust the certificates of the issuing Certification Authorities.
Optional as the CA authorities are normally already installed.
You can verify that the CA are already installed in the certs directory
ls /etc/ssl/certs/*.crt
/etc/ssl/certs/ca-bundle.crt /etc/ssl/certs/ca-bundle.trust.crt
On Centos the package ca-certificates is responsible to update them
yum info ca-certificates
Installed Packages
Name : ca-certificates
Arch : noarch
Version : 2019.2.32
Release : 76.el7_7
Size : 968 k
Repo : installed
From repo : updates
Summary : The Mozilla CA root certificate bundle
URL : http://www.mozilla.org/
License : Public Domain
Description : This package contains the set of CA certificates chosen by the
: Mozilla Foundation for use with the Internet PKI.
If you want to specify them you can specify them (in PEM Format) via the following configuration:
$OPENSSL_HOME/bin/c_rehash /path/to/directory
The smtpd_tls configuration (receiving side) for all postfix process
smtpd_tls_security_level = may
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
The smtp_tls configurations (sending side)
smtp_tls_security_level = encrypt
smtp_tls_note_starttls_offer = yes
Send an email
echo "Body: This is a test mail. Hallo Charlie" | mail -s "Subject: A big test" [email protected]
Received: from server01.bytle.net (server01.bytle.net. [164.132.99.202])
by mx.google.com with ESMTPS id k12si12202871wrq.512.2020.06.14.08.49.36
for <[email protected]>
(version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
Sun, 14 Jun 2020 08:49:36 -0700 (PDT)
openssl s_client -connect localhost:25 -starttls smtp
Jun 14 18:39:27 vps748761 postfix/smtpd[31959]: Anonymous TLS connection established from localhost[127.0.0.1]: TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)
You may or you may not be able to send an email via an Anonymous TLS connection through a port connection.
The STARTTLS keyword in response to the HELO command advertises that the server supports STARTTLS and that the client can issue a STARTTLS command to secure the connection.
Example:
nc localhost 25
220 server01.bytle.net ESMTP Postfix
EHLO server01.bytle.net
250-server01.bytle.net
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
STARTTLS
220 Go ahead
See postconf.5.html
You cannot use telnet because it does not support TLS