Improve GTK-DOC coverage.
[gnutls.git] / doc / protocol / draft-ietf-tls-rfc2246-bis-09.txt
blob2a802d6f02bf4e4ca40c1bb23167a017b6f70b31
3                                                               Tim Dierks
4                                                              Independent
5                                                            Eric Rescorla
6 INTERNET-DRAFT                                                RTFM, Inc.
7 <draft-ietf-tls-rfc2246-bis-09.txt>    December 2004 (Expires June 2005)
9                             The TLS Protocol
10                               Version 1.1
12 Status of this Memo
14 By submitting this Internet-Draft, I certify that any applicable
15 patent or other IPR claims of which I am aware have been disclosed,
16 and any of which I become aware will be disclosed, in accordance with
17 RFC 3668.
19 Internet-Drafts are working documents of the Internet Engineering
20 Task Force (IETF), its areas, and its working groups. Note that other
21 groups may also distribute working documents as Internet-Drafts.
23 Internet-Drafts are draft documents valid for a maximum of six months
24 and may be updated, replaced, or obsoleted by other documents at any
25 time. It is inappropriate to use Internet-Drafts as reference
26 material or to cite them other than a "work in progress."
28 The list of current Internet-Drafts can be accessed at
29 http://www.ietf.org/1id-abstracts.html
31 The list of Internet-Draft Shadow Directories can be accessed at
32 http://www.ietf.org/shadow.html
34 Copyright Notice
36    Copyright (C) The Internet Society (1999-2004).  All Rights Reserved.
38 Abstract
40    This document specifies Version 1.1 of the Transport Layer Security
41    (TLS) protocol. The TLS protocol provides communications security
42    over the Internet. The protocol allows client/server applications to
43    communicate in a way that is designed to prevent eavesdropping,
44    tampering, or message forgery.
46 Table of Contents
48    1.        Introduction
49    3 1.1       Requirements Terminology
50    4 2.        Goals
54 Dierks & Rescorla            Standards Track                     [Page 1]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
57    4 3.        Goals of this document
58    5 4.        Presentation language
59    5 4.1.      Basic block size
60    6 4.2.      Miscellaneous
61    6 4.3.      Vectors
62    6 4.4.      Numbers
63    7 4.5.      Enumerateds
64    7 4.6.      Constructed types
65    8 4.6.1.    Variants
66    9 4.7.      Cryptographic attributes
67    10 4.8.      Constants
68    11 5.        HMAC and the pseudorandom function
69    11 6.        The TLS Record Protocol
70    13 6.1.      Connection states
71    14 6.2.      Record layer
72    16 6.2.1.    Fragmentation
73    16 6.2.2.    Record compression and decompression
74    18 6.2.3.    Record payload protection
75    18 6.2.3.1.  Null or standard stream cipher
76    19 6.2.3.2.  CBC block cipher
77    20 6.3.      Key calculation
78    22 6.3.1.    Export key generation example
79    23 7.        The TLS Handshaking Protocols
80    24 7.1.      Change cipher spec protocol
81    25 7.2.      Alert protocol
82    25 7.2.1.    Closure alerts
83    26 7.2.2.    Error alerts
84    27 7.3.      Handshake Protocol overview
85    30 7.4.      Handshake protocol
86    34 7.4.1.    Hello messages
87    35 7.4.1.1.  Hello request
88    35 7.4.1.2.  Client hello
89    36 7.4.1.3.  Server hello
90    38 7.4.2.    Server certificate
91    39 7.4.3.    Server key exchange message
92    42 7.4.4.    Certificate request
93    45 7.4.5.    Server hello done
94    46 7.4.6.    Client certificate
95    46 7.4.7.    Client key exchange message
96    47 7.4.7.1.  RSA encrypted premaster secret message
97    47 7.4.7.2.  Client Diffie-Hellman public value
98    49 7.4.8.    Certificate verify
99    50 7.4.9.    Finished
100    51 8.        Cryptographic computations
101    52 8.1.      Computing the master secret
102    52 8.1.1.    RSA
103    53 8.1.2.    Diffie-Hellman
104    53 9.        Mandatory Cipher Suites
108 Dierks & Rescorla            Standards Track                     [Page 2]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
111    53 A.        Protocol constant values
112    55 A.1.      Record layer
113    55 A.2.      Change cipher specs message
114    56 A.3.      Alert messages
115    56 A.4.      Handshake protocol
116    57 A.4.1.    Hello messages
117    57 A.4.2.    Server authentication and key exchange messages
118    58 A.4.3.    Client authentication and key exchange messages
119    59 A.4.4.    Handshake finalization message
120    60 A.5.      The CipherSuite
121    60 A.6.      The Security Parameters
122    63 B.        Glossary
123    64 C.        CipherSuite definitions
124    68 D.        Implementation Notes
125    71 D.1.      Temporary RSA keys
126    71 D.2.      Random Number Generation and Seeding
127    71 D.3.      Certificates and authentication
128    72 D.4.      CipherSuites
129    72 E.        Backward Compatibility With SSL
130    73 E.1.      Version 2 client hello
131    74 E.2.      Avoiding man-in-the-middle version rollback
132    75 F.        Security analysis
133    77 F.1.      Handshake protocol
134    77 F.1.1.    Authentication and key exchange
135    77 F.1.1.1.  Anonymous key exchange
136    77 F.1.1.2.  RSA key exchange and authentication
137    78 F.1.1.3.  Diffie-Hellman key exchange with authentication
138    79 F.1.2.    Version rollback attacks
139    79 F.1.3.    Detecting attacks against the handshake protocol
140    80 F.1.4.    Resuming sessions
141    80 F.1.5.    MD5 and SHA
142    81 F.2.      Protecting application data
143    81 F.3.      Explicit IVs
144    81 F.4       Security of Composite Cipher Modes
145    82 F.5       Denial of Service
146    83 F.6.      Final notes
147    83
150 Change history
152    03-Dec-04 ekr@rtfm.com
153     * Removed export cipher suites
155    26-Oct-04 ekr@rtfm.com
156     * Numerous cleanups from Last Call comments
158    10-Aug-04 ekr@rtfm.com
162 Dierks & Rescorla            Standards Track                     [Page 3]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
165     * Added clarifying material about interleaved application data.
167    27-Jul-04 ekr@rtfm.com
168     * Premature closes no longer cause a session to be nonresumable.
169       Response to WG consensus.
171     * Added IANA considerations and registry for cipher suites
172       and ClientCertificateTypes
174    26-Jun-03 ekr@rtfm.com
175     * Incorporated Last Call comments from Franke Marcus, Jack Lloyd,
176     Brad Wetmore, and others.
178    22-Apr-03 ekr@rtfm.com
179     * coverage of the Vaudenay, Boneh-Brumley, and KPR attacks
180     * cleaned up IV text a bit.
181     * Added discussion of Denial of Service attacks.
183    11-Feb-02 ekr@rtfm.com
184     * Clarified the behavior of empty certificate lists [Nelson Bolyard]
185     * Added text explaining the security implications of authenticate
186       then encrypt.
187     * Cleaned up the explicit IV text.
188     * Added some more acknowledgement names
190    02-Nov-02 ekr@rtfm.com
191     * Changed this to be TLS 1.1.
192     * Added fixes for the Rogaway and Vaudenay CBC attacks
193     * Separated references into normative and informative
195    01-Mar-02 ekr@rtfm.com
196     * Tightened up the language in F.1.1.2 [Peter Watkins]
197     * Fixed smart quotes [Bodo Moeller]
198     * Changed handling of padding errors to prevent CBC-based attack
199       [Bodo Moeller]
200     * Fixed certificate_list spec in the appendix [Aman Sawrup]
201     * Fixed a bug in the V2 definitions [Aman Sawrup]
202     * Fixed S 7.2.1 to point out that you don't need a close notify
203       if you just sent some other fatal alert [Andreas Sterbenz]
204     * Marked alert 41 reserved [Andreas Sterbenz]
205     * Changed S 7.4.2 to point out that 512-bit keys cannot be used for
206       signing [Andreas Sterbenz]
207     * Added reserved client key types from SSLv3 [Andreas Sterbenz]
208     * Changed EXPORT40 to "40-bit EXPORT" in S 9 [Andreas Sterbenz]
209     * Removed RSA patent statement [Andreas Sterbenz]
210     * Removed references to BSAFE and RSAREF [Andreas Sterbenz]
212    14-Feb-02 ekr@rtfm.com
216 Dierks & Rescorla            Standards Track                     [Page 4]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
219     * Re-converted to I-D from RFC
220     * Made RSA/3DES the mandatory cipher suite.
221     * Added discussion of the EncryptedPMS encoding and PMS version number
222       issues to 7.4.7.1
223     * Removed the requirement in 7.4.1.3 that the Server random must be
224       different from the Client random, since these are randomly generated
225       and we don't expect servers to reject Server random values which
226       coincidentally are the same as the Client random.
227     * Replaced may/should/must with MAY/SHOULD/MUST where appropriate.
228       In many cases, shoulds became MUSTs, where I believed that was the
229       actual sense of the text. Added an RFC 2119 bulletin.
230    * Clarified the meaning of "empty certificate" message. [Peter Gutmann]
231    * Redid the CertificateRequest grammar to allow no distinguished names.
232      [Peter Gutmann]
233    * Removed the reference to requiring the master secret to generate
234      the CertificateVerify in F.1.1 [Bodo Moeller]
235    * Deprecated EXPORT40.
236    * Fixed a bunch of errors in the SSLv2 backward compatible client hello.
238 1. Introduction
240    The primary goal of the TLS Protocol is to provide privacy and data
241    integrity between two communicating applications. The protocol is
242    composed of two layers: the TLS Record Protocol and the TLS Handshake
243    Protocol. At the lowest level, layered on top of some reliable
244    transport protocol (e.g., TCP[TCP]), is the TLS Record Protocol. The
245    TLS Record Protocol provides connection security that has two basic
246    properties:
248      -  The connection is private. Symmetric cryptography is used for
249        data encryption (e.g., DES [DES], RC4 [RC4], etc.). The keys for
250        this symmetric encryption are generated uniquely for each
251        connection and are based on a secret negotiated by another
252        protocol (such as the TLS Handshake Protocol). The Record
253        Protocol can also be used without encryption.
255      -  The connection is reliable. Message transport includes a message
256        integrity check using a keyed MAC. Secure hash functions (e.g.,
257        SHA, MD5, etc.) are used for MAC computations. The Record
258        Protocol can operate without a MAC, but is generally only used in
259        this mode while another protocol is using the Record Protocol as
260        a transport for negotiating security parameters.
262    The TLS Record Protocol is used for encapsulation of various higher
263    level protocols. One such encapsulated protocol, the TLS Handshake
264    Protocol, allows the server and client to authenticate each other and
265    to negotiate an encryption algorithm and cryptographic keys before
266    the application protocol transmits or receives its first byte of
270 Dierks & Rescorla            Standards Track                     [Page 5]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
273    data. The TLS Handshake Protocol provides connection security that
274    has three basic properties:
276      -  The peer's identity can be authenticated using asymmetric, or
277        public key, cryptography (e.g., RSA [RSA], DSS [DSS], etc.). This
278        authentication can be made optional, but is generally required
279        for at least one of the peers.
281      -  The negotiation of a shared secret is secure: the negotiated
282        secret is unavailable to eavesdroppers, and for any authenticated
283        connection the secret cannot be obtained, even by an attacker who
284        can place himself in the middle of the connection.
286      -  The negotiation is reliable: no attacker can modify the
287        negotiation communication without being detected by the parties
288        to the communication.
290    One advantage of TLS is that it is application protocol independent.
291    Higher level protocols can layer on top of the TLS Protocol
292    transparently. The TLS standard, however, does not specify how
293    protocols add security with TLS; the decisions on how to initiate TLS
294    handshaking and how to interpret the authentication certificates
295    exchanged are left up to the judgment of the designers and
296    implementors of protocols which run on top of TLS.
298 1.1 Requirements Terminology
300    Keywords "MUST", "MUST NOT", "REQUIRED", "SHOULD", "SHOULD NOT" and
301    "MAY" that appear in this document are to be interpreted as described
302    in RFC 2119 [REQ].
304 2. Goals
306    The goals of TLS Protocol, in order of their priority, are:
308     1. Cryptographic security: TLS should be used to establish a secure
309        connection between two parties.
311     2. Interoperability: Independent programmers should be able to
312        develop applications utilizing TLS that will then be able to
313        successfully exchange cryptographic parameters without knowledge
314        of one another's code.
316     3. Extensibility: TLS seeks to provide a framework into which new
317        public key and bulk encryption methods can be incorporated as
318        necessary. This will also accomplish two sub-goals: to prevent
319        the need to create a new protocol (and risking the introduction
320        of possible new weaknesses) and to avoid the need to implement an
324 Dierks & Rescorla            Standards Track                     [Page 6]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
327        entire new security library.
329     4. Relative efficiency: Cryptographic operations tend to be highly
330        CPU intensive, particularly public key operations. For this
331        reason, the TLS protocol has incorporated an optional session
332        caching scheme to reduce the number of connections that need to
333        be established from scratch. Additionally, care has been taken to
334        reduce network activity.
336 3. Goals of this document
338    This document and the TLS protocol itself are based on the SSL 3.0
339    Protocol Specification as published by Netscape. The differences
340    between this protocol and SSL 3.0 are not dramatic, but they are
341    significant enough that TLS 1.1, TLS 1.0,  and SSL 3.0 do not
342    interoperate (although each protocol incorporates a mechanism by
343    which an implementation can back down prior versions. This document
344    is intended primarily for readers who will be implementing the
345    protocol and those doing cryptographic analysis of it. The
346    specification has been written with this in mind, and it is intended
347    to reflect the needs of those two groups. For that reason, many of
348    the algorithm-dependent data structures and rules are included in the
349    body of the text (as opposed to in an appendix), providing easier
350    access to them.
352    This document is not intended to supply any details of service
353    definition nor interface definition, although it does cover select
354    areas of policy as they are required for the maintenance of solid
355    security.
357 4. Presentation language
359    This document deals with the formatting of data in an external
360    representation. The following very basic and somewhat casually
361    defined presentation syntax will be used. The syntax draws from
362    several sources in its structure. Although it resembles the
363    programming language "C" in its syntax and XDR [XDR] in both its
364    syntax and intent, it would be risky to draw too many parallels. The
365    purpose of this presentation language is to document TLS only, not to
366    have general application beyond that particular goal.
378 Dierks & Rescorla            Standards Track                     [Page 7]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
381 4.1. Basic block size
383    The representation of all data items is explicitly specified. The
384    basic data block size is one byte (i.e. 8 bits). Multiple byte data
385    items are concatenations of bytes, from left to right, from top to
386    bottom. From the bytestream a multi-byte item (a numeric in the
387    example) is formed (using C notation) by:
389        value = (byte[0] << 8*(n-1)) | (byte[1] << 8*(n-2)) |
390                ... | byte[n-1];
392    This byte ordering for multi-byte values is the commonplace network
393    byte order or big endian format.
395 4.2. Miscellaneous
397    Comments begin with "/*" and end with "*/".
399    Optional components are denoted by enclosing them in "[[ ]]" double
400    brackets.
402    Single byte entities containing uninterpreted data are of type
403    opaque.
405 4.3. Vectors
407    A vector (single dimensioned array) is a stream of homogeneous data
408    elements. The size of the vector may be specified at documentation
409    time or left unspecified until runtime. In either case the length
410    declares the number of bytes, not the number of elements, in the
411    vector. The syntax for specifying a new type T' that is a fixed
412    length vector of type T is
414        T T'[n];
416    Here T' occupies n bytes in the data stream, where n is a multiple of
417    the size of T. The length of the vector is not included in the
418    encoded stream.
420    In the following example, Datum is defined to be three consecutive
421    bytes that the protocol does not interpret, while Data is three
422    consecutive Datum, consuming a total of nine bytes.
424        opaque Datum[3];      /* three uninterpreted bytes */
425        Datum Data[9];        /* 3 consecutive 3 byte vectors */
432 Dierks & Rescorla            Standards Track                     [Page 8]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
435    Variable length vectors are defined by specifying a subrange of legal
436    lengths, inclusively, using the notation <floor..ceiling>.  When
437    encoded, the actual length precedes the vector's contents in the byte
438    stream. The length will be in the form of a number consuming as many
439    bytes as required to hold the vector's specified maximum (ceiling)
440    length. A variable length vector with an actual length field of zero
441    is referred to as an empty vector.
443        T T'<floor..ceiling>;
445    In the following example, mandatory is a vector that must contain
446    between 300 and 400 bytes of type opaque. It can never be empty. The
447    actual length field consumes two bytes, a uint16, sufficient to
448    represent the value 400 (see Section 4.4). On the other hand, longer
449    can represent up to 800 bytes of data, or 400 uint16 elements, and it
450    may be empty. Its encoding will include a two byte actual length
451    field prepended to the vector. The length of an encoded vector must
452    be an even multiple of the length of a single element (for example, a
453    17 byte vector of uint16 would be illegal).
455        opaque mandatory<300..400>;
456              /* length field is 2 bytes, cannot be empty */
457        uint16 longer<0..800>;
458              /* zero to 400 16-bit unsigned integers */
460 4.4. Numbers
462    The basic numeric data type is an unsigned byte (uint8). All larger
463    numeric data types are formed from fixed length series of bytes
464    concatenated as described in Section 4.1 and are also unsigned. The
465    following numeric types are predefined.
467        uint8 uint16[2];
468        uint8 uint24[3];
469        uint8 uint32[4];
470        uint8 uint64[8];
472    All values, here and elsewhere in the specification, are stored in
473    "network" or "big-endian" order; the uint32 represented by the hex
474    bytes 01 02 03 04 is equivalent to the decimal value 16909060.
476 4.5. Enumerateds
478    An additional sparse data type is available called enum. A field of
479    type enum can only assume the values declared in the definition.
480    Each definition is a different type. Only enumerateds of the same
481    type may be assigned or compared. Every element of an enumerated must
486 Dierks & Rescorla            Standards Track                     [Page 9]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
489    be assigned a value, as demonstrated in the following example.  Since
490    the elements of the enumerated are not ordered, they can be assigned
491    any unique value, in any order.
493        enum { e1(v1), e2(v2), ... , en(vn) [[, (n)]] } Te;
495    Enumerateds occupy as much space in the byte stream as would its
496    maximal defined ordinal value. The following definition would cause
497    one byte to be used to carry fields of type Color.
499        enum { red(3), blue(5), white(7) } Color;
501    One may optionally specify a value without its associated tag to
502    force the width definition without defining a superfluous element.
503    In the following example, Taste will consume two bytes in the data
504    stream but can only assume the values 1, 2 or 4.
506        enum { sweet(1), sour(2), bitter(4), (32000) } Taste;
508    The names of the elements of an enumeration are scoped within the
509    defined type. In the first example, a fully qualified reference to
510    the second element of the enumeration would be Color.blue. Such
511    qualification is not required if the target of the assignment is well
512    specified.
514        Color color = Color.blue;     /* overspecified, legal */
515        Color color = blue;           /* correct, type implicit */
517    For enumerateds that are never converted to external representation,
518    the numerical information may be omitted.
520        enum { low, medium, high } Amount;
522 4.6. Constructed types
524    Structure types may be constructed from primitive types for
525    convenience. Each specification declares a new, unique type. The
526    syntax for definition is much like that of C.
528        struct {
529          T1 f1;
530          T2 f2;
531          ...
532          Tn fn;
533        } [[T]];
540 Dierks & Rescorla            Standards Track                    [Page 10]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
543    The fields within a structure may be qualified using the type's name
544    using a syntax much like that available for enumerateds. For example,
545    T.f2 refers to the second field of the previous declaration.
546    Structure definitions may be embedded.
548 4.6.1. Variants
550    Defined structures may have variants based on some knowledge that is
551    available within the environment. The selector must be an enumerated
552    type that defines the possible variants the structure defines. There
553    must be a case arm for every element of the enumeration declared in
554    the select. The body of the variant structure may be given a label
555    for reference. The mechanism by which the variant is selected at
556    runtime is not prescribed by the presentation language.
558        struct {
559            T1 f1;
560            T2 f2;
561            ....
562            Tn fn;
563            select (E) {
564                case e1: Te1;
565                case e2: Te2;
566                ....
567                case en: Ten;
568            } [[fv]];
569        } [[Tv]];
571    For example:
573        enum { apple, orange } VariantTag;
574        struct {
575            uint16 number;
576            opaque string<0..10>; /* variable length */
577        } V1;
578        struct {
579            uint32 number;
580            opaque string[10];    /* fixed length */
581        } V2;
582        struct {
583            select (VariantTag) { /* value of selector is implicit */
584                case apple: V1;   /* VariantBody, tag = apple */
585                case orange: V2;  /* VariantBody, tag = orange */
586            } variant_body;       /* optional label on variant */
587        } VariantRecord;
589    Variant structures may be qualified (narrowed) by specifying a value
590    for the selector prior to the type. For example, a
594 Dierks & Rescorla            Standards Track                    [Page 11]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
597        orange VariantRecord
599    is a narrowed type of a VariantRecord containing a variant_body of
600    type V2.
602 4.7. Cryptographic attributes
604    The four cryptographic operations digital signing, stream cipher
605    encryption, block cipher encryption, and public key encryption are
606    designated digitally-signed, stream-ciphered, block-ciphered, and
607    public-key-encrypted, respectively. A field's cryptographic
608    processing is specified by prepending an appropriate key word
609    designation before the field's type specification. Cryptographic keys
610    are implied by the current session state (see Section 6.1).
612    In digital signing, one-way hash functions are used as input for a
613    signing algorithm. A digitally-signed element is encoded as an opaque
614    vector <0..2^16-1>, where the length is specified by the signing
615    algorithm and key.
617    In RSA signing, a 36-byte structure of two hashes (one SHA and one
618    MD5) is signed (encrypted with the private key). It is encoded with
619    PKCS #1 block type 0 or type 1 as described in [PKCS1].
621    In DSS, the 20 bytes of the SHA hash are run directly through the
622    Digital Signing Algorithm with no additional hashing. This produces
623    two values, r and s. The DSS signature is an opaque vector, as above,
624    the contents of which are the DER encoding of:
626        Dss-Sig-Value  ::=  SEQUENCE  {
627             r       INTEGER,
628             s       INTEGER
629        }
631    In stream cipher encryption, the plaintext is exclusive-ORed with an
632    identical amount of output generated from a cryptographically-secure
633    keyed pseudorandom number generator.
635    In block cipher encryption, every block of plaintext encrypts to a
636    block of ciphertext. All block cipher encryption is done in CBC
637    (Cipher Block Chaining) mode, and all items which are block-ciphered
638    will be an exact multiple of the cipher block length.
640    In public key encryption, a public key algorithm is used to encrypt
641    data in such a way that it can be decrypted only with the matching
642    private key. A public-key-encrypted element is encoded as an opaque
643    vector <0..2^16-1>, where the length is specified by the signing
644    algorithm and key.
648 Dierks & Rescorla            Standards Track                    [Page 12]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
651    An RSA encrypted value is encoded with PKCS #1 block type 2 as
652    described in [PKCS1].
654    In the following example:
656        stream-ciphered struct {
657            uint8 field1;
658            uint8 field2;
659            digitally-signed opaque hash[20];
660        } UserType;
662    The contents of hash are used as input for the signing algorithm,
663    then the entire structure is encrypted with a stream cipher. The
664    length of this structure, in bytes would be equal to 2 bytes for
665    field1 and field2, plus two bytes for the length of the signature,
666    plus the length of the output of the signing algorithm. This is known
667    due to the fact that the algorithm and key used for the signing are
668    known prior to encoding or decoding this structure.
670 4.8. Constants
672    Typed constants can be defined for purposes of specification by
673    declaring a symbol of the desired type and assigning values to it.
674    Under-specified types (opaque, variable length vectors, and
675    structures that contain opaque) cannot be assigned values. No fields
676    of a multi-element structure or vector may be elided.
678    For example,
680        struct {
681            uint8 f1;
682            uint8 f2;
683        } Example1;
685        Example1 ex1 = {1, 4};  /* assigns f1 = 1, f2 = 4 */
687 5. HMAC and the pseudorandom function
689    A number of operations in the TLS record and handshake layer required
690    a keyed MAC; this is a secure digest of some data protected by a
691    secret. Forging the MAC is infeasible without knowledge of the MAC
692    secret. The construction we use for this operation is known as HMAC,
693    described in [HMAC].
695    HMAC can be used with a variety of different hash algorithms. TLS
696    uses it in the handshake with two different algorithms: MD5 and
697    SHA-1, denoting these as HMAC_MD5(secret, data) and HMAC_SHA(secret,
702 Dierks & Rescorla            Standards Track                    [Page 13]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
705    data). Additional hash algorithms can be defined by cipher suites and
706    used to protect record data, but MD5 and SHA-1 are hard coded into
707    the description of the handshaking for this version of the protocol.
709    In addition, a construction is required to do expansion of secrets
710    into blocks of data for the purposes of key generation or validation.
711    This pseudo-random function (PRF) takes as input a secret, a seed,
712    and an identifying label and produces an output of arbitrary length.
714    In order to make the PRF as secure as possible, it uses two hash
715    algorithms in a way which should guarantee its security if either
716    algorithm remains secure.
718    First, we define a data expansion function, P_hash(secret, data)
719    which uses a single hash function to expand a secret and seed into an
720    arbitrary quantity of output:
722        P_hash(secret, seed) = HMAC_hash(secret, A(1) + seed) +
723                               HMAC_hash(secret, A(2) + seed) +
724                               HMAC_hash(secret, A(3) + seed) + ...
726    Where + indicates concatenation.
728    A() is defined as:
729        A(0) = seed
730        A(i) = HMAC_hash(secret, A(i-1))
732    P_hash can be iterated as many times as is necessary to produce the
733    required quantity of data. For example, if P_SHA-1 was being used to
734    create 64 bytes of data, it would have to be iterated 4 times
735    (through A(4)), creating 80 bytes of output data; the last 16 bytes
736    of the final iteration would then be discarded, leaving 64 bytes of
737    output data.
739    TLS's PRF is created by splitting the secret into two halves and
740    using one half to generate data with P_MD5 and the other half to
741    generate data with P_SHA-1, then exclusive-or'ing the outputs of
742    these two expansion functions together.
744    S1 and S2 are the two halves of the secret and each is the same
745    length. S1 is taken from the first half of the secret, S2 from the
746    second half. Their length is created by rounding up the length of the
747    overall secret divided by two; thus, if the original secret is an odd
748    number of bytes long, the last byte of S1 will be the same as the
749    first byte of S2.
751        L_S = length in bytes of secret;
752        L_S1 = L_S2 = ceil(L_S / 2);
756 Dierks & Rescorla            Standards Track                    [Page 14]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
759    The secret is partitioned into two halves (with the possibility of
760    one shared byte) as described above, S1 taking the first L_S1 bytes
761    and S2 the last L_S2 bytes.
763    The PRF is then defined as the result of mixing the two pseudorandom
764    streams by exclusive-or'ing them together.
766        PRF(secret, label, seed) = P_MD5(S1, label + seed) XOR
767                                   P_SHA-1(S2, label + seed);
769    The label is an ASCII string. It should be included in the exact form
770    it is given without a length byte or trailing null character.  For
771    example, the label "slithy toves" would be processed by hashing the
772    following bytes:
774        73 6C 69 74 68 79 20 74 6F 76 65 73
776    Note that because MD5 produces 16 byte outputs and SHA-1 produces 20
777    byte outputs, the boundaries of their internal iterations will not be
778    aligned; to generate a 80 byte output will involve P_MD5 being
779    iterated through A(5), while P_SHA-1 will only iterate through A(4).
781 6. The TLS Record Protocol
783    The TLS Record Protocol is a layered protocol. At each layer,
784    messages may include fields for length, description, and content.
785    The Record Protocol takes messages to be transmitted, fragments the
786    data into manageable blocks, optionally compresses the data, applies
787    a MAC, encrypts, and transmits the result. Received data is
788    decrypted, verified, decompressed, and reassembled, then delivered to
789    higher level clients.
791    Four record protocol clients are described in this document: the
792    handshake protocol, the alert protocol, the change cipher spec
793    protocol, and the application data protocol. In order to allow
794    extension of the TLS protocol, additional record types can be
795    supported by the record protocol. Any new record types SHOULD
796    allocate type values immediately beyond the ContentType values for
797    the four record types described here (see Appendix A.1). All such
798    values must be defined by RFC 2434 Standards Action.  Section 11 for
799    IANA Considerations for ContentType values.
801    If a TLS implementation receives a record type it does not
802    understand, it SHOULD just ignore it. Any protocol designed for use
803    over TLS MUST be carefully designed to deal with all possible attacks
804    against it.  Note that because the type and length of a record are
805    not protected by encryption, care SHOULD be taken to minimize the
806    value of traffic analysis of these values.
810 Dierks & Rescorla            Standards Track                    [Page 15]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
813 6.1. Connection states
815    A TLS connection state is the operating environment of the TLS Record
816    Protocol. It specifies a compression algorithm, encryption algorithm,
817    and MAC algorithm. In addition, the parameters for these algorithms
818    are known: the MAC secret and the bulk encryption keys for the
819    connection in both the read and the write directions. Logically,
820    there are always four connection states outstanding: the current read
821    and write states, and the pending read and write states. All records
822    are processed under the current read and write states. The security
823    parameters for the pending states can be set by the TLS Handshake
824    Protocol, and the Change Cipher Spec can selectively make either of
825    the pending states current, in which case the appropriate current
826    state is disposed of and replaced with the pending state; the pending
827    state is then reinitialized to an empty state. It is illegal to make
828    a state which has not been initialized with security parameters a
829    current state. The initial current state always specifies that no
830    encryption, compression, or MAC will be used.
832    The security parameters for a TLS Connection read and write state are
833    set by providing the following values:
835    connection end
836        Whether this entity is considered the "client" or the "server" in
837        this connection.
839    bulk encryption algorithm
840        An algorithm to be used for bulk encryption. This specification
841        includes the key size of this algorithm, how much of that key is
842        secret, whether it is a block or stream cipher, the block size of
843        the cipher (if appropriate).
845    MAC algorithm
846        An algorithm to be used for message authentication. This
847        specification includes the size of the hash which is returned by
848        the MAC algorithm.
850    compression algorithm
851        An algorithm to be used for data compression. This specification
852        must include all information the algorithm requires to do
853        compression.
855    master secret
856        A 48 byte secret shared between the two peers in the connection.
858    client random
859        A 32 byte value provided by the client.
864 Dierks & Rescorla            Standards Track                    [Page 16]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
867    server random
868        A 32 byte value provided by the server.
870    These parameters are defined in the presentation language as:
872        enum { server, client } ConnectionEnd;
874        enum { null, rc4, rc2, des, 3des, des40 } BulkCipherAlgorithm;
876        enum { stream, block } CipherType;
878        enum { null, md5, sha } MACAlgorithm;
880        enum { null(0), (255) } CompressionMethod;
882        /* The algorithms specified in CompressionMethod,
883           BulkCipherAlgorithm, and MACAlgorithm may be added to. */
885        struct {
886            ConnectionEnd          entity;
887            BulkCipherAlgorithm    bulk_cipher_algorithm;
888            CipherType             cipher_type;
889            uint8                  key_size;
890            uint8                  key_material_length;
891            MACAlgorithm           mac_algorithm;
892            uint8                  hash_size;
893            CompressionMethod      compression_algorithm;
894            opaque                 master_secret[48];
895            opaque                 client_random[32];
896            opaque                 server_random[32];
897        } SecurityParameters;
899    The record layer will use the security parameters to generate the
900    following four items:
902        client write MAC secret
903        server write MAC secret
904        client write key
905        server write key
907    The client write parameters are used by the server when receiving and
908    processing records and vice-versa. The algorithm used for generating
909    these items from the security parameters is described in section 6.3.
911    Once the security parameters have been set and the keys have been
912    generated, the connection states can be instantiated by making them
913    the current states. These current states MUST be updated for each
914    record processed. Each connection state includes the following
918 Dierks & Rescorla            Standards Track                    [Page 17]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
921    elements:
923    compression state
924        The current state of the compression algorithm.
926    cipher state
927        The current state of the encryption algorithm. This will consist
928        of the scheduled key for that connection. For stream ciphers,
929        this will also contain whatever the necessary state information
930        is to allow the stream to continue to encrypt or decrypt data.
932    MAC secret
933        The MAC secret for this connection as generated above.
935    sequence number
936        Each connection state contains a sequence number, which is
937        maintained separately for read and write states. The sequence
938        number MUST be set to zero whenever a connection state is made
939        the active state. Sequence numbers are of type uint64 and may not
940        exceed 2^64-1. Sequence numbers do not wrap. If a TLS
941        implementation would need to wrap a sequence number it must
942        renegotiate instead. A sequence number is incremented after each
943        record: specifically, the first record which is transmitted under
944        a particular connection state MUST use sequence number 0.
946 6.2. Record layer
948    The TLS Record Layer receives uninterpreted data from higher layers
949    in non-empty blocks of arbitrary size.
951 6.2.1. Fragmentation
953    The record layer fragments information blocks into TLSPlaintext
954    records carrying data in chunks of 2^14 bytes or less. Client message
955    boundaries are not preserved in the record layer (i.e., multiple
956    client messages of the same ContentType MAY be coalesced into a
957    single TLSPlaintext record, or a single message MAY be fragmented
958    across several records).
961        struct {
962            uint8 major, minor;
963        } ProtocolVersion;
965        enum {
966            change_cipher_spec(20), alert(21), handshake(22),
967            application_data(23), (255)
968        } ContentType;
972 Dierks & Rescorla            Standards Track                    [Page 18]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
975        struct {
976            ContentType type;
977            ProtocolVersion version;
978            uint16 length;
979            opaque fragment[TLSPlaintext.length];
980        } TLSPlaintext;
982    type
983        The higher level protocol used to process the enclosed fragment.
985    version
986        The version of the protocol being employed. This document
987        describes TLS Version 1.1, which uses the version { 3, 2 }. The
988        version value 3.2 is historical: TLS version 1.1 is a minor
989        modification to the TLS 1.0 protocol, which was itself a minor
990        modification to the SSL 3.0 protocol, which bears the version
991        value 3.0. (See Appendix A.1).
993    length
994        The length (in bytes) of the following TLSPlaintext.fragment.
995        The length should not exceed 2^14.
997    fragment
998        The application data. This data is transparent and treated as an
999        independent block to be dealt with by the higher level protocol
1000        specified by the type field.
1002  Note: Data of different TLS Record layer content types MAY be
1003        interleaved. Application data is generally of higher precedence
1004        for transmission than other content types and therefore handshake
1005        records may be held if application data is pending.  However,
1006        records MUST be delivered to the network in the same order as
1007        they are protected by the record layer. Recipients MUST receive
1008        and process interleaved application layer traffic during
1009        handshakes subsequent to the first one on a connection.
1011 6.2.2. Record compression and decompression
1013    All records are compressed using the compression algorithm defined in
1014    the current session state. There is always an active compression
1015    algorithm; however, initially it is defined as
1016    CompressionMethod.null. The compression algorithm translates a
1017    TLSPlaintext structure into a TLSCompressed structure. Compression
1018    functions are initialized with default state information whenever a
1019    connection state is made active.
1026 Dierks & Rescorla            Standards Track                    [Page 19]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
1029    Compression must be lossless and may not increase the content length
1030    by more than 1024 bytes. If the decompression function encounters a
1031    TLSCompressed.fragment that would decompress to a length in excess of
1032    2^14 bytes, it should report a fatal decompression failure error.
1034        struct {
1035            ContentType type;       /* same as TLSPlaintext.type */
1036            ProtocolVersion version;/* same as TLSPlaintext.version */
1037            uint16 length;
1038            opaque fragment[TLSCompressed.length];
1039        } TLSCompressed;
1041    length
1042        The length (in bytes) of the following TLSCompressed.fragment.
1043        The length should not exceed 2^14 + 1024.
1045    fragment
1046        The compressed form of TLSPlaintext.fragment.
1048  Note: A CompressionMethod.null operation is an identity operation; no
1049        fields are altered.
1051    Implementation note:
1052        Decompression functions are responsible for ensuring that
1053        messages cannot cause internal buffer overflows.
1055 6.2.3. Record payload protection
1057    The encryption and MAC functions translate a TLSCompressed structure
1058    into a TLSCiphertext. The decryption functions reverse the process.
1059    The MAC of the record also includes a sequence number so that
1060    missing, extra or repeated messages are detectable.
1062        struct {
1063            ContentType type;
1064            ProtocolVersion version;
1065            uint16 length;
1066            select (CipherSpec.cipher_type) {
1067                case stream: GenericStreamCipher;
1068                case block: GenericBlockCipher;
1069            } fragment;
1070        } TLSCiphertext;
1072    type
1073        The type field is identical to TLSCompressed.type.
1075    version
1076        The version field is identical to TLSCompressed.version.
1080 Dierks & Rescorla            Standards Track                    [Page 20]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
1083    length
1084        The length (in bytes) of the following TLSCiphertext.fragment.
1085        The length may not exceed 2^14 + 2048.
1087    fragment
1088        The encrypted form of TLSCompressed.fragment, with the MAC.
1090 6.2.3.1. Null or standard stream cipher
1092    Stream ciphers (including BulkCipherAlgorithm.null - see Appendix
1093    A.6) convert TLSCompressed.fragment structures to and from stream
1094    TLSCiphertext.fragment structures.
1096        stream-ciphered struct {
1097            opaque content[TLSCompressed.length];
1098            opaque MAC[CipherSpec.hash_size];
1099        } GenericStreamCipher;
1101    The MAC is generated as:
1103        HMAC_hash(MAC_write_secret, seq_num + TLSCompressed.type +
1104                      TLSCompressed.version + TLSCompressed.length +
1105                      TLSCompressed.fragment));
1107    where "+" denotes concatenation.
1109    seq_num
1110        The sequence number for this record.
1112    hash
1113        The hashing algorithm specified by
1114        SecurityParameters.mac_algorithm.
1116    Note that the MAC is computed before encryption. The stream cipher
1117    encrypts the entire block, including the MAC. For stream ciphers that
1118    do not use a synchronization vector (such as RC4), the stream cipher
1119    state from the end of one record is simply used on the subsequent
1120    packet. If the CipherSuite is TLS_NULL_WITH_NULL_NULL, encryption
1121    consists of the identity operation (i.e., the data is not encrypted
1122    and the MAC size is zero implying that no MAC is used).
1123    TLSCiphertext.length is TLSCompressed.length plus
1124    CipherSpec.hash_size.
1126 6.2.3.2. CBC block cipher
1128    For block ciphers (such as RC2 or DES), the encryption and MAC
1129    functions convert TLSCompressed.fragment structures to and from block
1130    TLSCiphertext.fragment structures.
1134 Dierks & Rescorla            Standards Track                    [Page 21]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
1137        block-ciphered struct {
1138            opaque IV[CipherSpec.block_length];
1139            opaque content[TLSCompressed.length];
1140            opaque MAC[CipherSpec.hash_size];
1141            uint8 padding[GenericBlockCipher.padding_length];
1142            uint8 padding_length;
1143        } GenericBlockCipher;
1145    The MAC is generated as described in Section 6.2.3.1.
1147    IV
1148        Unlike previous versions of SSL and TLS, TLS 1.1 uses an explicit
1149        IV in order to prevent the attacks described by [CBCATT].
1150        We recommend the following equivalently strong procedures.
1151        For clarity we use the following notation.
1153        IV -- the transmitted value of the IV field in the
1154            GenericBlockCipher structure.
1155        CBC residue -- the last ciphertext block of the previous record
1156        mask -- the actual value which the cipher XORs with the
1157            plaintext prior to encryption of the first cipher block
1158            of the record.
1160        In prior versions of TLS, there was no IV field and the CBC residue
1161        and mask were one and the same. See Sections 6.1, 6.2.3.2 and 6.3,
1162        of [TLS1.0] for details of TLS 1.0 IV handling.
1164        One of the following two algorithms SHOULD be used to generate the
1165        per-record IV:
1167        (1) Generate a cryptographically strong random string R of
1168            length CipherSpec.block_length. Place R
1169            in the IV field. Set the mask to R. Thus, the first
1170            cipher block will be encrypted as E(R XOR Data).
1172        (2) Generate a cryptographically strong random number R of
1173            length CipherSpec.block_length and prepend it to the plaintext
1174            prior to encryption. In
1175            this case either:
1177            (a)   The cipher may use a fixed mask such as zero.
1178            (b) The CBC residue from the previous record may be used
1179                as the mask. This preserves maximum code compatibility
1180             with TLS 1.0 and SSL 3. It also has the advantage that
1181             it does not require the ability to quickly reset the IV,
1182             which is known to be a   problem on some systems.
1184             In either case, the data (R || data) is fed into the
1188 Dierks & Rescorla            Standards Track                    [Page 22]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
1191             encryption process. The first cipher block (containing
1192             E(mask XOR R) is placed in the IV field. The first
1193             block of content contains E(IV XOR data)
1195        The following alternative procedure MAY be used: However, it has
1196        not been demonstrated to be equivalently cryptographically strong
1197        to the above procedures. The sender prepends a fixed block F to
1198        the plaintext (or alternatively a block generated with a weak
1199        PRNG). He then encrypts as in (2) above, using the CBC residue
1200        from the previous block as the mask for the prepended block. Note
1201        that in this case the mask for the first record transmitted by
1202        the application (the Finished) MUST be generated using a
1203        cryptographically strong PRNG.
1205        The decryption operation for all three alternatives is the same.
1206        The receiver decrypts the entire GenericBlockCipher structure and
1207        then discards the first cipher block, corresponding to the IV
1208        component.
1210    padding
1211        Padding that is added to force the length of the plaintext to be
1212        an integral multiple of the block cipher's block length. The
1213        padding MAY be any length up to 255 bytes long, as long as it
1214        results in the TLSCiphertext.length being an integral multiple of
1215        the block length. Lengths longer than necessary might be
1216        desirable to frustrate attacks on a protocol based on analysis of
1217        the lengths of exchanged messages. Each uint8 in the padding data
1218        vector MUST be filled with the padding length value. The receiver
1219        MUST check this padding and SHOULD use the bad_record_mac alert
1220        to indicate padding errors.
1222    padding_length
1223        The padding length MUST be such that the total size of the
1224        GenericBlockCipher structure is a multiple of the cipher's block
1225        length. Legal values range from zero to 255, inclusive. This
1226        length specifies the length of the padding field exclusive of the
1227        padding_length field itself.
1229    The encrypted data length (TLSCiphertext.length) is one more than the
1230    sum of TLSCompressed.length, CipherSpec.hash_size, and
1231    padding_length.
1233  Example: If the block length is 8 bytes, the content length
1234           (TLSCompressed.length) is 61 bytes, and the MAC length is 20
1235           bytes, the length before padding is 82 bytes (this does not
1236           include the IV, which may or may not be encrypted, as
1237           discussed above). Thus, the padding length modulo 8 must be
1238           equal to 6 in order to make the total length an even multiple
1242 Dierks & Rescorla            Standards Track                    [Page 23]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
1245           of 8 bytes (the block length). The padding length can be 6,
1246           14, 22, and so on, through 254. If the padding length were the
1247           minimum necessary, 6, the padding would be 6 bytes, each
1248           containing the value 6.  Thus, the last 8 octets of the
1249           GenericBlockCipher before block encryption would be xx 06 06
1250           06 06 06 06 06, where xx is the last octet of the MAC.
1252  Note: With block ciphers in CBC mode (Cipher Block Chaining),
1253        it is critical that the entire plaintext of the record be known
1254        before any ciphertext is transmitted. Otherwise it is possible
1255        for the attacker to mount the attack described in [CBCATT].
1257  Implementation Note: Canvel et. al. [CBCTIME] have demonstrated a
1258        timing attack on CBC padding based on the time required to
1259        compute the MAC. In order to defend against this attack,
1260        implementations MUST ensure that record processing time is
1261        essentially the same whether or not the padding is correct.  In
1262        general, the best way to to do this is to compute the MAC even if
1263        the padding is incorrect, and only then reject the packet. For
1264        instance, if the pad appears to be incorrect the implementation
1265        might assume a zero-length pad and then compute the MAC. This
1266        leaves a small timing channel, since MAC performance depends to
1267        some extent on the size of the data fragment, but it is not
1268        believed to be large enough to be exploitable due to the large
1269        block size of existing MACs and the small size of the timing
1270        signal.
1272 6.3. Key calculation
1274    The Record Protocol requires an algorithm to generate keys, and MAC
1275    secrets from the security parameters provided by the handshake
1276    protocol.
1278    The master secret is hashed into a sequence of secure bytes, which
1279    are assigned to the MAC secrets and keys required by the current
1280    connection state (see Appendix A.6). CipherSpecs require a client
1281    write MAC secret, a server write MAC secret, a client write key, and
1282    a server write key, which are generated from the master secret in
1283    that order. Unused values are empty.
1285    When generating keys and MAC secrets, the master secret is used as an
1286    entropy source.
1288    To generate the key material, compute
1290        key_block = PRF(SecurityParameters.master_secret,
1291                           "key expansion",
1292                           SecurityParameters.server_random +
1296 Dierks & Rescorla            Standards Track                    [Page 24]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
1299                           SecurityParameters.client_random);
1301    until enough output has been generated. Then the key_block is
1302    partitioned as follows:
1304        client_write_MAC_secret[SecurityParameters.hash_size]
1305        server_write_MAC_secret[SecurityParameters.hash_size]
1306        client_write_key[SecurityParameters.key_material_length]
1307        server_write_key[SecurityParameters.key_material_length]
1310    Implementation note:
1311        The currently defined which requires the most material is
1312        AES_256_CBC_SHA, defined in [TLSAES]. It requires 2 x 32 byte
1313        keys and 2 x 20 byte MAC secrets, for a total 104 bytes of key
1314        material.
1316 7. The TLS Handshaking Protocols
1318        TLS has three subprotocols which are used to allow peers to agree
1319        upon security parameters for the record layer, authenticate
1320        themselves, instantiate negotiated security parameters, and
1321        report error conditions to each other.
1323        The Handshake Protocol is responsible for negotiating a session,
1324        which consists of the following items:
1326        session identifier
1327        An arbitrary byte sequence chosen by the server to identify an
1328        active or resumable session state.
1330    peer certificate
1331        X509v3 [X509] certificate of the peer. This element of the state
1332        may be null.
1334    compression method
1335        The algorithm used to compress data prior to encryption.
1337    cipher spec
1338        Specifies the bulk data encryption algorithm (such as null, DES,
1339        etc.) and a MAC algorithm (such as MD5 or SHA). It also defines
1340        cryptographic attributes such as the hash_size. (See Appendix A.6
1341        for formal definition)
1343    master secret
1344        48-byte secret shared between the client and server.
1346    is resumable
1350 Dierks & Rescorla            Standards Track                    [Page 25]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
1353        A flag indicating whether the session can be used to initiate new
1354        connections.
1356    These items are then used to create security parameters for use by
1357    the Record Layer when protecting application data. Many connections
1358    can be instantiated using the same session through the resumption
1359    feature of the TLS Handshake Protocol.
1361 7.1. Change cipher spec protocol
1363    The change cipher spec protocol exists to signal transitions in
1364    ciphering strategies. The protocol consists of a single message,
1365    which is encrypted and compressed under the current (not the pending)
1366    connection state. The message consists of a single byte of value 1.
1368        struct {
1369            enum { change_cipher_spec(1), (255) } type;
1370        } ChangeCipherSpec;
1372    The change cipher spec message is sent by both the client and server
1373    to notify the receiving party that subsequent records will be
1374    protected under the newly negotiated CipherSpec and keys. Reception
1375    of this message causes the receiver to instruct the Record Layer to
1376    immediately copy the read pending state into the read current state.
1377    Immediately after sending this message, the sender MUST instruct the
1378    record layer to make the write pending state the write active state.
1379    (See section 6.1.) The change cipher spec message is sent during the
1380    handshake after the security parameters have been agreed upon, but
1381    before the verifying finished message is sent (see section 7.4.9).
1383  Note: if a rehandshake occurs while data is flowing on a connection,
1384    the communicating parties may continue to send data using the old
1385    CipherSpec However, once the ChangeCipherSpec has been sent, the new
1386    CipherSpec MUST be used. The first side to send the ChangeCipherSpec
1387    does not know that the other side has finished computing the new
1388    keying material (e.g. if it has to perform a time consuming public
1389    key operation). Thus, a small window of time during which the
1390    recipient must buffer the data MAY exist. In practice, with modern
1391    machines this interval is likely to be fairly short.
1393 7.2. Alert protocol
1395    One of the content types supported by the TLS Record layer is the
1396    alert type. Alert messages convey the severity of the message and a
1397    description of the alert. Alert messages with a level of fatal result
1398    in the immediate termination of the connection. In this case, other
1399    connections corresponding to the session may continue, but the
1400    session identifier MUST be invalidated, preventing the failed session
1404 Dierks & Rescorla            Standards Track                    [Page 26]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
1407    from being used to establish new connections. Like other messages,
1408    alert messages are encrypted and compressed, as specified by the
1409    current connection state.
1411        enum { warning(1), fatal(2), (255) } AlertLevel;
1413        enum {
1414            close_notify(0),
1415            unexpected_message(10),
1416            bad_record_mac(20),
1417            decryption_failed(21),
1418            record_overflow(22),
1419            decompression_failure(30),
1420            handshake_failure(40),
1421            no_certificate_RESERVED (41),
1422            bad_certificate(42),
1423            unsupported_certificate(43),
1424            certificate_revoked(44),
1425            certificate_expired(45),
1426            certificate_unknown(46),
1427            illegal_parameter(47),
1428            unknown_ca(48),
1429            access_denied(49),
1430            decode_error(50),
1431            decrypt_error(51),
1432            export_restriction_RESERVED(60),
1433            protocol_version(70),
1434            insufficient_security(71),
1435            internal_error(80),
1436            user_canceled(90),
1437            no_renegotiation(100),
1438            (255)
1439        } AlertDescription;
1441        struct {
1442            AlertLevel level;
1443            AlertDescription description;
1444        } Alert;
1446 7.2.1. Closure alerts
1448    The client and the server must share knowledge that the connection is
1449    ending in order to avoid a truncation attack. Either party may
1450    initiate the exchange of closing messages.
1452    close_notify
1453        This message notifies the recipient that the sender will not send
1454        any more messages on this connection. Note that as of TLS 1.1,
1458 Dierks & Rescorla            Standards Track                    [Page 27]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
1461        failure to properly close a connection no longer requires that a
1462        session not be resumed. This is a change from TLS 1.0 to conform
1463        with widespread implementation practice.
1465    Either party may initiate a close by sending a close_notify alert.
1466    Any data received after a closure alert is ignored.
1468    Unless some other fatal alert has been transmitted, each party is
1469    required to send a close_notify alert before closing the write side
1470    of the connection. The other party MUST respond with a close_notify
1471    alert of its own and close down the connection immediately,
1472    discarding any pending writes. It is not required for the initiator
1473    of the close to wait for the responding close_notify alert before
1474    closing the read side of the connection.
1476    If the application protocol using TLS provides that any data may be
1477    carried over the underlying transport after the TLS connection is
1478    closed, the TLS implementation must receive the responding
1479    close_notify alert before indicating to the application layer that
1480    the TLS connection has ended. If the application protocol will not
1481    transfer any additional data, but will only close the underlying
1482    transport connection, then the implementation MAY choose to close the
1483    transport without waiting for the responding close_notify. No part of
1484    this standard should be taken to dictate the manner in which a usage
1485    profile for TLS manages its data transport, including when
1486    connections are opened or closed.
1488    NB: It is assumed that closing a connection reliably delivers
1489        pending data before destroying the transport.
1491 7.2.2. Error alerts
1493    Error handling in the TLS Handshake protocol is very simple. When an
1494    error is detected, the detecting party sends a message to the other
1495    party. Upon transmission or receipt of an fatal alert message, both
1496    parties immediately close the connection. Servers and clients MUST
1497    forget any session-identifiers, keys, and secrets associated with a
1498    failed connection. Thus, any connection terminated with a fatal alert
1499    MUST NOT be resumed. The following error alerts are defined:
1501    unexpected_message
1502        An inappropriate message was received. This alert is always fatal
1503        and should never be observed in communication between proper
1504        implementations.
1506    bad_record_mac
1507        This alert is returned if a record is received with an incorrect
1508        MAC. This alert also MUST be returned if an alert is sent because
1512 Dierks & Rescorla            Standards Track                    [Page 28]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
1515        a TLSCiphertext decrypted in an invalid way: either it wasn't an
1516        even multiple of the block length, or its padding values, when
1517        checked, weren't correct. This message is always fatal.
1519    decryption_failed
1520        This alert MAY be returned if a TLSCiphertext decrypted in an
1521        invalid way: either it wasn't an even multiple of the block
1522        length, or its padding values, when checked, weren't correct.
1523        This message is always fatal.
1525        NB: Differentiating between bad_record_mac and decryption_failed
1526        alerts may permit certain attacks against CBC mode as used in TLS
1527        [CBCATT]. It is preferable to uniformly use the bad_record_mac
1528        alert to hide the specific type of the error.
1531    record_overflow
1532        A TLSCiphertext record was received which had a length more than
1533        2^14+2048 bytes, or a record decrypted to a TLSCompressed record
1534        with more than 2^14+1024 bytes. This message is always fatal.
1536    decompression_failure
1537        The decompression function received improper input (e.g. data
1538        that would expand to excessive length). This message is always
1539        fatal.
1541    handshake_failure
1542        Reception of a handshake_failure alert message indicates that the
1543        sender was unable to negotiate an acceptable set of security
1544        parameters given the options available. This is a fatal error.
1546    no_certificate_RESERVED
1547        This alert was used in SSLv3 but not in TLS. It should not be
1548        sent by compliant implementations.
1550    bad_certificate
1551        A certificate was corrupt, contained signatures that did not
1552        verify correctly, etc.
1554    unsupported_certificate
1555        A certificate was of an unsupported type.
1557    certificate_revoked
1558        A certificate was revoked by its signer.
1560    certificate_expired
1561        A certificate has expired or is not currently valid.
1566 Dierks & Rescorla            Standards Track                    [Page 29]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
1569    certificate_unknown
1570        Some other (unspecified) issue arose in processing the
1571        certificate, rendering it unacceptable.
1573    illegal_parameter
1574        A field in the handshake was out of range or inconsistent with
1575        other fields. This is always fatal.
1577    unknown_ca
1578        A valid certificate chain or partial chain was received, but the
1579        certificate was not accepted because the CA certificate could not
1580        be located or couldn't be matched with a known, trusted CA.  This
1581        message is always fatal.
1583    access_denied
1584        A valid certificate was received, but when access control was
1585        applied, the sender decided not to proceed with negotiation.
1586        This message is always fatal.
1588    decode_error
1589        A message could not be decoded because some field was out of the
1590        specified range or the length of the message was incorrect. This
1591        message is always fatal.
1593    decrypt_error
1594        A handshake cryptographic operation failed, including being
1595        unable to correctly verify a signature, decrypt a key exchange,
1596        or validate a finished message.
1598    export_restriction_RESERVED
1599        This alert was used in TLS 1.0 but not TLS 1.1.
1601    protocol_version
1602        The protocol version the client has attempted to negotiate is
1603        recognized, but not supported. (For example, old protocol
1604        versions might be avoided for security reasons). This message is
1605        always fatal.
1607    insufficient_security
1608        Returned instead of handshake_failure when a negotiation has
1609        failed specifically because the server requires ciphers more
1610        secure than those supported by the client. This message is always
1611        fatal.
1613    internal_error
1614        An internal error unrelated to the peer or the correctness of the
1615        protocol makes it impossible to continue (such as a memory
1616        allocation failure). This message is always fatal.
1620 Dierks & Rescorla            Standards Track                    [Page 30]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
1623    user_canceled
1624        This handshake is being canceled for some reason unrelated to a
1625        protocol failure. If the user cancels an operation after the
1626        handshake is complete, just closing the connection by sending a
1627        close_notify is more appropriate. This alert should be followed
1628        by a close_notify. This message is generally a warning.
1630    no_renegotiation
1631        Sent by the client in response to a hello request or by the
1632        server in response to a client hello after initial handshaking.
1633        Either of these would normally lead to renegotiation; when that
1634        is not appropriate, the recipient should respond with this alert;
1635        at that point, the original requester can decide whether to
1636        proceed with the connection. One case where this would be
1637        appropriate would be where a server has spawned a process to
1638        satisfy a request; the process might receive security parameters
1639        (key length, authentication, etc.) at startup and it might be
1640        difficult to communicate changes to these parameters after that
1641        point. This message is always a warning.
1643    For all errors where an alert level is not explicitly specified, the
1644    sending party MAY determine at its discretion whether this is a fatal
1645    error or not; if an alert with a level of warning is received, the
1646    receiving party MAY decide at its discretion whether to treat this as
1647    a fatal error or not. However, all messages which are transmitted
1648    with a level of fatal MUST be treated as fatal messages.
1650    New alerts values MUST be defined by RFC 2434 Standards Action. See
1651    Section 11 for IANA Considerations for alert values.
1653 7.3. Handshake Protocol overview
1655    The cryptographic parameters of the session state are produced by the
1656    TLS Handshake Protocol, which operates on top of the TLS Record
1657    Layer. When a TLS client and server first start communicating, they
1658    agree on a protocol version, select cryptographic algorithms,
1659    optionally authenticate each other, and use public-key encryption
1660    techniques to generate shared secrets.
1662    The TLS Handshake Protocol involves the following steps:
1664      -  Exchange hello messages to agree on algorithms, exchange random
1665        values, and check for session resumption.
1667      -  Exchange the necessary cryptographic parameters to allow the
1668        client and server to agree on a premaster secret.
1670      -  Exchange certificates and cryptographic information to allow the
1674 Dierks & Rescorla            Standards Track                    [Page 31]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
1677        client and server to authenticate themselves.
1679      -  Generate a master secret from the premaster secret and exchanged
1680        random values.
1682      -  Provide security parameters to the record layer.
1684      -  Allow the client and server to verify that their peer has
1685        calculated the same security parameters and that the handshake
1686        occurred without tampering by an attacker.
1688    Note that higher layers should not be overly reliant on TLS always
1689    negotiating the strongest possible connection between two peers:
1690    there are a number of ways a man in the middle attacker can attempt
1691    to make two entities drop down to the least secure method they
1692    support. The protocol has been designed to minimize this risk, but
1693    there are still attacks available: for example, an attacker could
1694    block access to the port a secure service runs on, or attempt to get
1695    the peers to negotiate an unauthenticated connection. The fundamental
1696    rule is that higher levels must be cognizant of what their security
1697    requirements are and never transmit information over a channel less
1698    secure than what they require. The TLS protocol is secure, in that
1699    any cipher suite offers its promised level of security: if you
1700    negotiate 3DES with a 1024 bit RSA key exchange with a host whose
1701    certificate you have verified, you can expect to be that secure.
1728 Dierks & Rescorla            Standards Track                    [Page 32]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
1731    However, you SHOULD never send data over a link encrypted with 40 bit
1732    security unless you feel that data is worth no more than the effort
1733    required to break that encryption.
1735    These goals are achieved by the handshake protocol, which can be
1736    summarized as follows: The client sends a client hello message to
1737    which the server must respond with a server hello message, or else a
1738    fatal error will occur and the connection will fail. The client hello
1739    and server hello are used to establish security enhancement
1740    capabilities between client and server. The client hello and server
1741    hello establish the following attributes: Protocol Version, Session
1742    ID, Cipher Suite, and Compression Method. Additionally, two random
1743    values are generated and exchanged: ClientHello.random and
1744    ServerHello.random.
1746    The actual key exchange uses up to four messages: the server
1747    certificate, the server key exchange, the client certificate, and the
1748    client key exchange. New key exchange methods can be created by
1749    specifying a format for these messages and defining the use of the
1750    messages to allow the client and server to agree upon a shared
1751    secret. This secret MUST be quite long; currently defined key
1752    exchange methods exchange secrets which range from 48 to 128 bytes in
1753    length.
1755    Following the hello messages, the server will send its certificate,
1756    if it is to be authenticated. Additionally, a server key exchange
1757    message may be sent, if it is required (e.g. if their server has no
1758    certificate, or if its certificate is for signing only). If the
1759    server is authenticated, it may request a certificate from the
1760    client, if that is appropriate to the cipher suite selected. Now the
1761    server will send the server hello done message, indicating that the
1762    hello-message phase of the handshake is complete. The server will
1763    then wait for a client response. If the server has sent a certificate
1764    request message, the client must send the certificate message. The
1765    client key exchange message is now sent, and the content of that
1766    message will depend on the public key algorithm selected between the
1767    client hello and the server hello. If the client has sent a
1768    certificate with signing ability, a digitally-signed certificate
1769    verify message is sent to explicitly verify the certificate.
1771    At this point, a change cipher spec message is sent by the client,
1772    and the client copies the pending Cipher Spec into the current Cipher
1773    Spec. The client then immediately sends the finished message under
1774    the new algorithms, keys, and secrets. In response, the server will
1775    send its own change cipher spec message, transfer the pending to the
1776    current Cipher Spec, and send its finished message under the new
1782 Dierks & Rescorla            Standards Track                    [Page 33]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
1785    Cipher Spec. At this point, the handshake is complete and the client
1786    and server may begin to exchange application layer data. (See flow
1787    chart below.) Application data MUST NOT be sent prior to the
1788    completion of the first handshake (before a cipher suite other
1789    TLS_NULL_WITH_NULL_NULL is established).
1790       Client                                               Server
1792       ClientHello                  -------->
1793                                                       ServerHello
1794                                                      Certificate*
1795                                                ServerKeyExchange*
1796                                               CertificateRequest*
1797                                    <--------      ServerHelloDone
1798       Certificate*
1799       ClientKeyExchange
1800       CertificateVerify*
1801       [ChangeCipherSpec]
1802       Finished                     -------->
1803                                                [ChangeCipherSpec]
1804                                    <--------             Finished
1805       Application Data             <------->     Application Data
1807              Fig. 1 - Message flow for a full handshake
1809    * Indicates optional or situation-dependent messages that are not
1810    always sent.
1812   Note: To help avoid pipeline stalls, ChangeCipherSpec is an
1813        independent TLS Protocol content type, and is not actually a TLS
1814        handshake message.
1816    When the client and server decide to resume a previous session or
1817    duplicate an existing session (instead of negotiating new security
1818    parameters) the message flow is as follows:
1820    The client sends a ClientHello using the Session ID of the session to
1821    be resumed. The server then checks its session cache for a match.  If
1822    a match is found, and the server is willing to re-establish the
1823    connection under the specified session state, it will send a
1824    ServerHello with the same Session ID value. At this point, both
1825    client and server MUST send change cipher spec messages and proceed
1826    directly to finished messages. Once the re-establishment is complete,
1827    the client and server MAY begin to exchange application layer data.
1828    (See flow chart below.) If a Session ID match is not found, the
1829    server generates a new session ID and the TLS client and server
1830    perform a full handshake.
1836 Dierks & Rescorla            Standards Track                    [Page 34]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
1839       Client                                                Server
1841       ClientHello                   -------->
1842                                                        ServerHello
1843                                                 [ChangeCipherSpec]
1844                                     <--------             Finished
1845       [ChangeCipherSpec]
1846       Finished                      -------->
1847       Application Data              <------->     Application Data
1849           Fig. 2 - Message flow for an abbreviated handshake
1851    The contents and significance of each message will be presented in
1852    detail in the following sections.
1854 7.4. Handshake protocol
1856    The TLS Handshake Protocol is one of the defined higher level clients
1857    of the TLS Record Protocol. This protocol is used to negotiate the
1858    secure attributes of a session. Handshake messages are supplied to
1859    the TLS Record Layer, where they are encapsulated within one or more
1860    TLSPlaintext structures, which are processed and transmitted as
1861    specified by the current active session state.
1863        enum {
1864            hello_request(0), client_hello(1), server_hello(2),
1865            certificate(11), server_key_exchange (12),
1866            certificate_request(13), server_hello_done(14),
1867            certificate_verify(15), client_key_exchange(16),
1868            finished(20), (255)
1869        } HandshakeType;
1871        struct {
1872            HandshakeType msg_type;    /* handshake type */
1873            uint24 length;             /* bytes in message */
1874            select (HandshakeType) {
1875                case hello_request:       HelloRequest;
1876                case client_hello:        ClientHello;
1877                case server_hello:        ServerHello;
1878                case certificate:         Certificate;
1879                case server_key_exchange: ServerKeyExchange;
1880                case certificate_request: CertificateRequest;
1881                case server_hello_done:   ServerHelloDone;
1882                case certificate_verify:  CertificateVerify;
1883                case client_key_exchange: ClientKeyExchange;
1884                case finished:            Finished;
1885            } body;
1886        } Handshake;
1890 Dierks & Rescorla            Standards Track                    [Page 35]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
1893    The handshake protocol messages are presented below in the order they
1894    MUST be sent; sending handshake messages in an unexpected order
1895    results in a fatal error. Unneeded handshake messages can be omitted,
1896    however. Note one exception to the ordering: the Certificate message
1897    is used twice in the handshake (from server to client, then from
1898    client to server), but described only in its first position. The one
1899    message which is not bound by these ordering rules is the Hello
1900    Request message, which can be sent at any time, but which should be
1901    ignored by the client if it arrives in the middle of a handshake.
1903    New Handshake message type values MUST be defined via RFC 2434
1904    Standards Action. See Section 11 for IANA Considerations for these
1905    values.
1907 7.4.1. Hello messages
1909    The hello phase messages are used to exchange security enhancement
1910    capabilities between the client and server. When a new session
1911    begins, the Record Layer's connection state encryption, hash, and
1912    compression algorithms are initialized to null. The current
1913    connection state is used for renegotiation messages.
1915 7.4.1.1. Hello request
1917    When this message will be sent:
1918        The hello request message MAY be sent by the server at any time.
1920    Meaning of this message:
1921        Hello request is a simple notification that the client should
1922        begin the negotiation process anew by sending a client hello
1923        message when convenient. This message will be ignored by the
1924        client if the client is currently negotiating a session. This
1925        message may be ignored by the client if it does not wish to
1926        renegotiate a session, or the client may, if it wishes, respond
1927        with a no_renegotiation alert. Since handshake messages are
1928        intended to have transmission precedence over application data,
1929        it is expected that the negotiation will begin before no more
1930        than a few records are received from the client. If the server
1931        sends a hello request but does not receive a client hello in
1932        response, it may close the connection with a fatal alert.
1934    After sending a hello request, servers SHOULD not repeat the request
1935    until the subsequent handshake negotiation is complete.
1937    Structure of this message:
1938        struct { } HelloRequest;
1944 Dierks & Rescorla            Standards Track                    [Page 36]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
1947  Note: This message MUST NOT be included in the message hashes which are
1948        maintained throughout the handshake and used in the finished
1949        messages and the certificate verify message.
1951 7.4.1.2. Client hello
1953    When this message will be sent:
1954        When a client first connects to a server it is required to send
1955        the client hello as its first message. The client can also send a
1956        client hello in response to a hello request or on its own
1957        initiative in order to renegotiate the security parameters in an
1958        existing connection.
1960        Structure of this message:
1961            The client hello message includes a random structure, which is
1962            used later in the protocol.
1964            struct {
1965               uint32 gmt_unix_time;
1966               opaque random_bytes[28];
1967            } Random;
1969        gmt_unix_time
1970        The current time and date in standard UNIX 32-bit format (seconds
1971        since the midnight starting Jan 1, 1970, GMT) according to the
1972        sender's internal clock. Clocks are not required to be set
1973        correctly by the basic TLS Protocol; higher level or application
1974        protocols may define additional requirements.
1976    random_bytes
1977        28 bytes generated by a secure random number generator.
1979    The client hello message includes a variable length session
1980    identifier. If not empty, the value identifies a session between the
1981    same client and server whose security parameters the client wishes to
1982    reuse. The session identifier MAY be from an earlier connection, this
1983    connection, or another currently active connection. The second option
1984    is useful if the client only wishes to update the random structures
1985    and derived values of a connection, while the third option makes it
1986    possible to establish several independent secure connections without
1987    repeating the full handshake protocol. These independent connections
1988    may occur sequentially or simultaneously; a SessionID becomes valid
1989    when the handshake negotiating it completes with the exchange of
1990    Finished messages and persists until removed due to aging or because
1991    a fatal error was encountered on a connection associated with the
1992    session. The actual contents of the SessionID are defined by the
1993    server.
1998 Dierks & Rescorla            Standards Track                    [Page 37]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
2001        opaque SessionID<0..32>;
2003    Warning:
2004        Because the SessionID is transmitted without encryption or
2005        immediate MAC protection, servers MUST not place confidential
2006        information in session identifiers or let the contents of fake
2007        session identifiers cause any breach of security. (Note that the
2008        content of the handshake as a whole, including the SessionID, is
2009        protected by the Finished messages exchanged at the end of the
2010        handshake.)
2012    The CipherSuite list, passed from the client to the server in the
2013    client hello message, contains the combinations of cryptographic
2014    algorithms supported by the client in order of the client's
2015    preference (favorite choice first). Each CipherSuite defines a key
2016    exchange algorithm, a bulk encryption algorithm (including secret key
2017    length) and a MAC algorithm. The server will select a cipher suite
2018    or, if no acceptable choices are presented, return a handshake
2019    failure alert and close the connection.
2021        uint8 CipherSuite[2];    /* Cryptographic suite selector */
2023    The client hello includes a list of compression algorithms supported
2024    by the client, ordered according to the client's preference.
2026        enum { null(0), (255) } CompressionMethod;
2028        struct {
2029            ProtocolVersion client_version;
2030            Random random;
2031            SessionID session_id;
2032            CipherSuite cipher_suites<2..2^16-1>;
2033            CompressionMethod compression_methods<1..2^8-1>;
2034        } ClientHello;
2036    client_version
2037        The version of the TLS protocol by which the client wishes to
2038        communicate during this session. This SHOULD be the latest
2039        (highest valued) version supported by the client. For this
2040        version of the specification, the version will be 3.2 (See
2041        Appendix E for details about backward compatibility).
2043    random
2044        A client-generated random structure.
2046    session_id
2047        The ID of a session the client wishes to use for this connection.
2048        This field should be empty if no session_id is available or the
2052 Dierks & Rescorla            Standards Track                    [Page 38]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
2055        client wishes to generate new security parameters.
2057    cipher_suites
2058        This is a list of the cryptographic options supported by the
2059        client, with the client's first preference first. If the
2060        session_id field is not empty (implying a session resumption
2061        request) this vector MUST include at least the cipher_suite from
2062        that session. Values are defined in Appendix A.5.
2064    compression_methods
2065        This is a list of the compression methods supported by the
2066        client, sorted by client preference. If the session_id field is
2067        not empty (implying a session resumption request) it must include
2068        the compression_method from that session. This vector must
2069        contain, and all implementations must support,
2070        CompressionMethod.null. Thus, a client and server will always be
2071        able to agree on a compression method.
2073    After sending the client hello message, the client waits for a server
2074    hello message. Any other handshake message returned by the server
2075    except for a hello request is treated as a fatal error.
2077    Forward compatibility note:
2078        In the interests of forward compatibility, it is permitted for a
2079        client hello message to include extra data after the compression
2080        methods. This data MUST be included in the handshake hashes, but
2081        must otherwise be ignored. This is the only handshake message for
2082        which this is legal; for all other messages, the amount of data
2083        in the message MUST match the description of the message
2084        precisely.
2086 Note: For the intended use of trailing data in the ClientHello, see RFC
2087        3546 [TLSEXT].
2089 7.4.1.3. Server hello
2091    When this message will be sent:
2092        The server will send this message in response to a client hello
2093        message when it was able to find an acceptable set of algorithms.
2094        If it cannot find such a match, it will respond with a handshake
2095        failure alert.
2097    Structure of this message:
2098        struct {
2099            ProtocolVersion server_version;
2100            Random random;
2101            SessionID session_id;
2102            CipherSuite cipher_suite;
2106 Dierks & Rescorla            Standards Track                    [Page 39]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
2109            CompressionMethod compression_method;
2110        } ServerHello;
2112    server_version
2113        This field will contain the lower of that suggested by the client
2114        in the client hello and the highest supported by the server. For
2115        this version of the specification, the version is 3.2 (See
2116        Appendix E for details about backward compatibility).
2118    random
2119        This structure is generated by the server and MUST be
2120        independently generated from the ClientHello.random.
2122    session_id
2123        This is the identity of the session corresponding to this
2124        connection. If the ClientHello.session_id was non-empty, the
2125        server will look in its session cache for a match. If a match is
2126        found and the server is willing to establish the new connection
2127        using the specified session state, the server will respond with
2128        the same value as was supplied by the client. This indicates a
2129        resumed session and dictates that the parties must proceed
2130        directly to the finished messages. Otherwise this field will
2131        contain a different value identifying the new session. The server
2132        may return an empty session_id to indicate that the session will
2133        not be cached and therefore cannot be resumed. If a session is
2134        resumed, it must be resumed using the same cipher suite it was
2135        originally negotiated with.
2137    cipher_suite
2138        The single cipher suite selected by the server from the list in
2139        ClientHello.cipher_suites. For resumed sessions this field is the
2140        value from the state of the session being resumed.
2142    compression_method
2143        The single compression algorithm selected by the server from the
2144        list in ClientHello.compression_methods. For resumed sessions
2145        this field is the value from the resumed session state.
2147 7.4.2. Server certificate
2149    When this message will be sent:
2150        The server MUST send a certificate whenever the agreed-upon key
2151        exchange method is not an anonymous one. This message will always
2152        immediately follow the server hello message.
2154    Meaning of this message:
2155        The certificate type MUST be appropriate for the selected cipher
2156        suite's key exchange algorithm, and is generally an X.509v3
2160 Dierks & Rescorla            Standards Track                    [Page 40]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
2163        certificate. It MUST contain a key which matches the key exchange
2164        method, as follows. Unless otherwise specified, the signing
2165        algorithm for the certificate MUST be the same as the algorithm
2166        for the certificate key. Unless otherwise specified, the public
2167        key MAY be of any length.
2169        Key Exchange Algorithm  Certificate Key Type
2171        RSA                     RSA public key; the certificate MUST
2172                                allow the key to be used for encryption.
2174        DHE_DSS                 DSS public key.
2176        DHE_RSA                 RSA public key which can be used for
2177                                signing.
2179        DH_DSS                  Diffie-Hellman key. The algorithm used
2180                                to sign the certificate MUST be DSS.
2182        DH_RSA                  Diffie-Hellman key. The algorithm used
2183                                to sign the certificate MUST be RSA.
2185    All certificate profiles, key and cryptographic formats are defined
2186    by the IETF PKIX working group [PKIX]. When a key usage extension is
2187    present, the digitalSignature bit MUST be set for the key to be
2188    eligible for signing, as described above, and the keyEncipherment bit
2189    MUST be present to allow encryption, as described above. The
2190    keyAgreement bit must be set on Diffie-Hellman certificates.
2192    As CipherSuites which specify new key exchange methods are specified
2193    for the TLS Protocol, they will imply certificate format and the
2194    required encoded keying information.
2196    Structure of this message:
2197        opaque ASN.1Cert<1..2^24-1>;
2199        struct {
2200            ASN.1Cert certificate_list<0..2^24-1>;
2201        } Certificate;
2203    certificate_list
2204        This is a sequence (chain) of X.509v3 certificates. The sender's
2205        certificate must come first in the list. Each following
2206        certificate must directly certify the one preceding it. Because
2207        certificate validation requires that root keys be distributed
2208        independently, the self-signed certificate which specifies the
2209        root certificate authority may optionally be omitted from the
2210        chain, under the assumption that the remote end must already
2214 Dierks & Rescorla            Standards Track                    [Page 41]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
2217        possess it in order to validate it in any case.
2219    The same message type and structure will be used for the client's
2220    response to a certificate request message. Note that a client MAY
2221    send no certificates if it does not have an appropriate certificate
2222    to send in response to the server's authentication request.
2224  Note: PKCS #7 [PKCS7] is not used as the format for the certificate
2225        vector because PKCS #6 [PKCS6] extended certificates are not
2226        used. Also PKCS #7 defines a SET rather than a SEQUENCE, making
2227        the task of parsing the list more difficult.
2229 7.4.3. Server key exchange message
2231    When this message will be sent:
2232        This message will be sent immediately after the server
2233        certificate message (or the server hello message, if this is an
2234        anonymous negotiation).
2236        The server key exchange message is sent by the server only when
2237        the server certificate message (if sent) does not contain enough
2238        data to allow the client to exchange a premaster secret. This is
2239        true for the following key exchange methods:
2241            DHE_DSS
2242            DHE_RSA
2243            DH_anon
2245        It is not legal to send the server key exchange message for the
2246        following key exchange methods:
2248            RSA
2249            DH_DSS
2250            DH_RSA
2252    Meaning of this message:
2253        This message conveys cryptographic information to allow the
2254        client to communicate the premaster secret: either an RSA public
2255        key to encrypt the premaster secret with, or a Diffie-Hellman
2256        public key with which the client can complete a key exchange
2257        (with the result being the premaster secret.)
2259    As additional CipherSuites are defined for TLS which include new key
2260    exchange algorithms, the server key exchange message will be sent if
2261    and only if the certificate type associated with the key exchange
2262    algorithm does not provide enough information for the client to
2263    exchange a premaster secret.
2268 Dierks & Rescorla            Standards Track                    [Page 42]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
2271    Structure of this message:
2272        enum { rsa, diffie_hellman } KeyExchangeAlgorithm;
2274        struct {
2275            opaque rsa_modulus<1..2^16-1>;
2276            opaque rsa_exponent<1..2^16-1>;
2277        } ServerRSAParams;
2279        rsa_modulus
2280            The modulus of the server's temporary RSA key.
2282        rsa_exponent
2283            The public exponent of the server's temporary RSA key.
2285        struct {
2286            opaque dh_p<1..2^16-1>;
2287            opaque dh_g<1..2^16-1>;
2288            opaque dh_Ys<1..2^16-1>;
2289        } ServerDHParams;     /* Ephemeral DH parameters */
2291        dh_p
2292            The prime modulus used for the Diffie-Hellman operation.
2294        dh_g
2295            The generator used for the Diffie-Hellman operation.
2297        dh_Ys
2298            The server's Diffie-Hellman public value (g^X mod p).
2300        struct {
2301            select (KeyExchangeAlgorithm) {
2302                case diffie_hellman:
2303                    ServerDHParams params;
2304                    Signature signed_params;
2305                case rsa:
2306                    ServerRSAParams params;
2307                    Signature signed_params;
2308            };
2309        } ServerKeyExchange;
2311        struct {
2312            select (KeyExchangeAlgorithm) {
2313                case diffie_hellman:
2314                    ServerDHParams params;
2315                case rsa:
2316                    ServerRSAParams params;
2317            };
2318         } ServerParams;
2322 Dierks & Rescorla            Standards Track                    [Page 43]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
2325        params
2326            The server's key exchange parameters.
2328        signed_params
2329            For non-anonymous key exchanges, a hash of the corresponding
2330            params value, with the signature appropriate to that hash
2331            applied.
2333        md5_hash
2334            MD5(ClientHello.random + ServerHello.random + ServerParams);
2336        sha_hash
2337            SHA(ClientHello.random + ServerHello.random + ServerParams);
2339        enum { anonymous, rsa, dsa } SignatureAlgorithm;
2342        select (SignatureAlgorithm)
2343        {
2344            case anonymous: struct { };
2345            case rsa:
2346                digitally-signed struct {
2347                    opaque md5_hash[16];
2348                    opaque sha_hash[20];
2349                };
2350            case dsa:
2351                digitally-signed struct {
2352                    opaque sha_hash[20];
2353                };
2354        } Signature;
2356 7.4.4. Certificate request
2358    When this message will be sent:
2359        A non-anonymous server can optionally request a certificate from
2360        the client, if appropriate for the selected cipher suite. This
2361        message, if sent, will immediately follow the Server Key Exchange
2362        message (if it is sent; otherwise, the Server Certificate
2363        message).
2365    Structure of this message:
2366        enum {
2367            rsa_sign(1), dss_sign(2), rsa_fixed_dh(3), dss_fixed_dh(4),
2368         rsa_ephemeral_dh_RESERVED(5), dss_ephemeral_dh_RESERVED(6),
2369         fortezza_dms_RESERVED(20),
2370            (255)
2371        } ClientCertificateType;
2376 Dierks & Rescorla            Standards Track                    [Page 44]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
2379        opaque DistinguishedName<1..2^16-1>;
2381        struct {
2382            ClientCertificateType certificate_types<1..2^8-1>;
2383            DistinguishedName certificate_authorities<0..2^16-1>;
2384        } CertificateRequest;
2386        certificate_types
2387            This field is a list of the types of certificates requested,
2388            sorted in order of the server's preference.
2390        certificate_authorities
2391            A list of the distinguished names of acceptable certificate
2392            authorities. These distinguished names may specify a desired
2393            distinguished name for a root CA or for a subordinate CA;
2394            thus, this message can be used both to describe known roots
2395            and a desired authorization space. If the
2396            certificate_authorities list is empty then the client MAY
2397            send any certificate of the appropriate
2398            ClientCertificateType, unless there is some external
2399            arrangement to the contrary.
2402  ClientCertificateType values are divided into three groups:
2404               1. Values from 0 (zero) through 63 decimal (0x3F) inclusive are
2405                  reserved for IETF Standards Track protocols.
2407               2. Values from 64 decimal (0x40) through 223 decimal (0xDF) inclusive
2408                  are reserved for assignment for non-Standards Track methods.
2410               3. Values from 224 decimal (0xE0) through 255 decimal (0xFF)
2411                  inclusive are reserved for private use.
2413            Additional information describing the role of IANA in the
2414            allocation of ClientCertificateType code points is described
2415            in Section 11.
2417            Note: Values listed as RESERVED may not be used. They were used in SSLv3.
2419  Note: DistinguishedName is derived from [X509]. DistinguishedNames are
2420            represented in DER-encoded format.
2422  Note: It is a fatal handshake_failure alert for an anonymous server to
2423        request client authentication.
2425 7.4.5. Server hello done
2430 Dierks & Rescorla            Standards Track                    [Page 45]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
2433    When this message will be sent:
2434        The server hello done message is sent by the server to indicate
2435        the end of the server hello and associated messages. After
2436        sending this message the server will wait for a client response.
2438    Meaning of this message:
2439        This message means that the server is done sending messages to
2440        support the key exchange, and the client can proceed with its
2441        phase of the key exchange.
2443        Upon receipt of the server hello done message the client SHOULD
2444        verify that the server provided a valid certificate if required
2445        and check that the server hello parameters are acceptable.
2447    Structure of this message:
2448        struct { } ServerHelloDone;
2450 7.4.6. Client certificate
2452    When this message will be sent:
2453        This is the first message the client can send after receiving a
2454        server hello done message. This message is only sent if the
2455        server requests a certificate. If no suitable certificate is
2456        available, the client should send a certificate message
2457        containing no certificates: I.e. the certificate_list structure
2458        should have a length of zero. If client authentication is
2459        required by the server for the handshake to continue, it may
2460        respond with a fatal handshake failure alert. Client certificates
2461        are sent using the Certificate structure defined in Section
2462        7.4.2.
2465  Note: When using a static Diffie-Hellman based key exchange method
2466        (DH_DSS or DH_RSA), if client authentication is requested, the
2467        Diffie-Hellman group and generator encoded in the client's
2468        certificate must match the server specified Diffie-Hellman
2469        parameters if the client's parameters are to be used for the key
2470        exchange.
2472 7.4.7. Client key exchange message
2474    When this message will be sent:
2475        This message is always sent by the client. It will immediately
2476        follow the client certificate message, if it is sent. Otherwise
2477        it will be the first message sent by the client after it receives
2478        the server hello done message.
2480    Meaning of this message:
2484 Dierks & Rescorla            Standards Track                    [Page 46]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
2487        With this message, the premaster secret is set, either though
2488        direct transmission of the RSA-encrypted secret, or by the
2489        transmission of Diffie-Hellman parameters which will allow each
2490        side to agree upon the same premaster secret. When the key
2491        exchange method is DH_RSA or DH_DSS, client certification has
2492        been requested, and the client was able to respond with a
2493        certificate which contained a Diffie-Hellman public key whose
2494        parameters (group and generator) matched those specified by the
2495        server in its certificate, this message MUST not contain any
2496        data.
2498    Structure of this message:
2499        The choice of messages depends on which key exchange method has
2500        been selected. See Section 7.4.3 for the KeyExchangeAlgorithm
2501        definition.
2503        struct {
2504            select (KeyExchangeAlgorithm) {
2505                case rsa: EncryptedPreMasterSecret;
2506                case diffie_hellman: ClientDiffieHellmanPublic;
2507            } exchange_keys;
2508        } ClientKeyExchange;
2510 7.4.7.1. RSA encrypted premaster secret message
2512    Meaning of this message:
2513        If RSA is being used for key agreement and authentication, the
2514        client generates a 48-byte premaster secret, encrypts it using
2515        the public key from the server's certificate or the temporary RSA
2516        key provided in a server key exchange message, and sends the
2517        result in an encrypted premaster secret message. This structure
2518        is a variant of the client key exchange message, not a message in
2519        itself.
2521    Structure of this message:
2522        struct {
2523            ProtocolVersion client_version;
2524            opaque random[46];
2525        } PreMasterSecret;
2527        client_version
2528            The latest (newest) version supported by the client. This is
2529            used to detect version roll-back attacks. Upon receiving the
2530            premaster secret, the server SHOULD check that this value
2531            matches the value transmitted by the client in the client
2532            hello message.
2534        random
2538 Dierks & Rescorla            Standards Track                    [Page 47]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
2541            46 securely-generated random bytes.
2543        struct {
2544            public-key-encrypted PreMasterSecret pre_master_secret;
2545        } EncryptedPreMasterSecret;
2547        pre_master_secret
2548            This random value is generated by the client and is used to
2549            generate the master secret, as specified in Section 8.1.
2551  Note: An attack discovered by Daniel Bleichenbacher [BLEI] can be used
2552        to attack a TLS server which is using PKCS#1 encoded RSA. The
2553        attack takes advantage of the fact that by failing in different
2554        ways, a TLS server can be coerced into revealing whether a
2555        particular message, when decrypted, is properly PKCS#1 formatted
2556        or not.
2558        The best way to avoid vulnerability to this attack is to treat
2559        incorrectly formatted messages in a manner indistinguishable from
2560        correctly formatted RSA blocks. Thus, when it receives an
2561        incorrectly formatted RSA block, a server should generate a
2562        random 48-byte value and proceed using it as the premaster
2563        secret. Thus, the server will act identically whether the
2564        received RSA block is correctly encoded or not.
2566  Implementation Note: public-key-encrypted data is represented as an
2567        opaque vector <0..2^16-1> (see S. 4.7). Thus the RSA-encrypted
2568        PreMaster Secret in a ClientKeyExchange is preceded by two length
2569        bytes. These bytes are redundant in the case of RSA because the
2570        EncryptedPreMasterSecret is the only data in the
2571        ClientKeyExchange and its length can therefore be unambiguously
2572        determined. The SSLv3 specification was not clear about the
2573        encoding of public-key-encrypted data and therefore many SSLv3
2574        implementations do not include the the length bytes, encoding the
2575        RSA encrypted data directly in the ClientKeyExchange message.
2577        This specification requires correct encoding of the
2578        EncryptedPreMasterSecret complete with length bytes. The
2579        resulting PDU is incompatible with many SSLv3 implementations.
2580        Implementors upgrading from SSLv3 must modify their
2581        implementations to generate and accept the correct encoding.
2582        Implementors who wish to be compatible with both SSLv3 and TLS
2583        should make their implementation's behavior dependent on the
2584        protocol version.
2586  Implementation Note: It is now known that remote timing-based attacks
2587        on SSL are possible, at least when the client and server are on
2588        the same LAN. Accordingly, implementations which use static RSA
2592 Dierks & Rescorla            Standards Track                    [Page 48]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
2595        keys SHOULD use RSA blinding or some other anti-timing technique,
2596        as described in [TIMING].
2598  Note: The version number in the PreMasterSecret is that offered by the
2599        client, NOT the version negotiated for the connection. This
2600        feature is designed to prevent rollback attacks. Unfortunately,
2601        many implementations use the negotiated version instead and
2602        therefore checking the version number may lead to failure to
2603        interoperate with such incorrect client implementations. Client
2604        implementations MUST and Server implementations MAY check the
2605        version number. In practice, since there are no significant known
2606        security differences between TLS and SSLv3, rollback to SSLv3 is
2607        not believed to be a serious security risk.  Note that if servers
2608        choose to to check the version number, they should randomize the
2609        PreMasterSecret in case of error, rather than generate an alert,
2610        in order to avoid variants on the Bleichenbacher attack. [KPR03]
2612 7.4.7.2. Client Diffie-Hellman public value
2614    Meaning of this message:
2615        This structure conveys the client's Diffie-Hellman public value
2616        (Yc) if it was not already included in the client's certificate.
2617        The encoding used for Yc is determined by the enumerated
2618        PublicValueEncoding. This structure is a variant of the client
2619        key exchange message, not a message in itself.
2621    Structure of this message:
2622        enum { implicit, explicit } PublicValueEncoding;
2624        implicit
2625            If the client certificate already contains a suitable Diffie-
2626            Hellman key, then Yc is implicit and does not need to be sent
2627            again. In this case, the Client Key Exchange message will be
2628            sent, but will be empty.
2630        explicit
2631            Yc needs to be sent.
2633        struct {
2634            select (PublicValueEncoding) {
2635                case implicit: struct { };
2636                case explicit: opaque dh_Yc<1..2^16-1>;
2637            } dh_public;
2638        } ClientDiffieHellmanPublic;
2640        dh_Yc
2641            The client's Diffie-Hellman public value (Yc).
2646 Dierks & Rescorla            Standards Track                    [Page 49]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
2649 7.4.8. Certificate verify
2651    When this message will be sent:
2652        This message is used to provide explicit verification of a client
2653        certificate. This message is only sent following a client
2654        certificate that has signing capability (i.e. all certificates
2655        except those containing fixed Diffie-Hellman parameters). When
2656        sent, it will immediately follow the client key exchange message.
2658    Structure of this message:
2659        struct {
2660             Signature signature;
2661        } CertificateVerify;
2663        The Signature type is defined in 7.4.3.
2665        CertificateVerify.signature.md5_hash
2666            MD5(handshake_messages);
2668        CertificateVerify.signature.sha_hash
2669            SHA(handshake_messages);
2671    Here handshake_messages refers to all handshake messages sent or
2672    received starting at client hello up to but not including this
2673    message, including the type and length fields of the handshake
2674    messages. This is the concatenation of all the Handshake structures
2675    as defined in 7.4 exchanged thus far.
2677 7.4.9. Finished
2679    When this message will be sent:
2680        A finished message is always sent immediately after a change
2681        cipher spec message to verify that the key exchange and
2682        authentication processes were successful. It is essential that a
2683        change cipher spec message be received between the other
2684        handshake messages and the Finished message.
2686    Meaning of this message:
2687        The finished message is the first protected with the just-
2688        negotiated algorithms, keys, and secrets. Recipients of finished
2689        messages MUST verify that the contents are correct.  Once a side
2690        has sent its Finished message and received and validated the
2691        Finished message from its peer, it may begin to send and receive
2692        application data over the connection.
2694        struct {
2695            opaque verify_data[12];
2696        } Finished;
2700 Dierks & Rescorla            Standards Track                    [Page 50]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
2703        verify_data
2704            PRF(master_secret, finished_label, MD5(handshake_messages) +
2705            SHA-1(handshake_messages)) [0..11];
2707        finished_label
2708            For Finished messages sent by the client, the string "client
2709            finished". For Finished messages sent by the server, the
2710            string "server finished".
2712        handshake_messages
2713            All of the data from all messages in this handshake (not
2714            including any HelloRequest messages) up to but not including
2715            this message. This is only data visible at the handshake
2716            layer and does not include record layer headers.  This is the
2717            concatenation of all the Handshake structures as defined in
2718            7.4 exchanged thus far.
2720    It is a fatal error if a finished message is not preceded by a change
2721    cipher spec message at the appropriate point in the handshake.
2723    The value handshake_messages includes all handshake messages starting
2724    at client hello up to, but not including, this finished message. This
2725    may be different from handshake_messages in Section 7.4.8 because it
2726    would include the certificate verify message (if sent). Also, the
2727    handshake_messages for the finished message sent by the client will
2728    be different from that for the finished message sent by the server,
2729    because the one which is sent second will include the prior one.
2731  Note: Change cipher spec messages, alerts and any other record types
2732        are not handshake messages and are not included in the hash
2733        computations. Also, Hello Request messages are omitted from
2734        handshake hashes.
2736 8. Cryptographic computations
2738    In order to begin connection protection, the TLS Record Protocol
2739    requires specification of a suite of algorithms, a master secret, and
2740    the client and server random values. The authentication, encryption,
2741    and MAC algorithms are determined by the cipher_suite selected by the
2742    server and revealed in the server hello message. The compression
2743    algorithm is negotiated in the hello messages, and the random values
2744    are exchanged in the hello messages. All that remains is to calculate
2745    the master secret.
2747 8.1. Computing the master secret
2749    For all key exchange methods, the same algorithm is used to convert
2750    the pre_master_secret into the master_secret. The pre_master_secret
2754 Dierks & Rescorla            Standards Track                    [Page 51]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
2757    should be deleted from memory once the master_secret has been
2758    computed.
2760        master_secret = PRF(pre_master_secret, "master secret",
2761                            ClientHello.random + ServerHello.random)
2762        [0..47];
2764    The master secret is always exactly 48 bytes in length. The length of
2765    the premaster secret will vary depending on key exchange method.
2808 Dierks & Rescorla            Standards Track                    [Page 52]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
2811 8.1.1. RSA
2813    When RSA is used for server authentication and key exchange, a
2814    48-byte pre_master_secret is generated by the client, encrypted under
2815    the server's public key, and sent to the server. The server uses its
2816    private key to decrypt the pre_master_secret. Both parties then
2817    convert the pre_master_secret into the master_secret, as specified
2818    above.
2820    RSA digital signatures are performed using PKCS #1 [PKCS1] block type
2821    1. RSA public key encryption is performed using PKCS #1 block type 2.
2823 8.1.2. Diffie-Hellman
2825    A conventional Diffie-Hellman computation is performed. The
2826    negotiated key (Z) is used as the pre_master_secret, and is converted
2827    into the master_secret, as specified above.  Leading 0 bytes of Z are
2828    stripped before it is used as the pre_master_secret.
2830  Note: Diffie-Hellman parameters are specified by the server, and may
2831        be either ephemeral or contained within the server's certificate.
2833 9. Mandatory Cipher Suites
2835    In the absence of an application profile standard specifying
2836    otherwise, a TLS compliant application MUST implement the cipher
2837    suite TLS_RSA_WITH_3DES_EDE_CBC_SHA.
2839 10. Application data protocol
2841    Application data messages are carried by the Record Layer and are
2842    fragmented, compressed and encrypted based on the current connection
2843    state. The messages are treated as transparent data to the record
2844    layer.
2846 10. IANA Considerations
2848    Section 7.4.3 describes a TLS ClientCertificateType Registry to be
2849    maintained by the IANA, as defining a number of such code point
2850    identifiers. ClientCertificateType identifiers with values in the
2851    range 0-63 (decimal) inclusive are assigned via RFC 2434 Standards
2852    Action. Values from the range 64-223 (decimal) inclusive are assigned
2853    via [RFC 2434] Specification Required.  Identifier values from
2854    224-255 (decimal) inclusive are reserved for RFC 2434 Private Use.
2855    The registry will be initially populated with the values in this
2856    document.
2858    Section A.5 describes a TLS Cipher Suite Registry to be maintained by
2862 Dierks & Rescorla            Standards Track                    [Page 53]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
2865    the IANA, as well as defining a number of such cipher suite
2866    identifiers. Cipher suite values with the first byte in the range
2867    0-191 (decimal) inclusive are assigned via RFC 2434 Standards Action.
2868    Values with the first byte in the range 192-254 (decimal) are
2869    assigned via RFC 2434 Specification Required. Values with the first
2870    byte 255 (decimal) are reserved for RFC 2434 Private Use. The
2871    registry will be initially populated with the values from this
2872    document, [TLSAES], and [TLSKRB].
2874    Section 6 requires that all ContentType values be defined by RFC 2434
2875    Standards Action. IANA SHOULD create a TLS ContentType registry,
2876    initially populated with values from this document. Future values
2877    MUST be allocated via Standards Action as described in [RFC 2434].
2879    Section 7.2.2 requires that all Alert values be defined by RFC 2434
2880    Standards Action. IANA SHOULD create a TLS Alert registry, initially
2881    populated with values from this document and [TLSEXT]. Future values
2882    MUST be allocated via Standards Action as described in [RFC 2434].
2884    Section 7.4 requires that all HandshakeType values be defined by RFC
2885    2434 Standards Action. IANA SHOULD create a TLS HandshakeType
2886    registry, initially populated with values from this document,
2887    [TLSEXT], and [TLSKRB].  Future values MUST be allocated via
2888    Standards Action as described in [RFC 2434].
2916 Dierks & Rescorla            Standards Track                    [Page 54]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
2919 A. Protocol constant values
2921    This section describes protocol types and constants.
2923 A.1. Record layer
2925     struct {
2926         uint8 major, minor;
2927     } ProtocolVersion;
2929     ProtocolVersion version = { 3, 2 };     /* TLS v1.1 */
2931     enum {
2932         change_cipher_spec(20), alert(21), handshake(22),
2933         application_data(23), (255)
2934     } ContentType;
2936     struct {
2937         ContentType type;
2938         ProtocolVersion version;
2939         uint16 length;
2940         opaque fragment[TLSPlaintext.length];
2941     } TLSPlaintext;
2943     struct {
2944         ContentType type;
2945         ProtocolVersion version;
2946         uint16 length;
2947         opaque fragment[TLSCompressed.length];
2948     } TLSCompressed;
2950     struct {
2951         ContentType type;
2952         ProtocolVersion version;
2953         uint16 length;
2954         select (CipherSpec.cipher_type) {
2955             case stream: GenericStreamCipher;
2956             case block:  GenericBlockCipher;
2957         } fragment;
2958     } TLSCiphertext;
2960     stream-ciphered struct {
2961         opaque content[TLSCompressed.length];
2962         opaque MAC[CipherSpec.hash_size];
2963     } GenericStreamCipher;
2965     block-ciphered struct {
2966         opaque IV[CipherSpec.block_length];
2970 Dierks & Rescorla            Standards Track                    [Page 55]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
2973         opaque content[TLSCompressed.length];
2974         opaque MAC[CipherSpec.hash_size];
2975         uint8 padding[GenericBlockCipher.padding_length];
2976         uint8 padding_length;
2977     } GenericBlockCipher;
2979 A.2. Change cipher specs message
2981     struct {
2982         enum { change_cipher_spec(1), (255) } type;
2983     } ChangeCipherSpec;
2985 A.3. Alert messages
2987     enum { warning(1), fatal(2), (255) } AlertLevel;
2989         enum {
2990             close_notify(0),
2991             unexpected_message(10),
2992             bad_record_mac(20),
2993             decryption_failed(21),
2994             record_overflow(22),
2995             decompression_failure(30),
2996             handshake_failure(40),
2997             no_certificate_RESERVED (41),
2998             bad_certificate(42),
2999             unsupported_certificate(43),
3000             certificate_revoked(44),
3001             certificate_expired(45),
3002             certificate_unknown(46),
3003             illegal_parameter(47),
3004             unknown_ca(48),
3005             access_denied(49),
3006             decode_error(50),
3007             decrypt_error(51),
3008             export_restriction_RESERVED(60),
3009             protocol_version(70),
3010             insufficient_security(71),
3011             internal_error(80),
3012             user_canceled(90),
3013             no_renegotiation(100),
3014             (255)
3015         } AlertDescription;
3017     struct {
3018         AlertLevel level;
3019         AlertDescription description;
3020     } Alert;
3024 Dierks & Rescorla            Standards Track                    [Page 56]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
3027 A.4. Handshake protocol
3029     enum {
3030         hello_request(0), client_hello(1), server_hello(2),
3031         certificate(11), server_key_exchange (12),
3032         certificate_request(13), server_hello_done(14),
3033         certificate_verify(15), client_key_exchange(16),
3034         finished(20), (255)
3035     } HandshakeType;
3037     struct {
3038         HandshakeType msg_type;
3039         uint24 length;
3040         select (HandshakeType) {
3041             case hello_request:       HelloRequest;
3042             case client_hello:        ClientHello;
3043             case server_hello:        ServerHello;
3044             case certificate:         Certificate;
3045             case server_key_exchange: ServerKeyExchange;
3046             case certificate_request: CertificateRequest;
3047             case server_hello_done:   ServerHelloDone;
3048             case certificate_verify:  CertificateVerify;
3049             case client_key_exchange: ClientKeyExchange;
3050             case finished:            Finished;
3051         } body;
3052     } Handshake;
3054 A.4.1. Hello messages
3056     struct { } HelloRequest;
3058     struct {
3059         uint32 gmt_unix_time;
3060         opaque random_bytes[28];
3061     } Random;
3063     opaque SessionID<0..32>;
3065     uint8 CipherSuite[2];
3067     enum { null(0), (255) } CompressionMethod;
3069     struct {
3070         ProtocolVersion client_version;
3071         Random random;
3072         SessionID session_id;
3073         CipherSuite cipher_suites<2..2^16-1>;
3074         CompressionMethod compression_methods<1..2^8-1>;
3078 Dierks & Rescorla            Standards Track                    [Page 57]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
3081     } ClientHello;
3083     struct {
3084         ProtocolVersion server_version;
3085         Random random;
3086         SessionID session_id;
3087         CipherSuite cipher_suite;
3088         CompressionMethod compression_method;
3089     } ServerHello;
3091 A.4.2. Server authentication and key exchange messages
3093     opaque ASN.1Cert<2^24-1>;
3095     struct {
3096         ASN.1Cert certificate_list<0..2^24-1>;
3097     } Certificate;
3099     enum { rsa, diffie_hellman } KeyExchangeAlgorithm;
3101     struct {
3102         opaque RSA_modulus<1..2^16-1>;
3103         opaque RSA_exponent<1..2^16-1>;
3104     } ServerRSAParams;
3106     struct {
3107         opaque DH_p<1..2^16-1>;
3108         opaque DH_g<1..2^16-1>;
3109         opaque DH_Ys<1..2^16-1>;
3110     } ServerDHParams;
3112     struct {
3113         select (KeyExchangeAlgorithm) {
3114             case diffie_hellman:
3115                 ServerDHParams params;
3116                 Signature signed_params;
3117             case rsa:
3118                 ServerRSAParams params;
3119                 Signature signed_params;
3120         };
3121     } ServerKeyExchange;
3123     enum { anonymous, rsa, dsa } SignatureAlgorithm;
3125     struct {
3126         select (KeyExchangeAlgorithm) {
3127             case diffie_hellman:
3128                 ServerDHParams params;
3132 Dierks & Rescorla            Standards Track                    [Page 58]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
3135             case rsa:
3136                 ServerRSAParams params;
3137         };
3138      } ServerParams;
3140     select (SignatureAlgorithm)
3141     {   case anonymous: struct { };
3142         case rsa:
3143             digitally-signed struct {
3144                 opaque md5_hash[16];
3145                 opaque sha_hash[20];
3146             };
3147         case dsa:
3148             digitally-signed struct {
3149                 opaque sha_hash[20];
3150             };
3151     } Signature;
3153     enum {
3154         rsa_sign(1), dss_sign(2), rsa_fixed_dh(3), dss_fixed_dh(4),
3155      rsa_ephemeral_dh_RESERVED(5), dss_ephemeral_dh_RESERVED(6),
3156      fortezza_dms_RESERVED(20),
3157      (255)
3158     } ClientCertificateType;
3160     opaque DistinguishedName<1..2^16-1>;
3162     struct {
3163         ClientCertificateType certificate_types<1..2^8-1>;
3164         DistinguishedName certificate_authorities<0..2^16-1>;
3165     } CertificateRequest;
3167     struct { } ServerHelloDone;
3169 A.4.3. Client authentication and key exchange messages
3171     struct {
3172         select (KeyExchangeAlgorithm) {
3173             case rsa: EncryptedPreMasterSecret;
3174             case diffie_hellman: DiffieHellmanClientPublicValue;
3175         } exchange_keys;
3176     } ClientKeyExchange;
3178     struct {
3179         ProtocolVersion client_version;
3180         opaque random[46];
3181     } PreMasterSecret;
3186 Dierks & Rescorla            Standards Track                    [Page 59]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
3189     struct {
3190         public-key-encrypted PreMasterSecret pre_master_secret;
3191     } EncryptedPreMasterSecret;
3193     enum { implicit, explicit } PublicValueEncoding;
3195     struct {
3196         select (PublicValueEncoding) {
3197             case implicit: struct {};
3198             case explicit: opaque DH_Yc<1..2^16-1>;
3199         } dh_public;
3200     } ClientDiffieHellmanPublic;
3202     struct {
3203         Signature signature;
3204     } CertificateVerify;
3206 A.4.4. Handshake finalization message
3208     struct {
3209         opaque verify_data[12];
3210     } Finished;
3212 A.5. The CipherSuite
3214    The following values define the CipherSuite codes used in the client
3215    hello and server hello messages.
3217    A CipherSuite defines a cipher specification supported in TLS Version
3218    1.1.
3220    TLS_NULL_WITH_NULL_NULL is specified and is the initial state of a
3221    TLS connection during the first handshake on that channel, but must
3222    not be negotiated, as it provides no more protection than an
3223    unsecured connection.
3225     CipherSuite TLS_NULL_WITH_NULL_NULL                = { 0x00,0x00 };
3227    The following CipherSuite definitions require that the server provide
3228    an RSA certificate that can be used for key exchange. The server may
3229    request either an RSA or a DSS signature-capable certificate in the
3230    certificate request message.
3232     CipherSuite TLS_RSA_WITH_NULL_MD5                  = { 0x00,0x01 };
3233     CipherSuite TLS_RSA_WITH_NULL_SHA                  = { 0x00,0x02 };
3234     CipherSuite TLS_RSA_WITH_RC4_128_MD5               = { 0x00,0x04 };
3235     CipherSuite TLS_RSA_WITH_RC4_128_SHA               = { 0x00,0x05 };
3236     CipherSuite TLS_RSA_WITH_IDEA_CBC_SHA              = { 0x00,0x07 };
3240 Dierks & Rescorla            Standards Track                    [Page 60]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
3243     CipherSuite TLS_RSA_WITH_DES_CBC_SHA               = { 0x00,0x09 };
3244     CipherSuite TLS_RSA_WITH_3DES_EDE_CBC_SHA          = { 0x00,0x0A };
3246    The following CipherSuite definitions are used for server-
3247    authenticated (and optionally client-authenticated) Diffie-Hellman.
3248    DH denotes cipher suites in which the server's certificate contains
3249    the Diffie-Hellman parameters signed by the certificate authority
3250    (CA). DHE denotes ephemeral Diffie-Hellman, where the Diffie-Hellman
3251    parameters are signed by a DSS or RSA certificate, which has been
3252    signed by the CA. The signing algorithm used is specified after the
3253    DH or DHE parameter. The server can request an RSA or DSS signature-
3254    capable certificate from the client for client authentication or it
3255    may request a Diffie-Hellman certificate. Any Diffie-Hellman
3256    certificate provided by the client must use the parameters (group and
3257    generator) described by the server.
3259     CipherSuite TLS_DH_DSS_WITH_DES_CBC_SHA            = { 0x00,0x0C };
3260     CipherSuite TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA       = { 0x00,0x0D };
3261     CipherSuite TLS_DH_RSA_WITH_DES_CBC_SHA            = { 0x00,0x0F };
3262     CipherSuite TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA       = { 0x00,0x10 };
3263     CipherSuite TLS_DHE_DSS_WITH_DES_CBC_SHA           = { 0x00,0x12 };
3264     CipherSuite TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA      = { 0x00,0x13 };
3265     CipherSuite TLS_DHE_RSA_WITH_DES_CBC_SHA           = { 0x00,0x15 };
3266     CipherSuite TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA      = { 0x00,0x16 };
3268    The following cipher suites are used for completely anonymous Diffie-
3269    Hellman communications in which neither party is authenticated. Note
3270    that this mode is vulnerable to man-in-the-middle attacks and is
3271    therefore deprecated.
3273     CipherSuite TLS_DH_anon_WITH_RC4_128_MD5           = { 0x00,0x18 };
3274     CipherSuite TLS_DH_anon_WITH_DES_CBC_SHA           = { 0x00,0x1A };
3275     CipherSuite TLS_DH_anon_WITH_3DES_EDE_CBC_SHA      = { 0x00,0x1B };
3277    When SSLv3 and TLS 1.0 were designed, the United States restricted
3278    the export of cryptographic software containing certain strong
3279    encryption algorithms. A series of cipher suites were designed to
3280    operate at reduced key lengths in order to comply with those
3281    regulations. Due to advances in computer performance, these
3282    algorithms are now unacceptably weak and export restrictions have
3283    since been loosened. TLS 1.1 implementations MUST NOT negotiate these
3284    cipher suites in TLS 1.1 mode. However, for backward compatibility
3285    they may be offered in the ClientHello for use with TLS 1.0 or SSLv3
3286    only servers. TLS 1.1 clients MUST check that the server did not
3287    choose one of these cipher suites during the handshake. These
3288    ciphersuites are listed below for informational purposes and to
3289    reserve the numbers.
3294 Dierks & Rescorla            Standards Track                    [Page 61]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
3297     CipherSuite TLS_RSA_EXPORT_WITH_RC4_40_MD5         = { 0x00,0x03 };
3298     CipherSuite TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5     = { 0x00,0x06 };
3299     CipherSuite TLS_RSA_EXPORT_WITH_DES40_CBC_SHA      = { 0x00,0x08 };
3300     CipherSuite TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA   = { 0x00,0x0B };
3301     CipherSuite TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA   = { 0x00,0x0E };
3302     CipherSuite TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA  = { 0x00,0x11 };
3303     CipherSuite TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA  = { 0x00,0x14 };
3304     CipherSuite TLS_DH_anon_EXPORT_WITH_RC4_40_MD5     = { 0x00,0x17 };
3305     CipherSuite TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA  = { 0x00,0x19 };
3307    The following cipher suites were defined in [TLSKRB] and are included
3308    here for completeness. See [TLSKRB] for details:
3310     CipherSuite      TLS_KRB5_WITH_DES_CBC_SHA            = { 0x00,0x1E };
3311     CipherSuite      TLS_KRB5_WITH_3DES_EDE_CBC_SHA       = { 0x00,0x1F };
3312     CipherSuite      TLS_KRB5_WITH_RC4_128_SHA            = { 0x00,0x20 };
3313     CipherSuite      TLS_KRB5_WITH_IDEA_CBC_SHA           = { 0x00,0x21 };
3314     CipherSuite      TLS_KRB5_WITH_DES_CBC_MD5            = { 0x00,0x22 };
3315     CipherSuite      TLS_KRB5_WITH_3DES_EDE_CBC_MD5       = { 0x00,0x23 };
3316     CipherSuite      TLS_KRB5_WITH_RC4_128_MD5            = { 0x00,0x24 };
3317     CipherSuite      TLS_KRB5_WITH_IDEA_CBC_MD5           = { 0x00,0x25 };
3319    The following exportable cipher suites were defined in [TLSKRB] and
3320    are included here for completeness. TLS 1.1 implementations MUST NOT
3321    negotiate these cipher suites.
3323     CipherSuite      TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA  = { 0x00,0x26
3324    };
3325     CipherSuite      TLS_KRB5_EXPORT_WITH_RC2_CBC_40_SHA  = { 0x00,0x27
3326    };
3327     CipherSuite      TLS_KRB5_EXPORT_WITH_RC4_40_SHA      = { 0x00,0x28
3328    };
3329     CipherSuite      TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5  = { 0x00,0x29
3330    };
3331     CipherSuite      TLS_KRB5_EXPORT_WITH_RC2_CBC_40_MD5  = { 0x00,0x2A
3332    };
3333     CipherSuite      TLS_KRB5_EXPORT_WITH_RC4_40_MD5      = { 0x00,0x2B
3334    };
3336    The following cipher suites were defined in [TLSAES] and are included
3337    here for completeness. See [TLSAES] for details:
3339       CipherSuite TLS_RSA_WITH_AES_128_CBC_SHA      = { 0x00, 0x2F };
3340       CipherSuite TLS_DH_DSS_WITH_AES_128_CBC_SHA   = { 0x00, 0x30 };
3341       CipherSuite TLS_DH_RSA_WITH_AES_128_CBC_SHA   = { 0x00, 0x31 };
3342       CipherSuite TLS_DHE_DSS_WITH_AES_128_CBC_SHA  = { 0x00, 0x32 };
3343       CipherSuite TLS_DHE_RSA_WITH_AES_128_CBC_SHA  = { 0x00, 0x33 };
3344       CipherSuite TLS_DH_anon_WITH_AES_128_CBC_SHA  = { 0x00, 0x34 };
3348 Dierks & Rescorla            Standards Track                    [Page 62]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
3351       CipherSuite TLS_RSA_WITH_AES_256_CBC_SHA      = { 0x00, 0x35 };
3352       CipherSuite TLS_DH_DSS_WITH_AES_256_CBC_SHA   = { 0x00, 0x36 };
3353       CipherSuite TLS_DH_RSA_WITH_AES_256_CBC_SHA   = { 0x00, 0x37 };
3354       CipherSuite TLS_DHE_DSS_WITH_AES_256_CBC_SHA  = { 0x00, 0x38 };
3355       CipherSuite TLS_DHE_RSA_WITH_AES_256_CBC_SHA  = { 0x00, 0x39 };
3356       CipherSuite TLS_DH_anon_WITH_AES_256_CBC_SHA  = { 0x00, 0x3A };
3358  The cipher suite space is divided into three regions:
3360        1. Cipher suite values with first byte 0x00 (zero)
3361           through decimal 191 (0xBF) inclusive are reserved for the IETF
3362           Standards Track protocols.
3364        2. Cipher suite values with first byte decimal 192 (0xC0)
3365           through decimal 254 (0xFE) inclusive are reserved
3366           for assignment for non-Standards Track methods.
3368        3. Cipher suite values with first byte 0xFF are
3369           reserved for private use.
3370    Additional information describing the role of IANA in the allocation
3371    of cipher suite code points is described in Section 11.
3373  Note: The cipher suite values { 0x00, 0x1C } and { 0x00, 0x1D } are
3374    reserved to avoid collision with Fortezza-based cipher suites in SSL
3375    3.
3377 A.6. The Security Parameters
3379    These security parameters are determined by the TLS Handshake
3380    Protocol and provided as parameters to the TLS Record Layer in order
3381    to initialize a connection state. SecurityParameters includes:
3383        enum { null(0), (255) } CompressionMethod;
3385        enum { server, client } ConnectionEnd;
3387        enum { null, rc4, rc2, des, 3des, des40, idea }
3388        BulkCipherAlgorithm;
3390        enum { stream, block } CipherType;
3392        enum { null, md5, sha } MACAlgorithm;
3394    /* The algorithms specified in CompressionMethod,
3395    BulkCipherAlgorithm, and MACAlgorithm may be added to. */
3397        struct {
3398            ConnectionEnd entity;
3402 Dierks & Rescorla            Standards Track                    [Page 63]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
3405            BulkCipherAlgorithm bulk_cipher_algorithm;
3406            CipherType cipher_type;
3407            uint8 key_size;
3408            uint8 key_material_length;
3409            MACAlgorithm mac_algorithm;
3410            uint8 hash_size;
3411            CompressionMethod compression_algorithm;
3412            opaque master_secret[48];
3413            opaque client_random[32];
3414            opaque server_random[32];
3415        } SecurityParameters;
3456 Dierks & Rescorla            Standards Track                    [Page 64]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
3459 B. Glossary
3461    application protocol
3462        An application protocol is a protocol that normally layers
3463        directly on top of the transport layer (e.g., TCP/IP). Examples
3464        include HTTP, TELNET, FTP, and SMTP.
3466    asymmetric cipher
3467        See public key cryptography.
3469    authentication
3470        Authentication is the ability of one entity to determine the
3471        identity of another entity.
3473    block cipher
3474        A block cipher is an algorithm that operates on plaintext in
3475        groups of bits, called blocks. 64 bits is a common block size.
3477    bulk cipher
3478        A symmetric encryption algorithm used to encrypt large quantities
3479        of data.
3481    cipher block chaining (CBC)
3482        CBC is a mode in which every plaintext block encrypted with a
3483        block cipher is first exclusive-ORed with the previous ciphertext
3484        block (or, in the case of the first block, with the
3485        initialization vector). For decryption, every block is first
3486        decrypted, then exclusive-ORed with the previous ciphertext block
3487        (or IV).
3489    certificate
3490        As part of the X.509 protocol (a.k.a. ISO Authentication
3491        framework), certificates are assigned by a trusted Certificate
3492        Authority and provide a strong binding between a party's identity
3493        or some other attributes and its public key.
3495    client
3496        The application entity that initiates a TLS connection to a
3497        server. This may or may not imply that the client initiated the
3498        underlying transport connection. The primary operational
3499        difference between the server and client is that the server is
3500        generally authenticated, while the client is only optionally
3501        authenticated.
3503    client write key
3504        The key used to encrypt data written by the client.
3510 Dierks & Rescorla            Standards Track                    [Page 65]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
3513    client write MAC secret
3514        The secret data used to authenticate data written by the client.
3516    connection
3517        A connection is a transport (in the OSI layering model
3518        definition) that provides a suitable type of service. For TLS,
3519        such connections are peer to peer relationships. The connections
3520        are transient. Every connection is associated with one session.
3522    Data Encryption Standard
3523        DES is a very widely used symmetric encryption algorithm. DES is
3524        a block cipher with a 56 bit key and an 8 byte block size. Note
3525        that in TLS, for key generation purposes, DES is treated as
3526        having an 8 byte key length (64 bits), but it still only provides
3527        56 bits of protection. (The low bit of each key byte is presumed
3528        to be set to produce odd parity in that key byte.) DES can also
3529        be operated in a mode where three independent keys and three
3530        encryptions are used for each block of data; this uses 168 bits
3531        of key (24 bytes in the TLS key generation method) and provides
3532        the equivalent of 112 bits of security. [DES], [3DES]
3534    Digital Signature Standard (DSS)
3535        A standard for digital signing, including the Digital Signing
3536        Algorithm, approved by the National Institute of Standards and
3537        Technology, defined in NIST FIPS PUB 186, "Digital Signature
3538        Standard," published May, 1994 by the U.S. Dept. of Commerce.
3539        [DSS]
3541    digital signatures
3542        Digital signatures utilize public key cryptography and one-way
3543        hash functions to produce a signature of the data that can be
3544        authenticated, and is difficult to forge or repudiate.
3546    handshake
3547        An initial negotiation between client and server that establishes
3548        the parameters of their transactions.
3550    Initialization Vector (IV)
3551        When a block cipher is used in CBC mode, the initialization
3552        vector is exclusive-ORed with the first plaintext block prior to
3553        encryption.
3555    IDEA
3556        A 64-bit block cipher designed by Xuejia Lai and James Massey.
3557        [IDEA]
3564 Dierks & Rescorla            Standards Track                    [Page 66]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
3567    Message Authentication Code (MAC)
3568        A Message Authentication Code is a one-way hash computed from a
3569        message and some secret data. It is difficult to forge without
3570        knowing the secret data. Its purpose is to detect if the message
3571        has been altered.
3573    master secret
3574        Secure secret data used for generating encryption keys, MAC
3575        secrets, and IVs.
3577    MD5
3578        MD5 is a secure hashing function that converts an arbitrarily
3579        long data stream into a digest of fixed size (16 bytes). [MD5]
3581    public key cryptography
3582        A class of cryptographic techniques employing two-key ciphers.
3583        Messages encrypted with the public key can only be decrypted with
3584        the associated private key. Conversely, messages signed with the
3585        private key can be verified with the public key.
3587    one-way hash function
3588        A one-way transformation that converts an arbitrary amount of
3589        data into a fixed-length hash. It is computationally hard to
3590        reverse the transformation or to find collisions. MD5 and SHA are
3591        examples of one-way hash functions.
3593    RC2
3594        A block cipher developed by Ron Rivest at RSA Data Security, Inc.
3595        [RSADSI] described in [RC2].
3597    RC4
3598        A stream cipher invented by Ron Rivest. A compatible cipher is
3599        described in [RC4].
3601    RSA
3602        A very widely used public-key algorithm that can be used for
3603        either encryption or digital signing. [RSA]
3605    server
3606        The server is the application entity that responds to requests
3607        for connections from clients. See also under client.
3609    session
3610        A TLS session is an association between a client and a server.
3611        Sessions are created by the handshake protocol. Sessions define a
3612        set of cryptographic security parameters, which can be shared
3613        among multiple connections. Sessions are used to avoid the
3614        expensive negotiation of new security parameters for each
3618 Dierks & Rescorla            Standards Track                    [Page 67]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
3621        connection.
3623    session identifier
3624        A session identifier is a value generated by a server that
3625        identifies a particular session.
3627    server write key
3628        The key used to encrypt data written by the server.
3630    server write MAC secret
3631        The secret data used to authenticate data written by the server.
3633    SHA
3634        The Secure Hash Algorithm is defined in FIPS PUB 180-2. It
3635        produces a 20-byte output. Note that all references to SHA
3636        actually use the modified SHA-1 algorithm. [SHA]
3638    SSL
3639        Netscape's Secure Socket Layer protocol [SSL3]. TLS is based on
3640        SSL Version 3.0
3642    stream cipher
3643        An encryption algorithm that converts a key into a
3644        cryptographically-strong keystream, which is then exclusive-ORed
3645        with the plaintext.
3647    symmetric cipher
3648        See bulk cipher.
3650    Transport Layer Security (TLS)
3651        This protocol; also, the Transport Layer Security working group
3652        of the Internet Engineering Task Force (IETF). See "Comments" at
3653        the end of this document.
3672 Dierks & Rescorla            Standards Track                    [Page 68]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
3675 C. CipherSuite definitions
3677 CipherSuite                             Key          Cipher      Hash
3678                                         Exchange
3680 TLS_NULL_WITH_NULL_NULL                 NULL           NULL        NULL
3681 TLS_RSA_WITH_NULL_MD5                   RSA            NULL         MD5
3682 TLS_RSA_WITH_NULL_SHA                   RSA            NULL         SHA
3683 TLS_RSA_WITH_RC4_128_MD5                RSA            RC4_128      MD5
3684 TLS_RSA_WITH_RC4_128_SHA                RSA            RC4_128      SHA
3685 TLS_RSA_WITH_IDEA_CBC_SHA               RSA            IDEA_CBC     SHA
3686 TLS_RSA_WITH_DES_CBC_SHA                RSA            DES_CBC      SHA
3687 TLS_RSA_WITH_3DES_EDE_CBC_SHA           RSA            3DES_EDE_CBC SHA
3688 TLS_DH_DSS_WITH_DES_CBC_SHA             DH_DSS         DES_CBC      SHA
3689 TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA        DH_DSS         3DES_EDE_CBC SHA
3690 TLS_DH_RSA_WITH_DES_CBC_SHA             DH_RSA         DES_CBC      SHA
3691 TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA        DH_RSA         3DES_EDE_CBC SHA
3692 TLS_DHE_DSS_WITH_DES_CBC_SHA            DHE_DSS        DES_CBC      SHA
3693 TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA       DHE_DSS        3DES_EDE_CBC SHA
3694 TLS_DHE_RSA_WITH_DES_CBC_SHA            DHE_RSA        DES_CBC      SHA
3695 TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA       DHE_RSA        3DES_EDE_CBC SHA
3696 TLS_DH_anon_WITH_RC4_128_MD5            DH_anon        RC4_128      MD5
3697 TLS_DH_anon_WITH_DES_CBC_SHA            DH_anon        DES_CBC      SHA
3698 TLS_DH_anon_WITH_3DES_EDE_CBC_SHA       DH_anon        3DES_EDE_CBC SHA
3700       Key
3701       Exchange
3702       Algorithm       Description                        Key size limit
3704       DHE_DSS         Ephemeral DH with DSS signatures   None
3705       DHE_RSA         Ephemeral DH with RSA signatures   None
3706       DH_anon         Anonymous DH, no signatures        None
3707       DH_DSS          DH with DSS-based certificates     None
3708       DH_RSA          DH with RSA-based certificates     None
3709                                                          RSA = none
3710       NULL            No key exchange                    N/A
3711       RSA             RSA key exchange                   None
3713                          Key      Expanded     IV    Block
3714     Cipher       Type  Material Key Material   Size   Size
3716     NULL         Stream   0          0         0     N/A
3717     IDEA_CBC     Block   16         16         8      8
3718     RC2_CBC_40   Block    5         16         8      8
3719     RC4_40       Stream   5         16         0     N/A
3720     RC4_128      Stream  16         16         0     N/A
3721     DES40_CBC    Block    5          8         8      8
3722     DES_CBC      Block    8          8         8      8
3726 Dierks & Rescorla            Standards Track                    [Page 69]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
3729     3DES_EDE_CBC Block   24         24         8      8
3731    Type
3732        Indicates whether this is a stream cipher or a block cipher
3733        running in CBC mode.
3735    Key Material
3736        The number of bytes from the key_block that are used for
3737        generating the write keys.
3739    Expanded Key Material
3740        The number of bytes actually fed into the encryption algorithm
3742    IV Size
3743        How much data needs to be generated for the initialization
3744        vector. Zero for stream ciphers; equal to the block size for
3745        block ciphers.
3747    Block Size
3748        The amount of data a block cipher enciphers in one chunk; a
3749        block cipher running in CBC mode can only encrypt an even
3750        multiple of its block size.
3752       Hash      Hash      Padding
3753     function    Size       Size
3754       NULL       0          0
3755       MD5        16         48
3756       SHA        20         40
3780 Dierks & Rescorla            Standards Track                    [Page 70]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
3783 D. Implementation Notes
3785    The TLS protocol cannot prevent many common security mistakes. This
3786    section provides several recommendations to assist implementors.
3788 D.1 Random Number Generation and Seeding
3790    TLS requires a cryptographically-secure pseudorandom number generator
3791    (PRNG). Care must be taken in designing and seeding PRNGs.  PRNGs
3792    based on secure hash operations, most notably MD5 and/or SHA, are
3793    acceptable, but cannot provide more security than the size of the
3794    random number generator state. (For example, MD5-based PRNGs usually
3795    provide 128 bits of state.)
3797    To estimate the amount of seed material being produced, add the
3798    number of bits of unpredictable information in each seed byte. For
3799    example, keystroke timing values taken from a PC compatible's 18.2 Hz
3800    timer provide 1 or 2 secure bits each, even though the total size of
3801    the counter value is 16 bits or more. To seed a 128-bit PRNG, one
3802    would thus require approximately 100 such timer values.
3804    [RANDOM] provides guidance on the generation of random values.
3806 D.2 Certificates and authentication
3808    Implementations are responsible for verifying the integrity of
3809    certificates and should generally support certificate revocation
3810    messages. Certificates should always be verified to ensure proper
3811    signing by a trusted Certificate Authority (CA). The selection and
3812    addition of trusted CAs should be done very carefully. Users should
3813    be able to view information about the certificate and root CA.
3815 D.3 CipherSuites
3817    TLS supports a range of key sizes and security levels, including some
3818    which provide no or minimal security. A proper implementation will
3819    probably not support many cipher suites. For example, 40-bit
3820    encryption is easily broken, so implementations requiring strong
3821    security should not allow 40-bit keys. Similarly, anonymous Diffie-
3822    Hellman is strongly discouraged because it cannot prevent man-in-the-
3823    middle attacks. Applications should also enforce minimum and maximum
3824    key sizes. For example, certificate chains containing 512-bit RSA
3825    keys or signatures are not appropriate for high-security
3826    applications.
3834 Dierks & Rescorla            Standards Track                    [Page 71]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
3837 E. Backward Compatibility With SSL
3839    For historical reasons and in order to avoid a profligate consumption
3840    of reserved port numbers, application protocols which are secured by
3841    TLS 1.1, TLS 1.0, SSL 3.0, and SSL 2.0 all frequently share the same
3842    connection port: for example, the https protocol (HTTP secured by SSL
3843    or TLS) uses port 443 regardless of which security protocol it is
3844    using. Thus, some mechanism must be determined to distinguish and
3845    negotiate among the various protocols.
3847    TLS versions 1.1, 1.0, and SSL 3.0 are very similar; thus, supporting
3848    both is easy. TLS clients who wish to negotiate with such older
3849    servers SHOULD send client hello messages using the SSL 3.0 record
3850    format and client hello structure, sending {3, 2} for the version
3851    field to note that they support TLS 1.1. If the server supports only
3852    TLS 1.0 or SSL 3.0, it will respond with a downrev 3.0 server hello;
3853    if it supports TLS 1.1 it will respond with a TLS 1.1 server hello.
3854    The negotiation then proceeds as appropriate for the negotiated
3855    protocol.
3857    Similarly, a TLS 1.1  server which wishes to interoperate with TLS
3858    1.0 or SSL 3.0 clients SHOULD accept SSL 3.0 client hello messages
3859    and respond with a SSL 3.0 server hello if an SSL 3.0 client hello
3860    with a version field of {3, 0} is received, denoting that this client
3861    does not support TLS. Similarly, if a SSL 3.0 or TLS 1.0 hello with a
3862    version field of {3, 1} is received, the server SHOULD respond with a
3863    TLS 1.0 hello with a version field of {3, 1}.
3865    Whenever a client already knows the highest protocol known to a
3866    server (for example, when resuming a session), it SHOULD initiate the
3867    connection in that native protocol.
3869    TLS 1.1 clients that support SSL Version 2.0 servers MUST send SSL
3870    Version 2.0 client hello messages [SSL2]. TLS servers SHOULD accept
3871    either client hello format if they wish to support SSL 2.0 clients on
3872    the same connection port. The only deviations from the Version 2.0
3873    specification are the ability to specify a version with a value of
3874    three and the support for more ciphering types in the CipherSpec.
3876  Warning: The ability to send Version 2.0 client hello messages will be
3877           phased out with all due haste. Implementors SHOULD make every
3878           effort to move forward as quickly as possible. Version 3.0
3879           provides better mechanisms for moving to newer versions.
3881    The following cipher specifications are carryovers from SSL Version
3882    2.0. These are assumed to use RSA for key exchange and
3883    authentication.
3888 Dierks & Rescorla            Standards Track                    [Page 72]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
3891        V2CipherSpec TLS_RC4_128_WITH_MD5          = { 0x01,0x00,0x80 };
3892        V2CipherSpec TLS_RC4_128_EXPORT40_WITH_MD5 = { 0x02,0x00,0x80 };
3893        V2CipherSpec TLS_RC2_CBC_128_CBC_WITH_MD5  = { 0x03,0x00,0x80 };
3894        V2CipherSpec TLS_RC2_CBC_128_CBC_EXPORT40_WITH_MD5
3895                                                   = { 0x04,0x00,0x80 };
3896        V2CipherSpec TLS_IDEA_128_CBC_WITH_MD5     = { 0x05,0x00,0x80 };
3897        V2CipherSpec TLS_DES_64_CBC_WITH_MD5       = { 0x06,0x00,0x40 };
3898        V2CipherSpec TLS_DES_192_EDE3_CBC_WITH_MD5 = { 0x07,0x00,0xC0 };
3900    Cipher specifications native to TLS can be included in Version 2.0
3901    client hello messages using the syntax below. Any V2CipherSpec
3902    element with its first byte equal to zero will be ignored by Version
3903    2.0 servers. Clients sending any of the above V2CipherSpecs SHOULD
3904    also include the TLS equivalent (see Appendix A.5):
3906        V2CipherSpec (see TLS name) = { 0x00, CipherSuite };
3908  Note: TLS 1.1 clients may generate the SSLv2 EXPORT cipher suites in
3909    handshakes for backward compatibility but MUST NOT negotiate them in
3910    TLS 1.1 mode.
3912 E.1. Version 2 client hello
3914    The Version 2.0 client hello message is presented below using this
3915    document's presentation model. The true definition is still assumed
3916    to be the SSL Version 2.0 specification. Note that this message MUST
3917    be sent directly on the wire, not wrapped as an SSLv3 record
3919        uint8 V2CipherSpec[3];
3921        struct {
3922            uint16 msg_length;
3923            uint8 msg_type;
3924            Version version;
3925            uint16 cipher_spec_length;
3926            uint16 session_id_length;
3927            uint16 challenge_length;
3928            V2CipherSpec cipher_specs[V2ClientHello.cipher_spec_length];
3929            opaque session_id[V2ClientHello.session_id_length];
3930            opaque challenge[V2ClientHello.challenge_length;
3931        } V2ClientHello;
3933    msg_length
3934        This field is the length of the following data in bytes. The high
3935        bit MUST be 1 and is not part of the length.
3937    msg_type
3938        This field, in conjunction with the version field, identifies a
3942 Dierks & Rescorla            Standards Track                    [Page 73]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
3945        version 2 client hello message. The value SHOULD be one (1).
3947    version
3948        The highest version of the protocol supported by the client
3949        (equals ProtocolVersion.version, see Appendix A.1).
3951    cipher_spec_length
3952        This field is the total length of the field cipher_specs. It
3953        cannot be zero and MUST be a multiple of the V2CipherSpec length
3954        (3).
3956    session_id_length
3957        This field MUST have a value of zero.
3959    challenge_length
3960        The length in bytes of the client's challenge to the server to
3961        authenticate itself. When using the SSLv2 backward compatible
3962        handshake the client MUST use a 32-byte challenge.
3964    cipher_specs
3965        This is a list of all CipherSpecs the client is willing and able
3966        to use. There MUST be at least one CipherSpec acceptable to the
3967        server.
3969    session_id
3970        This field MUST be empty.
3972    challenge
3973        The client challenge to the server for the server to identify
3974        itself is a (nearly) arbitrary length random. The TLS server will
3975        right justify the challenge data to become the ClientHello.random
3976        data (padded with leading zeroes, if necessary), as specified in
3977        this protocol specification. If the length of the challenge is
3978        greater than 32 bytes, only the last 32 bytes are used. It is
3979        legitimate (but not necessary) for a V3 server to reject a V2
3980        ClientHello that has fewer than 16 bytes of challenge data.
3982  Note: Requests to resume a TLS session MUST use a TLS client hello.
3984 E.2. Avoiding man-in-the-middle version rollback
3986    When TLS clients fall back to Version 2.0 compatibility mode, they
3987    SHOULD use special PKCS #1 block formatting. This is done so that TLS
3988    servers will reject Version 2.0 sessions with TLS-capable clients.
3990    When TLS clients are in Version 2.0 compatibility mode, they set the
3991    right-hand (least-significant) 8 random bytes of the PKCS padding
3992    (not including the terminal null of the padding) for the RSA
3996 Dierks & Rescorla            Standards Track                    [Page 74]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
3999    encryption of the ENCRYPTED-KEY-DATA field of the CLIENT-MASTER-KEY
4000    to 0x03 (the other padding bytes are random). After decrypting the
4001    ENCRYPTED-KEY-DATA field, servers that support TLS SHOULD issue an
4002    error if these eight padding bytes are 0x03. Version 2.0 servers
4003    receiving blocks padded in this manner will proceed normally.
4050 Dierks & Rescorla            Standards Track                    [Page 75]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
4053 F. Security analysis
4055    The TLS protocol is designed to establish a secure connection between
4056    a client and a server communicating over an insecure channel. This
4057    document makes several traditional assumptions, including that
4058    attackers have substantial computational resources and cannot obtain
4059    secret information from sources outside the protocol. Attackers are
4060    assumed to have the ability to capture, modify, delete, replay, and
4061    otherwise tamper with messages sent over the communication channel.
4062    This appendix outlines how TLS has been designed to resist a variety
4063    of attacks.
4065 F.1. Handshake protocol
4067    The handshake protocol is responsible for selecting a CipherSpec and
4068    generating a Master Secret, which together comprise the primary
4069    cryptographic parameters associated with a secure session. The
4070    handshake protocol can also optionally authenticate parties who have
4071    certificates signed by a trusted certificate authority.
4073 F.1.1. Authentication and key exchange
4075    TLS supports three authentication modes: authentication of both
4076    parties, server authentication with an unauthenticated client, and
4077    total anonymity. Whenever the server is authenticated, the channel is
4078    secure against man-in-the-middle attacks, but completely anonymous
4079    sessions are inherently vulnerable to such attacks.  Anonymous
4080    servers cannot authenticate clients. If the server is authenticated,
4081    its certificate message must provide a valid certificate chain
4082    leading to an acceptable certificate authority.  Similarly,
4083    authenticated clients must supply an acceptable certificate to the
4084    server. Each party is responsible for verifying that the other's
4085    certificate is valid and has not expired or been revoked.
4087    The general goal of the key exchange process is to create a
4088    pre_master_secret known to the communicating parties and not to
4089    attackers. The pre_master_secret will be used to generate the
4090    master_secret (see Section 8.1). The master_secret is required to
4091    generate the finished messages, encryption keys, and MAC secrets (see
4092    Sections 7.4.8, 7.4.9 and 6.3). By sending a correct finished
4093    message, parties thus prove that they know the correct
4094    pre_master_secret.
4096 F.1.1.1. Anonymous key exchange
4098    Completely anonymous sessions can be established using RSA or Diffie-
4099    Hellman for key exchange. With anonymous RSA, the client encrypts a
4100    pre_master_secret with the server's uncertified public key extracted
4104 Dierks & Rescorla            Standards Track                    [Page 76]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
4107    from the server key exchange message. The result is sent in a client
4108    key exchange message. Since eavesdroppers do not know the server's
4109    private key, it will be infeasible for them to decode the
4110    pre_master_secret.
4112    Note: No anonymous RSA Cipher Suites are defined in this document.
4114    With Diffie-Hellman, the server's public parameters are contained in
4115    the server key exchange message and the client's are sent in the
4116    client key exchange message. Eavesdroppers who do not know the
4117    private values should not be able to find the Diffie-Hellman result
4118    (i.e. the pre_master_secret).
4120  Warning: Completely anonymous connections only provide protection
4121           against passive eavesdropping. Unless an independent tamper-
4122           proof channel is used to verify that the finished messages
4123           were not replaced by an attacker, server authentication is
4124           required in environments where active man-in-the-middle
4125           attacks are a concern.
4127 F.1.1.2. RSA key exchange and authentication
4129    With RSA, key exchange and server authentication are combined. The
4130    public key may be either contained in the server's certificate or may
4131    be a temporary RSA key sent in a server key exchange message.  When
4132    temporary RSA keys are used, they are signed by the server's RSA
4133    certificate. The signature includes the current ClientHello.random,
4134    so old signatures and temporary keys cannot be replayed. Servers may
4135    use a single temporary RSA key for multiple negotiation sessions.
4137  Note: The temporary RSA key option is useful if servers need large
4138        certificates but must comply with government-imposed size limits
4139        on keys used for key exchange.
4141    Note that if ephemeral RSA is not used, compromise of the server's
4142    static RSA key results in a loss of confidentiality for all sessions
4143    protected under that static key. TLS users desiring Perfect Forward
4144    Secrecy should use DHE cipher suites. The damage done by exposure of
4145    a private key can be limited by changing one's private key (and
4146    certificate) frequently.
4148    After verifying the server's certificate, the client encrypts a
4149    pre_master_secret with the server's public key. By successfully
4150    decoding the pre_master_secret and producing a correct finished
4151    message, the server demonstrates that it knows the private key
4152    corresponding to the server certificate.
4154    When RSA is used for key exchange, clients are authenticated using
4158 Dierks & Rescorla            Standards Track                    [Page 77]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
4161    the certificate verify message (see Section 7.4.8). The client signs
4162    a value derived from the master_secret and all preceding handshake
4163    messages. These handshake messages include the server certificate,
4164    which binds the signature to the server, and ServerHello.random,
4165    which binds the signature to the current handshake process.
4167 F.1.1.3. Diffie-Hellman key exchange with authentication
4169    When Diffie-Hellman key exchange is used, the server can either
4170    supply a certificate containing fixed Diffie-Hellman parameters or
4171    can use the server key exchange message to send a set of temporary
4172    Diffie-Hellman parameters signed with a DSS or RSA certificate.
4173    Temporary parameters are hashed with the hello.random values before
4174    signing to ensure that attackers do not replay old parameters. In
4175    either case, the client can verify the certificate or signature to
4176    ensure that the parameters belong to the server.
4178    If the client has a certificate containing fixed Diffie-Hellman
4179    parameters, its certificate contains the information required to
4180    complete the key exchange. Note that in this case the client and
4181    server will generate the same Diffie-Hellman result (i.e.,
4182    pre_master_secret) every time they communicate. To prevent the
4183    pre_master_secret from staying in memory any longer than necessary,
4184    it should be converted into the master_secret as soon as possible.
4185    Client Diffie-Hellman parameters must be compatible with those
4186    supplied by the server for the key exchange to work.
4188    If the client has a standard DSS or RSA certificate or is
4189    unauthenticated, it sends a set of temporary parameters to the server
4190    in the client key exchange message, then optionally uses a
4191    certificate verify message to authenticate itself.
4193    If the same DH keypair is to be used for multiple handshakes, either
4194    because the client or server has a certificate containing a fixed DH
4195    keypair or because the server is reusing DH keys, care must be taken
4196    to prevent small subgroup attacks. Implementations SHOULD follow the
4197    guidelines found in [SUBGROUP].
4199    Small subgroup attacks are most easily avoided by using one of the
4200    DHE ciphersuites and generating a fresh DH private key (X) for each
4201    handshake. If a suitable base (such as 2) is chosen, g^X mod p can be
4202    computed very quickly so the performance cost is minimized.
4203    Additionally, using a fresh key for each handshake provides Perfect
4204    Forward Secrecy. Implementations SHOULD generate a new X for each
4205    handshake when using DHE ciphersuites.
4207 F.1.2. Version rollback attacks
4212 Dierks & Rescorla            Standards Track                    [Page 78]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
4215    Because TLS includes substantial improvements over SSL Version 2.0,
4216    attackers may try to make TLS-capable clients and servers fall back
4217    to Version 2.0. This attack can occur if (and only if) two TLS-
4218    capable parties use an SSL 2.0 handshake.
4220    Although the solution using non-random PKCS #1 block type 2 message
4221    padding is inelegant, it provides a reasonably secure way for Version
4222    3.0 servers to detect the attack. This solution is not secure against
4223    attackers who can brute force the key and substitute a new ENCRYPTED-
4224    KEY-DATA message containing the same key (but with normal padding)
4225    before the application specified wait threshold has expired. Parties
4226    concerned about attacks of this scale should not be using 40-bit
4227    encryption keys anyway. Altering the padding of the least-significant
4228    8 bytes of the PKCS padding does not impact security for the size of
4229    the signed hashes and RSA key lengths used in the protocol, since
4230    this is essentially equivalent to increasing the input block size by
4231    8 bytes.
4233 F.1.3. Detecting attacks against the handshake protocol
4235    An attacker might try to influence the handshake exchange to make the
4236    parties select different encryption algorithms than they would
4237    normally chooses.
4239    For this attack, an attacker must actively change one or more
4240    handshake messages. If this occurs, the client and server will
4241    compute different values for the handshake message hashes. As a
4242    result, the parties will not accept each others' finished messages.
4243    Without the master_secret, the attacker cannot repair the finished
4244    messages, so the attack will be discovered.
4246 F.1.4. Resuming sessions
4248    When a connection is established by resuming a session, new
4249    ClientHello.random and ServerHello.random values are hashed with the
4250    session's master_secret. Provided that the master_secret has not been
4251    compromised and that the secure hash operations used to produce the
4252    encryption keys and MAC secrets are secure, the connection should be
4253    secure and effectively independent from previous connections.
4254    Attackers cannot use known encryption keys or MAC secrets to
4255    compromise the master_secret without breaking the secure hash
4256    operations (which use both SHA and MD5).
4258    Sessions cannot be resumed unless both the client and server agree.
4259    If either party suspects that the session may have been compromised,
4260    or that certificates may have expired or been revoked, it should
4261    force a full handshake. An upper limit of 24 hours is suggested for
4262    session ID lifetimes, since an attacker who obtains a master_secret
4266 Dierks & Rescorla            Standards Track                    [Page 79]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
4269    may be able to impersonate the compromised party until the
4270    corresponding session ID is retired. Applications that may be run in
4271    relatively insecure environments should not write session IDs to
4272    stable storage.
4274 F.1.5. MD5 and SHA
4276    TLS uses hash functions very conservatively. Where possible, both MD5
4277    and SHA are used in tandem to ensure that non-catastrophic flaws in
4278    one algorithm will not break the overall protocol.
4280 F.2. Protecting application data
4282    The master_secret is hashed with the ClientHello.random and
4283    ServerHello.random to produce unique data encryption keys and MAC
4284    secrets for each connection.
4286    Outgoing data is protected with a MAC before transmission. To prevent
4287    message replay or modification attacks, the MAC is computed from the
4288    MAC secret, the sequence number, the message length, the message
4289    contents, and two fixed character strings. The message type field is
4290    necessary to ensure that messages intended for one TLS Record Layer
4291    client are not redirected to another. The sequence number ensures
4292    that attempts to delete or reorder messages will be detected. Since
4293    sequence numbers are 64-bits long, they should never overflow.
4294    Messages from one party cannot be inserted into the other's output,
4295    since they use independent MAC secrets. Similarly, the server-write
4296    and client-write keys are independent so stream cipher keys are used
4297    only once.
4299    If an attacker does break an encryption key, all messages encrypted
4300    with it can be read. Similarly, compromise of a MAC key can make
4301    message modification attacks possible. Because MACs are also
4302    encrypted, message-alteration attacks generally require breaking the
4303    encryption algorithm as well as the MAC.
4305  Note: MAC secrets may be larger than encryption keys, so messages can
4306        remain tamper resistant even if encryption keys are broken.
4308 F.3. Explicit IVs
4310        [CBCATT] describes a chosen plaintext attack on TLS that depends
4311        on knowing the IV for a record. Previous versions of TLS [TLS1.0]
4312        used the CBC residue of the previous record as the IV and
4313        therefore enabled this attack. This version uses an explicit IV
4314        in order to protect against this attack.
4320 Dierks & Rescorla            Standards Track                    [Page 80]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
4323 F.4 Security of Composite Cipher Modes
4325        TLS secures transmitted application data via the use of symmetric
4326        encryption and authentication functions defined in the negotiated
4327        ciphersuite.  The objective is to protect both the integrity  and
4328        confidentiality of the transmitted data from malicious actions by
4329        active attackers in the network.  It turns out that the order in
4330        which encryption and authentication functions are applied to the
4331        data plays an important role for achieving this goal [ENCAUTH].
4333        The most robust method, called encrypt-then-authenticate, first
4334        applies encryption to the data and then applies a MAC to the
4335        ciphertext.  This method ensures that the integrity and
4336        confidentiality goals are obtained with ANY pair of encryption
4337        and MAC functions provided that the former is secure against
4338        chosen plaintext attacks and the MAC is secure against chosen-
4339        message attacks.  TLS uses another method, called authenticate-
4340        then-encrypt, in which first a MAC is computed on the plaintext
4341        and then the concatenation of plaintext and MAC is encrypted.
4342        This method has been proven secure for CERTAIN combinations of
4343        encryption functions and MAC functions, but is not guaranteed to
4344        be secure in general. In particular, it has been shown that there
4345        exist perfectly secure encryption functions (secure even in the
4346        information theoretic sense) that combined with any secure MAC
4347        function fail to provide the confidentiality goal against an
4348        active attack.  Therefore, new ciphersuites and operation modes
4349        adopted into TLS need to be analyzed under the authenticate-then-
4350        encrypt method to verify that they achieve the stated integrity
4351        and confidentiality goals.
4353        Currently, the security of the authenticate-then-encrypt method
4354        has been proven for some important cases.  One is the case of
4355        stream ciphers in which a computationally unpredictable pad of
4356        the length of the message plus the length of the MAC tag is
4357        produced using a pseudo-random generator and this pad is xor-ed
4358        with the concatenation of plaintext and MAC tag.  The other is
4359        the case of CBC mode using a secure block cipher.  In this case,
4360        security can be shown if one applies one CBC encryption pass to
4361        the concatenation of plaintext and MAC and uses a new,
4362        independent and unpredictable, IV for each new pair of plaintext
4363        and MAC.  In previous versions of SSL, CBC mode was used properly
4364        EXCEPT that it used a predictable IV in the form of the last
4365        block of the previous ciphertext. This made TLS open to chosen
4366        plaintext attacks.  This verson of the protocol is immune to
4367        those attacks.  For exact details in the encryption modes proven
4368        secure see [ENCAUTH].
4374 Dierks & Rescorla            Standards Track                    [Page 81]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
4377 F.5 Denial of Service
4379        TLS is susceptible to a number of denial of service (DoS)
4380        attacks.  In particular, an attacker who initiates a large number
4381        of TCP connections can cause a server to consume large amounts of
4382        CPU doing RSA decryption. However, because TLS is generally used
4383        over TCP, it is difficult for the attacker to hide his point of
4384        origin if proper TCP SYN randomization is used [SEQNUM] by the
4385        TCP stack.
4387        Because TLS runs over TCP, it is also susceptible to a number of
4388        denial of service attacks on individual connections. In
4389        particular, attackers can forge RSTs, terminating connections, or
4390        forge partial TLS records, causing the connection to stall.
4391        These attacks cannot in general be defended against by a TCP-
4392        using protocol. Implementors or users who are concerned with this
4393        class of attack should use IPsec AH [AH] or ESP [ESP].
4395 F.6. Final notes
4397    For TLS to be able to provide a secure connection, both the client
4398    and server systems, keys, and applications must be secure. In
4399    addition, the implementation must be free of security errors.
4401    The system is only as strong as the weakest key exchange and
4402    authentication algorithm supported, and only trustworthy
4403    cryptographic functions should be used. Short public keys, 40-bit
4404    bulk encryption keys, and anonymous servers should be used with great
4405    caution. Implementations and users must be careful when deciding
4406    which certificates and certificate authorities are acceptable; a
4407    dishonest certificate authority can do tremendous damage.
4428 Dierks & Rescorla            Standards Track                    [Page 82]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
4431 Security Considerations
4433    Security issues are discussed throughout this memo, especially in
4434    Appendices D, E, and F.
4436 Normative References
4438    [3DES]   W. Tuchman, "Hellman Presents No Shortcut Solutions To DES,"
4439             IEEE Spectrum, v. 16, n. 7, July 1979, pp40-41.
4441    [DES]    ANSI X3.106, "American National Standard for Information
4442             Systems-Data Link Encryption," American National Standards
4443             Institute, 1983.
4445    [DSS]    NIST FIPS PUB 186-2, "Digital Signature Standard," National
4446             Institute of Standards and Technology, U.S. Department of
4447             Commerce, 2000.
4449    [HMAC]   Krawczyk, H., Bellare, M., and R. Canetti, "HMAC: Keyed-
4450             Hashing for Message Authentication," RFC 2104, February
4451             1997.
4453    [IDEA]   X. Lai, "On the Design and Security of Block Ciphers," ETH
4454             Series in Information Processing, v. 1, Konstanz: Hartung-
4455             Gorre Verlag, 1992.
4457    [MD2]    Kaliski, B., "The MD2 Message Digest Algorithm", RFC 1319,
4458             April 1992.
4460    [MD5]    Rivest, R., "The MD5 Message Digest Algorithm", RFC 1321,
4461             April 1992.
4463    [PKCS1]  J. Jonsson, B. Kaliski, "3447 Public-Key Cryptography
4464             Standards (PKCS) #1: RSA Cryptography Specifications Version
4465             2.1", RFC 3447, February 2003"
4467    [PKIX]   Housley, R., Ford, W., Polk, W. and D. Solo, "Internet
4468             Public Key Infrastructure: Part I: X.509 Certificate and CRL
4469             Profile", RFC 3280, April 2002.
4471    [RC2]    Rivest, R., "A Description of the RC2(r) Encryption
4472             Algorithm", RFC 2268, January 1998.
4474    [SCH]    B. Schneier. "Applied Cryptography: Protocols, Algorithms,
4475             and Source Code in C, 2ed", Published by John Wiley & Sons,
4476             Inc. 1996.
4482 Dierks & Rescorla            Standards Track                    [Page 83]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
4485    [SHA]    NIST FIPS PUB 180-2, "Secure Hash Standard," National
4486             Institute of Standards and Technology, U.S. Department of
4487             Commerce., August 2001.
4489    [REQ]    Bradner, S., "Key words for use in RFCs to Indicate
4490             Requirement Levels", BCP 14, RFC 2119, March 1997.
4492    [RFC2434] T. Narten, H. Alvestrand, "Guidelines for Writing an IANA
4493             Considerations Section in RFCs", RFC 3434, October 1998.
4495    [TLSAES] Chown, P. "Advanced Encryption Standard (AES) Ciphersuites
4496             for Transport Layer Security (TLS)", RFC 3268, Junr 2002.
4498    [TLSEXT] Blake-Wilson, S., Nystrom, M, Hopwood, D., Mikkelsen, J.,
4499             Wright, T., "Transport Layer Security (TLS) Extensions", RFC
4500             3546, June 2003.        [TLSKRB] A. Medvinsky, M. Hur,
4501             "Addition of Kerberos Cipher Suites to Transport Layer
4502             Security (TLS)", RFC 2712, October 1999.
4505 Informative References
4507    [AH]     Kent, S., and Atkinson, R., "IP Authentication Header", RFC
4508             2402, November 1998.
4510    [BLEI]   Bleichenbacher D., "Chosen Ciphertext Attacks against
4511             Protocols Based on RSA Encryption Standard PKCS #1" in
4512             Advances in Cryptology -- CRYPTO'98, LNCS vol. 1462, pages:
4513             1-12, 1998.
4515    [CBCATT] Moeller, B., "Security of CBC Ciphersuites in SSL/TLS:
4516             Problems and Countermeasures",
4517             http://www.openssl.org/~bodo/tls-cbc.txt.
4519    [CBCTIME] Canvel, B., "Password Interception in a SSL/TLS Channel",
4520             http://lasecwww.epfl.ch/memo_ssl.shtml, 2003.
4522    [ENCAUTH] Krawczyk, H., "The Order of Encryption and Authentication
4523             for Protecting Communications (Or: How Secure is SSL?)",
4524             Crypto 2001.
4526    [ESP]     Kent, S., and Atkinson, R., "IP Encapsulating Security
4527             Payload (ESP)", RFC 2406, November 1998.
4529    [FTP]    Postel J., and J. Reynolds, "File Transfer Protocol", STD 9,
4530             RFC 959, October 1985.
4532    [HTTP]   Berners-Lee, T., Fielding, R., and H. Frystyk, "Hypertext
4536 Dierks & Rescorla            Standards Track                    [Page 84]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
4539             Transfer Protocol -- HTTP/1.0", RFC 1945, May 1996.
4541    [KPR03]  Klima, V., Pokorny, O., Rosa, T., "Attacking RSA-based
4542             Sessions in SSL/TLS", http://eprint.iacr.org/2003/052/,
4543             March 2003.
4545    [PKCS6]  RSA Laboratories, "PKCS #6: RSA Extended Certificate Syntax
4546             Standard," version 1.5, November 1993.
4548    [PKCS7]  RSA Laboratories, "PKCS #7: RSA Cryptographic Message Syntax
4549             Standard," version 1.5, November 1993.
4551             [RANDOM] D. Eastlake 3rd, S. Crocker, J. Schiller.
4552             "Randomness Recommendations for Security", RFC 1750,
4553             December 1994.
4555    [RSA]    R. Rivest, A. Shamir, and L. M. Adleman, "A Method for
4556             Obtaining Digital Signatures and Public-Key Cryptosystems,"
4557             Communications of the ACM, v. 21, n. 2, Feb 1978, pp.
4558             120-126.
4560    [SEQNUM] Bellovin. S., "Defending Against Sequence Number Attacks",
4561             RFC 1948, May 1996.
4563    [SSL2]   Hickman, Kipp, "The SSL Protocol", Netscape Communications
4564             Corp., Feb 9, 1995.
4566    [SSL3]   A. Frier, P. Karlton, and P. Kocher, "The SSL 3.0 Protocol",
4567             Netscape Communications Corp., Nov 18, 1996.
4569    [SUBGROUP] R. Zuccherato, "Methods for Avoiding the Small-Subgroup
4570             Attacks on the Diffie-Hellman Key Agreement Method for
4571             S/MIME", RFC 2785, March 2000.
4573    [TCP]    Postel, J., "Transmission Control Protocol," STD 7, RFC 793,
4574             September 1981.
4576    [TIMING] Boneh, D., Brumley, D., "Remote timing attacks are
4577             practical", USENIX Security Symposium 2003.
4579    [TLS1.0] Dierks, T., and Allen, C., "The TLS Protocol, Version 1.0",
4580             RFC 2246, January 1999.
4582    [X509]   CCITT. Recommendation X.509: "The Directory - Authentication
4583             Framework". 1988.
4585    [XDR]    R. Srinivansan, Sun Microsystems, RFC-1832: XDR: External
4586             Data Representation Standard, August 1995.
4590 Dierks & Rescorla            Standards Track                    [Page 85]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
4593 Credits
4595    Working Group Chairs
4596    Win Treese
4597    EMail: treese@acm.org
4599    Eric Rescorla
4600    EMail: ekr@rtfm.com
4603    Editors
4605    Tim Dierks                Eric Rescorla
4606    Independent                   RTFM, Inc.
4608    EMail: tim@dierks.org         EMail: ekr@rtfm.com
4612    Other contributors
4614    Christopher Allen (co-editor of TLS 1.0)
4615    Alacrity Ventures
4616    ChristopherA@AlacrityManagement.com
4618    Martin Abadi
4619    University of California, Santa Cruz
4620    abadi@cs.ucsc.edu
4622    Ran Canetti
4623    IBM
4624    canetti@watson.ibm.com
4626    Taher Elgamal
4627    taher@securify.com
4628    Securify
4630    Anil Gangolli
4631    anil@busybuddha.org
4633    Kipp Hickman
4635    Phil Karlton (co-author of SSLv3)
4637    Paul Kocher (co-author of SSLv3)
4638    Cryptography Research
4639    paul@cryptography.com
4644 Dierks & Rescorla            Standards Track                    [Page 86]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
4647    Hugo Krawczyk
4648    Technion Israel Institute of Technology
4649    hugo@ee.technion.ac.il
4651    Robert Relyea
4652    Netscape Communications
4653    relyea@netscape.com
4655    Jim Roskind
4656    Netscape Communications
4657    jar@netscape.com
4659    Michael Sabin
4661    Dan Simon
4662    Microsoft, Inc.
4663    dansimon@microsoft.com
4665    Tom Weinstein
4667 Comments
4669    The discussion list for the IETF TLS working group is located at the
4670    e-mail address <ietf-tls@lists.consensus.com>. Information on the
4671    group and information on how to subscribe to the list is at
4672    <http://lists.consensus.com/>.
4674    Archives of the list can be found at:
4675        <http://www.imc.org/ietf-tls/mail-archive/>
4698 Dierks & Rescorla            Standards Track                    [Page 87]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
4701 Full Copyright Statement
4703    The IETF takes no position regarding the validity or scope of any
4704    Intellectual Property Rights or other rights that might be claimed to
4705    pertain to the implementation or use of the technology described in
4706    this document or the extent to which any license under such rights
4707    might or might not be available; nor does it represent that it has
4708    made any independent effort to identify any such rights. Information
4709    on the procedures with respect to rights in RFC documents can be
4710    found in BCP 78 and BCP 79.
4712    Copies of IPR disclosures made to the IETF Secretariat and any
4713    assurances of licenses to be made available, or the result of an
4714    attempt made to obtain a general license or permission for the use of
4715    such proprietary rights by implementers or users of this
4716    specification can be obtained from the IETF on-line IPR repository at
4717    http://www.ietf.org/ipr.
4719    The IETF invites any interested party to bring to its attention any
4720    copyrights, patents or patent applications, or other proprietary
4721    rights that may cover technology that may be required to implement
4722    this standard. Please address the information to the IETF at ietf-
4723    ipr@ietf.org.
4725 Copyright Notice
4726    Copyright (C) The Internet Society (2003). This document is subject
4727    to the rights, licenses and restrictions contained in BCP 78, and
4728    except as set forth therein, the authors retain all their rights.
4730    This document and the information contained herein are provided on an
4731    "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS
4732    OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY AND THE INTERNET
4733    ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED,
4734    INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE
4735    INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED
4736    WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
4752 Dierks & Rescorla            Standards Track                    [Page 88]\fdraft-ietf-tls-rfc2246-bis-09.txt  TLS                     December 2004
4806 Dierks & Rescorla            Standards Track                    [Page 89]\f