1*46e7f790Sjmc.\" $OpenBSD: starttls.8,v 1.14 2005/07/04 08:44:37 jmc Exp $ 253affce0Smillert.\" 353affce0Smillert.\" Copyright (c) 2001 Jose Nazario <jose@monkey.org> 453affce0Smillert.\" All rights reserved. 553affce0Smillert.\" 653affce0Smillert.\" Redistribution and use in source and binary forms, with or without 753affce0Smillert.\" modification, are permitted provided that the following conditions 853affce0Smillert.\" are met: 953affce0Smillert.\" 1. Redistributions of source code must retain the above copyright 1053affce0Smillert.\" notice, this list of conditions and the following disclaimer. 1153affce0Smillert.\" 2. Redistributions in binary form must reproduce the above copyright 1253affce0Smillert.\" notice, this list of conditions and the following disclaimer in the 1353affce0Smillert.\" documentation and/or other materials provided with the distribution. 1453affce0Smillert.\" 1553affce0Smillert.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 1653affce0Smillert.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 1753affce0Smillert.\" AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 1853affce0Smillert.\" THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 1953affce0Smillert.\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 2053affce0Smillert.\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 2153affce0Smillert.\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 2253affce0Smillert.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 2353affce0Smillert.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 2453affce0Smillert.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2553affce0Smillert.\" 265828a48cSmillert.Dd January 11, 2002 277faf1a54Smillert.Dt STARTTLS 8 2853affce0Smillert.Os 297faf1a54Smillert.Sh NAME 307faf1a54Smillert.Nm starttls 315828a48cSmillert.Nd ESMTP over TLS/SSL 327faf1a54Smillert.Sh DESCRIPTION 337faf1a54SmillertSTARTTLS is an ESMTP option, defined in RFC 2487, which is used to conduct 347faf1a54SmillertESMTP transactions over TLS circuits. 357faf1a54SmillertThis is used to increase the security of mail server transactions. 365828a48cSmillertAs of version 8.11, 377faf1a54Smillert.Xr sendmail 8 387faf1a54Smillerthas supported the use of TLS to protect ESMTP communications. 397faf1a54Smillert.Pp 407faf1a54SmillertSTARTTLS allows for the combination of several security solutions for MTA 417faf1a54Smillert(mail transport agent) level services through the TLS suite. 427faf1a54SmillertThese security features include: 437faf1a54Smillert.Bl -tag -width Ds 447faf1a54Smillert.It Confidentiality 457faf1a54SmillertEncryption is used to protect data from passive monitoring. 467faf1a54SmillertAn attacker would have to recover the encryption key used to 477faf1a54Smillertdecode the transmitted data. 487faf1a54Smillert.It Integrity 497faf1a54SmillertHash algorithms are used to ensure the integrity of the 507faf1a54Smillerttransmitted data, and alternatively the timestamp, protecting against a 517faf1a54Smillertreplay attack. 527faf1a54SmillertThis protects data from modification in transit. 537faf1a54Smillert.It Authentication 547faf1a54SmillertThe use of public key encryption allows for the strong authentication of 557faf1a54Smillerteither, or both, communicating parties. 567faf1a54SmillertThis can be used to allow for select features, such as relaying, 577faf1a54Smillertto be controlled more securely. 587faf1a54Smillert.El 597faf1a54Smillert.Pp 607faf1a54SmillertA new ESMTP option, STARTTLS, has been added. 617faf1a54SmillertThis is presented by the server when an ESMTP session is initiated. 627faf1a54SmillertThe client then begins the TLS portion of the ESMTP session by issuing 637faf1a54Smillertthe command 647faf1a54Smillert.Dq STARTTLS . 657faf1a54SmillertThe remaining portion of the ESMTP session occurs over a TLS channel. 66eefea0cbSmillert.Ss Creating a private key and certificate for sendmail 675828a48cSmillertThis example assumes you are creating your own self-signed certificates 685828a48cSmillertfor use with sendmail and STARTTLS. 69eefea0cbSmillertIf you have an existing private key and you simply wish to generate 70eefea0cbSmillerta new certificate (for example, if your old certificate has expired), 71eefea0cbSmillertsee the section entitled 72eefea0cbSmillert.Sx "Creating a certificate with an existing private key" . 73eefea0cbSmillert.Pp 745828a48cSmillertFor the purposes of this example the certificates will be stored in 755828a48cSmillert.Pa /etc/mail/certs , 765828a48cSmillertthough it is possible to use a different directory if needed. 775828a48cSmillertIf this directory does not already exist, you must create it: 780d8a9824Sjmc.Pp 790d8a9824Sjmc.Dl # mkdir /etc/mail/certs 805828a48cSmillert.Pp 815828a48cSmillertNext, you must generate a 825828a48cSmillert.Ar DSA 835828a48cSmillertparameter set with a command like the following: 840d8a9824Sjmc.Pp 850d8a9824Sjmc.Dl # openssl dsaparam 1024 -out dsa1024.pem 865828a48cSmillert.Pp 875828a48cSmillertThis would generate 885828a48cSmillert.Ar DSA 897dbb7873Sjmcparameters for 1024-bit 905828a48cSmillert.Ar DSA 915828a48cSmillertkeys, and save them to the 925828a48cSmillertfile 935828a48cSmillert.Pa dsa1024.pem . 945828a48cSmillert.Pp 955828a48cSmillertOnce you have the 965828a48cSmillert.Ar DSA 975828a48cSmillertparameters generated, you can generate a certificate 985828a48cSmillertand unencrypted private key using the command: 990d8a9824Sjmc.Bd -literal -offset indent 1000d8a9824Sjmc# openssl req -x509 -nodes -days 365 -newkey dsa:dsa1024.pem \e 1015828a48cSmillert -out /etc/mail/certs/mycert.pem -keyout /etc/mail/certs/mykey.pem 1025828a48cSmillert.Ed 1035828a48cSmillert.Pp 104eefea0cbSmillertYou may adjust the lifetime of the certificate via the 105eefea0cbSmillert.Fl days 106eefea0cbSmillertparameter (one year in this example). 107eefea0cbSmillert.Pp 1085828a48cSmillertMake sure to leave the private key files unencrypted, using the 1095828a48cSmillert.Fl nodes 1105828a48cSmillertoption. 1115828a48cSmillertOtherwise, 1125828a48cSmillert.Xr sendmail 8 1135828a48cSmillertwill be unable to initiate TLS server functions. 1145828a48cSmillert.Pp 115eefea0cbSmillertYou can verify that the newly-generated certificate has correct information 116eefea0cbSmillertwith the following command: 1170d8a9824Sjmc.Pp 1180d8a9824Sjmc.Dl # openssl x509 -in /etc/mail/certs/mycert.pem -text 119eefea0cbSmillert.Pp 120dae54d7eSgrangeIf you don't intend to use TLS for authentication (and if you are using 1215828a48cSmillertself-signed certificates you probably don't) you can simply link 122*46e7f790Sjmcyour new certificate to 1235828a48cSmillert.Pa CAcert.pem . 1240d8a9824Sjmc.Pp 1250d8a9824Sjmc.Dl # ln -s /etc/mail/certs/mycert.pem /etc/mail/certs/CAcert.pem 1265828a48cSmillert.Pp 1275828a48cSmillertIf, on the other hand, you intend to use TLS for authentication 1285828a48cSmillertyou should install your certificate authority bundle as 1295828a48cSmillert.Pa /etc/mail/certs/CAcert.pem . 1305828a48cSmillert.Pp 1315828a48cSmillertAt this point, you no longer need the 1325828a48cSmillert.Pa dsa1024.pem 1335828a48cSmillertfile and it can be removed. 1340d8a9824Sjmc.Pp 1350d8a9824Sjmc.Dl # rm dsa1024.pem 1365828a48cSmillert.Pp 1375828a48cSmillertBecause the private key files are unencrypted, 1385828a48cSmillert.Xr sendmail 8 1395828a48cSmillertis picky about using tight permissions on those files. 1405828a48cSmillertThe certificate directory and the files therein should be 1415828a48cSmillertreadable and writable only by the owner (root). 1425828a48cSmillertA simple way to ensure this is to run the following: 1430d8a9824Sjmc.Pp 1440d8a9824Sjmc.Dl # chmod -R go-rwx /etc/mail/certs 145eefea0cbSmillert.Ss Creating a certificate with an existing private key 146eefea0cbSmillertThis example assumes you already have an existing private key, 147eefea0cbSmillert.Pa /etc/mail/certs/mykey.pem . 148eefea0cbSmillertYou can generate a new certificate based on this key using the command: 1490d8a9824Sjmc.Bd -literal -offset indent 1500d8a9824Sjmc# openssl req -x509 -new -days 365 -key /etc/mail/certs/mykey.pem \e 151eefea0cbSmillert -out /etc/mail/certs/mycert.pem 152eefea0cbSmillert# chmod 600 /etc/mail/certs/mycert.pem 153eefea0cbSmillert.Ed 154eefea0cbSmillert.Pp 155eefea0cbSmillertYou may adjust the lifetime of the certificate via the 156eefea0cbSmillert.Fl days 157eefea0cbSmillertparameter (one year in this example). 1587faf1a54Smillert.Ss Configuring sendmail to utilize TLS 1595828a48cSmillertThe global sendmail configuration files, 1605828a48cSmillert.Pa /etc/mail/sendmail.cf 1615828a48cSmillertand 1627b813f50Smillert.Pa /etc/mail/localhost.cf 1637b813f50Smillertmust be modified to support TLS functionality. 1647faf1a54SmillertAn example .mc file which has entries for TLS options, such as certificates, 1657faf1a54Smillertis available as 1667faf1a54Smillert.Pa /usr/share/sendmail/cf/knecht.mc . 1677faf1a54Smillert.Pp 1687faf1a54SmillertThe pertinent options are: 1695828a48cSmillert.Pp 1700d8a9824Sjmc.Bl -bullet -compact 1717faf1a54Smillert.It 1727faf1a54SmillertCERT_DIR 1737faf1a54Smillert.It 1747faf1a54SmillertconfCACERT_PATH 1757faf1a54Smillert.It 1767faf1a54SmillertconfCACERT 1777faf1a54Smillert.It 1787faf1a54SmillertconfSERVER_CERT 1797faf1a54Smillert.It 1807faf1a54SmillertconfSERVER_KEY 1817faf1a54Smillert.It 1827faf1a54SmillertconfCLIENT_CERT 1837faf1a54Smillert.It 1847faf1a54SmillertconfCLIENT_KEY 1857faf1a54Smillert.El 1867faf1a54Smillert.Pp 1877faf1a54SmillertBy default, the directory 1887faf1a54Smillert.Pa /etc/mail/certs , 1895828a48cSmillertdefined by CERT_DIR, is used to store certificates, and the server will 1905828a48cSmillertuse the same certificates both as a client (outgoing mail) and as a server 1915828a48cSmillert(for incoming mail). 1927faf1a54SmillertThis can be changed by having different entries for the respective roles. 1937faf1a54Smillert.Pp 1945828a48cSmillertThe next step is to edit the .mc files your 1957b813f50Smillert.Pa sendmail.cf 1965828a48cSmillertand 1977b813f50Smillert.Pa localhost.cf 1985828a48cSmillertfiles are generated from. 1995828a48cSmillertFirst, change to the directory where your .mc files are stored. 2005828a48cSmillertYou will need to make TLS-enabled versions of the following files: 2017b813f50Smillert.Pa openbsd-proto.mc 2025828a48cSmillertand 2037b813f50Smillert.Pa openbsd-localhost.mc . 2040d8a9824Sjmc.Bd -literal -offset indent 2059d314f1eSmillert# cd /usr/share/sendmail/cf 2065828a48cSmillert 2075828a48cSmillert# cp openbsd-proto.mc openbsd-proto-tls.mc 2087b813f50Smillert# cp openbsd-localhost.mc openbsd-localhost-tls.mc 2097faf1a54Smillert.Ed 2107faf1a54Smillert.Pp 2117b813f50SmillertYou must then edit 2125828a48cSmillert.Pa openbsd-proto-tls.mc , 2135828a48cSmillertand 2147b813f50Smillert.Pa openbsd-localhost-tls.mc 2155828a48cSmillertto add the following lines after the 2165828a48cSmillert.Dq VERSIONID 2175828a48cSmillertdefinition (the actual placement within the file is not critical as long 2185828a48cSmillertas it is after the 2195828a48cSmillert.Dq divert(0)dnl 2205828a48cSmillertline). 2210d8a9824Sjmc.Bd -literal -offset indent 2225828a48cSmillertdefine(`CERT_DIR', `MAIL_SETTINGS_DIR`'certs') 2235828a48cSmillertdefine(`confCACERT_PATH', `CERT_DIR') 2245828a48cSmillertdefine(`confCACERT', `CERT_DIR/CAcert.pem') 2255828a48cSmillertdefine(`confSERVER_CERT', `CERT_DIR/mycert.pem') 2265828a48cSmillertdefine(`confSERVER_KEY', `CERT_DIR/mykey.pem') 2275828a48cSmillertdefine(`confCLIENT_CERT', `CERT_DIR/mycert.pem') 2285828a48cSmillertdefine(`confCLIENT_KEY', `CERT_DIR/mykey.pem') 2295828a48cSmillert.Ed 2305828a48cSmillert.Pp 2315828a48cSmillertNow that you have the TLS-enabled versions of the .mc files 2325828a48cSmillertyou must generate .cf files from them and install the .cf 2335828a48cSmillertfiles in 2345828a48cSmillert.Pa /etc/mail . 2350d8a9824Sjmc.Bd -literal -offset indent 2367b813f50Smillert# make openbsd-proto-tls.cf openbsd-localhost-tls.cf 2375828a48cSmillert 2385828a48cSmillert# cp openbsd-proto-tls.cf /etc/mail/sendmail.cf 2397b813f50Smillert# cp openbsd-localhost-tls.cf /etc/mail/localhost.cf 2405828a48cSmillert.Ed 2415828a48cSmillert.Pp 2425828a48cSmillertFinally, restart sendmail with the new configuration by sending 2435828a48cSmillertit a 2445828a48cSmillert.Dv SIGHUP . 2450d8a9824Sjmc.Pp 2460d8a9824Sjmc.Dl # kill -HUP `head -1 /var/run/sendmail.pid` 2475828a48cSmillert.Pp 2485828a48cSmillertNote that those are backticks and not single quotes in the example above. 2495828a48cSmillert.Pp 2505828a48cSmillertAfter having installed the certificates and configuration files and having 2517faf1a54Smillertrestarted the sendmail daemon, a new option should be presented for ESMTP 2527faf1a54Smillerttransactions, STARTTLS. 2535828a48cSmillertYou can test this by connecting to the local host and issuing the 2545828a48cSmillert.Dq EHLO 2555828a48cSmillertcommand. 2560d8a9824Sjmc.Bd -literal -offset indent 2575828a48cSmillert# telnet localhost 25 2585828a48cSmillertTrying ::1... 2595828a48cSmillertConnected to localhost. 2605828a48cSmillertEscape character is '^]'. 2615828a48cSmillert220 localhost ESMTP Sendmail 8.12.1/8.12.1 ready 2625828a48cSmillertEHLO localhost 2635828a48cSmillert.Ed 2645828a48cSmillert.Pp 2655828a48cSmillertAfter typing 2665828a48cSmillert.Em EHLO localhost 2675828a48cSmillertyou should receive something like the following back. 2680d8a9824Sjmc.Bd -literal -offset indent 2695828a48cSmillert250-localhost Hello localhost [IPv6:::1], pleased to meet you 2705828a48cSmillert250-ENHANCEDSTATUSCODES 2715828a48cSmillert250-PIPELINING 2725828a48cSmillert250-8BITMIME 2735828a48cSmillert250-SIZE 2745828a48cSmillert250-DSN 2755828a48cSmillert250-ETRN 2765828a48cSmillert250-STARTTLS 2775828a48cSmillert250-DELIVERBY 2785828a48cSmillert250 HELP 2795828a48cSmillert.Ed 2805828a48cSmillert.Pp 2815828a48cSmillertYou should see 2825828a48cSmillert.Dq STARTTLS 2835828a48cSmillertlisted along with the other options. 2845828a48cSmillertIf so, congratulations, sendmail will now use TLS to encrypt your mail 2855828a48cSmillerttraffic when the remote server supports it. 2865828a48cSmillertIf not, check 28719e53896Smillert.Pa /var/log/maillog 2885828a48cSmillertto see whether sendmail has reported any security problems or other errors. 2897faf1a54Smillert.Ss Uses for TLS-Equipped sendmail 2907faf1a54SmillertThe most obvious use of a cryptographically enabled sendmail installation 2917faf1a54Smillertis for confidentiality of the electronic mail transaction and the 2927faf1a54Smillertintegrity checking provided by the cipher suite. 2937faf1a54SmillertAll traffic between the two mail servers is encrypted, including the 2947faf1a54Smillertsender and recipient addresses. 2957faf1a54SmillertTLS also allows for authentication of either or both systems in the transaction. 2967faf1a54Smillert.Pp 2977faf1a54SmillertOne use of public key cryptography is for strong authentication. 2987faf1a54SmillertWe can use this authentication to selectively relay clients, including 2997faf1a54Smillertother mail servers and mobile clients like laptops. 3007faf1a54SmillertHowever, there have been some problems getting some mail clients to work using 3017faf1a54Smillertcertificate-based authentication. 3027faf1a54SmillertNote that your clients will have to generate certificates and have them 3037faf1a54Smillertsigned (for trust validation) by a CA (certificate authority) you also trust, 3047faf1a54Smillertif you configure your server to do client certificate checking. 3057faf1a54Smillert.Pp 3067faf1a54SmillertThe use of the access map (usually 3077faf1a54Smillert.Pa /etc/mail/access ) , 3087faf1a54Smillertwhich is normally used to determine connections and relaying, 3097faf1a54Smillertcan also be extended to give server level control for the use of TLS. 3107faf1a54SmillertTwo new entries are available for TLS options: 3117faf1a54Smillert.Bl -tag -width Ds -offset indent 3127faf1a54Smillert.It VERIFY 3137faf1a54Smillertcontains the status of the level of verification (held in the macro {verify}) 3147faf1a54Smillert.It ENCR 3157faf1a54Smillertthe strength of the encryption (in the macro {cipher_bits}) 3167faf1a54Smillert.El 3177faf1a54Smillert.Pp 3187faf1a54SmillertVERIFY can also accept the argument for {cipher_bits}. 3197faf1a54SmillertHere are a few example entries that illustrate these features, and 3207faf1a54Smillertthe role based granularity as well: 3210d8a9824Sjmc.Pp 3227dbb7873SjmcForce strong (112-bit) encryption for communications for this server: 3230d8a9824Sjmc.Pp 3247740bb94Sdavid.Dl server1.example.net ENCR:112 3250d8a9824Sjmc.Pp 3260d8a9824SjmcFor a TLS client, force string verification depths to at least 80 bits: 3277740bb94Sdavid.Pp 328b8d462b6Smillert.Dl TLS_Clt:desktop.example.net VERIFY:80 3297faf1a54Smillert.Pp 3307faf1a54SmillertMuch more complicated access maps are possible, and error conditions (such 3317faf1a54Smillertas permanent or temporary, PERM+ or TEMP+) can be set on the basis of 3327faf1a54Smillertvarious criteria. 3337faf1a54SmillertThis allows you fine-grained control over the types of connections you 3347faf1a54Smillertcan allow. 3357faf1a54Smillert.Pp 3367faf1a54SmillertNote that it is unwise to force all SMTP clients to use TLS, as it is not 3377faf1a54Smillertyet widespread. 3387faf1a54SmillertThe RFC document notes that publicly referenced SMTP servers, such as the 3397faf1a54SmillertMX servers for a domain, must not refuse non-TLS connections. 3407faf1a54SmillertHowever, restricted access SMTP servers, such as those for a corporate 3417faf1a54Smillertintranet, can use TLS as an access control mechanism. 3427faf1a54Smillert.Sh LIMITATIONS 3437faf1a54SmillertOne often forgotten limitation of using TLS on a mail server is the 3447faf1a54Smillertpayload of the mail message and the resulting security there. 3457faf1a54SmillertMany virus and worm files are now distributed via electronic mail. 3467faf1a54SmillertWhile the mail may be encrypted and the servers authenticated, the payload 3477faf1a54Smillertcan still be malicious. 3487faf1a54SmillertThe use of a good content protection program on the desktop is 3497faf1a54Smillerttherefore still of value even with TLS at the MTA level. 3507faf1a54Smillert.Pp 3517faf1a54SmillertBecause sendmail with TLS can only authenticate at the server level, true 3527faf1a54Smillertend-to-end authentication of the mail message cannot be performed with 3537faf1a54Smillertonly the use of STARTLS on the server. 3547faf1a54SmillertThe use of S/MIME or PGP e-mail and trustworthy key hierarchies can guarantee 3557faf1a54Smillertfull confidentiality and integrity of the entire message path. 3567faf1a54Smillert.Pp 3577faf1a54SmillertFurthermore, if a mail message traverses more than just the starting and 3587faf1a54Smillertending servers, there is no way to control interactions between the intervening 3597faf1a54Smillertmail servers, which may use non-secure connections. 3607faf1a54SmillertThis introduces a point of vulnerability in the chain. 3617faf1a54Smillert.Pp 3627faf1a54SmillertAdditionally, SMTP over TLS is not yet widely implemented. 3637faf1a54SmillertThe standard, in fact, doesn't require it, leaving it only as an option, though 3647faf1a54Smillertspecific sites can configure their servers to force it for specific clients. 3655828a48cSmillertAs such, it is difficult to foresee the widespread use of SMTP using TLS, 3667faf1a54Smillertdespite the fact that the standard is, at the date of this writing, 3677faf1a54Smillertover two years old. 3687faf1a54Smillert.Pp 3697faf1a54SmillertLastly, interoperability problems can appear between different implementations. 3707faf1a54Smillert.Sh SEE ALSO 3715828a48cSmillert.Xr mail 1 , 3727faf1a54Smillert.Xr openssl 1 , 3737faf1a54Smillert.Xr afterboot 8 , 3747faf1a54Smillert.Xr sendmail 8 , 3757faf1a54Smillert.Xr ssl 8 3767faf1a54Smillert.Pp 3777faf1a54Smillert.Tn DARPA 3780d8a9824SjmcInternet Request for Comments RFC 2487 3797faf1a54Smillert.Pp 3805828a48cSmillerthttp://www.sendmail.org/~ca/email/starttls.html 3817faf1a54Smillert.Sh HISTORY 3827faf1a54SmillertTLS features first appeared in sendmail 8.11. 383