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}
8 \subsubsection{Tested with Version} Dovecot 2.2
10 \subsubsection{Settings}
11 % Example: http://dovecot.org/list/dovecot/2013-October/092999.html
13 \begin{lstlisting}[breaklines]
14 ssl_cipher_list = '@@@CIPHERSTRINGB@@@'
15 ssl_prefer_server_ciphers = yes
18 \subsubsection{Additional info}
20 Dovecot 2.1: Almost as good as dovecot 2.2. Does not support
21 ssl\_prefer\_server\_ciphers
23 \subsubsection{Limitations}
25 Dovecot currently does not support disabling TLS compression. Furthermore, DH
26 parameters greater than 1024bit are not supported. The most recent version
27 2.2.7 of Dovecot implements configurable DH parameter length
28 \footnote{\url{http://hg.dovecot.org/dovecot-2.2/rev/43ab5abeb8f0}}.
30 %\item[Justification for special settings (if needed):] \mbox{}
32 % 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
34 \subsubsection{References} \url{http://wiki2.dovecot.org/SSL}
36 % add any further references or best practice documents here
38 \subsubsection{How to test}
39 % 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.
44 %% ----------------------------------------------------------------------
46 \subsubsection{cyrus-imapd (based on 2.4.17)}
48 \subsubsection{Tested with Version} \todo{FIXME: add}
50 \subsubsection{Settings}
51 \paragraph*{imapd.conf}\mbox{}\\
53 To activate SSL/TLS configure your certificate with
54 \begin{lstlisting}[breaklines]
55 tls_cert_file: .../cert.pem
56 tls_key_file: .../cert.key
59 Do not forget to add necessary intermediate certificates to the .pem file.\\
61 Limiting the ciphers provided may force (especially older) clients to connect without encryption at all! Sticking to the defaults is recommended.\\
63 If you still want to force strong encryption use
64 \begin{lstlisting}[breaklines]
65 tls_cipher_list: @@@CIPHERSTRINGB@@@
68 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.\\
70 To prevent unencrypted connections on the STARTTLS ports you can set
71 \begin{lstlisting}[breaklines]
74 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.\\
76 \paragraph*{cyrus.conf}\mbox{}\\
78 To support POP3/IMAP on ports 110/143 with STARTTLS add
79 \begin{lstlisting}[breaklines]
80 imap cmd="imapd" listen="imap" prefork=3
81 pop3 cmd="pop3d" listen="pop3" prefork=1
83 to the SERVICES section.\\
85 To support POP3S/IMAPS on ports 995/993 add
86 \begin{lstlisting}[breaklines]
87 imaps cmd="imapd -s" listen="imaps" prefork=3
88 pop3s cmd="pop3d -s" listen="pop3s" prefork=1
92 \subsubsection{Limitations}
94 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.\\
96 Currently there is no way to prefer server ciphers or to disable compression.\\
98 There is a working patch for all three features:
99 \url{https://bugzilla.cyrusimap.org/show_bug.cgi?id=3823}\\
101 \subsubsection{References}
104 \subsubsection{How to test}
110 % XXX config von Adi?
112 % ciphers = EDH+CAMELLIA256:EDH+aRSA:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS:!RC4:!SEED:-AES128:!CAMELLIA128:!ECDSA:AES256-SHA:EDH+AES128;
113 % options = CIPHER_SERVER_PREFERENCE
116 %% ----------------------------------------------------------------------
118 \subsubsection{SMTP in general}
119 \label{subsection:smtp_general}
121 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.\\
123 Furthermore a mailserver can operate in three modes:
125 \item As MSA (Mail Submission Agent) your mailserver receives mail from your clients MUAs (Mail User Agent).
126 \item As receiving MTA (Mail Transmission Agent, MX)
127 \item As sending MTA (SMTP client)
130 We recommend the following basic setup for all modes:
132 \item correctly setup MX, A and PTR RRs without using CNAMEs at all.
133 \item enable encryption (opportunistic TLS)
134 \item do not use self signed certificates
137 For SMTP client mode we additionally recommend:
139 \item the hostname used as HELO must match the PTR RR
140 \item setup a client certificate (most server certificates are client certificates as well)
141 \item either the common name or at least an alternate subject name of your certificate must match the PTR RR
142 \item do not modify the cipher suite for client mode
145 For MSA operation we recommend:
147 \item listen on submission port 587
148 \item enforce SMTP AUTH even for local networks
149 \item do not allow SMTP AUTH on unencrypted connections
150 \item optionally use the recommended cipher suites if (and only if) all your connecting MUAs support them
155 % 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.
157 We strongly recommend to allow all cipher suites for anything but MSA
158 mode, because the alternative is plain text transmission.
160 %% ----------------------------------------------------------------------
162 \subsubsection{Postfix}
165 \item[Tested with Version:] \mbox{}
168 \item Postfix 2.9.6 (Debian Wheezy)
171 \item[Settings:] \mbox{}
173 %% I (cm) consider the generation of own DH parameters to be voodoo until
174 %% someone can explain the contrary. They are, after all, public, and
175 %% I found no research that would show that long-term use of a
176 %% parameter set would weaken the DH exchange. Also notice that IPSEC
177 %% uses fixed parameter sets only.
179 %% also notice the following comment from src/tls/tls_dh.c:
180 %% * Compiled-in EDH primes (the compiled-in generator is always 2). These are
181 %% * used when no parameters are explicitly loaded from a site-specific file.
183 %% * 512-bit parameters are used for export ciphers, and 1024-bit parameters are
184 %% * used for non-export ciphers. An ~80-bit strong EDH key exchange is really
185 %% * too weak to protect 128+ bit keys, but larger DH primes are
186 %% * computationally expensive. When greater security is required, use EECDH.
188 %% First, you need to generate Diffie Hellman parameters (please first take a look at the section \ref{section:RNGs}):
190 %% \todo{FIXME: this is a really weak setting! See also: http://postfix.1071664.n5.nabble.com/postfix-hardening-what-can-we-do-td61874.html}
191 %% \begin{lstlisting}[breaklines]
192 %% % openssl gendh -out /etc/postfix/dh_param_512.pem -2 512
193 %% % openssl gendh -out /etc/postfix/dh_param_1024.pem -2 1024
196 %% Next, we specify these DH parameters in \verb|main.cf|:
198 %% \begin{lstlisting}[breaklines]
199 %% smtpd_tls_dh512_param_file = /etc/postfix/dh_param_512.pem
200 %% smtpd_tls_dh1024_param_file = /etc/postfix/dh_param_1024.pem
203 \paragraph*{MX and SMTP client configuration}\mbox{}\\
205 As discussed in section \ref{subsection:smtp_general}, because of opportunistic encryption we do not
206 restrict the list of ciphers. There are still some steps needed to
207 enable TLS, all in \verb|main.cf|:
209 \begin{lstlisting}[breaklines]
210 smtpd_tls_cert_file = /etc/postfix/server.pem
211 smtpd_tls_key_file = /etc/postfix/server.key
212 # use 0 for Postfix >= 2.9, and 1 for earlier versions
213 smtpd_tls_loglevel = 0
214 # enable opportunistic TLS support in the SMTP server and client
215 smtpd_tls_security_level = may
216 smtp_tls_security_level = may
217 # if you have authentication enabled, only offer it after STARTTLS
218 smtpd_tls_auth_only = yes
219 tls_ssl_options = NO_COMPRESSION
222 \paragraph*{MSA}\mbox{}\\
224 For the MSA \verb|smtpd| process, we first define the ciphers that are
225 acceptable for the ``mandatory'' security level, again in
228 \begin{lstlisting}[breaklines]
229 smtpd_tls_mandatory_protocols = !SSLv2, !SSLv3
230 smtpd_tls_mandatory_ciphers=high
231 tls_high_cipherlist=@@@CIPHERSTRINGB@@@
234 Then, we configure the MSA smtpd in \verb|master.cf| with two
235 additional options that are only used for this instance of smtpd:
237 \begin{lstlisting}[breaklines]
238 587 inet n - - - - smtpd
239 -o smtpd_tls_security_level=encrypt -o tls_preempt_cipherlist = yes
242 For those users who want to use ECC key exchange, it is possible to specify this via:
243 \begin{lstlisting}[breaklines]
244 smtpd_tls_eecdh_grade = ultra
247 \item[Limitations:] \mbox{}
249 tls\_ssl\_options is supported from Postfix 2.11 onwards. You can
250 leave the statement in the configuration for older versions, it will
253 tls\_preempt\_cipherlist is supported from Postfix 2.8 onwards. Again,
254 you can leave the statement in for older versions.
258 Refer to \url{http://www.postfix.org/TLS_README.html} for an in-depth
261 \item[Additional settings:]
263 Postfix has two sets of built-in DH parameters that can be overridden
264 with the \verb|smtpd_tls_dh512_param_file|
265 and \verb|smtpd_tls_dh1024_param_file| options. The ``dh512''
266 parameters are used for export ciphers, while the ``dh1024'' ones are
267 used for all other ciphers.
269 The ``bit lenght'' in those parameter names is just a name, so one
270 could use stronger parameter sets; it should be possible to e.g. use the
271 IKE Group14 parameters (see section \ref{section:DH}) without much
272 interoperability risk, but we have not tested this yet.
274 % \item[Justification for special settings (if needed):]
275 % no special settings
279 You can check the effect of the settings with the following command:
280 \begin{lstlisting}[breaklines]
281 $ 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
282 1 SSLv3 with cipher DHE-RSA-AES256-SHA
283 23 TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384
284 60 TLSv1 with cipher ECDHE-RSA-AES256-SHA
285 270 TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384
286 335 TLSv1 with cipher DHE-RSA-AES256-SHA
292 %% ----------------------------------------------------------------------
294 \subsubsection{Exim (based on 4.82)}
296 It is highly recommended to read
298 \url{http://exim.org/exim-html-current/doc/html/spec_html/ch-encrypted_smtp_connections_using_tlsssl.html}
302 \paragraph*{MSA mode (submission)}\mbox{}\\
304 In the main config section of Exim add:
306 \begin{lstlisting}[breaklines]
307 tls_certificate = ..../cert.pem
308 tls_privatekey = ..../cert.key
310 don't forget to add intermediate certificates to the .pem file if needed.\\
312 Tell Exim to advertise STARTTLS in the EHLO answer to everyone:
313 \begin{lstlisting}[breaklines]
314 tls_advertise_hosts = *
317 If you want to support legacy SMTPS on port 465, and STARTTLS on smtp(25)/submission(587) ports set
318 \begin{lstlisting}[breaklines]
319 daemon_smtp_ports = smtp : smtps : submission
320 tls_on_connect_ports = 465
323 It is highly recommended to limit SMTP AUTH to SSL connections only. To do so add
324 \begin{lstlisting}[breaklines]
325 server_advertise_condition = ${if eq{$tls_cipher}{}{no}{yes}}
327 to every authenticator defined.\\
329 Add the following rules on top of your acl\_smtp\_mail:
330 \begin{lstlisting}[breaklines]
332 control = submission/sender_retain
334 This switches Exim to submission mode and allows addition of missing ``Message-ID'' and ``Date'' headers.\\
336 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.\\
337 % Exim maintainers do not recommend to change default ciphers
338 % I think we shouldn't, too
340 %\begin{lstlisting}[breaklines]
341 % tls_require_ciphers = <...recommended ciphersuite...>
344 The cipher used is written to the logfiles by default. You may want to add
345 \begin{lstlisting}[breaklines]
346 log_selector = <....whatever your log_selector already contains...> \
347 +tls_certificate_verified +tls_peerdn +tls_sni
349 to get even more TLS information logged.
352 \paragraph*{server mode (incoming)}\mbox{}\\
354 In the main config section of Exim add:
356 \begin{lstlisting}[breaklines]
357 tls_certificate = ..../cert.pem
358 tls_privatekey = ..../cert.key
360 don't forget to add intermediate certificates to the .pem file if needed.\\
362 Tell Exim to advertise STARTTLS in the EHLO answer to everyone:
363 \begin{lstlisting}[breaklines]
364 tls_advertise_hosts = *
367 Listen on smtp(25) port only
368 \begin{lstlisting}[breaklines]
369 daemon_smtp_ports = smtp
372 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.\\
373 % Exim maintainers do not recommend to change default ciphers
376 %\begin{lstlisting}[breaklines]
377 % tls_require_ciphers = <...recommended ciphersuite...>
380 If you want to request and verify client certificates from sending hosts set
381 \begin{lstlisting}[breaklines]
382 tls_verify_certificates = /etc/pki/tls/certs/ca-bundle.crt
383 tls_try_verify_hosts = *
386 tls\_try\_verify\_hosts only reports the result to your logfile. If you want to disconnect such clients you have to use
387 \begin{lstlisting}[breaklines]
391 The cipher used is written to the logfiles by default. You may want to add
392 \begin{lstlisting}[breaklines]
393 log_selector = <....whatever your log_selector already contains...> \
394 +tls_certificate_verified +tls_peerdn +tls_sni
396 to get even more TLS information logged.
398 \paragraph*{client mode (outgoing)}\mbox{}\\
400 Exim uses opportunistic encryption in the SMTP transport by default.
402 Client mode settings have to be done in the configuration section of the smtp transport (driver = smtp).
404 If you want to use a client certificate (most server certificates can be used as client certificate, too) set
405 \begin{lstlisting}[breaklines]
406 tls_certificate = .../cert.pem
407 tls_privatekey = .../cert.key
409 This is recommended for MTA-MTA traffic.\\
411 %If you want to limit used ciphers set
412 %\begin{lstlisting}[breaklines]
413 % tls_require_ciphers = <...recommended ciphersuite...>
415 % Exim Maintainers do not recommend ciphers. We shouldn't do so, too.
416 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.
418 \paragraph*{OpenSSL}\mbox{}\\
419 Exim already disables SSLv2 by default. We recommend to add
420 \begin{lstlisting}[breaklines]
421 openssl_options = +all +no_sslv2 +no_compression +cipher_server_preference
423 to the main configuration.\\
424 Note: +all is misleading here since OpenSSL only activates the most common workarounds. But that's how SSL\_OP\_ALL is defined.\\
426 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).
427 If you want to set your own DH parameters please read the TLS documentation of exim.\\
431 \paragraph*{GnuTLS}\mbox{}\\
433 GnuTLS is different in only some respects to OpenSSL:
435 \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.
436 \item There is no option like openssl\_options
439 \paragraph*{Exim string expansion}\mbox{}\\
441 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.
443 \paragraph*{Limitations}\mbox{}\\
445 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.
446 There already is a working patch to provide support:\\
447 \url{http://bugs.exim.org/show_bug.cgi?id=1397}
450 % do we need to documment starttls in detail?
451 %\subsubsection{starttls?}
453 %% ----------------------------------------------------------------------
454 \subsubsection{Exchange}
456 \todo{FIXME: write this section}