xref: /openbsd/share/man/man8/starttls.8 (revision 1c80ab25)
1*1c80ab25Sjmc.\" $OpenBSD: starttls.8,v 1.26 2018/06/27 05:39:02 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.\"
26*1c80ab25Sjmc.Dd $Mdocdate: June 27 2018 $
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
105dae54d7eSgrangeIf you don't intend to use TLS for authentication (and if you are using
1065828a48cSmillertself-signed certificates you probably don't) you can simply link
10746e7f790Sjmcyour new certificate to
1084a92a028Sjmc.Pa cert.pem :
1090d8a9824Sjmc.Pp
1104a92a028Sjmc.Dl # ln -s /etc/ssl/mail.example.com.crt /etc/ssl/cert.pem
1115828a48cSmillert.Pp
1125828a48cSmillertIf, on the other hand, you intend to use TLS for authentication
1134a92a028Sjmcyou should add your certificate authority bundle to
1144a92a028Sjmc.Pa /etc/ssl/cert.pem
1154a92a028Sjmc(or whatever your software expects).
1165828a48cSmillert.Pp
1175828a48cSmillertBecause the private key files are unencrypted,
1184a92a028SjmcMTAs can be picky about using tight permissions on those files.
1195828a48cSmillertThe certificate directory and the files therein should be
1205828a48cSmillertreadable and writable only by the owner (root).
1215828a48cSmillertA simple way to ensure this is to run the following:
1220d8a9824Sjmc.Pp
12309a15da0Sjmc.Dl # chmod -R go-rwx /etc/ssl/private
124eefea0cbSmillert.Ss Creating a certificate with an existing private key
125eefea0cbSmillertThis example assumes you already have an existing private key,
126d0099e99Smillert.Pa /etc/ssl/private/mail.example.com.key .
127eefea0cbSmillertYou can generate a new certificate based on this key using the command:
1280d8a9824Sjmc.Bd -literal -offset indent
129d0099e99Smillert# openssl req -x509 -new -key /etc/ssl/private/mail.example.com.key \e
130d0099e99Smillert  -out /etc/ssl/mail.example.com.crt -days 365
131712ac6d2Sjmc# chmod 600 /etc/ssl/mail.example.com.crt
132eefea0cbSmillert.Ed
133eefea0cbSmillert.Pp
134eefea0cbSmillertYou may adjust the lifetime of the certificate via the
135eefea0cbSmillert.Fl days
136eefea0cbSmillertparameter (one year in this example).
1377faf1a54Smillert.Pp
13809a15da0SjmcAfter having installed the certificates
139d0099e99Smillertthe mail server needs to be configured to accept TLS sessions
140d0099e99Smillertand use the key and certificate.
14109a15da0SjmcFor
14209a15da0Sjmc.Xr smtpd 8 ,
143d0099e99Smillertit's as simple as adding pki configuration to
14409a15da0Sjmc.Xr smtpd.conf 5 :
145d0099e99Smillert.Bd -literal -offset indent
146*1c80ab25Sjmcpki mail.example.com cert "/etc/ssl/mail.example.com.crt"
147d0099e99Smillertpki mail.example.com key "/etc/ssl/private/mail.example.com.key"
148d0099e99Smillert
149d0099e99Smillertlisten on [...] tls pki mail.example.com auth
150d0099e99Smillert.Ed
1517faf1a54Smillert.Pp
15209a15da0SjmcAfter restarting the mail server, a new option should be presented for ESMTP
1537faf1a54Smillerttransactions, STARTTLS.
1545828a48cSmillertYou can test this by connecting to the local host and issuing the
1555828a48cSmillert.Dq EHLO
1565828a48cSmillertcommand.
1570d8a9824Sjmc.Bd -literal -offset indent
1585828a48cSmillert# telnet localhost 25
15909a15da0SjmcTrying 127.0.0.1...
1605828a48cSmillertConnected to localhost.
1615828a48cSmillertEscape character is '^]'.
16209a15da0Sjmc220 localhost ESMTP OpenSMTPD
1635828a48cSmillertEHLO localhost
1645828a48cSmillert.Ed
1655828a48cSmillert.Pp
1665828a48cSmillertAfter typing
1675828a48cSmillert.Em EHLO localhost
1685828a48cSmillertyou should receive something like the following back.
1690d8a9824Sjmc.Bd -literal -offset indent
17009a15da0Sjmc250-localhost Hello localhost [127.0.0.1], pleased to meet you
1715828a48cSmillert250-8BITMIME
17209a15da0Sjmc250-ENHANCEDSTATUSCODES
17309a15da0Sjmc250-SIZE 36700160
1745828a48cSmillert250-DSN
1755828a48cSmillert250-STARTTLS
1765828a48cSmillert250 HELP
1775828a48cSmillert.Ed
1785828a48cSmillert.Pp
1795828a48cSmillertYou should see
1805828a48cSmillert.Dq STARTTLS
1815828a48cSmillertlisted along with the other options.
18209a15da0SjmcIf so, congratulations, the MTA will now use TLS to encrypt your mail
1835828a48cSmillerttraffic when the remote server supports it.
1845828a48cSmillertIf not, check
18519e53896Smillert.Pa /var/log/maillog
18609a15da0Sjmcto see whether the MTA has reported any security problems or other errors.
18709a15da0Sjmc.Ss Uses for TLS equipped MTAs
18809a15da0SjmcThe most obvious use of a cryptographically enabled MTA
1897faf1a54Smillertis for confidentiality of the electronic mail transaction and the
1907faf1a54Smillertintegrity checking provided by the cipher suite.
1917faf1a54SmillertAll traffic between the two mail servers is encrypted, including the
1927faf1a54Smillertsender and recipient addresses.
1937faf1a54SmillertTLS also allows for authentication of either or both systems in the transaction.
1947faf1a54Smillert.Pp
1957faf1a54SmillertOne use of public key cryptography is for strong authentication.
1967faf1a54SmillertWe can use this authentication to selectively relay clients, including
1977faf1a54Smillertother mail servers and mobile clients like laptops.
1987faf1a54SmillertHowever, there have been some problems getting some mail clients to work using
1997faf1a54Smillertcertificate-based authentication.
2004a92a028SjmcClients will have to generate certificates and have them
2014a92a028Sjmcsigned (for trust validation) by a trusted CA (certificate authority).
2027faf1a54Smillert.Pp
2037faf1a54SmillertNote that it is unwise to force all SMTP clients to use TLS, as it is not
2047faf1a54Smillertyet widespread.
2057faf1a54SmillertThe RFC document notes that publicly referenced SMTP servers, such as the
2067faf1a54SmillertMX servers for a domain, must not refuse non-TLS connections.
2077faf1a54SmillertHowever, restricted access SMTP servers, such as those for a corporate
2087faf1a54Smillertintranet, can use TLS as an access control mechanism.
20909a15da0Sjmc.Sh SEE ALSO
21009a15da0Sjmc.Xr mail 1 ,
21109a15da0Sjmc.Xr openssl 1 ,
21209a15da0Sjmc.Xr smtpd 8 ,
21309a15da0Sjmc.Xr ssl 8
21409a15da0Sjmc.Sh STANDARDS
21509a15da0Sjmc.Rs
21609a15da0Sjmc.%A P. Hoffman
21709a15da0Sjmc.%D February 2002
21809a15da0Sjmc.%R RFC 3207
21909a15da0Sjmc.%T SMTP Service Extension for Secure SMTP over Transport Layer Security
22009a15da0Sjmc.Re
22109a15da0Sjmc.Sh CAVEATS
2227faf1a54SmillertOne often forgotten limitation of using TLS on a mail server is the
2237faf1a54Smillertpayload of the mail message and the resulting security there.
2247faf1a54SmillertMany virus and worm files are now distributed via electronic mail.
2257faf1a54SmillertWhile the mail may be encrypted and the servers authenticated, the payload
2267faf1a54Smillertcan still be malicious.
2277faf1a54SmillertThe use of a good content protection program on the desktop is
2287faf1a54Smillerttherefore still of value even with TLS at the MTA level.
2297faf1a54Smillert.Pp
23009a15da0SjmcBecause TLS can only authenticate at the server level, true
2317faf1a54Smillertend-to-end authentication of the mail message cannot be performed with
232d6b898c0Sjmconly the use of STARTTLS on the server.
2337f0be37cSmmccThe use of S/MIME or PGP email and trustworthy key hierarchies can guarantee
2347faf1a54Smillertfull confidentiality and integrity of the entire message path.
2357faf1a54Smillert.Pp
2367faf1a54SmillertFurthermore, if a mail message traverses more than just the starting and
2377faf1a54Smillertending servers, there is no way to control interactions between the intervening
2387faf1a54Smillertmail servers, which may use non-secure connections.
2397faf1a54SmillertThis introduces a point of vulnerability in the chain.
2407faf1a54Smillert.Pp
2417faf1a54SmillertAdditionally, SMTP over TLS is not yet widely implemented.
2427faf1a54SmillertThe standard, in fact, doesn't require it, leaving it only as an option, though
2437faf1a54Smillertspecific sites can configure their servers to force it for specific clients.
2445828a48cSmillertAs such, it is difficult to foresee the widespread use of SMTP using TLS,
2457faf1a54Smillertdespite the fact that the standard is, at the date of this writing,
2467faf1a54Smillertover two years old.
2477faf1a54Smillert.Pp
2487faf1a54SmillertLastly, interoperability problems can appear between different implementations.
249