2 \gdef\currentsectionname{MailServers}
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 %% ----------------------------------------------------------------------
7 \subsection{SMTP in general}
8 \label{subsection:smtp_general}
9 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.
11 Furthermore a mailserver can operate in three modes:
13 \item As MSA (Mail Submission Agent) your mailserver receives mail from your clients MUAs (Mail User Agent).
14 \item As receiving MTA (Mail Transmission Agent, MX)
15 \item As sending MTA (SMTP client)
17 We recommend the following basic setup for all modes:
19 \item correctly setup MX, A and PTR RRs without using CNAMEs at all.
20 \item enable encryption (opportunistic TLS)
21 \item do not use self signed certificates
24 For SMTP client mode we additionally recommend:
26 \item the hostname used as HELO must match the PTR RR
27 \item setup a client certificate (most server certificates are client certificates as well)
28 \item either the common name or at least an alternate subject name of your certificate must match the PTR RR
29 \item do not modify the cipher suite for client mode
32 For MSA operation we recommend:
34 \item listen on submission port 587
35 \item enforce SMTP AUTH even for local networks
36 \item do not allow SMTP AUTH on unencrypted connections
37 \item optionally use the recommended cipher suites if (and only if) all your connecting MUAs support them
41 % 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.
43 We strongly recommend to allow all cipher suites for anything but MSA
44 mode, because the alternative is plain text transmission.
46 %% ----------------------------------------------------------------------
50 \subsubsection{Tested with Version}
52 \item Dovecot 2.1.7, Debian Wheezy (without ``ssl\_prefer\_server\_ciphers'' setting)
53 \item Dovecot 2.2.9, Debian Jessie
54 \item 2.0.19apple1 on OS X Server 10.8.5 (without ``ssl\_prefer\_server\_ciphers'' setting)
57 \subsubsection{Settings}
58 % Example: http://dovecot.org/list/dovecot/2013-October/092999.html
60 \configfile{10-ssl.conf}{51-55}{Dovecot SSL configuration}
62 \subsubsection{Additional info}
63 Dovecot 2.0, 2.1: Almost as good as dovecot 2.2. Dovecot does not ignore unknown configuration parameters. Does not support
64 ssl\_prefer\_server\_ciphers
66 \subsubsection{Limitations}
67 Dovecot currently does not support disabling TLS compression. Furthermore, DH
68 parameters greater than 1024bit are not supported. The most recent version
69 2.2.7 of Dovecot implements configurable DH parameter length
70 \footnote{\url{http://hg.dovecot.org/dovecot-2.2/rev/43ab5abeb8f0}}.
72 %\subsubsection{Justification for special settings (if needed)}
74 % 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
76 \subsubsection{References}
78 \item \url{http://wiki2.dovecot.org/SSL}
81 % add any further references or best practice documents here
83 \subsubsection{How to test}
84 % 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.
86 openssl s_client -crlf -connect SERVER.TLD:993
90 %% ----------------------------------------------------------------------
91 \subsection{cyrus-imapd}
92 \subsubsection{Tested with Versions}
97 \subsubsection{Settings}
99 To activate SSL/TLS configure your certificate with
100 \configfile{imapd.conf}{206-206,209-209}{Activating TLS in cyrus}
102 Do not forget to add necessary intermediate certificates to the .pem file.
104 Limiting the ciphers provided may force (especially older) clients to connect without encryption at all! Sticking to the defaults is recommended.
106 If you still want to force strong encryption use
107 \configfile{imapd.conf}{263-263}{TLS cipher selection in cyrus}
109 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.
111 To prevent unencrypted connections on the STARTTLS ports you can set
112 \configfile{imapd.conf}{131-131}{Force encrypted connections in cyrus}
113 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.
115 To support POP3/IMAP on ports 110/143 with STARTTLS and POP3S/IMAPS on ports
116 995/993 add, check the SERVICES setction in \texttt{cyrus.conf}
117 \configfile{cyrus.conf}{28-28,31-34,71-71}{STARTTLS for POP3/IMAP and POP3S/IMAPS in cyrus}
120 \subsubsection{Limitations}
121 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.
123 Currently there is no way to prefer server ciphers or to disable compression.
125 There is a working patch for all three features:
126 \url{https://bugzilla.cyrusimap.org/show_bug.cgi?id=3823}
128 \subsubsection{How to test}
130 openssl s_client -crlf -connect SERVER.TLD:993
133 % XXX config von Adi?
135 % ciphers = EDH+CAMELLIA256:EDH+aRSA:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS:!RC4:!SEED:-AES128:!CAMELLIA128:!ECDSA:AES256-SHA:EDH+AES128;
136 % options = CIPHER_SERVER_PREFERENCE
140 %% ----------------------------------------------------------------------
143 \subsubsection{Tested with Versions}
145 \item Postfix 2.9.6, Debian Wheezy
149 \subsubsection{Settings}
151 %% I (cm) consider the generation of own DH parameters to be voodoo until
152 %% someone can explain the contrary. They are, after all, public, and
153 %% I found no research that would show that long-term use of a
154 %% parameter set would weaken the DH exchange. Also notice that IPSEC
155 %% uses fixed parameter sets only.
157 %% also notice the following comment from src/tls/tls_dh.c:
158 %% * Compiled-in EDH primes (the compiled-in generator is always 2). These are
159 %% * used when no parameters are explicitly loaded from a site-specific file.
161 %% * 512-bit parameters are used for export ciphers, and 1024-bit parameters are
162 %% * used for non-export ciphers. An ~80-bit strong EDH key exchange is really
163 %% * too weak to protect 128+ bit keys, but larger DH primes are
164 %% * computationally expensive. When greater security is required, use EECDH.
166 %% First, you need to generate Diffie Hellman parameters (please first take a look at the section \ref{section:RNGs}):
168 %% \todo{FIXME: this is a really weak setting! See also: http://postfix.1071664.n5.nabble.com/postfix-hardening-what-can-we-do-td61874.html}
169 %% \begin{lstlisting}
170 %% % openssl gendh -out /etc/postfix/dh_param_512.pem -2 512
171 %% % openssl gendh -out /etc/postfix/dh_param_1024.pem -2 1024
174 %% Next, we specify these DH parameters in \verb|main.cf|:
176 %% \begin{lstlisting}
177 %% smtpd_tls_dh512_param_file = /etc/postfix/dh_param_512.pem
178 %% smtpd_tls_dh1024_param_file = /etc/postfix/dh_param_1024.pem
181 \paragraph{MX and SMTP client configuration:}
182 As discussed in section \ref{subsection:smtp_general}, because of opportunistic encryption we do not
183 restrict the list of ciphers. There are still some steps needed to
184 enable TLS, all in \verb|main.cf|:
186 \configfile{main.cf}{22-33}{Opportunistic TLS in Postfix}
189 For the MSA \verb|smtpd| process, we first define the ciphers that are
190 acceptable for the ``mandatory'' security level, again in
193 \configfile{main.cf}{35-37}{MSA TLS configuration in Postfix}
195 Then, we configure the MSA smtpd in \verb|master.cf| with two
196 additional options that are only used for this instance of smtpd:
198 \configfile{master.cf}{12-14}{MSA smtpd service configuraiton in Postfix}
200 For those users who want to use ECC key exchange, it is possible to customize this via:
201 \configfile{main.cf}{38-38}{EECDH customization in Postfix}
202 The default value since Postfix 2.8 is ``strong''.
205 \subsubsection{Limitations}
206 tls\_ssl\_options is supported from Postfix 2.11 onwards. You can
207 leave the statement in the configuration for older versions, it will
210 tls\_preempt\_cipherlist is supported from Postfix 2.8 onwards. Again,
211 you can leave the statement in for older versions.
213 \subsubsection{References}
214 Refer to \url{http://www.postfix.org/TLS_README.html} for an in-depth
217 \subsubsection{Additional settings}
218 Postfix has two sets of built-in DH parameters that can be overridden
219 with the \verb|smtpd_tls_dh512_param_file|
220 and \verb|smtpd_tls_dh1024_param_file| options. The ``dh512''
221 parameters are used for export ciphers, while the ``dh1024'' ones are
222 used for all other ciphers.
224 The ``bit length'' in those parameter names is just a name, so one
225 could use stronger parameter sets; it should be possible to e.g. use the
226 IKE Group14 parameters (see section \ref{section:DH}) without much
227 interoperability risk, but we have not tested this yet.
229 % \subsubsection{Justification for special settings (if needed)}
230 % no special settings
233 \subsubsection{How to test}
234 You can check the effect of the settings with the following command:
236 $ 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
237 1 SSLv3 with cipher DHE-RSA-AES256-SHA
238 23 TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384
239 60 TLSv1 with cipher ECDHE-RSA-AES256-SHA
240 270 TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384
241 335 TLSv1 with cipher DHE-RSA-AES256-SHA
245 openssl s_client -starttls smtp -crlf -connect SERVER.TLD:25
248 %% ----------------------------------------------------------------------
252 \subsubsection{Tested with Versions}
254 \item Exim 4.82, Debian Jessie
258 It is highly recommended to read
259 \url{http://exim.org/exim-html-current/doc/html/spec_html/ch-encrypted_smtp_connections_using_tlsssl.html}
262 \paragraph{MSA mode (submission):}
263 In the main config section of Exim add:
264 \configfile{configure.msa}{153-154}{Certificate selection in Exim (MSA)}
265 Don't forget to add intermediate certificates to the .pem file if needed.
267 Tell Exim to advertise STARTTLS in the EHLO answer to everyone:
268 \configfile{configure.msa}{145-145}{TLS advertise in Exim (MSA)}
270 If you want to support legacy SMTPS on port 465, and STARTTLS on smtp(25)/submission(587) ports set
271 \configfile{configure.msa}{165-166}{STARTTLS and SMTPS in Exim (MSA)}
273 It is highly recommended to limit SMTP AUTH to SSL connections only. To do so add
274 \configfile{configure.msa}{813-813}{SSL-only authentication in Exim (MSA)}
275 to every authenticator defined.
277 Add the following rules on top of your acl\_smtp\_mail:
278 \configfile{configure.msa}{111-111,501-505}{Submission mode in Exim (MSA)}
279 This switches Exim to submission mode and allows addition of missing ``Message-ID'' and ``Date'' headers.
281 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.
282 % Exim maintainers do not recommend to change default ciphers
283 % I think we shouldn't, too
286 % tls_require_ciphers = <...recommended ciphersuite...>
289 The cipher used is written to the logfiles by default. You may want to add
291 log_selector = <whatever your log_selector already contains> +tls_certificate_verified +tls_peerdn +tls_sni
293 to get even more TLS information logged.
296 \paragraph{Server mode (incoming):}
297 In the main config section of Exim add:
298 \configfile{configure.server}{152-153}{Certificate selection in Exim (Server)}
299 don't forget to add intermediate certificates to the .pem file if needed.
301 Tell Exim to advertise STARTTLS in the EHLO answer to everyone:
302 \configfile{configure.server}{144-144}{TLS advertise in Exim (Server)}
304 Listen on smtp(25) port only
305 \configfile{configure.server}{166-166}{STARTTLS on SMTP in Exim (Server)}
307 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.
308 % Exim maintainers do not recommend to change default ciphers
312 % tls_require_ciphers = <...recommended ciphersuite...>
315 If you want to request and verify client certificates from sending hosts set
316 \configfile{configure.server}{154-155}{TLS certificate verifiaction in Exim (Server)}
318 tls\_try\_verify\_hosts only reports the result to your logfile. If you want to disconnect such clients you have to use
323 The cipher used is written to the logfiles by default. You may want to add
325 log_selector = <whatever your log_selector already contains> +tls_certificate_verified +tls_peerdn +tls_sni
327 to get even more TLS information logged.
329 \paragraph{Client mode (outgoing):}
330 Exim uses opportunistic encryption in the SMTP transport by default.
332 Client mode settings have to be done in the configuration section of the smtp transport (driver = smtp).
334 If you want to use a client certificate (most server certificates can be used as client certificate, too) set
335 \configfile{configure.client}{152-153}{Certificate selection in Exim (Client)}
336 This is recommended for MTA-MTA traffic.
338 %If you want to limit used ciphers set
340 % tls_require_ciphers = <...recommended ciphersuite...>
342 % Exim Maintainers do not recommend ciphers. We shouldn't do so, too.
343 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.
346 Exim already disables SSLv2 by default. We recommend to add
348 openssl_options = +all +no_sslv2 +no_compression +cipher_server_preference
350 to the main configuration.
352 Note: +all is misleading here since OpenSSL only activates the most common workarounds. But that's how SSL\_OP\_ALL is defined.
354 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).
355 If you want to set your own DH parameters please read the TLS documentation of exim.
359 GnuTLS is different in only some respects to OpenSSL:
361 \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.
362 \item There is no option like openssl\_options
365 \paragraph{Exim string expansion:}
366 Note that 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.
368 \paragraph{Limitations:}
369 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.
370 There already is a working patch to provide support:
371 \url{http://bugs.exim.org/show_bug.cgi?id=1397}
373 \subsubsection{How to test}
375 openssl s_client -starttls smtp -crlf -connect SERVER.TLD:25
379 %% ----------------------------------------------------------------------
380 %\subsection{Exchange}
382 %\todo{FIXME: write this section}