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.
6 %% ----------------------------------------------------------------------
8 \subsection{SMTP in general}
9 \label{subsection:smtp_general}
11 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.\\
13 Furthermore a mailserver can operate in three modes:
15 \item As MSA (Mail Submission Agent) your mailserver receives mail from your clients MUAs (Mail User Agent).
16 \item As receiving MTA (Mail Transmission Agent, MX)
17 \item As sending MTA (SMTP client)
20 We recommend the following basic setup for all modes:
22 \item correctly setup MX, A and PTR RRs without using CNAMEs at all.
23 \item enable encryption (opportunistic TLS)
24 \item do not use self signed certificates
27 For SMTP client mode we additionally recommend:
29 \item the hostname used as HELO must match the PTR RR
30 \item setup a client certificate (most server certificates are client certificates as well)
31 \item either the common name or at least an alternate subject name of your certificate must match the PTR RR
32 \item do not modify the cipher suite for client mode
35 For MSA operation we recommend:
37 \item listen on submission port 587
38 \item enforce SMTP AUTH even for local networks
39 \item do not allow SMTP AUTH on unencrypted connections
40 \item optionally use the recommended cipher suites if (and only if) all your connecting MUAs support them
45 % 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.
47 We strongly recommend to allow all cipher suites for anything but MSA
48 mode, because the alternative is plain text transmission.
50 %% ----------------------------------------------------------------------
55 \subsubsection{Tested with Version} Dovecot 2.2
57 \subsubsection{Settings}
58 % Example: http://dovecot.org/list/dovecot/2013-October/092999.html
60 \begin{lstlisting}[breaklines]
61 ssl_cipher_list = '@@@CIPHERSTRINGB@@@'
62 ssl_prefer_server_ciphers = yes
65 \subsubsection{Additional info}
67 Dovecot 2.1: Almost as good as dovecot 2.2. Does not support
68 ssl\_prefer\_server\_ciphers
70 \subsubsection{Limitations}
72 Dovecot currently does not support disabling TLS compression. Furthermore, DH
73 parameters greater than 1024bit are not supported. The most recent version
74 2.2.7 of Dovecot implements configurable DH parameter length
75 \footnote{\url{http://hg.dovecot.org/dovecot-2.2/rev/43ab5abeb8f0}}.
77 %\item[Justification for special settings (if needed):] \mbox{}
79 % in case you have the need for further justifications why you chose this and that setting or if the settings do not fit into the standard Variant A or Variant B schema, please document this here
81 \subsubsection{References} \url{http://wiki2.dovecot.org/SSL}
83 % add any further references or best practice documents here
85 \subsubsection{How to test}
86 % describe here or point the admin to tools (can be a simple footnote or \ref{} to the tools section) which help the admin to test his settings.
87 \begin{lstlisting}[breaklines]
88 openssl s_client -crlf -connect SERVER.TLD:993
92 %% ----------------------------------------------------------------------
94 \subsection{cyrus-imapd (based on 2.4.17)}
96 \subsubsection{Tested with Version} \todo{FIXME: add}
98 \subsubsection{Settings}
99 \paragraph*{imapd.conf}\mbox{}\\
101 To activate SSL/TLS configure your certificate with
102 \begin{lstlisting}[breaklines]
103 tls_cert_file: .../cert.pem
104 tls_key_file: .../cert.key
107 Do not forget to add necessary intermediate certificates to the .pem file.\\
109 Limiting the ciphers provided may force (especially older) clients to connect without encryption at all! Sticking to the defaults is recommended.\\
111 If you still want to force strong encryption use
112 \begin{lstlisting}[breaklines]
113 tls_cipher_list: @@@CIPHERSTRINGB@@@
116 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.\\
118 To prevent unencrypted connections on the STARTTLS ports you can set
119 \begin{lstlisting}[breaklines]
122 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.\\
124 \paragraph*{cyrus.conf}\mbox{}\\
126 To support POP3/IMAP on ports 110/143 with STARTTLS add
127 \begin{lstlisting}[breaklines]
128 imap cmd="imapd" listen="imap" prefork=3
129 pop3 cmd="pop3d" listen="pop3" prefork=1
131 to the SERVICES section.\\
133 To support POP3S/IMAPS on ports 995/993 add
134 \begin{lstlisting}[breaklines]
135 imaps cmd="imapd -s" listen="imaps" prefork=3
136 pop3s cmd="pop3d -s" listen="pop3s" prefork=1
140 \subsubsection{Limitations}
142 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.\\
144 Currently there is no way to prefer server ciphers or to disable compression.\\
146 There is a working patch for all three features:
147 \url{https://bugzilla.cyrusimap.org/show_bug.cgi?id=3823}\\
149 \subsubsection{How to test}
150 \begin{lstlisting}[breaklines]
151 openssl s_client -crlf -connect SERVER.TLD:993
156 % XXX config von Adi?
158 % ciphers = EDH+CAMELLIA256:EDH+aRSA:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS:!RC4:!SEED:-AES128:!CAMELLIA128:!ECDSA:AES256-SHA:EDH+AES128;
159 % options = CIPHER_SERVER_PREFERENCE
164 \subsubsection{Tested with Version} Postfix 2.9.6 (Debian Wheezy)
165 \subsubsection{Settings}
167 %% I (cm) consider the generation of own DH parameters to be voodoo until
168 %% someone can explain the contrary. They are, after all, public, and
169 %% I found no research that would show that long-term use of a
170 %% parameter set would weaken the DH exchange. Also notice that IPSEC
171 %% uses fixed parameter sets only.
173 %% also notice the following comment from src/tls/tls_dh.c:
174 %% * Compiled-in EDH primes (the compiled-in generator is always 2). These are
175 %% * used when no parameters are explicitly loaded from a site-specific file.
177 %% * 512-bit parameters are used for export ciphers, and 1024-bit parameters are
178 %% * used for non-export ciphers. An ~80-bit strong EDH key exchange is really
179 %% * too weak to protect 128+ bit keys, but larger DH primes are
180 %% * computationally expensive. When greater security is required, use EECDH.
182 %% First, you need to generate Diffie Hellman parameters (please first take a look at the section \ref{section:RNGs}):
184 %% \todo{FIXME: this is a really weak setting! See also: http://postfix.1071664.n5.nabble.com/postfix-hardening-what-can-we-do-td61874.html}
185 %% \begin{lstlisting}[breaklines]
186 %% % openssl gendh -out /etc/postfix/dh_param_512.pem -2 512
187 %% % openssl gendh -out /etc/postfix/dh_param_1024.pem -2 1024
190 %% Next, we specify these DH parameters in \verb|main.cf|:
192 %% \begin{lstlisting}[breaklines]
193 %% smtpd_tls_dh512_param_file = /etc/postfix/dh_param_512.pem
194 %% smtpd_tls_dh1024_param_file = /etc/postfix/dh_param_1024.pem
197 \paragraph*{MX and SMTP client configuration}\mbox{}\\
199 As discussed in section \ref{subsection:smtp_general}, because of opportunistic encryption we do not
200 restrict the list of ciphers. There are still some steps needed to
201 enable TLS, all in \verb|main.cf|:
203 \begin{lstlisting}[breaklines]
204 smtpd_tls_cert_file = /etc/postfix/server.pem
205 smtpd_tls_key_file = /etc/postfix/server.key
206 # use 0 for Postfix >= 2.9, and 1 for earlier versions
207 smtpd_tls_loglevel = 0
208 # enable opportunistic TLS support in the SMTP server and client
209 smtpd_tls_security_level = may
210 smtp_tls_security_level = may
211 # if you have authentication enabled, only offer it after STARTTLS
212 smtpd_tls_auth_only = yes
213 tls_ssl_options = NO_COMPRESSION
216 \paragraph*{MSA}\mbox{}\\
218 For the MSA \verb|smtpd| process, we first define the ciphers that are
219 acceptable for the ``mandatory'' security level, again in
222 \begin{lstlisting}[breaklines]
223 smtpd_tls_mandatory_protocols = !SSLv2, !SSLv3
224 smtpd_tls_mandatory_ciphers=high
225 tls_high_cipherlist=@@@CIPHERSTRINGB@@@
228 Then, we configure the MSA smtpd in \verb|master.cf| with two
229 additional options that are only used for this instance of smtpd:
231 \begin{lstlisting}[breaklines]
232 587 inet n - - - - smtpd
233 -o smtpd_tls_security_level=encrypt -o tls_preempt_cipherlist = yes
236 For those users who want to use ECC key exchange, it is possible to specify this via:
237 \begin{lstlisting}[breaklines]
238 smtpd_tls_eecdh_grade = ultra
241 \subsubsection{Limitations}
243 tls\_ssl\_options is supported from Postfix 2.11 onwards. You can
244 leave the statement in the configuration for older versions, it will
247 tls\_preempt\_cipherlist is supported from Postfix 2.8 onwards. Again,
248 you can leave the statement in for older versions.
250 \subsubsection{References}
252 Refer to \url{http://www.postfix.org/TLS_README.html} for an in-depth
255 \subsubsection{Additional settings}
257 Postfix has two sets of built-in DH parameters that can be overridden
258 with the \verb|smtpd_tls_dh512_param_file|
259 and \verb|smtpd_tls_dh1024_param_file| options. The ``dh512''
260 parameters are used for export ciphers, while the ``dh1024'' ones are
261 used for all other ciphers.
263 The ``bit lenght'' in those parameter names is just a name, so one
264 could use stronger parameter sets; it should be possible to e.g. use the
265 IKE Group14 parameters (see section \ref{section:DH}) without much
266 interoperability risk, but we have not tested this yet.
268 % \item[Justification for special settings (if needed):]
269 % no special settings
272 \subsubsection{How to test}
274 You can check the effect of the settings with the following command:
275 \begin{lstlisting}[breaklines]
276 $ 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
277 1 SSLv3 with cipher DHE-RSA-AES256-SHA
278 23 TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384
279 60 TLSv1 with cipher ECDHE-RSA-AES256-SHA
280 270 TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384
281 335 TLSv1 with cipher DHE-RSA-AES256-SHA
284 \begin{lstlisting}[breaklines]
285 openssl s_client -starttls smtp -crlf -connect SERVER.TLD:25
288 \subsubsection{References} \todo{FIXME}
290 %% ----------------------------------------------------------------------
292 \subsection{Exim (based on 4.82)}
294 It is highly recommended to read
295 \url{http://exim.org/exim-html-current/doc/html/spec_html/ch-encrypted_smtp_connections_using_tlsssl.html}
298 \paragraph*{MSA mode (submission)}\mbox{}\\
300 In the main config section of Exim add:
302 \begin{lstlisting}[breaklines]
303 tls_certificate = ..../cert.pem
304 tls_privatekey = ..../cert.key
306 don't forget to add intermediate certificates to the .pem file if needed.\\
308 Tell Exim to advertise STARTTLS in the EHLO answer to everyone:
309 \begin{lstlisting}[breaklines]
310 tls_advertise_hosts = *
313 If you want to support legacy SMTPS on port 465, and STARTTLS on smtp(25)/submission(587) ports set
314 \begin{lstlisting}[breaklines]
315 daemon_smtp_ports = smtp : smtps : submission
316 tls_on_connect_ports = 465
319 It is highly recommended to limit SMTP AUTH to SSL connections only. To do so add
320 \begin{lstlisting}[breaklines]
321 server_advertise_condition = ${if eq{$tls_cipher}{}{no}{yes}}
323 to every authenticator defined.\\
325 Add the following rules on top of your acl\_smtp\_mail:
326 \begin{lstlisting}[breaklines]
328 control = submission/sender_retain
330 This switches Exim to submission mode and allows addition of missing ``Message-ID'' and ``Date'' headers.\\
332 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.\\
333 % Exim maintainers do not recommend to change default ciphers
334 % I think we shouldn't, too
336 %\begin{lstlisting}[breaklines]
337 % tls_require_ciphers = <...recommended ciphersuite...>
340 The cipher used is written to the logfiles by default. You may want to add
341 \begin{lstlisting}[breaklines]
342 log_selector = <....whatever your log_selector already contains...> \
343 +tls_certificate_verified +tls_peerdn +tls_sni
345 to get even more TLS information logged.
348 \paragraph*{server mode (incoming)}\mbox{}\\
350 In the main config section of Exim add:
352 \begin{lstlisting}[breaklines]
353 tls_certificate = ..../cert.pem
354 tls_privatekey = ..../cert.key
356 don't forget to add intermediate certificates to the .pem file if needed.\\
358 Tell Exim to advertise STARTTLS in the EHLO answer to everyone:
359 \begin{lstlisting}[breaklines]
360 tls_advertise_hosts = *
363 Listen on smtp(25) port only
364 \begin{lstlisting}[breaklines]
365 daemon_smtp_ports = smtp
368 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.\\
369 % Exim maintainers do not recommend to change default ciphers
372 %\begin{lstlisting}[breaklines]
373 % tls_require_ciphers = <...recommended ciphersuite...>
376 If you want to request and verify client certificates from sending hosts set
377 \begin{lstlisting}[breaklines]
378 tls_verify_certificates = /etc/pki/tls/certs/ca-bundle.crt
379 tls_try_verify_hosts = *
382 tls\_try\_verify\_hosts only reports the result to your logfile. If you want to disconnect such clients you have to use
383 \begin{lstlisting}[breaklines]
387 The cipher used is written to the logfiles by default. You may want to add
388 \begin{lstlisting}[breaklines]
389 log_selector = <....whatever your log_selector already contains...> \
390 +tls_certificate_verified +tls_peerdn +tls_sni
392 to get even more TLS information logged.
394 \paragraph*{client mode (outgoing)}\mbox{}\\
396 Exim uses opportunistic encryption in the SMTP transport by default.
398 Client mode settings have to be done in the configuration section of the smtp transport (driver = smtp).
400 If you want to use a client certificate (most server certificates can be used as client certificate, too) set
401 \begin{lstlisting}[breaklines]
402 tls_certificate = .../cert.pem
403 tls_privatekey = .../cert.key
405 This is recommended for MTA-MTA traffic.\\
407 %If you want to limit used ciphers set
408 %\begin{lstlisting}[breaklines]
409 % tls_require_ciphers = <...recommended ciphersuite...>
411 % Exim Maintainers do not recommend ciphers. We shouldn't do so, too.
412 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.
414 \paragraph*{OpenSSL}\mbox{}\\
415 Exim already disables SSLv2 by default. We recommend to add
416 \begin{lstlisting}[breaklines]
417 openssl_options = +all +no_sslv2 +no_compression +cipher_server_preference
419 to the main configuration.\\
420 Note: +all is misleading here since OpenSSL only activates the most common workarounds. But that's how SSL\_OP\_ALL is defined.\\
422 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\cite{rfc5114} (ike23).
423 If you want to set your own DH parameters please read the TLS documentation of exim.\\
427 \paragraph*{GnuTLS}\mbox{}\\
429 GnuTLS is different in only some respects to OpenSSL:
431 \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.
432 \item There is no option like openssl\_options
435 \paragraph*{Exim string expansion}\mbox{}\\
437 Note that most of the options accept expansion strings. This way you can eg. set cipher lists or STARTTLS advertisement conditionally. Please follow the link to the official Exim documentation to get more information.
439 \paragraph*{Limitations}\mbox{}\\
441 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.
442 There already is a working patch to provide support:\\
443 \url{http://bugs.exim.org/show_bug.cgi?id=1397}
445 \paragraph*{How to test}\mbox{}\\
446 \begin{lstlisting}[breaklines]
447 openssl s_client -starttls smtp -crlf -connect SERVER.TLD:25
451 %% ----------------------------------------------------------------------
452 \subsection{Exchange}
454 \todo{FIXME: write this section}