RFC 3207

SMTP Service Extension for Secure SMTP over Transport Layer Security

๐Ÿ“… published February 2002, from ietf

RFC 3207: SMTP Service Extension for Secure SMTP over Transport Layer Security ๐ŸŽ€

okay bestie, RFC 3207 is from February 2002 ๐Ÿ“… and it's a Standards Track doc, so it's a real spec, not just vibes. It was written by P. Hoffman from the Internet Mail Consortium for the Network Working Group ๐Ÿงš and it obsoletes RFC 2487. It doesn't update anything else. Let's get into it ๐Ÿ’…

Status of this Memo โœจ

this doc is an Internet standards track protocol for the Internet community, and it's asking for discussion and suggestions for improvements ๐Ÿซถ for the standardization state and status of this protocol, check the current "Internet Official Protocol Standards" (STD 1). distribution of this memo is unlimited, so share away ๐Ÿฆ‹

Copyright (C) The Internet Society (2002). All Rights Reserved.

Abstract ๐Ÿ’œ

this doc describes an extension to SMTP (Simple Mail Transfer Protocol) that lets an SMTP server and client use TLS (Transport Layer Security) to get private, authenticated communication over the Internet ๐Ÿ” so SMTP agents can protect some or all of their messages from eavesdroppers and attackers. no more letting the nosy people read your mail ๐Ÿ‘€

1. Introduction ๐Ÿฆ‹

okay so SMTP [RFC2821] servers and clients normally talk in the clear over the Internet, which is lowkey terrifying ๐Ÿ˜ญ a lot of the time that traffic goes through one or more routers that neither side controls or trusts. an untrusted router could let some third party snoop on or mess with the conversation between server and client ๐Ÿ’€

it's also really common for two SMTP agents to want to verify each other's identities ๐Ÿชช like, a secure SMTP server might only accept messages from other agents it already knows, or it might treat messages from known agents differently than from strangers. main character behavior ๐Ÿ‘‘

TLS [TLS], more commonly known as SSL, is the popular way to add privacy and authentication on top of TCP ๐Ÿ’– it's everywhere with HTTP, and it's also getting added to a bunch of other protocols that run over TCP. iykyk ๐Ÿ˜Œ

this document obsoletes RFC 2487. ๐Ÿ“œ

1.1 Terminology ๐Ÿ’…

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in [RFC2119]. โœจ

2. STARTTLS Extension ๐ŸŽ€

the STARTTLS extension to SMTP is set up like this ๐Ÿงš

  • (1) the name of the SMTP service defined here is STARTTLS;
  • (2) the EHLO keyword value associated with the extension is STARTTLS;
  • (3) the STARTTLS keyword has no parameters;
  • (4) a new SMTP verb, STARTTLS, is defined;
  • (5) no additional parameters are added to any SMTP command.

3. The STARTTLS Keyword ๐ŸŒˆ

the STARTTLS keyword is how the server tells the client that it's currently able to negotiate TLS ๐Ÿ”ฅ it takes no parameters, so it's giving simple and clean ๐Ÿ’…

4. The STARTTLS Command ๐Ÿ’–

the format for the STARTTLS command is just this, with no parameters ๐Ÿ“

STARTTLS

after the client sends the STARTTLS command, the server answers with one of these reply codes ๐Ÿงš

220 Ready to start TLS
501 Syntax error (no parameters allowed)
454 TLS not available due to temporary reason

if the client gets the 454 response, it's on the client to decide whether to keep the SMTP session going ๐Ÿค” that call is based on local policy. for example, if TLS was being used for client authentication, the client might try to keep going, in case the server lets it through even with no authentication. but if TLS was being negotiated for encryption, a client that gets a 454 has to figure out whether to send the message anyway with no TLS encryption, whether to wait and try again later, or whether to give up and tell the sender about the error ๐Ÿ˜ญ

a publicly-referenced SMTP server MUST NOT require use of the STARTTLS extension in order to deliver mail locally ๐Ÿšซ this rule keeps STARTTLS from wrecking the interoperability of the Internet's SMTP infrastructure, which is a huge deal ๐Ÿ’œ a publicly-referenced SMTP server is one that runs on port 25 of an Internet host listed in the MX record (or A record if an MX record is not present) for the domain name on the right hand side of an Internet mail address ๐Ÿฆ‹

any SMTP server may refuse to accept messages for relay based on authentication supplied during the TLS negotiation ๐Ÿ™…โ€โ™€๏ธ and an SMTP server that is not publicly referenced may refuse to accept any messages for relay or local delivery based on authentication supplied during the TLS negotiation. that's its call ๐Ÿ’…

a SMTP server that is not publicly referenced may choose to require that the client do a TLS negotiation before accepting any commands ๐Ÿ” in that case, the server SHOULD return this reply code:

530 Must issue a STARTTLS command first

to every command other than NOOP, EHLO, STARTTLS, or QUIT. if the client and server are using the ENHANCEDSTATUSCODES ESMTP extension [RFC2034], the status code to be returned SHOULD be 5.7.0. โœจ

after the client gets a 220 response to a STARTTLS command, it MUST start the TLS negotiation before giving any other SMTP commands ๐Ÿซถ if, after sending STARTTLS, the client finds out some failure is stopping it from actually starting a TLS handshake, then it SHOULD abort the connection. no drama, just bounce ๐Ÿ’€

if the SMTP client is using pipelining as defined in RFC 2920, the STARTTLS command must be the last command in a group ๐Ÿงš

4.1 Processing After the STARTTLS Command ๐Ÿ”

once the TLS handshake is done, both parties MUST immediately decide whether or not to continue, based on the authentication and privacy they got ๐Ÿชž the SMTP client and server may decide to move ahead even if the TLS negotiation ended with no authentication and/or no privacy, because most SMTP services run with no authentication and no privacy. but some clients or servers may only want to continue if a particular level of authentication and/or privacy was achieved ๐Ÿ”’

if the SMTP client decides the level of authentication or privacy isn't high enough, it SHOULD issue an SMTP QUIT command right after the TLS negotiation is complete ๐Ÿ‘‹ if the SMTP server decides the same thing, it SHOULD reply to every SMTP command from the client (other than a QUIT command) with the 554 reply code, with a possible text string such as "Command refused due to lack of security" ๐Ÿ™…โ€โ™€๏ธ

whether to believe the authenticity of the other party in a TLS negotiation is a local matter ๐Ÿ’… but some general rules for that decision are:

  • A SMTP client would probably only want to authenticate an SMTP server whose server certificate has a domain name that is the domain name that the client thought it was connecting to. ๐Ÿ”Ž
  • A publicly-referenced SMTP server would probably want to accept any verifiable certificate from an SMTP client, and would possibly want to put distinguishing information about the certificate in the Received header of messages that were relayed or submitted from the client. ๐Ÿงพ

4.2 Result of the STARTTLS Command ๐ŸŒŸ

once the TLS handshake is complete, the SMTP protocol is reset to the initial state (the state in SMTP after a server issues a 220 service ready greeting) ๐Ÿ”„ the server MUST discard any knowledge it got from the client, like the argument to the EHLO command, that did NOT come from the TLS negotiation itself. the client MUST discard any knowledge it got from the server, like the list of SMTP service extensions, that did not come from the TLS negotiation itself. the client SHOULD send an EHLO command as the first command after a successful TLS negotiation ๐Ÿงน

the list of SMTP service extensions returned in response to an EHLO command received after the TLS handshake MAY be different from the list returned before it ๐Ÿฆ‹ for example, an SMTP server might not want to advertise support for a particular SASL mechanism [SASL] unless a client has sent an appropriate client certificate during the TLS handshake ๐Ÿชช

both the client and the server MUST know if there is a TLS session active ๐Ÿ‘€ a client MUST NOT attempt to start a TLS session if one is already active, and a server MUST NOT return the STARTTLS extension in response to an EHLO command received after a TLS handshake has completed. no double-wrapping, we don't do that here ๐Ÿ™…โ€โ™€๏ธ

4.3 STARTTLS on the Submission Port ๐Ÿ“ฎ

STARTTLS is a valid ESMTP extension when used on the Submission port, as defined in [RFC2476]. and honestly? since the submission port is by definition not a publicly referenced SMTP server, STARTTLS can be super useful there for security and authentication for this service ๐Ÿ’–

5. Usage Example ๐Ÿ“

here's a dialog showing how a client and server can start a TLS session ๐Ÿ’ฌ

S: <waits for connection on TCP port 25>
C: <opens connection>
S: 220 mail.imc.org SMTP service ready
C: EHLO mail.example.com
S: 250-mail.imc.org offers a warm hug of welcome
S: 250-8BITMIME
S: 250-STARTTLS
S: 250 DSN
C: STARTTLS
S: 220 Go ahead
C: <starts TLS negotiation>
C & S: <negotiate a TLS session>
C & S: <check result of negotiation>
C: EHLO mail.example.com
S: 250-mail.imc.org touches your hand gently for a moment
S: 250-8BITMIME
S: 250 DSN

6. Security Considerations ๐Ÿ”๐Ÿ’–

okay bestie, this section is SERIOUS but also iconic ๐Ÿ’… SMTP is not end-to-end, so if an SMTP client/server pair decides to add TLS privacy, they are NOT securing the transport from the originating mail user agent to the recipient ๐Ÿ˜ญ Also, one piece of mail can hop between more than two SMTP servers, so adding TLS to one pair of servers does not mean the whole SMTP chain is private. And just because an SMTP server can authenticate an SMTP client doesn't mean the mail was authenticated by that client when the client received it ๐Ÿ™ˆ

Both the SMTP client and server must check the result of the TLS negotiation to see whether an acceptable degree of authentication and privacy was achieved. Skipping this step completely invalidates using TLS for security ๐Ÿ’€ Whether the authentication or privacy is acceptable is decided locally, it's implementation-dependent, and it's beyond the scope of this document ๐Ÿงš

The SMTP client and server should note carefully the result of the TLS negotiation. If there's no privacy, or the privacy uses algorithms or key lengths that aren't strong enough, or the authentication isn't good enough for either party, the client may choose to end the SMTP session with an immediate QUIT command, or the server may choose to not accept any more SMTP commands ๐Ÿซถ

Man-in-the-middle alert ๐Ÿšจ An attacker can launch a man-in-the-middle attack by deleting the 250 STARTTLS response from the server. That makes the client not even try to start a TLS session. Another man-in-the-middle attack lets the server announce its STARTTLS capability but alters the client's request to start TLS and the server's response. To defend against attacks like these, both clients and servers MUST be able to be configured to require successful TLS negotiation of an appropriate cipher suite for selected hosts before messages can be successfully transferred. The additional option of using TLS when possible SHOULD also be provided. An implementation MAY provide the ability to record that TLS was used in communicating with a given peer and generate a warning if it is not used in a later session ๐Ÿ‘‘

If the TLS negotiation fails, or the client receives a 454 response, the client has to decide what to do next ๐Ÿค” There are three main choices: go ahead with the rest of the SMTP session, retry TLS at a later time, or give up and return the mail to the sender. If a failure or error happens, the client can assume the server may be able to negotiate TLS in the future, so it should try to negotiate TLS in a later session, until some locally-chosen timeout occurs. At that point, the client should return the mail to the sender. However, if the client and server were only using TLS for authentication, the client may want to proceed with the SMTP session, in case some of the operations the client wanted to perform are accepted by the server even if the client is unauthenticated ๐Ÿฆ‹

Before the TLS handshake has begun, any protocol interactions are performed in the clear and may be modified by an active attacker ๐Ÿ‘€

For this reason, clients and servers MUST discard any knowledge obtained prior to the start of the TLS handshake upon completion of the TLS handshake. No keeping old info around, periodt ๐Ÿงนโœจ

The STARTTLS extension is not suitable for authenticating the author of an email message unless every hop in the delivery chain, including the submission to the first SMTP server, is authenticated ๐Ÿ™…โ€โ™€๏ธ Another proposal, [SMTP-AUTH], can be used to authenticate delivery, and MIME security multiparts [MIME-SEC] can be used to authenticate the author of an email message. On top of that, the [SMTP-AUTH] proposal offers simpler and more flexible options for authenticating an SMTP client, and the SASL EXTERNAL mechanism [SASL] MAY be used in conjunction with the STARTTLS command to provide an authorization identity ๐ŸŒธ


7. References ๐Ÿ“š

  • [RFC2821] Klensin, J., "Simple Mail Transfer Protocol", RFC 2821, April 2001.
  • [RFC2034] Freed, N., "SMTP Service Extension for Returning Enhanced Error Codes", RFC 2034, October 1996.
  • [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, March 1997.
  • [RFC2476] Gellens, R. and J. Klensin, "Message Submission", RFC 2476, December 1998.
  • [SASL] Myers, J., "Simple Authentication and Security Layer (SASL)", RFC 2222, October 1997.
  • [SMTP-AUTH] Myers, J., "SMTP Service Extension for Authentication", RFC 2554, March 1999.
  • [TLS] Dierks, T. and C. Allen, "The TLS Protocol Version 1.0", RFC 2246, January 1999.

Appendix ๐ŸŒˆ

This document is a revision of RFC 2487, which is a Proposed Standard. Here's what changed, bestie ๐ŸŽ€

  • Section 5 and 7: More discussion of the man-in-the-middle attacks
  • Section 5: Additional discussion of when a server should and should not advertise the STARTTLS extension
  • Section 5: Changed the requirements on SMTP clients after receiving a 220 response.
  • Section 5.1: Clarified description of verifying certificates.
  • Section 5.3: Added the section on "STARTTLS on the Submission Port"
  • Section 6: Bug fix in the example to indicate that the client needs to issue a new EHLO command, as already is described in section 5.2.
  • Section 7: Clarification of the paragraph on acceptable degree of privacy. Significant change to the discussion of how to avoid a man-in-the-middle attack.
  • Section A: Update reference from RFC 821 to RFC 2821.

Author's Address ๐Ÿ–Š๏ธ

Paul Hoffman Internet Mail Consortium 127 Segre Place Santa Cruz, CA 95060

Phone: (831) 426-9827 EMail: phoffman@imc.org


Copyright (C) The Internet Society (2002). All Rights Reserved.

This document and translations of it may be copied and furnished to others, and derivative works that comment on or otherwise explain it or assist in its implementation may be prepared, copied, published and distributed, in whole or in part, without restriction of any kind, as long as the above copyright notice and this paragraph are included on all such copies and derivative works. However, this document itself may not be modified in any way, such as by removing the copyright notice or references to the Internet Society or other Internet organizations. The exceptions are when it's needed for developing Internet standards, in which case the procedures for copyrights defined in the Internet Standards process must be followed, or when it's required to translate it into languages other than English.

The limited permissions granted above are perpetual and will not be revoked by the Internet Society or its successors or assigns.

This document and the information contained herein is provided on an "AS IS" basis, and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.


Acknowledgement ๐Ÿ™

Funding for the RFC Editor function is currently provided by the Internet Society. ๐Ÿ’œ

๐Ÿ“ฆ where this page comes from