idnits 2.17.1 draft-ietf-quic-tls-05.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- No issues found here. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year == The document seems to lack the recommended RFC 2119 boilerplate, even if it appears to use RFC 2119 keywords. (The document does seem to have the reference to RFC 2119 which the ID-Checklist requires). -- The document date (August 15, 2017) is 2446 days in the past. Is this intentional? -- Found something which looks like a code comment -- if you have code sections in the document, please surround them with '' and '' lines. Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) == Unused Reference: 'QUIC-HTTP' is defined on line 1653, but no explicit reference was found in the text == Outdated reference: A later version (-28) exists of draft-ietf-tls-tls13-21 ** Downref: Normative reference to an Informational RFC: RFC 5869 == Outdated reference: A later version (-22) exists of draft-eastlake-fnv-13 -- Obsolete informational reference (is this intentional?): RFC 2818 (Obsoleted by RFC 9110) Summary: 1 error (**), 0 flaws (~~), 5 warnings (==), 3 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 QUIC M. Thomson, Ed. 3 Internet-Draft Mozilla 4 Intended status: Standards Track S. Turner, Ed. 5 Expires: February 16, 2018 sn3rd 6 August 15, 2017 8 Using Transport Layer Security (TLS) to Secure QUIC 9 draft-ietf-quic-tls-05 11 Abstract 13 This document describes how Transport Layer Security (TLS) is used to 14 secure QUIC. 16 Note to Readers 18 Discussion of this draft takes place on the QUIC working group 19 mailing list (quic@ietf.org), which is archived at 20 https://mailarchive.ietf.org/arch/search/?email_list=quic. 22 Working Group information can be found at https://github.com/quicwg; 23 source code and issues list for this draft can be found at 24 https://github.com/quicwg/base-drafts/labels/tls. 26 Status of This Memo 28 This Internet-Draft is submitted in full conformance with the 29 provisions of BCP 78 and BCP 79. 31 Internet-Drafts are working documents of the Internet Engineering 32 Task Force (IETF). Note that other groups may also distribute 33 working documents as Internet-Drafts. The list of current Internet- 34 Drafts is at http://datatracker.ietf.org/drafts/current/. 36 Internet-Drafts are draft documents valid for a maximum of six months 37 and may be updated, replaced, or obsoleted by other documents at any 38 time. It is inappropriate to use Internet-Drafts as reference 39 material or to cite them other than as "work in progress." 41 This Internet-Draft will expire on February 16, 2018. 43 Copyright Notice 45 Copyright (c) 2017 IETF Trust and the persons identified as the 46 document authors. All rights reserved. 48 This document is subject to BCP 78 and the IETF Trust's Legal 49 Provisions Relating to IETF Documents 50 (http://trustee.ietf.org/license-info) in effect on the date of 51 publication of this document. Please review these documents 52 carefully, as they describe your rights and restrictions with respect 53 to this document. Code Components extracted from this document must 54 include Simplified BSD License text as described in Section 4.e of 55 the Trust Legal Provisions and are provided without warranty as 56 described in the Simplified BSD License. 58 Table of Contents 60 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 3 61 2. Notational Conventions . . . . . . . . . . . . . . . . . . . 4 62 3. Protocol Overview . . . . . . . . . . . . . . . . . . . . . . 4 63 3.1. TLS Overview . . . . . . . . . . . . . . . . . . . . . . 5 64 3.2. TLS Handshake . . . . . . . . . . . . . . . . . . . . . . 6 65 4. TLS Usage . . . . . . . . . . . . . . . . . . . . . . . . . . 7 66 4.1. Handshake and Setup Sequence . . . . . . . . . . . . . . 7 67 4.2. Interface to TLS . . . . . . . . . . . . . . . . . . . . 9 68 4.2.1. Handshake Interface . . . . . . . . . . . . . . . . . 9 69 4.2.2. Source Address Validation . . . . . . . . . . . . . . 10 70 4.2.3. Key Ready Events . . . . . . . . . . . . . . . . . . 11 71 4.2.4. Secret Export . . . . . . . . . . . . . . . . . . . . 12 72 4.2.5. TLS Interface Summary . . . . . . . . . . . . . . . . 12 73 4.3. TLS Version . . . . . . . . . . . . . . . . . . . . . . . 13 74 4.4. ClientHello Size . . . . . . . . . . . . . . . . . . . . 13 75 4.5. Peer Authentication . . . . . . . . . . . . . . . . . . . 13 76 4.6. TLS Errors . . . . . . . . . . . . . . . . . . . . . . . 14 77 5. QUIC Packet Protection . . . . . . . . . . . . . . . . . . . 14 78 5.1. Installing New Keys . . . . . . . . . . . . . . . . . . . 14 79 5.2. QUIC Key Expansion . . . . . . . . . . . . . . . . . . . 15 80 5.2.1. 0-RTT Secret . . . . . . . . . . . . . . . . . . . . 15 81 5.2.2. 1-RTT Secrets . . . . . . . . . . . . . . . . . . . . 15 82 5.2.3. Packet Protection Key and IV . . . . . . . . . . . . 17 83 5.3. QUIC AEAD Usage . . . . . . . . . . . . . . . . . . . . . 17 84 5.4. Packet Numbers . . . . . . . . . . . . . . . . . . . . . 18 85 5.5. Receiving Protected Packets . . . . . . . . . . . . . . . 19 86 5.6. Packet Number Gaps . . . . . . . . . . . . . . . . . . . 19 87 6. Unprotected Packets . . . . . . . . . . . . . . . . . . . . . 19 88 6.1. Integrity Check Processing . . . . . . . . . . . . . . . 19 89 6.2. The 64-bit FNV-1a Algorithm . . . . . . . . . . . . . . . 20 90 7. Key Phases . . . . . . . . . . . . . . . . . . . . . . . . . 20 91 7.1. Packet Protection for the TLS Handshake . . . . . . . . . 21 92 7.1.1. Initial Key Transitions . . . . . . . . . . . . . . . 21 93 7.1.2. Retransmission and Acknowledgment of Unprotected 94 Packets . . . . . . . . . . . . . . . . . . . . . . . 22 95 7.2. Key Update . . . . . . . . . . . . . . . . . . . . . . . 23 97 8. Client Address Validation . . . . . . . . . . . . . . . . . . 24 98 8.1. HelloRetryRequest Address Validation . . . . . . . . . . 25 99 8.1.1. Stateless Address Validation . . . . . . . . . . . . 25 100 8.1.2. Sending HelloRetryRequest . . . . . . . . . . . . . . 26 101 8.2. NewSessionTicket Address Validation . . . . . . . . . . . 26 102 8.3. Address Validation Token Integrity . . . . . . . . . . . 27 103 9. Pre-handshake QUIC Messages . . . . . . . . . . . . . . . . . 27 104 9.1. Unprotected Packets Prior to Handshake Completion . . . . 28 105 9.1.1. STREAM Frames . . . . . . . . . . . . . . . . . . . . 28 106 9.1.2. ACK Frames . . . . . . . . . . . . . . . . . . . . . 28 107 9.1.3. Updates to Data and Stream Limits . . . . . . . . . . 29 108 9.1.4. Denial of Service with Unprotected Packets . . . . . 29 109 9.2. Use of 0-RTT Keys . . . . . . . . . . . . . . . . . . . . 30 110 9.3. Receiving Out-of-Order Protected Frames . . . . . . . . . 30 111 10. QUIC-Specific Additions to the TLS Handshake . . . . . . . . 31 112 10.1. Protocol and Version Negotiation . . . . . . . . . . . . 31 113 10.2. QUIC Transport Parameters Extension . . . . . . . . . . 32 114 10.3. Priming 0-RTT . . . . . . . . . . . . . . . . . . . . . 32 115 11. Security Considerations . . . . . . . . . . . . . . . . . . . 33 116 11.1. Packet Reflection Attack Mitigation . . . . . . . . . . 33 117 11.2. Peer Denial of Service . . . . . . . . . . . . . . . . . 33 118 12. Error codes . . . . . . . . . . . . . . . . . . . . . . . . . 34 119 13. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 34 120 14. References . . . . . . . . . . . . . . . . . . . . . . . . . 34 121 14.1. Normative References . . . . . . . . . . . . . . . . . . 34 122 14.2. Informative References . . . . . . . . . . . . . . . . . 35 123 Appendix A. Contributors . . . . . . . . . . . . . . . . . . . . 36 124 Appendix B. Acknowledgments . . . . . . . . . . . . . . . . . . 36 125 Appendix C. Change Log . . . . . . . . . . . . . . . . . . . . . 36 126 C.1. Since draft-ietf-quic-tls-04 . . . . . . . . . . . . . . 36 127 C.2. Since draft-ietf-quic-tls-03 . . . . . . . . . . . . . . 36 128 C.3. Since draft-ietf-quic-tls-02 . . . . . . . . . . . . . . 36 129 C.4. Since draft-ietf-quic-tls-01 . . . . . . . . . . . . . . 36 130 C.5. Since draft-ietf-quic-tls-00 . . . . . . . . . . . . . . 37 131 C.6. Since draft-thomson-quic-tls-01 . . . . . . . . . . . . . 37 132 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 37 134 1. Introduction 136 This document describes how QUIC [QUIC-TRANSPORT] is secured using 137 Transport Layer Security (TLS) version 1.3 [I-D.ietf-tls-tls13]. TLS 138 1.3 provides critical latency improvements for connection 139 establishment over previous versions. Absent packet loss, most new 140 connections can be established and secured within a single round 141 trip; on subsequent connections between the same client and server, 142 the client can often send application data immediately, that is, 143 using a zero round trip setup. 145 This document describes how the standardized TLS 1.3 acts a security 146 component of QUIC. The same design could work for TLS 1.2, though 147 few of the benefits QUIC provides would be realized due to the 148 handshake latency in versions of TLS prior to 1.3. 150 2. Notational Conventions 152 The words "MUST", "MUST NOT", "SHOULD", and "MAY" are used in this 153 document. It's not shouting; when they are capitalized, they have 154 the special meaning defined in [RFC2119]. 156 This document uses the terminology established in [QUIC-TRANSPORT]. 158 For brevity, the acronym TLS is used to refer to TLS 1.3. 160 TLS terminology is used when referring to parts of TLS. Though TLS 161 assumes a continuous stream of octets, it divides that stream into 162 _records_. Most relevant to QUIC are the records that contain TLS 163 _handshake messages_, which are discrete messages that are used for 164 key agreement, authentication and parameter negotiation. Ordinarily, 165 TLS records can also contain _application data_, though in the QUIC 166 usage there is no use of TLS application data. 168 3. Protocol Overview 170 QUIC [QUIC-TRANSPORT] assumes responsibility for the confidentiality 171 and integrity protection of packets. For this it uses keys derived 172 from a TLS 1.3 connection [I-D.ietf-tls-tls13]; QUIC also relies on 173 TLS 1.3 for authentication and negotiation of parameters that are 174 critical to security and performance. 176 Rather than a strict layering, these two protocols are co-dependent: 177 QUIC uses the TLS handshake; TLS uses the reliability and ordered 178 delivery provided by QUIC streams. 180 This document defines how QUIC interacts with TLS. This includes a 181 description of how TLS is used, how keying material is derived from 182 TLS, and the application of that keying material to protect QUIC 183 packets. Figure 1 shows the basic interactions between TLS and QUIC, 184 with the QUIC packet protection being called out specially. 186 +------------+ +------------+ 187 | |------ Handshake ------>| | 188 | |<-- Validate Address ---| | 189 | |-- OK/Error/Validate -->| | 190 | |<----- Handshake -------| | 191 | QUIC |------ Validate ------->| TLS | 192 | | | | 193 | |<------ 0-RTT OK -------| | 194 | |<------ 1-RTT OK -------| | 195 | |<--- Handshake Done ----| | 196 +------------+ +------------+ 197 | ^ ^ | 198 | Protect | Protected | | 199 v | Packet | | 200 +------------+ / / 201 | QUIC | / / 202 | Packet |-------- Get Secret -------' / 203 | Protection |<-------- Secret -----------' 204 +------------+ 206 Figure 1: QUIC and TLS Interactions 208 The initial state of a QUIC connection has packets exchanged without 209 any form of protection. In this state, QUIC is limited to using 210 stream 0 and associated packets. Stream 0 is reserved for a TLS 211 connection. This is a complete TLS connection as it would appear 212 when layered over TCP; the only difference is that QUIC provides the 213 reliability and ordering that would otherwise be provided by TCP. 215 At certain points during the TLS handshake, keying material is 216 exported from the TLS connection for use by QUIC. This keying 217 material is used to derive packet protection keys. Details on how 218 and when keys are derived and used are included in Section 5. 220 3.1. TLS Overview 222 TLS provides two endpoints with a way to establish a means of 223 communication over an untrusted medium (that is, the Internet) that 224 ensures that messages they exchange cannot be observed, modified, or 225 forged. 227 TLS features can be separated into two basic functions: an 228 authenticated key exchange and record protection. QUIC primarily 229 uses the authenticated key exchange provided by TLS but provides its 230 own packet protection. 232 The TLS authenticated key exchange occurs between two entities: 233 client and server. The client initiates the exchange and the server 234 responds. If the key exchange completes successfully, both client 235 and server will agree on a secret. TLS supports both pre-shared key 236 (PSK) and Diffie-Hellman (DH) key exchanges. PSK is the basis for 237 0-RTT; the latter provides perfect forward secrecy (PFS) when the DH 238 keys are destroyed. 240 After completing the TLS handshake, the client will have learned and 241 authenticated an identity for the server and the server is optionally 242 able to learn and authenticate an identity for the client. TLS 243 supports X.509 [RFC5280] certificate-based authentication for both 244 server and client. 246 The TLS key exchange is resistent to tampering by attackers and it 247 produces shared secrets that cannot be controlled by either 248 participating peer. 250 3.2. TLS Handshake 252 TLS 1.3 provides two basic handshake modes of interest to QUIC: 254 o A full 1-RTT handshake in which the client is able to send 255 application data after one round trip and the server immediately 256 responds after receiving the first handshake message from the 257 client. 259 o A 0-RTT handshake in which the client uses information it has 260 previously learned about the server to send application data 261 immediately. This application data can be replayed by an attacker 262 so it MUST NOT carry a self-contained trigger for any non- 263 idempotent action. 265 A simplified TLS 1.3 handshake with 0-RTT application data is shown 266 in Figure 2, see [I-D.ietf-tls-tls13] for more options and details. 268 Client Server 270 ClientHello 271 (0-RTT Application Data) --------> 272 ServerHello 273 {EncryptedExtensions} 274 {Finished} 275 <-------- [Application Data] 276 (EndOfEarlyData) 277 {Finished} --------> 279 [Application Data] <-------> [Application Data] 281 Figure 2: TLS Handshake with 0-RTT 283 This 0-RTT handshake is only possible if the client and server have 284 previously communicated. In the 1-RTT handshake, the client is 285 unable to send protected application data until it has received all 286 of the handshake messages sent by the server. 288 Two additional variations on this basic handshake exchange are 289 relevant to this document: 291 o The server can respond to a ClientHello with a HelloRetryRequest, 292 which adds an additional round trip prior to the basic exchange. 293 This is needed if the server wishes to request a different key 294 exchange key from the client. HelloRetryRequest is also used to 295 verify that the client is correctly able to receive packets on the 296 address it claims to have (see [QUIC-TRANSPORT]). 298 o A pre-shared key mode can be used for subsequent handshakes to 299 reduce the number of public key operations. This is the basis for 300 0-RTT data, even if the remainder of the connection is protected 301 by a new Diffie-Hellman exchange. 303 4. TLS Usage 305 QUIC reserves stream 0 for a TLS connection. Stream 0 contains a 306 complete TLS connection, which includes the TLS record layer. Other 307 than the definition of a QUIC-specific extension (see Section 10.2), 308 TLS is unmodified for this use. This means that TLS will apply 309 confidentiality and integrity protection to its records. In 310 particular, TLS record protection is what provides confidentiality 311 protection for the TLS handshake messages sent by the server. 313 QUIC permits a client to send frames on streams starting from the 314 first packet. The initial packet from a client contains a stream 315 frame for stream 0 that contains the first TLS handshake messages 316 from the client. This allows the TLS handshake to start with the 317 first packet that a client sends. 319 QUIC packets are protected using a scheme that is specific to QUIC, 320 see Section 5. Keys are exported from the TLS connection when they 321 become available using a TLS exporter (see Section 7.5 of 322 [I-D.ietf-tls-tls13] and Section 5.2). After keys are exported from 323 TLS, QUIC manages its own key schedule. 325 4.1. Handshake and Setup Sequence 327 The integration of QUIC with a TLS handshake is shown in more detail 328 in Figure 3. QUIC "STREAM" frames on stream 0 carry the TLS 329 handshake. QUIC performs loss recovery [QUIC-RECOVERY] for this 330 stream and ensures that TLS handshake messages are delivered in the 331 correct order. 333 Client Server 335 @C QUIC STREAM Frame(s) <0>: 336 ClientHello 337 + QUIC Extension 338 --------> 339 0-RTT Key => @0 341 @0 QUIC STREAM Frame(s) : 342 Replayable QUIC Frames 343 --------> 345 QUIC STREAM Frame <0>: @C 346 ServerHello 347 {TLS Handshake Messages} 348 <-------- 349 1-RTT Key => @1 351 QUIC Frames @1 352 <-------- 353 @C QUIC STREAM Frame(s) <0>: 354 (EndOfEarlyData) 355 {Finished} 356 --------> 358 @1 QUIC Frames <-------> QUIC Frames @1 360 Figure 3: QUIC over TLS Handshake 362 In Figure 3, symbols mean: 364 o "<" and ">" enclose stream numbers. 366 o "@" indicates the keys that are used for protecting the QUIC 367 packet (C = cleartext, with integrity only; 0 = 0-RTT keys; 1 = 368 1-RTT keys). 370 o "(" and ")" enclose messages that are protected with TLS 0-RTT 371 handshake or application keys. 373 o "{" and "}" enclose messages that are protected by the TLS 374 Handshake keys. 376 If 0-RTT is not attempted, then the client does not send packets 377 protected by the 0-RTT key (@0). In that case, the only key 378 transition on the client is from cleartext packets (@C) to 1-RTT 379 protection (@1), which happens after it sends its final set of TLS 380 handshake messages. 382 Note: the client uses two different types of cleartext packet during 383 the handshake. The Client Initial packet carries a TLS ClientHello 384 message; the remainder of the TLS handshake is carried in Client 385 Cleartext packets. 387 The server sends TLS handshake messages without protection (@C). The 388 server transitions from no protection (@C) to full 1-RTT protection 389 (@1) after it sends the last of its handshake messages. 391 Some TLS handshake messages are protected by the TLS handshake record 392 protection. These keys are not exported from the TLS connection for 393 use in QUIC. QUIC packets from the server are sent in the clear 394 until the final transition to 1-RTT keys. 396 The client transitions from cleartext (@C) to 0-RTT keys (@0) when 397 sending 0-RTT data, and subsequently to to 1-RTT keys (@1) after its 398 second flight of TLS handshake messages. This creates the potential 399 for unprotected packets to be received by a server in close proximity 400 to packets that are protected with 1-RTT keys. 402 More information on key transitions is included in Section 7.1. 404 4.2. Interface to TLS 406 As shown in Figure 1, the interface from QUIC to TLS consists of four 407 primary functions: Handshake, Source Address Validation, Key Ready 408 Events, and Secret Export. 410 Additional functions might be needed to configure TLS. 412 4.2.1. Handshake Interface 414 In order to drive the handshake, TLS depends on being able to send 415 and receive handshake messages on stream 0. There are two basic 416 functions on this interface: one where QUIC requests handshake 417 messages and one where QUIC provides handshake packets. 419 Before starting the handshake QUIC provides TLS with the transport 420 parameters (see Section 10.2) that it wishes to carry. 422 A QUIC client starts TLS by requesting TLS handshake octets from TLS. 423 The client acquires handshake octets before sending its first packet. 425 A QUIC server starts the process by providing TLS with stream 0 426 octets. 428 Each time that an endpoint receives data on stream 0, it delivers the 429 octets to TLS if it is able. Each time that TLS is provided with new 430 data, new handshake octets are requested from TLS. TLS might not 431 provide any octets if the handshake messages it has received are 432 incomplete or it has no data to send. 434 Once the TLS handshake is complete, this is indicated to QUIC along 435 with any final handshake octets that TLS needs to send. TLS also 436 provides QUIC with the transport parameters that the peer advertised 437 during the handshake. 439 Once the handshake is complete, TLS becomes passive. TLS can still 440 receive data from its peer and respond in kind, but it will not need 441 to send more data unless specifically requested - either by an 442 application or QUIC. One reason to send data is that the server 443 might wish to provide additional or updated session tickets to a 444 client. 446 When the handshake is complete, QUIC only needs to provide TLS with 447 any data that arrives on stream 0. In the same way that is done 448 during the handshake, new data is requested from TLS after providing 449 received data. 451 Important: Until the handshake is reported as complete, the 452 connection and key exchange are not properly authenticated at the 453 server. Even though 1-RTT keys are available to a server after 454 receiving the first handshake messages from a client, the server 455 cannot consider the client to be authenticated until it receives 456 and validates the client's Finished message. 458 The requirement for the server to wait for the client Finished 459 message creates a dependency on that message being delivered. A 460 client can avoid the potential for head-of-line blocking that this 461 implies by sending a copy of the STREAM frame that carries the 462 Finished message in multiple packets. This enables immediate 463 server processing for those packets. 465 4.2.2. Source Address Validation 467 During the processing of the TLS ClientHello, TLS requests that the 468 transport make a decision about whether to request source address 469 validation from the client. 471 An initial TLS ClientHello that resumes a session includes an address 472 validation token in the session ticket; this includes all attempts at 473 0-RTT. If the client does not attempt session resumption, no token 474 will be present. While processing the initial ClientHello, TLS 475 provides QUIC with any token that is present. In response, QUIC 476 provides one of three responses: 478 o proceed with the connection, 480 o ask for client address validation, or 482 o abort the connection. 484 If QUIC requests source address validation, it also provides a new 485 address validation token. TLS includes that along with any 486 information it requires in the cookie extension of a TLS 487 HelloRetryRequest message. In the other cases, the connection either 488 proceeds or terminates with a handshake error. 490 The client echoes the cookie extension in a second ClientHello. A 491 ClientHello that contains a valid cookie extension will always be in 492 response to a HelloRetryRequest. If address validation was requested 493 by QUIC, then this will include an address validation token. TLS 494 makes a second address validation request of QUIC, including the 495 value extracted from the cookie extension. In response to this 496 request, QUIC cannot ask for client address validation, it can only 497 abort or permit the connection attempt to proceed. 499 QUIC can provide a new address validation token for use in session 500 resumption at any time after the handshake is complete. Each time a 501 new token is provided TLS generates a NewSessionTicket message, with 502 the token included in the ticket. 504 See Section 8 for more details on client address validation. 506 4.2.3. Key Ready Events 508 TLS provides QUIC with signals when 0-RTT and 1-RTT keys are ready 509 for use. These events are not asynchronous, they always occur 510 immediately after TLS is provided with new handshake octets, or after 511 TLS produces handshake octets. 513 When TLS completed its handshake, 1-RTT keys can be provided to QUIC. 514 On both client and server, this occurs after sending the TLS Finished 515 message. 517 This ordering means that there could be frames that carry TLS 518 handshake messages ready to send at the same time that application 519 data is available. An implementation MUST ensure that TLS handshake 520 messages are always sent in cleartext packets. Separate packets are 521 required for data that needs protection from 1-RTT keys. 523 If 0-RTT is possible, it is ready after the client sends a TLS 524 ClientHello message or the server receives that message. After 525 providing a QUIC client with the first handshake octets, the TLS 526 stack might signal that 0-RTT keys are ready. On the server, after 527 receiving handshake octets that contain a ClientHello message, a TLS 528 server might signal that 0-RTT keys are available. 530 1-RTT keys are used for packets in both directions. 0-RTT keys are 531 only used to protect packets sent by the client. 533 4.2.4. Secret Export 535 Details how secrets are exported from TLS are included in 536 Section 5.2. 538 4.2.5. TLS Interface Summary 540 Figure 4 summarizes the exchange between QUIC and TLS for both client 541 and server. 543 Client Server 545 Get Handshake 546 0-RTT Key Ready 547 --- send/receive ---> 548 Handshake Received 549 0-RTT Key Ready 550 Get Handshake 551 1-RTT Keys Ready 552 <--- send/receive --- 553 Handshake Received 554 Get Handshake 555 Handshake Complete 556 1-RTT Keys Ready 557 --- send/receive ---> 558 Handshake Received 559 Get Handshake 560 Handshake Complete 561 <--- send/receive --- 562 Handshake Received 563 Get Handshake 565 Figure 4: Interaction Summary between QUIC and TLS 567 4.3. TLS Version 569 This document describes how TLS 1.3 [I-D.ietf-tls-tls13] is used with 570 QUIC. 572 In practice, the TLS handshake will negotiate a version of TLS to 573 use. This could result in a newer version of TLS than 1.3 being 574 negotiated if both endpoints support that version. This is 575 acceptable provided that the features of TLS 1.3 that are used by 576 QUIC are supported by the newer version. 578 A badly configured TLS implementation could negotiate TLS 1.2 or 579 another older version of TLS. An endpoint MUST terminate the 580 connection if a version of TLS older than 1.3 is negotiated. 582 4.4. ClientHello Size 584 QUIC requires that the initial handshake packet from a client fit 585 within the payload of a single packet. The size limits on QUIC 586 packets mean that a record containing a ClientHello needs to fit 587 within 1171 octets. 589 A TLS ClientHello can fit within this limit with ample space 590 remaining. However, there are several variables that could cause 591 this limit to be exceeded. Implementations are reminded that large 592 session tickets or HelloRetryRequest cookies, multiple or large key 593 shares, and long lists of supported ciphers, signature algorithms, 594 versions, QUIC transport parameters, and other negotiable parameters 595 and extensions could cause this message to grow. 597 For servers, the size of the session tickets and HelloRetryRequest 598 cookie extension can have an effect on a client's ability to connect. 599 Choosing a small value increases the probability that these values 600 can be successfully used by a client. 602 The TLS implementation does not need to ensure that the ClientHello 603 is sufficiently large. QUIC PADDING frames are added to increase the 604 size of the packet as necessary. 606 4.5. Peer Authentication 608 The requirements for authentication depend on the application 609 protocol that is in use. TLS provides server authentication and 610 permits the server to request client authentication. 612 A client MUST authenticate the identity of the server. This 613 typically involves verification that the identity of the server is 614 included in a certificate and that the certificate is issued by a 615 trusted entity (see for example [RFC2818]). 617 A server MAY request that the client authenticate during the 618 handshake. A server MAY refuse a connection if the client is unable 619 to authenticate when requested. The requirements for client 620 authentication vary based on application protocol and deployment. 622 A server MUST NOT use post-handshake client authentication (see 623 Section 4.6.2 of [I-D.ietf-tls-tls13]). 625 4.6. TLS Errors 627 Errors in the TLS connection SHOULD be signaled using TLS alerts on 628 stream 0. A failure in the handshake MUST be treated as a QUIC 629 connection error of type TLS_HANDSHAKE_FAILED. Once the handshake is 630 complete, an error in the TLS connection that causes a TLS alert to 631 be sent or received MUST be treated as a QUIC connection error of 632 type TLS_FATAL_ALERT_GENERATED or TLS_FATAL_ALERT_RECEIVED 633 respectively. 635 5. QUIC Packet Protection 637 QUIC packet protection provides authenticated encryption of packets. 638 This provides confidentiality and integrity protection for the 639 content of packets (see Section 5.3). Packet protection uses keys 640 that are exported from the TLS connection (see Section 5.2). 642 Different keys are used for QUIC packet protection and TLS record 643 protection. TLS handshake messages are protected solely with TLS 644 record protection, but post-handshake messages are redundantly 645 proteted with both both the QUIC packet protection and the TLS record 646 protection. These messages are limited in number, and so the 647 additional overhead is small. 649 5.1. Installing New Keys 651 As TLS reports the availability of keying material, the packet 652 protection keys and initialization vectors (IVs) are updated (see 653 Section 5.2). The selection of AEAD function is also updated to 654 match the AEAD negotiated by TLS. 656 For packets other than any unprotected handshake packets (see 657 Section 7.1), once a change of keys has been made, packets with 658 higher packet numbers MUST be sent with the new keying material. The 659 KEY_PHASE bit on these packets is inverted each time new keys are 660 installed to signal the use of the new keys to the recipient (see 661 Section 7 for details). 663 An endpoint retransmits stream data in a new packet. New packets 664 have new packet numbers and use the latest packet protection keys. 665 This simplifies key management when there are key updates (see 666 Section 7.2). 668 5.2. QUIC Key Expansion 670 QUIC uses a system of packet protection secrets, keys and IVs that 671 are modelled on the system used in TLS [I-D.ietf-tls-tls13]. The 672 secrets that QUIC uses as the basis of its key schedule are obtained 673 using TLS exporters (see Section 7.5 of [I-D.ietf-tls-tls13]). 675 QUIC uses HKDF with the same hash function negotiated by TLS for key 676 derivation. For example, if TLS is using the TLS_AES_128_GCM_SHA256, 677 the SHA-256 hash function is used. 679 5.2.1. 0-RTT Secret 681 0-RTT keys are those keys that are used in resumed connections prior 682 to the completion of the TLS handshake. Data sent using 0-RTT keys 683 might be replayed and so has some restrictions on its use, see 684 Section 9.2. 0-RTT keys are used after sending or receiving a 685 ClientHello. 687 The secret is exported from TLS using the exporter label "EXPORTER- 688 QUIC 0-RTT Secret" and an empty context. The size of the secret MUST 689 be the size of the hash output for the PRF hash function negotiated 690 by TLS. This uses the TLS early_exporter_secret. The QUIC 0-RTT 691 secret is only used for protection of packets sent by the client. 693 client_0rtt_secret 694 = TLS-Exporter("EXPORTER-QUIC 0-RTT Secret" 695 "", Hash.length) 697 5.2.2. 1-RTT Secrets 699 1-RTT keys are used by both client and server after the TLS handshake 700 completes. There are two secrets used at any time: one is used to 701 derive packet protection keys for packets sent by the client, the 702 other for packet protection keys on packets sent by the server. 704 The initial client packet protection secret is exported from TLS 705 using the exporter label "EXPORTER-QUIC client 1-RTT Secret"; the 706 initial server packet protection secret uses the exporter label 707 "EXPORTER-QUIC server 1-RTT Secret". Both exporters use an empty 708 context. The size of the secret MUST be the size of the hash output 709 for the PRF hash function negotiated by TLS. 711 client_pp_secret_0 712 = TLS-Exporter("EXPORTER-QUIC client 1-RTT Secret" 713 "", Hash.length) 714 server_pp_secret_0 715 = TLS-Exporter("EXPORTER-QUIC server 1-RTT Secret" 716 "", Hash.length) 718 These secrets are used to derive the initial client and server packet 719 protection keys. 721 After a key update (see Section 7.2), these secrets are updated using 722 the HKDF-Expand-Label function defined in Section 7.1 of 723 [I-D.ietf-tls-tls13]. HKDF-Expand-Label uses the PRF hash function 724 negotiated by TLS. The replacement secret is derived using the 725 existing Secret, a Label of "QUIC client 1-RTT Secret" for the client 726 and "QUIC server 1-RTT Secret" for the server, an empty HashValue, 727 and the same output Length as the hash function selected by TLS for 728 its PRF. 730 client_pp_secret_ 731 = HKDF-Expand-Label(client_pp_secret_, 732 "QUIC client 1-RTT Secret", 733 "", Hash.length) 734 server_pp_secret_ 735 = HKDF-Expand-Label(server_pp_secret_, 736 "QUIC server 1-RTT Secret", 737 "", Hash.length) 739 This allows for a succession of new secrets to be created as needed. 741 HKDF-Expand-Label uses HKDF-Expand [RFC5869] with a specially 742 formatted info parameter, as shown: 744 HKDF-Expand-Label(Secret, Label, HashValue, Length) = 745 HKDF-Expand(Secret, HkdfLabel, Length) 747 Where HkdfLabel is specified as: 749 struct { 750 uint16 length = Length; 751 opaque label<10..255> = "tls13 " + Label; 752 uint8 hashLength; // Always 0 753 } HkdfLabel; 755 For example, the client packet protection secret uses an info 756 parameter of: 758 info = (HashLen / 256) || (HashLen % 256) || 0x1f || 759 "tls13 QUIC client 1-RTT secret" || 0x00 761 5.2.3. Packet Protection Key and IV 763 The complete key expansion uses an identical process for key 764 expansion as defined in Section 7.3 of [I-D.ietf-tls-tls13], using 765 different values for the input secret. QUIC uses the AEAD function 766 negotiated by TLS. 768 The packet protection key and IV used to protect the 0-RTT packets 769 sent by a client are derived from the QUIC 0-RTT secret. The packet 770 protection keys and IVs for 1-RTT packets sent by the client and 771 server are derived from the current generation of client_pp_secret 772 and server_pp_secret respectively. The length of the output is 773 determined by the requirements of the AEAD function selected by TLS. 774 The key length is the AEAD key size. As defined in Section 5.3 of 775 [I-D.ietf-tls-tls13], the IV length is the larger of 8 or N_MIN (see 776 Section 4 of [RFC5116]). For any secret S, the corresponding key and 777 IV are derived as shown below: 779 key = HKDF-Expand-Label(S, "key", "", key_length) 780 iv = HKDF-Expand-Label(S, "iv", "", iv_length) 782 The QUIC record protection initially starts without keying material. 783 When the TLS state machine reports that the ClientHello has been 784 sent, the 0-RTT keys can be generated and installed for writing. 785 When the TLS state machine reports completion of the handshake, the 786 1-RTT keys can be generated and installed for writing. 788 5.3. QUIC AEAD Usage 790 The Authentication Encryption with Associated Data (AEAD) [RFC5116] 791 function used for QUIC packet protection is AEAD that is negotiated 792 for use with the TLS connection. For example, if TLS is using the 793 TLS_AES_128_GCM_SHA256, the AEAD_AES_128_GCM function is used. 795 Regular QUIC packets are protected by an AEAD algorithm [RFC5116]. 796 Version negotiation and public reset packets are not protected. 798 Once TLS has provided a key, the contents of regular QUIC packets 799 immediately after any TLS messages have been sent are protected by 800 the AEAD selected by TLS. 802 The key, K, is either the client packet protection key 803 (client_pp_key_n) or the server packet protection key 804 (server_pp_key_n), derived as defined in Section 5.2. 806 The nonce, N, is formed by combining the packet protection IV (either 807 client_pp_iv_n or server_pp_iv_n) with the packet number. The 64 808 bits of the reconstructed QUIC packet number in network byte order is 809 left-padded with zeros to the size of the IV. The exclusive OR of 810 the padded packet number and the IV forms the AEAD nonce. 812 The associated data, A, for the AEAD is the contents of the QUIC 813 header, starting from the flags octet in either the short or long 814 header. 816 The input plaintext, P, for the AEAD is the content of the QUIC frame 817 following the header, as described in [QUIC-TRANSPORT]. 819 The output ciphertext, C, of the AEAD is transmitted in place of P. 821 Prior to TLS providing keys, no record protection is performed and 822 the plaintext, P, is transmitted unmodified. 824 5.4. Packet Numbers 826 QUIC has a single, contiguous packet number space. In comparison, 827 TLS restarts its sequence number each time that record protection 828 keys are changed. The sequence number restart in TLS ensures that a 829 compromise of the current traffic keys does not allow an attacker to 830 truncate the data that is sent after a key update by sending 831 additional packets under the old key (causing new packets to be 832 discarded). 834 QUIC does not assume a reliable transport and is required to handle 835 attacks where packets are dropped in other ways. QUIC is therefore 836 not affected by this form of truncation. 838 The QUIC packet number is not reset and it is not permitted to go 839 higher than its maximum value of 2^64-1. This establishes a hard 840 limit on the number of packets that can be sent. 842 Some AEAD functions have limits for how many packets can be encrypted 843 under the same key and IV (see for example [AEBounds]). This might 844 be lower than the packet number limit. An endpoint MUST initiate a 845 key update (Section 7.2) prior to exceeding any limit set for the 846 AEAD that is in use. 848 TLS maintains a separate sequence number that is used for record 849 protection on the connection that is hosted on stream 0. This 850 sequence number is not visible to QUIC. 852 5.5. Receiving Protected Packets 854 Once an endpoint successfully receives a packet with a given packet 855 number, it MUST discard all packets with higher packet numbers if 856 they cannot be successfully unprotected with either the same key, or 857 - if there is a key update - the next packet protection key (see 858 Section 7.2). Similarly, a packet that appears to trigger a key 859 update, but cannot be unprotected successfully MUST be discarded. 861 Failure to unprotect a packet does not necessarily indicate the 862 existence of a protocol error in a peer or an attack. The truncated 863 packet number encoding used in QUIC can cause packet numbers to be 864 decoded incorrectly if they are delayed significantly. 866 5.6. Packet Number Gaps 868 [QUIC-TRANSPORT]; Section 7.5.1.1 also requires a secret to compute 869 packet number gaps on connection ID transitions. That secret is 870 computed as: 872 packet_number_secret 873 = TLS-Exporter("EXPORTER-QUIC Packet Number Secret" 874 "", Hash.length) 876 6. Unprotected Packets 878 QUIC adds an integrity check to all cleartext packets. Cleartext 879 packets are not protected by the negotiated AEAD (see Section 5), but 880 instead include an integrity check. This check does not prevent the 881 packet from being altered, it exists for added resilience against 882 data corruption and to provide added assurance that the sender 883 intends to use QUIC. 885 Cleartext packets all use the long form of the QUIC header and so 886 will include a version number. For this version of QUIC, the 887 integrity check uses the 64-bit FNV-1a hash (see Section 6.2). The 888 output of this hash is appended to the payload of the packet. 890 The integrity check algorithm MAY change for other versions of the 891 protocol. 893 6.1. Integrity Check Processing 895 An endpoint sending a packet that has a long header and a type that 896 does not indicate that the packet will be protected (that is, 0-RTT 897 Encrypted (0x05), 1-RTT Encrypted (key phase 0) (0x06), or 1-RTT 898 Encrypted (key phase 1) (0x07)) first constructs the packet that it 899 sends without the integrity check. 901 The sender then calculates the integrity check over the entire 902 packet, starting from the type field. The output of the hash is 903 appended to the packet. 905 A receiver that receives an unprotected packet first checks that the 906 version is correct, then removes the trailing 8 octets. It 907 calculates the integrity check over the remainder of the packet. 908 Unprotected packets that do not contain a valid integrity check MUST 909 be discarded. 911 6.2. The 64-bit FNV-1a Algorithm 913 QUIC uses the 64-bit version of the alternative Fowler/Noll/Vo hash 914 (FNV-1a) [FNV]. 916 FNV-1a can be expressed in pseudocode as: 918 hash := offset basis 919 for each input octet: 920 hash := hash XOR input octet 921 hash := hash * prime 923 That is, a 64-bit unsigned integer is initialized with an offset 924 basis. Then, for each octet of the input, the exclusive binary OR of 925 the value is taken, then multiplied by a prime. Any overflow from 926 multiplication is discarded. 928 The offset basis for the 64-bit FNV-1a is the decimal value 929 14695981039346656037 (in hex, 0xcbf29ce484222325). The prime is 930 1099511628211 (in hex, 0x100000001b3; or as an expression 2^40 + 2^8 931 + 0xb3). 933 Once all octets have been processed in this fashion, the final 934 integer value is encoded as 8 octets in network byte order. 936 7. Key Phases 938 As TLS reports the availability of 0-RTT and 1-RTT keys, new keying 939 material can be exported from TLS and used for QUIC packet 940 protection. At each transition during the handshake a new secret is 941 exported from TLS and packet protection keys are derived from that 942 secret. 944 Every time that a new set of keys is used for protecting outbound 945 packets, the KEY_PHASE bit in the public flags is toggled. 0-RTT 946 protected packets use the QUIC long header, they do not use the 947 KEY_PHASE bit to select the correct keys (see Section 7.1.1). 949 Once the connection is fully enabled, the KEY_PHASE bit allows a 950 recipient to detect a change in keying material without necessarily 951 needing to receive the first packet that triggered the change. An 952 endpoint that notices a changed KEY_PHASE bit can update keys and 953 decrypt the packet that contains the changed bit, see Section 7.2. 955 The KEY_PHASE bit is included as the 0x20 bit of the QUIC short 956 header, or is determined by the packet type from the long header (a 957 type of 0x06 indicates a key phase of 0, 0x07 indicates key phase 1). 959 Transitions between keys during the handshake are complicated by the 960 need to ensure that TLS handshake messages are sent with the correct 961 packet protection. 963 7.1. Packet Protection for the TLS Handshake 965 The initial exchange of packets are sent without protection. These 966 packets use a cleartext packet type. 968 TLS handshake messages MUST NOT be protected using QUIC packet 969 protection. All TLS handshake messages up to the TLS Finished 970 message sent by either endpoint use cleartext packets. 972 Any TLS handshake messages that are sent after completing the TLS 973 handshake do not need special packet protection rules. Packets 974 containing these messages use the packet protection keys that are 975 current at the time of sending (or retransmission). 977 Like the client, a server MUST send retransmissions of its 978 unprotected handshake messages or acknowledgments for unprotected 979 handshake messages sent by the client in cleartext packets. 981 7.1.1. Initial Key Transitions 983 Once the TLS handshake is complete, keying material is exported from 984 TLS and QUIC packet protection commences. 986 Packets protected with 1-RTT keys initially have a KEY_PHASE bit set 987 to 0. This bit inverts with each subsequent key update (see 988 Section 7.2). 990 If the client sends 0-RTT data, it uses the 0-RTT packet type. The 991 packet that contains the TLS EndOfEarlyData and Finished messages are 992 sent in cleartext packets. 994 Using distinct packet types during the handshake for handshake 995 messages, 0-RTT data, and 1-RTT data ensures that the server is able 996 to distinguish between the different keys used to remove packet 997 protection. All of these packets can arrive concurrently at a 998 server. 1000 A server might choose to retain 0-RTT packets that arrive before a 1001 TLS ClientHello. The server can then use those packets once the 1002 ClientHello arrives. However, the potential for denial of service 1003 from buffering 0-RTT packets is significant. These packets cannot be 1004 authenticated and so might be employed by an attacker to exhaust 1005 server resources. Limiting the number of packets that are saved 1006 might be necessary. 1008 The server transitions to using 1-RTT keys after sending its first 1009 flight of TLS handshake messages. From this point, the server 1010 protects all packets with 1-RTT keys. Future packets are therefore 1011 protected with 1-RTT keys. Initially, these are marked with a 1012 KEY_PHASE of 0. 1014 7.1.2. Retransmission and Acknowledgment of Unprotected Packets 1016 TLS handshake messages from both client and server are critical to 1017 the key exchange. The contents of these messages determines the keys 1018 used to protect later messages. If these handshake messages are 1019 included in packets that are protected with these keys, they will be 1020 indecipherable to the recipient. 1022 Even though newer keys could be available when retransmitting, 1023 retransmissions of these handshake messages MUST be sent in cleartext 1024 packets. An endpoint MUST generate ACK frames for these messages and 1025 send them in cleartext packets. 1027 A HelloRetryRequest handshake message might be used to reject an 1028 initial ClientHello. A HelloRetryRequest handshake message is sent 1029 in a Server Stateless Retry packet; any second ClientHello that is 1030 sent in response uses a Client Initial packet type. Neither packet 1031 is protected. This is natural, because no new keying material will 1032 be available when these messages need to be sent. Upon receipt of a 1033 HelloRetryRequest, a client SHOULD cease any transmission of 0-RTT 1034 data; 0-RTT data will only be discarded by any server that sends a 1035 HelloRetryRequest. 1037 The packet type ensures that protected packets are clearly 1038 distinguished from unprotected packets. Loss or reordering might 1039 cause unprotected packets to arrive once 1-RTT keys are in use, 1040 unprotected packets are easily distinguished from 1-RTT packets using 1041 the packet type. 1043 Once 1-RTT keys are available to an endpoint, it no longer needs the 1044 TLS handshake messages that are carried in unprotected packets. 1046 However, a server might need to retransmit its TLS handshake messages 1047 in response to receiving an unprotected packet that contains ACK 1048 frames. A server MUST process ACK frames in unprotected packets 1049 until the TLS handshake is reported as complete, or it receives an 1050 ACK frame in a protected packet that acknowledges all of its 1051 handshake messages. 1053 To limit the number of key phases that could be active, an endpoint 1054 MUST NOT initiate a key update while there are any unacknowledged 1055 handshake messages, see Section 7.2. 1057 7.2. Key Update 1059 Once the TLS handshake is complete, the KEY_PHASE bit allows for 1060 refreshes of keying material by either peer. Endpoints start using 1061 updated keys immediately without additional signaling; the change in 1062 the KEY_PHASE bit indicates that a new key is in use. 1064 An endpoint MUST NOT initiate more than one key update at a time. A 1065 new key cannot be used until the endpoint has received and 1066 successfully decrypted a packet with a matching KEY_PHASE. Note that 1067 when 0-RTT is attempted the value of the KEY_PHASE bit will be 1068 different on packets sent by either peer. 1070 A receiving endpoint detects an update when the KEY_PHASE bit doesn't 1071 match what it is expecting. It creates a new secret (see 1072 Section 5.2) and the corresponding read key and IV. If the packet 1073 can be decrypted and authenticated using these values, then the keys 1074 it uses for packet protection are also updated. The next packet sent 1075 by the endpoint will then use the new keys. 1077 An endpoint doesn't need to send packets immediately when it detects 1078 that its peer has updated keys. The next packet that it sends will 1079 simply use the new keys. If an endpoint detects a second update 1080 before it has sent any packets with updated keys it indicates that 1081 its peer has updated keys twice without awaiting a reciprocal update. 1082 An endpoint MUST treat consecutive key updates as a fatal error and 1083 abort the connection. 1085 An endpoint SHOULD retain old keys for a short period to allow it to 1086 decrypt packets with smaller packet numbers than the packet that 1087 triggered the key update. This allows an endpoint to consume packets 1088 that are reordered around the transition between keys. Packets with 1089 higher packet numbers always use the updated keys and MUST NOT be 1090 decrypted with old keys. 1092 Keys and their corresponding secrets SHOULD be discarded when an 1093 endpoint has received all packets with sequence numbers lower than 1094 the lowest sequence number used for the new key. An endpoint might 1095 discard keys if it determines that the length of the delay to 1096 affected packets is excessive. 1098 This ensures that once the handshake is complete, packets with the 1099 same KEY_PHASE will have the same packet protection keys, unless 1100 there are multiple key updates in a short time frame succession and 1101 significant packet reordering. 1103 Initiating Peer Responding Peer 1105 @M QUIC Frames 1106 New Keys -> @N 1107 @N QUIC Frames 1108 --------> 1109 QUIC Frames @M 1110 New Keys -> @N 1111 QUIC Frames @N 1112 <-------- 1114 Figure 5: Key Update 1116 As shown in Figure 3 and Figure 5, there is never a situation where 1117 there are more than two different sets of keying material that might 1118 be received by a peer. Once both sending and receiving keys have 1119 been updated, 1121 A server cannot initiate a key update until it has received the 1122 client's Finished message. Otherwise, packets protected by the 1123 updated keys could be confused for retransmissions of handshake 1124 messages. A client cannot initiate a key update until all of its 1125 handshake messages have been acknowledged by the server. 1127 A packet that triggers a key update could arrive after successfully 1128 processing a packet with a higher packet number. This is only 1129 possible if there is a key compromise and an attack, or if the peer 1130 is incorrectly reverting to use of old keys. Because the latter 1131 cannot be differentiated from an attack, an endpoint MUST immediately 1132 terminate the connection if it detects this condition. 1134 8. Client Address Validation 1136 Two tools are provided by TLS to enable validation of client source 1137 addresses at a server: the cookie in the HelloRetryRequest message, 1138 and the ticket in the NewSessionTicket message. 1140 8.1. HelloRetryRequest Address Validation 1142 The cookie extension in the TLS HelloRetryRequest message allows a 1143 server to perform source address validation during the handshake. 1145 When QUIC requests address validation during the processing of the 1146 first ClientHello, the token it provides is included in the cookie 1147 extension of a HelloRetryRequest. As long as the cookie cannot be 1148 successfully guessed by a client, the server can be assured that the 1149 client received the HelloRetryRequest if it includes the value in a 1150 second ClientHello. 1152 An initial ClientHello never includes a cookie extension. Thus, if a 1153 server constructs a cookie that contains all the information 1154 necessary to reconstruct state, it can discard local state after 1155 sending a HelloRetryRequest. Presence of a valid cookie in a 1156 ClientHello indicates that the ClientHello is a second attempt from 1157 the client. 1159 An address validation token can be extracted from a second 1160 ClientHello and passed to the transport for further validation. If 1161 that validation fails, the server MUST fail the TLS handshake and 1162 send an illegal_parameter alert. 1164 Combining address validation with the other uses of HelloRetryRequest 1165 ensures that there are fewer ways in which an additional round-trip 1166 can be added to the handshake. In particular, this makes it possible 1167 to combine a request for address validation with a request for a 1168 different client key share. 1170 If TLS needs to send a HelloRetryRequest for other reasons, it needs 1171 to ensure that it can correctly identify the reason that the 1172 HelloRetryRequest was generated. During the processing of a second 1173 ClientHello, TLS does not need to consult the transport protocol 1174 regarding address validation if address validation was not requested 1175 originally. In such cases, the cookie extension could either be 1176 absent or it could indicate that an address validation token is not 1177 present. 1179 8.1.1. Stateless Address Validation 1181 A server can use the cookie extension to store all state necessary to 1182 continue the connection. This allows a server to avoid committing 1183 state for clients that have unvalidated source addresses. 1185 For instance, a server could use a statically-configured key to 1186 encrypt the information that it requires and include that information 1187 in the cookie. In addition to address validation information, a 1188 server that uses encryption also needs to be able recover the hash of 1189 the ClientHello and its length, plus any information it needs in 1190 order to reconstruct the HelloRetryRequest. 1192 8.1.2. Sending HelloRetryRequest 1194 A server does not need to maintain state for the connection when 1195 sending a HelloRetryRequest message. This might be necessary to 1196 avoid creating a denial of service exposure for the server. However, 1197 this means that information about the transport will be lost at the 1198 server. This includes the stream offset of stream 0, the packet 1199 number that the server selects, and any opportunity to measure round 1200 trip time. 1202 A server MUST send a TLS HelloRetryRequest in a Server Stateless 1203 Retry packet. Using a Server Stateless Retry packet causes the 1204 client to reset stream offsets. It also avoids the need for the 1205 server select an initial packet number, which would need to be 1206 remembered so that subsequent packets could be correctly numbered. 1208 A HelloRetryRequest message MUST NOT be split between multiple Server 1209 Stateless Retry packets. This means that HelloRetryRequest is 1210 subject to the same size constraints as a ClientHello (see 1211 Section 4.4). 1213 8.2. NewSessionTicket Address Validation 1215 The ticket in the TLS NewSessionTicket message allows a server to 1216 provide a client with a similar sort of token. When a client resumes 1217 a TLS connection - whether or not 0-RTT is attempted - it includes 1218 the ticket in the handshake message. As with the HelloRetryRequest 1219 cookie, the server includes the address validation token in the 1220 ticket. TLS provides the token it extracts from the session ticket 1221 to the transport when it asks whether source address validation is 1222 needed. 1224 If both a HelloRetryRequest cookie and a session ticket are present 1225 in the ClientHello, only the token from the cookie is passed to the 1226 transport. The presence of a cookie indicates that this is a second 1227 ClientHello - the token from the session ticket will have been 1228 provided to the transport when it appeared in the first ClientHello. 1230 A server can send a NewSessionTicket message at any time. This 1231 allows it to update the state - and the address validation token - 1232 that is included in the ticket. This might be done to refresh the 1233 ticket or token, or it might be generated in response to changes in 1234 the state of the connection. QUIC can request that a 1235 NewSessionTicket be sent by providing a new address validation token. 1237 A server that intends to support 0-RTT SHOULD provide an address 1238 validation token immediately after completing the TLS handshake. 1240 8.3. Address Validation Token Integrity 1242 TLS MUST provide integrity protection for address validation token 1243 unless the transport guarantees integrity protection by other means. 1244 For a NewSessionTicket that includes confidential information - such 1245 as the resumption secret - including the token under authenticated 1246 encryption ensures that the token gains both confidentiality and 1247 integrity protection without duplicating the overheads of that 1248 protection. 1250 9. Pre-handshake QUIC Messages 1252 Implementations MUST NOT exchange data on any stream other than 1253 stream 0 without packet protection. QUIC requires the use of several 1254 types of frame for managing loss detection and recovery during this 1255 phase. In addition, it might be useful to use the data acquired 1256 during the exchange of unauthenticated messages for congestion 1257 control. 1259 This section generally only applies to TLS handshake messages from 1260 both peers and acknowledgments of the packets carrying those 1261 messages. In many cases, the need for servers to provide 1262 acknowledgments is minimal, since the messages that clients send are 1263 small and implicitly acknowledged by the server's responses. 1265 The actions that a peer takes as a result of receiving an 1266 unauthenticated packet needs to be limited. In particular, state 1267 established by these packets cannot be retained once record 1268 protection commences. 1270 There are several approaches possible for dealing with 1271 unauthenticated packets prior to handshake completion: 1273 o discard and ignore them 1275 o use them, but reset any state that is established once the 1276 handshake completes 1278 o use them and authenticate them afterwards; failing the handshake 1279 if they can't be authenticated 1281 o save them and use them when they can be properly authenticated 1283 o treat them as a fatal error 1284 Different strategies are appropriate for different types of data. 1285 This document proposes that all strategies are possible depending on 1286 the type of message. 1288 o Transport parameters are made usable and authenticated as part of 1289 the TLS handshake (see Section 10.2). 1291 o Most unprotected messages are treated as fatal errors when 1292 received except for the small number necessary to permit the 1293 handshake to complete (see Section 9.1). 1295 o Protected packets can either be discarded or saved and later used 1296 (see Section 9.3). 1298 9.1. Unprotected Packets Prior to Handshake Completion 1300 This section describes the handling of messages that are sent and 1301 received prior to the completion of the TLS handshake. 1303 Sending and receiving unprotected messages is hazardous. Unless 1304 expressly permitted, receipt of an unprotected message of any kind 1305 MUST be treated as a fatal error. 1307 9.1.1. STREAM Frames 1309 "STREAM" frames for stream 0 are permitted. These carry the TLS 1310 handshake messages. Once 1-RTT keys are available, unprotected 1311 "STREAM" frames on stream 0 can be ignored. 1313 Receiving unprotected "STREAM" frames for other streams MUST be 1314 treated as a fatal error. 1316 9.1.2. ACK Frames 1318 "ACK" frames are permitted prior to the handshake being complete. 1319 Information learned from "ACK" frames cannot be entirely relied upon, 1320 since an attacker is able to inject these packets. Timing and packet 1321 retransmission information from "ACK" frames is critical to the 1322 functioning of the protocol, but these frames might be spoofed or 1323 altered. 1325 Endpoints MUST NOT use an "ACK" frame in an unprotected packet to 1326 acknowledge packets that were protected by 0-RTT or 1-RTT keys. An 1327 endpoint MUST treat receipt of an "ACK" frame in an unprotected 1328 packet that claims to acknowledge protected packets as a connection 1329 error of type OPTIMISTIC_ACK. An endpoint that can read protected 1330 data is always able to send protected data. 1332 Note: 0-RTT data can be acknowledged by the server as it receives 1333 it, but any packets containing acknowledgments of 0-RTT data 1334 cannot have packet protection removed by the client until the TLS 1335 handshake is complete. The 1-RTT keys necessary to remove packet 1336 protection cannot be derived until the client receives all server 1337 handshake messages. 1339 An endpoint SHOULD use data from "ACK" frames carried in unprotected 1340 packets or packets protected with 0-RTT keys only during the initial 1341 handshake. All "ACK" frames contained in unprotected packets that 1342 are received after successful receipt of a packet protected with 1343 1-RTT keys MUST be discarded. An endpoint SHOULD therefore include 1344 acknowledgments for unprotected and any packets protected with 0-RTT 1345 keys until it sees an acknowledgment for a packet that is both 1346 protected with 1-RTT keys and contains an "ACK" frame. 1348 9.1.3. Updates to Data and Stream Limits 1350 "MAX_DATA", "MAX_STREAM_DATA", "BLOCKED", "STREAM_BLOCKED", and 1351 "MAX_STREAM_ID" frames MUST NOT be sent unprotected. 1353 Though data is exchanged on stream 0, the initial flow control window 1354 on that stream is sufficiently large to allow the TLS handshake to 1355 complete. This limits the maximum size of the TLS handshake and 1356 would prevent a server or client from using an abnormally large 1357 certificate chain. 1359 Stream 0 is exempt from the connection-level flow control window. 1361 Consequently, there is no need to signal being blocked on flow 1362 control. 1364 Similarly, there is no need to increase the number of allowed streams 1365 until the handshake completes. 1367 9.1.4. Denial of Service with Unprotected Packets 1369 Accepting unprotected - specifically unauthenticated - packets 1370 presents a denial of service risk to endpoints. An attacker that is 1371 able to inject unprotected packets can cause a recipient to drop even 1372 protected packets with a matching sequence number. The spurious 1373 packet shadows the genuine packet, causing the genuine packet to be 1374 ignored as redundant. 1376 Once the TLS handshake is complete, both peers MUST ignore 1377 unprotected packets. From that point onward, unprotected messages 1378 can be safely dropped. 1380 Since only TLS handshake packets and acknowledgments are sent in the 1381 clear, an attacker is able to force implementations to rely on 1382 retransmission for packets that are lost or shadowed. Thus, an 1383 attacker that intends to deny service to an endpoint has to drop or 1384 shadow protected packets in order to ensure that their victim 1385 continues to accept unprotected packets. The ability to shadow 1386 packets means that an attacker does not need to be on path. 1388 In addition to causing valid packets to be dropped, an attacker can 1389 generate packets with an intent of causing the recipient to expend 1390 processing resources. See Section 11.2 for a discussion of these 1391 risks. 1393 To avoid receiving TLS packets that contain no useful data, a TLS 1394 implementation MUST reject empty TLS handshake records and any record 1395 that is not permitted by the TLS state machine. Any TLS application 1396 data or alerts that is received prior to the end of the handshake 1397 MUST be treated as a fatal error. 1399 9.2. Use of 0-RTT Keys 1401 If 0-RTT keys are available, the lack of replay protection means that 1402 restrictions on their use are necessary to avoid replay attacks on 1403 the protocol. 1405 A client MUST only use 0-RTT keys to protect data that is idempotent. 1406 A client MAY wish to apply additional restrictions on what data it 1407 sends prior to the completion of the TLS handshake. A client 1408 otherwise treats 0-RTT keys as equivalent to 1-RTT keys. 1410 A client that receives an indication that its 0-RTT data has been 1411 accepted by a server can send 0-RTT data until it receives all of the 1412 server's handshake messages. A client SHOULD stop sending 0-RTT data 1413 if it receives an indication that 0-RTT data has been rejected. 1415 A server MUST NOT use 0-RTT keys to protect packets. 1417 9.3. Receiving Out-of-Order Protected Frames 1419 Due to reordering and loss, protected packets might be received by an 1420 endpoint before the final TLS handshake messages are received. A 1421 client will be unable to decrypt 1-RTT packets from the server, 1422 whereas a server will be able to decrypt 1-RTT packets from the 1423 client. 1425 Packets protected with 1-RTT keys MAY be stored and later decrypted 1426 and used once the handshake is complete. A server MUST NOT use 1-RTT 1427 protected packets before verifying either the client Finished message 1428 or - in the case that the server has chosen to use a pre-shared key - 1429 the pre-shared key binder (see Section 4.2.8 of 1430 [I-D.ietf-tls-tls13]). Verifying these values provides the server 1431 with an assurance that the ClientHello has not been modified. 1433 A server could receive packets protected with 0-RTT keys prior to 1434 receiving a TLS ClientHello. The server MAY retain these packets for 1435 later decryption in anticipation of receiving a ClientHello. 1437 Receiving and verifying the TLS Finished message is critical in 1438 ensuring the integrity of the TLS handshake. A server MUST NOT use 1439 protected packets from the client prior to verifying the client 1440 Finished message if its response depends on client authentication. 1442 10. QUIC-Specific Additions to the TLS Handshake 1444 QUIC uses the TLS handshake for more than just negotiation of 1445 cryptographic parameters. The TLS handshake validates protocol 1446 version selection, provides preliminary values for QUIC transport 1447 parameters, and allows a server to perform return routeability checks 1448 on clients. 1450 10.1. Protocol and Version Negotiation 1452 The QUIC version negotiation mechanism is used to negotiate the 1453 version of QUIC that is used prior to the completion of the 1454 handshake. However, this packet is not authenticated, enabling an 1455 active attacker to force a version downgrade. 1457 To ensure that a QUIC version downgrade is not forced by an attacker, 1458 version information is copied into the TLS handshake, which provides 1459 integrity protection for the QUIC negotiation. This does not prevent 1460 version downgrade prior to the completion of the handshake, though it 1461 means that a downgrade causes a handshake failure. 1463 TLS uses Application Layer Protocol Negotiation (ALPN) [RFC7301] to 1464 select an application protocol. The application-layer protocol MAY 1465 restrict the QUIC versions that it can operate over. Servers MUST 1466 select an application protocol compatible with the QUIC version that 1467 the client has selected. 1469 If the server cannot select a compatible combination of application 1470 protocol and QUIC version, it MUST abort the connection. A client 1471 MUST abort a connection if the server picks an incompatible 1472 combination of QUIC version and ALPN identifier. 1474 10.2. QUIC Transport Parameters Extension 1476 QUIC transport parameters are carried in a TLS extension. Different 1477 versions of QUIC might define a different format for this struct. 1479 Including transport parameters in the TLS handshake provides 1480 integrity protection for these values. 1482 enum { 1483 quic_transport_parameters(26), (65535) 1484 } ExtensionType; 1486 The "extension_data" field of the quic_transport_parameters extension 1487 contains a value that is defined by the version of QUIC that is in 1488 use. The quic_transport_parameters extension carries a 1489 TransportParameters when the version of QUIC defined in 1490 [QUIC-TRANSPORT] is used. 1492 The quic_transport_parameters extension is carried in the ClientHello 1493 and the EncryptedExtensions messages during the handshake. The 1494 extension MAY be included in a NewSessionTicket message. 1496 10.3. Priming 0-RTT 1498 QUIC uses TLS without modification. Therefore, it is possible to use 1499 a pre-shared key that was established in a TLS handshake over TCP to 1500 enable 0-RTT in QUIC. Similarly, QUIC can provide a pre-shared key 1501 that can be used to enable 0-RTT in TCP. 1503 All the restrictions on the use of 0-RTT apply, with the exception of 1504 the ALPN label, which MUST only change to a label that is explicitly 1505 designated as being compatible. The client indicates which ALPN 1506 label it has chosen by placing that ALPN label first in the ALPN 1507 extension. 1509 The certificate that the server uses MUST be considered valid for 1510 both connections, which will use different protocol stacks and could 1511 use different port numbers. For instance, HTTP/1.1 and HTTP/2 1512 operate over TLS and TCP, whereas QUIC operates over UDP. 1514 Source address validation is not completely portable between 1515 different protocol stacks. Even if the source IP address remains 1516 constant, the port number is likely to be different. Packet 1517 reflection attacks are still possible in this situation, though the 1518 set of hosts that can initiate these attacks is greatly reduced. A 1519 server might choose to avoid source address validation for such a 1520 connection, or allow an increase to the amount of data that it sends 1521 toward the client without source validation. 1523 11. Security Considerations 1525 There are likely to be some real clangers here eventually, but the 1526 current set of issues is well captured in the relevant sections of 1527 the main text. 1529 Never assume that because it isn't in the security considerations 1530 section it doesn't affect security. Most of this document does. 1532 11.1. Packet Reflection Attack Mitigation 1534 A small ClientHello that results in a large block of handshake 1535 messages from a server can be used in packet reflection attacks to 1536 amplify the traffic generated by an attacker. 1538 Certificate caching [RFC7924] can reduce the size of the server's 1539 handshake messages significantly. 1541 QUIC requires that the packet containing a ClientHello be padded to a 1542 minimum size. A server is less likely to generate a packet 1543 reflection attack if the data it sends is a small multiple of this 1544 size. A server SHOULD use a HelloRetryRequest if the size of the 1545 handshake messages it sends is likely to significantly exceed the 1546 size of the packet containing the ClientHello. 1548 11.2. Peer Denial of Service 1550 QUIC, TLS and HTTP/2 all contain a messages that have legitimate uses 1551 in some contexts, but that can be abused to cause a peer to expend 1552 processing resources without having any observable impact on the 1553 state of the connection. If processing is disproportionately large 1554 in comparison to the observable effects on bandwidth or state, then 1555 this could allow a malicious peer to exhaust processing capacity 1556 without consequence. 1558 QUIC prohibits the sending of empty "STREAM" frames unless they are 1559 marked with the FIN bit. This prevents "STREAM" frames from being 1560 sent that only waste effort. 1562 TLS records SHOULD always contain at least one octet of a handshake 1563 messages or alert. Records containing only padding are permitted 1564 during the handshake, but an excessive number might be used to 1565 generate unnecessary work. Once the TLS handshake is complete, 1566 endpoints SHOULD NOT send TLS application data records unless it is 1567 to hide the length of QUIC records. QUIC packet protection does not 1568 include any allowance for padding; padded TLS application data 1569 records can be used to mask the length of QUIC frames. 1571 While there are legitimate uses for some redundant packets, 1572 implementations SHOULD track redundant packets and treat excessive 1573 volumes of any non-productive packets as indicative of an attack. 1575 12. Error codes 1577 The portion of the QUIC error code space allocated for the crypto 1578 handshake is 0xC0000000-0xFFFFFFFF. The following error codes are 1579 defined when TLS is used for the crypto handshake: 1581 TLS_HANDSHAKE_FAILED (0xC000001C): The TLS handshake failed. 1583 TLS_FATAL_ALERT_GENERATED (0xC000001D): A TLS fatal alert was sent, 1584 causing the TLS connection to end prematurely. 1586 TLS_FATAL_ALERT_RECEIVED (0xC000001E): A TLS fatal alert was 1587 received, causing the TLS connection to end prematurely. 1589 13. IANA Considerations 1591 This document does not create any new IANA registries, but it does 1592 utilize the following registries: 1594 o QUIC Transport Parameter Registry - IANA is to register the three 1595 values found in Section 12. 1597 o TLS ExtensionsType Registry - IANA is to register the 1598 quic_transport_parameters extension found in Section 10.2. 1599 Assigning 26 to the extension would be greatly appreciated. The 1600 Recommended column is to be marked Yes. 1602 o TLS Exporter Label Registry - IANA is requested to register 1603 "EXPORTER-QUIC 0-RTT Secret" from Section 5.2.1; "EXPORTER-QUIC 1604 client 1-RTT Secret" and "EXPORTER-QUIC server 1-RTT Secret" from 1605 Section 5.2.2; "EXPORTER-QUIC Packet Number Secret" Section 5.6. 1606 The DTLS column is to be marked No. The Recommended column is to 1607 be marked Yes. 1609 14. References 1611 14.1. Normative References 1613 [I-D.ietf-tls-tls13] 1614 Rescorla, E., "The Transport Layer Security (TLS) Protocol 1615 Version 1.3", draft-ietf-tls-tls13-21 (work in progress), 1616 July 2017. 1618 [QUIC-TRANSPORT] 1619 Iyengar, J., Ed. and M. Thomson, Ed., "QUIC: A UDP-Based 1620 Multiplexed and Secure Transport", draft-ietf-quic- 1621 transport (work in progress), August 2017. 1623 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 1624 Requirement Levels", BCP 14, RFC 2119, 1625 DOI 10.17487/RFC2119, March 1997, 1626 . 1628 [RFC5116] McGrew, D., "An Interface and Algorithms for Authenticated 1629 Encryption", RFC 5116, DOI 10.17487/RFC5116, January 2008, 1630 . 1632 [RFC5869] Krawczyk, H. and P. Eronen, "HMAC-based Extract-and-Expand 1633 Key Derivation Function (HKDF)", RFC 5869, 1634 DOI 10.17487/RFC5869, May 2010, 1635 . 1637 [RFC7301] Friedl, S., Popov, A., Langley, A., and E. Stephan, 1638 "Transport Layer Security (TLS) Application-Layer Protocol 1639 Negotiation Extension", RFC 7301, DOI 10.17487/RFC7301, 1640 July 2014, . 1642 14.2. Informative References 1644 [AEBounds] 1645 Luykx, A. and K. Paterson, "Limits on Authenticated 1646 Encryption Use in TLS", March 2016, 1647 . 1649 [FNV] Fowler, G., Noll, L., Vo, K., Eastlake, D., and T. Hansen, 1650 "The FNV Non-Cryptographic Hash Algorithm", draft- 1651 eastlake-fnv-13 (work in progress), June 2017. 1653 [QUIC-HTTP] 1654 Bishop, M., Ed., "Hypertext Transfer Protocol (HTTP) over 1655 QUIC", draft-ietf-quic-http (work in progress), August 1656 2017. 1658 [QUIC-RECOVERY] 1659 Iyengar, J., Ed. and I. Swett, Ed., "QUIC Loss Detection 1660 and Congestion Control", draft-ietf-quic-recovery (work in 1661 progress), August 2017. 1663 [RFC2818] Rescorla, E., "HTTP Over TLS", RFC 2818, 1664 DOI 10.17487/RFC2818, May 2000, 1665 . 1667 [RFC5280] Cooper, D., Santesson, S., Farrell, S., Boeyen, S., 1668 Housley, R., and W. Polk, "Internet X.509 Public Key 1669 Infrastructure Certificate and Certificate Revocation List 1670 (CRL) Profile", RFC 5280, DOI 10.17487/RFC5280, May 2008, 1671 . 1673 [RFC7924] Santesson, S. and H. Tschofenig, "Transport Layer Security 1674 (TLS) Cached Information Extension", RFC 7924, 1675 DOI 10.17487/RFC7924, July 2016, 1676 . 1678 Appendix A. Contributors 1680 Ryan Hamilton was originally an author of this specification. 1682 Appendix B. Acknowledgments 1684 This document has benefited from input from Dragana Damjanovic, 1685 Christian Huitema, Jana Iyengar, Adam Langley, Roberto Peon, Eric 1686 Rescorla, Ian Swett, and many others. 1688 Appendix C. Change Log 1690 *RFC Editor's Note:* Please remove this section prior to 1691 publication of a final version of this document. 1693 Issue and pull request numbers are listed with a leading octothorp. 1695 C.1. Since draft-ietf-quic-tls-04 1697 o Update labels used in HKDF-Expand-Label to match TLS 1.3 (#642) 1699 C.2. Since draft-ietf-quic-tls-03 1701 No significant changes. 1703 C.3. Since draft-ietf-quic-tls-02 1705 o Updates to match changes in transport draft 1707 C.4. Since draft-ietf-quic-tls-01 1709 o Use TLS alerts to signal TLS errors (#272, #374) 1711 o Require ClientHello to fit in a single packet (#338) 1713 o The second client handshake flight is now sent in the clear (#262, 1714 #337) 1716 o The QUIC header is included as AEAD Associated Data (#226, #243, 1717 #302) 1719 o Add interface necessary for client address validation (#275) 1721 o Define peer authentication (#140) 1723 o Require at least TLS 1.3 (#138) 1725 o Define transport parameters as a TLS extension (#122) 1727 o Define handling for protected packets before the handshake 1728 completes (#39) 1730 o Decouple QUIC version and ALPN (#12) 1732 C.5. Since draft-ietf-quic-tls-00 1734 o Changed bit used to signal key phase 1736 o Updated key phase markings during the handshake 1738 o Added TLS interface requirements section 1740 o Moved to use of TLS exporters for key derivation 1742 o Moved TLS error code definitions into this document 1744 C.6. Since draft-thomson-quic-tls-01 1746 o Adopted as base for draft-ietf-quic-tls 1748 o Updated authors/editors list 1750 o Added status note 1752 Authors' Addresses 1754 Martin Thomson (editor) 1755 Mozilla 1757 Email: martin.thomson@gmail.com 1759 Sean Turner (editor) 1760 sn3rd 1762 Email: sean@sn3rd.com