1<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN" 2 "http://www.w3.org/TR/html4/loose.dtd"> 3 4<html> 5 6<head> 7 8<title>Postfix legacy TLS Support </title> 9 10<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 11<link rel='stylesheet' type='text/css' href='postfix-doc.css'> 12 13</head> 14 15<body> 16 17<h1><img src="postfix-logo.jpg" width="203" height="98" ALT="">Postfix legacy TLS Support 18</h1> 19 20<hr> 21 22<h2> NOTE </h2> 23 24<p> This document describes an old TLS user interface that is based 25on a third-party TLS patch by Lutz Jänicke. As of Postfix 26version 2.3, the old user interface still exists to allow migration 27from earlier Postfix releases, but its functionality is frozen. </p> 28 29<h2> What Postfix TLS support does for you </h2> 30 31<p> Transport Layer Security (TLS, formerly called SSL) provides 32certificate-based authentication and encrypted sessions. An 33encrypted session protects the information that is transmitted with 34SMTP mail or with SASL authentication. 35 36<p> Postfix version 2.2 introduces support for TLS as described in 37RFC 3207. TLS Support for older Postfix versions was available as 38an add-on patch. The section "<a href="#compat">Compatibility with 39Postfix < 2.2 TLS support</a>" below discusses the differences 40between these implementations. </p> 41 42<p> Topics covered in this document: </p> 43 44<ul> 45 46<li><a href="#how">How Postfix TLS support works</a> 47 48<li><a href="#build_tls">Building Postfix with TLS support</a> 49 50<li><a href="#server_tls">SMTP Server specific settings</a> 51 52<li> <a href="#client_tls">SMTP Client specific settings</a> 53 54<li><a href="#tlsmgr_controls"> TLS manager specific settings </a> 55 56<li><a href="#problems"> Reporting problems </a> 57 58<li><a href="#compat">Compatibility with Postfix < 2.2 TLS support</a> 59 60<li><a href="#credits"> Credits </a> 61 62</ul> 63 64<p> And last but not least, for the impatient: </p> 65 66<ul> 67 68<li><a href="#quick-start">Getting started, quick and dirty</a> 69 70</ul> 71 72<h2><a name="how">How Postfix TLS support works</a></h2> 73 74<p> The diagram below shows the main elements of the Postfix TLS 75architecture and their relationships. Colored boxes with numbered 76names represent Postfix daemon programs. Other colored boxes 77represent storage elements. </p> 78 79<ul> 80 81<li> <p> The smtpd(8) server implements the SMTP over TLS server 82side. </p> 83 84<li> <p> The smtp(8) client implements the SMTP over TLS client 85side. </p> 86 87<li> <p> The tlsmgr(8) server maintains the pseudo-random number 88generator (PRNG) that seeds the TLS engines in the smtpd(8) server 89and smtp(8) client processes, and maintains the TLS session key 90cache files. </p> 91 92</ul> 93 94<table> 95 96<tr> <td>Network<tt>-> </tt> </td> <td align="center" 97bgcolor="#f0f0ff"> <br> <a href="smtpd.8.html">smtpd(8)</a> <br> </td> <td colspan="2"> 98 99<tt> <---seed---<br><br><-session-> </tt> </td> <td 100align="center" bgcolor="#f0f0ff"> <br> <a href="tlsmgr.8.html">tlsmgr(8)</a> <br> </td> 101<td colspan="3"> <tt> ---seed---><br> <br><-session-> 102 103</tt> </td> <td align="center" bgcolor="#f0f0ff"> <br> <a href="smtp.8.html">smtp(8)</a> <br> 104 </td> <td> <tt> -></tt>Network </td> </tr> 105 106<tr> <td colspan="3"> </td> <td align="right"> <table> <tr> <td> 107 108</td> <td> / </td> </tr> <tr> <td> / </td> <td> </td> </tr> </table> 109</td> <td align="center"> |<br> |</td> <td align="left"> <table> 110 111<tr> <td> \ </td> <td> </td> </tr> <tr> <td> </td> <td> \ </td> 112</tr> </table> </td> <td colspan="3"> </td> </tr> 113 114<tr> <td colspan="2"> </td> <td align="center" bgcolor="#f0f0ff"> 115smtpd<br> session<br> key cache </td> <td> </td> <td align="center" 116bgcolor="#f0f0ff"> PRNG<br> state <br>file </td> <td> </td> <td 117align="center" bgcolor="#f0f0ff"> smtp<br> session<br> key cache 118</td> 119 120<td colspan="2"> </td> </tr> 121 122</table> 123 124<h2><a name="build_tls">Building Postfix with TLS support</a></h2> 125 126<p> To build Postfix with TLS support, first we need to generate 127the <tt>make(1)</tt> files with the necessary definitions. This is 128done by invoking the command "<tt>make makefiles</tt>" in the Postfix 129top-level directory and with arguments as shown next. </p> 130 131<p> <b> NOTE: Do not use Gnu TLS. It will spontaneously terminate 132a Postfix daemon process with exit status code 2, instead of allowing 133Postfix to 1) report the error to the maillog file, and to 2) provide 134plaintext service where this is appropriate. </b> </p> 135 136<ul> 137 138<li> <p> If the OpenSSL include files (such as <tt>ssl.h</tt>) are 139in directory <tt>/usr/include/openssl</tt>, and the OpenSSL libraries 140(such as <tt>libssl.so</tt> and <tt>libcrypto.so</tt>) are in 141directory <tt>/usr/lib</tt>: </p> 142 143<blockquote> 144<pre> 145% <b>make tidy</b> # if you have left-over files from a previous build 146% <b>make makefiles CCARGS="-DUSE_TLS" AUXLIBS="-lssl -lcrypto"</b> 147</pre> 148</blockquote> 149 150<li> <p> If the OpenSSL include files (such as <tt>ssl.h</tt>) are 151in directory <tt>/usr/local/include/openssl</tt>, and the OpenSSL 152libraries (such as <tt>libssl.so</tt> and <tt>libcrypto.so</tt>) 153are in directory <tt>/usr/local/lib</tt>: </p> 154 155<blockquote> 156<pre> 157% <b>make tidy</b> # if you have left-over files from a previous build 158% <b>make makefiles CCARGS="-DUSE_TLS -I/usr/local/include" \ 159 AUXLIBS="-L/usr/local/lib -lssl -lcrypto" </b> 160</pre> 161</blockquote> 162 163<p> On Solaris, specify the <tt>-R</tt> option as shown below: 164 165<blockquote> 166<pre> 167% <b>make tidy</b> # if you have left-over files from a previous build 168% <b>make makefiles CCARGS="-DUSE_TLS -I/usr/local/include" \ 169 AUXLIBS="-R/usr/local/lib -L/usr/local/lib -lssl -lcrypto" </b> 170</pre> 171</blockquote> 172 173</ul> 174 175<p> If you need to apply other customizations (such as Berkeley DB 176databases, MySQL, PosgreSQL, LDAP or SASL), see the respective 177Postfix README documents, and combine their "<tt>make makefiles</tt>" 178instructions with the instructions above: </p> 179 180<blockquote> 181<pre> 182% <b>make tidy</b> # if you have left-over files from a previous build 183% <b>make makefiles CCARGS="-DUSE_TLS \ 184 <i>(other -D or -I options)</i>" \ 185 AUXLIBS="-lssl -lcrypto \ 186 <i>(other -l options for libraries in /usr/lib)</i> \ 187 <i>(-L/path/name + -l options for other libraries)</i>"</b> 188</pre> 189</blockquote> 190 191<p> To complete the build process, see the Postfix INSTALL 192instructions. Postfix has TLS support turned off by default, so 193you can start using Postfix as soon as it is installed. </p> 194 195<h2><a name="server_tls">SMTP Server specific settings</a></h2> 196 197<p> Topics covered in this section: </p> 198 199<ul> 200 201<li><a href="#server_cert_key">Server-side certificate and private 202key configuration </a> 203 204<li><a href="#server_logging"> Server-side TLS activity logging 205</a> 206 207<li><a href="#server_enable">Enabling TLS in the Postfix SMTP server </a> 208 209<li><a href="#server_vrfy_client">Client certificate verification</a> 210 211<li><a href="#server_tls_auth">Supporting AUTH over TLS only</a> 212 213<li><a href="#server_tls_cache">Server-side TLS session cache</a> 214 215<li><a href="#server_access">Server access control</a> 216 217<li><a href="#server_cipher">Server-side cipher controls</a> 218 219<li><a href="#server_misc"> Miscellaneous server controls</a> 220 221</ul> 222 223<h3><a name="server_cert_key">Server-side certificate and private 224key configuration </a> </h3> 225 226<p> In order to use TLS, the Postfix SMTP server needs a certificate 227and a private key. Both must be in "pem" format. The private key 228must not be encrypted, meaning: the key must be accessible without 229a password. Both certificate and private key may be in the same 230file. </p> 231 232<p> Both RSA and DSA certificates are supported. Typically you will 233only have RSA certificates issued by a commercial CA. In addition, 234the tools supplied with OpenSSL will by default issue RSA certificates. 235You can have both at the same time, in which case the cipher used 236determines which certificate is presented. For Netscape and OpenSSL 237clients without special cipher choices, the RSA certificate is 238preferred. </p> 239 240<p> In order for remote SMTP clients to check the Postfix SMTP 241server certificates, the CA certificate (in case of a certificate 242chain, all CA certificates) must be available. You should add 243these certificates to the server certificate, the server certificate 244first, then the issuing CA(s). </p> 245 246<p> Example: the certificate for "server.dom.ain" was issued by 247"intermediate CA" which itself has a certificate issued by "root 248CA". Create the server.pem file with: </p> 249 250<blockquote> 251<pre> 252% <b>cat server_cert.pem intermediate_CA.pem > server.pem</b> 253</pre> 254</blockquote> 255 256<p> A Postfix SMTP server certificate supplied here must be usable 257as an SSL server certificate and hence pass the "openssl verify -purpose 258sslserver ..." test. </p> 259 260<p> A client that trusts the root CA has a local copy of the root 261CA certificate, so it is not necessary to include the root CA 262certificate here. Leaving it out of the "server.pem" file reduces 263the overhead of the TLS exchange. </p> 264 265<p> If you want the Postfix SMTP server to accept remote SMTP client 266certificates issued by these CAs, append the root certificate to 267$smtpd_tls_CAfile or install it in the $smtpd_tls_CApath directory. When 268you configure trust in a root CA, it is not necessary to explicitly trust 269intermediary CAs signed by the root CA, unless $smtpd_tls_ccert_verifydepth 270is less than the number of CAs in the certificate chain for the clients 271of interest. With a verify depth of 1 you can only verify certificates 272directly signed by a trusted CA, and all trusted intermediary CAs need to 273be configured explicitly. With a verify depth of 2 you can verify clients 274signed by a root CA or a direct intermediary CA (so long as the client 275is correctly configured to supply its intermediate CA certificate). </p> 276 277<p> RSA key and certificate examples: </p> 278 279<blockquote> 280<pre> 281/etc/postfix/main.cf: 282 smtpd_tls_cert_file = /etc/postfix/server.pem 283 smtpd_tls_key_file = $smtpd_tls_cert_file 284</pre> 285</blockquote> 286 287<p> Their DSA counterparts: </p> 288 289<blockquote> 290<pre> 291/etc/postfix/main.cf: 292 smtpd_tls_dcert_file = /etc/postfix/server-dsa.pem 293 smtpd_tls_dkey_file = $smtpd_tls_dcert_file 294</pre> 295</blockquote> 296 297<p> To verify a remote SMTP client certificate, the Postfix SMTP 298server needs to trust the certificates of the issuing Certification 299Authorities. These certificates in "pem" format can be stored in a 300single $smtpd_tls_CAfile or in multiple files, one CA per file in 301the $smtpd_tls_CApath directory. If you use a directory, don't forget 302to create the necessary "hash" links with: </p> 303 304<blockquote> 305<pre> 306# <b>$OPENSSL_HOME/bin/c_rehash <i>/path/to/directory</i> </b> 307</pre> 308</blockquote> 309 310<p> The $smtpd_tls_CAfile contains the CA certificates of one or 311more trusted CAs. The file is opened (with root privileges) before 312Postfix enters the optional chroot jail and so need not be accessible 313from inside the chroot jail. </p> 314 315<p> Additional trusted CAs can be specified via the $smtpd_tls_CApath 316directory, in which case the certificates are read (with $mail_owner 317privileges) from the files in the directory when the information 318is needed. Thus, the $smtpd_tls_CApath directory needs to be 319accessible inside the optional chroot jail. </p> 320 321<p> When you configure Postfix to request client certificates (by 322setting $smtpd_tls_ask_ccert = yes), any certificates in 323$smtpd_tls_CAfile are sent to the client, in order to allow it to 324choose an identity signed by a CA you trust. If no $smtpd_tls_CAfile 325is specified, no preferred CA list is sent, and the client is free 326to choose an identity signed by any CA. Many clients use a fixed 327identity regardless of the preferred CA list and you may be able 328to reduce TLS negotiation overhead by installing client CA certificates 329mostly or only in $smtpd_tls_CApath. In the latter case you need 330not specify a $smtpd_tls_CAfile. </p> 331 332<p> Note, that unless client certificates are used to allow greater 333access to TLS authenticated clients, it is best to not ask for 334client certificates at all, as in addition to increased overhead 335some clients (notably in some cases qmail) are unable to complete 336the TLS handshake when client certificates are requested. </p> 337 338<p> Example: </p> 339<blockquote> 340<pre> 341/etc/postfix/main.cf: 342 smtpd_tls_CAfile = /etc/postfix/CAcert.pem 343 smtpd_tls_CApath = /etc/postfix/certs 344</pre> 345</blockquote> 346 347<h3><a name="server_logging"> Server-side TLS activity logging </a> </h3> 348 349<p> To get additional information about Postfix SMTP server TLS 350activity you can increase the loglevel from 0..4. Each logging 351level also includes the information that is logged at a lower 352logging level. </p> 353 354<blockquote> 355 356<table> 357 358<tr> <td> 0 </td> <td> Disable logging of TLS activity.</td> </tr> 359 360<tr> <td> 1 </td> <td> Log TLS handshake and certificate information. 361</td> </tr> 362 363<tr> <td> 2 </td> <td> Log levels during TLS negotiation. </td> 364</tr> 365 366<tr> <td> 3 </td> <td> Log hexadecimal and ASCII dump of TLS 367negotiation process </td> </tr> 368 369<tr> <td> 4 </td> <td> Log hexadecimal and ASCII dump of complete 370transmission after STARTTLS </td> </tr> 371 372</table> 373 374</blockquote> 375 376<p> Use loglevel 3 only in case of problems. Use of loglevel 4 is 377strongly discouraged. </p> 378 379<p> Example: </p> 380 381<blockquote> 382<pre> 383/etc/postfix/main.cf: 384 smtpd_tls_loglevel = 0 385</pre> 386</blockquote> 387 388<p> To include information about the protocol and cipher used as 389well as the client and issuer CommonName into the "Received:" 390message header, set the smtpd_tls_received_header variable to true. 391The default is no, as the information is not necessarily authentic. 392Only information recorded at the final destination is reliable, 393since the headers may be changed by intermediate servers. </p> 394 395<p> Example: </p> 396 397<blockquote> 398<pre> 399/etc/postfix/main.cf: 400 smtpd_tls_received_header = yes 401</pre> 402</blockquote> 403 404<h3><a name="server_enable">Enabling TLS in the Postfix SMTP server </a> </h3> 405 406<p> By default, TLS is disabled in the Postfix SMTP server, so no 407difference to plain Postfix is visible. Explicitly switch it on 408using "smtpd_use_tls = yes". </p> 409 410<p> Example: </p> 411 412<blockquote> 413<pre> 414/etc/postfix/main.cf: 415 smtpd_use_tls = yes 416</pre> 417</blockquote> 418 419<p> With this, Postfix SMTP server announces STARTTLS support to 420SMTP clients, but does not require that clients use TLS encryption. 421</p> 422 423<p> Note: when an unprivileged user invokes "sendmail -bs", STARTTLS 424is never offered due to insufficient privileges to access the server 425private key. This is intended behavior. </p> 426 427<p> You can ENFORCE the use of TLS, so that the Postfix SMTP server 428announces STARTTLS and accepts no mail without TLS encryption, by 429setting "smtpd_enforce_tls = yes". According to RFC 2487 this MUST 430NOT be applied in case of a publicly-referenced Postfix SMTP server. 431This option is off by default and should only seldom be used. </p> 432 433<p> Example: </p> 434 435<blockquote> 436<pre> 437/etc/postfix/main.cf: 438 smtpd_enforce_tls = yes 439</pre> 440</blockquote> 441 442<p> TLS is sometimes used in the non-standard "wrapper" mode where 443a server always uses TLS, instead of announcing STARTTLS support 444and waiting for clients to request TLS service. Some clients, namely 445Outlook [Express] prefer the "wrapper" mode. This is true for OE 446(Win32 < 5.0 and Win32 >=5.0 when run on a port<>25 447and OE (5.01 Mac on all ports). </p> 448 449<p> It is strictly discouraged to use this mode from main.cf. If 450you want to support this service, enable a special port in master.cf 451and specify "-o smtpd_tls_wrappermode = yes" as an smtpd(8) command 452line option. Port 465 (smtps) was once chosen for this feature. 453</p> 454 455<p> Example: </p> 456 457<blockquote> 458<pre> 459/etc/postfix/master.cf: 460 smtps inet n - n - - smtpd 461 -o smtpd_tls_wrappermode=yes -o smtpd_sasl_auth_enable=yes 462</pre> 463</blockquote> 464 465<h3><a name="server_vrfy_client">Client certificate verification</a> </h3> 466 467<p> To receive a remote SMTP client certificate, the Postfix SMTP 468server must explicitly ask for one (any contents of $smtpd_tls_CAfile 469are also sent to the client as a hint for choosing a certificate 470from a suitable CA). Unfortunately, Netscape clients will either 471complain if no matching client certificate is available or will 472offer the user client a list of certificates to choose from. 473Additionally some MTAs (notably some versions of qmail) are unable 474to complete TLS negotiation when client certificates are requested, 475and abort the SMTP session. So this option is "off" by default. 476You will however need the certificate if you want to use certificate 477based relaying with, for example, the permit_tls_clientcerts 478feature. </p> 479 480<p> Example: </p> 481 482<blockquote> 483<pre> 484/etc/postfix/main.cf: 485 smtpd_tls_ask_ccert = no 486</pre> 487</blockquote> 488 489<p> You may also decide to REQUIRE a remote SMTP client certificate 490before allowing TLS connections. This feature is included for 491completeness, and implies "smtpd_tls_ask_ccert = yes". </p> 492 493<p> Please be aware, that this will inhibit TLS connections without 494a proper client certificate and that it makes sense only when 495non-TLS submission is disabled (smtpd_enforce_tls = yes). Otherwise, 496clients could bypass the restriction by simply not using STARTTLS 497at all. </p> 498 499<p> When TLS is not enforced, the connection will be handled as 500if only "smtpd_tls_ask_ccert = yes" is specified, and a warning is 501logged. </p> 502 503<p> Example: </p> 504 505<blockquote> 506<pre> 507/etc/postfix/main.cf: 508 smtpd_tls_req_ccert = no 509</pre> 510</blockquote> 511 512<p> A client certificate verification depth of 1 is sufficient if 513the certificate is directly issued by a CA listed in the CA file. 514The default value (5) should also suffice for longer chains (root 515CA issues special CA which then issues the actual certificate...) 516</p> 517 518<p> Example: </p> 519 520<blockquote> 521<pre> 522/etc/postfix/main.cf: 523 smtpd_tls_ccert_verifydepth = 5 524</pre> 525</blockquote> 526 527<h3><a name="server_tls_auth">Supporting AUTH over TLS only</a></h3> 528 529<p> Sending AUTH data over an unencrypted channel poses a security 530risk. When TLS layer encryption is required (smtpd_enforce_tls = 531yes), the Postfix SMTP server will announce and accept AUTH only 532after the TLS layer has been activated with STARTTLS. When TLS 533layer encryption is optional (smtpd_enforce_tls = no), it may 534however still be useful to only offer AUTH when TLS is active. To 535maintain compatibility with non-TLS clients, the default is to 536accept AUTH without encryption. In order to change this behavior, 537set "smtpd_tls_auth_only = yes". </p> 538 539<p> Example: </p> 540 541<blockquote> 542<pre> 543/etc/postfix/main.cf: 544 smtpd_tls_auth_only = no 545</pre> 546</blockquote> 547 548<h3><a name="server_tls_cache">Server-side TLS session cache</a> </h3> 549 550<p> The Postfix SMTP server and the remote SMTP client negotiate 551a session, which takes some computer time and network bandwidth. 552By default, this session information is cached only in the smtpd(8) 553process actually using this session and is lost when the process 554terminates. To share the session information between multiple 555smtpd(8) processes, a persistent session cache can be used. You 556can specify any database type that can store objects of several 557kbytes and that supports the sequence operator. DBM databases are 558not suitable because they can only store small objects. The cache 559is maintained by the tlsmgr(8) process, so there is no problem with 560concurrent access. Session caching is highly recommended, because 561the cost of repeatedly negotiating TLS session keys is high.</p> 562 563<p> Example: </p> 564 565<blockquote> 566<pre> 567/etc/postfix/main.cf: 568 smtpd_tls_session_cache_database = btree:/etc/postfix/smtpd_scache 569</pre> 570</blockquote> 571 572<p> As of version 2.5, Postfix will no longer maintain this file 573in a directory with non-Postfix ownership. As a migration aid, 574attempts to open such files are redirected to the Postfix-owned 575$data_directory, and a warning is logged. </p> 576 577<p> Cached Postfix SMTP server session information expires after 578a certain amount of time. Postfix/TLS does not use the OpenSSL 579default of 300s, but a longer time of 3600sec (=1 hour). RFC 2246 580recommends a maximum of 24 hours. </p> 581 582<p> Example: </p> 583 584<blockquote> 585<pre> 586/etc/postfix/main.cf: 587 smtpd_tls_session_cache_timeout = 3600s 588</pre> 589</blockquote> 590 591<h3><a name="server_access">Server access control</a> </h3> 592 593<p> Postfix TLS support introduces three additional features for 594Postfix SMTP server access control: </p> 595 596<blockquote> 597 598<dl> 599 600<dt> permit_tls_clientcerts </dt> <dd> <p> Allow the remote SMTP 601client SMTP request if the client certificate passes verification, 602and if its fingerprint is listed in the list of client certificates 603(see relay_clientcerts discussion below). </p> </dd> 604 605<dt> permit_tls_all_clientcerts </dt> <dd> <p> Allow the remote 606client SMTP request if the client certificate passes verification. 607</p> </dd> 608 609<dt> check_ccert_access type:table</dt> <dd> 610<p> If the client certificate passes verification, use its fingerprint 611as a key for the specified access(5) table. </p> </dd> 612 613</dl> 614 615</blockquote> 616 617<p> The permit_tls_all_clientcerts feature must be used with caution, 618because it can result in too many access permissions. Use this 619feature only if a special CA issues the client certificates, and 620only if this CA is listed as a trusted CA. If other CAs are trusted, 621any owner of a valid client certificate would be authorized. 622The permit_tls_all_clientcerts feature can be practical for a 623specially created email relay server. </p> 624 625<p> It is however recommended to stay with the permit_tls_clientcerts 626feature and list all certificates via $relay_clientcerts, as 627permit_tls_all_clientcerts does not permit any control when a 628certificate must no longer be used (e.g. an employee leaving). </p> 629 630<p> Example: </p> 631 632<blockquote> 633<pre> 634/etc/postfix/main.cf: 635 smtpd_recipient_restrictions = 636 ... 637 permit_tls_clientcerts 638 reject_unauth_destination 639 ... 640</pre> 641</blockquote> 642 643<p> The Postfix list manipulation routines give special treatment 644to whitespace and some other characters, making the use of certificate 645names impractical. Instead we use the certificate fingerprints as 646they are difficult to fake but easy to use for lookup. Postfix 647lookup tables are in the form of (key, value) pairs. Since we only 648need the key, the value can be chosen freely, e.g. the name of 649the user or host.</p> 650 651<p> Example: </p> 652 653<blockquote> 654<pre> 655/etc/postfix/main.cf: 656 relay_clientcerts = hash:/etc/postfix/relay_clientcerts 657 658/etc/postfix/relay_clientcerts: 659 D7:04:2F:A7:0B:8C:A5:21:FA:31:77:E1:41:8A:EE:80 lutzpc.at.home 660</pre> 661</blockquote> 662 663<h3><a name="server_cipher">Server-side cipher controls</a> </h3> 664 665<p> To influence the Postfix SMTP server cipher selection scheme, 666you can give cipherlist string. A detailed description would go 667too far here; please refer to the OpenSSL documentation. If you 668don't know what to do with it, simply don't touch it and leave the 669(openssl-)compiled in default! </p> 670 671<p> DO NOT USE " to enclose the string, specify just the string!!! </p> 672 673<p> Example: </p> 674 675<blockquote> 676<pre> 677/etc/postfix/main.cf: 678 smtpd_tls_cipherlist = DEFAULT 679</pre> 680</blockquote> 681 682<p> If you want to take advantage of ciphers with EDH, DH parameters 683are needed. Instead of using the built-in DH parameters for both 6841024bit and 512bit, it is better to generate "own" parameters, 685since otherwise it would "pay" for a possible attacker to start a 686brute force attack against parameters that are used by everybody. 687For this reason, the parameters chosen are already different from 688those distributed with other TLS packages. </p> 689 690<p> To generate your own set of DH parameters, use: </p> 691 692<blockquote> 693<pre> 694% <b>openssl gendh -out /etc/postfix/dh_1024.pem -2 -rand /var/run/egd-pool 1024</b> 695% <b>openssl gendh -out /etc/postfix/dh_512.pem -2 -rand /var/run/egd-pool 512</b> 696</pre> 697</blockquote> 698 699<p> Examples: </p> 700 701<blockquote> 702<pre> 703/etc/postfix/main.cf: 704 smtpd_tls_dh1024_param_file = /etc/postfix/dh_1024.pem 705 smtpd_tls_dh512_param_file = /etc/postfix/dh_512.pem 706</pre> 707</blockquote> 708 709<h3><a name="server_misc"> Miscellaneous server controls</a> </h3> 710 711<p> The smtpd_starttls_timeout parameter limits the time of Postfix 712SMTP server write and read operations during TLS startup and shutdown 713handshake procedures. </p> 714 715<p> Example: </p> 716 717<blockquote> 718<pre> 719/etc/postfix/main.cf: 720 smtpd_starttls_timeout = 300s 721</pre> 722</blockquote> 723 724<h2> <a name="client_tls">SMTP Client specific settings</a> </h2> 725 726<p> Topics covered in this section: </p> 727 728<ul> 729 730<li><a href="#client_cert_key">Client-side certificate and private 731key configuration </a> 732 733<li><a href="#client_logging"> Client-side TLS activity logging 734</a> 735 736<li><a href="#client_tls_cache">Client-side TLS session cache</a> 737 738<li><a href="#client_tls_enable"> Enabling TLS in the Postfix SMTP client </a> 739 740<li><a href="#client_tls_require"> Requiring TLS encryption </a> 741 742<li><a href="#client_tls_nopeer"> Disabling server certificate verification </a> 743 744<li><a href="#client_tls_per_site"> Per-site TLS policies </a> 745 746<!-- 747<li><a href="#client_tls_obs"> Obsolete per-site TLS policy support </a> 748--> 749 750<li><a href="#client_tls_harden"> Closing a DNS loophole with <!-- legacy --> per-site TLS policies </a> 751 752<li><a href="#client_tls_discover"> Discovering servers that support TLS </a> 753 754<li><a href="#client_vrfy_server">Server certificate verification depth</a> 755 756<li> <a href="#client_cipher">Client-side cipher controls </a> 757 758<li> <a href="#client_misc"> Miscellaneous client controls </a> 759 760</ul> 761 762<h3><a name="client_cert_key">Client-side certificate and private 763key configuration </a> </h3> 764 765<p> During TLS startup negotiation the Postfix SMTP client may present 766a certificate to the remote SMTP server. The Netscape client is 767rather clever here and lets the user select between only those 768certificates that match CA certificates offered by the remote SMTP 769server. As the Postfix SMTP client uses the "SSL_connect()" function 770from the OpenSSL package, this is not possible and we have to choose 771just one certificate. So for now the default is to use _no_ 772certificate and key unless one is explicitly specified here. </p> 773 774<p> Both RSA and DSA certificates are supported. You can have both 775at the same time, in which case the cipher used determines which 776certificate is presented. </p> 777 778<p> It is possible for the Postfix SMTP client to use the same 779key/certificate pair as the Postfix SMTP server. If a certificate 780is to be presented, it must be in "pem" format. The private key 781must not be encrypted, meaning: it must be accessible without 782a password. Both parts (certificate and private key) may be in the 783same file. </p> 784 785<p> In order for remote SMTP servers to verify the Postfix SMTP 786client certificates, the CA certificate (in case of a certificate 787chain, all CA certificates) must be available. You should add 788these certificates to the client certificate, the client certificate 789first, then the issuing CA(s). </p> 790 791<p> Example: the certificate for "client.example.com" was issued by 792"intermediate CA" which itself has a certificate of "root CA". 793Create the client.pem file with: </p> 794 795<blockquote> 796<pre> 797% <b>cat client_cert.pem intermediate_CA.pem > client.pem </b> 798</pre> 799</blockquote> 800 801<p> A Postfix SMTP client certificate supplied here must be usable 802as an SSL client certificate and hence pass the "openssl verify -purpose 803sslclient ..." test. </p> 804 805<p> A server that trusts the root CA has a local copy of the root 806CA certificate, so it is not necessary to include the root CA 807certificate here. Leaving it out of the "client.pem" file reduces 808the overhead of the TLS exchange. </p> 809 810<p> If you want the Postfix SMTP client to accept remote SMTP server 811certificates issued by these CAs, append the root certificate to 812$smtp_tls_CAfile or install it in the $smtp_tls_CApath directory. When 813you configure trust in a root CA, it is not necessary to explicitly trust 814intermediary CAs signed by the root CA, unless $smtp_tls_scert_verifydepth 815is less than the number of CAs in the certificate chain for the servers 816of interest. With a verify depth of 1 you can only verify certificates 817directly signed by a trusted CA, and all trusted intermediary CAs need to 818be configured explicitly. With a verify depth of 2 you can verify servers 819signed by a root CA or a direct intermediary CA (so long as the server 820is correctly configured to supply its intermediate CA certificate). </p> 821 822<p> RSA key and certificate examples: </p> 823 824<blockquote> 825<pre> 826/etc/postfix/main.cf: 827 smtp_tls_cert_file = /etc/postfix/client.pem 828 smtp_tls_key_file = $smtp_tls_cert_file 829</pre> 830</blockquote> 831 832<p> Their DSA counterparts: </p> 833 834<blockquote> 835<pre> 836/etc/postfix/main.cf: 837 smtp_tls_dcert_file = /etc/postfix/client-dsa.pem 838 smtp_tls_dkey_file = $smtp_tls_dcert_file 839</pre> 840</blockquote> 841 842<p> To verify a remote SMTP server certificate, the Postfix SMTP 843client needs to trust the certificates of the issuing Certification 844Authorities. These certificates in "pem" format can be stored in a 845single $smtp_tls_CAfile or in multiple files, one CA per file in 846the $smtp_tls_CApath directory. If you use a directory, don't forget 847to create the necessary "hash" links with: </p> 848 849<blockquote> 850<pre> 851# <b>$OPENSSL_HOME/bin/c_rehash <i>/path/to/directory</i> </b> 852</pre> 853</blockquote> 854 855<p> The $smtp_tls_CAfile contains the CA certificates of one or more 856trusted CAs. The file is opened (with root privileges) before Postfix 857enters the optional chroot jail and so need not be accessible from inside the 858chroot jail. </p> 859 860<p> Additional trusted CAs can be specified via the $smtp_tls_CApath 861directory, in which case the certificates are read (with $mail_owner 862privileges) from the files in the directory when the information 863is needed. Thus, the $smtp_tls_CApath directory needs to be accessible 864inside the optional chroot jail. </p> 865 866<p> The choice between $smtp_tls_CAfile and $smtp_tls_CApath is 867a space/time tradeoff. If there are many trusted CAs, the cost of 868preloading them all into memory may not pay off in reduced access time 869when the certificate is needed. </p> 870 871<p> Example: </p> 872 873<blockquote> 874<pre> 875/etc/postfix/main.cf: 876 smtp_tls_CAfile = /etc/postfix/CAcert.pem 877 smtp_tls_CApath = /etc/postfix/certs 878</pre> 879</blockquote> 880 881<h3><a name="client_logging"> Client-side TLS activity logging </a> </h3> 882 883<p> To get additional information about Postfix SMTP client TLS 884activity you can increase the loglevel from 0..4. Each logging 885level also includes the information that is logged at a lower 886logging level. </p> 887 888<blockquote> 889 890<table> 891 892<tr> <td> 0 </td> <td> Disable logging of TLS activity.</td> </tr> 893 894<tr> <td> 1 </td> <td> Log TLS handshake and certificate information. 895</td> </tr> 896 897<tr> <td> 2 </td> <td> Log levels during TLS negotiation. </td> 898</tr> 899 900<tr> <td> 3 </td> <td> Log hexadecimal and ASCII dump of TLS 901negotiation process </td> </tr> 902 903<tr> <td> 4 </td> <td> Log hexadecimal and ASCII dump of complete 904transmission after STARTTLS </td> </tr> 905 906</table> 907 908</blockquote> 909 910<p> Example: </p> 911 912<blockquote> 913<pre> 914/etc/postfix/main.cf: 915 smtp_tls_loglevel = 0 916</pre> 917</blockquote> 918 919<h3><a name="client_tls_cache">Client-side TLS session cache</a> </h3> 920 921<p> The remote SMTP server and the Postfix SMTP client negotiate a 922session, which takes some computer time and network bandwidth. By 923default, this session information is cached only in the smtp(8) 924process actually using this session and is lost when the process 925terminates. To share the session information between multiple 926smtp(8) processes, a persistent session cache can be used. You 927can specify any database type that can store objects of several 928kbytes and that supports the sequence operator. DBM databases are 929not suitable because they can only store small objects. The cache 930is maintained by the tlsmgr(8) process, so there is no problem with 931concurrent access. Session caching is highly recommended, because 932the cost of repeatedly negotiating TLS session keys is high. Future 933Postfix SMTP servers may limit the number of sessions that a client 934is allowed to negotiate per unit time.</p> 935 936 937<p> Example: </p> 938 939<blockquote> 940<pre> 941/etc/postfix/main.cf: 942 smtp_tls_session_cache_database = btree:/etc/postfix/smtp_scache 943</pre> 944</blockquote> 945 946<p> As of version 2.5, Postfix will no longer maintain this file 947in a directory with non-Postfix ownership. As a migration aid, 948attempts to open such files are redirected to the Postfix-owned 949$data_directory, and a warning is logged. </p> 950 951<p> Cached Postfix SMTP client session information expires after 952a certain amount of time. Postfix/TLS does not use the OpenSSL 953default of 300s, but a longer time of 3600s (=1 hour). RFC 2246 954recommends a maximum of 24 hours. </p> 955 956<p> Example: </p> 957 958<blockquote> 959<pre> 960/etc/postfix/main.cf: 961 smtp_tls_session_cache_timeout = 3600s 962</pre> 963</blockquote> 964 965<h3><a name="client_tls_enable"> Enabling TLS in the Postfix SMTP 966client </a> </h3> 967 968<p> By default, TLS is disabled in the Postfix SMTP client, so no 969difference to plain Postfix is visible. If you enable TLS, the 970Postfix SMTP client will send STARTTLS when TLS support is announced 971by the remote SMTP server. </p> 972 973<p> When the server accepts the STARTTLS command, but the subsequent 974TLS handshake fails, and no other server is available, the Postfix SMTP 975client defers the delivery attempt, and the mail stays in the queue. After 976a handshake failure, the communications channel is in an indeterminate 977state and cannot be used for non-TLS deliveries. </p> 978 979<p> Example: </p> 980 981<blockquote> 982<pre> 983/etc/postfix/main.cf: 984 smtp_use_tls = yes 985</pre> 986</blockquote> 987 988<h3><a name="client_tls_require"> Requiring TLS encryption </a> 989</h3> 990 991<p> You can ENFORCE the use of TLS, so that the Postfix SMTP client 992will not deliver mail over unencrypted connections. In this mode, 993the remote SMTP server hostname must match the information in the 994remote server certificate, and the server certificate must be issued 995by a CA that is trusted by the Postfix SMTP client. If the remote 996server certificate doesn't verify or the remote SMTP server hostname 997doesn't match, and no other server is available, the delivery 998attempt is deferred and the mail stays in the queue. </p> 999 1000<p> The remote SMTP server hostname is verified against all names 1001provided as dNSNames 1002in the SubjectAlternativeName. If no dNSNames are specified, the 1003CommonName is checked. Verification may be turned off with the 1004smtp_tls_enforce_peername option which is discussed below. </p> 1005 1006<p> Enforcing the use of TLS is useful if you know that you will 1007only 1008connect to servers that support RFC 2487 _and_ that present server 1009certificates that meet the above requirements. An example would 1010be a client only sends email to one specific mailhub that offers 1011the necessary STARTTLS support. </p> 1012 1013<p> Example: </p> 1014 1015<blockquote> 1016<pre> 1017/etc/postfix/main.cf: 1018 smtp_enforce_tls = yes 1019</pre> 1020</blockquote> 1021 1022<h3> <a name="client_tls_nopeer"> Disabling server certificate 1023verification </a> </h3> 1024 1025<p> As of RFC 2487 the requirements for hostname checking for MTA 1026clients are not set. When TLS is required (smtp_enforce_tls = yes), 1027the option smtp_tls_enforce_peername can be set to "no" to disable 1028strict remote SMTP server hostname checking. In this case, the mail 1029delivery will proceed regardless of the CommonName etc. listed in 1030the certificate. </p> 1031 1032<p> Despite the potential for eliminating "man-in-the-middle" and 1033other attacks, mandatory certificate/peername verification is not 1034viable as a default Internet mail delivery policy at this time. A 1035significant fraction of TLS enabled MTAs uses self-signed certificates, 1036or certificates that are signed by a private Certification Authority. 1037On a machine that delivers mail to the Internet, if you set 1038smtp_enforce_tls = yes, you should probably also set 1039smtp_tls_enforce_peername = no. You can use the per-site TLS 1040policies (see below) to enable full peer verification for specific 1041destinations that are known to have verifiable TLS server certificates. 1042</p> 1043 1044<p> Example: </p> 1045 1046<blockquote> 1047<pre> 1048/etc/postfix/main.cf: 1049 smtp_enforce_tls = yes 1050 smtp_tls_enforce_peername = no 1051</pre> 1052</blockquote> 1053 1054<h3> <a name="client_tls_per_site"> Per-site TLS policies </a> </h3> 1055 1056<p> A small fraction of servers offer STARTTLS but the negotiation 1057consistently fails, leading to mail aging out of the queue and 1058bouncing back to the sender. In such cases, you can use the per-site 1059policies to disable TLS for the problem sites. Alternatively, you 1060can enable TLS for just a few specific sites and not enable it for 1061all sites. </p> 1062 1063<!-- insert new-style TLS policy mechanism here 1064 1065<h3> <a name="client_tls_obs"> Obsolete per-site TLS policy support 1066</a> </h3> 1067 1068<p> This section describes an obsolete per-site TLS policy mechanism. 1069Unlike the newer mechanism it supports TLS policy lookup by server 1070hostname, and lacks control over what names can appear in server 1071certificates. Because of this, the obsolete mechanism is vulnerable 1072to false DNS hostname information in MX or CNAME records. These 1073attacks can be eliminated only with great difficulty. </p> 1074 1075--> 1076 1077<p> The smtp_tls_per_site table is searched for a policy that matches 1078the following information: </p> 1079 1080<blockquote> 1081 1082<dl> 1083 1084<dt> remote SMTP server hostname </dt> <dd> This is simply the DNS 1085name of the server that the Postfix SMTP client connects to; this 1086name may be obtained from other DNS lookups, such as MX lookups or 1087CNAME lookups. </dd> 1088 1089<dt> next-hop destination </dt> <dd> This is normally the domain 1090portion of the recipient address, but it may be overruled by 1091information from the transport(5) table, from the relayhost parameter 1092setting, or from the relay_transport setting. When it's not the 1093recipient domain, the next-hop destination can have the Postfix-specific 1094form "<tt>[name]</tt>", <tt>[name]:port</tt>", "<tt>name</tt>" or 1095"<tt>name:port</tt>". </dd> 1096 1097</dl> 1098 1099</blockquote> 1100 1101<p> When both the hostname lookup and the next-hop lookup succeed, 1102the host policy does not automatically override the next-hop policy. 1103Instead, precedence is given to either the more specific or the 1104more secure per-site policy as described below. </p> 1105 1106<p> The smtp_tls_per_site table uses a simple "<i>name whitespace 1107value</i>" format. Specify host names or next-hop destinations on 1108the left-hand side; no wildcards are allowed. On the right hand 1109side specify one of the following keywords: </p> 1110 1111<blockquote> 1112 1113<dl> 1114 1115<dt> NONE </dt> <dd> Don't use TLS at all. This overrides a less 1116specific <b>MAY</b> lookup result from the alternate host or next-hop 1117lookup key, and overrides the global smtp_use_tls, smtp_enforce_tls, 1118and smtp_tls_enforce_peername settings. </dd> 1119 1120<dt> MAY </dt> <dd> Try to use TLS if the server announces support, 1121otherwise use the unencrypted connection. This has less precedence 1122than a more specific result (including <b>NONE</b>) from the alternate 1123host or next-hop lookup key, and has less precedence than the more 1124specific global "smtp_enforce_tls = yes" or "smtp_tls_enforce_peername 1125= yes". </dd> 1126 1127<dt> MUST_NOPEERMATCH </dt> <dd> Require TLS encryption, but do not 1128require that the remote SMTP server hostname matches the information 1129in the remote SMTP server certificate, or that the server certificate 1130was issued by a trusted CA. This overrides a less secure <b>NONE</b> 1131or a less specific <b>MAY</b> lookup result from the alternate host 1132or next-hop lookup key, and overrides the global smtp_use_tls, 1133smtp_enforce_tls and smtp_tls_enforce_peername settings. </dd> 1134 1135<dt> MUST </dt> <dd> Require TLS encryption, require that the remote 1136SMTP server hostname matches the information in the remote SMTP 1137server certificate, and require that the remote SMTP server certificate 1138was issued by a trusted CA. This overrides a less secure <b>NONE</b> 1139and <b>MUST_NOPEERMATCH</b> or a less specific <b>MAY</b> lookup 1140result from the alternate host or next-hop lookup key, and overrides 1141the global smtp_use_tls, smtp_enforce_tls and smtp_tls_enforce_peername 1142settings. </dd> 1143 1144</dl> 1145 1146</blockquote> 1147 1148<p> The precedences between global (main.cf) and per-site TLS 1149policies can be summarized as follows: </p> 1150 1151<ul> 1152 1153<li> <p> When neither the remote SMTP server hostname nor the 1154next-hop destination are found in the smtp_tls_per_site table, the 1155policy is based on smtp_use_tls, smtp_enforce_tls and 1156smtp_tls_enforce_peername. Note: "smtp_enforce_tls = yes" and 1157"smtp_tls_enforce_peername = yes" imply "smtp_use_tls = yes". </p> 1158 1159<li> <p> When both hostname and next-hop destination lookups produce 1160a result, the more specific per-site policy (NONE, MUST, etc.) 1161overrides the less specific one (MAY), and the more secure per-site 1162policy (MUST, etc.) overrides the less secure one (NONE). </p> 1163 1164<li> <p> After the per-site policy lookups are combined, the result 1165generally overrides the global policy. The exception is the less 1166specific <b>MAY</b> per-site policy, which is overruled by the more 1167specific global "smtp_enforce_tls = yes" with server certificate 1168verification as specified with the smtp_tls_enforce_peername 1169parameter. </p> 1170 1171</ul> 1172 1173<h3> <a name="client_tls_harden"> Closing a DNS loophole with 1174<!-- legacy --> per-site TLS policies </a> </h3> 1175 1176<p> As long as no secure DNS lookup mechanism is available, false 1177hostnames in MX or CNAME responses can change the server hostname 1178that Postfix uses for TLS policy lookup and server certificate 1179verification. Even with a perfect match between the server hostname 1180and the server certificate, there is no guarantee that Postfix is 1181connected to the right server. To avoid this loophole take the 1182following steps: </p> 1183 1184<ul> 1185 1186<li> <p> Eliminate MX lookups. Specify local transport(5) table 1187entries for sensitive domains with explicit smtp:[<i>mailhost</i>] 1188or smtp:[<i>mailhost</i>]:<i>port</i> destinations (you can assure 1189security of this table unlike DNS); in the smtp_tls_per_site table 1190specify the value <b>MUST</b> for the key [<i>mailhost</i>] or 1191smtp:[<i>mailhost</i>]:<i>port</i>. This prevents false hostname 1192information in DNS MX records from changing the server hostname 1193that Postfix uses for TLS policy lookup and server certificate 1194verification. </p> 1195 1196<li> <p> Disallow CNAME hostname overrides. In main.cf specify 1197"smtp_cname_overrides_servername = no". This prevents false hostname 1198information in DNS CNAME records from changing the server hostname 1199that Postfix uses for TLS policy lookup and server certificate 1200verification. This feature requires Postfix 2.2.9 or later. </p> 1201 1202</ul> 1203 1204<p> Example: </p> 1205 1206<blockquote> <pre> 1207/etc/postfix/main.cf: 1208 smtp_tls_per_site = hash:/etc/postfix/tls_per_site 1209 relayhost = [msa.example.net]:587 1210 1211/etc/postfix/tls_per_site: 1212 # relayhost exact nexthop match 1213 [msa.example.net]:587 MUST 1214 1215 # TLS should not be used with the <i>example.org</i> MX hosts. 1216 example.org NONE 1217 1218 # TLS should not be used with the host <i>smtp.example.com</i>. 1219 [smtp.example.com] NONE 1220</pre> 1221</blockquote> 1222 1223<h3> <a name="client_tls_discover"> Discovering servers that support 1224TLS </a> </h3> 1225 1226<p> As we decide on a "per site" basis whether or not to use TLS, 1227it would be good to have a list of sites that offered "STARTTLS". 1228We can collect it ourselves with this option. </p> 1229 1230<p> If the smtp_tls_note_starttls_offer feature is enabled and a 1231server offers STARTTLS while TLS is not already enabled for that 1232server, the Postfix SMTP client logs a line as follows: </p> 1233 1234<blockquote> 1235<pre> 1236postfix/smtp[pid]: Host offered STARTTLS: [hostname.example.com] 1237</pre> 1238</blockquote> 1239 1240<p> Example: </p> 1241 1242<blockquote> 1243<pre> 1244/etc/postfix/main.cf: 1245 smtp_tls_note_starttls_offer = yes 1246</pre> 1247</blockquote> 1248 1249<h3><a name="client_vrfy_server">Server certificate verification depth</a> </h3> 1250 1251<p> When verifying a remote SMTP server certificate, a verification 1252depth of 1 is sufficient if the certificate is directly issued by 1253a CA specified with smtp_tls_CAfile or smtp_tls_CApath. The default 1254value of 5 should also suffice for longer chains (root CA issues 1255special CA which then issues the actual certificate...) </p> 1256 1257<p> Example: </p> 1258 1259<blockquote> 1260<pre> 1261/etc/postfix/main.cf: 1262 smtp_tls_scert_verifydepth = 5 1263</pre> 1264</blockquote> 1265 1266<h3> <a name="client_cipher">Client-side cipher controls </a> </h3> 1267 1268<p> To influence the Postfix SMTP client cipher selection scheme, 1269you can give cipherlist string. A detailed description would go 1270too far here; please refer to the OpenSSL documentation. If you 1271don't know what to do with it, simply don't touch it and leave the 1272(openssl-)compiled in default! </p> 1273 1274<p> DO NOT USE " to enclose the string, specify just the string!!! </p> 1275 1276<p> Example: </p> 1277 1278<blockquote> 1279<pre> 1280/etc/postfix/main.cf: 1281 smtp_tls_cipherlist = DEFAULT 1282</pre> 1283</blockquote> 1284 1285<h3> <a name="client_misc"> Miscellaneous client controls </a> </h3> 1286 1287<p> The smtp_starttls_timeout parameter limits the time of Postfix 1288SMTP client write and read operations during TLS startup and shutdown 1289handshake procedures. In case of problems the Postfix SMTP client 1290tries the next network address on the mail exchanger list, and 1291defers delivery if no alternative server is available. </p> 1292 1293<p> Example: </p> 1294 1295<blockquote> 1296<pre> 1297/etc/postfix/main.cf: 1298 smtp_starttls_timeout = 300s 1299</pre> 1300</blockquote> 1301 1302<h2><a name="tlsmgr_controls"> TLS manager specific settings </a> </h2> 1303 1304<p> The security of cryptographic software such as TLS depends 1305critically on the ability to generate unpredictable numbers for 1306keys and other information. To this end, the tlsmgr(8) process 1307maintains a Pseudo Random Number Generator (PRNG) pool. This is 1308queried by the smtp(8) and smtpd(8) processes when they initialize. 1309By default, these daemons request 32 bytes, the equivalent to 256 1310bits. This is more than sufficient to generate a 128bit (or 168bit) 1311session key. </p> 1312 1313<p> Example: </p> 1314 1315<blockquote> 1316<pre> 1317/etc/postfix/main.cf: 1318 tls_daemon_random_bytes = 32 1319</pre> 1320</blockquote> 1321 1322<p> In order to feed its in-memory PRNG pool, the tlsmgr(8) reads 1323entropy from an external source, both at startup and during run-time. 1324Specify a good entropy source, like EGD or /dev/urandom; be sure 1325to only use non-blocking sources (on OpenBSD, use /dev/arandom 1326when tlsmgr(8) complains about /dev/urandom timeout errors). 1327If the entropy source is not a 1328regular file, you must prepend the source type to the source name: 1329"dev:" for a device special file, or "egd:" for a source with EGD 1330compatible socket interface. </p> 1331 1332<p> Examples (specify only one in main.cf): </p> 1333 1334<blockquote> 1335<pre> 1336/etc/postfix/main.cf: 1337 tls_random_source = dev:/dev/urandom 1338 tls_random_source = egd:/var/run/egd-pool 1339</pre> 1340</blockquote> 1341 1342<p> By default, tlsmgr(8) reads 32 bytes from the external entropy 1343source at each seeding event. This amount (256bits) is more than 1344sufficient for generating a 128bit symmetric key. With EGD and 1345device entropy sources, the tlsmgr(8) limits the amount of data 1346read at each step to 255 bytes. If you specify a regular file as 1347entropy source, a larger amount of data can be read. </p> 1348 1349<p> Example: </p> 1350 1351<blockquote> 1352<pre> 1353/etc/postfix/main.cf: 1354 tls_random_bytes = 32 1355</pre> 1356</blockquote> 1357 1358<p> In order to update its in-memory PRNG pool, the tlsmgr(8) 1359queries the external entropy source again after a pseudo-random 1360amount of time. The time is calculated using the PRNG, and is 1361between 0 and the maximal time specified with tls_random_reseed_period. 1362The default maximal time interval is 1 hour. </p> 1363 1364<p> Example: </p> 1365 1366<blockquote> 1367<pre> 1368/etc/postfix/main.cf: 1369 tls_random_reseed_period = 3600s 1370</pre> 1371</blockquote> 1372 1373<p> The tlsmgr(8) process saves the PRNG state to a persistent 1374exchange file at regular times and when the process terminates, so 1375that it can recover the PRNG state the next time it starts up. 1376This file is created when it does not exist. Its default location 1377is under the Postfix configuration directory, which is not the 1378proper place for information that is modified by Postfix. Instead, 1379the file location should probably be on the /var partition (but 1380<b>not</b> inside the chroot jail). </p> 1381 1382<p> Examples: </p> 1383 1384<blockquote> 1385<pre> 1386/etc/postfix/main.cf: 1387 tls_random_exchange_name = /etc/postfix/prng_exch 1388 tls_random_prng_update_period = 3600s 1389</pre> 1390</blockquote> 1391 1392<h2><a name="quick-start">Getting started, quick and dirty</a></h2> 1393 1394<p> The following steps will get you started quickly. Because you 1395sign your own Postfix public key certificate, you get TLS encryption 1396but no TLS authentication. This is sufficient for testing, and 1397for exchanging email with sites that you have no trust relationship 1398with. For real authentication, your Postfix public key certificate 1399needs to be signed by a recognized Certification Authority, and 1400Postfix needs to be configured with a list of public key certificates 1401of Certification Authorities, so that Postfix can verify the public key 1402certificates of remote hosts. </p> 1403 1404<p> In the examples below, user input is shown in <b><tt>bold</tt></b> 1405font, and a "<tt>#</tt>" prompt indicates a super-user shell. </p> 1406 1407<ul> 1408 1409<li> <p> Become your own Certification Authority, so that you can 1410sign your own public keys. This example uses the CA.pl script that 1411ships with OpenSSL. By default, OpenSSL installs this as 1412<tt>/usr/local/ssl/misc/CA.pl</tt>, but your mileage may vary. 1413The script creates a private key in <tt>./demoCA/private/cakey.pem</tt> 1414and a public key in <tt>./demoCA/cacert.pem</tt>.</p> 1415 1416<blockquote> 1417<pre> 1418% <b>/usr/local/ssl/misc/CA.pl -newca</b> 1419CA certificate filename (or enter to create) 1420 1421Making CA certificate ... 1422Using configuration from /etc/ssl/openssl.cnf 1423Generating a 1024 bit RSA private key 1424....................++++++ 1425.....++++++ 1426writing new private key to './demoCA/private/cakey.pem' 1427Enter PEM pass phrase:<b>whatever</b> 1428</pre> 1429</blockquote> 1430 1431<li> <p> Create an unpassworded private key for host FOO and create 1432an unsigned public key certificate. </p> 1433 1434<blockquote> 1435<pre> 1436% <b>openssl req -new -nodes -keyout FOO-key.pem -out FOO-req.pem -days 365</b> 1437Using configuration from /etc/ssl/openssl.cnf 1438Generating a 1024 bit RSA private key 1439........................................++++++ 1440....++++++ 1441writing new private key to 'FOO-key.pem' 1442----- 1443You are about to be asked to enter information that will be incorporated 1444into your certificate request. 1445What you are about to enter is what is called a Distinguished Name or a DN. 1446There are quite a few fields but you can leave some blank 1447For some fields there will be a default value, 1448If you enter '.', the field will be left blank. 1449----- 1450Country Name (2 letter code) [AU]:<b>US</b> 1451State or Province Name (full name) [Some-State]:<b>New York</b> 1452Locality Name (eg, city) []:<b>Westchester</b> 1453Organization Name (eg, company) [Internet Widgits Pty Ltd]:<b>Porcupine</b> 1454Organizational Unit Name (eg, section) []: 1455Common Name (eg, YOUR name) []:<b>FOO</b> 1456Email Address []:<b>wietse@porcupine.org</b> 1457 1458Please enter the following 'extra' attributes 1459to be sent with your certificate request 1460A challenge password []:<b>whatever</b> 1461An optional company name []: 1462</pre> 1463</blockquote> 1464 1465<li> <p> Sign the public key certificate for host FOO with the 1466Certification Authority private key that we created a few 1467steps ago. </p> 1468 1469<blockquote> 1470<pre> 1471% <b>openssl ca -out FOO-cert.pem -infiles FOO-req.pem</b> 1472Uing configuration from /etc/ssl/openssl.cnf 1473Enter PEM pass phrase:<b>whatever</b> 1474Check that the request matches the signature 1475Signature ok 1476The Subjects Distinguished Name is as follows 1477countryName :PRINTABLE:'US' 1478stateOrProvinceName :PRINTABLE:'New York' 1479localityName :PRINTABLE:'Westchester' 1480organizationName :PRINTABLE:'Porcupine' 1481commonName :PRINTABLE:'FOO' 1482emailAddress :IA5STRING:'wietse@porcupine.org' 1483Certificate is to be certified until Nov 21 19:40:56 2005 GMT (365 days) 1484Sign the certificate? [y/n]:<b>y</b> 1485 1486 14871 out of 1 certificate requests certified, commit? [y/n]<b>y</b> 1488Write out database with 1 new entries 1489Data Base Updated 1490</pre> 1491</blockquote> 1492 1493<li> <p> Install the host private key, the host public key certificate, 1494and the Certification Authority certificate files. This requires 1495super-user privileges. </p> 1496 1497<blockquote> 1498<pre> 1499# <b>cp demoCA/cacert.pem FOO-key.pem FOO-cert.pem /etc/postfix</b> 1500# <b>chmod 644 /etc/postfix/FOO-cert.pem /etc/postfix/cacert.pem</b> 1501# <b>chmod 400 /etc/postfix/FOO-key.pem</b> 1502</pre> 1503</blockquote> 1504 1505<li> <p> Configure Postfix, by adding the following to 1506<tt>/etc/postfix/main.cf </tt>. </p> 1507 1508<blockquote> 1509<pre> 1510smtp_tls_CAfile = /etc/postfix/cacert.pem 1511smtp_tls_cert_file = /etc/postfix/FOO-cert.pem 1512smtp_tls_key_file = /etc/postfix/FOO-key.pem 1513smtp_tls_session_cache_database = btree:/var/run/smtp_tls_session_cache 1514smtp_use_tls = yes 1515smtpd_tls_CAfile = /etc/postfix/cacert.pem 1516smtpd_tls_cert_file = /etc/postfix/FOO-cert.pem 1517smtpd_tls_key_file = /etc/postfix/FOO-key.pem 1518smtpd_tls_received_header = yes 1519smtpd_tls_session_cache_database = btree:/var/run/smtpd_tls_session_cache 1520smtpd_use_tls = yes 1521tls_random_source = dev:/dev/urandom 1522</pre> 1523</blockquote> 1524 1525</ul> 1526 1527 1528<h2> <a name="problems"> Reporting problems </a> </h2> 1529 1530<p> When reporting a problem, please be thorough in the report. 1531Patches, when possible, are greatly appreciated too. </p> 1532 1533<p> Please differentiate when possible between: </p> 1534 1535<ul> 1536 1537<li> Problems in the TLS code: <postfix_tls@aet.tu-cottbus.de> 1538 1539<li> Problems in vanilla Postfix: <postfix-users@postfix.org> 1540 1541</ul> 1542 1543<h2><a name="compat">Compatibility with Postfix < 2.2 TLS support</a></h2> 1544 1545<p> Postfix version 2.2 TLS support is based on the Postfix/TLS 1546patch by Lutz Jänicke, but differs in a few minor ways. </p> 1547 1548<ul> 1549 1550<li> <p> main.cf: Specify "btree" instead of "sdbm" for TLS 1551session cache databases. </p> 1552 1553<p> TLS session cache databases are now accessed only by the 1554tlsmgr(8) process, so there are no more concurrency issues. Although 1555Postfix has an sdbm client, the sdbm library (1000 1556lines of code) is not included with Postfix. </p> 1557 1558<p> TLS session caches can use any database that can store objects 1559of several kbytes or more, and that implements the sequence operation. 1560In most cases, btree databases should be adequate. </p> 1561 1562<p> NOTE: You cannot use dbm databases. TLS session objects 1563are too large. </p> 1564 1565<li> <p> master.cf: Specify "unix" instead of "fifo" as 1566the tlsmgr service type. </p> 1567 1568<p> The smtp(8) and smtpd(8) processes now use a client-server 1569protocol in order to access the tlsmgr(8) pseudo-random number 1570generation (PRNG) pool, and in order to access the TLS session 1571cache databases. Such a protocol cannot be run across fifos. </p> 1572 1573<li> <p> smtp_tls_per_site: the MUST_NOPEERMATCH per-site policy 1574cannot override the global "smtp_tls_enforce_peername = yes" setting. 1575</p> 1576 1577<li> <p> smtp_tls_per_site: a combined (NONE + MAY) lookup result 1578for (hostname and next-hop destination) produces counter-intuitive 1579results for different main.cf settings. TLS is enabled with 1580"smtp_tls_enforce_peername = no", but it is disabled when both 1581"smtp_enforce_tls = yes" and "smtp_tls_enforce_peername = yes". 1582</p> 1583 1584</ul> 1585 1586<p> The smtp_tls_per_site limitations were removed by the end of 1587the Postfix 2.2 support cycle. </p> 1588 1589<h2><a name="credits">Credits </a> </h2> 1590 1591<ul> 1592 1593<li> TLS support for Postfix was originally developed by Lutz 1594Jänicke at Cottbus Technical University. 1595 1596<li> Wietse Venema adopted the code, did some restructuring, and 1597compiled this part of the documentation from Lutz's documents. 1598 1599<li> Victor Duchovni was instrumental with the re-implementation 1600of the smtp_tls_per_site code in terms of enforcement levels, which 1601simplified the implementation greatly. 1602 1603</ul> 1604 1605</body> 1606 1607</html> 1608