documented update
[gnutls.git] / doc / protocol / rfc4347.txt
blob7231bb7cd25904ae46c66782d702dc7e08c440af
7 Network Working Group                                        E. Rescorla
8 Request for Comments: 4347                                    RTFM, Inc.
9 Category: Standards Track                                    N. Modadugu
10                                                      Stanford University
11                                                               April 2006
14                    Datagram Transport Layer Security
17 Status of This Memo
19    This document specifies an Internet standards track protocol for the
20    Internet community, and requests discussion and suggestions for
21    improvements.  Please refer to the current edition of the "Internet
22    Official Protocol Standards" (STD 1) for the standardization state
23    and status of this protocol.  Distribution of this memo is unlimited.
25 Copyright Notice
27    Copyright (C) The Internet Society (2006).
29 Abstract
31    This document specifies Version 1.0 of the Datagram Transport Layer
32    Security (DTLS) protocol.  The DTLS protocol provides communications
33    privacy for datagram protocols.  The protocol allows client/server
34    applications to communicate in a way that is designed to prevent
35    eavesdropping, tampering, or message forgery.  The DTLS protocol is
36    based on the Transport Layer Security (TLS) protocol and provides
37    equivalent security guarantees.  Datagram semantics of the underlying
38    transport are preserved by the DTLS protocol.
40 Table of Contents
42    1. Introduction ....................................................2
43       1.1. Requirements Terminology ...................................3
44    2. Usage Model .....................................................3
45    3. Overview of DTLS ................................................4
46       3.1. Loss-Insensitive Messaging .................................4
47       3.2. Providing Reliability for Handshake ........................4
48            3.2.1. Packet Loss .........................................5
49            3.2.2. Reordering ..........................................5
50            3.2.3. Message Size ........................................5
51       3.3. Replay Detection ...........................................6
52    4. Differences from TLS ............................................6
53       4.1. Record Layer ...............................................6
54            4.1.1. Transport Layer Mapping .............................7
58 Rescorla & Modadugu         Standards Track                     [Page 1]
60 RFC 4347           Datagram Transport Layer Security          April 2006
63                   4.1.1.1. PMTU Discovery .............................8
64            4.1.2. Record Payload Protection ...........................9
65                   4.1.2.1. MAC ........................................9
66                   4.1.2.2. Null or Standard Stream Cipher .............9
67                   4.1.2.3. Block Cipher ..............................10
68                   4.1.2.4. New Cipher Suites .........................10
69                   4.1.2.5. Anti-replay ...............................10
70       4.2. The DTLS Handshake Protocol ...............................11
71            4.2.1. Denial of Service Countermeasures ..................11
72            4.2.2. Handshake Message Format ...........................13
73            4.2.3. Message Fragmentation and Reassembly ...............15
74            4.2.4. Timeout and Retransmission .........................15
75                   4.2.4.1. Timer Values ..............................18
76            4.2.5. ChangeCipherSpec ...................................19
77            4.2.6. Finished Messages ..................................19
78            4.2.7. Alert Messages .....................................19
79       4.3. Summary of new syntax .....................................19
80            4.3.1. Record Layer .......................................20
81            4.3.2. Handshake Protocol .................................20
82    5. Security Considerations ........................................21
83    6. Acknowledgements ...............................................22
84    7. IANA Considerations ............................................22
85    8. References .....................................................22
86       8.1. Normative References ......................................22
87       8.2. Informative References ....................................23
89 1. Introduction
91    TLS [TLS] is the most widely deployed protocol for securing network
92    traffic.  It is widely used for protecting Web traffic and for e-mail
93    protocols such as IMAP [IMAP] and POP [POP].  The primary advantage
94    of TLS is that it provides a transparent connection-oriented channel.
95    Thus, it is easy to secure an application protocol by inserting TLS
96    between the application layer and the transport layer.  However, TLS
97    must run over a reliable transport channel -- typically TCP [TCP].
98    It therefore cannot be used to secure unreliable datagram traffic.
100    However, over the past few years an increasing number of application
101    layer protocols have been designed that use UDP transport.  In
102    particular protocols such as the Session Initiation Protocol (SIP)
103    [SIP] and electronic gaming protocols are increasingly popular.
104    (Note that SIP can run over both TCP and UDP, but that there are
105    situations in which UDP is preferable).  Currently, designers of
106    these applications are faced with a number of unsatisfactory choices.
107    First, they can use IPsec [RFC2401].  However, for a number of
108    reasons detailed in [WHYIPSEC], this is only suitable for some
109    applications.  Second, they can design a custom application layer
110    security protocol.  SIP, for instance, uses a subset of S/MIME to
114 Rescorla & Modadugu         Standards Track                     [Page 2]
116 RFC 4347           Datagram Transport Layer Security          April 2006
119    secure its traffic.  Unfortunately, although application layer
120    security protocols generally provide superior security properties
121    (e.g., end-to-end security in the case of S/MIME), they typically
122    requires a large amount of effort to design -- in contrast to the
123    relatively small amount of effort required to run the protocol over
124    TLS.
126    In many cases, the most desirable way to secure client/server
127    applications would be to use TLS; however, the requirement for
128    datagram semantics automatically prohibits use of TLS.  Thus, a
129    datagram-compatible variant of TLS would be very desirable.  This
130    memo describes such a protocol: Datagram Transport Layer Security
131    (DTLS).  DTLS is deliberately designed to be as similar to TLS as
132    possible, both to minimize new security invention and to maximize the
133    amount of code and infrastructure reuse.
135 1.1. Requirements Terminology
137    In this document, the keywords "MUST", "MUST NOT", "REQUIRED",
138    "SHOULD", "SHOULD NOT", and "MAY" are to be interpreted as described
139    in RFC 2119 [REQ].
141 2. Usage Model
143    The DTLS protocol is designed to secure data between communicating
144    applications.  It is designed to run in application space, without
145    requiring any kernel modifications.
147    Datagram transport does not require or provide reliable or in-order
148    delivery of data.  The DTLS protocol preserves this property for
149    payload data.  Applications such as media streaming, Internet
150    telephony, and online gaming use datagram transport for communication
151    due to the delay-sensitive nature of transported data.  The behavior
152    of such applications is unchanged when the DTLS protocol is used to
153    secure communication, since the DTLS protocol does not compensate for
154    lost or re-ordered data traffic.
170 Rescorla & Modadugu         Standards Track                     [Page 3]
172 RFC 4347           Datagram Transport Layer Security          April 2006
175 3. Overview of DTLS
177    The basic design philosophy of DTLS is to construct "TLS over
178    datagram".  The reason that TLS cannot be used directly in datagram
179    environments is simply that packets may be lost or reordered.  TLS
180    has no internal facilities to handle this kind of unreliability, and
181    therefore TLS implementations break when rehosted on datagram
182    transport.  The purpose of DTLS is to make only the minimal changes
183    to TLS required to fix this problem.  To the greatest extent
184    possible, DTLS is identical to TLS.  Whenever we need to invent new
185    mechanisms, we attempt to do so in such a way that preserves the
186    style of TLS.
188    Unreliability creates problems for TLS at two levels:
190       1. TLS's traffic encryption layer does not allow independent
191       decryption of individual records.  If record N is not received,
192       then record N+1 cannot be decrypted.
194       2. The TLS handshake layer assumes that handshake messages are
195       delivered reliably and breaks if those messages are lost.
197    The rest of this section describes the approach that DTLS uses to
198    solve these problems.
200 3.1. Loss-Insensitive Messaging
202    In TLS's traffic encryption layer (called the TLS Record Layer),
203    records are not independent.  There are two kinds of inter-record
204    dependency:
206       1. Cryptographic context (CBC state, stream cipher key stream) is
207       chained between records.
209       2. Anti-replay and message reordering protection are provided by a
210       MAC that includes a sequence number, but the sequence numbers are
211       implicit in the records.
213    The fix for both of these problems is straightforward and well known
214    from IPsec ESP [ESP]: add explicit state to the records.  TLS 1.1
215    [TLS11] is already adding explicit CBC state to TLS records.  DTLS
216    borrows that mechanism and adds explicit sequence numbers.
218 3.2. Providing Reliability for Handshake
220    The TLS handshake is a lockstep cryptographic handshake.  Messages
221    must be transmitted and received in a defined order, and any other
222    order is an error.  Clearly, this is incompatible with reordering and
226 Rescorla & Modadugu         Standards Track                     [Page 4]
228 RFC 4347           Datagram Transport Layer Security          April 2006
231    message loss.  In addition, TLS handshake messages are potentially
232    larger than any given datagram, thus creating the problem of
233    fragmentation.  DTLS must provide fixes for both of these problems.
235 3.2.1. Packet Loss
237    DTLS uses a simple retransmission timer to handle packet loss.  The
238    following figure demonstrates the basic concept, using the first
239    phase of the DTLS handshake:
241       Client                                   Server
242       ------                                   ------
243       ClientHello           ------>
245                               X<-- HelloVerifyRequest
246                                                (lost)
248       [Timer Expires]
250       ClientHello           ------>
251       (retransmit)
253    Once the client has transmitted the ClientHello message, it expects
254    to see a HelloVerifyRequest from the server.  However, if the
255    server's message is lost the client knows that either the ClientHello
256    or the HelloVerifyRequest has been lost and retransmits.  When the
257    server receives the retransmission, it knows to retransmit.  The
258    server also maintains a retransmission timer and retransmits when
259    that timer expires.
261    Note: timeout and retransmission do not apply to the
262    HelloVerifyRequest, because this requires creating state on the
263    server.
265 3.2.2. Reordering
267    In DTLS, each handshake message is assigned a specific sequence
268    number within that handshake.  When a peer receives a handshake
269    message, it can quickly determine whether that message is the next
270    message it expects.  If it is, then it processes it.  If not, it
271    queues it up for future handling once all previous messages have been
272    received.
274 3.2.3. Message Size
276    TLS and DTLS handshake messages can be quite large (in theory up to
277    2^24-1 bytes, in practice many kilobytes).  By contrast, UDP
278    datagrams are often limited to <1500 bytes if fragmentation is not
282 Rescorla & Modadugu         Standards Track                     [Page 5]
284 RFC 4347           Datagram Transport Layer Security          April 2006
287    desired.  In order to compensate for this limitation, each DTLS
288    handshake message may be fragmented over several DTLS records.  Each
289    DTLS handshake message contains both a fragment offset and a fragment
290    length.  Thus, a recipient in possession of all bytes of a handshake
291    message can reassemble the original unfragmented message.
293 3.3. Replay Detection
295    DTLS optionally supports record replay detection.  The technique used
296    is the same as in IPsec AH/ESP, by maintaining a bitmap window of
297    received records.  Records that are too old to fit in the window and
298    records that have previously been received are silently discarded.
299    The replay detection feature is optional, since packet duplication is
300    not always malicious, but can also occur due to routing errors.
301    Applications may conceivably detect duplicate packets and accordingly
302    modify their data transmission strategy.
304 4. Differences from TLS
306    As mentioned in Section 3, DTLS is intentionally very similar to TLS.
307    Therefore, instead of presenting DTLS as a new protocol, we present
308    it as a series of deltas from TLS 1.1 [TLS11].  Where we do not
309    explicitly call out differences, DTLS is the same as in [TLS11].
311 4.1. Record Layer
313    The DTLS record layer is extremely similar to that of TLS 1.1.  The
314    only change is the inclusion of an explicit sequence number in the
315    record.  This sequence number allows the recipient to correctly
316    verify the TLS MAC.  The DTLS record format is shown below:
318        struct {
319          ContentType type;
320          ProtocolVersion version;
321          uint16 epoch;                                    // New field
322          uint48 sequence_number;                          // New field
323          uint16 length;
324          opaque fragment[DTLSPlaintext.length];
325        } DTLSPlaintext;
327       type
328        Equivalent to the type field in a TLS 1.1 record.
330       version
331        The version of the protocol being employed.  This document
332        describes DTLS Version 1.0, which uses the version { 254, 255
333        }.  The version value of 254.255 is the 1's complement of DTLS
334        Version 1.0. This maximal spacing between TLS and DTLS version
338 Rescorla & Modadugu         Standards Track                     [Page 6]
340 RFC 4347           Datagram Transport Layer Security          April 2006
343        numbers ensures that records from the two protocols can be
344        easily distinguished.  It should be noted that future on-the-wire
345        version numbers of DTLS are decreasing in value (while the true
346        version number is increasing in value.)
348       epoch
349        A counter value that is incremented on every cipher state
350        change.
352       sequence_number
353        The sequence number for this record.
355       length
356        Identical to the length field in a TLS 1.1 record.  As in TLS
357        1.1, the length should not exceed 2^14.
359       fragment
360        Identical to the fragment field of a TLS 1.1 record.
362    DTLS uses an explicit sequence number, rather than an implicit one,
363    carried in the sequence_number field of the record.  As with TLS, the
364    sequence number is set to zero after each ChangeCipherSpec message is
365    sent.
367    If several handshakes are performed in close succession, there might
368    be multiple records on the wire with the same sequence number but
369    from different cipher states.  The epoch field allows recipients to
370    distinguish such packets.  The epoch number is initially zero and is
371    incremented each time the ChangeCipherSpec messages is sent.  In
372    order to ensure that any given sequence/epoch pair is unique,
373    implementations MUST NOT allow the same epoch value to be reused
374    within two times the TCP maximum segment lifetime.  In practice, TLS
375    implementations rarely rehandshake and we therefore do not expect
376    this to be a problem.
378 4.1.1. Transport Layer Mapping
380    Each DTLS record MUST fit within a single datagram.  In order to
381    avoid IP fragmentation [MOGUL], DTLS implementations SHOULD determine
382    the MTU and send records smaller than the MTU.  DTLS implementations
383    SHOULD provide a way for applications to determine the value of the
384    PMTU (or, alternately, the maximum application datagram size, which
385    is the PMTU minus the DTLS per-record overhead).  If the application
386    attempts to send a record larger than the MTU, the DTLS
387    implementation SHOULD generate an error, thus avoiding sending a
388    packet which will be fragmented.
394 Rescorla & Modadugu         Standards Track                     [Page 7]
396 RFC 4347           Datagram Transport Layer Security          April 2006
399    Note that unlike IPsec, DTLS records do not contain any association
400    identifiers.  Applications must arrange to multiplex between
401    associations.  With UDP, this is presumably done with host/port
402    number.
404    Multiple DTLS records may be placed in a single datagram.  They are
405    simply encoded consecutively.  The DTLS record framing is sufficient
406    to determine the boundaries.  Note, however, that the first byte of
407    the datagram payload must be the beginning of a record.  Records may
408    not span datagrams.
410    Some transports, such as DCCP [DCCP] provide their own sequence
411    numbers.  When carried over those transports, both the DTLS and the
412    transport sequence numbers will be present.  Although this introduces
413    a small amount of inefficiency, the transport layer and DTLS sequence
414    numbers serve different purposes, and therefore for conceptual
415    simplicity it is superior to use both sequence numbers.  In the
416    future, extensions to DTLS may be specified that allow the use of
417    only one set of sequence numbers for deployment in constrained
418    environments.
420    Some transports, such as DCCP, provide congestion control for traffic
421    carried over them.  If the congestion window is sufficiently narrow,
422    DTLS handshake retransmissions may be held rather than transmitted
423    immediately, potentially leading to timeouts and spurious
424    retransmission.  When DTLS is used over such transports, care should
425    be taken not to overrun the likely congestion window.  In the future,
426    a DTLS-DCCP mapping may be specified to provide optimal behavior for
427    this interaction.
429 4.1.1.1. PMTU Discovery
431    In general, DTLS's philosophy is to avoid dealing with PMTU issues.
432    The general strategy is to start with a conservative MTU and then
433    update it if events during the handshake or actual application data
434    transport phase require it.
436    The PMTU SHOULD be initialized from the interface MTU that will be
437    used to send packets.  If the DTLS implementation receives an RFC
438    1191 [RFC1191] ICMP Destination Unreachable message with the
439    "fragmentation needed and DF set" Code (otherwise known as Datagram
440    Too Big), it should decrease its PMTU estimate to that given in the
441    ICMP message.  A DTLS implementation SHOULD allow the application to
442    occasionally reset its PMTU estimate.  The DTLS implementation SHOULD
443    also allow applications to control the status of the DF bit.  These
444    controls allow the application to perform PMTU discovery.  RFC 1981
445    [RFC1981] procedures SHOULD be followed for IPv6.
450 Rescorla & Modadugu         Standards Track                     [Page 8]
452 RFC 4347           Datagram Transport Layer Security          April 2006
455    One special case is the DTLS handshake system.  Handshake messages
456    should be set with DF set.  Because some firewalls and routers screen
457    out ICMP messages, it is difficult for the handshake layer to
458    distinguish packet loss from an overlarge PMTU estimate.  In order to
459    allow connections under these circumstances, DTLS implementations
460    SHOULD back off handshake packet size during the retransmit backoff
461    described in Section 4.2.4. For instance, if a large packet is being
462    sent, after 3 retransmits the handshake layer might choose to
463    fragment the handshake message on retransmission.  In general, choice
464    of a conservative initial MTU will avoid this problem.
466 4.1.2. Record Payload Protection
468    Like TLS, DTLS transmits data as a series of protected records.  The
469    rest of this section describes the details of that format.
471 4.1.2.1. MAC
473    The DTLS MAC is the same as that of TLS 1.1. However, rather than
474    using TLS's implicit sequence number, the sequence number used to
475    compute the MAC is the 64-bit value formed by concatenating the epoch
476    and the sequence number in the order they appear on the wire.  Note
477    that the DTLS epoch + sequence number is the same length as the TLS
478    sequence number.
480    TLS MAC calculation is parameterized on the protocol version number,
481    which, in the case of DTLS, is the on-the-wire version, i.e., {254,
482    255 } for DTLS 1.0.
484    Note that one important difference between DTLS and TLS MAC handling
485    is that in TLS MAC errors must result in connection termination.  In
486    DTLS, the receiving implementation MAY simply discard the offending
487    record and continue with the connection.  This change is possible
488    because DTLS records are not dependent on each other in the way that
489    TLS records are.
491    In general, DTLS implementations SHOULD silently discard data with
492    bad MACs.  If a DTLS implementation chooses to generate an alert when
493    it receives a message with an invalid MAC, it MUST generate
494    bad_record_mac alert with level fatal and terminate its connection
495    state.
497 4.1.2.2. Null or Standard Stream Cipher
499    The DTLS NULL cipher is performed exactly as the TLS 1.1 NULL cipher.
501    The only stream cipher described in TLS 1.1 is RC4, which cannot be
502    randomly accessed.  RC4 MUST NOT be used with DTLS.
506 Rescorla & Modadugu         Standards Track                     [Page 9]
508 RFC 4347           Datagram Transport Layer Security          April 2006
511 4.1.2.3. Block Cipher
513    DTLS block cipher encryption and decryption are performed exactly as
514    with TLS 1.1.
516 4.1.2.4. New Cipher Suites
518    Upon registration, new TLS cipher suites MUST indicate whether they
519    are suitable for DTLS usage and what, if any, adaptations must be
520    made.
522 4.1.2.5. Anti-replay
524    DTLS records contain a sequence number to provide replay protection.
525    Sequence number verification SHOULD be performed using the following
526    sliding window procedure, borrowed from Section 3.4.3 of [RFC 2402].
528    The receiver packet counter for this session MUST be initialized to
529    zero when the session is established.  For each received record, the
530    receiver MUST verify that the record contains a Sequence Number that
531    does not duplicate the Sequence Number of any other record received
532    during the life of this session.  This SHOULD be the first check
533    applied to a packet after it has been matched to a session, to speed
534    rejection of duplicate records.
536    Duplicates are rejected through the use of a sliding receive window.
537    (How the window is implemented is a local matter, but the following
538    text describes the functionality that the implementation must
539    exhibit.)  A minimum window size of 32 MUST be supported, but a
540    window size of 64 is preferred and SHOULD be employed as the default.
541    Another window size (larger than the minimum) MAY be chosen by the
542    receiver.  (The receiver does not notify the sender of the window
543    size.)
545    The "right" edge of the window represents the highest validated
546    Sequence Number value received on this session.  Records that contain
547    Sequence Numbers lower than the "left" edge of the window are
548    rejected.  Packets falling within the window are checked against a
549    list of received packets within the window.  An efficient means for
550    performing this check, based on the use of a bit mask, is described
551    in Appendix C of [RFC 2401].
553    If the received record falls within the window and is new, or if the
554    packet is to the right of the window, then the receiver proceeds to
555    MAC verification.  If the MAC validation fails, the receiver MUST
556    discard the received record as invalid.  The receive window is
557    updated only if the MAC verification succeeds.
562 Rescorla & Modadugu         Standards Track                    [Page 10]
564 RFC 4347           Datagram Transport Layer Security          April 2006
567 4.2. The DTLS Handshake Protocol
569    DTLS uses all of the same handshake messages and flows as TLS, with
570    three principal changes:
572       1. A stateless cookie exchange has been added to prevent denial of
573       service attacks.
575       2. Modifications to the handshake header to handle message loss,
576       reordering, and fragmentation.
578       3. Retransmission timers to handle message loss.
580    With these exceptions, the DTLS message formats, flows, and logic are
581    the same as those of TLS 1.1.
583 4.2.1. Denial of Service Countermeasures
585    Datagram security protocols are extremely susceptible to a variety of
586    denial of service (DoS) attacks.  Two attacks are of particular
587    concern:
589       1. An attacker can consume excessive resources on the server by
590       transmitting a series of handshake initiation requests, causing
591       the server to allocate state and potentially to perform expensive
592       cryptographic operations.
594       2. An attacker can use the server as an amplifier by sending
595       connection initiation messages with a forged source of the victim.
596       The server then sends its next message (in DTLS, a Certificate
597       message, which can be quite large) to the victim machine, thus
598       flooding it.
600    In order to counter both of these attacks, DTLS borrows the stateless
601    cookie technique used by Photuris [PHOTURIS] and IKE [IKE].  When the
602    client sends its ClientHello message to the server, the server MAY
603    respond with a HelloVerifyRequest message.  This message contains a
604    stateless cookie generated using the technique of [PHOTURIS].  The
605    client MUST retransmit the ClientHello with the cookie added.  The
606    server then verifies the cookie and proceeds with the handshake only
607    if it is valid.  This mechanism forces the attacker/client to be able
608    to receive the cookie, which makes DoS attacks with spoofed IP
609    addresses difficult.  This mechanism does not provide any defense
610    against DoS attacks mounted from valid IP addresses.
618 Rescorla & Modadugu         Standards Track                    [Page 11]
620 RFC 4347           Datagram Transport Layer Security          April 2006
623    The exchange is shown below:
625          Client                                   Server
626          ------                                   ------
627          ClientHello           ------>
629                                <----- HelloVerifyRequest
630                                       (contains cookie)
632          ClientHello           ------>
633          (with cookie)
635          [Rest of handshake]
637    DTLS therefore modifies the ClientHello message to add the cookie
638    value.
640       struct {
641         ProtocolVersion client_version;
642         Random random;
643         SessionID session_id;
644         opaque cookie<0..32>;                             // New field
645         CipherSuite cipher_suites<2..2^16-1>;
646         CompressionMethod compression_methods<1..2^8-1>;
647       } ClientHello;
649    When sending the first ClientHello, the client does not have a cookie
650    yet; in this case, the Cookie field is left empty (zero length).
652    The definition of HelloVerifyRequest is as follows:
654       struct {
655         ProtocolVersion server_version;
656         opaque cookie<0..32>;
657       } HelloVerifyRequest;
659    The HelloVerifyRequest message type is hello_verify_request(3).
661    The server_version field is defined as in TLS.
663    When responding to a HelloVerifyRequest the client MUST use the same
664    parameter values (version, random, session_id, cipher_suites,
665    compression_method) as it did in the original ClientHello.  The
666    server SHOULD use those values to generate its cookie and verify that
667    they are correct upon cookie receipt.  The server MUST use the same
668    version number in the HelloVerifyRequest that it would use when
669    sending a ServerHello.  Upon receipt of the ServerHello, the client
670    MUST verify that the server version values match.
674 Rescorla & Modadugu         Standards Track                    [Page 12]
676 RFC 4347           Datagram Transport Layer Security          April 2006
679    The DTLS server SHOULD generate cookies in such a way that they can
680    be verified without retaining any per-client state on the server.
681    One technique is to have a randomly generated secret and generate
682    cookies as:  Cookie = HMAC(Secret, Client-IP, Client-Parameters)
684    When the second ClientHello is received, the server can verify that
685    the Cookie is valid and that the client can receive packets at the
686    given IP address.
688    One potential attack on this scheme is for the attacker to collect a
689    number of cookies from different addresses and then reuse them to
690    attack the server.  The server can defend against this attack by
691    changing the Secret value frequently, thus invalidating those
692    cookies.  If the server wishes that legitimate clients be able to
693    handshake through the transition (e.g., they received a cookie with
694    Secret 1 and then sent the second ClientHello after the server has
695    changed to Secret 2), the server can have a limited window during
696    which it accepts both secrets. [IKEv2] suggests adding a version
697    number to cookies to detect this case.  An alternative approach is
698    simply to try verifying with both secrets.
700    DTLS servers SHOULD perform a cookie exchange whenever a new
701    handshake is being performed.  If the server is being operated in an
702    environment where amplification is not a problem, the server MAY be
703    configured not to perform a cookie exchange.  The default SHOULD be
704    that the exchange is performed, however.  In addition, the server MAY
705    choose not to do a cookie exchange when a session is resumed.
706    Clients MUST be prepared to do a cookie exchange with every
707    handshake.
709    If HelloVerifyRequest is used, the initial ClientHello and
710    HelloVerifyRequest are not included in the calculation of the
711    verify_data for the Finished message.
713 4.2.2. Handshake Message Format
715    In order to support message loss, reordering, and fragmentation, DTLS
716    modifies the TLS 1.1 handshake header:
718       struct {
719         HandshakeType msg_type;
720         uint24 length;
721         uint16 message_seq;                               // New field
722         uint24 fragment_offset;                           // New field
723         uint24 fragment_length;                           // New field
724         select (HandshakeType) {
725           case hello_request: HelloRequest;
726           case client_hello:  ClientHello;
730 Rescorla & Modadugu         Standards Track                    [Page 13]
732 RFC 4347           Datagram Transport Layer Security          April 2006
735           case hello_verify_request: HelloVerifyRequest;  // New type
736           case server_hello:  ServerHello;
737           case certificate:Certificate;
738           case server_key_exchange: ServerKeyExchange;
739           case certificate_request: CertificateRequest;
740           case server_hello_done:ServerHelloDone;
741           case certificate_verify:  CertificateVerify;
742           case client_key_exchange: ClientKeyExchange;
743           case finished:Finished;
744         } body;
745       } Handshake;
747    The first message each side transmits in each handshake always has
748    message_seq = 0.  Whenever each new message is generated, the
749    message_seq value is incremented by one.  When a message is
750    retransmitted, the same message_seq value is used.  For example:
752       Client                             Server
753       ------                             ------
754       ClientHello (seq=0)  ------>
756                               X<-- HelloVerifyRequest (seq=0)
757                                               (lost)
759       [Timer Expires]
761       ClientHello (seq=0)  ------>
762       (retransmit)
764                            <------ HelloVerifyRequest (seq=0)
766       ClientHello (seq=1)  ------>
767       (with cookie)
769                            <------        ServerHello (seq=1)
770                            <------        Certificate (seq=2)
771                            <------    ServerHelloDone (seq=3)
773       [Rest of handshake]
775    Note, however, that from the perspective of the DTLS record layer,
776    the retransmission is a new record.  This record will have a new
777    DTLSPlaintext.sequence_number value.
779    DTLS implementations maintain (at least notionally) a
780    next_receive_seq counter.  This counter is initially set to zero.
781    When a message is received, if its sequence number matches
782    next_receive_seq, next_receive_seq is incremented and the message is
786 Rescorla & Modadugu         Standards Track                    [Page 14]
788 RFC 4347           Datagram Transport Layer Security          April 2006
791    processed.  If the sequence number is less than next_receive_seq, the
792    message MUST be discarded.  If the sequence number is greater than
793    next_receive_seq, the implementation SHOULD queue the message but MAY
794    discard it.  (This is a simple space/bandwidth tradeoff).
796 4.2.3. Message Fragmentation and Reassembly
798    As noted in Section 4.1.1, each DTLS message MUST fit within a single
799    transport layer datagram.  However, handshake messages are
800    potentially bigger than the maximum record size.  Therefore, DTLS
801    provides a mechanism for fragmenting a handshake message over a
802    number of records.
804    When transmitting the handshake message, the sender divides the
805    message into a series of N contiguous data ranges.  These ranges MUST
806    NOT be larger than the maximum handshake fragment size and MUST
807    jointly contain the entire handshake message.  The ranges SHOULD NOT
808    overlap.  The sender then creates N handshake messages, all with the
809    same message_seq value as the original handshake message.  Each new
810    message is labelled with the fragment_offset (the number of bytes
811    contained in previous fragments) and the fragment_length (the length
812    of this fragment).  The length field in all messages is the same as
813    the length field of the original message.  An unfragmented message is
814    a degenerate case with fragment_offset=0 and fragment_length=length.
816    When a DTLS implementation receives a handshake message fragment, it
817    MUST buffer it until it has the entire handshake message.  DTLS
818    implementations MUST be able to handle overlapping fragment ranges.
819    This allows senders to retransmit handshake messages with smaller
820    fragment sizes during path MTU discovery.
822    Note that as with TLS, multiple handshake messages may be placed in
823    the same DTLS record, provided that there is room and that they are
824    part of the same flight.  Thus, there are two acceptable ways to pack
825    two DTLS messages into the same datagram: in the same record or in
826    separate records.
828 4.2.4. Timeout and Retransmission
830    DTLS messages are grouped into a series of message flights, according
831    to the diagrams below.  Although each flight of messages may consist
832    of a number of messages, they should be viewed as monolithic for the
833    purpose of timeout and retransmission.
842 Rescorla & Modadugu         Standards Track                    [Page 15]
844 RFC 4347           Datagram Transport Layer Security          April 2006
847     Client                                          Server
848     ------                                          ------
850     ClientHello             -------->                           Flight 1
852                             <-------    HelloVerifyRequest      Flight 2
854    ClientHello              -------->                           Flight 3
856                                                ServerHello    \
857                                               Certificate*     \
858                                         ServerKeyExchange*      Flight 4
859                                        CertificateRequest*     /
860                             <--------      ServerHelloDone    /
862     Certificate*                                              \
863     ClientKeyExchange                                          \
864     CertificateVerify*                                          Flight 5
865     [ChangeCipherSpec]                                         /
866     Finished                -------->                         /
868                                         [ChangeCipherSpec]    \ Flight 6
869                             <--------             Finished    /
871           Figure 1. Message flights for full handshake
874     Client                                           Server
875     ------                                           ------
877     ClientHello             -------->                          Flight 1
879                                                ServerHello    \
880                                         [ChangeCipherSpec]     Flight 2
881                              <--------             Finished    /
883     [ChangeCipherSpec]                                         \Flight 3
884     Finished                 -------->                         /
886    Figure 2. Message flights for session-resuming handshake
887                            (no cookie exchange)
889    DTLS uses a simple timeout and retransmission scheme with the
890    following state machine.  Because DTLS clients send the first message
891    (ClientHello), they start in the PREPARING state.  DTLS servers start
892    in the WAITING state, but with empty buffers and no retransmit timer.
898 Rescorla & Modadugu         Standards Track                    [Page 16]
900 RFC 4347           Datagram Transport Layer Security          April 2006
903                    +-----------+
904                    | PREPARING |
905              +---> |           | <--------------------+
906              |     |           |                      |
907              |     +-----------+                      |
908              |           |                            |
909              |           |                            |
910              |           | Buffer next flight         |
911              |           |                            |
912              |          \|/                           |
913              |     +-----------+                      |
914              |     |           |                      |
915              |     |  SENDING  |<------------------+  |
916              |     |           |                   |  | Send
917              |     +-----------+                   |  | HelloRequest
918      Receive |           |                         |  |
919         next |           | Send flight             |  | or
920       flight |  +--------+                         |  |
921              |  |        | Set retransmit timer    |  | Receive
922              |  |       \|/                        |  | HelloRequest
923              |  |  +-----------+                   |  | Send
924              |  |  |           |                   |  | ClientHello
925              +--)--|  WAITING  |-------------------+  |
926              |  |  |           |   Timer expires   |  |
927              |  |  +-----------+                   |  |
928              |  |         |                        |  |
929              |  |         |                        |  |
930              |  |         +------------------------+  |
931              |  |                Read retransmit      |
932      Receive |  |                                     |
933         last |  |                                     |
934       flight |  |                                     |
935              |  |                                     |
936             \|/\|/                                    |
937                                                       |
938          +-----------+                                |
939          |           |                                |
940          | FINISHED  | -------------------------------+
941          |           |
942          +-----------+
944         Figure 3. DTLS timeout and retransmission state machine
946    The state machine has three basic states.
954 Rescorla & Modadugu         Standards Track                    [Page 17]
956 RFC 4347           Datagram Transport Layer Security          April 2006
959    In the PREPARING state the implementation does whatever computations
960    are necessary to prepare the next flight of messages.  It then
961    buffers them up for transmission (emptying the buffer first) and
962    enters the SENDING state.
964    In the SENDING state, the implementation transmits the buffered
965    flight of messages.  Once the messages have been sent, the
966    implementation then enters the FINISHED state if this is the last
967    flight in the handshake.  Or, if the implementation expects to
968    receive more messages, it sets a retransmit timer and then enters the
969    WAITING state.
971    There are three ways to exit the WAITING state:
973       1. The retransmit timer expires: the implementation transitions to
974       the SENDING state, where it retransmits the flight, resets the
975       retransmit timer, and returns to the WAITING state.
977       2. The implementation reads a retransmitted flight from the peer:
978       the implementation transitions to the SENDING state, where it
979       retransmits the flight, resets the retransmit timer, and returns
980       to the WAITING state.  The rationale here is that the receipt of a
981       duplicate message is the likely result of timer expiry on the peer
982       and therefore suggests that part of one's previous flight was
983       lost.
985       3. The implementation receives the next flight of messages:  if
986       this is the final flight of messages, the implementation
987       transitions to FINISHED.  If the implementation needs to send a
988       new flight, it transitions to the PREPARING state.  Partial reads
989       (whether partial messages or only some of the messages in the
990       flight) do not cause state transitions or timer resets.
992    Because DTLS clients send the first message (ClientHello), they start
993    in the PREPARING state.  DTLS servers start in the WAITING state, but
994    with empty buffers and no retransmit timer.
996    When the server desires a rehandshake, it transitions from the
997    FINISHED state to the PREPARING state to transmit the HelloRequest.
998    When the client receives a HelloRequest it transitions from FINISHED
999    to PREPARING to transmit the ClientHello.
1001 4.2.4.1. Timer Values
1003    Though timer values are the choice of the implementation, mishandling
1004    of the timer can lead to serious congestion problems; for example, if
1005    many instances of a DTLS time out early and retransmit too quickly on
1006    a congested link.  Implementations SHOULD use an initial timer value
1010 Rescorla & Modadugu         Standards Track                    [Page 18]
1012 RFC 4347           Datagram Transport Layer Security          April 2006
1015    of 1 second (the minimum defined in RFC 2988 [RFC2988]) and double
1016    the value at each retransmission, up to no less than the RFC 2988
1017    maximum of 60 seconds.  Note that we recommend a 1-second timer
1018    rather than the 3-second RFC 2988 default in order to improve latency
1019    for time-sensitive applications.  Because DTLS only uses
1020    retransmission for handshake and not dataflow, the effect on
1021    congestion should be minimal.
1023    Implementations SHOULD retain the current timer value until a
1024    transmission without loss occurs, at which time the value may be
1025    reset to the initial value.  After a long period of idleness, no less
1026    than 10 times the current timer value, implementations may reset the
1027    timer to the initial value.  One situation where this might occur is
1028    when a rehandshake is used after substantial data transfer.
1030 4.2.5. ChangeCipherSpec
1032    As with TLS, the ChangeCipherSpec message is not technically a
1033    handshake message but MUST be treated as part of the same flight as
1034    the associated Finished message for the purposes of timeout and
1035    retransmission.
1037 4.2.6. Finished Messages
1039    Finished messages have the same format as in TLS.  However, in order
1040    to remove sensitivity to fragmentation, the Finished MAC MUST be
1041    computed as if each handshake message had been sent as a single
1042    fragment.  Note that in cases where the cookie exchange is used, the
1043    initial ClientHello and HelloVerifyRequest MUST NOT be included in
1044    the Finished MAC.
1046 4.2.7. Alert Messages
1048    Note that Alert messages are not retransmitted at all, even when they
1049    occur in the context of a handshake.  However, a DTLS implementation
1050    SHOULD generate a new alert message if the offending record is
1051    received again (e.g., as a retransmitted handshake message).
1052    Implementations SHOULD detect when a peer is persistently sending bad
1053    messages and terminate the local connection state after such
1054    misbehavior is detected.
1056 4.3. Summary of new syntax
1058    This section includes specifications for the data structures that
1059    have changed between TLS 1.1 and DTLS.
1066 Rescorla & Modadugu         Standards Track                    [Page 19]
1068 RFC 4347           Datagram Transport Layer Security          April 2006
1071 4.3.1. Record Layer
1073       struct {
1074         ContentType type;
1075         ProtocolVersion version;
1076         uint16 epoch;                                     // New field
1077         uint48 sequence_number;                           // New field
1078         uint16 length;
1079         opaque fragment[DTLSPlaintext.length];
1080       } DTLSPlaintext;
1082       struct {
1083         ContentType type;
1084         ProtocolVersion version;
1085         uint16 epoch;                                     // New field
1086         uint48 sequence_number;                           // New field
1087         uint16 length;
1088         opaque fragment[DTLSCompressed.length];
1089       } DTLSCompressed;
1091       struct {
1092         ContentType type;
1093         ProtocolVersion version;
1094         uint16 epoch;                                     // New field
1095         uint48 sequence_number;                           // New field
1096         uint16 length;
1097         select (CipherSpec.cipher_type) {
1098           case block:  GenericBlockCipher;
1099         } fragment;
1100       } DTLSCiphertext;
1102 4.3.2. Handshake Protocol
1104       enum {
1105         hello_request(0), client_hello(1), server_hello(2),
1106         hello_verify_request(3),                          // New field
1107         certificate(11), server_key_exchange (12),
1108         certificate_request(13), server_hello_done(14),
1109         certificate_verify(15), client_key_exchange(16),
1110         finished(20), (255)
1111       } HandshakeType;
1113       struct {
1114         HandshakeType msg_type;
1115         uint24 length;
1116         uint16 message_seq;                               // New field
1117         uint24 fragment_offset;                           // New field
1118         uint24 fragment_length;                           // New field
1122 Rescorla & Modadugu         Standards Track                    [Page 20]
1124 RFC 4347           Datagram Transport Layer Security          April 2006
1127         select (HandshakeType) {
1128           case hello_request: HelloRequest;
1129           case client_hello:  ClientHello;
1130           case server_hello:  ServerHello;
1131           case hello_verify_request: HelloVerifyRequest;  // New field
1132           case certificate:Certificate;
1133           case server_key_exchange: ServerKeyExchange;
1134           case certificate_request: CertificateRequest;
1135           case server_hello_done:ServerHelloDone;
1136           case certificate_verify:  CertificateVerify;
1137           case client_key_exchange: ClientKeyExchange;
1138           case finished:Finished;
1139         } body;
1140       } Handshake;
1142       struct {
1143         ProtocolVersion client_version;
1144         Random random;
1145         SessionID session_id;
1146         opaque cookie<0..32>;                             // New field
1147         CipherSuite cipher_suites<2..2^16-1>;
1148         CompressionMethod compression_methods<1..2^8-1>;
1149       } ClientHello;
1151       struct {
1152         ProtocolVersion server_version;
1153         opaque cookie<0..32>;
1154       } HelloVerifyRequest;
1156 5. Security Considerations
1158    This document describes a variant of TLS 1.1 and therefore most of
1159    the security considerations are the same as those of TLS 1.1 [TLS11],
1160    described in Appendices D, E, and F.
1162    The primary additional security consideration raised by DTLS is that
1163    of denial of service.  DTLS includes a cookie exchange designed to
1164    protect against denial of service.  However, implementations which do
1165    not use this cookie exchange are still vulnerable to DoS.  In
1166    particular, DTLS servers which do not use the cookie exchange may be
1167    used as attack amplifiers even if they themselves are not
1168    experiencing DoS.  Therefore, DTLS servers SHOULD use the cookie
1169    exchange unless there is good reason to believe that amplification is
1170    not a threat in their environment.  Clients MUST be prepared to do a
1171    cookie exchange with every handshake.
1178 Rescorla & Modadugu         Standards Track                    [Page 21]
1180 RFC 4347           Datagram Transport Layer Security          April 2006
1183 6. Acknowledgements
1185    The authors would like to thank Dan Boneh, Eu-Jin Goh, Russ Housley,
1186    Constantine Sapuntzakis, and Hovav Shacham for discussions and
1187    comments on the design of DTLS.  Thanks to the anonymous NDSS
1188    reviewers of our original NDSS paper on DTLS [DTLS] for their
1189    comments.  Also, thanks to Steve Kent for feedback that helped
1190    clarify many points.  The section on PMTU was cribbed from the DCCP
1191    specification [DCCP].  Pasi Eronen provided a detailed review of this
1192    specification.  Helpful comments on the document were also received
1193    from Mark Allman, Jari Arkko, Joel Halpern, Ted Hardie, and Allison
1194    Mankin.
1196 7. IANA Considerations
1198    This document uses the same identifier space as TLS [TLS11], so no
1199    new IANA registries are required.  When new identifiers are assigned
1200    for TLS, authors MUST specify whether they are suitable for DTLS.
1202    This document defines a new handshake message, hello_verify_request,
1203    whose value has been allocated from the TLS HandshakeType registry
1204    defined in [TLS11].  The value "3" has been assigned by the IANA.
1206 8. References
1208 8.1. Normative References
1210    [RFC1191]  Mogul, J. and S. Deering, "Path MTU discovery", RFC 1191,
1211               November 1990.
1213    [RFC1981]  McCann, J., Deering, S., and J. Mogul, "Path MTU Discovery
1214               for IP version 6", RFC 1981, August 1996.
1216    [RFC2401]  Kent, S. and R. Atkinson, "Security Architecture for the
1217               Internet Protocol", RFC 2401, November 1998.
1219    [RFC2988]  Paxson, V. and M. Allman, "Computing TCP's Retransmission
1220               Timer", RFC 2988, November 2000.
1222    [TCP]      Postel, J., "Transmission Control Protocol", STD 7, RFC
1223               793, September 1981.
1225    [TLS11]    Dierks, T. and E. Rescorla, "The Transport Layer Security
1226               (TLS) Protocol Version 1.1", RFC 4346, April 2006.
1234 Rescorla & Modadugu         Standards Track                    [Page 22]
1236 RFC 4347           Datagram Transport Layer Security          April 2006
1239 8.2. Informative References
1241    [AESCACHE] Bernstein, D.J., "Cache-timing attacks on AES"
1242               http://cr.yp.to/antiforgery/cachetiming-20050414.pdf.
1244    [AH]       Kent, S. and R. Atkinson, "IP Authentication Header", RFC
1245               2402, November 1998.
1247    [DCCP]     Kohler, E., Handley, M., Floyd, S., Padhye, J., "Datagram
1248               Congestion Control Protocol", Work in Progress, 10 March
1249               2005.
1251    [DNS]      Mockapetris, P., "Domain names - implementation and
1252               specification", STD 13, RFC 1035, November 1987.
1254    [DTLS]     Modadugu, N., Rescorla, E., "The Design and Implementation
1255               of Datagram TLS", Proceedings of ISOC NDSS 2004, February
1256               2004.
1258    [ESP]      Kent, S. and R. Atkinson, "IP Encapsulating Security
1259               Payload (ESP)", RFC 2406, November 1998.
1261    [IKE]      Harkins, D. and D. Carrel, "The Internet Key Exchange
1262               (IKE)", RFC 2409, November 1998.
1264    Kaufman, C., "Internet Key Exchange (IKEv2) Protocol", RFC 4306,
1265               December 2005.
1267    [IMAP]     Crispin, M., "INTERNET MESSAGE ACCESS PROTOCOL - VERSION
1268               4rev1", RFC 3501, March 2003.
1270    [PHOTURIS] Karn, P. and W. Simpson, "ICMP Security Failures
1271               Messages", RFC 2521, March 1999.
1273    [POP]      Myers, J. and M. Rose, "Post Office Protocol - Version 3",
1274               STD 53, RFC 1939, May 1996.
1276    [REQ]      Bradner, S., "Key words for use in RFCs to Indicate
1277               Requirement Levels", BCP 14, RFC 2119, March 1997.
1279    [SCTP]     Stewart, R., Xie, Q., Morneault, K., Sharp, C.,
1280               Schwarzbauer, H., Taylor, T., Rytina, I., Kalla, M.,
1281               Zhang, L., and V. Paxson, "Stream Control Transmission
1282               Protocol", RFC 2960, October 2000.
1290 Rescorla & Modadugu         Standards Track                    [Page 23]
1292 RFC 4347           Datagram Transport Layer Security          April 2006
1295    [SIP]      Rosenberg, J., Schulzrinne, H., Camarillo, G., Johnston,
1296               A., Peterson, J., Sparks, R., Handley, M., and E.
1297               Schooler, "SIP:  Session Initiation Protocol", RFC 3261,
1298               June 2002.
1300    [TLS]      Dierks, T. and C. Allen, "The TLS Protocol Version 1.0",
1301               RFC 2246, January 1999.
1303    [WHYIPSEC] Bellovin, S., "Guidelines for Mandating the Use of IPsec",
1304               Work in Progress, October 2003.
1306 Authors' Addresses
1308    Eric Rescorla
1309    RTFM, Inc.
1310    2064 Edgewood Drive
1311    Palo Alto, CA 94303
1313    EMail: ekr@rtfm.com
1316    Nagendra Modadugu
1317    Computer Science Department
1318    Stanford University
1319    353 Serra Mall
1320    Stanford, CA 94305
1322    EMail: nagendra@cs.stanford.edu
1346 Rescorla & Modadugu         Standards Track                    [Page 24]
1348 RFC 4347           Datagram Transport Layer Security          April 2006
1351 Full Copyright Statement
1353    Copyright (C) The Internet Society (2006).
1355    This document is subject to the rights, licenses and restrictions
1356    contained in BCP 78, and except as set forth therein, the authors
1357    retain all their rights.
1359    This document and the information contained herein are provided on an
1360    "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS
1361    OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY AND THE INTERNET
1362    ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED,
1363    INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE
1364    INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED
1365    WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
1367 Intellectual Property
1369    The IETF takes no position regarding the validity or scope of any
1370    Intellectual Property Rights or other rights that might be claimed to
1371    pertain to the implementation or use of the technology described in
1372    this document or the extent to which any license under such rights
1373    might or might not be available; nor does it represent that it has
1374    made any independent effort to identify any such rights.  Information
1375    on the procedures with respect to rights in RFC documents can be
1376    found in BCP 78 and BCP 79.
1378    Copies of IPR disclosures made to the IETF Secretariat and any
1379    assurances of licenses to be made available, or the result of an
1380    attempt made to obtain a general license or permission for the use of
1381    such proprietary rights by implementers or users of this
1382    specification can be obtained from the IETF on-line IPR repository at
1383    http://www.ietf.org/ipr.
1385    The IETF invites any interested party to bring to its attention any
1386    copyrights, patents or patent applications, or other proprietary
1387    rights that may cover technology that may be required to implement
1388    this standard.  Please address the information to the IETF at
1389    ietf-ipr@ietf.org.
1391 Acknowledgement
1393    Funding for the RFC Editor function is provided by the IETF
1394    Administrative Support Activity (IASA).
1402 Rescorla & Modadugu         Standards Track                    [Page 25]