Kryptografie/Mailserver: Unterschied zwischen den Versionen
K Textersetzung - „Verschlüsselung“ durch „Kryptografie“ |
K Textersetzung - „Kategorie:(.*):(.*)“ durch „Kategorie:/$1/$2“ |
||
Zeile 218: | Zeile 218: | ||
# https://bettercrypto.org/ | # https://bettercrypto.org/ | ||
[[Kategorie:Kryptografie | [[Kategorie:/Kryptografie/Best Practice]] | ||
[[Kategorie:E-Mail | [[Kategorie:/E-Mail/Server]] |
Version vom 27. März 2023, 14:55 Uhr
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
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