1 <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN" 2 "https://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 25 on a third-party TLS patch by Lutz Jänicke. As of Postfix 26 version 2.3, the old user interface still exists to allow migration 27 from 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 32 certificate-based authentication and encrypted sessions. An 33 encrypted session protects the information that is transmitted with 34 SMTP mail or with SASL authentication. 35 36 <p> Postfix version 2.2 introduces support for TLS as described in 37 RFC 3207. TLS Support for older Postfix versions was available as 38 an add-on patch. The section "<a href="#compat">Compatibility with 39 Postfix < 2.2 TLS support</a>" below discusses the differences 40 between 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 75 architecture and their relationships. Colored boxes with numbered 76 names represent Postfix daemon programs. Other colored boxes 77 represent storage elements. </p> 78 79 <ul> 80 81 <li> <p> The smtpd(8) server implements the SMTP over TLS server 82 side. </p> 83 84 <li> <p> The smtp(8) client implements the SMTP over TLS client 85 side. </p> 86 87 <li> <p> The tlsmgr(8) server maintains the pseudo-random number 88 generator (PRNG) that seeds the TLS engines in the smtpd(8) server 89 and smtp(8) client processes, and maintains the TLS session key 90 cache files. </p> 91 92 </ul> 93 94 <table> 95 96 <tr> <td>Network<tt>-> </tt> </td> <td align="center" 97 bgcolor="#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 100 align="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"> 115 smtpd<br> session<br> key cache </td> <td> </td> <td align="center" 116 bgcolor="#f0f0ff"> PRNG<br> state <br>file </td> <td> </td> <td 117 align="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 127 the <tt>make(1)</tt> files with the necessary definitions. This is 128 done by invoking the command "<tt>make makefiles</tt>" in the Postfix 129 top-level directory and with arguments as shown next. </p> 130 131 <p> <b> NOTE: Do not use Gnu TLS. It will spontaneously terminate 132 a Postfix daemon process with exit status code 2, instead of allowing 133 Postfix to 1) report the error to the maillog file, and to 2) provide 134 plaintext 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 139 in directory <tt>/usr/include/openssl</tt>, and the OpenSSL libraries 140 (such as <tt>libssl.so</tt> and <tt>libcrypto.so</tt>) are in 141 directory <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 151 in directory <tt>/usr/local/include/openssl</tt>, and the OpenSSL 152 libraries (such as <tt>libssl.so</tt> and <tt>libcrypto.so</tt>) 153 are 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 176 databases, MySQL, PosgreSQL, LDAP or SASL), see the respective 177 Postfix README documents, and combine their "<tt>make makefiles</tt>" 178 instructions 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 192 instructions. Postfix has TLS support turned off by default, so 193 you 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 202 key 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 224 key configuration </a> </h3> 225 226 <p> In order to use TLS, the Postfix SMTP server needs a certificate 227 and a private key. Both must be in "pem" format. The private key 228 must not be encrypted, meaning: the key must be accessible without 229 a password. Both certificate and private key may be in the same 230 file. </p> 231 232 <p> Both RSA and DSA certificates are supported. Typically you will 233 only have RSA certificates issued by a commercial CA. In addition, 234 the tools supplied with OpenSSL will by default issue RSA certificates. 235 You can have both at the same time, in which case the cipher used 236 determines which certificate is presented. For Netscape and OpenSSL 237 clients without special cipher choices, the RSA certificate is 238 preferred. </p> 239 240 <p> In order for remote SMTP clients to check the Postfix SMTP 241 server certificates, the CA certificate (in case of a certificate 242 chain, all CA certificates) must be available. You should add 243 these certificates to the server certificate, the server certificate 244 first, 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 248 CA". 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 257 as an SSL server certificate and hence pass the "openssl verify -purpose 258 sslserver ..." test. </p> 259 260 <p> A client that trusts the root CA has a local copy of the root 261 CA certificate, so it is not necessary to include the root CA 262 certificate here. Leaving it out of the "server.pem" file reduces 263 the overhead of the TLS exchange. </p> 264 265 <p> If you want the Postfix SMTP server to accept remote SMTP client 266 certificates issued by these CAs, append the root certificate to 267 $smtpd_tls_CAfile or install it in the $smtpd_tls_CApath directory. When 268 you configure trust in a root CA, it is not necessary to explicitly trust 269 intermediary CAs signed by the root CA, unless $smtpd_tls_ccert_verifydepth 270 is less than the number of CAs in the certificate chain for the clients 271 of interest. With a verify depth of 1 you can only verify certificates 272 directly signed by a trusted CA, and all trusted intermediary CAs need to 273 be configured explicitly. With a verify depth of 2 you can verify clients 274 signed by a root CA or a direct intermediary CA (so long as the client 275 is 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 298 server needs to trust the certificates of the issuing Certification 299 Authorities. These certificates in "pem" format can be stored in a 300 single $smtpd_tls_CAfile or in multiple files, one CA per file in 301 the $smtpd_tls_CApath directory. If you use a directory, don't forget 302 to 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 311 more trusted CAs. The file is opened (with root privileges) before 312 Postfix enters the optional chroot jail and so need not be accessible 313 from inside the chroot jail. </p> 314 315 <p> Additional trusted CAs can be specified via the $smtpd_tls_CApath 316 directory, in which case the certificates are read (with $mail_owner 317 privileges) from the files in the directory when the information 318 is needed. Thus, the $smtpd_tls_CApath directory needs to be 319 accessible inside the optional chroot jail. </p> 320 321 <p> When you configure Postfix to request client certificates (by 322 setting $smtpd_tls_ask_ccert = yes), any certificates in 323 $smtpd_tls_CAfile are sent to the client, in order to allow it to 324 choose an identity signed by a CA you trust. If no $smtpd_tls_CAfile 325 is specified, no preferred CA list is sent, and the client is free 326 to choose an identity signed by any CA. Many clients use a fixed 327 identity regardless of the preferred CA list and you may be able 328 to reduce TLS negotiation overhead by installing client CA certificates 329 mostly or only in $smtpd_tls_CApath. In the latter case you need 330 not specify a $smtpd_tls_CAfile. </p> 331 332 <p> Note, that unless client certificates are used to allow greater 333 access to TLS authenticated clients, it is best to not ask for 334 client certificates at all, as in addition to increased overhead 335 some clients (notably in some cases qmail) are unable to complete 336 the 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 350 activity you can increase the loglevel from 0..4. Each logging 351 level also includes the information that is logged at a lower 352 logging 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 367 negotiation process </td> </tr> 368 369 <tr> <td> 4 </td> <td> Log hexadecimal and ASCII dump of complete 370 transmission 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 377 strongly 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 389 well as the client and issuer CommonName into the "Received:" 390 message header, set the smtpd_tls_received_header variable to true. 391 The default is no, as the information is not necessarily authentic. 392 Only information recorded at the final destination is reliable, 393 since 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 407 difference to plain Postfix is visible. Explicitly switch it on 408 using "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 420 SMTP clients, but does not require that clients use TLS encryption. 421 </p> 422 423 <p> Note: when an unprivileged user invokes "sendmail -bs", STARTTLS 424 is never offered due to insufficient privileges to access the server 425 private key. This is intended behavior. </p> 426 427 <p> You can ENFORCE the use of TLS, so that the Postfix SMTP server 428 announces STARTTLS and accepts no mail without TLS encryption, by 429 setting "smtpd_enforce_tls = yes". According to RFC 2487 this MUST 430 NOT be applied in case of a publicly-referenced Postfix SMTP server. 431 This 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 443 a server always uses TLS, instead of announcing STARTTLS support 444 and waiting for clients to request TLS service. Some clients, namely 445 Outlook [Express] prefer the "wrapper" mode. This is true for OE 446 (Win32 < 5.0 and Win32 >=5.0 when run on a port<>25 447 and OE (5.01 Mac on all ports). </p> 448 449 <p> It is strictly discouraged to use this mode from main.cf. If 450 you want to support this service, enable a special port in master.cf 451 and specify "-o smtpd_tls_wrappermode = yes" as an smtpd(8) command 452 line 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 468 server must explicitly ask for one (any contents of $smtpd_tls_CAfile 469 are also sent to the client as a hint for choosing a certificate 470 from a suitable CA). Unfortunately, Netscape clients will either 471 complain if no matching client certificate is available or will 472 offer the user client a list of certificates to choose from. 473 Additionally some MTAs (notably some versions of qmail) are unable 474 to complete TLS negotiation when client certificates are requested, 475 and abort the SMTP session. So this option is "off" by default. 476 You will however need the certificate if you want to use certificate 477 based relaying with, for example, the permit_tls_clientcerts 478 feature. </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 490 before allowing TLS connections. This feature is included for 491 completeness, and implies "smtpd_tls_ask_ccert = yes". </p> 492 493 <p> Please be aware, that this will inhibit TLS connections without 494 a proper client certificate and that it makes sense only when 495 non-TLS submission is disabled (smtpd_enforce_tls = yes). Otherwise, 496 clients could bypass the restriction by simply not using STARTTLS 497 at all. </p> 498 499 <p> When TLS is not enforced, the connection will be handled as 500 if only "smtpd_tls_ask_ccert = yes" is specified, and a warning is 501 logged. </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 513 the certificate is directly issued by a CA listed in the CA file. 514 The default value (5) should also suffice for longer chains (root 515 CA 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 530 risk. When TLS layer encryption is required (smtpd_enforce_tls = 531 yes), the Postfix SMTP server will announce and accept AUTH only 532 after the TLS layer has been activated with STARTTLS. When TLS 533 layer encryption is optional (smtpd_enforce_tls = no), it may 534 however still be useful to only offer AUTH when TLS is active. To 535 maintain compatibility with non-TLS clients, the default is to 536 accept AUTH without encryption. In order to change this behavior, 537 set "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 551 a session, which takes some computer time and network bandwidth. 552 By default, this session information is cached only in the smtpd(8) 553 process actually using this session and is lost when the process 554 terminates. To share the session information between multiple 555 smtpd(8) processes, a persistent session cache can be used. You 556 can specify any database type that can store objects of several 557 kbytes and that supports the sequence operator. DBM databases are 558 not suitable because they can only store small objects. The cache 559 is maintained by the tlsmgr(8) process, so there is no problem with 560 concurrent access. Session caching is highly recommended, because 561 the 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 573 in a directory with non-Postfix ownership. As a migration aid, 574 attempts 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 578 a certain amount of time. Postfix/TLS does not use the OpenSSL 579 default of 300s, but a longer time of 3600sec (=1 hour). RFC 2246 580 recommends 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 594 Postfix SMTP server access control: </p> 595 596 <blockquote> 597 598 <dl> 599 600 <dt> permit_tls_clientcerts </dt> <dd> <p> Allow the remote SMTP 601 client SMTP request if the client certificate passes verification, 602 and 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 606 client 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 611 as 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, 618 because it can result in too many access permissions. Use this 619 feature only if a special CA issues the client certificates, and 620 only if this CA is listed as a trusted CA. If other CAs are trusted, 621 any owner of a valid client certificate would be authorized. 622 The permit_tls_all_clientcerts feature can be practical for a 623 specially created email relay server. </p> 624 625 <p> It is however recommended to stay with the permit_tls_clientcerts 626 feature and list all certificates via $relay_clientcerts, as 627 permit_tls_all_clientcerts does not permit any control when a 628 certificate 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 644 to whitespace and some other characters, making the use of certificate 645 names impractical. Instead we use the certificate fingerprints as 646 they are difficult to fake but easy to use for lookup. Postfix 647 lookup tables are in the form of (key, value) pairs. Since we only 648 need the key, the value can be chosen freely, e.g. the name of 649 the 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, 666 you can give cipherlist string. A detailed description would go 667 too far here; please refer to the OpenSSL documentation. If you 668 don'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 683 are needed. Instead of using the built-in DH parameters for both 684 1024bit and 512bit, it is better to generate "own" parameters, 685 since otherwise it would "pay" for a possible attacker to start a 686 brute force attack against parameters that are used by everybody. 687 For this reason, the parameters chosen are already different from 688 those 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 712 SMTP server write and read operations during TLS startup and shutdown 713 handshake 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 731 key 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 763 key configuration </a> </h3> 764 765 <p> During TLS startup negotiation the Postfix SMTP client may present 766 a certificate to the remote SMTP server. The Netscape client is 767 rather clever here and lets the user select between only those 768 certificates that match CA certificates offered by the remote SMTP 769 server. As the Postfix SMTP client uses the "SSL_connect()" function 770 from the OpenSSL package, this is not possible and we have to choose 771 just one certificate. So for now the default is to use _no_ 772 certificate and key unless one is explicitly specified here. </p> 773 774 <p> Both RSA and DSA certificates are supported. You can have both 775 at the same time, in which case the cipher used determines which 776 certificate is presented. </p> 777 778 <p> It is possible for the Postfix SMTP client to use the same 779 key/certificate pair as the Postfix SMTP server. If a certificate 780 is to be presented, it must be in "pem" format. The private key 781 must not be encrypted, meaning: it must be accessible without 782 a password. Both parts (certificate and private key) may be in the 783 same file. </p> 784 785 <p> In order for remote SMTP servers to verify the Postfix SMTP 786 client certificates, the CA certificate (in case of a certificate 787 chain, all CA certificates) must be available. You should add 788 these certificates to the client certificate, the client certificate 789 first, 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". 793 Create 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 802 as an SSL client certificate and hence pass the "openssl verify -purpose 803 sslclient ..." test. </p> 804 805 <p> A server that trusts the root CA has a local copy of the root 806 CA certificate, so it is not necessary to include the root CA 807 certificate here. Leaving it out of the "client.pem" file reduces 808 the overhead of the TLS exchange. </p> 809 810 <p> If you want the Postfix SMTP client to accept remote SMTP server 811 certificates issued by these CAs, append the root certificate to 812 $smtp_tls_CAfile or install it in the $smtp_tls_CApath directory. When 813 you configure trust in a root CA, it is not necessary to explicitly trust 814 intermediary CAs signed by the root CA, unless $smtp_tls_scert_verifydepth 815 is less than the number of CAs in the certificate chain for the servers 816 of interest. With a verify depth of 1 you can only verify certificates 817 directly signed by a trusted CA, and all trusted intermediary CAs need to 818 be configured explicitly. With a verify depth of 2 you can verify servers 819 signed by a root CA or a direct intermediary CA (so long as the server 820 is 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 843 client needs to trust the certificates of the issuing Certification 844 Authorities. These certificates in "pem" format can be stored in a 845 single $smtp_tls_CAfile or in multiple files, one CA per file in 846 the $smtp_tls_CApath directory. If you use a directory, don't forget 847 to 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 856 trusted CAs. The file is opened (with root privileges) before Postfix 857 enters the optional chroot jail and so need not be accessible from inside the 858 chroot jail. </p> 859 860 <p> Additional trusted CAs can be specified via the $smtp_tls_CApath 861 directory, in which case the certificates are read (with $mail_owner 862 privileges) from the files in the directory when the information 863 is needed. Thus, the $smtp_tls_CApath directory needs to be accessible 864 inside the optional chroot jail. </p> 865 866 <p> The choice between $smtp_tls_CAfile and $smtp_tls_CApath is 867 a space/time tradeoff. If there are many trusted CAs, the cost of 868 preloading them all into memory may not pay off in reduced access time 869 when 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 884 activity you can increase the loglevel from 0..4. Each logging 885 level also includes the information that is logged at a lower 886 logging 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 901 negotiation process </td> </tr> 902 903 <tr> <td> 4 </td> <td> Log hexadecimal and ASCII dump of complete 904 transmission 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 922 session, which takes some computer time and network bandwidth. By 923 default, this session information is cached only in the smtp(8) 924 process actually using this session and is lost when the process 925 terminates. To share the session information between multiple 926 smtp(8) processes, a persistent session cache can be used. You 927 can specify any database type that can store objects of several 928 kbytes and that supports the sequence operator. DBM databases are 929 not suitable because they can only store small objects. The cache 930 is maintained by the tlsmgr(8) process, so there is no problem with 931 concurrent access. Session caching is highly recommended, because 932 the cost of repeatedly negotiating TLS session keys is high. Future 933 Postfix SMTP servers may limit the number of sessions that a client 934 is 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 947 in a directory with non-Postfix ownership. As a migration aid, 948 attempts 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 952 a certain amount of time. Postfix/TLS does not use the OpenSSL 953 default of 300s, but a longer time of 3600s (=1 hour). RFC 2246 954 recommends 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 966 client </a> </h3> 967 968 <p> By default, TLS is disabled in the Postfix SMTP client, so no 969 difference to plain Postfix is visible. If you enable TLS, the 970 Postfix SMTP client will send STARTTLS when TLS support is announced 971 by the remote SMTP server. </p> 972 973 <p> When the server accepts the STARTTLS command, but the subsequent 974 TLS handshake fails, and no other server is available, the Postfix SMTP 975 client defers the delivery attempt, and the mail stays in the queue. After 976 a handshake failure, the communications channel is in an indeterminate 977 state 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 992 will not deliver mail over unencrypted connections. In this mode, 993 the remote SMTP server hostname must match the information in the 994 remote server certificate, and the server certificate must be issued 995 by a CA that is trusted by the Postfix SMTP client. If the remote 996 server certificate doesn't verify or the remote SMTP server hostname 997 doesn't match, and no other server is available, the delivery 998 attempt is deferred and the mail stays in the queue. </p> 999 1000 <p> The remote SMTP server hostname is verified against all names 1001 provided as dNSNames 1002 in the SubjectAlternativeName. If no dNSNames are specified, the 1003 CommonName is checked. Verification may be turned off with the 1004 smtp_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 1007 only 1008 connect to servers that support RFC 2487 _and_ that present server 1009 certificates that meet the above requirements. An example would 1010 be a client only sends email to one specific mailhub that offers 1011 the 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 1023 verification </a> </h3> 1024 1025 <p> As of RFC 2487 the requirements for hostname checking for MTA 1026 clients are not set. When TLS is required (smtp_enforce_tls = yes), 1027 the option smtp_tls_enforce_peername can be set to "no" to disable 1028 strict remote SMTP server hostname checking. In this case, the mail 1029 delivery will proceed regardless of the CommonName etc. listed in 1030 the certificate. </p> 1031 1032 <p> Despite the potential for eliminating "man-in-the-middle" and 1033 other attacks, mandatory certificate/peername verification is not 1034 viable as a default Internet mail delivery policy at this time. A 1035 significant fraction of TLS enabled MTAs uses self-signed certificates, 1036 or certificates that are signed by a private Certification Authority. 1037 On a machine that delivers mail to the Internet, if you set 1038 smtp_enforce_tls = yes, you should probably also set 1039 smtp_tls_enforce_peername = no. You can use the per-site TLS 1040 policies (see below) to enable full peer verification for specific 1041 destinations 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 1057 consistently fails, leading to mail aging out of the queue and 1058 bouncing back to the sender. In such cases, you can use the per-site 1059 policies to disable TLS for the problem sites. Alternatively, you 1060 can enable TLS for just a few specific sites and not enable it for 1061 all 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. 1069 Unlike the newer mechanism it supports TLS policy lookup by server 1070 hostname, and lacks control over what names can appear in server 1071 certificates. Because of this, the obsolete mechanism is vulnerable 1072 to false DNS hostname information in MX or CNAME records. These 1073 attacks 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 1078 the following information: </p> 1079 1080 <blockquote> 1081 1082 <dl> 1083 1084 <dt> remote SMTP server hostname </dt> <dd> This is simply the DNS 1085 name of the server that the Postfix SMTP client connects to; this 1086 name may be obtained from other DNS lookups, such as MX lookups or 1087 CNAME lookups. </dd> 1088 1089 <dt> next-hop destination </dt> <dd> This is normally the domain 1090 portion of the recipient address, but it may be overruled by 1091 information from the transport(5) table, from the relayhost parameter 1092 setting, or from the relay_transport setting. When it's not the 1093 recipient domain, the next-hop destination can have the Postfix-specific 1094 form "<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, 1102 the host policy does not automatically override the next-hop policy. 1103 Instead, precedence is given to either the more specific or the 1104 more secure per-site policy as described below. </p> 1105 1106 <p> The smtp_tls_per_site table uses a simple "<i>name whitespace 1107 value</i>" format. Specify host names or next-hop destinations on 1108 the left-hand side; no wildcards are allowed. On the right hand 1109 side 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 1116 specific <b>MAY</b> lookup result from the alternate host or next-hop 1117 lookup key, and overrides the global smtp_use_tls, smtp_enforce_tls, 1118 and smtp_tls_enforce_peername settings. </dd> 1119 1120 <dt> MAY </dt> <dd> Try to use TLS if the server announces support, 1121 otherwise use the unencrypted connection. This has less precedence 1122 than a more specific result (including <b>NONE</b>) from the alternate 1123 host or next-hop lookup key, and has less precedence than the more 1124 specific 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 1128 require that the remote SMTP server hostname matches the information 1129 in the remote SMTP server certificate, or that the server certificate 1130 was issued by a trusted CA. This overrides a less secure <b>NONE</b> 1131 or a less specific <b>MAY</b> lookup result from the alternate host 1132 or next-hop lookup key, and overrides the global smtp_use_tls, 1133 smtp_enforce_tls and smtp_tls_enforce_peername settings. </dd> 1134 1135 <dt> MUST </dt> <dd> Require TLS encryption, require that the remote 1136 SMTP server hostname matches the information in the remote SMTP 1137 server certificate, and require that the remote SMTP server certificate 1138 was issued by a trusted CA. This overrides a less secure <b>NONE</b> 1139 and <b>MUST_NOPEERMATCH</b> or a less specific <b>MAY</b> lookup 1140 result from the alternate host or next-hop lookup key, and overrides 1141 the global smtp_use_tls, smtp_enforce_tls and smtp_tls_enforce_peername 1142 settings. </dd> 1143 1144 </dl> 1145 1146 </blockquote> 1147 1148 <p> The precedences between global (main.cf) and per-site TLS 1149 policies can be summarized as follows: </p> 1150 1151 <ul> 1152 1153 <li> <p> When neither the remote SMTP server hostname nor the 1154 next-hop destination are found in the smtp_tls_per_site table, the 1155 policy is based on smtp_use_tls, smtp_enforce_tls and 1156 smtp_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 1160 a result, the more specific per-site policy (NONE, MUST, etc.) 1161 overrides the less specific one (MAY), and the more secure per-site 1162 policy (MUST, etc.) overrides the less secure one (NONE). </p> 1163 1164 <li> <p> After the per-site policy lookups are combined, the result 1165 generally overrides the global policy. The exception is the less 1166 specific <b>MAY</b> per-site policy, which is overruled by the more 1167 specific global "smtp_enforce_tls = yes" with server certificate 1168 verification as specified with the smtp_tls_enforce_peername 1169 parameter. </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 1177 hostnames in MX or CNAME responses can change the server hostname 1178 that Postfix uses for TLS policy lookup and server certificate 1179 verification. Even with a perfect match between the server hostname 1180 and the server certificate, there is no guarantee that Postfix is 1181 connected to the right server. To avoid this loophole take the 1182 following steps: </p> 1183 1184 <ul> 1185 1186 <li> <p> Eliminate MX lookups. Specify local transport(5) table 1187 entries for sensitive domains with explicit smtp:[<i>mailhost</i>] 1188 or smtp:[<i>mailhost</i>]:<i>port</i> destinations (you can assure 1189 security of this table unlike DNS); in the smtp_tls_per_site table 1190 specify the value <b>MUST</b> for the key [<i>mailhost</i>] or 1191 smtp:[<i>mailhost</i>]:<i>port</i>. This prevents false hostname 1192 information in DNS MX records from changing the server hostname 1193 that Postfix uses for TLS policy lookup and server certificate 1194 verification. </p> 1195 1196 <li> <p> Disallow CNAME hostname overrides. In main.cf specify 1197 "smtp_cname_overrides_servername = no". This prevents false hostname 1198 information in DNS CNAME records from changing the server hostname 1199 that Postfix uses for TLS policy lookup and server certificate 1200 verification. 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 1224 TLS </a> </h3> 1225 1226 <p> As we decide on a "per site" basis whether or not to use TLS, 1227 it would be good to have a list of sites that offered "STARTTLS". 1228 We can collect it ourselves with this option. </p> 1229 1230 <p> If the smtp_tls_note_starttls_offer feature is enabled and a 1231 server offers STARTTLS while TLS is not already enabled for that 1232 server, the Postfix SMTP client logs a line as follows: </p> 1233 1234 <blockquote> 1235 <pre> 1236 postfix/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 1252 depth of 1 is sufficient if the certificate is directly issued by 1253 a CA specified with smtp_tls_CAfile or smtp_tls_CApath. The default 1254 value of 5 should also suffice for longer chains (root CA issues 1255 special 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, 1269 you can give cipherlist string. A detailed description would go 1270 too far here; please refer to the OpenSSL documentation. If you 1271 don'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 1288 SMTP client write and read operations during TLS startup and shutdown 1289 handshake procedures. In case of problems the Postfix SMTP client 1290 tries the next network address on the mail exchanger list, and 1291 defers 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 1305 critically on the ability to generate unpredictable numbers for 1306 keys and other information. To this end, the tlsmgr(8) process 1307 maintains a Pseudo Random Number Generator (PRNG) pool. This is 1308 queried by the smtp(8) and smtpd(8) processes when they initialize. 1309 By default, these daemons request 32 bytes, the equivalent to 256 1310 bits. This is more than sufficient to generate a 128bit (or 168bit) 1311 session 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 1323 entropy from an external source, both at startup and during run-time. 1324 Specify a good entropy source, like EGD or /dev/urandom; be sure 1325 to only use non-blocking sources (on OpenBSD, use /dev/arandom 1326 when tlsmgr(8) complains about /dev/urandom timeout errors). 1327 If the entropy source is not a 1328 regular 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 1330 compatible 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 1343 source at each seeding event. This amount (256bits) is more than 1344 sufficient for generating a 128bit symmetric key. With EGD and 1345 device entropy sources, the tlsmgr(8) limits the amount of data 1346 read at each step to 255 bytes. If you specify a regular file as 1347 entropy 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) 1359 queries the external entropy source again after a pseudo-random 1360 amount of time. The time is calculated using the PRNG, and is 1361 between 0 and the maximal time specified with tls_random_reseed_period. 1362 The 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 1374 exchange file at regular times and when the process terminates, so 1375 that it can recover the PRNG state the next time it starts up. 1376 This file is created when it does not exist. Its default location 1377 is under the Postfix configuration directory, which is not the 1378 proper place for information that is modified by Postfix. Instead, 1379 the 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 1395 sign your own Postfix public key certificate, you get TLS encryption 1396 but no TLS authentication. This is sufficient for testing, and 1397 for exchanging email with sites that you have no trust relationship 1398 with. For real authentication, your Postfix public key certificate 1399 needs to be signed by a recognized Certification Authority, and 1400 Postfix needs to be configured with a list of public key certificates 1401 of Certification Authorities, so that Postfix can verify the public key 1402 certificates of remote hosts. </p> 1403 1404 <p> In the examples below, user input is shown in <b><tt>bold</tt></b> 1405 font, 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 1410 sign your own public keys. This example uses the CA.pl script that 1411 ships with OpenSSL. By default, OpenSSL installs this as 1412 <tt>/usr/local/ssl/misc/CA.pl</tt>, but your mileage may vary. 1413 The script creates a private key in <tt>./demoCA/private/cakey.pem</tt> 1414 and 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> 1419 CA certificate filename (or enter to create) 1420 1421 Making CA certificate ... 1422 Using configuration from /etc/ssl/openssl.cnf 1423 Generating a 1024 bit RSA private key 1424 ....................++++++ 1425 .....++++++ 1426 writing new private key to './demoCA/private/cakey.pem' 1427 Enter PEM pass phrase:<b>whatever</b> 1428 </pre> 1429 </blockquote> 1430 1431 <li> <p> Create an unpassworded private key for host FOO and create 1432 an 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> 1437 Using configuration from /etc/ssl/openssl.cnf 1438 Generating a 1024 bit RSA private key 1439 ........................................++++++ 1440 ....++++++ 1441 writing new private key to 'FOO-key.pem' 1442 ----- 1443 You are about to be asked to enter information that will be incorporated 1444 into your certificate request. 1445 What you are about to enter is what is called a Distinguished Name or a DN. 1446 There are quite a few fields but you can leave some blank 1447 For some fields there will be a default value, 1448 If you enter '.', the field will be left blank. 1449 ----- 1450 Country Name (2 letter code) [AU]:<b>US</b> 1451 State or Province Name (full name) [Some-State]:<b>New York</b> 1452 Locality Name (eg, city) []:<b>Westchester</b> 1453 Organization Name (eg, company) [Internet Widgits Pty Ltd]:<b>Porcupine</b> 1454 Organizational Unit Name (eg, section) []: 1455 Common Name (eg, YOUR name) []:<b>FOO</b> 1456 Email Address []:<b>wietse (a] porcupine.org</b> 1457 1458 Please enter the following 'extra' attributes 1459 to be sent with your certificate request 1460 A challenge password []:<b>whatever</b> 1461 An optional company name []: 1462 </pre> 1463 </blockquote> 1464 1465 <li> <p> Sign the public key certificate for host FOO with the 1466 Certification Authority private key that we created a few 1467 steps ago. </p> 1468 1469 <blockquote> 1470 <pre> 1471 % <b>openssl ca -out FOO-cert.pem -infiles FOO-req.pem</b> 1472 Uing configuration from /etc/ssl/openssl.cnf 1473 Enter PEM pass phrase:<b>whatever</b> 1474 Check that the request matches the signature 1475 Signature ok 1476 The Subjects Distinguished Name is as follows 1477 countryName :PRINTABLE:'US' 1478 stateOrProvinceName :PRINTABLE:'New York' 1479 localityName :PRINTABLE:'Westchester' 1480 organizationName :PRINTABLE:'Porcupine' 1481 commonName :PRINTABLE:'FOO' 1482 emailAddress :IA5STRING:'wietse (a] porcupine.org' 1483 Certificate is to be certified until Nov 21 19:40:56 2005 GMT (365 days) 1484 Sign the certificate? [y/n]:<b>y</b> 1485 1486 1487 1 out of 1 certificate requests certified, commit? [y/n]<b>y</b> 1488 Write out database with 1 new entries 1489 Data Base Updated 1490 </pre> 1491 </blockquote> 1492 1493 <li> <p> Install the host private key, the host public key certificate, 1494 and the Certification Authority certificate files. This requires 1495 super-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> 1510 smtp_tls_CAfile = /etc/postfix/cacert.pem 1511 smtp_tls_cert_file = /etc/postfix/FOO-cert.pem 1512 smtp_tls_key_file = /etc/postfix/FOO-key.pem 1513 smtp_tls_session_cache_database = btree:/var/run/smtp_tls_session_cache 1514 smtp_use_tls = yes 1515 smtpd_tls_CAfile = /etc/postfix/cacert.pem 1516 smtpd_tls_cert_file = /etc/postfix/FOO-cert.pem 1517 smtpd_tls_key_file = /etc/postfix/FOO-key.pem 1518 smtpd_tls_received_header = yes 1519 smtpd_tls_session_cache_database = btree:/var/run/smtpd_tls_session_cache 1520 smtpd_use_tls = yes 1521 tls_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. 1531 Patches, 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 (a] aet.tu-cottbus.de> 1538 1539 <li> Problems in vanilla Postfix: <postfix-users (a] 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 1546 patch 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 1551 session cache databases. </p> 1552 1553 <p> TLS session cache databases are now accessed only by the 1554 tlsmgr(8) process, so there are no more concurrency issues. Although 1555 Postfix has an sdbm client, the sdbm library (1000 1556 lines of code) is not included with Postfix. </p> 1557 1558 <p> TLS session caches can use any database that can store objects 1559 of several kbytes or more, and that implements the sequence operation. 1560 In most cases, btree databases should be adequate. </p> 1561 1562 <p> NOTE: You cannot use dbm databases. TLS session objects 1563 are too large. </p> 1564 1565 <li> <p> master.cf: Specify "unix" instead of "fifo" as 1566 the tlsmgr service type. </p> 1567 1568 <p> The smtp(8) and smtpd(8) processes now use a client-server 1569 protocol in order to access the tlsmgr(8) pseudo-random number 1570 generation (PRNG) pool, and in order to access the TLS session 1571 cache databases. Such a protocol cannot be run across fifos. </p> 1572 1573 <li> <p> smtp_tls_per_site: the MUST_NOPEERMATCH per-site policy 1574 cannot 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 1578 for (hostname and next-hop destination) produces counter-intuitive 1579 results 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 1587 the 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 1594 Jänicke at Cottbus Technical University. 1595 1596 <li> Wietse Venema adopted the code, did some restructuring, and 1597 compiled this part of the documentation from Lutz's documents. 1598 1599 <li> Victor Duchovni was instrumental with the re-implementation 1600 of the smtp_tls_per_site code in terms of enforcement levels, which 1601 simplified the implementation greatly. 1602 1603 </ul> 1604 1605 </body> 1606 1607 </html> 1608