Kryptografie/Mailserver
Mailservers
This section documents the most common mail servers. Mail servers may usually be grouped into three categories:
- Mail Submission Agent (MSA)
- Mail Transfer Agent (MTA) / Mail Exchanger (MX)
- Mail Delivery Agent (MDA)
An email client (mail user agent, MUA) submits mail to the MSA. This is usually been done using the Simple Mail Transfer Protocol (SMTP). Afterwards, the mail is transmitted by the MTA over the Internet to the MTA of the receiver. This happens again via SMTP. Finally, the mail client of the receiver will fetch mail from an MDA usually via the Internet Message Access Protocol (IMAP) or the Post Office Protocol (POP). As MSAs and MTAs both use SMTP as transfer protocols, both functionalities may often be implemented with the same software. On the other hand, MDA software might or might not implement both IMAP and POP.
TLS usage in mail server protocols
Email protocols support TLS in two different ways. It may be added as a protocol wrapper on a different port. This method is referred to as Implicit TLS or as protocol variants SMTPS, IMAPS and POP3S. The other method is to establish a cleartext session first and switch to TLS afterwards by issuing the STARTTLS command. SMTP between MTAs usually makes use of opportunistic TLS. This means that an MTA will accept TLS connections when asked for it but will not require it. MTAs should always try opportunistic TLS handshakes outgoing and always accept incoming opportunistic TLS.
Recommended configuration
We recommend to use the following settings for Mail Transfer Agents:* correctly setup MX, A and PTR RRs without using CNAMEs at all
- the hostname used as HELO/EHLO in outgoing mail shall match the PTR RR
- enable opportunistic TLS, using the STARTTLS mechanism on port 25
- Implicit TLS on port 465 may be offered additionally
- use server and client certificates (most server certificates are client certificates as well)
- either the common name or at least an alternate subject name of the certificate shall match the PTR RR (client mode) or the MX RR (server mode)
- do not use self signed certificates
- accept all cipher suites, as the alternative would be to fall back to cleartext transmission
- an execption to the last sentence is that MTAs MUST NOT enable SSLv2 protocol support, due to the DROWN attack.
For MSA operation we recommend:* listen on submission port 587 with mandatory STARTTLS
- optionally listen on port 465 with Implicit TLS
- enforce SMTP AUTH even for local networks
- ensure that SMTP AUTH is not allowed on unencrypted connections
- only use the recommended cipher suites if all connecting MUAs support them
For MDA operation we recommend:* listen on the protocol port (143 for IMAP, 110 for POP3) with mandatory STARTTLS
- optionally listen on Implicit TLS ports (993 for IMAPS, 995 for POP3S)
- enforce authentication even for local networks
- make sure that authentication is not allowed on unencrypted connections
- use the recommended cipher suites if all connecting MUAs support them
- turn off SSLv2 (see: DROWN attack)
Dovecot
Tested with Versions
Table 4. Tested Dovecot Versions
Program Version | OS/Distribution/Version | Comment |
---|---|---|
2.1.7 | Debian Wheezy | without ssl_prefer_server_ciphers |
2.2.9 | Debian Jessie | |
2.2.13 | Debian 8.2 Jessie | |
2.0.19apple1 | OS X Server 10.8.5 | without ssl_prefer_server_ciphers |
2.2.9 | Ubuntu 14.04 Trusty | |
2.2.31 | Ubuntu 16.04.3 LTS |
Settings
- Dovecot SSL Configuration
# SSL protocols to use, disable SSL, use TLS only ssl_protocols = !SSLv3 !SSLv2 # SSL ciphers to use ssl_cipher_list = EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA256:EECDH:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!DSS:!RC4:!SEED:!IDEA:!ECDSA:kEDH:CAMELLIA128-SHA:AES128-SHA # Prefer the server's order of ciphers over client's. (Dovecot >=2.2.6 Required) ssl_prefer_server_ciphers = yes # Diffie-Hellman parameters length (Default is 1024, Dovecot >=2.2.7 Required) # ToDo: for ReGenerating DH-Parameters: # manually delete /var/lib/dovecot/ssl-parameters.dat and restart # Dovecot to regenerate /var/lib/dovecot/ssl-parameters.dat ssl_dh_parameters_length = 2048 # Disable Compression (Dovecot >= 2.2.14 Required) # ssl_options = no_compression
Dovecot 2.0, 2.1: Almost as good as dovecot 2.2. Dovecot does not ignore unknown configuration parameters. Does not support ssl_prefer_server_ciphers. |
Limitations
Dovecot <2.2.14 does not support disabling TLS compression.
- In >2.2.14 [6] use: ssl_options = no_compression
Dovecot <2.2.7 uses fixed DH parameters.
- In >2.2.7 [7] greater DH-Parameters are supported: ssl_dh_parameters_length = 2048.
References
How to test
$ openssl s_client -crlf -connect example.com:993 $ openssl s_client -crlf -connect example.com:995 $ openssl s_client -crlf -starttls imap -connect example.com:143 $ openssl s_client -crlf -starttls pop3 -connect example.com:110
SSLyze offers scanning for common vulnerabilities and displays Protocols and Cipher-Suites.
$ sslyze.exe --regular example.com:993 $ sslyze.exe --regular example.com:995 $ sslyze.exe --regular --starttls=imap example.com:143 $ sslyze.exe --regular --starttls=pop3 example.com:110
cyrus-imapd
Tested with Versions
Tested cyrus-imapd Versions
Program Version | OS/Distribution/Version | Comment |
---|---|---|
2.4.17 |
Settings
To activate SSL/TLS configure your certificate with
- Activating TLS in cyrus
tls_cert_file: /etc/ssl/certs/ssl-cert-snakeoil.pem tls_key_file: /etc/ssl/private/ssl-cert-snakeoil.key
- Do not forget to add necessary intermediate certificates to the .pem file.
- Limiting the ciphers provided may force (especially older) clients to connect without encryption at all! Sticking to the defaults is recommended.
If you still want to force strong encryption use
- TLS cipher selection in cyrus
tls_cipher_list: EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA256:EECDH:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!DSS:!RC4:!SEED:!IDEA:!ECDSA:kEDH:CAMELLIA128-SHA:AES128-SHA
- cyrus-imapd loads hardcoded 1024 bit DH parameters using get_rfc2409_prime_1024() by default.
- If you want to load your own DH parameters add them PEM encoded to the certificate file given in tls_cert_file.
- Do not forget to re-add them after updating your certificate.
- To prevent unencrypted connections on the STARTTLS ports you can set
- Force encrypted connections in cyrus
allowplaintext: no
- This way MUAs can only authenticate with plain text authentication schemes after issuing the STARTTLS command.
- Providing CRAM-MD5 or DIGEST-MD5 methods is not recommended.
To support POP3/IMAP on ports 110/143 with STARTTLS and POP3S/IMAPS on ports 995/993 check the SERVICES section in cyrus.conf
- STARTTLS for POP3/IMAP and POP3S/IMAPS in cyrus
SERVICES { imap cmd="imapd -U 30" listen="imap" prefork=0 maxchild=100 imaps cmd="imapd -s -U 30" listen="imaps" prefork=0 maxchild=100 pop3 cmd="pop3d -U 30" listen="pop3" prefork=0 maxchild=50 pop3s cmd="pop3d -s -U 30" listen="pop3s" prefork=0 maxchild=50 }
Limitations
cyrus-imapd currently (2.4.17, trunk) does not support elliptic curve cryptography.
- Hence, ECDHE will not work even if defined in your cipher list.
Currently there is no way to prefer server ciphers or to disable compression.
- There is a working patch for all three features.
How to test
$ openssl s_client -crlf -connect example.com:993
Postfix
Tested with Versions
Tested Postfix Versions
Program Version | OS/Distribution/Version | Comment |
---|---|---|
2.9.6 | Debian Wheezy | with OpenSSL 1.0.1e |
2.11.0 | Ubuntu 14.04.02 | with OpenSSL 1.0.1f |
3.1.0 | Ubuntu 16.04.3 LTS |
Settings
Postfix has five internal lists of ciphers, and the possibility to switch between those with smtpd_tls_ciphers. However, we leave this at its default value for server to server connections, as many mail servers only support outdated protocols and ciphers. We consider bad encryption still better than plain text transmission. For connections to MUAs, TLS is mandatory and the ciphersuite is modified.
MX and SMTP client configuration:
As discussed in section [smtp_general], because of opportunistic encryption we do not restrict the list of ciphers or protocols for communication with other mail servers to avoid transmission in plain text. There are still some steps needed to enable TLS, all in main.cf:
- Opportunistic TLS in Postfix
# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
# log TLS connection info
smtpd_tls_loglevel = 1 smtp_tls_loglevel = 1
# enable opportunistic TLS support in the SMTP server and client
smtpd_tls_security_level = may smtp_tls_security_level = may
# if you have authentication enabled, only offer it after STARTTLS
smtpd_tls_auth_only = yes tls_ssl_options = NO_COMPRESSION
MSA:
For the MSA smtpd process which communicates with mail clients, we first define the ciphers that are acceptable for the “mandatory” security level, again in main.cf:
- MSA TLS configuration in Postfix
smtp_tls_mandatory_protocols = !SSLv2, !SSLv3 smtp_tls_protocols = !SSLv2, !SSLv3 lmtp_tls_mandatory_protocols = !SSLv2, !SSLv3 lmtp_tls_protocols = !SSLv2, !SSLv3 smtpd_tls_mandatory_protocols = !SSLv2, !SSLv3 smtpd_tls_protocols = !SSLv2, !SSLv3 smtpd_tls_mandatory_ciphers=high tls_high_cipherlist=EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA256:EECDH:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!DSS:!RC4:!SEED:!IDEA:!ECDSA:kEDH:CAMELLIA128-SHA:AES128-SHA
Then, we configure the MSA smtpd in master.cf with two additional options that are only used for this instance of smtpd:
- MSA smtpd service configuration in Postfix
# ========================================================================== # service type private unpriv chroot wakeup maxproc command + args # (yes) (yes) (no) (never) (100) # ========================================================================== # ... submission inet n - - - - smtpd -o smtpd_tls_security_level=encrypt -o tls_preempt_cipherlist=yes # ...
For those users who want to use EECDH key exchange, it is possible to customize this via: The default value since Postfix 2.8 is “strong”.
- EECDH customization in Postfix
smtpd_tls_eecdh_grade = ultra
Limitations
tls_ssl_options is supported from Postfix 2.11 onwards. You can leave the statement in the configuration for older versions, it will be ignored. tls_preempt_cipherlist is supported from Postfix 2.8 onwards. Again, you can leave the statement in for older versions.
References
- Refer to https://www.postfix.org/TLS_README.html for an in-depth discussion.
Additional settings
Postfix has two sets of built-in DH parameters that can be overridden with the smtpd_tls_dh512_param_file and smtpd_tls_dh1024_param_file options. The “dh512” parameters are used for export ciphers, while the “dh1024” ones are used for all other ciphers. The “bit length” in those parameter names is just a name, so one could use stronger parameter sets; it should be possible to e.g. use the IKE Group14 parameters (see section [DH] without much interoperability risk, but we have not tested this yet.
How to test
You can check the effect of the settings with the following command: $ zegrep "TLS connection established from.*with cipher" /var/log/mail.log | awk '{printf("%s %s %s %s\n", $12, $13, $14, $15)}' | sort | uniq -c | sort -n
1 SSLv3 with cipher DHE-RSA-AES256-SHA 23 TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 60 TLSv1 with cipher ECDHE-RSA-AES256-SHA 270 TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 335 TLSv1 with cipher DHE-RSA-AES256-SHA
$ openssl s_client -starttls smtp -crlf -connect example.com:25
Exim
Tested with Versions
Table 7. Tested Exim Versions
Program Version | OS/Distribution/Version | Comment |
---|---|---|
4.82 | Debian Jessie | |
4.82 | Ubuntu 14.04.2 | with OpenSSL 1.0.1e |
It is highly recommended to read Encrypted SMTP connections using TLS/SSL first.
MSA mode (submission):
In the main config section of Exim add:
- Certificate selection in Exim (MSA)
tls_certificate = /etc/ssl/exim.crt tls_privatekey = /etc/ssl/exim.pem Don’t forget to add intermediate certificates to the .pem file if needed. Tell Exim to advertise STARTTLS in the EHLO answer to everyone:
- TLS advertise in Exim (MSA)
tls_advertise_hosts = * If you want to support legacy SMTPS on port 465, and STARTTLS on smtp(25)/submission(587) ports set
- STARTTLS and SMTPS in Exim (MSA)
daemon_smtp_ports = smtp : smtps : submission tls_on_connect_ports = 465 It is highly recommended to limit SMTP AUTH to SSL connections only. To do so add
- SSL-only authentication in Exim (MSA)
server_advertise_condition = ${if eq{$tls_cipher}{}{no}{yes}} to every authenticator defined. Add the following rules on top of your acl_smtp_mail:
- Submission mode in Exim (MSA)
acl_smtp_mail = acl_check_mail acl_check_mail:
warn hosts = * control = submission/sender_retain accept
This switches Exim to submission mode and allows addition of missing “Message-ID” and “Date” headers. It is not advisable to restrict the default cipher list for MSA mode if you don’t know all connecting MUAs. If you still want to define one please consult the Exim documentation or ask on the exim-users mailinglist. The cipher used is written to the logfiles by default. You may want to add log_selector = <whatever your log_selector already contains> +tls_certificate_verified +tls_peerdn +tls_sni to get even more TLS information logged.
Server mode (incoming):
In the main config section of Exim add:
- Certificate selection in Exim (Server)
tls_certificate = /etc/ssl/exim.crt tls_privatekey = /etc/ssl/exim.pem Don’t forget to add intermediate certificates to the .pem file if needed. Tell Exim to advertise STARTTLS in the EHLO answer to everyone:
- TLS advertise in Exim (Server)
tls_advertise_hosts = * Listen on smtp(25) port only:
- STARTTLS on SMTP in Exim (Server)
daemon_smtp_ports = smtp It is not advisable to restrict the default cipher list for opportunistic encryption as used by SMTP. Do not use cipher lists recommended for HTTPS! If you still want to define one please consult the Exim documentation or ask on the exim-users mailinglist. If you want to request and verify client certificates from sending hosts set
- TLS certificate verification in Exim (Server)
tls_verify_certificates = /etc/pki/tls/certs/ca-bundle.crt tls_try_verify_hosts = * tls_try_verify_hosts only reports the result to your logfile. If you want to disconnect such clients you have to use tls_verify_hosts = * The cipher used is written to the logfiles by default. You may want to add log_selector = <whatever your log_selector already contains> +tls_certificate_verified +tls_peerdn +tls_sni to get even more TLS information logged.
Client mode (outgoing):
Exim uses opportunistic encryption in the SMTP transport by default. Client mode settings have to be done in the configuration section of the smtp transport (driver = smtp). If you want to use a client certificate (most server certificates can be used as client certificate, too) set
- Certificate selection in Exim (Client)
tls_certificate = /etc/ssl/exim.crt tls_privatekey = /etc/ssl/exim.pem This is recommended for MTA-MTA traffic. Do not limit ciphers without a very good reason. In the worst case you end up without encryption at all instead of some weak encryption. Please consult the Exim documentation if you really need to define ciphers.
OpenSSL:
Exim already disables SSLv2 by default. We recommend to add openssl_options = +all +no_sslv2 +no_sslv3 +no_compression +cipher_server_preference to the main configuration.
+all is misleading here since OpenSSL only activates the most common workarounds. But that’s how SSL_OP_ALL is defined. |
You do not need to set dh_parameters. Exim with OpenSSL by default uses parameter initialization with the “2048-bit MODP Group with 224-bit Prime Order Subgroup” defined in section 2.2 of RFC 5114 (ike23). If you want to set your own DH parameters please read the TLS documentation of exim.
GnuTLS:
GnuTLS is different in only some respects to OpenSSL:* tls_require_ciphers needs a GnuTLS priority string instead of a cipher list. It is recommended to use the defaults by not defining this option. It highly depends on the version of GnuTLS used. Therefore it is not advisable to change the defaults.
- There is no option like openssl_options
Exim string expansion
Most of the options accept expansion strings. This way you can e.g. set cipher lists or STARTTLS advertisement conditionally. Please follow the link to the official Exim documentation to get more information. |
Limitations:
Exim currently (4.82) does not support elliptic curves with OpenSSL. This means that ECDHE is not used even if defined in your cipher list. There already is a working patch to provide support.
How to test
$ openssl s_client -starttls smtp -crlf -connect example.com:25
Cisco ESA/IronPort
Tested with Versions
Table 8. Tested Cisco ESA/IronPort Versions
Program Version | OS/Distribution/Version | Comment |
---|---|---|
AsyncOS 7.6.1 | ||
AsyncOS 8.5.6 | ||
AsyncOS 9.0.0 | ||
AsyncOS 9.5.0 | ||
AsyncOS 9.6.0 | ||
AsyncOS 9.7.0 |
Settings
Import your certificate(s) using the WEBUI (Network → Certificates). From AsyncOS 9.0 and up, SSL parameters for inbound SMTP, outbound SMTP and GUI access can be configured in one step via the WEBUI (System Administration → SSL Configuration, see figure IronPort Default SSL Settings). For all versions prior to 9.0, you have to connect to the CLI and configure the SSL parameters separately, as shown below using inbound SMTP as example. ironport.example.com> sslconfig sslconfig settings:
GUI HTTPS method: sslv3tlsv1 GUI HTTPS ciphers: RC4-SHA:RC4-MD5:ALL Inbound SMTP method: sslv3tlsv1 Inbound SMTP ciphers: RC4-SHA:RC4-MD5:ALL Outbound SMTP method: sslv3tlsv1 Outbound SMTP ciphers: RC4-SHA:RC4-MD5:ALL
Choose the operation you want to perform: - GUI - Edit GUI HTTPS ssl settings. - INBOUND - Edit Inbound SMTP ssl settings. - OUTBOUND - Edit Outbound SMTP ssl settings. - VERIFY - Verify and show ssl cipher list. []> inbound Enter the inbound SMTP ssl method you want to use. 1. SSL v2. 2. SSL v3 3. TLS v1 4. SSL v2 and v3 5. SSL v3 and TLS v1 6. SSL v2, v3 and TLS v1 [5]> 3 Enter the inbound SMTP ssl cipher you want to use. [RC4-SHA:RC4-MD5:ALL]> EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA256:EECDH:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!DSS:!RC4:!SEED:!IDEA:!ECDSA:kEDH:CAMELLIA128-SHA:AES128-SHA sslconfig settings:
GUI HTTPS method: sslv3tlsv1 GUI HTTPS ciphers: RC4-SHA:RC4-MD5:ALL Inbound SMTP method: tlsv1 Inbound SMTP ciphers: EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH:+CAMELLIA256:+AES256:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS:!RC4:!SEED:!ECDSA:CAMELLIA256-SHA:AES256-SHA:CAMELLIA128-SHA:AES128-SHA Outbound SMTP method: sslv3tlsv1 Outbound SMTP ciphers: RC4-SHA:RC4-MD5:ALL
Starting with AsyncOS 9.0 SSLv3 is disabled by default, whereas the default cipher set is still RC4-SHA:RC4-MD5:ALL (see figure IronPort Default SSL Settings). |
"IronPort Default SSL Settings" Figure 1. IronPort Default SSL Settings After committing these changes in the CLI, you have to activate the use of TLS in several locations. For inbound connections, first select the appropriate certificate in the settings of each listener you want to have TLS enabled on (Network → Listeners, see figure IronPort Default SSL Settings). Afterwards, for each listener, configure all Mail Flow Policies which have their Connection Behavior set to “Accept” or “Relay” to at least prefer TLS (Mail Policies → Mail Flow Policies, see figure IronPort Default SSL Settings). It is recommended to also enable TLS in the default Mail Flow Policy, because these settings will be inherited by newly created policies, unless specifically overwritten. + TLS can be enforced by creating a new Mail Flow Policy with TLS set to “required”, creating a new Sender Group defining the addresses of the sending mail servers for which you want to enforce encryption (Mail Policies → HAT Overview) and using this new Sender Group in conjunction with the newly created Mail Flow Policy. "IronPort Listener Settings" Figure 2. IronPort Listener Settings "IronPort Mail Flow Policy Security Features" Figure 3. IronPort Mail Flow Policy Security Features TLS settings for outbound connections have to be configured within the Destination Controls (Mail Policies → Destination Controls). Choose the appropriate SSL certificate within the global settings and configure TLS to be preferred in the default profile to enable it for all outbound connections. After these two steps the Destination Control overview page should look like figure IronPort Destination Control overview on page . To enforce TLS for a specific destination domain, add an entry to the Destination Control Table and set “TLS Support” to “required”. "Destination Control overview" Figure 4. IronPort Destination Control overview
Limitations
All AsyncOS releases prior to version 9.5 use OpenSSL 0.9.8. Therefore TLS 1.2 is not supported in these versions and some of the suggested ciphers won’t work. Starting with AsyncOS 9.5 TLS 1.2 is fully supported. [8] You can check the supported ciphers on the CLI by using the option verify from within the sslconfig command: []> verify Enter the ssl cipher you want to verify. []> EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA256:EECDH:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!DSS:!RC4:!SEED:!IDEA:!ECDSA:kEDH:CAMELLIA128-SHA:AES128-SHA DHE-RSA-CAMELLIA256-SHA SSLv3 Kx=DH Au=RSA Enc=Camellia(256) Mac=SHA1 DHE-RSA-CAMELLIA128-SHA SSLv3 Kx=DH Au=RSA Enc=Camellia(128) Mac=SHA1 DHE-RSA-AES256-SHA SSLv3 Kx=DH Au=RSA Enc=AES(256) Mac=SHA1 DHE-RSA-AES128-SHA SSLv3 Kx=DH Au=RSA Enc=AES(128) Mac=SHA1 CAMELLIA128-SHA SSLv3 Kx=RSA Au=RSA Enc=Camellia(128) Mac=SHA1 AES128-SHA SSLv3 Kx=RSA Au=RSA Enc=AES(128) Mac=SHA1
How to test
$ openssl s_client -starttls smtp -crlf -connect example.com:25