1 %%\subsection{Mail Servers}
3 This section documents the most common mail (SMTP) and IMAPs/POPs servers. Another option to secure IMAPs/POPs servers is to place them behind an stunnel server.
5 \subsubsection{Dovecot}
10 % Example: http://dovecot.org/list/dovecot/2013-October/092999.html
12 \begin{lstlisting}[breaklines]
13 ssl_cipher_list = 'EECDH+aRSA+AESGCM:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EDH+CAMELLIA256:EECDH:EDH+aRSA:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS:!RC4:!SEED:!AES128:!CAMELLIA128:!ECDSA:AES256-SHA'
14 ssl_prefer_server_ciphers = yes
17 Dovecot 2.1: Almost as good as dovecot 2.2. Does not support ssl\_prefer\_server\_ciphers
19 \paragraph*{Limitations}\mbox{}\\
21 Dovecot currently does not support disabling TLS compression. Furthermore, DH parameters
22 greater than 1024bit are not supported. The most recent version 2.2.7 of Dovecot implements
23 configurable DH parameter length
24 \footnote{\url{http://hg.dovecot.org/dovecot-2.2/rev/43ab5abeb8f0}}.
26 \subsubsection{cyrus-imapd (based on 2.4.17)}
28 \paragraph*{imapd.conf}\mbox{}\\
30 To activate SSL/TLS configure your certificate with
31 \begin{lstlisting}[breaklines]
32 tls_cert_file: .../cert.pem
33 tls_key_file: .../cert.key
36 Do not forget to add necessary intermediate certificates to the .pem file.\\
38 Limiting the ciphers provided may force (especially older) clients to connect without encryption at all! Sticking to the defaults is recommended.\\
40 If you still want to force strong encryption use
41 \begin{lstlisting}[breaklines]
42 tls_cipher_list: <...recommended ciphersuite...>
45 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.\\
47 To prevent unencrypted connections on the STARTTLS ports you can set
48 \begin{lstlisting}[breaklines]
51 This way MUAs can only authenticate after STARTTLS if you only provide plaintext and SASL PLAIN login methods. Therefore providing CRAM-MD5 or DIGEST-MD5 methods is not recommended.\\
53 \paragraph*{cyrus.conf}\mbox{}\\
55 To support POP3/IMAP on ports 110/143 with STARTTLS add
56 \begin{lstlisting}[breaklines]
57 imap cmd="imapd" listen="imap" prefork=3
58 pop3 cmd="pop3d" listen="pop3" prefork=1
60 to the SERVICES section.\\
62 To support POP3S/IMAPS on ports 995/993 add
63 \begin{lstlisting}[breaklines]
64 imaps cmd="imapd -s" listen="imaps" prefork=3
65 pop3s cmd="pop3d -s" listen="pop3s" prefork=1
69 \paragraph*{Limitations}\mbox{}\\
71 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.\\
73 Currently there is no way to prefer server ciphers or to disable compression.\\
75 There is a working patch for all three features:
76 \url{https://bugzilla.cyrusimap.org/show_bug.cgi?id=3823}\\
84 % ciphers = EDH+CAMELLIA256:EDH+aRSA:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS:!RC4:!SEED:-AES128:!CAMELLIA128:!ECDSA:AES256-SHA:EDH+AES128;
85 % options = CIPHER_SERVER_PREFERENCE
88 \subsubsection{SMTP in general}
90 SMTP usually makes use of opportunistic TLS. This means that an MTA will accept TLS connections when asked for it during handshake but will not require it. One should always support incoming opportunistic TLS and always try TLS handshake outgoing.\\
92 Furthermore a mailserver can operate in three modes:
94 \item As MSA (Mail Submission Agent) your mailserver receives mail from your clients MUAs (Mail User Agent).
95 \item As receiving MTA (Mail Transmission Agent, MX)
96 \item As sending MTA (SMTP client)
99 We recommend the following basic setup for all modes:
101 \item correctly setup MX, A and PTR RRs without using CNAMEs at all.
102 \item enable encryption (opportunistic TLS)
103 \item do not use self signed certificates
106 For SMTP client mode we additionally recommend:
108 \item the hostname used as HELO must match the PTR RR
109 \item setup a client certificate (most server certificates are client certificates as well)
110 \item either the common name or at least an alternate subject name of your certificate must match the PTR RR
111 \item do not modify the cipher suite for client mode
114 For MSA operation we recommend:
116 \item listen on submission port 587
117 \item enforce SMTP AUTH even for local networks
118 \item do not allow SMTP AUTH on unencrypted connections
119 \item optionally use the recommended cipher suites if (and only if) all your connecting MUAs support them
124 % Note that (with the exception of MSA mode), it might be better to allow any cipher suite -- since any encryption is better than no encryption when it comes to opportunistic TLS.
126 We strongly recommend to allow all cipher suites for anything but MSA
127 mode, because the alternative is plain text transmission.
129 \subsubsection{Postfix}
132 \item[Tested with Version:] \mbox{}
135 \item Postfix 2.9.6 (Debian Wheezy)
138 \item[Settings:] \mbox{}
140 First, you need to generate Diffie Hellman parameters (please first take a look at the section \ref{section:RNGs}):
142 \todo{FIXME: this is a really weak setting! See also: http://postfix.1071664.n5.nabble.com/postfix-hardening-what-can-we-do-td61874.html}
143 \begin{lstlisting}[breaklines]
144 % openssl gendh -out /etc/postfix/dh_param_512.pem -2 512
145 % openssl gendh -out /etc/postfix/dh_param_1024.pem -2 1024
148 Next, we specify these DH parameters in \verb|main.cf|:
150 \begin{lstlisting}[breaklines]
151 smtpd_tls_dh512_param_file = /etc/postfix/dh_param_512.pem
152 smtpd_tls_dh1024_param_file = /etc/postfix/dh_param_1024.pem
155 \paragraph*{MX and SMTP client configuration}\mbox{}\\
157 As discussed above, because of opportunistic encryption we do not
158 restrict the list of ciphers. There are still some steps needed to
159 enable TLS, all in \verb|main.cf|:
161 \begin{lstlisting}[breaklines]
162 smtpd_tls_cert_file = /etc/postfix/server.pem
163 smtpd_tls_key_file = /etc/postfix/server.key
164 # use 0 for Postfix >= 2.9, and 1 for earlier versions
165 smtpd_tls_loglevel = 0
166 # enable opportunistic TLS support in the SMTP server and client
167 smtpd_tls_security_level = may
168 smtp_tls_security_level = may
169 # if you have authentication enabled, only offer it after STARTTLS
170 smtpd_tls_auth_only = yes
171 tls_ssl_options=NO_COMPRESSION
172 tls_random_source = dev:/dev/urandom
175 \paragraph*{MSA}\mbox{}\\
177 For the MSA \verb|smtpd| process, we first define the ciphers that are
178 acceptable for the ``mandatory'' security level, again in
181 \begin{lstlisting}[breaklines]
182 smtpd_tls_mandatory_protocols = !SSLv2, !SSLv3
183 smtpd_tls_mandatory_ciphers=high
184 tls_high_cipherlist=EECDH+aRSA+AESGCM:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EDH+CAMELLIA256:EECDH:EDH+aRSA:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS:!RC4:!SEED:!AES128:!CAMELLIA128:!ECDSA:AES256-SHA
187 Then, we configure the MSA smtpd in \verb|master.cf| with two
188 additional options that are only used for this instance of smtpd:
190 \begin{lstlisting}[breaklines]
191 587 inet n - - - - smtpd
192 -o smtpd_tls_security_level=encrypt -o tls_preempt_cipherlist = yes
195 For those users who want to use ECC key exchange, it is possible to specify this via:
196 \begin{lstlisting}[breaklines]
197 smtpd_tls_eecdh_grade = ultra
200 \item[Limitations:] \mbox{}
202 tls\_ssl\_options is supported from Postfix 2.11 onwards. You can
203 leave the statement in the configuration for older versions, it will
206 tls\_preempt\_cipherlist is supported from Postfix 2.8 onwards. Again,
207 you can leave the statement in for older versions.
211 Refer to \url{http://www.postfix.org/TLS_README.html} for an in-depth
214 % \item[Additional settings:]
215 % no additional settings
217 % \item[Justification for special settings (if needed):]
218 % no special settings
222 You can check the effect of the settings with the following command:
223 \begin{lstlisting}[breaklines]
224 $ 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
225 1 SSLv3 with cipher DHE-RSA-AES256-SHA
226 23 TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384
227 60 TLSv1 with cipher ECDHE-RSA-AES256-SHA
228 270 TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384
229 335 TLSv1 with cipher DHE-RSA-AES256-SHA
234 \subsubsection{Exim (based on 4.82)}
236 It is highly recommended to read
238 \url{http://exim.org/exim-html-current/doc/html/spec_html/ch-encrypted_smtp_connections_using_tlsssl.html}
242 \paragraph*{MSA mode (submission)}\mbox{}\\
244 In the main config section of Exim add:
246 \begin{lstlisting}[breaklines]
247 tls_certificate = ..../cert.pem
248 tls_privatekey = ..../cert.key
250 don't forget to add intermediate certificates to the .pem file if needed.\\
252 Tell Exim to advertise STARTTLS in the EHLO answer to everyone:
253 \begin{lstlisting}[breaklines]
254 tls_advertise_hosts = *
257 If you want to support legacy SMTPS on port 465, and STARTTLS on smtp(25)/submission(587) ports set
258 \begin{lstlisting}[breaklines]
259 daemon_smtp_ports = smtp : smtps : submission
260 tls_on_connect_ports = 465
263 It is highly recommended to limit SMTP AUTH to SSL connections only. To do so add
264 \begin{lstlisting}[breaklines]
265 server_advertise_condition = ${if eq{$tls_cipher}{}{no}{yes}}
267 to every authenticator defined.\\
269 Add the following rules on top of your acl\_smtp\_mail:
270 \begin{lstlisting}[breaklines]
272 control = submission/sender_retain
274 This switches Exim to submission mode and allows addition of missing ``Message-ID'' and ``Date'' headers.\\
276 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.\\
277 % Exim maintainers do not recommend to change default ciphers
278 % I think we shouldn't, too
280 %\begin{lstlisting}[breaklines]
281 % tls_require_ciphers = <...recommended ciphersuite...>
284 The cipher used is written to the logfiles by default. You may want to add
285 \begin{lstlisting}[breaklines]
286 log_selector = <....whatever your log_selector already contains...> \
287 +tls_certificate_verified +tls_peerdn +tls_sni
289 to get even more TLS information logged.
292 \paragraph*{server mode (incoming)}\mbox{}\\
294 In the main config section of Exim add:
296 \begin{lstlisting}[breaklines]
297 tls_certificate = ..../cert.pem
298 tls_privatekey = ..../cert.key
300 don't forget to add intermediate certificates to the .pem file if needed.\\
302 Tell Exim to advertise STARTTLS in the EHLO answer to everyone:
303 \begin{lstlisting}[breaklines]
304 tls_advertise_hosts = *
307 Listen on smtp(25) port only
308 \begin{lstlisting}[breaklines]
309 daemon_smtp_ports = smtp
312 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.\\
313 % Exim maintainers do not recommend to change default ciphers
316 %\begin{lstlisting}[breaklines]
317 % tls_require_ciphers = <...recommended ciphersuite...>
320 If you want to request and verify client certificates from sending hosts set
321 \begin{lstlisting}[breaklines]
322 tls_verify_certificates = /etc/pki/tls/certs/ca-bundle.crt
323 tls_try_verify_hosts = *
326 tls\_try\_verify\_hosts only reports the result to your logfile. If you want to disconnect such clients you have to use
327 \begin{lstlisting}[breaklines]
331 The cipher used is written to the logfiles by default. You may want to add
332 \begin{lstlisting}[breaklines]
333 log_selector = <....whatever your log_selector already contains...> \
334 +tls_certificate_verified +tls_peerdn +tls_sni
336 to get even more TLS information logged.
338 \paragraph*{client mode (outgoing)}\mbox{}\\
340 Exim uses opportunistic encryption in the SMTP transport by default.
342 Client mode settings have to be done in the configuration section of the smtp transport (driver = smtp).
344 If you want to use a client certificate (most server certificates can be used as client certificate, too) set
345 \begin{lstlisting}[breaklines]
346 tls_certificate = .../cert.pem
347 tls_privatekey = .../cert.key
349 This is recommended for MTA-MTA traffic.\\
351 %If you want to limit used ciphers set
352 %\begin{lstlisting}[breaklines]
353 % tls_require_ciphers = <...recommended ciphersuite...>
355 % Exim Maintainers do not recommend ciphers. We shouldn't do so, too.
356 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.
358 \paragraph*{OpenSSL}\mbox{}\\
359 Exim already disables SSLv2 by default. We recommend to add
360 \begin{lstlisting}[breaklines]
361 openssl_options = +all +no_sslv2 +no_compression +cipher_server_preference
363 to the main configuration.\\
364 Note: +all is misleading here since OpenSSL only activates the most common workarounds. But that's how SSL\_OP\_ALL is defined.\\
366 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).
367 If you want to set your own DH parameters please read the TLS documentation of exim.\\
371 \paragraph*{GnuTLS}\mbox{}\\
373 GnuTLS is different in only some respects to OpenSSL:
375 \item 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.
376 \item There is no option like openssl\_options
379 \paragraph*{Exim string expansion}\mbox{}\\
381 Note that most of the options accept expansion strings. This way you can eg. set cipher lists or STARTTLS advertisment conditionally. Please follow the link to the official Exim documentation to get more information.
383 \paragraph*{Limitations}\mbox{}\\
385 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.
386 There already is a working patch to provide support:\\
387 \url{http://bugs.exim.org/show_bug.cgi?id=1397}
390 % do we need to documment starttls in detail?
391 %\subsubsection{starttls?}