Improve GTK-DOC coverage.
[gnutls.git] / doc / protocol / draft-rescorla-dtls-02.txt
blob9a2636910aa3a12d8894729397bf9fb88a5fc559
3                                                              E. Rescorla
4                                                               RTFM, Inc.
5                                                              N. Modadugu
6 INTERNET-DRAFT                                       Stanford University
7 <draft-rescorla-dtls-02.txt>           December 2003 (Expires June 2004)
9                    Datagram Transport Layer Security
11 Status of this Memo
13 By submitting this Internet-Draft, I certify that any applicable
14 patent or other IPR claims of which I am aware have been disclosed,
15 and any of which I become aware will be disclosed, in accordance with
16 RFC 3668.
18 Internet-Drafts are working documents of the Internet Engineering
19 Task Force (IETF), its areas, and its working groups. Note that other
20 groups may also distribute working documents as 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 a "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 (1999-2004). All Rights Reserved.
39 Rescorla, Modadugu                                               [Page 1] 
41 Contents
45 Abstract
47    This document specifies Version 1.0 of the Datagram Transport Layer
48    Security (DTLS) protocol. The DTLS protocol provides communications
49    privacy for datagram protocols. The protocol allows client/server
50    applications to communicate in a way that is designed to prevent
51    eavesdropping, tampering, or message forgery. The DTLS protocol is
52    based on the TLS protocol and provides equivalent security
53    guarantees. Datagram semantics of the underlying transport are
54    preserved by the DTLS protocol.
56 1. Introduction
58    TLS [TLS] is the most widely deployed protocol for securing network
59    traffic. It is widely used for protecting Web traffic and for e-mail
60    protocols such as IMAP [IMAP] and POP [POP]. The primary advantage of
61    TLS is that it provides a transparent channel. Thus, it is easy to
62    secure an application protocol by inserting TLS between the
63    application layer and the network layer. However, TLS must run over a
64    reliable transport channel--typically TCP [TCP]. It therefore cannot
65    be used to secure unreliable datagram traffic.
67    However, over the past few years an increasing number of application
68    layer protocols have been designed which UDP transport. In particular
69    such protocols as the Session Initiation Protocol (SIP) [SIP], and
70    electronic gaming protocols are increasingly popular. (Note that SIP
71    can run over both TCP and UDP, but that there are situations in which
72    UDP is preferable). Currently, designers these applications are faced
73    with a number of unsatisfactory choices. First, they can use IPsec
74    [RFC2401]. However, for a number of reasons detailed in [WHYIPSEC],
75    this is only suitable for some applications. Second, they can design
76    a custom application layer security protocol. SIP, for instance, uses
77    a variant of S/MIME to secure its traffic. Unfortunately, application
78    layer security protocols typically require a large amount of effort
79    to design--by contrast to the relatively small amount of effort
80    required to run the protocol over TLS.
82    In many cases, the most desirable way to secure client/server
83    applications would be to use TLS, however the requirement for
84    datagram semantics automatically prohibits use of TLS. Thus, a
85    datagram-compatible variant of TLS would be very desirable. This memo
86    describes such a protocol: Datagram Transport Layer Security (DTLS).
89 Rescorla, Modadugu                                               [Page 2] 
91    DTLS is deliberately designed to be as similar to to TLS as possible,
92    both to minimize new security invention and to maximize the amount of
93    code and infrastructure reuse.
95 2. Usage Model
97    The DTLS protocol is designed to secure data between communicating
98    applications. It is designed to run in application space, without
99    requiring any kernel modifications. While the design of the DTLS
100    protocol does not preclude its use in securing arbitrary datagram
101    traffic, it is primarily expected to secure communication based on
102    datagram sockets.
104    Datagram transport does not guarantee reliable or in-order delivery
105    of data. The DTLS protocol preserves this property for payload data.
106    Applications such as media streaming, Internet telephony and online
107    gaming use datagram transport for communication due to the delay-
108    sensitive nature of transported data. The behavior of such
109    applications is unchanged when the DTLS protocol is used to secure
110    communication, since the DTLS protocol does not compensate for lost
111    or re-ordered data traffic.
113 3. Overview of DTLS
115    The basic design philosophy of DTLS is to construct "TLS over
116    datagram". The reason that TLS cannot be used directly in datagram
117    environments is simply that packets may be lost or reordered. TLS has
118    no internal facilities to handle this kind of unreliability and
119    therefore TLS implementations break when rehosted on datagram
120    transport. The purpose of DTLS is to make only the minimal changes to
121    TLS required to fix this problem. To the greatest extent possible,
122    DTLS is identical to TLS. Whenever we need to invent new mechanisms,
123    we attempt to do so in such a way that it preserves the style of TLS.
125    Unreliability creates problems for TLS at two levels:
127       1. TLS's traffic encryption layer does not allow independent
128       decryption of individual records. If record N is not received,
129       then record N+1 cannot be decrypted.
131       2. The TLS handshake layer assumes that handshake messages are
132       delivered reliably and breaks if those messages are lost.
134    The rest of this section describes the approach that DTLS uses to
135    solve these problems.
139 Rescorla, Modadugu                                               [Page 3] 
141 3.1. Loss-insensitive messaging
143    In TLS's traffic encryption layer (called the TLS Record Layer),
144    records are not independent. There are two kinds of inter-record
145    dependency:
147       1. Cryptographic context (CBC state, stream cipher key stream) is
148       chained between records.
150       2. Anti-replay and message reordering protection are provided by a
151       MAC which includes a sequence number, but the sequence numbers are
152       implicit in the records.
154    The fix for both of these problems is straightforward and well-known
155    from IPsec ESP [ESP]: add explicit state to the records. TLS 1.1
156    [TLS11] is already adding explicit CBC state to TLS records. DTLS
157    borrows that mechanism and adds explicit sequence numbers.
159 3.2. Providing Reliability for Handshake
161    The TLS handshake is a lockstep cryptographic handshake. Messages
162    must be transmitted and received in a defined order and any other
163    order is an error. Clearly, this is incompatible with reordering and
164    message loss. In addition, TLS handshake messages are potentially
165    larger than any given datagram, thus creating the problem of
166    fragmentation. DTLS must provide fixes for both these problems.
168 3.2.1. Packet Loss
170    DTLS uses a simple retransmission timer to handle packet loss. The
171    following figure demonstrates the basic concept using the first phase
172    of the DTLS handshake:
174       Client                                   Server
175       ------                                   ------
176       ClientHello           ------>
178                               X<-- HelloVerifyRequest
179                                                (lost)
181       [Timer Expires]
183       ClientHello           ------>
184       (retransmit)
186    Once the client has transmitted the ClientHello message, it expects
187    to see a HelloVerifyRequest from the server. However, if the server's
188    message is lost the client knows that either the ClientHello or the
191 Rescorla, Modadugu                                               [Page 4] 
193    HelloVerifyRequest has been lost and retransmits. When the server
194    receives the retransmission, it knows to retransmit. The server also
195    maintains a retransmission timer and retransmits when that timer
196    expires.
198 3.2.2. Reordering
200    In DTLS, each handshake message is assigned a specific sequence
201    number within that handshake. When a peer receives a handshake
202    message, it can quickly determine whether that message is the next
203    message it expects. If it is, then it processes it. If not, it queues
204    it up for future handling once all previous messages have been
205    received.
207 3.3. Message Size
209    TLS and DTLS handshake messages can be quite large (in theory up to
210    2^24-1 bytes, in practice many kilobytes). By contrast, UDP datagrams
211    are often limited to <1500 bytes. In order to compensate for this
212    limitation, each DTLS handshake message may be fragmented over
213    several DTLS records. Each DTLS handshake message contains both a
214    fragment offset and a fragment length. Thus, a recipient in
215    possession of all bytes of a handshake message can reassemble the
216    original unfragmented message.
217    DTLS optionally supports record replay detection. The technique used
218    is the same as in IPsec AH/ESP, by maintaining a bitmap window of
219    received records. Records that are too old to fit in the window and
220    records that have been previously received are silently discarded.
221    The replay detection feature is optional, since packet duplication is
222    not always malicious, but can also occur due to routing errors.
223    Applications may conceivably detect duplicate packets and accordingly
224    modify their data transmission strategy.
226 4. Differences from TLS
228    As mentioned in Section , DTLS is intentionally very similar to TLS.
229    Therefore, instead of presenting DTLS as a new protocol, we instead
230    present it as a series of deltas from TLS 1.1 [TLS11]. Where we do
231    not explicitly call out differences, DTLS is the same as TLS.
233 4.1. Record Layer
235    The DTLS record layer is extremely similar to that of TLS 1.1. The
236    only change is the inclusion of an explicit sequence number in the
237    record. This sequence number allows the recipient to correctly verify
238    the TLS MAC. The DTLS record format is shown below:
242 Rescorla, Modadugu                                               [Page 5] 
244        struct {
245         ContentType type;
246         ProtocolVersion version;
247         uint16 epoch;
248         uint48 sequence_number;
249         uint16 length;
250         opaque fragment[DTLSPlaintext.length];
251        } DTLSPlaintext;
253       type
254        Equivalent to the type field in a TLS 1.1 record.
256       version
257        The version of the protocol being employed. This document
258        describes DTLS Version 1.0, which uses the version { 254, 255
259        }. The version value of 254.255 is the 1's complement of DTLS
260        Version 1.0. This maximal spacing between TLS and DTLS version
261        numbers ensures that records from the two protocols can be
262        easily distinguished.
264       epoch
265        A counter value that is incremented on every cipher state
266        change.
268       sequence_number
269        The sequence number for this record.
271       length
272        Identical to the length field in a TLS 1.1 record. As in TLS
273        1.1, the length should not exceed 2^14.
275       fragment
276        Identical to the fragment field of a TLS 1.1 record.
278    DTLS uses an explicit rather than implicit sequence number, carried
279    in the sequence_number field of the record. As with TLS, the sequence
280    number is set to zero after each ChangeCipherSpec message is sent.
282    If several handshakes are performed in close succession, there might
283    be multiple records on the wire with the same sequence number but
284    from different cipher states. The epoch field allows recipients to
285    distinguish such packets. The epoch number is initially zero and is
286    incremented each time the ChangeCipherSpec messages is sent. In order
287    to ensure that any given sequence/epoch pair is unique,
288    implementations MUST NOT allow the same epoch value to be reused
289    within two times the maximum segment lifetime. In practice, TLS
290    implementations rehandshake rarely and we therefore do not expect
291    this to be a problem.
294 Rescorla, Modadugu                                               [Page 6] 
296 4.1.1. Transport Layer Mapping
298    Each DTLS record MUST fit within a single datagram. In order to avoid
299    IP fragmentation [MOGUL], DTLS implementations SHOULD determine the
300    MTU and send records smaller than the MTU. DTLS implementations
301    SHOULD provide a way for applications to determine the value of the
302    MTU (optimally the maximum application datagram size, which is the
303    PMTU minus the DTLS per-record overhead). If the application attempts
304    to send a record larger than the MTU, the DTLS implementation MUST
305    either generate an error or fragment the packet.
307 4.1.1.1. PMTU Discovery
309    The PMTU SHOULD be initialized from the interface MTU that will be
310    used to send packets.
312    To perform PMTU discovery, the DTLS sender sets the IP Don't Fragment
313    (DF) bit. As specified in [RFC 1191], when a router receives a packet
314    with DF set that is larger than the next link's MTU, it sends an ICMP
315    Destination Unreachable message to the source of the datagram with
316    the Code indicating "fragmentation needed and DF set" (also known as
317    a "Datagram Too Big" message). When a DTLS implementation receives a
318    Datagram Too Big message, it decreases its PMTU to the Next-Hop MTU
319    value given in the ICMP message. If the MTU given in the message is
320    zero, the sender chooses a value for PMTU using the algorithm
321    described in Section 7 of [RFC 1191]. If the MTU given in the message
322    is greater than the current PMTU, the Datagram Too Big message is
323    ignored, as described in [RFC 1191].
325    A DTLS implementation may allow the application to occasionally
326    request that PMTU discovery be performed again. This will reset the
327    PMTU to the outgoing interface's MTU. Such requests SHOULD be rate
328    limited, to one per two seconds, for example.
330    Because some firewalls and routers screen out ICMP messages, it is
331    difficult to distinguish packet loss from a large PMTU estimate. In
332    order to allow connections under these circumstances, DTLS
333    implementations MAY choose to back off their PMTU estimate during the
334    retransmit backoff described in Section . For instance, if a large
335    packet is being sent, after 3 retransmits a sender might choose to
336    fragment the packet.
338 4.1.2. Record payload protection
340 4.1.2.1. MAC
342    The DTLS MAC is the same as that of TLS 1.1. However, rather than
343    using TLS's implicit sequence number, the sequence number used to
346 Rescorla, Modadugu                                               [Page 7] 
348    compute the MAC is the 64-bit value formed by concatenating the epoch
349    and the sequence number in the order they appear on the wire. Note
350    that the DTLS epoch + sequence number is the same length as the TLS
351    sequence number.
353 4.1.2.2. Null or standard stream cipher
355    The DTLS NULL cipher is performed exactly as the TLS 1.1 NULL cipher.
357    The only stream cipher described in TLS 1.1 is RC4, which cannot be
358    randomly accessed. RC4 MUST NOT be used with DTLS.
360 4.1.2.3. Block Cipher
362    DTLS block cipher encryption and decryption are performed exactly as
363    with TLS 1.1.
365 4.1.2.4. Anti-Replay
367    DTLS records contain a sequence number to provide replay protection.
368    Sequence number verification SHOULD be performed using the following
369    sliding, window procedure, borrowed from Section 3.4.3 of [RFC 2402]
371    The receiver packet counter for this session MUST be initialized to
372    zero when the session is established. For each received record, the
373    receiver MUST verify that the record contains a Sequence Number that
374    does not duplicate the Sequence Number of any other record received
375    during the life of this session. This SHOULD be the first check
376    applied to a packet after it has been matched to a session, to speed
377    rejection of duplicate records.
379    Duplicates are rejected through the use of a sliding receive window.
380    (How the window is implemented is a local matter, but the following
381    text describes the functionality that the implementation must
382    exhibit.) A MINIMUM window size of 32 MUST be supported; but a window
383    size of 64 is preferred and SHOULD be employed as the default.
384    Another window size (larger than the MINIMUM) MAY be chosen by the
385    receiver. (The receiver does NOT notify the sender of the window
386    size.)
388    The "right" edge of the window represents the highest, validated
389    Sequence Number value received on this session. Records that contain
390    Sequence Numbers lower than the "left" edge of the window are
391    rejected. Packets falling within the window are checked against a
392    list of received packets within the window. An efficient means for
393    performing this check, based on the use of a bit mask, is described
394    in [RFC 2401].
397 Rescorla, Modadugu                                               [Page 8] 
399    If the received record falls within the window and is new, or if the
400    packet is to the right of the window, then the receiver proceeds to
401    MAC verification. If the MAC validation fails, the receiver MUST
402    discard the received record as invalid. The receive window is updated
403    only if the MAC verification succeeds.
405 4.2. The DTLS Handshake Protocol
407    DTLS uses all of the same handshake messages and flows as TLS, with
408    three principal changes:
410       1. A stateless cookie exchange to prevent denial of service
411       attacks.
413       2. Modifications to the handshake header to handle message loss,
414       reordering and fragmentation.
416       3. Retransmission timers to handle message loss.
418    With these exceptions, the DTLS message formats, flows, and logic are
419    the same as those of TLS 1.1.
421 4.2.1. Denial of Service Countermeasures
423    Datagram security protocols are extremely susceptible to a variety of
424    denial of service (DoS) attacks. Two attacks are of particular
425    concern:
427       1. An attacker can consume excessive resources on the server by
428       transmitting a series of handshake initiation requests, causing
429       the server to allocate state and potentially perform expensive
430       cryptographic operations.
432       2. An attacker can use the server as an amplifier by sending
433       connection initiation messages with a forged source of the victim.
434       The server then sends its next message (in DTLS, a Certificate
435       message, which can be quite large) to the victim machine, thus
436       flooding it.
438    In order to prevent both of these attacks, DTLS borrows the stateless
439    cookie technique used by Photuris [PHOTURIS] and IKEv2 [IKE]. When
440    the client sends its ClientHello message to the server, the server
441    MAY respond with a HelloVerifyRequest message. This message contains
442    a stateless cookie generated using the technique of [PHOTURIS]. The
443    client MUST retransmit the ClientHello with the cookie added. The
444    server then verifies the cookie and proceeds with the handshake only
445    if it is valid.
448 Rescorla, Modadugu                                               [Page 9] 
450    The exchange is shown below:
452          Client                                   Server
453          ------                                   ------
454          ClientHello           ------>
456                                <----- HelloVerifyRequest
457                                       (contains cookie)
459          ClientHello           ------>
460          (with cookie)
462          [Rest of handshake]
464    DTLS therefore modifies the ClientHello message to add the cookie
465    value.
467       struct {
468         ProtocolVersion client_version;
469         Random random;
470         SessionID session_id;
471         Cookie cookie<0..32>;                 // New field
472         CipherSuite cipher_suites<2..2^16-1>;
473         CompressionMethod compression_methods<1..2^8-1>;
474       } ClientHello;
476    If the client does not have a cookie for a given server, it should
477    use a zero-length cookie.
479    The definition of HelloVerifyRequest is as follows:
481       struct {
482         Cookie cookie<0..32>;
483       } HelloVerifyRequest;
485    The HelloVerifyRequest message type is hello_verify_request(3).
487    When responding to a HelloVerifyRequest the client MUST use the same
488    parameter values (version, random, session_id, cipher_suites,
489    compression_method) as in the original ClientHello. The server SHOULD
490    use those values to generate its cookie and verify that they are
491    correct upon cookie receipt.
493    Although DTLS servers are not required to do a cookie exchange, they
494    SHOULD do so whenever a new handshake is performed in order to avoid
495    being used as amplifiers. If the server is being operated in an
496    environment where amplification is not a problem, the server MAY
497    choose not to perform a cookie exchange. In addition, the server MAY
500 Rescorla, Modadugu                                              [Page 10] 
502    choose not do to a cookie exchange when a session is resumed. Clients
503    MUST be prepared to do a cookie exchange with every handshake.
505 4.2.2. Handshake Message Format
507    In order to support message loss, reordering, and fragmentation DTLS
508    modifies the TLS 1.1 handshake header:
510       struct {
511         HandshakeType msg_type;
512         uint24 length;
513         uint16 message_seq;                              // New field
514         uint24 fragment_offset;                          // New field
515         uint24 fragment_length;                          // New field
516         select (HandshakeType) {
517       case hello_request: HelloRequest;
518       case client_hello:  ClientHello;
519       case hello_verify_request: HelloVerifyRequest;     // New message type
520       case server_hello:  ServerHello;
521       case certificate:Certificate;
522       case server_key_exchange: ServerKeyExchange;
523       case certificate_request: CertificateRequest;
524       case server_hello_done:ServerHelloDone;
525       case certificate_verify:  CertificateVerify;
526       case client_key_exchange: ClientKeyExchange;
527       case finished:Finished;
528         } body;
529       } Handshake;
531    The first message each side transmits in each handshake always has
532    message_seq = 0. Whenever each new message is generated, the
533    message_seq value is incremented by one. When a message is
534    retransmitted, the same message_seq value is used. For example.
536       Client                             Server
537       ------                             ------
538       ClientHello (seq=0)  ------>
540                               X<-- HelloVerifyRequest (seq=0)
541                                               (lost)
543       [Timer Expires]
545       ClientHello (seq=0)  ------>
546       (retransmit)
548                            <------ HelloVerifyRequest (seq=0)
551 Rescorla, Modadugu                                              [Page 11] 
553       ClientHello (seq=1)  ------>
554       (with cookie)
556                            <------        ServerHello (seq=1)
557                            <------        Certificate (seq=2)
558                            <------    ServerHelloDone (seq=3)
560       [Rest of handshake]
562    DTLS implementations maintain (at least notionally) a
563    next_receive_seq counter. This counter is initially set to zero. When
564    a message is received, if its sequence number matches
565    next_receive_seq, next_receive_seq is incremented and the message is
566    processed. If the sequence number is less than next_receive_seq the
567    message MUST be discarded. If the sequence number is greater than
568    next_receive_seq, the implementation SHOULD queue the message but MAY
569    discard it. (This is a simple space/bandwidth tradeoff).
571 4.2.3. Message Fragmentation and Reassembly
573    As noted in Section , each DTLS message MUST fit within a single
574    transport layer datagram. However, handshake messages are potentially
575    bigger than the maximum record size. Therefore DTLS provides a
576    mechanism for fragmenting a handshake message over a number of
577    records.
579    When transmitting the handshake message, the sender divides the
580    message into a series of N contiguous data ranges. These range must
581    be no larger than the maximum handshake fragment size and MUST
582    jointly contain the entire handshake message. The ranges SHOULD NOT
583    overlap. The sender then creates N handshake messages, all with the
584    same message_seq value as the original handshake message. Each new
585    message is labelled with the fragment_offset (the number of bytes
586    contained in previous fragments) and the fragment_length (the length
587    of this fragment). The length field in all messages is the same as
588    the length field of the original message. An unfragmented message is
589    a degenerate case with fragment_offset=0 and fragment_length=length.
591    When a DTLS implementation receives a handshake message fragment, it
592    MUST buffer it until it has the entire handshake message. DTLS
593    implementations MUST be able to handle overlapping fragment ranges.
594    This allows senders to retransmit handshake messages with smaller
595    fragment sizes during path MTU discovery.
597 4.2.4. Timeout and Retransmission
599    DTLS messages are grouped into a series of message flights, according
600    the diagrams below. Although each flight of messages may consist of a
603 Rescorla, Modadugu                                              [Page 12] 
605    number of messages, they should be viewed as monolithic for the
606    purpose of timeout and retransmission.
608       Client                                          Server
609       ------                                          ------
611       ClientHello             -------->                           Flight 1
613                               <-------    HelloVerifyRequest      Flight 2
615      ClientHello              -------->                           Flight 3
617                                                  ServerHello    \
618                                                 Certificate*     \
619                                           ServerKeyExchange*      Flight 4
620                                          CertificateRequest*     /
621                               <--------      ServerHelloDone    /
623       Certificate*                                              \
624       ClientKeyExchange                                          \
625       CertificateVerify*                                          Flight 5
626       [ChangeCipherSpec]                                         /
627       Finished                -------->                         /
629                                           [ChangeCipherSpec]    \ Flight 6
630                               <--------             Finished    /
631                Figure 1: Message flights for full handshake
633       Client                                           Server
634       ------                                           ------
636       ClientHello             -------->                          Flight 1
638                                                  ServerHello    \
639                                           [ChangeCipherSpec]     Flight 2
640                                <--------             Finished    /
642       [ChangeCipherSpec]                                         \Flight 3
643       Finished                 -------->                         /
644    Figure 2: Message flights for session resuming handshake (no cookie exchange)
646    DTLS uses a simple timeout and retransmission scheme with the
647    following state machine.
651 Rescorla, Modadugu                                              [Page 13] 
653                    +--------+
654                    | PREPAR |
655              +---> | -ING   |
656              |     |        |
657              |     +--------+
658              |         |
659              |         |
660              |         | Buffer next flight
661              |         |
662              |        \|/
663              |     +---------+
664              |     |         |
665              |     | SENDING |<--------------------+
666              |     |         |                     |
667              |     +---------+                     |
668      Receive |          |                          |
669         next |          | Send flight              |
670       flight |  +-------+                          |
671              |  |       | Set retransmit timer     |
672              |  |      \|/                         |
673              |  |  +---------+                     |
674              |  |  |         |                     |
675              +--)--| WAITING |---------------------+
676              |  |  |         |     Timer expires   |
677              |  |  +---------+                     |
678              |  |         |                        |
679              |  |         |                        |
680              |  |         +------------------------+
681              |  |                  Read retransmit
682      Receive |  |
683         last |  |
684       flight |  |
685              |  |
686             \|/\|/
688             FINISH
689           Figure 3: DTLS timeout and retransmission state machine
691    The state machine has three basic states.
693    In the PREPARING state the implementation does whatever computations
694    are necessary to prepare the next flight of messages. It then buffers
695    them up for transmission (emptying the buffer first) and enters the
696    SENDING state.
700 Rescorla, Modadugu                                              [Page 14] 
702    In the SENDING state, the implementation transmits the buffered
703    flight of messages. Once the messages have been sent, the
704    implementation then enters the FINISH state if this is the last
705    flight in the handshake, or, if the implementation expects to receive
706    more messages, sets a retransmit timer and then enters the WAITING
707    state.
709    There are three ways to exit the WAITING state:
711       1. The retransmit timer expires: the implementation transitions to
712       the SENDING state, where it retransmits the flight, resets the
713       retransmit timer, and returns to the WAITING state.
715       2. The implementation reads a retransmitted flight from the peer:
716       the implementation transitions to the SENDING state, where it
717       retransmits the flight, resets the retransmit timer, and returns
718       to the WAITING state. The rationale here is that the receipt of a
719       duplicate message is the likely result of timer expiry on the peer
720       and therefore suggests that part of one's previous flight was
721       lost.
723       3. The implementation receives the next flight of messages: if
724       this is the final flight of messages the implementation
725       transitions to FINISHED. If the implementation needs to send a new
726       flight, it transitions to the PREPARING state. Partial reads
727       (whether partial messages or only some of the messages in the
728       flight) do not cause state transitions or timer resets.
730    Because DTLS clients send the first message (ClientHello) they start
731    in the PREPARING state. DTLS servers start in the WAITING state, but
732    with empty buffers and no retransmit timer.
734 4.2.4.1. Timer Values
736    Timer value choices are a local matter. We recommend that
737    implementations use an initial timer value of 500 ms and double the
738    value at each retransmission, up to 2MSL. Implementations SHOULD
739    start the timer value at the initial value with each new flight of
740    messages.
742 4.2.5. ChangeCipherSpec
744    As with TLS, the ChangeCipherSpec message is not technically a
745    handshake message but MUST be treated as part of the same flight as
746    the associated Finished message for the purposes of timeout and
747    retransmission.
751 Rescorla, Modadugu                                              [Page 15] 
753 4.2.6. Finished messages
755    Finished messages have the same format as in TLS. However, in order
756    to remove sensitivity to fragmentation, the Finished MAC MUST be
757    computed as if each handshake message had been sent as a single
758    fragment. Note that in cases where the cookie exchange is used, the
759    initial ClientHello and HelloVerifyRequest ARE included in the
760    Finished MAC.
763 A.1 Summary of new syntax
765    This section includes specifications for the data structures that
766    have changed between TLS 1.1 and DTLS.
768 4.2. Record Layer
769    struct {
770      ContentType type;
771      ProtocolVersion version;
772      uint16 epoch;                                   // NEW
773      uint48 sequence_number;                         // NEW
774      uint16 length;
775      opaque fragment[DTLSPlaintext.length];
776    } DTLSPlaintext;
778    struct {
779      ContentType type;
780      ProtocolVersion version;
781      uint16 epoch;                                   // NEW
782      uint48 sequence_number;                         // NEW
783      uint16 length;
784      opaque fragment[DTLSCompressed.length];
785    } DTLSCompressed;
787    struct {
788      ContentType type;
789      ProtocolVersion version;
790      uint16 epoch;                                   // NEW
791      uint48 sequence_number;                         // NEW
792      uint16 length;
793      select (CipherSpec.cipher_type) {
794    case block:  GenericBlockCipher;
795      } fragment;
796    } DTLSCiphertext;
800 Rescorla, Modadugu                                              [Page 16] 
802 4.3. Handshake Protocol
804    enum {
805      hello_request(0), client_hello(1), server_hello(2),
806      hello_verify_request(3),                        // NEW
807      certificate(11), server_key_exchange (12),
808      certificate_request(13), server_hello_done(14),
809      certificate_verify(15), client_key_exchange(16),
810      finished(20), (255)
811    } HandshakeType;
813    struct {
814      HandshakeType msg_type;
815      uint24 length;
816      uint16 message_seq;                             // NEW
817      uint24 fragment_offset;                         // NEW
818      uint24 fragment_length;                         // NEW
819      select (HandshakeType) {
820    case hello_request: HelloRequest;
821    case client_hello:  ClientHello;
822    case server_hello:  ServerHello;
823    case hello_verify_request: HelloVerifyRequest;    // NEW
824    case certificate:Certificate;
825    case server_key_exchange: ServerKeyExchange;
826    case certificate_request: CertificateRequest;
827    case server_hello_done:ServerHelloDone;
828    case certificate_verify:  CertificateVerify;
829    case client_key_exchange: ClientKeyExchange;
830    case finished:Finished;
831      } body;
832    } Handshake;
834    struct {
835      Cookie cookie<H0..32>;
836    } HelloVerifyRequest;
838 5. Security Considerations
840    This document describes a variant of TLS 1.1 and therefore most of
841    the security considerations are the same as TLS 1.1.
843    The primary additional security consideration raised by DTLS is that
844    of denial of service. DTLS includes a cookie exchange designed to
845    protect against denial of service. However, implementations which do
846    not use this cookie exchange are still vulnerable to DoS. In
847    particular, DTLS servers which do not use the cookie exchange may be
848    used as attack amplifiers even if they themselves are not
849    experiencing DoS. Therefore DTLS servers SHOULD use the cookie
852 Rescorla, Modadugu                                              [Page 17] 
854    exchange unless there is good reason to believe that amplification is
855    not a threat in their environment.
857 6. IANA Considerations
859    This document uses the same identifier space as does TLS [TLS11], so
860    no IANA registries are required beyond those for TLS. Identifiers MAY
861    NOT be assigned for DTLS that conflict with TLS.
863 References
865 Normative References
867    [PHOTURIS] Karn, P., Simpson, W., "Photuris: Session-Key Management
868               Protocol", RFC 2521, March 1999.
870    [RFC1191]  Mogul, J. C., Deering, S.E., "Path MTU Discovery",
871               RFC 1191, November 1990.
873    [RFC2401]  Kent, S., Atkinson, R., "Security Architecture for the
874               Internet Protocol", RFC2401, November 1998.
876    [TLS]      Dierks, T., and Allen, C., "The TLS Protocol Version 1.0",
877               RFC 2246, January 1999.
879    [TLS11]    Dierks, T., Rescorla, E., "The TLS Protocol Version 1.1",
880               draft-ietf-tls-rfc2246-bis-05.txt, July 2003.
882 Informative References
884    [AH]       Kent, S., and Atkinson, R., "IP Authentication Header",
885               RFC 2402, November 1998.
887    [DCCP]     Kohler, E., Handley, M., Floyd, S., Padhye, J., "Datagram
888               Congestion Control Protocol", draft-ietf-dccp-spec-05.txt,
889               October 2003
891    [DTLS]     Modadugu, N., Rescorla, E., "The Design and Implementation
892               of Datagram TLS", in Proceedings of ISOC NDSS 2004,
893               February 2004.
895    [ESP]      Kent, S., and Atkinson, R., "IP Encapsulating Security
896               Payload (ESP)", RFC 2406, November 1998.
898    [IKE]      Harkins, D., Carrel, D., "The Internet Key Exchange (IKE)",
899               RFC 2409, November 1998.
902 Rescorla, Modadugu                                              [Page 18] 
904    [IMAP]     Crispin, M., "Internet Message Access Protocol - Version
905               4rev1", RFC 3501, March 2003.
907    [POP]      Myers, J., and Rose, M., "Post Office Protocol -
908               Version 3", RFC 1939, May 1996.
910    [SIP]      Rosenberg, J., Schulzrinne, Camarillo, G., Johnston, A.,
911               Peterson, J., Sparks, R., Handley, M., Schooler, E.,
912               "SIP: Session Initiation Protocol", RFC 3261,
913               June 2002.
915    [TCP]      Postel, J., "Transmission Control Protocol",
916               RFC 793, September 1981.
918    [WHYIPSEC] Bellovin, S., "Guidelines for Mandating the Use of IPsec",
919               draft-bellovin-useipsec-02.txt, October 2003
921 Authors' Address
923    Eric Rescorla <ekr@rtfm.com>
924    RTFM, Inc.
925    2064 Edgewood Drive
926    Palo Alto, CA 94303
928    Nagendra Modadugu <nagendra@cs.stanford.edu>
929    Computer Science Department
930    353 Serra Mall
931    Stanford University
932    Stanford, CA 94305
935 Acknowledgements
937    The authors would like to thank Dan Boneh, Eu-Jin Goh, Constantine
938    Sapuntzakis, and Hovav Shacham for discussions and comments on the
939    design of DTLS. Thanks to the anonymous NDSS reviewers of our
940    original NDSS paper on DTLS [DTLS] for their comments. Also, thanks
941    to Steve Kent for feedback that helped clarify many points. The
942    section on PMTU was cribbed from the DCCP specification [DCCP].
948 Rescorla, Modadugu                                              [Page 19] 
950 Full Copyright Statement
952    The IETF takes no position regarding the validity or scope of any
953    Intellectual Property Rights or other rights that might be claimed to
954    pertain to the implementation or use of the technology described in
955    this document or the extent to which any license under such rights
956    might or might not be available; nor does it represent that it has
957    made any independent effort to identify any such rights. Information
958    on the procedures with respect to rights in RFC documents can be
959    found in BCP 78 and BCP 79.
961    Copies of IPR disclosures made to the IETF Secretariat and any
962    assurances of licenses to be made available, or the result of an
963    attempt made to obtain a general license or permission for the use of
964    such proprietary rights by implementers or users of this
965    specification can be obtained from the IETF on-line IPR repository at
966    http://www.ietf.org/ipr.
968    The IETF invites any interested party to bring to its attention any
969    copyrights, patents or patent applications, or other proprietary
970    rights that may cover technology that may be required to implement
971    this standard. Please address the information to the IETF at ietf-
972    ipr@ietf.org.
974 Copyright Notice
975    Copyright (C) The Internet Society (2003). This document is subject
976    to the rights, licenses and restrictions contained in BCP 78, and
977    except as set forth therein, the authors retain all their rights.
979    This document and the information contained herein are provided on an
980    "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS
981    OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY AND THE INTERNET
982    ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED,
983    INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE
984    INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED
985    WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
994 Rescorla, Modadugu                                              [Page 20]