corrected copyright notices
[gnutls.git] / doc / protocol / draft-rescorla-dtls-05.txt
blobba75c2ad99f3adb478bd8ef96fdc116b923bd0aa
2                                                              E. Rescorla
3                                                               RTFM, Inc.
4                                                              N. Modadugu
5 INTERNET-DRAFT                                       Stanford University
6 <draft-rescorla-dtls-05.txt>           June 2004 (Expires December 2005)
8                    Datagram Transport Layer Security
10 Status of this Memo
12 By submitting this Internet-Draft, each author represents that any
13 applicable patent or other IPR claims of which he or she is aware
14 have been or will be disclosed, and any of which he or she becomes
15 aware will be disclosed, in accordance with Section 6 of BCP 79.
17 Internet-Drafts are working documents of the Internet Engineering
18 Task Force (IETF), its areas, and its working groups. Note that
19 other groups may also distribute working documents as
20 Internet-Drafts.
22 Internet-Drafts are draft documents valid for a maximum of six months
23 and may be updated, replaced, or obsoleted by other documents at any
24 time. It is inappropriate to use Internet-Drafts as reference
25 material or to cite them other than as "work in progress."
27 The list of current Internet-Drafts can be accessed at
28 http://www.ietf.org/1id-abstracts.html
30 The list of Internet-Draft Shadow Directories can be accessed at
31 http://www.ietf.org/shadow.html
33 Copyright Notice
35    Copyright (C) The Internet Society (2005). All Rights Reserved.
42 Rescorla, Modadugu                                               [Page 1]\f
45 Abstract
47    This document specifies Version 1.0 of the Datagram Transport
48    Layer Security (DTLS) protocol. The DTLS protocol provides
49    communications privacy for datagram protocols. The protocol
50    allows client/server applications to communicate in a way that
51    is designed to prevent eavesdropping, tampering, or message
52    forgery. The DTLS protocol is based on the TLS protocol and
53    provides equivalent security guarantees. Datagram semantics of
54    the underlying transport are preserved by the DTLS protocol.
57 Contents
59    1           Introduction                                          3
60      1.1         Requirements Terminology                            3
61    2           Usage Model                                           4
62    3           Overview of DTLS                                      4
63      3.1         Loss-insensitive messaging                          4
64      3.2         Providing Reliability for Handshake                 5
65        3.2.1       Packet Loss                                       5
66        3.2.2       Reordering                                        6
67        3.2.3       Message Size                                      6
68      3.3         Replay Detection                                    6
69    4           Differences from TLS                                  6
70      4.1         Record Layer                                        7
71        4.1.1       Transport Layer Mapping                           8
72          4.1.1.1     PMTU Discovery                                  9
73        4.1.2       Record payload protection                         9
74          4.1.2.1     MAC                                            10
75          4.1.2.2     Null or standard stream cipher                 10
76          4.1.2.3     Block Cipher                                   10
77          4.1.2.4     New Cipher Suites                              10
78          4.1.2.5     Anti-Replay                                    10
79      4.2         The DTLS Handshake Protocol                        11
80        4.2.1       Denial of Service Countermeasures                12
81        4.2.2       Handshake Message Format                         14
82        4.2.3       Message Fragmentation and Reassembly             16
83        4.2.4       Timeout and Retransmission                       16
84          4.2.4.1     Timer Values                                   19
85        4.2.5       ChangeCipherSpec                                 20
86        4.2.6       Finished messages                                20
87        4.2.7       Alert Messages                                   20
88      4.2         Record Layer                                       21
89      4.3         Handshake Protocol                                 21
90    5           Security Considerations                              22
91    6           IANA Considerations                                  23
96 Rescorla, Modadugu                                               [Page 2]\f
99 1. Introduction
101    TLS [TLS] is the most widely deployed protocol for securing
102    network traffic. It is widely used for protecting Web traffic
103    and for e-mail protocols such as IMAP [IMAP] and POP [POP].
104    The primary advantage of TLS is that it provides a transparent
105    connection-oriented channel. Thus, it is easy to secure an
106    application protocol by inserting TLS between the application
107    layer and the transport layer. However, TLS must run over a
108    reliable transport channel--typically TCP [TCP]. It therefore
109    cannot be used to secure unreliable datagram traffic.
111    However, over the past few years an increasing number of
112    application layer protocols have been designed which use UDP
113    transport. In particular such protocols as the Session
114    Initiation Protocol (SIP) [SIP], and electronic gaming
115    protocols are increasingly popular. (Note that SIP can run
116    over both TCP and UDP, but that there are situations in which
117    UDP is preferable). Currently, designers of these applications
118    are faced with a number of unsatisfactory choices. First, they
119    can use IPsec [RFC2401]. However, for a number of reasons
120    detailed in [WHYIPSEC], this is only suitable for some
121    applications. Second, they can design a custom application
122    layer security protocol. SIP, for instance, uses a subset of
123    S/MIME to secure its traffic. Unfortunately, while application
124    layer security protocols generally provide superior security
125    properties (e.g., end-to-end security in the case of S/MIME)
126    it typically requires a large amount of effort to design--by
127    contrast to the relatively small amount of effort required to
128    run the protocol over TLS.
130    In many cases, the most desirable way to secure client/server
131    applications would be to use TLS; however the requirement for
132    datagram semantics automatically prohibits use of TLS. Thus, a
133    datagram-compatible variant of TLS would be very desirable.
134    This memo describes such a protocol: Datagram Transport Layer
135    Security (DTLS). DTLS is deliberately designed to be as
136    similar to to TLS as possible, both to minimize new security
137    invention and to maximize the amount of code and
138    infrastructure reuse.
141 1.1. Requirements Terminology
143    Keywords "MUST", "MUST NOT", "REQUIRED", "SHOULD", "SHOULD
144    NOT" and "MAY" that appear in this document are to be
145    interpreted as described in RFC 2119 [REQ].
150 Rescorla, Modadugu                                               [Page 3]\f
153 2. Usage Model
155    The DTLS protocol is designed to secure data between
156    communicating applications. It is designed to run in
157    application space, without requiring any kernel modifications.
159    Datagram transport does not require or provide reliable or in-
160    order delivery of data. The DTLS protocol preserves this
161    property for payload data. Applications such as media
162    streaming, Internet telephony and online gaming use datagram
163    transport for communication due to the delay-sensitive nature
164    of transported data. The behavior of such applications is
165    unchanged when the DTLS protocol is used to secure
166    communication, since the DTLS protocol does not compensate for
167    lost or re-ordered data traffic.
169 3. Overview of DTLS
171    The basic design philosophy of DTLS is to construct "TLS over
172    datagram". The reason that TLS cannot be used directly in
173    datagram environments is simply that packets may be lost or
174    reordered. TLS has no internal facilities to handle this kind
175    of unreliability and therefore TLS implementations break when
176    rehosted on datagram transport. The purpose of DTLS is to make
177    only the minimal changes to TLS required to fix this problem.
178    To the greatest extent possible, DTLS is identical to TLS.
179    Whenever we need to invent new mechanisms, we attempt to do so
180    in such a way that it preserves the style of TLS.
182    Unreliability creates problems for TLS at two levels:
184       1. TLS's traffic encryption layer does not allow
185       independent decryption of individual records. If record N
186       is not received, then record N+1 cannot be decrypted.
188       2. The TLS handshake layer assumes that handshake messages
189       are delivered reliably and breaks if those messages are
190       lost.
192    The rest of this section describes the approach that DTLS uses
193    to solve these problems.
195 3.1. Loss-insensitive messaging
197    In TLS's traffic encryption layer (called the TLS Record
198    Layer), records are not independent. There are two kinds of
199    inter-record dependency:
204 Rescorla, Modadugu                                               [Page 4]\f
207       1. Cryptographic context (CBC state, stream cipher key
208       stream) is chained between records.
210       2. Anti-replay and message reordering protection are
211       provided by a MAC which includes a sequence number, but the
212       sequence numbers are implicit in the records.
214    The fix for both of these problems is straightforward and
215    well-known from IPsec ESP [ESP]: add explicit state to the
216    records. TLS 1.1 [TLS11] is already adding explicit CBC state
217    to TLS records. DTLS borrows that mechanism and adds explicit
218    sequence numbers.
220 3.2. Providing Reliability for Handshake
222    The TLS handshake is a lockstep cryptographic handshake.
223    Messages must be transmitted and received in a defined order
224    and any other order is an error. Clearly, this is incompatible
225    with reordering and message loss. In addition, TLS handshake
226    messages are potentially larger than any given datagram, thus
227    creating the problem of fragmentation. DTLS must provide fixes
228    for both these problems.
230 3.2.1. Packet Loss
232    DTLS uses a simple retransmission timer to handle packet loss.
233    The following figure demonstrates the basic concept using the
234    first phase of the DTLS handshake:
236       Client                                   Server
237       ------                                   ------
238       ClientHello           ------>
240                               X<-- HelloVerifyRequest
241                                                (lost)
243       [Timer Expires]
245       ClientHello           ------>
246       (retransmit)
248    Once the client has transmitted the ClientHello message, it
249    expects to see a HelloVerifyRequest from the server. However,
250    if the server's message is lost the client knows that either
251    the ClientHello or the HelloVerifyRequest has been lost and
252    retransmits. When the server receives the retransmission, it
253    knows to retransmit. The server also maintains a
254    retransmission timer and retransmits when that timer expires.
258 Rescorla, Modadugu                                               [Page 5]\f
261    Note: timeout and retransmission do not apply to the
262    HelloVerifyRequest, because this requires creating state on
263    the server.
265 3.2.2. Reordering
267    In DTLS, each handshake message is assigned a specific
268    sequence number within that handshake. When a peer receives a
269    handshake message, it can quickly determine whether that
270    message is the next message it expects. If it is, then it
271    processes it. If not, it queues it up for future handling once
272    all previous messages have been received.
274 3.2.3. Message Size
276    TLS and DTLS handshake messages can be quite large (in theory
277    up to 2^24-1 bytes, in practice many kilobytes). By contrast,
278    UDP datagrams are often limited to <1500 bytes if
279    fragmentation is not desired. In order to compensate for this
280    limitation, each DTLS handshake message may be fragmented over
281    several DTLS records. Each DTLS handshake message contains
282    both a fragment offset and a fragment length. Thus, a
283    recipient in possession of all bytes of a handshake message
284    can reassemble the original unfragmented message.
286 3.3. Replay Detection
288    DTLS optionally supports record replay detection. The
289    technique used is the same as in IPsec AH/ESP, by maintaining
290    a bitmap window of received records. Records that are too old
291    to fit in the window and records that have been previously
292    received are silently discarded. The replay detection feature
293    is optional, since packet duplication is not always malicious,
294    but can also occur due to routing errors. Applications may
295    conceivably detect duplicate packets and accordingly modify
296    their data transmission strategy.
298 4. Differences from TLS
300    As mentioned in Section 3., DTLS is intentionally very similar
301    to TLS. Therefore, instead of presenting DTLS as a new
302    protocol, we instead present it as a series of deltas from TLS
303    1.1 [TLS11]. Where we do not explicitly call out differences,
304    DTLS is the same as in [TLS11].
312 Rescorla, Modadugu                                               [Page 6]\f
315 4.1. Record Layer
317    The DTLS record layer is extremely similar to that of TLS 1.1.
318    The only change is the inclusion of an explicit sequence
319    number in the record. This sequence number allows the
320    recipient to correctly verify the TLS MAC. The DTLS record
321    format is shown below:
323        struct {
324         ContentType type;
325         ProtocolVersion version;
326         uint16 epoch;               // New field
327         uint48 sequence_number;       // New field
328         uint16 length;
329         opaque fragment[DTLSPlaintext.length];
330        } DTLSPlaintext;
332       type
333        Equivalent to the type field in a TLS 1.1 record.
335       version
336        The version of the protocol being employed. This document
337        describes DTLS Version 1.0, which uses the version { 254, 255
338        }. The version value of 254.255 is the 1's complement of DTLS
339        Version 1.0. This maximal spacing between TLS and DTLS version
340        numbers ensures that records from the two protocols can be
341        easily distinguished.
343       epoch
344        A counter value that is incremented on every cipher state
345        change.
347       sequence_number
348        The sequence number for this record.
350       length
351        Identical to the length field in a TLS 1.1 record. As in TLS
352        1.1, the length should not exceed 2^14.
354       fragment
355        Identical to the fragment field of a TLS 1.1 record.
357    DTLS uses an explicit rather than implicit sequence number,
358    carried in the sequence_number field of the record. As with
359    TLS, the sequence number is set to zero after each
360    ChangeCipherSpec message is sent.
366 Rescorla, Modadugu                                               [Page 7]\f
369    If several handshakes are performed in close succession, there
370    might be multiple records on the wire with the same sequence
371    number but from different cipher states. The epoch field
372    allows recipients to distinguish such packets. The epoch
373    number is initially zero and is incremented each time the
374    ChangeCipherSpec messages is sent. In order to ensure that any
375    given sequence/epoch pair is unique, implementations MUST NOT
376    allow the same epoch value to be reused within two times the
377    TCP maximum segment lifetime. In practice, TLS implementations
378    rehandshake rarely and we therefore do not expect this to be a
379    problem.
381 4.1.1. Transport Layer Mapping
383    Each DTLS record MUST fit within a single datagram. In order
384    to avoid IP fragmentation [MOGUL], DTLS implementations SHOULD
385    determine the MTU and send records smaller than the MTU. DTLS
386    implementations SHOULD provide a way for applications to
387    determine the value of the PMTU (or alternately the maximum
388    application datagram size, which is the PMTU minus the DTLS
389    per-record overhead). If the application attempts to send a
390    record larger than the MTU the DTLS implementation SHOULD
391    generate an error, thus avoiding sending a packet which will
392    be fragmented.
394    Note that unlike IPsec, DTLS records do not contain any
395    association identifiers. Applications must arrange to
396    multiplex between associations. With UDP, this is presumably
397    done with host/port number.
399    Multiple DTLS records may be placed in a single datagram. They
400    are simply encoded consecutively. The DTLS record framing is
401    sufficient to determine the boundaries. Note, however, that
402    the first byte of the datagram payload must be the beginning
403    of a record. Records may not span datagrams.
405    Some transports, such as DCCP [DCCP] provide their own
406    sequence numbers. When carried over those transports, both the
407    DTLS and the transport sequence numbers will be present.
408    Although this introduces a small amount of inefficiency, the
409    transport layer and DTLS sequence numbers serve different
410    purposes and therefore for conceptual simplicity it is
411    superior to use both sequence numbers. In the future,
412    extensions to DTLS may be specified that allow the use of only
413    one set of sequence numbers for deployment in constrained
414    environments.
415      Some transports, such as DCCP, provide congestion control
416    for traffic carried over them. If the congestion window is
420 Rescorla, Modadugu                                               [Page 8]\f
423    sufficiently narrow, DTLS handshake retransmissions may be
424    held rather than transmitted immediately, potentially leading
425    to timeouts and spurious retransmission. When DTLS is used
426    over such transports, care should be taken not to overrun the
427    likely congestion window. In the future, a DTLS-DCCP mapping
428    may be specificied to provide optimal behavior for this
429    interaction.
431 4.1.1.1. PMTU Discovery
433    In general, DTLS's philosophy is to avoid dealing with PMTU
434    issues. The general strategy is to start with a conservative
435    MTU and then update it if events during the handshake or
436    actual application data transport phase require it.
438    The PMTU SHOULD be initialized from the interface MTU that
439    will be used to send packets. If the DTLS implementation
440    receives an RFC 1191 [RFC1191] ICMP Destination Unreachable
441    message with the "fragmentation needed and DF set" Code
442    (otherwise known as Datagram Too Big) it should decrease its
443    PMTU estimate to that given in the ICMP message. A DTLS
444    implementation SHOULD allow the application to occasionally
445    reset its PMTU estimate. The DTLS implementation SHOULD also
446    allow applications to control the status of the DF bit. These
447    controls allow the application to perform PMTU discovery. RFC
448    1981 [RFC1981] procedures SHOULD be followed for IPv6.
450    One special case is the DTLS handshake system. Handshake
451    messages should be set with DF set. Because some firewalls and
452    routers screen out ICMP messages, it is difficult for the
453    handshake layer to distinguish packet loss from an overlarge
454    PMTU estimate. In order to allow connections under these
455    circumstances, DTLS implementations SHOULD back off handshake
456    packet size during the retransmit backoff described in Section
457    4.2.4.. For instance, if a large packet is being sent, after 3
458    retransmits the handshake layer might choose to fragment the
459    handshake message on retransmission. In general, choice of a
460    conservative initial MTU will avoid this problem.
462 4.1.2. Record payload protection
464    Like TLS, DTLS transmits data as a series of protected
465    records. The rest of this section describes the details of
466    that format.
474 Rescorla, Modadugu                                               [Page 9]\f
477 4.1.2.1. MAC
479    The DTLS MAC is the same as that of TLS 1.1. However, rather
480    than using TLS's implicit sequence number, the sequence number
481    used to compute the MAC is the 64-bit value formed by
482    concatenating the epoch and the sequence number in the order
483    they appear on the wire. Note that the DTLS epoch + sequence
484    number is the same length as the TLS sequence number.
486    Note that one important difference between DTLS and TLS MAC
487    handling is that in TLS MAC errors must result in connection
488    termination. In DTLS, the receiving implementation MAY simply
489    discard the offending record and continue with the connection.
490    This change is possible because DTLS records are not dependent
491    on each other the way that TLS records are.
492      In general, DTLS implementations SHOULD silently discard
493    data with bad MACs. If a DTLS implementation chooses to
494    generate an alert when it receives a message with an invalid
495    MAC, it MUST generate bad_record_mac alert with level fatal
496    and terminate its connection state.
498 4.1.2.2. Null or standard stream cipher
500    The DTLS NULL cipher is performed exactly as the TLS 1.1 NULL
501    cipher.
503    The only stream cipher described in TLS 1.1 is RC4, which
504    cannot be randomly accessed. RC4 MUST NOT be used with DTLS.
506 4.1.2.3. Block Cipher
508    DTLS block cipher encryption and decryption are performed
509    exactly as with TLS 1.1.
511 4.1.2.4. New Cipher Suites
513    Upon registration, new TLS cipher suites MUST indicate whether
514    they are suitable for DTLS usage and what, if any, adaptations
515    must be made.
517 4.1.2.5. Anti-Replay
519    DTLS records contain a sequence number to provide replay
520    protection. Sequence number verification SHOULD be performed
521    using the following sliding window procedure, borrowed from
522    Section 3.4.3 of [RFC 2402].
528 Rescorla, Modadugu                                              [Page 10]\f
531    The receiver packet counter for this session MUST be
532    initialized to zero when the session is established. For each
533    received record, the receiver MUST verify that the record
534    contains a Sequence Number that does not duplicate the
535    Sequence Number of any other record received during the life
536    of this session. This SHOULD be the first check applied to a
537    packet after it has been matched to a session, to speed
538    rejection of duplicate records.
540    Duplicates are rejected through the use of a sliding receive
541    window. (How the window is implemented is a local matter, but
542    the following text describes the functionality that the
543    implementation must exhibit.) A minimum window size of 32 MUST
544    be supported; but a window size of 64 is preferred and SHOULD
545    be employed as the default. Another window size (larger than
546    the minimum) MAY be chosen by the receiver. (The receiver does
547    not notify the sender of the window size.)
549    The "right" edge of the window represents the highest,
550    validated Sequence Number value received on this session.
551    Records that contain Sequence Numbers lower than the "left"
552    edge of the window are rejected. Packets falling within the
553    window are checked against a list of received packets within
554    the window. An efficient means for performing this check,
555    based on the use of a bit mask, is described in Appendix C of
556    [RFC 2401].
558    If the received record falls within the window and is new, or
559    if the packet is to the right of the window, then the receiver
560    proceeds to MAC verification. If the MAC validation fails, the
561    receiver MUST discard the received record as invalid. The
562    receive window is updated only if the MAC verification
563    succeeds.
565 4.2. The DTLS Handshake Protocol
567    DTLS uses all of the same handshake messages and flows as TLS,
568    with three principal changes:
570       1. A stateless cookie exchange has been added to prevent
571       denial of service attacks.
573       2. Modifications to the handshake header to handle message
574       loss, reordering and fragmentation.
576       3. Retransmission timers to handle message loss.
582 Rescorla, Modadugu                                              [Page 11]\f
585    With these exceptions, the DTLS message formats, flows, and
586    logic are the same as those of TLS 1.1.
588 4.2.1. Denial of Service Countermeasures
590    Datagram security protocols are extremely susceptible to a
591    variety of denial of service (DoS) attacks. Two attacks are of
592    particular concern:
594       1. An attacker can consume excessive resources on the
595       server by transmitting a series of handshake initiation
596       requests, causing the server to allocate state and
597       potentially perform expensive cryptographic operations.
599       2. An attacker can use the server as an amplifier by
600       sending connection initiation messages with a forged source
601       of the victim. The server then sends its next message (in
602       DTLS, a Certificate message, which can be quite large) to
603       the victim machine, thus flooding it.
605    In order to counter both of these attacks, DTLS borrows the
606    stateless cookie technique used by Photuris [PHOTURIS] and IKE
607    [IKE]. When the client sends its ClientHello message to the
608    server, the server MAY respond with a HelloVerifyRequest
609    message. This message contains a stateless cookie generated
610    using the technique of [PHOTURIS]. The client MUST retransmit
611    the ClientHello with the cookie added. The server then
612    verifies the cookie and proceeds with the handshake only if it
613    is valid. This mechanism forces the attacker/client to be able
614    to receive the cookie, which makes DoS attacks with spoofed IP
615    addresses difficult. This mechanism does not provide any
616    defense against DoS attacks mounted from valid IP addresses.
618    The exchange is shown below:
620          Client                                   Server
621          ------                                   ------
622          ClientHello           ------>
624                                <----- HelloVerifyRequest
625                                       (contains cookie)
627          ClientHello           ------>
628          (with cookie)
630          [Rest of handshake]
636 Rescorla, Modadugu                                              [Page 12]\f
639    DTLS therefore modifies the ClientHello message to add the
640    cookie value.
642       struct {
643         ProtocolVersion client_version;
644         Random random;
645         SessionID session_id;
646         opaque cookie<0..32>;                 // New field
647         CipherSuite cipher_suites<2..2^16-1>;
648         CompressionMethod compression_methods<1..2^8-1>;
649       } ClientHello;
651    When sending the first ClientHello, the client does not have a
652    cookie yet; in this case, the Cookie field is left empty (zero
653    length).
655    The definition of HelloVerifyRequest is as follows:
657       struct {
658         ProtocolVersion server_version;
659         opaque cookie<0..32>;
660       } HelloVerifyRequest;
662    The HelloVerifyRequest message type is
663    hello_verify_request(3).
665    The server_version field is defined as in TLS.
667    When responding to a HelloVerifyRequest the client MUST use
668    the same parameter values (version, random, session_id,
669    cipher_suites, compression_method) as in the original
670    ClientHello. The server SHOULD use those values to generate
671    its cookie and verify that they are correct upon cookie
672    receipt. The server MUST use the same version number in the
673    HelloVerifyRequest that it would use when sending a
674    ServerHello. Upon receipt of the ServerHello, the client MUST
675    verify that the server version values match.
677    The DTLS server SHOULD generate cookies in such a way that
678    they can be verified without retaining any per-client state on
679    the server. One technique is to have a randomly generated
680    secret and generate cookies as:
681    Cookie = HMAC(Secret, Client-IP, Client-Parameters)
683    When the second ClientHello is received, the server can verify
684    that the Cookie is valid and that the client can receive
685    packets at the given IP address.
686      One potential attack on this scheme is for the attacker to
690 Rescorla, Modadugu                                              [Page 13]\f
693    collect a number of cookies from different addresses and then
694    reuse them to attack the server. The server can defend against
695    this attack by changing the Secret value frequently, thus
696    invalidating those cookies. If the server wishes legitimate
697    clients to be able to handshake through the transition (e.g.,
698    they received a cookie with Secret 1 and then sent the second
699    ClientHello after the server has changed to Secret 2), the
700    server can have a limited window during which it accepts both
701    secrets. [IKEv2] suggests adding a version number to cookies
702    to detect this case. An alternative approach is simply to try
703    verifying with both secrets.
705    DTLS servers SHOULD perform a cookie exchange whenever a new
706    handshake is being performed. If the server is being operated
707    in an environment where amplification is not a problem, the
708    server MAY be configured to not to perform a cookie exchange.
709    The default SHOULD be that the exchange is performed, however.
710    In addition, the server MAY choose not do to a cookie exchange
711    when a session is resumed. Clients MUST be prepared to do a
712    cookie exchange with every handshake.
714    If HelloVerifyRequest is used, the initial ClientHello and
715    HelloVerifyRequest are not included in the calculation of the
716    verify_data for the Finished message.
718 4.2.2. Handshake Message Format
720    In order to support message loss, reordering, and
721    fragmentation DTLS modifies the TLS 1.1 handshake header:
723       struct {
724         HandshakeType msg_type;
725         uint24 length;
726         uint16 message_seq;                              // New field
727         uint24 fragment_offset;                          // New field
728         uint24 fragment_length;                          // New field
729         select (HandshakeType) {
730       case hello_request: HelloRequest;
731       case client_hello:  ClientHello;
732       case hello_verify_request: HelloVerifyRequest;     // New type
733       case server_hello:  ServerHello;
734       case certificate:Certificate;
735       case server_key_exchange: ServerKeyExchange;
736       case certificate_request: CertificateRequest;
737       case server_hello_done:ServerHelloDone;
738       case certificate_verify:  CertificateVerify;
739       case client_key_exchange: ClientKeyExchange;
740       case finished:Finished;
744 Rescorla, Modadugu                                              [Page 14]\f
747         } body;
748       } Handshake;
750    The first message each side transmits in each handshake always
751    has message_seq = 0. Whenever each new message is generated,
752    the message_seq value is incremented by one. When a message is
753    retransmitted, the same message_seq value is used. For
754    example.
756       Client                             Server
757       ------                             ------
758       ClientHello (seq=0)  ------>
760                               X<-- HelloVerifyRequest (seq=0)
761                                               (lost)
763       [Timer Expires]
765       ClientHello (seq=0)  ------>
766       (retransmit)
768                            <------ HelloVerifyRequest (seq=0)
770       ClientHello (seq=1)  ------>
771       (with cookie)
773                            <------        ServerHello (seq=1)
774                            <------        Certificate (seq=2)
775                            <------    ServerHelloDone (seq=3)
777       [Rest of handshake]
779    Note, however, that from the perspective of the DTLS record
780    layer, the retransmission is a new record. This record will
781    have a new DTLSPlaintext.sequence_number value.
783    DTLS implementations maintain (at least notionally) a
784    next_receive_seq counter. This counter is initially set to
785    zero. When a message is received, if its sequence number
786    matches next_receive_seq, next_receive_seq is incremented and
787    the message is processed. If the sequence number is less than
788    next_receive_seq the message MUST be discarded. If the
789    sequence number is greater than next_receive_seq, the
790    implementation SHOULD queue the message but MAY discard it.
791    (This is a simple space/bandwidth tradeoff).
798 Rescorla, Modadugu                                              [Page 15]\f
801 4.2.3. Message Fragmentation and Reassembly
803    As noted in Section 4.1.1., each DTLS message MUST fit within
804    a single transport layer datagram. However, handshake messages
805    are potentially bigger than the maximum record size. Therefore
806    DTLS provides a mechanism for fragmenting a handshake message
807    over a number of records.
809    When transmitting the handshake message, the sender divides
810    the message into a series of N contiguous data ranges. These
811    range MUST NOT be larger than the maximum handshake fragment
812    size and MUST jointly contain the entire handshake message.
813    The ranges SHOULD NOT overlap. The sender then creates N
814    handshake messages, all with the same message_seq value as the
815    original handshake message. Each new message is labelled with
816    the fragment_offset (the number of bytes contained in previous
817    fragments) and the fragment_length (the length of this
818    fragment). The length field in all messages is the same as the
819    length field of the original message. An unfragmented message
820    is a degenerate case with fragment_offset=0 and
821    fragment_length=length.
823    When a DTLS implementation receives a handshake message
824    fragment, it MUST buffer it until it has the entire handshake
825    message. DTLS implementations MUST be able to handle
826    overlapping fragment ranges. This allows senders to retransmit
827    handshake messages with smaller fragment sizes during path MTU
828    discovery.
830    Note that as with TLS, multiple handshake messages may be
831    placed in the same DTLS record, provided that there is room
832    and that they are part of the same flight. Thus, there are two
833    acceptable ways to pack two DTLS messages into the same
834    datagram: in the same record or in separate records.
836 4.2.4. Timeout and Retransmission
838    DTLS messages are grouped into a series of message flights,
839    according the diagrams below. Although each flight of messages
840    may consist of a number of messages, they should be viewed as
841    monolithic for the purpose of timeout and retransmission.
852 Rescorla, Modadugu                                              [Page 16]\f
855       Client                                          Server
856       ------                                          ------
858       ClientHello             -------->                           Flight 1
860                               <-------    HelloVerifyRequest      Flight 2
862      ClientHello              -------->                           Flight 3
864                                                  ServerHello    \
865                                                 Certificate*     \
866                                           ServerKeyExchange*      Flight 4
867                                          CertificateRequest*     /
868                               <--------      ServerHelloDone    /
870       Certificate*                                              \
871       ClientKeyExchange                                          \
872       CertificateVerify*                                          Flight 5
873       [ChangeCipherSpec]                                         /
874       Finished                -------->                         /
876                                           [ChangeCipherSpec]    \ Flight 6
877                               <--------             Finished    /
878             Figure 1: Message flights for full handshake
881       Client                                           Server
882       ------                                           ------
884       ClientHello             -------->                          Flight 1
886                                                  ServerHello    \
887                                           [ChangeCipherSpec]     Flight 2
888                                <--------             Finished    /
890       [ChangeCipherSpec]                                         \Flight 3
891       Finished                 -------->                         /
892    Figure 2: Message flights for session resuming handshake (no
893                           cookie exchange)
896    DTLS uses a simple timeout and retransmission scheme with the
897    following state machine. Because DTLS clients send the first
898    message (ClientHello) they start in the PREPARING state. DTLS
899    servers start in the WAITING state, but with empty buffers and
900    no retransmit timer.
906 Rescorla, Modadugu                                              [Page 17]\f
909                 +-----------+
910                 | PREPARING |
911           +---> |           | <--------------------+
912           |     |           |                      |
913           |     +-----------+                      |
914           |           |                            |
915           |           |                            |
916           |           | Buffer next flight         |
917           |           |                            |
918           |          \|/                           |
919           |     +-----------+                      |
920           |     |           |                      |
921           |     |  SENDING  |<------------------+  |
922           |     |           |                   |  | Send
923           |     +-----------+                   |  | HelloRequest
924   Receive |           |                         |  |
925      next |           | Send flight             |  | or
926    flight |  +--------+                         |  |
927           |  |        | Set retransmit timer    |  | Receive
928           |  |       \|/                        |  | HelloRequest
929           |  |  +-----------+                   |  | Send
930           |  |  |           |                   |  | ClientHello
931           +--)--|  WAITING  |-------------------+  |
932           |  |  |           |   Timer expires   |  |
933           |  |  +-----------+                   |  |
934           |  |         |                        |  |
935           |  |         |                        |  |
936           |  |         +------------------------+  |
937           |  |                Read retransmit      |
938   Receive |  |                                     |
939      last |  |                                     |
940    flight |  |                                     |
941           |  |                                     |
942          \|/\|/                                    |
943                                                    |
944       +-----------+                                |
945       |           |                                |
946       | FINISHED  | -------------------------------+
947       |           |
948       +-----------+
950      Figure 3: DTLS timeout and retransmission state machine
953    The state machine has three basic states.
955    In the PREPARING state the implementation does whatever
956    computations are necessary to prepare the next flight of
960 Rescorla, Modadugu                                              [Page 18]\f
963    messages. It then buffers them up for transmission (emptying
964    the buffer first) and enters the SENDING state.
966    In the SENDING state, the implementation transmits the
967    buffered flight of messages. Once the messages have been sent,
968    the implementation then enters the FINISHED state if this is
969    the last flight in the handshake, or, if the implementation
970    expects to receive more messages, sets a retransmit timer and
971    then enters the WAITING state.
973    There are three ways to exit the WAITING state:
975       1. The retransmit timer expires: the implementation
976       transitions to the SENDING state, where it retransmits the
977       flight, resets the retransmit timer, and returns to the
978       WAITING state.
980       2. The implementation reads a retransmitted flight from the
981       peer: the implementation transitions to the SENDING state,
982       where it retransmits the flight, resets the retransmit
983       timer, and returns to the WAITING state. The rationale here
984       is that the receipt of a duplicate message is the likely
985       result of timer expiry on the peer and therefore suggests
986       that part of one's previous flight was lost.
988       3. The implementation receives the next flight of messages:
989       if this is the final flight of messages the implementation
990       transitions to FINISHED. If the implementation needs to
991       send a new flight, it transitions to the PREPARING state.
992       Partial reads (whether partial messages or only some of the
993       messages in the flight) do not cause state transitions or
994       timer resets.
996    Because DTLS clients send the first message (ClientHello) they
997    start in the PREPARING state. DTLS servers start in the
998    WAITING state, but with empty buffers and no retransmit timer.
1000    When the server desires a rehandshake, it transitions from the
1001    FINISHED state to the PREPARING state to transmit the
1002    HelloRequest. When the client receives a HelloRequest it
1003    transitions from FINISHED to PREPARING to transmit the
1004    ClientHello.
1006 4.2.4.1. Timer Values
1008    Though timer value choices are the choice of the
1009    implementation, mishandling of the timer can lead to serious
1010    congestion problems, for example if many instances of a DTLS
1014 Rescorla, Modadugu                                              [Page 19]\f
1017    time out early and retransmit too quickly on a congested link.
1018    Implementations SHOULD use an initial timer value of 1 second
1019    (the minimum defined in RFC 2988 [RFC2988]) and double the
1020    value at each retransmission, up to no less than the the RFC
1021    2988 maximum of 60 seconds. Note that we recommend a 1 second
1022    timer rather than the 3 second RFC 2988 default in order to
1023    improve latency for time-sensitive applications. Because DTLS
1024    only uses retransmission for handshake and not dataflow, the
1025    effect on congestion should be minimal.
1026      Implementations SHOULD retain the current timer value until
1027    a transmission without loss occurs, at which time the value
1028    may be reset to the initial value. After a long period of
1029    idleness, no less than 10 times the current timer value,
1030    implementations may reset the timer to the initial value. One
1031    situation where this might occur is when a rehandshake is used
1032    after substantial data transfer.
1034 4.2.5. ChangeCipherSpec
1036    As with TLS, the ChangeCipherSpec message is not technically a
1037    handshake message but MUST be treated as part of the same
1038    flight as the associated Finished message for the purposes of
1039    timeout and retransmission.
1041 4.2.6. Finished messages
1043    Finished messages have the same format as in TLS. However, in
1044    order to remove sensitivity to fragmentation, the Finished MAC
1045    MUST be computed as if each handshake message had been sent as
1046    a single fragment. Note that in cases where the cookie
1047    exchange is used, the initial ClientHello and
1048    HelloVerifyRequest MUST NOT included in the Finished MAC.
1050 4.2.7. Alert Messages
1052    Note that Alert messages are not retransmitted at all, even
1053    when they occur in the context of a handshake. However, a DTLS
1054    implementation SHOULD generate a new alert message if the
1055    offending record is received again (e.g., as a retransmitted
1056    handshake message). Implementations SHOULD detect when a peer
1057    is persistently sending bad messages and terminate the local
1058    connection state after such misbehavior is detected.
1062 A.1\bSummary of new syntax
1068 Rescorla, Modadugu                                              [Page 20]\f
1071    This section includes specifications for the data structures
1072    that have changed between TLS 1.1 and DTLS.
1074 4.2. Record Layer
1075    struct {
1076      ContentType type;
1077      ProtocolVersion version;
1078      uint16 epoch;                                   // New field
1079      uint48 sequence_number;                         // New field
1080      uint16 length;
1081      opaque fragment[DTLSPlaintext.length];
1082    } DTLSPlaintext;
1084    struct {
1085      ContentType type;
1086      ProtocolVersion version;
1087      uint16 epoch;                                   // New field
1088      uint48 sequence_number;                         // New field
1089      uint16 length;
1090      opaque fragment[DTLSCompressed.length];
1091    } DTLSCompressed;
1093    struct {
1094      ContentType type;
1095      ProtocolVersion version;
1096      uint16 epoch;                                   // New field
1097      uint48 sequence_number;                         // New field
1098      uint16 length;
1099      select (CipherSpec.cipher_type) {
1100    case block:  GenericBlockCipher;
1101      } fragment;
1102    } DTLSCiphertext;
1104 4.3. Handshake Protocol
1106    enum {
1107      hello_request(0), client_hello(1), server_hello(2),
1108      hello_verify_request(3),                        // New field
1109      certificate(11), server_key_exchange (12),
1110      certificate_request(13), server_hello_done(14),
1111      certificate_verify(15), client_key_exchange(16),
1112      finished(20), (255)
1113    } HandshakeType;
1115    struct {
1116      HandshakeType msg_type;
1117      uint24 length;
1118      uint16 message_seq;                             // New field
1122 Rescorla, Modadugu                                              [Page 21]\f
1125      uint24 fragment_offset;                         // New field
1126      uint24 fragment_length;                         // New field
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      opaque cookie<0..32>;
1153    } HelloVerifyRequest;
1155 5. Security Considerations
1157    This document describes a variant of TLS 1.1 and therefore
1158    most of the security considerations are the same as those of
1159    TLS 1.1 [TLS11], described in Appendices D, E, and F.
1161    The primary additional security consideration raised by DTLS
1162    is that of denial of service. DTLS includes a cookie exchange
1163    designed to protect against denial of service. However,
1164    implementations which do not use this cookie exchange are
1165    still vulnerable to DoS. In particular, DTLS servers which do
1166    not use the cookie exchange may be used as attack amplifiers
1167    even if they themselves are not experiencing DoS. Therefore
1168    DTLS servers SHOULD use the cookie exchange unless there is
1169    good reason to believe that amplification is not a threat in
1170    their environment. Clients MUST be prepared to do a cookie
1171    exchange with every handshake.
1176 Rescorla, Modadugu                                              [Page 22]\f
1179 6. IANA Considerations
1181    This document uses the same identifier space as TLS [TLS11],
1182    so no new IANA registries are required. When new identifiers
1183    are assigned for TLS, authors MUST specify whether they are
1184    suitable for DTLS.
1186    This document defines a new handshake message,
1187    hello_verify_request, whose value is to be allocated from the
1188    TLS HandshakeType registry defined in [TLS11]. The value "3"
1189    is suggested.
1191 References
1193 Normative References
1195    [RFC1191]  Mogul, J. C., Deering, S.E., "Path MTU Discovery",
1196               RFC 1191, November 1990.
1198    [RFC1981]  J. McCann, S. Deering, J. Mogul, "Path MTU Discovery
1199               for IP version 6", RFC1981, August 1996.
1201    [RFC2401]  Kent, S., Atkinson, R., "Security Architecture for the
1202               Internet Protocol", RFC2401, November 1998.
1204    [RFC2988]  Paxson, V., Allman, M., "Computing TCP's Retransmission
1205            Timer", RFC 2988, November 2000.
1207    [TCP]      Postel, J., "Transmission Control Protocol",
1208               RFC 793, September 1981.
1210    [TLS11]    Dierks, T., Rescorla, E., "The TLS Protocol Version 1.1",
1211               draft-ietf-tls-rfc2246-bis-05.txt, July 2003.
1214 Informative References
1216    [AESCACHE] Bernstein, D.J., "Cache-timing attacks on AES"
1217            http://cr.yp.to/antiforgery/cachetiming-20050414.pdf.
1219    [AH]       Kent, S., and Atkinson, R., "IP Authentication Header",
1220               RFC 2402, November 1998.
1222    [DCCP]     Kohler, E., Handley, M., Floyd, S., Padhye, J., "Datagram
1223               Congestion Control Protocol", draft-ietf-dccp-spec-11.txt,
1224               10 March 2005
1226    [DNS]      Mockapetris, P.V., "Domain names - implementation and
1230 Rescorla, Modadugu                                              [Page 23]\f
1233               specification", RFC 1035, November 1987.
1235    [DTLS]     Modadugu, N., Rescorla, E., "The Design and Implementation
1236               of Datagram TLS", Proceedings of ISOC NDSS 2004, February 2004.
1238    [ESP]      Kent, S., and Atkinson, R., "IP Encapsulating Security
1239               Payload (ESP)", RFC 2406, November 1998.
1242    [IKE]      Harkins, D., Carrel, D., "The Internet Key Exchange (IKE)",
1243               RFC 2409, November 1998.
1245    [IKEv2]    Kaufman, C., "Internet Key Exchange (IKEv2) Protocol",
1246               draft-ietf-ipsec-ikev2-17.txt, September 2004.
1248    [IMAP]     Crispin, M., "Internet Message Access Protocol - Version
1249               4rev1", RFC 3501, March 2003.
1251    [PHOTURIS] Karn, P., Simpson, W., "Photuris: Session-Key Management
1252               Protocol", RFC 2521, March 1999.
1255    [POP]      Myers, J., and Rose, M., "Post Office Protocol -
1256               Version 3", RFC 1939, May 1996.
1259    [REQ]      Bradner, S., "Key words for use in RFCs to Indicate
1260               Requirement Levels", BCP 14, RFC 2119, March 1997.
1262    [SCTP]     R. Stewart, Q. Xie, K. Morneault, C. Sharp, H. Schwarzbauer,
1263               T. Taylor, I. Rytina, M. Kalla, L. Zhang, V. Paxson,
1264               Stream Control Transmission Protocol", RFC 2960,
1265               October 2000.
1267    [SIP]      Rosenberg, J., Schulzrinne, Camarillo, G., Johnston, A.,
1268               Peterson, J., Sparks, R., Handley, M., Schooler, E.,
1269               "SIP: Session Initiation Protocol", RFC 3261,
1270               June 2002.
1272    [TLS]      Dierks, T., and Allen, C., "The TLS Protocol Version 1.0",
1273               RFC 2246, January 1999.
1275    [WHYIPSEC] Bellovin, S., "Guidelines for Mandating the Use of IPsec",
1276               draft-bellovin-useipsec-02.txt, October 2003
1278 Authors' Address
1284 Rescorla, Modadugu                                              [Page 24]\f
1287    Eric Rescorla <ekr@rtfm.com>
1288    RTFM, Inc.
1289    2064 Edgewood Drive
1290    Palo Alto, CA 94303
1292    Nagendra Modadugu <nagendra@cs.stanford.edu>
1293    Computer Science Department
1294    353 Serra Mall
1295    Stanford University
1296    Stanford, CA 94305
1300 Acknowledgements
1302    The authors would like to thank Dan Boneh, Eu-Jin Goh, Russ
1303    Housley, Constantine Sapuntzakis, and Hovav Shacham for
1304    discussions and comments on the design of DTLS. Thanks to the
1305    anonymous NDSS reviewers of our original NDSS paper on DTLS
1306    [DTLS] for their comments. Also, thanks to Steve Kent for
1307    feedback that helped clarify many points. The section on PMTU
1308    was cribbed from the DCCP specification [DCCP]. Pasi Eronen
1309    provided a detailed review of this specification. Helpful
1310    comments on the document were also received from Mark Allman,
1311    Jari Arkko, Joel Halpern, Ted Hardie and Allison Mankin.
1338 Rescorla, Modadugu                                              [Page 25]\f
1341 Full Copyright Statement
1343    The IETF takes no position regarding the validity or scope of any
1344    Intellectual Property Rights or other rights that might be claimed to
1345    pertain to the implementation or use of the technology described in
1346    this document or the extent to which any license under such rights
1347    might or might not be available; nor does it represent that it has
1348    made any independent effort to identify any such rights. Information
1349    on the procedures with respect to rights in RFC documents can be
1350    found in BCP 78 and BCP 79.
1352    Copies of IPR disclosures made to the IETF Secretariat and any
1353    assurances of licenses to be made available, or the result of an
1354    attempt made to obtain a general license or permission for the use of
1355    such proprietary rights by implementers or users of this
1356    specification can be obtained from the IETF on-line IPR repository at
1357    http://www.ietf.org/ipr.
1359    The IETF invites any interested party to bring to its attention any
1360    copyrights, patents or patent applications, or other proprietary
1361    rights that may cover technology that may be required to implement
1362    this standard. Please address the information to the IETF at ietf-
1363    ipr@ietf.org.
1365 Copyright Notice
1366    Copyright (C) The Internet Society (2003). This document is subject
1367    to the rights, licenses and restrictions contained in BCP 78, and
1368    except as set forth therein, the authors retain all their rights.
1370    This document and the information contained herein are provided on an
1371    "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS
1372    OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY AND THE INTERNET
1373    ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED,
1374    INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE
1375    INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED
1376    WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
1392 Rescorla, Modadugu                                              [Page 26]\f