xref: /openbsd/share/man/man8/starttls.8 (revision 41ce3b17)
1*41ce3b17Snaddy.\" $OpenBSD: starttls.8,v 1.28 2022/03/31 17:27:23 naddy 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.\"
26*41ce3b17Snaddy.Dd $Mdocdate: March 31 2022 $
277faf1a54Smillert.Dt STARTTLS 8
2853affce0Smillert.Os
297faf1a54Smillert.Sh NAME
307faf1a54Smillert.Nm starttls
315828a48cSmillert.Nd ESMTP over TLS/SSL
327faf1a54Smillert.Sh DESCRIPTION
333175ab57SgrunkSTARTTLS is an ESMTP option, defined in RFC 3207, which is used to conduct
347faf1a54SmillertESMTP transactions over TLS circuits.
357faf1a54SmillertThis is used to increase the security of mail server transactions.
367faf1a54Smillert.Pp
377faf1a54SmillertSTARTTLS allows for the combination of several security solutions for MTA
387faf1a54Smillert(mail transport agent) level services through the TLS suite.
397faf1a54SmillertThese security features include:
407faf1a54Smillert.Bl -tag -width Ds
417faf1a54Smillert.It Confidentiality
427faf1a54SmillertEncryption is used to protect data from passive monitoring.
437faf1a54SmillertAn attacker would have to recover the encryption key used to
447faf1a54Smillertdecode the transmitted data.
457faf1a54Smillert.It Integrity
467faf1a54SmillertHash algorithms are used to ensure the integrity of the
477faf1a54Smillerttransmitted data, and alternatively the timestamp, protecting against a
487faf1a54Smillertreplay attack.
497faf1a54SmillertThis protects data from modification in transit.
507faf1a54Smillert.It Authentication
517faf1a54SmillertThe use of public key encryption allows for the strong authentication of
527faf1a54Smillerteither, or both, communicating parties.
537faf1a54SmillertThis can be used to allow for select features, such as relaying,
547faf1a54Smillertto be controlled more securely.
557faf1a54Smillert.El
567faf1a54Smillert.Pp
577faf1a54SmillertA new ESMTP option, STARTTLS, has been added.
587faf1a54SmillertThis is presented by the server when an ESMTP session is initiated.
597faf1a54SmillertThe client then begins the TLS portion of the ESMTP session by issuing
607faf1a54Smillertthe command
617faf1a54Smillert.Dq STARTTLS .
627faf1a54SmillertThe remaining portion of the ESMTP session occurs over a TLS channel.
6309a15da0Sjmc.Ss Creating a private key and certificate for an MTA
645828a48cSmillertThis example assumes you are creating your own self-signed certificates
6509a15da0Sjmcfor use with
6609a15da0Sjmc.Xr smtpd 8
6709a15da0Sjmcand STARTTLS.
68eefea0cbSmillertIf you have an existing private key and you simply wish to generate
69eefea0cbSmillerta new certificate (for example, if your old certificate has expired),
70eefea0cbSmillertsee the section entitled
7109a15da0Sjmc.Sx Creating a certificate with an existing private key .
72eefea0cbSmillert.Pp
735828a48cSmillertFor the purposes of this example the certificates will be stored in
7409a15da0Sjmc.Pa /etc/ssl ,
755828a48cSmillertthough it is possible to use a different directory if needed.
765828a48cSmillert.Pp
77d0099e99SmillertNext, you must generate an
78d0099e99Smillert.Ar RSA
79d0099e99Smillertprivate key:
800d8a9824Sjmc.Pp
81d0099e99Smillert.Dl # openssl genrsa -out /etc/ssl/private/mail.example.com.key 4096
825828a48cSmillert.Pp
83d0099e99SmillertThis would generate a 4096-bit
84d0099e99Smillert.Ar RSA
85d0099e99Smillertkey stored in the file
86d0099e99Smillert.Pa mail.example.com.key .
875828a48cSmillert.Pp
88d0099e99SmillertOnce you have generated the
89d0099e99Smillert.Ar RSA
90d0099e99Smillertkey, you can generate a certificate from it using the command:
910d8a9824Sjmc.Bd -literal -offset indent
92d0099e99Smillert# openssl req -x509 -new -key /etc/ssl/private/mail.example.com.key \e
93d0099e99Smillert  -out /etc/ssl/mail.example.com.crt -days 365
945828a48cSmillert.Ed
955828a48cSmillert.Pp
96eefea0cbSmillertYou may adjust the lifetime of the certificate via the
97eefea0cbSmillert.Fl days
98eefea0cbSmillertparameter (one year in this example).
99eefea0cbSmillert.Pp
100eefea0cbSmillertYou can verify that the newly-generated certificate has correct information
101eefea0cbSmillertwith the following command:
1020d8a9824Sjmc.Pp
103d0099e99Smillert.Dl # openssl x509 -in /etc/ssl/mail.example.com.crt -text
104eefea0cbSmillert.Pp
1055828a48cSmillertBecause the private key files are unencrypted,
1064a92a028SjmcMTAs can be picky about using tight permissions on those files.
1075828a48cSmillertThe certificate directory and the files therein should be
1085828a48cSmillertreadable and writable only by the owner (root).
1095828a48cSmillertA simple way to ensure this is to run the following:
1100d8a9824Sjmc.Pp
11109a15da0Sjmc.Dl # chmod -R go-rwx /etc/ssl/private
112eefea0cbSmillert.Ss Creating a certificate with an existing private key
113eefea0cbSmillertThis example assumes you already have an existing private key,
114d0099e99Smillert.Pa /etc/ssl/private/mail.example.com.key .
115eefea0cbSmillertYou can generate a new certificate based on this key using the command:
1160d8a9824Sjmc.Bd -literal -offset indent
117d0099e99Smillert# openssl req -x509 -new -key /etc/ssl/private/mail.example.com.key \e
118d0099e99Smillert  -out /etc/ssl/mail.example.com.crt -days 365
119712ac6d2Sjmc# chmod 600 /etc/ssl/mail.example.com.crt
120eefea0cbSmillert.Ed
121eefea0cbSmillert.Pp
122eefea0cbSmillertYou may adjust the lifetime of the certificate via the
123eefea0cbSmillert.Fl days
124eefea0cbSmillertparameter (one year in this example).
1257faf1a54Smillert.Pp
126*41ce3b17SnaddyAfter having installed the certificates,
127d0099e99Smillertthe mail server needs to be configured to accept TLS sessions
128d0099e99Smillertand use the key and certificate.
12909a15da0SjmcFor
13009a15da0Sjmc.Xr smtpd 8 ,
131d0099e99Smillertit's as simple as adding pki configuration to
13209a15da0Sjmc.Xr smtpd.conf 5 :
133d0099e99Smillert.Bd -literal -offset indent
1341c80ab25Sjmcpki mail.example.com cert "/etc/ssl/mail.example.com.crt"
135d0099e99Smillertpki mail.example.com key "/etc/ssl/private/mail.example.com.key"
136d0099e99Smillert
137d0099e99Smillertlisten on [...] tls pki mail.example.com auth
138d0099e99Smillert.Ed
1397faf1a54Smillert.Pp
14009a15da0SjmcAfter restarting the mail server, a new option should be presented for ESMTP
1417faf1a54Smillerttransactions, STARTTLS.
1425828a48cSmillertYou can test this by connecting to the local host and issuing the
1435828a48cSmillert.Dq EHLO
1445828a48cSmillertcommand.
1450d8a9824Sjmc.Bd -literal -offset indent
1465828a48cSmillert# telnet localhost 25
14709a15da0SjmcTrying 127.0.0.1...
1485828a48cSmillertConnected to localhost.
1495828a48cSmillertEscape character is '^]'.
15009a15da0Sjmc220 localhost ESMTP OpenSMTPD
1515828a48cSmillertEHLO localhost
1525828a48cSmillert.Ed
1535828a48cSmillert.Pp
1545828a48cSmillertAfter typing
155*41ce3b17Snaddy.Em EHLO localhost ,
1565828a48cSmillertyou should receive something like the following back.
1570d8a9824Sjmc.Bd -literal -offset indent
15809a15da0Sjmc250-localhost Hello localhost [127.0.0.1], pleased to meet you
1595828a48cSmillert250-8BITMIME
16009a15da0Sjmc250-ENHANCEDSTATUSCODES
16109a15da0Sjmc250-SIZE 36700160
1625828a48cSmillert250-DSN
1635828a48cSmillert250-STARTTLS
1645828a48cSmillert250 HELP
1655828a48cSmillert.Ed
1665828a48cSmillert.Pp
1675828a48cSmillertYou should see
1685828a48cSmillert.Dq STARTTLS
1695828a48cSmillertlisted along with the other options.
17009a15da0SjmcIf so, congratulations, the MTA will now use TLS to encrypt your mail
1715828a48cSmillerttraffic when the remote server supports it.
1725828a48cSmillertIf not, check
17319e53896Smillert.Pa /var/log/maillog
17409a15da0Sjmcto see whether the MTA has reported any security problems or other errors.
17509a15da0Sjmc.Ss Uses for TLS equipped MTAs
17609a15da0SjmcThe most obvious use of a cryptographically enabled MTA
1777faf1a54Smillertis for confidentiality of the electronic mail transaction and the
1787faf1a54Smillertintegrity checking provided by the cipher suite.
1797faf1a54SmillertAll traffic between the two mail servers is encrypted, including the
1807faf1a54Smillertsender and recipient addresses.
1817faf1a54SmillertTLS also allows for authentication of either or both systems in the transaction.
1827faf1a54Smillert.Pp
1837faf1a54SmillertOne use of public key cryptography is for strong authentication.
1847faf1a54SmillertWe can use this authentication to selectively relay clients, including
1857faf1a54Smillertother mail servers and mobile clients like laptops.
1867faf1a54SmillertHowever, there have been some problems getting some mail clients to work using
1877faf1a54Smillertcertificate-based authentication.
1884a92a028SjmcClients will have to generate certificates and have them
1894a92a028Sjmcsigned (for trust validation) by a trusted CA (certificate authority).
1907faf1a54Smillert.Pp
1917faf1a54SmillertNote that it is unwise to force all SMTP clients to use TLS, as it is not
1927faf1a54Smillertyet widespread.
1937faf1a54SmillertThe RFC document notes that publicly referenced SMTP servers, such as the
1947faf1a54SmillertMX servers for a domain, must not refuse non-TLS connections.
1957faf1a54SmillertHowever, restricted access SMTP servers, such as those for a corporate
1967faf1a54Smillertintranet, can use TLS as an access control mechanism.
19709a15da0Sjmc.Sh SEE ALSO
19809a15da0Sjmc.Xr mail 1 ,
19909a15da0Sjmc.Xr openssl 1 ,
20009a15da0Sjmc.Xr smtpd 8 ,
20109a15da0Sjmc.Xr ssl 8
20209a15da0Sjmc.Sh STANDARDS
20309a15da0Sjmc.Rs
20409a15da0Sjmc.%A P. Hoffman
20509a15da0Sjmc.%D February 2002
20609a15da0Sjmc.%R RFC 3207
20709a15da0Sjmc.%T SMTP Service Extension for Secure SMTP over Transport Layer Security
20809a15da0Sjmc.Re
20909a15da0Sjmc.Sh CAVEATS
2107faf1a54SmillertOne often forgotten limitation of using TLS on a mail server is the
2117faf1a54Smillertpayload of the mail message and the resulting security there.
2127faf1a54SmillertMany virus and worm files are now distributed via electronic mail.
2137faf1a54SmillertWhile the mail may be encrypted and the servers authenticated, the payload
2147faf1a54Smillertcan still be malicious.
2157faf1a54SmillertThe use of a good content protection program on the desktop is
2167faf1a54Smillerttherefore still of value even with TLS at the MTA level.
2177faf1a54Smillert.Pp
21809a15da0SjmcBecause TLS can only authenticate at the server level, true
2197faf1a54Smillertend-to-end authentication of the mail message cannot be performed with
220d6b898c0Sjmconly the use of STARTTLS on the server.
2217f0be37cSmmccThe use of S/MIME or PGP email and trustworthy key hierarchies can guarantee
2227faf1a54Smillertfull confidentiality and integrity of the entire message path.
2237faf1a54Smillert.Pp
2247faf1a54SmillertFurthermore, if a mail message traverses more than just the starting and
2257faf1a54Smillertending servers, there is no way to control interactions between the intervening
2267faf1a54Smillertmail servers, which may use non-secure connections.
2277faf1a54SmillertThis introduces a point of vulnerability in the chain.
2287faf1a54Smillert.Pp
2297faf1a54SmillertAdditionally, SMTP over TLS is not yet widely implemented.
2307faf1a54SmillertThe standard, in fact, doesn't require it, leaving it only as an option, though
2317faf1a54Smillertspecific sites can configure their servers to force it for specific clients.
2325828a48cSmillertAs such, it is difficult to foresee the widespread use of SMTP using TLS,
2337faf1a54Smillertdespite the fact that the standard is, at the date of this writing,
2347faf1a54Smillertover two years old.
2357faf1a54Smillert.Pp
2367faf1a54SmillertLastly, interoperability problems can appear between different implementations.
237