Improve GTK-DOC coverage.
[gnutls.git] / doc / protocol / draft-ietf-tls-rfc2246-bis-08.txt
blobcd2225bcbe67c984e9947e530e1751e496307173
1                                                              Tim Dierks
2                                                              Independent
3                                                            Eric Rescorla
4 INTERNET-DRAFT                                                RTFM, Inc.
5 <draft-ietf-tls-rfc2246-bis-08.txt>  August 2004 (Expires February 2005)
7                             The TLS Protocol
8                               Version 1.1
10 Status of this Memo
12 By submitting this Internet-Draft, I certify that any applicable
13 patent or other IPR claims of which I am aware have been disclosed,
14 and any of which I become aware will be disclosed, in accordance with
15 RFC 3668.
17 Internet-Drafts are working documents of the Internet Engineering
18 Task Force (IETF), its areas, and its working groups. Note that other
19 groups may also distribute working documents as Internet-Drafts.
21 Internet-Drafts are draft documents valid for a maximum of six months
22 and may be updated, replaced, or obsoleted by other documents at any
23 time. It is inappropriate to use Internet-Drafts as reference
24 material or to cite them other than a "work in progress."
26 The list of current Internet-Drafts can be accessed at
27 http://www.ietf.org/1id-abstracts.html
29 The list of Internet-Draft Shadow Directories can be accessed at
30 http://www.ietf.org/shadow.html
32 Copyright Notice
34    Copyright (C) The Internet Society (1999-2004).  All Rights Reserved.
36 Abstract
38    This document specifies Version 1.1 of the Transport Layer Security
39    (TLS) protocol. The TLS protocol provides communications security
40    over the Internet. The protocol allows client/server applications to
41    communicate in a way that is designed to prevent eavesdropping,
42    tampering, or message forgery.
44 Table of Contents
46    1.        Introduction
47    5 1.1       Requirements Terminology
48    6 2.        Goals
52 Dierks & Rescorla            Standards Track                     [Page 1]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
55    6 3.        Goals of this document
56    7 4.        Presentation language
57    7 4.1.      Basic block size
58    8 4.2.      Miscellaneous
59    8 4.3.      Vectors
60    8 4.4.      Numbers
61    9 4.5.      Enumerateds
62    9 4.6.      Constructed types
63    10 4.6.1.    Variants
64    11 4.7.      Cryptographic attributes
65    12 4.8.      Constants
66    13 5.        HMAC and the pseudorandom function
67    13 6.        The TLS Record Protocol
68    15 6.1.      Connection states
69    16 6.2.      Record layer
70    18 6.2.1.    Fragmentation
71    18 6.2.2.    Record compression and decompression
72    19 6.2.3.    Record payload protection
73    20 6.2.3.1.  Null or standard stream cipher
74    21 6.2.3.2.  CBC block cipher
75    21 6.3.      Key calculation
76    24 6.3.1.    Export key generation example
77    25 7.        The TLS Handshake Protocol
78    26 7.1.      Change cipher spec protocol
79    26 7.2.      Alert protocol
80    27 7.2.1.    Closure alerts
81    28 7.2.2.    Error alerts
82    29 7.3.      Handshake Protocol overview
83    33 7.4.      Handshake protocol
84    36 7.4.1.    Hello messages
85    37 7.4.1.1.  Hello request
86    37 7.4.1.2.  Client hello
87    38 7.4.1.3.  Server hello
88    40 7.4.2.    Server certificate
89    41 7.4.3.    Server key exchange message
90    43 7.4.4.    Certificate request
91    46 7.4.5.    Server hello done
92    47 7.4.6.    Client certificate
93    47 7.4.7.    Client key exchange message
94    48 7.4.7.1.  RSA encrypted premaster secret message
95    48 7.4.7.2.  Client Diffie-Hellman public value
96    50 7.4.8.    Certificate verify
97    51 7.4.9.    Finished
98    52 8.        Cryptographic computations
99    53 8.1.      Computing the master secret
100    53 8.1.1.    RSA
101    54 8.1.2.    Diffie-Hellman
102    54 9.        Mandatory Cipher Suites
106 Dierks & Rescorla            Standards Track                     [Page 2]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
109    54 A.        Protocol constant values
110    56 A.1.      Record layer
111    56 A.2.      Change cipher specs message
112    57 A.3.      Alert messages
113    57 A.4.      Handshake protocol
114    58 A.4.1.    Hello messages
115    58 A.4.2.    Server authentication and key exchange messages
116    59 A.4.3.    Client authentication and key exchange messages
117    60 A.4.4.    Handshake finalization message
118    61 A.5.      The CipherSuite
119    61 A.6.      The Security Parameters
120    63 B.        Glossary
121    65 C.        CipherSuite definitions
122    69 D.        Implementation Notes
123    72 D.1.      Temporary RSA keys
124    72 D.2.      Random Number Generation and Seeding
125    72 D.3.      Certificates and authentication
126    72 D.4.      CipherSuites
127    73 E.        Backward Compatibility With SSL
128    74 E.1.      Version 2 client hello
129    75 E.2.      Avoiding man-in-the-middle version rollback
130    76 F.        Security analysis
131    78 F.1.      Handshake protocol
132    78 F.1.1.    Authentication and key exchange
133    78 F.1.1.1.  Anonymous key exchange
134    78 F.1.1.2.  RSA key exchange and authentication
135    79 F.1.1.3.  Diffie-Hellman key exchange with authentication
136    80 F.1.2.    Version rollback attacks
137    80 F.1.3.    Detecting attacks against the handshake protocol
138    81 F.1.4.    Resuming sessions
139    81 F.1.5.    MD5 and SHA
140    82 F.2.      Protecting application data
141    82 F.3.      Explicit IVs
142    82 F.4       Security of Composite Cipher Modes
143    83 F.5       Denial of Service
144    84 F.6.      Final notes
145    84
148 Change history
150    Note: Change bars in this draft are from RFC 2246, not draft-00
151    10-Aug-04 ekr@rtfm.com
152     * Added clarifying material about interleaved application data.
154    27-Jul-04 ekr@rtfm.com
155     * Premature closes no longer cause a session to be nonresumable.
156       Response to WG consensus.
160 Dierks & Rescorla            Standards Track                     [Page 3]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
163     * Added IANA considerations and registry for cipher suites
164       and ClientCertificateTypes
166    26-Jun-03 ekr@rtfm.com
167     * Incorporated Last Call comments from Franke Marcus, Jack Lloyd,
168     Brad Wetmore, and others.
170    22-Apr-03 ekr@rtfm.com
171     * coverage of the Vaudenay, Boneh-Brumley, and KPR attacks
172     * cleaned up IV text a bit.
173     * Added discussion of Denial of Service attacks.
175    11-Feb-02 ekr@rtfm.com
176     * Clarified the behavior of empty certificate lists [Nelson Bolyard]
177     * Added text explaining the security implications of authenticate
178       then encrypt.
179     * Cleaned up the explicit IV text.
180     * Added some more acknowledgement names
182    02-Nov-02 ekr@rtfm.com
183     * Changed this to be TLS 1.1.
184     * Added fixes for the Rogaway and Vaudenay CBC attacks
185     * Separated references into normative and informative
187    01-Mar-02 ekr@rtfm.com
188     * Tightened up the language in F.1.1.2 [Peter Watkins]
189     * Fixed smart quotes [Bodo Moeller]
190     * Changed handling of padding errors to prevent CBC-based attack
191       [Bodo Moeller]
192     * Fixed certificate_list spec in the appendix [Aman Sawrup]
193     * Fixed a bug in the V2 definitions [Aman Sawrup]
194     * Fixed S 7.2.1 to point out that you don't need a close notify
195       if you just sent some other fatal alert [Andreas Sterbenz]
196     * Marked alert 41 reserved [Andreas Sterbenz]
197     * Changed S 7.4.2 to point out that 512-bit keys cannot be used for
198       signing [Andreas Sterbenz]
199     * Added reserved client key types from SSLv3 [Andreas Sterbenz]
200     * Changed EXPORT40 to "40-bit EXPORT" in S 9 [Andreas Sterbenz]
201     * Removed RSA patent statement [Andreas Sterbenz]
202     * Removed references to BSAFE and RSAREF [Andreas Sterbenz]
204    14-Feb-02 ekr@rtfm.com
205     * Re-converted to I-D from RFC
206     * Made RSA/3DES the mandatory cipher suite.
207     * Added discussion of the EncryptedPMS encoding and PMS version number
208       issues to 7.4.7.1
209     * Removed the requirement in 7.4.1.3 that the Server random must be
210       different from the Client random, since these are randomly generated
214 Dierks & Rescorla            Standards Track                     [Page 4]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
217       and we don't expect servers to reject Server random values which
218       coincidentally are the same as the Client random.
219     * Replaced may/should/must with MAY/SHOULD/MUST where appropriate.
220       In many cases, shoulds became MUSTs, where I believed that was the
221       actual sense of the text. Added an RFC 2119 bulletin.
222    * Clarified the meaning of "empty certificate" message. [Peter Gutmann]
223    * Redid the CertificateRequest grammar to allow no distinguished names.
224      [Peter Gutmann]
225    * Removed the reference to requiring the master secret to generate
226      the CertificateVerify in F.1.1 [Bodo Moeller]
227    * Deprecated EXPORT40.
228    * Fixed a bunch of errors in the SSLv2 backward compatible client hello.
230 1. Introduction
232    The primary goal of the TLS Protocol is to provide privacy and data
233    integrity between two communicating applications. The protocol is
234    composed of two layers: the TLS Record Protocol and the TLS Handshake
235    Protocol. At the lowest level, layered on top of some reliable
236    transport protocol (e.g., TCP[TCP]), is the TLS Record Protocol. The
237    TLS Record Protocol provides connection security that has two basic
238    properties:
240      - - The connection is private. Symmetric cryptography is used for
241        data encryption (e.g., DES [DES], RC4 [RC4], etc.) The keys for
242        this symmetric encryption are generated uniquely for each
243        connection and are based on a secret negotiated by another
244        protocol (such as the TLS Handshake Protocol). The Record
245        Protocol can also be used without encryption.
247      - - The connection is reliable. Message transport includes a
248        message integrity check using a keyed MAC. Secure hash functions
249        (e.g., SHA, MD5, etc.) are used for MAC computations. The Record
250        Protocol can operate without a MAC, but is generally only used in
251        this mode while another protocol is using the Record Protocol as
252        a transport for negotiating security parameters.
254    The TLS Record Protocol is used for encapsulation of various higher
255    level protocols. One such encapsulated protocol, the TLS Handshake
256    Protocol, allows the server and client to authenticate each other and
257    to negotiate an encryption algorithm and cryptographic keys before
258    the application protocol transmits or receives its first byte of
259    data. The TLS Handshake Protocol provides connection security that
260    has three basic properties:
262      - - The peer's identity can be authenticated using asymmetric, or
263        public key, cryptography (e.g., RSA [RSA], DSS [DSS], etc.). This
264        authentication can be made optional, but is generally required
268 Dierks & Rescorla            Standards Track                     [Page 5]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
271        for at least one of the peers.
273      - - The negotiation of a shared secret is secure: the negotiated
274        secret is unavailable to eavesdroppers, and for any authenticated
275        connection the secret cannot be obtained, even by an attacker who
276        can place himself in the middle of the connection.
278      - - The negotiation is reliable: no attacker can modify the
279        negotiation communication without being detected by the parties
280        to the communication.
282    One advantage of TLS is that it is application protocol independent.
283    Higher level protocols can layer on top of the TLS Protocol
284    transparently. The TLS standard, however, does not specify how
285    protocols add security with TLS; the decisions on how to initiate TLS
286    handshaking and how to interpret the authentication certificates
287    exchanged are left up to the judgment of the designers and
288    implementors of protocols which run on top of TLS.
290 1.1 Requirements Terminology
292    Keywords "MUST", "MUST NOT", "REQUIRED", "SHOULD", "SHOULD NOT" and
293    "MAY" that appear in this document are to be interpreted as described
294    in RFC 2119 [REQ].
296 2. Goals
298    The goals of TLS Protocol, in order of their priority, are:
300     1. Cryptographic security: TLS should be used to establish a secure
301        connection between two parties.
303     2. Interoperability: Independent programmers should be able to
304        develop applications utilizing TLS that will then be able to
305        successfully exchange cryptographic parameters without knowledge
306        of one another's code.
308     3. Extensibility: TLS seeks to provide a framework into which new
309        public key and bulk encryption methods can be incorporated as
310        necessary. This will also accomplish two sub-goals: to prevent
311        the need to create a new protocol (and risking the introduction
312        of possible new weaknesses) and to avoid the need to implement an
313        entire new security library.
315     4. Relative efficiency: Cryptographic operations tend to be highly
316        CPU intensive, particularly public key operations. For this
317        reason, the TLS protocol has incorporated an optional session
318        caching scheme to reduce the number of connections that need to
322 Dierks & Rescorla            Standards Track                     [Page 6]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
325        be established from scratch. Additionally, care has been taken to
326        reduce network activity.
328 3. Goals of this document
330    This document and the TLS protocol itself are based on the SSL 3.0
331    Protocol Specification as published by Netscape. The differences
332    between this protocol and SSL 3.0 are not dramatic, but they are
333    significant enough that TLS 1.0 and SSL 3.0 do not interoperate
334    (although TLS 1.0 does incorporate a mechanism by which a TLS
335    implementation can back down to SSL 3.0). This document is intended
336    primarily for readers who will be implementing the protocol and those
337    doing cryptographic analysis of it. The specification has been
338    written with this in mind, and it is intended to reflect the needs of
339    those two groups. For that reason, many of the algorithm-dependent
340    data structures and rules are included in the body of the text (as
341    opposed to in an appendix), providing easier access to them.
343    This document is not intended to supply any details of service
344    definition nor interface definition, although it does cover select
345    areas of policy as they are required for the maintenance of solid
346    security.
348 4. Presentation language
350    This document deals with the formatting of data in an external
351    representation. The following very basic and somewhat casually
352    defined presentation syntax will be used. The syntax draws from
353    several sources in its structure. Although it resembles the
354    programming language "C" in its syntax and XDR [XDR] in both its
355    syntax and intent, it would be risky to draw too many parallels. The
356    purpose of this presentation language is to document TLS only, not to
357    have general application beyond that particular goal.
376 Dierks & Rescorla            Standards Track                     [Page 7]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
379 4.1. Basic block size
381    The representation of all data items is explicitly specified. The
382    basic data block size is one byte (i.e. 8 bits). Multiple byte data
383    items are concatenations of bytes, from left to right, from top to
384    bottom. From the bytestream a multi-byte item (a numeric in the
385    example) is formed (using C notation) by:
387        value = (byte[0] << 8*(n-1)) | (byte[1] << 8*(n-2)) |
388                ... | byte[n-1];
390    This byte ordering for multi-byte values is the commonplace network
391    byte order or big endian format.
393 4.2. Miscellaneous
395    Comments begin with "/*" and end with "*/".
397    Optional components are denoted by enclosing them in "[[ ]]" double
398    brackets.
400    Single byte entities containing uninterpreted data are of type
401    opaque.
403 4.3. Vectors
405    A vector (single dimensioned array) is a stream of homogeneous data
406    elements. The size of the vector may be specified at documentation
407    time or left unspecified until runtime. In either case the length
408    declares the number of bytes, not the number of elements, in the
409    vector. The syntax for specifying a new type T' that is a fixed
410    length vector of type T is
412        T T'[n];
414    Here T' occupies n bytes in the data stream, where n is a multiple of
415    the size of T. The length of the vector is not included in the
416    encoded stream.
418    In the following example, Datum is defined to be three consecutive
419    bytes that the protocol does not interpret, while Data is three
420    consecutive Datum, consuming a total of nine bytes.
422        opaque Datum[3];      /* three uninterpreted bytes */
423        Datum Data[9];        /* 3 consecutive 3 byte vectors */
430 Dierks & Rescorla            Standards Track                     [Page 8]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
433    Variable length vectors are defined by specifying a subrange of legal
434    lengths, inclusively, using the notation <floor..ceiling>.  When
435    encoded, the actual length precedes the vector's contents in the byte
436    stream. The length will be in the form of a number consuming as many
437    bytes as required to hold the vector's specified maximum (ceiling)
438    length. A variable length vector with an actual length field of zero
439    is referred to as an empty vector.
441        T T'<floor..ceiling>;
443    In the following example, mandatory is a vector that must contain
444    between 300 and 400 bytes of type opaque. It can never be empty. The
445    actual length field consumes two bytes, a uint16, sufficient to
446    represent the value 400 (see Section 4.4). On the other hand, longer
447    can represent up to 800 bytes of data, or 400 uint16 elements, and it
448    may be empty. Its encoding will include a two byte actual length
449    field prepended to the vector. The length of an encoded vector must
450    be an even multiple of the length of a single element (for example, a
451    17 byte vector of uint16 would be illegal).
453        opaque mandatory<300..400>;
454              /* length field is 2 bytes, cannot be empty */
455        uint16 longer<0..800>;
456              /* zero to 400 16-bit unsigned integers */
458 4.4. Numbers
460    The basic numeric data type is an unsigned byte (uint8). All larger
461    numeric data types are formed from fixed length series of bytes
462    concatenated as described in Section 4.1 and are also unsigned. The
463    following numeric types are predefined.
465        uint8 uint16[2];
466        uint8 uint24[3];
467        uint8 uint32[4];
468        uint8 uint64[8];
470    All values, here and elsewhere in the specification, are stored in
471    "network" or "big-endian" order; the uint32 represented by the hex
472    bytes 01 02 03 04 is equivalent to the decimal value 16909060.
474 4.5. Enumerateds
476    An additional sparse data type is available called enum. A field of
477    type enum can only assume the values declared in the definition.
478    Each definition is a different type. Only enumerateds of the same
479    type may be assigned or compared. Every element of an enumerated must
484 Dierks & Rescorla            Standards Track                     [Page 9]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
487    be assigned a value, as demonstrated in the following example.  Since
488    the elements of the enumerated are not ordered, they can be assigned
489    any unique value, in any order.
491        enum { e1(v1), e2(v2), ... , en(vn) [[, (n)]] } Te;
493    Enumerateds occupy as much space in the byte stream as would its
494    maximal defined ordinal value. The following definition would cause
495    one byte to be used to carry fields of type Color.
497        enum { red(3), blue(5), white(7) } Color;
499    One may optionally specify a value without its associated tag to
500    force the width definition without defining a superfluous element.
501    In the following example, Taste will consume two bytes in the data
502    stream but can only assume the values 1, 2 or 4.
504        enum { sweet(1), sour(2), bitter(4), (32000) } Taste;
506    The names of the elements of an enumeration are scoped within the
507    defined type. In the first example, a fully qualified reference to
508    the second element of the enumeration would be Color.blue. Such
509    qualification is not required if the target of the assignment is well
510    specified.
512        Color color = Color.blue;     /* overspecified, legal */
513        Color color = blue;           /* correct, type implicit */
515    For enumerateds that are never converted to external representation,
516    the numerical information may be omitted.
518        enum { low, medium, high } Amount;
520 4.6. Constructed types
522    Structure types may be constructed from primitive types for
523    convenience. Each specification declares a new, unique type. The
524    syntax for definition is much like that of C.
526        struct {
527          T1 f1;
528          T2 f2;
529          ...
530          Tn fn;
531        } [[T]];
538 Dierks & Rescorla            Standards Track                    [Page 10]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
541    The fields within a structure may be qualified using the type's name
542    using a syntax much like that available for enumerateds. For example,
543    T.f2 refers to the second field of the previous declaration.
544    Structure definitions may be embedded.
546 4.6.1. Variants
548    Defined structures may have variants based on some knowledge that is
549    available within the environment. The selector must be an enumerated
550    type that defines the possible variants the structure defines. There
551    must be a case arm for every element of the enumeration declared in
552    the select. The body of the variant structure may be given a label
553    for reference. The mechanism by which the variant is selected at
554    runtime is not prescribed by the presentation language.
556        struct {
557            T1 f1;
558            T2 f2;
559            ....
560            Tn fn;
561            select (E) {
562                case e1: Te1;
563                case e2: Te2;
564                ....
565                case en: Ten;
566            } [[fv]];
567        } [[Tv]];
569    For example:
571        enum { apple, orange } VariantTag;
572        struct {
573            uint16 number;
574            opaque string<0..10>; /* variable length */
575        } V1;
576        struct {
577            uint32 number;
578            opaque string[10];    /* fixed length */
579        } V2;
580        struct {
581            select (VariantTag) { /* value of selector is implicit */
582                case apple: V1;   /* VariantBody, tag = apple */
583                case orange: V2;  /* VariantBody, tag = orange */
584            } variant_body;       /* optional label on variant */
585        } VariantRecord;
587    Variant structures may be qualified (narrowed) by specifying a value
588    for the selector prior to the type. For example, a
592 Dierks & Rescorla            Standards Track                    [Page 11]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
595        orange VariantRecord
597    is a narrowed type of a VariantRecord containing a variant_body of
598    type V2.
600 4.7. Cryptographic attributes
602    The four cryptographic operations digital signing, stream cipher
603    encryption, block cipher encryption, and public key encryption are
604    designated digitally-signed, stream-ciphered, block-ciphered, and
605    public-key-encrypted, respectively. A field's cryptographic
606    processing is specified by prepending an appropriate key word
607    designation before the field's type specification. Cryptographic keys
608    are implied by the current session state (see Section 6.1).
610    In digital signing, one-way hash functions are used as input for a
611    signing algorithm. A digitally-signed element is encoded as an opaque
612    vector <0..2^16-1>, where the length is specified by the signing
613    algorithm and key.
615    In RSA signing, a 36-byte structure of two hashes (one SHA and one
616    MD5) is signed (encrypted with the private key). It is encoded with
617    PKCS #1 block type 0 or type 1 as described in [PKCS1].
619    In DSS, the 20 bytes of the SHA hash are run directly through the
620    Digital Signing Algorithm with no additional hashing. This produces
621    two values, r and s. The DSS signature is an opaque vector, as above,
622    the contents of which are the DER encoding of:
624        Dss-Sig-Value  ::=  SEQUENCE  {
625             r       INTEGER,
626             s       INTEGER
627        }
629    In stream cipher encryption, the plaintext is exclusive-ORed with an
630    identical amount of output generated from a cryptographically-secure
631    keyed pseudorandom number generator.
633    In block cipher encryption, every block of plaintext encrypts to a
634    block of ciphertext. All block cipher encryption is done in CBC
635    (Cipher Block Chaining) mode, and all items which are block-ciphered
636    will be an exact multiple of the cipher block length.
638    In public key encryption, a public key algorithm is used to encrypt
639    data in such a way that it can be decrypted only with the matching
640    private key. A public-key-encrypted element is encoded as an opaque
641    vector <0..2^16-1>, where the length is specified by the signing
642    algorithm and key.
646 Dierks & Rescorla            Standards Track                    [Page 12]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
649    An RSA encrypted value is encoded with PKCS #1 block type 2 as
650    described in [PKCS1].
652    In the following example:
654        stream-ciphered struct {
655            uint8 field1;
656            uint8 field2;
657            digitally-signed opaque hash[20];
658        } UserType;
660    The contents of hash are used as input for the signing algorithm,
661    then the entire structure is encrypted with a stream cipher. The
662    length of this structure, in bytes would be equal to 2 bytes for
663    field1 and field2, plus two bytes for the length of the signature,
664    plus the length of the output of the signing algorithm. This is known
665    due to the fact that the algorithm and key used for the signing are
666    known prior to encoding or decoding this structure.
668 4.8. Constants
670    Typed constants can be defined for purposes of specification by
671    declaring a symbol of the desired type and assigning values to it.
672    Under-specified types (opaque, variable length vectors, and
673    structures that contain opaque) cannot be assigned values. No fields
674    of a multi-element structure or vector may be elided.
676    For example,
678        struct {
679            uint8 f1;
680            uint8 f2;
681        } Example1;
683        Example1 ex1 = {1, 4};  /* assigns f1 = 1, f2 = 4 */
685 5. HMAC and the pseudorandom function
687    A number of operations in the TLS record and handshake layer required
688    a keyed MAC; this is a secure digest of some data protected by a
689    secret. Forging the MAC is infeasible without knowledge of the MAC
690    secret. The construction we use for this operation is known as HMAC,
691    described in [HMAC].
693    HMAC can be used with a variety of different hash algorithms. TLS
694    uses it in the handshake with two different algorithms: MD5 and
695    SHA-1, denoting these as HMAC_MD5(secret, data) and HMAC_SHA(secret,
700 Dierks & Rescorla            Standards Track                    [Page 13]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
703    data). Additional hash algorithms can be defined by cipher suites and
704    used to protect record data, but MD5 and SHA-1 are hard coded into
705    the description of the handshaking for this version of the protocol.
707    In addition, a construction is required to do expansion of secrets
708    into blocks of data for the purposes of key generation or validation.
709    This pseudo-random function (PRF) takes as input a secret, a seed,
710    and an identifying label and produces an output of arbitrary length.
712    In order to make the PRF as secure as possible, it uses two hash
713    algorithms in a way which should guarantee its security if either
714    algorithm remains secure.
716    First, we define a data expansion function, P_hash(secret, data)
717    which uses a single hash function to expand a secret and seed into an
718    arbitrary quantity of output:
720        P_hash(secret, seed) = HMAC_hash(secret, A(1) + seed) +
721                               HMAC_hash(secret, A(2) + seed) +
722                               HMAC_hash(secret, A(3) + seed) + ...
724    Where + indicates concatenation.
726    A() is defined as:
727        A(0) = seed
728        A(i) = HMAC_hash(secret, A(i-1))
730    P_hash can be iterated as many times as is necessary to produce the
731    required quantity of data. For example, if P_SHA-1 was being used to
732    create 64 bytes of data, it would have to be iterated 4 times
733    (through A(4)), creating 80 bytes of output data; the last 16 bytes
734    of the final iteration would then be discarded, leaving 64 bytes of
735    output data.
737    TLS's PRF is created by splitting the secret into two halves and
738    using one half to generate data with P_MD5 and the other half to
739    generate data with P_SHA-1, then exclusive-or'ing the outputs of
740    these two expansion functions together.
742    S1 and S2 are the two halves of the secret and each is the same
743    length. S1 is taken from the first half of the secret, S2 from the
744    second half. Their length is created by rounding up the length of the
745    overall secret divided by two; thus, if the original secret is an odd
746    number of bytes long, the last byte of S1 will be the same as the
747    first byte of S2.
749        L_S = length in bytes of secret;
750        L_S1 = L_S2 = ceil(L_S / 2);
754 Dierks & Rescorla            Standards Track                    [Page 14]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
757    The secret is partitioned into two halves (with the possibility of
758    one shared byte) as described above, S1 taking the first L_S1 bytes
759    and S2 the last L_S2 bytes.
761    The PRF is then defined as the result of mixing the two pseudorandom
762    streams by exclusive-or'ing them together.
764        PRF(secret, label, seed) = P_MD5(S1, label + seed) XOR
765                                   P_SHA-1(S2, label + seed);
767    The label is an ASCII string. It should be included in the exact form
768    it is given without a length byte or trailing null character.  For
769    example, the label "slithy toves" would be processed by hashing the
770    following bytes:
772        73 6C 69 74 68 79 20 74 6F 76 65 73
774    Note that because MD5 produces 16 byte outputs and SHA-1 produces 20
775    byte outputs, the boundaries of their internal iterations will not be
776    aligned; to generate a 80 byte output will involve P_MD5 being
777    iterated through A(5), while P_SHA-1 will only iterate through A(4).
779 6. The TLS Record Protocol
781    The TLS Record Protocol is a layered protocol. At each layer,
782    messages may include fields for length, description, and content.
783    The Record Protocol takes messages to be transmitted, fragments the
784    data into manageable blocks, optionally compresses the data, applies
785    a MAC, encrypts, and transmits the result. Received data is
786    decrypted, verified, decompressed, and reassembled, then delivered to
787    higher level clients.
789    Four record protocol clients are described in this document: the
790    handshake protocol, the alert protocol, the change cipher spec
791    protocol, and the application data protocol. In order to allow
792    extension of the TLS protocol, additional record types can be
793    supported by the record protocol. Any new record types SHOULD
794    allocate type values immediately beyond the ContentType values for
795    the four record types described here (see Appendix A.2). If a TLS
796    implementation receives a record type it does not understand, it
797    SHOULD just ignore it. Any protocol designed for use over TLS MUST be
798    carefully designed to deal with all possible attacks against it.
799    Note that because the type and length of a record are not protected
800    by encryption, care SHOULD be taken to minimize the value of traffic
801    analysis of these values.
808 Dierks & Rescorla            Standards Track                    [Page 15]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
811 6.1. Connection states
813    A TLS connection state is the operating environment of the TLS Record
814    Protocol. It specifies a compression algorithm, encryption algorithm,
815    and MAC algorithm. In addition, the parameters for these algorithms
816    are known: the MAC secret and the bulk encryption keys for the
817    connection in both the read and the write directions. Logically,
818    there are always four connection states outstanding: the current read
819    and write states, and the pending read and write states. All records
820    are processed under the current read and write states. The security
821    parameters for the pending states can be set by the TLS Handshake
822    Protocol, and the Handshake Protocol can selectively make either of
823    the pending states current, in which case the appropriate current
824    state is disposed of and replaced with the pending state; the pending
825    state is then reinitialized to an empty state. It is illegal to make
826    a state which has not been initialized with security parameters a
827    current state. The initial current state always specifies that no
828    encryption, compression, or MAC will be used.
830    The security parameters for a TLS Connection read and write state are
831    set by providing the following values:
833    connection end
834        Whether this entity is considered the "client" or the "server" in
835        this connection.
837    bulk encryption algorithm
838        An algorithm to be used for bulk encryption. This specification
839        includes the key size of this algorithm, how much of that key is
840        secret, whether it is a block or stream cipher, the block size of
841        the cipher (if appropriate), and whether it is considered an
842        "export" cipher.
844    MAC algorithm
845        An algorithm to be used for message authentication. This
846        specification includes the size of the hash which is returned by
847        the MAC algorithm.
849    compression algorithm
850        An algorithm to be used for data compression. This specification
851        must include all information the algorithm requires to do
852        compression.
854    master secret
855        A 48 byte secret shared between the two peers in the connection.
857    client random
858        A 32 byte value provided by the client.
862 Dierks & Rescorla            Standards Track                    [Page 16]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
865    server random
866        A 32 byte value provided by the server.
868    These parameters are defined in the presentation language as:
870        enum { server, client } ConnectionEnd;
872        enum { null, rc4, rc2, des, 3des, des40 } BulkCipherAlgorithm;
874        enum { stream, block } CipherType;
876        enum { true, false } IsExportable;
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            IsExportable           is_exportable;
892            MACAlgorithm           mac_algorithm;
893            uint8                  hash_size;
894            CompressionMethod      compression_algorithm;
895            opaque                 master_secret[48];
896            opaque                 client_random[32];
897            opaque                 server_random[32];
898        } SecurityParameters;
900    The record layer will use the security parameters to generate the
901    following four items:
903        client write MAC secret
904        server write MAC secret
905        client write key
906        server write key
908    The client write parameters are used by the server when receiving and
909    processing records and vice-versa. The algorithm used for generating
910    these items from the security parameters is described in section 6.3.
912    Once the security parameters have been set and the keys have been
916 Dierks & Rescorla            Standards Track                    [Page 17]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
919    generated, the connection states can be instantiated by making them
920    the current states. These current states MUST be updated for each
921    record processed. Each connection state includes the following
922    elements:
924    compression state
925        The current state of the compression algorithm.
927    cipher state
928        The current state of the encryption algorithm. This will consist
929        of the scheduled key for that connection. For stream ciphers,
930        this will also contain whatever the necessary state information
931        is to allow the stream to continue to encrypt or decrypt data.
933    MAC secret
934        The MAC secret for this connection as generated above.
936    sequence number
937        Each connection state contains a sequence number, which is
938        maintained separately for read and write states. The sequence
939        number MUST be set to zero whenever a connection state is made
940        the active state. Sequence numbers are of type uint64 and may not
941        exceed 2^64-1. Sequence numbers do not wrap. If a TLS
942        implementation would need to wrap a sequence number it must
943        renegotiate instead. A sequence number is incremented after each
944        record: specifically, the first record which is transmitted under
945        a particular connection state MUST use sequence number 0.
947 6.2. Record layer
949    The TLS Record Layer receives uninterpreted data from higher layers
950    in non-empty blocks of arbitrary size.
952 6.2.1. Fragmentation
954    The record layer fragments information blocks into TLSPlaintext
955    records carrying data in chunks of 2^14 bytes or less. Client message
956    boundaries are not preserved in the record layer (i.e., multiple
957    client messages of the same ContentType MAY be coalesced into a
958    single TLSPlaintext record, or a single message MAY be fragmented
959    across several records).
962        struct {
963            uint8 major, minor;
964        } ProtocolVersion;
966        enum {
970 Dierks & Rescorla            Standards Track                    [Page 18]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
973            change_cipher_spec(20), alert(21), handshake(22),
974            application_data(23), (255)
975        } ContentType;
977        struct {
978            ContentType type;
979            ProtocolVersion version;
980            uint16 length;
981            opaque fragment[TLSPlaintext.length];
982        } TLSPlaintext;
984    type
985        The higher level protocol used to process the enclosed fragment.
987    version
988        The version of the protocol being employed. This document
989        describes TLS Version 1.1, which uses the version { 3, 2 }. The
990        version value 3.2 is historical: TLS version 1.1 is a minor
991        modification to the TLS 1.0 protocol, which was itself a minor
992        modification to the SSL 3.0 protocol, which bears the version
993        value 3.0. (See Appendix A.1).
995    length
996        The length (in bytes) of the following TLSPlaintext.fragment.
997        The length should not exceed 2^14.
999    fragment
1000        The application data. This data is transparent and treated as an
1001        independent block to be dealt with by the higher level protocol
1002        specified by the type field.
1004  Note: Data of different TLS Record layer content types MAY be
1005        interleaved. Application data is generally of lower precedence
1006        for transmission than other content types and therefore handshake
1007        records may be held if application data is pending.  However,
1008        records MUST be delivered to the network in the same order as
1009        they are protected by the record layer. Recipients MUST receive
1010        and process interleaved application layer traffic during
1011        handshakes subsequent to the first one on a connection.
1013 6.2.2. Record compression and decompression
1015    All records are compressed using the compression algorithm defined in
1016    the current session state. There is always an active compression
1017    algorithm; however, initially it is defined as
1018    CompressionMethod.null. The compression algorithm translates a
1019    TLSPlaintext structure into a TLSCompressed structure. Compression
1020    functions are initialized with default state information whenever a
1024 Dierks & Rescorla            Standards Track                    [Page 19]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
1027    connection state is made active.
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.
1078 Dierks & Rescorla            Standards Track                    [Page 20]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
1081    version
1082        The version field is identical to TLSCompressed.version.
1084    length
1085        The length (in bytes) of the following TLSCiphertext.fragment.
1086        The length may not exceed 2^14 + 2048.
1088    fragment
1089        The encrypted form of TLSCompressed.fragment, with the MAC.
1091 6.2.3.1. Null or standard stream cipher
1093    Stream ciphers (including BulkCipherAlgorithm.null - see Appendix
1094    A.6) convert TLSCompressed.fragment structures to and from stream
1095    TLSCiphertext.fragment structures.
1097        stream-ciphered struct {
1098            opaque content[TLSCompressed.length];
1099            opaque MAC[CipherSpec.hash_size];
1100        } GenericStreamCipher;
1102    The MAC is generated as:
1104        HMAC_hash(MAC_write_secret, seq_num + TLSCompressed.type +
1105                      TLSCompressed.version + TLSCompressed.length +
1106                      TLSCompressed.fragment));
1108    where "+" denotes concatenation.
1110    seq_num
1111        The sequence number for this record.
1113    hash
1114        The hashing algorithm specified by
1115        SecurityParameters.mac_algorithm.
1117    Note that the MAC is computed before encryption. The stream cipher
1118    encrypts the entire block, including the MAC. For stream ciphers that
1119    do not use a synchronization vector (such as RC4), the stream cipher
1120    state from the end of one record is simply used on the subsequent
1121    packet. If the CipherSuite is TLS_NULL_WITH_NULL_NULL, encryption
1122    consists of the identity operation (i.e., the data is not encrypted
1123    and the MAC size is zero implying that no MAC is used).
1124    TLSCiphertext.length is TLSCompressed.length plus
1125    CipherSpec.hash_size.
1127 6.2.3.2. CBC block cipher
1132 Dierks & Rescorla            Standards Track                    [Page 21]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
1135    For block ciphers (such as RC2 or DES), the encryption and MAC
1136    functions convert TLSCompressed.fragment structures to and from block
1137    TLSCiphertext.fragment structures.
1139        block-ciphered struct {
1140            opaque IV[CipherSpec.block_length];
1141            opaque content[TLSCompressed.length];
1142            opaque MAC[CipherSpec.hash_size];
1143            uint8 padding[GenericBlockCipher.padding_length];
1144            uint8 padding_length;
1145        } GenericBlockCipher;
1147    The MAC is generated as described in Section 6.2.3.1.
1149    IV
1150        Unlike previous versions of SSL and TLS, TLS 1.1 uses an explicit
1151        IV in order to prevent the attacks described by [CBCATT].
1152        We recommend the following equivalently strong procedures.
1153        For clarity we use the following notation.
1155        IV -- the transmitted value of the IV field in the
1156            GenericBlockCipher structure.
1157        CBC residue -- the last ciphertext block of the previous record
1158        mask -- the actual value which the cipher XORs with the
1159            plaintext prior to encryption of the first cipher block
1160            of the record.
1162        In prior versions of TLS, there was no IV field and the CBC residue
1163        and mask were one and the same.
1166        (1) Generate a cryptographically strong random string R of
1167            length CipherSpec.block_length. Place R
1168            in the IV field. Set the mask to R. Thus, the first
1169            cipher block will be encrypted as E(R XOR Data).
1171        (2) Generate a cryptographically strong random number R of
1172            length CipherSpec.block_length and prepend it to the plaintext
1173            prior to encryption. In
1174            this case either:
1176            (a)   The cipher may use a fixed mask such as zero.
1177            (b) The CBC residue from the previous record may be used
1178                as the mask. This preserves maximum code compatibility
1179             with TLS 1.0 and SSL 3. It also has the advantage that
1180             it does not require the ability to quickly reset the IV,
1181             which is known to be a   problem on some systems.
1186 Dierks & Rescorla            Standards Track                    [Page 22]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
1189             In either case, the data (R || data) is fed into the
1190             encryption process. The first cipher block (containing
1191             E(mask XOR R) is placed in the IV field. The first
1192             block of content contains E(IV XOR data)
1194        The following alternative procedure MAY be used: However, it has
1195        not been demonstrated to be equivalently cryptographically strong
1196        to the above procedures. The sender prepends a fixed block F to
1197        the plaintext (or alternatively a block generated with a weak
1198        PRNG). He then encrypts as in (2) above, using the CBC residue
1199        from the previous block as the mask for the prepended block. Note
1200        that in this case the mask for the first record transmitted by
1201        the application (the Finished) MUST be generated using a
1202        cryptographically strong PRNG.
1204        The decryption operation for all three alternatives is the same.
1205        The receiver decrypts the entire GenericBlockCipher structure and
1206        then discards the first cipher block, corresponding to the IV
1207        component.
1209    padding
1210        Padding that is added to force the length of the plaintext to be
1211        an integral multiple of the block cipher's block length. The
1212        padding MAY be any length up to 255 bytes long, as long as it
1213        results in the TLSCiphertext.length being an integral multiple of
1214        the block length. Lengths longer than necessary might be
1215        desirable to frustrate attacks on a protocol based on analysis of
1216        the lengths of exchanged messages. Each uint8 in the padding data
1217        vector MUST be filled with the padding length value. The receiver
1218        MUST check this padding and SHOULD use the bad_record_mac alert
1219        to indicate padding errors.
1221    padding_length
1222        The padding length MUST be such that the total size of the
1223        GenericBlockCipher structure is a multiple of the cipher's block
1224        length. Legal values range from zero to 255, inclusive. This
1225        length specifies the length of the padding field exclusive of the
1226        padding_length field itself.
1228    The encrypted data length (TLSCiphertext.length) is one more than the
1229    sum of TLSCompressed.length, CipherSpec.hash_size, and
1230    padding_length.
1232  Example: If the block length is 8 bytes, the content length
1233           (TLSCompressed.length) is 61 bytes, and the MAC length is 20
1234           bytes, the length before padding is 82 bytes (this does not
1235           include the IV, which may or may not be encrypted, as
1236           discussed above). Thus, the padding length modulo 8 must be
1240 Dierks & Rescorla            Standards Track                    [Page 23]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
1243           equal to 6 in order to make the total length an even multiple
1244           of 8 bytes (the block length). The padding length can be 6,
1245           14, 22, and so on, through 254. If the padding length were the
1246           minimum necessary, 6, the padding would be 6 bytes, each
1247           containing the value 6.  Thus, the last 8 octets of the
1248           GenericBlockCipher before block encryption would be xx 06 06
1249           06 06 06 06 06, where xx is the last octet of the MAC.
1251  Note: With block ciphers in CBC mode (Cipher Block Chaining),
1252        it is critical that the entire plaintext of the record be known
1253        before any ciphertext is transmitted. Otherwise it is possible
1254        for the attacker to mount the attack described in [CBCATT].
1256  Implementation Note: Canvel et. al. [CBCTIME] have demonstrated a
1257        timing attack on CBC padding based on the time required to
1258        compute the MAC. In order to defend against this attack,
1259        implementations MUST ensure that record processing time is
1260        essentially the same whether or not the padding is correct.  In
1261        general, the best way to to do this is to compute the MAC even if
1262        the padding is incorrect, and only then reject the packet. For
1263        instance, if the pad appears to be incorrect the implementation
1264        might assume a zero-length pad and then compute the MAC. This
1265        leaves a small timing channel, since MAC performance depends to
1266        some extent on the size of the data fragment, but it is not
1267        believed to be large enough to be exploitable due to the large
1268        block size of existing MACs and the small size of the timing
1269        signal.
1271 6.3. Key calculation
1273    The Record Protocol requires an algorithm to generate keys, and MAC
1274    secrets from the security parameters provided by the handshake
1275    protocol.
1277    The master secret is hashed into a sequence of secure bytes, which
1278    are assigned to the MAC secrets and keys required by the current
1279    connection state (see Appendix A.6). CipherSpecs require a client
1280    write MAC secret, a server write MAC secret, a client write key, and
1281    a server write key, which are generated from the master secret in
1282    that order. Unused values are empty.
1284    When generating keys and MAC secrets, the master secret is used as an
1285    entropy source, and the random values provide unencrypted salt
1286    material for exportable ciphers.
1288    To generate the key material, compute
1290        key_block = PRF(SecurityParameters.master_secret,
1294 Dierks & Rescorla            Standards Track                    [Page 24]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
1297                           "key expansion",
1298                           SecurityParameters.server_random +
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 cipher spec which is defined in this document which requires
1312        the most material is 3DES_EDE_CBC_SHA: it requires 2 x 24 byte
1313        keys, 2 x 20 byte MAC secrets, for a total 88 bytes of key
1314        material.
1316    Exportable encryption algorithms (for which CipherSpec.is_exportable
1317    is true) require additional processing as follows to derive their
1318    final write keys:
1320        final_client_write_key =
1321        PRF(SecurityParameters.client_write_key,
1322                                   "client write key",
1323                                   SecurityParameters.client_random +
1324                                   SecurityParameters.server_random);
1325        final_server_write_key =
1326        PRF(SecurityParameters.server_write_key,
1327                                   "server write key",
1328                                   SecurityParameters.client_random +
1329                                   SecurityParameters.server_random);
1331 6.3.1. Export key generation example
1333    TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5 requires five random bytes for
1334    each of the two encryption keys and 16 bytes for each of the MAC
1335    keys, for a total of 42 bytes of key material. The PRF output is
1336    stored in the key_block. The key_block is partitioned, and the write
1337    keys are salted because this is an exportable encryption algorithm.
1339        key_block               = PRF(master_secret,
1340                                      "key expansion",
1341                                      server_random +
1342                                      client_random)[0..41]
1343        client_write_MAC_secret = key_block[0..15]
1344        server_write_MAC_secret = key_block[16..31]
1348 Dierks & Rescorla            Standards Track                    [Page 25]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
1351        client_write_key        = key_block[32..36]
1352        server_write_key        = key_block[37..41]
1353        final_client_write_key  = PRF(client_write_key,
1354                                      "client write key",
1355                                      client_random +
1356                                      server_random)[0..15]
1357        final_server_write_key  = PRF(server_write_key,
1358                                      "server write key",
1359                                      client_random +
1360                                      server_random)[0..15]
1363 7. The TLS Handshake Protocol
1365    The TLS Handshake Protocol consists of a suite of three sub-protocols
1366    which are used to allow peers to agree upon security parameters for
1367    the record layer, authenticate themselves, instantiate negotiated
1368    security parameters, and report error conditions to each other.
1370    The Handshake Protocol is responsible for negotiating a session,
1371    which consists of the following items:
1373    session identifier
1374        An arbitrary byte sequence chosen by the server to identify an
1375        active or resumable session state.
1377    peer certificate
1378        X509v3 [X509] certificate of the peer. This element of the state
1379        may be null.
1381    compression method
1382        The algorithm used to compress data prior to encryption.
1384    cipher spec
1385        Specifies the bulk data encryption algorithm (such as null, DES,
1386        etc.) and a MAC algorithm (such as MD5 or SHA). It also defines
1387        cryptographic attributes such as the hash_size. (See Appendix A.6
1388        for formal definition)
1390    master secret
1391        48-byte secret shared between the client and server.
1393    is resumable
1394        A flag indicating whether the session can be used to initiate new
1395        connections.
1402 Dierks & Rescorla            Standards Track                    [Page 26]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
1405    These items are then used to create security parameters for use by
1406    the Record Layer when protecting application data. Many connections
1407    can be instantiated using the same session through the resumption
1408    feature of the TLS Handshake Protocol.
1410 7.1. Change cipher spec protocol
1412    The change cipher spec protocol exists to signal transitions in
1413    ciphering strategies. The protocol consists of a single message,
1414    which is encrypted and compressed under the current (not the pending)
1415    connection state. The message consists of a single byte of value 1.
1417        struct {
1418            enum { change_cipher_spec(1), (255) } type;
1419        } ChangeCipherSpec;
1421    The change cipher spec message is sent by both the client and server
1422    to notify the receiving party that subsequent records will be
1423    protected under the newly negotiated CipherSpec and keys. Reception
1424    of this message causes the receiver to instruct the Record Layer to
1425    immediately copy the read pending state into the read current state.
1426    Immediately after sending this message, the sender MUST instruct the
1427    record layer to make the write pending state the write active state.
1428    (See section 6.1.) The change cipher spec message is sent during the
1429    handshake after the security parameters have been agreed upon, but
1430    before the verifying finished message is sent (see section 7.4.9).
1432  Note: if a rehandshake occurs while data is flowing on a connection,
1433    the communicating parties may continue to send data using the old
1434    CipherSpec However, once the ChangeCipherSpec has been sent, the new
1435    CipherSpec MUST be used. The first side to send the ChangeCipherSpec
1436    does not know that the other side has finished computing the new
1437    keying material (e.g. if it has to perform a time consuming public
1438    key operation). Thus, a small window of time during which the
1439    recipient must buffer the data MAY exist. In practice, with modern
1440    machines this interval is likely to be fairly short.
1442 7.2. Alert protocol
1444    One of the content types supported by the TLS Record layer is the
1445    alert type. Alert messages convey the severity of the message and a
1446    description of the alert. Alert messages with a level of fatal result
1447    in the immediate termination of the connection. In this case, other
1448    connections corresponding to the session may continue, but the
1449    session identifier MUST be invalidated, preventing the failed session
1450    from being used to establish new connections. Like other messages,
1451    alert messages are encrypted and compressed, as specified by the
1452    current connection state.
1456 Dierks & Rescorla            Standards Track                    [Page 27]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
1459        enum { warning(1), fatal(2), (255) } AlertLevel;
1461        enum {
1462            close_notify(0),
1463            unexpected_message(10),
1464            bad_record_mac(20),
1465            decryption_failed(21),
1466            record_overflow(22),
1467            decompression_failure(30),
1468            handshake_failure(40),
1469            no_certificate_RESERVED (41),
1470            bad_certificate(42),
1471            unsupported_certificate(43),
1472            certificate_revoked(44),
1473            certificate_expired(45),
1474            certificate_unknown(46),
1475            illegal_parameter(47),
1476            unknown_ca(48),
1477            access_denied(49),
1478            decode_error(50),
1479            decrypt_error(51),
1480            export_restriction(60),
1481            protocol_version(70),
1482            insufficient_security(71),
1483            internal_error(80),
1484            user_canceled(90),
1485            no_renegotiation(100),
1486            (255)
1487        } AlertDescription;
1489        struct {
1490            AlertLevel level;
1491            AlertDescription description;
1492        } Alert;
1494 7.2.1. Closure alerts
1496    The client and the server must share knowledge that the connection is
1497    ending in order to avoid a truncation attack. Either party may
1498    initiate the exchange of closing messages.
1500    close_notify
1501        This message notifies the recipient that the sender will not send
1502        any more messages on this connection. Note that as of TLS 1.1,
1503        failure to properly close a connection no longer requires that a
1504        session not be resumed. This is a change from TLS 1.0 to conform
1505        with widespread implementation practice.
1510 Dierks & Rescorla            Standards Track                    [Page 28]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
1513    Either party may initiate a close by sending a close_notify alert.
1514    Any data received after a closure alert is ignored.
1516    Unless some other fatal alert has been transmitted, each party is
1517    required to send a close_notify alert before closing the write side
1518    of the connection. The other party MUST respond with a close_notify
1519    alert of its own and close down the connection immediately,
1520    discarding any pending writes. It is not required for the initiator
1521    of the close to wait for the responding close_notify alert before
1522    closing the read side of the connection.
1524    If the application protocol using TLS provides that any data may be
1525    carried over the underlying transport after the TLS connection is
1526    closed, the TLS implementation must receive the responding
1527    close_notify alert before indicating to the application layer that
1528    the TLS connection has ended. If the application protocol will not
1529    transfer any additional data, but will only close the underlying
1530    transport connection, then the implementation MAY choose to close the
1531    transport without waiting for the responding close_notify. No part of
1532    this standard should be taken to dictate the manner in which a usage
1533    profile for TLS manages its data transport, including when
1534    connections are opened or closed.
1536    NB: It is assumed that closing a connection reliably delivers
1537        pending data before destroying the transport.
1539 7.2.2. Error alerts
1541    Error handling in the TLS Handshake protocol is very simple. When an
1542    error is detected, the detecting party sends a message to the other
1543    party. Upon transmission or receipt of an fatal alert message, both
1544    parties immediately close the connection. Servers and clients MUST
1545    forget any session-identifiers, keys, and secrets associated with a
1546    failed connection. Thus, any connection terminated with a fatal alert
1547    MUST NOT be resumed. The following error alerts are defined:
1549    unexpected_message
1550        An inappropriate message was received. This alert is always fatal
1551        and should never be observed in communication between proper
1552        implementations.
1554    bad_record_mac
1555        This alert is returned if a record is received with an incorrect
1556        MAC. This alert also SHOULD be returned if a TLSCiphertext
1557        decrypted in an invalid way: either it wasn't an even multiple of
1558        the block length, or its padding values, when checked, weren't
1559        correct. This message is always fatal.
1564 Dierks & Rescorla            Standards Track                    [Page 29]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
1567    decryption_failed
1568        This alert MAY be returned if a TLSCiphertext decrypted in an
1569        invalid way: either it wasn't an even multiple of the block
1570        length, or its padding values, when checked, weren't correct.
1571        This message is always fatal.
1573        NB: Differentiating between bad_record_mac and decryption_failed
1574        alerts may permit certain attacks against CBC mode as used in TLS
1575        [CBCATT]. It is preferable to uniformly use the bad_record_mac
1576        alert to hide the specific type of the error.
1579    record_overflow
1580        A TLSCiphertext record was received which had a length more than
1581        2^14+2048 bytes, or a record decrypted to a TLSCompressed record
1582        with more than 2^14+1024 bytes. This message is always fatal.
1584    decompression_failure
1585        The decompression function received improper input (e.g. data
1586        that would expand to excessive length). This message is always
1587        fatal.
1589    handshake_failure
1590        Reception of a handshake_failure alert message indicates that the
1591        sender was unable to negotiate an acceptable set of security
1592        parameters given the options available. This is a fatal error.
1594    no_certificate_RESERVED
1595        This alert was used in SSLv3 but not in TLS. It should not be
1596        sent by compliant implementations.
1598    bad_certificate
1599        A certificate was corrupt, contained signatures that did not
1600        verify correctly, etc.
1602    unsupported_certificate
1603        A certificate was of an unsupported type.
1605    certificate_revoked
1606        A certificate was revoked by its signer.
1608    certificate_expired
1609        A certificate has expired or is not currently valid.
1611    certificate_unknown
1612        Some other (unspecified) issue arose in processing the
1613        certificate, rendering it unacceptable.
1618 Dierks & Rescorla            Standards Track                    [Page 30]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
1621    illegal_parameter
1622        A field in the handshake was out of range or inconsistent with
1623        other fields. This is always fatal.
1625    unknown_ca
1626        A valid certificate chain or partial chain was received, but the
1627        certificate was not accepted because the CA certificate could not
1628        be located or couldn't be matched with a known, trusted CA.  This
1629        message is always fatal.
1631    access_denied
1632        A valid certificate was received, but when access control was
1633        applied, the sender decided not to proceed with negotiation.
1634        This message is always fatal.
1636    decode_error
1637        A message could not be decoded because some field was out of the
1638        specified range or the length of the message was incorrect. This
1639        message is always fatal.
1641    decrypt_error
1642        A handshake cryptographic operation failed, including being
1643        unable to correctly verify a signature, decrypt a key exchange,
1644        or validate a finished message.
1646    export_restriction
1647        A negotiation not in compliance with export restrictions was
1648        detected; for example, attempting to transfer a 1024 bit
1649        ephemeral RSA key for the RSA_EXPORT handshake method. This
1650        message is always fatal.
1652    protocol_version
1653        The protocol version the client has attempted to negotiate is
1654        recognized, but not supported. (For example, old protocol
1655        versions might be avoided for security reasons). This message is
1656        always fatal.
1658    insufficient_security
1659        Returned instead of handshake_failure when a negotiation has
1660        failed specifically because the server requires ciphers more
1661        secure than those supported by the client. This message is always
1662        fatal.
1664    internal_error
1665        An internal error unrelated to the peer or the correctness of the
1666        protocol makes it impossible to continue (such as a memory
1667        allocation failure). This message is always fatal.
1672 Dierks & Rescorla            Standards Track                    [Page 31]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
1675    user_canceled
1676        This handshake is being canceled for some reason unrelated to a
1677        protocol failure. If the user cancels an operation after the
1678        handshake is complete, just closing the connection by sending a
1679        close_notify is more appropriate. This alert should be followed
1680        by a close_notify. This message is generally a warning.
1682    no_renegotiation
1683        Sent by the client in response to a hello request or by the
1684        server in response to a client hello after initial handshaking.
1685        Either of these would normally lead to renegotiation; when that
1686        is not appropriate, the recipient should respond with this alert;
1687        at that point, the original requester can decide whether to
1688        proceed with the connection. One case where this would be
1689        appropriate would be where a server has spawned a process to
1690        satisfy a request; the process might receive security parameters
1691        (key length, authentication, etc.) at startup and it might be
1692        difficult to communicate changes to these parameters after that
1693        point. This message is always a warning.
1695    For all errors where an alert level is not explicitly specified, the
1696    sending party MAY determine at its discretion whether this is a fatal
1697    error or not; if an alert with a level of warning is received, the
1726 Dierks & Rescorla            Standards Track                    [Page 32]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
1729    receiving party MAY decide at its discretion whether to treat this as
1730    a fatal error or not. However, all messages which are transmitted
1731    with a level of fatal MUST be treated as fatal messages.
1733 7.3. Handshake Protocol overview
1735    The cryptographic parameters of the session state are produced by the
1736    TLS Handshake Protocol, which operates on top of the TLS Record
1737    Layer. When a TLS client and server first start communicating, they
1738    agree on a protocol version, select cryptographic algorithms,
1739    optionally authenticate each other, and use public-key encryption
1740    techniques to generate shared secrets.
1742    The TLS Handshake Protocol involves the following steps:
1744      - - Exchange hello messages to agree on algorithms, exchange random
1745        values, and check for session resumption.
1747      - - Exchange the necessary cryptographic parameters to allow the
1748        client and server to agree on a premaster secret.
1750      - - Exchange certificates and cryptographic information to allow
1751        the client and server to authenticate themselves.
1753      - - Generate a master secret from the premaster secret and
1754        exchanged random values.
1756      - - Provide security parameters to the record layer.
1758      - - Allow the client and server to verify that their peer has
1759        calculated the same security parameters and that the handshake
1760        occurred without tampering by an attacker.
1762    Note that higher layers should not be overly reliant on TLS always
1763    negotiating the strongest possible connection between two peers:
1764    there are a number of ways a man in the middle attacker can attempt
1765    to make two entities drop down to the least secure method they
1766    support. The protocol has been designed to minimize this risk, but
1767    there are still attacks available: for example, an attacker could
1768    block access to the port a secure service runs on, or attempt to get
1769    the peers to negotiate an unauthenticated connection. The fundamental
1770    rule is that higher levels must be cognizant of what their security
1771    requirements are and never transmit information over a channel less
1772    secure than what they require. The TLS protocol is secure, in that
1773    any cipher suite offers its promised level of security: if you
1774    negotiate 3DES with a 1024 bit RSA key exchange with a host whose
1775    certificate you have verified, you can expect to be that secure.
1780 Dierks & Rescorla            Standards Track                    [Page 33]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
1783    However, you SHOULD never send data over a link encrypted with 40 bit
1784    security unless you feel that data is worth no more than the effort
1785    required to break that encryption.
1787    These goals are achieved by the handshake protocol, which can be
1788    summarized as follows: The client sends a client hello message to
1789    which the server must respond with a server hello message, or else a
1790    fatal error will occur and the connection will fail. The client hello
1791    and server hello are used to establish security enhancement
1792    capabilities between client and server. The client hello and server
1793    hello establish the following attributes: Protocol Version, Session
1794    ID, Cipher Suite, and Compression Method. Additionally, two random
1795    values are generated and exchanged: ClientHello.random and
1796    ServerHello.random.
1798    The actual key exchange uses up to four messages: the server
1799    certificate, the server key exchange, the client certificate, and the
1800    client key exchange. New key exchange methods can be created by
1801    specifying a format for these messages and defining the use of the
1802    messages to allow the client and server to agree upon a shared
1803    secret. This secret MUST be quite long; currently defined key
1804    exchange methods exchange secrets which range from 48 to 128 bytes in
1805    length.
1807    Following the hello messages, the server will send its certificate,
1808    if it is to be authenticated. Additionally, a server key exchange
1809    message may be sent, if it is required (e.g. if their server has no
1810    certificate, or if its certificate is for signing only). If the
1811    server is authenticated, it may request a certificate from the
1812    client, if that is appropriate to the cipher suite selected. Now the
1813    server will send the server hello done message, indicating that the
1814    hello-message phase of the handshake is complete. The server will
1815    then wait for a client response. If the server has sent a certificate
1816    request message, the client must send the certificate message. The
1817    client key exchange message is now sent, and the content of that
1818    message will depend on the public key algorithm selected between the
1819    client hello and the server hello. If the client has sent a
1820    certificate with signing ability, a digitally-signed certificate
1821    verify message is sent to explicitly verify the certificate.
1823    At this point, a change cipher spec message is sent by the client,
1824    and the client copies the pending Cipher Spec into the current Cipher
1825    Spec. The client then immediately sends the finished message under
1826    the new algorithms, keys, and secrets. In response, the server will
1827    send its own change cipher spec message, transfer the pending to the
1828    current Cipher Spec, and send its finished message under the new
1834 Dierks & Rescorla            Standards Track                    [Page 34]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
1837    Cipher Spec. At this point, the handshake is complete and the client
1838    and server may begin to exchange application layer data. (See flow
1839    chart below.) Application data MUST NOT be sent prior to the
1840    completion of the first handshake (before a cipher suite other
1841    TLS_NULL_WITH_NULL_NULL is established).
1842       Client                                               Server
1844       ClientHello                  -------->
1845                                                       ServerHello
1846                                                      Certificate*
1847                                                ServerKeyExchange*
1848                                               CertificateRequest*
1849                                    <--------      ServerHelloDone
1850       Certificate*
1851       ClientKeyExchange
1852       CertificateVerify*
1853       [ChangeCipherSpec]
1854       Finished                     -------->
1855                                                [ChangeCipherSpec]
1856                                    <--------             Finished
1857       Application Data             <------->     Application Data
1859              Fig. 1 - Message flow for a full handshake
1861    * Indicates optional or situation-dependent messages that are not
1862    always sent.
1864   Note: To help avoid pipeline stalls, ChangeCipherSpec is an
1865        independent TLS Protocol content type, and is not actually a TLS
1866        handshake message.
1868    When the client and server decide to resume a previous session or
1869    duplicate an existing session (instead of negotiating new security
1870    parameters) the message flow is as follows:
1872    The client sends a ClientHello using the Session ID of the session to
1873    be resumed. The server then checks its session cache for a match.  If
1874    a match is found, and the server is willing to re-establish the
1875    connection under the specified session state, it will send a
1876    ServerHello with the same Session ID value. At this point, both
1877    client and server MUST send change cipher spec messages and proceed
1878    directly to finished messages. Once the re-establishment is complete,
1879    the client and server MAY begin to exchange application layer data.
1880    (See flow chart below.) If a Session ID match is not found, the
1881    server generates a new session ID and the TLS client and server
1882    perform a full handshake.
1888 Dierks & Rescorla            Standards Track                    [Page 35]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
1891       Client                                                Server
1893       ClientHello                   -------->
1894                                                        ServerHello
1895                                                 [ChangeCipherSpec]
1896                                     <--------             Finished
1897       [ChangeCipherSpec]
1898       Finished                      -------->
1899       Application Data              <------->     Application Data
1901           Fig. 2 - Message flow for an abbreviated handshake
1903    The contents and significance of each message will be presented in
1904    detail in the following sections.
1906 7.4. Handshake protocol
1908    The TLS Handshake Protocol is one of the defined higher level clients
1909    of the TLS Record Protocol. This protocol is used to negotiate the
1910    secure attributes of a session. Handshake messages are supplied to
1911    the TLS Record Layer, where they are encapsulated within one or more
1912    TLSPlaintext structures, which are processed and transmitted as
1913    specified by the current active session state.
1915        enum {
1916            hello_request(0), client_hello(1), server_hello(2),
1917            certificate(11), server_key_exchange (12),
1918            certificate_request(13), server_hello_done(14),
1919            certificate_verify(15), client_key_exchange(16),
1920            finished(20), (255)
1921        } HandshakeType;
1923        struct {
1924            HandshakeType msg_type;    /* handshake type */
1925            uint24 length;             /* bytes in message */
1926            select (HandshakeType) {
1927                case hello_request:       HelloRequest;
1928                case client_hello:        ClientHello;
1929                case server_hello:        ServerHello;
1930                case certificate:         Certificate;
1931                case server_key_exchange: ServerKeyExchange;
1932                case certificate_request: CertificateRequest;
1933                case server_hello_done:   ServerHelloDone;
1934                case certificate_verify:  CertificateVerify;
1935                case client_key_exchange: ClientKeyExchange;
1936                case finished:            Finished;
1937            } body;
1938        } Handshake;
1942 Dierks & Rescorla            Standards Track                    [Page 36]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
1945    The handshake protocol messages are presented below in the order they
1946    MUST be sent; sending handshake messages in an unexpected order
1947    results in a fatal error. Unneeded handshake messages can be omitted,
1948    however. Note one exception to the ordering: the Certificate message
1949    is used twice in the handshake (from server to client, then from
1950    client to server), but described only in its first position. The one
1951    message which is not bound by these ordering rules is the Hello
1952    Request message, which can be sent at any time, but which should be
1953    ignored by the client if it arrives in the middle of a handshake.
1955 7.4.1. Hello messages
1957    The hello phase messages are used to exchange security enhancement
1958    capabilities between the client and server. When a new session
1959    begins, the Record Layer's connection state encryption, hash, and
1960    compression algorithms are initialized to null. The current
1961    connection state is used for renegotiation messages.
1963 7.4.1.1. Hello request
1965    When this message will be sent:
1966        The hello request message MAY be sent by the server at any time.
1968    Meaning of this message:
1969        Hello request is a simple notification that the client should
1970        begin the negotiation process anew by sending a client hello
1971        message when convenient. This message will be ignored by the
1972        client if the client is currently negotiating a session. This
1973        message may be ignored by the client if it does not wish to
1974        renegotiate a session, or the client may, if it wishes, respond
1975        with a no_renegotiation alert. Since handshake messages are
1976        intended to have transmission precedence over application data,
1977        it is expected that the negotiation will begin before no more
1978        than a few records are received from the client. If the server
1979        sends a hello request but does not receive a client hello in
1980        response, it may close the connection with a fatal alert.
1982    After sending a hello request, servers SHOULD not repeat the request
1983    until the subsequent handshake negotiation is complete.
1985    Structure of this message:
1986        struct { } HelloRequest;
1988  Note: This message MUST NOT be included in the message hashes which are
1989        maintained throughout the handshake and used in the finished
1990        messages and the certificate verify message.
1996 Dierks & Rescorla            Standards Track                    [Page 37]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
1999 7.4.1.2. Client hello
2001    When this message will be sent:
2002        When a client first connects to a server it is required to send
2003        the client hello as its first message. The client can also send a
2004        client hello in response to a hello request or on its own
2005        initiative in order to renegotiate the security parameters in an
2006        existing connection.
2008        Structure of this message:
2009            The client hello message includes a random structure, which is
2010            used later in the protocol.
2012            struct {
2013               uint32 gmt_unix_time;
2014               opaque random_bytes[28];
2015            } Random;
2017        gmt_unix_time
2018        The current time and date in standard UNIX 32-bit format (seconds
2019        since the midnight starting Jan 1, 1970, GMT) according to the
2020        sender's internal clock. Clocks are not required to be set
2021        correctly by the basic TLS Protocol; higher level or application
2022        protocols may define additional requirements.
2024    random_bytes
2025        28 bytes generated by a secure random number generator.
2027    The client hello message includes a variable length session
2028    identifier. If not empty, the value identifies a session between the
2029    same client and server whose security parameters the client wishes to
2030    reuse. The session identifier MAY be from an earlier connection, this
2031    connection, or another currently active connection. The second option
2032    is useful if the client only wishes to update the random structures
2033    and derived values of a connection, while the third option makes it
2034    possible to establish several independent secure connections without
2035    repeating the full handshake protocol. These independent connections
2036    may occur sequentially or simultaneously; a SessionID becomes valid
2037    when the handshake negotiating it completes with the exchange of
2038    Finished messages and persists until removed due to aging or because
2039    a fatal error was encountered on a connection associated with the
2040    session. The actual contents of the SessionID are defined by the
2041    server.
2043        opaque SessionID<0..32>;
2050 Dierks & Rescorla            Standards Track                    [Page 38]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
2053    Warning:
2054        Because the SessionID is transmitted without encryption or
2055        immediate MAC protection, servers MUST not place confidential
2056        information in session identifiers or let the contents of fake
2057        session identifiers cause any breach of security. (Note that the
2058        content of the handshake as a whole, including the SessionID, is
2059        protected by the Finished messages exchanged at the end of the
2060        handshake.)
2062    The CipherSuite list, passed from the client to the server in the
2063    client hello message, contains the combinations of cryptographic
2064    algorithms supported by the client in order of the client's
2065    preference (favorite choice first). Each CipherSuite defines a key
2066    exchange algorithm, a bulk encryption algorithm (including secret key
2067    length) and a MAC algorithm. The server will select a cipher suite
2068    or, if no acceptable choices are presented, return a handshake
2069    failure alert and close the connection.
2071        uint8 CipherSuite[2];    /* Cryptographic suite selector */
2073    The client hello includes a list of compression algorithms supported
2074    by the client, ordered according to the client's preference.
2076        enum { null(0), (255) } CompressionMethod;
2078        struct {
2079            ProtocolVersion client_version;
2080            Random random;
2081            SessionID session_id;
2082            CipherSuite cipher_suites<2..2^16-1>;
2083            CompressionMethod compression_methods<1..2^8-1>;
2084        } ClientHello;
2086    client_version
2087        The version of the TLS protocol by which the client wishes to
2088        communicate during this session. This SHOULD be the latest
2089        (highest valued) version supported by the client. For this
2090        version of the specification, the version will be 3.2 (See
2091        Appendix E for details about backward compatibility).
2093    random
2094        A client-generated random structure.
2096    session_id
2097        The ID of a session the client wishes to use for this connection.
2098        This field should be empty if no session_id is available or the
2099        client wishes to generate new security parameters.
2104 Dierks & Rescorla            Standards Track                    [Page 39]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
2107    cipher_suites
2108        This is a list of the cryptographic options supported by the
2109        client, with the client's first preference first. If the
2110        session_id field is not empty (implying a session resumption
2111        request) this vector MUST include at least the cipher_suite from
2112        that session. Values are defined in Appendix A.5.
2114    compression_methods
2115        This is a list of the compression methods supported by the
2116        client, sorted by client preference. If the session_id field is
2117        not empty (implying a session resumption request) it must include
2118        the compression_method from that session. This vector must
2119        contain, and all implementations must support,
2120        CompressionMethod.null. Thus, a client and server will always be
2121        able to agree on a compression method.
2123    After sending the client hello message, the client waits for a server
2124    hello message. Any other handshake message returned by the server
2125    except for a hello request is treated as a fatal error.
2127    Forward compatibility note:
2128        In the interests of forward compatibility, it is permitted for a
2129        client hello message to include extra data after the compression
2130        methods. This data MUST be included in the handshake hashes, but
2131        must otherwise be ignored. This is the only handshake message for
2132        which this is legal; for all other messages, the amount of data
2133        in the message MUST match the description of the message
2134        precisely.
2136 Note: For the intended use of trailing data in the ClientHello, see RFC
2137        3546 [TLSEXT].
2139 7.4.1.3. Server hello
2141    When this message will be sent:
2142        The server will send this message in response to a client hello
2143        message when it was able to find an acceptable set of algorithms.
2144        If it cannot find such a match, it will respond with a handshake
2145        failure alert.
2147    Structure of this message:
2148        struct {
2149            ProtocolVersion server_version;
2150            Random random;
2151            SessionID session_id;
2152            CipherSuite cipher_suite;
2153            CompressionMethod compression_method;
2154        } ServerHello;
2158 Dierks & Rescorla            Standards Track                    [Page 40]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
2161    server_version
2162        This field will contain the lower of that suggested by the client
2163        in the client hello and the highest supported by the server. For
2164        this version of the specification, the version is 3.2 (See
2165        Appendix E for details about backward compatibility).
2167    random
2168        This structure is generated by the server and MUST be
2169        independently generated from the ClientHello.random.
2171    session_id
2172        This is the identity of the session corresponding to this
2173        connection. If the ClientHello.session_id was non-empty, the
2174        server will look in its session cache for a match. If a match is
2175        found and the server is willing to establish the new connection
2176        using the specified session state, the server will respond with
2177        the same value as was supplied by the client. This indicates a
2178        resumed session and dictates that the parties must proceed
2179        directly to the finished messages. Otherwise this field will
2180        contain a different value identifying the new session. The server
2181        may return an empty session_id to indicate that the session will
2182        not be cached and therefore cannot be resumed. If a session is
2183        resumed, it must be resumed using the same cipher suite it was
2184        originally negotiated with.
2186    cipher_suite
2187        The single cipher suite selected by the server from the list in
2188        ClientHello.cipher_suites. For resumed sessions this field is the
2189        value from the state of the session being resumed.
2191    compression_method
2192        The single compression algorithm selected by the server from the
2193        list in ClientHello.compression_methods. For resumed sessions
2194        this field is the value from the resumed session state.
2196 7.4.2. Server certificate
2198    When this message will be sent:
2199        The server MUST send a certificate whenever the agreed-upon key
2200        exchange method is not an anonymous one. This message will always
2201        immediately follow the server hello message.
2203    Meaning of this message:
2204        The certificate type MUST be appropriate for the selected cipher
2205        suite's key exchange algorithm, and is generally an X.509v3
2206        certificate. It MUST contain a key which matches the key exchange
2207        method, as follows. Unless otherwise specified, the signing
2212 Dierks & Rescorla            Standards Track                    [Page 41]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
2215        algorithm for the certificate MUST be the same as the algorithm
2216        for the certificate key. Unless otherwise specified, the public
2217        key MAY be of any length.
2219        Key Exchange Algorithm  Certificate Key Type
2221        RSA                     RSA public key; the certificate MUST
2222                                allow the key to be used for encryption.
2224        RSA_EXPORT              RSA public key of length greater than
2225                                512 bits which can be used for signing,
2226                                or a key of 512 bits or shorter which
2227                                can be used for encryption.
2229        DHE_DSS                 DSS public key.
2231        DHE_DSS_EXPORT          DSS public key.
2233        DHE_RSA                 RSA public key which can be used for
2234                                signing.
2236        DHE_RSA_EXPORT          RSA public key which can be used for
2237                                signing.
2239        DH_DSS                  Diffie-Hellman key. The algorithm used
2240                                to sign the certificate MUST be DSS.
2242        DH_RSA                  Diffie-Hellman key. The algorithm used
2243                                to sign the certificate MUST be RSA.
2245    All certificate profiles, key and cryptographic formats are defined
2246    by the IETF PKIX working group [PKIX]. When a key usage extension is
2247    present, the digitalSignature bit MUST be set for the key to be
2248    eligible for signing, as described above, and the keyEncipherment bit
2249    MUST be present to allow encryption, as described above. The
2250    keyAgreement bit must be set on Diffie-Hellman certificates.
2252    As CipherSuites which specify new key exchange methods are specified
2253    for the TLS Protocol, they will imply certificate format and the
2254    required encoded keying information.
2256    Structure of this message:
2257        opaque ASN.1Cert<1..2^24-1>;
2259        struct {
2260            ASN.1Cert certificate_list<0..2^24-1>;
2261        } Certificate;
2266 Dierks & Rescorla            Standards Track                    [Page 42]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
2269    certificate_list
2270        This is a sequence (chain) of X.509v3 certificates. The sender's
2271        certificate must come first in the list. Each following
2272        certificate must directly certify the one preceding it. Because
2273        certificate validation requires that root keys be distributed
2274        independently, the self-signed certificate which specifies the
2275        root certificate authority may optionally be omitted from the
2276        chain, under the assumption that the remote end must already
2277        possess it in order to validate it in any case.
2279    The same message type and structure will be used for the client's
2280    response to a certificate request message. Note that a client MAY
2281    send no certificates if it does not have an appropriate certificate
2282    to send in response to the server's authentication request.
2284  Note: PKCS #7 [PKCS7] is not used as the format for the certificate
2285        vector because PKCS #6 [PKCS6] extended certificates are not
2286        used. Also PKCS #7 defines a SET rather than a SEQUENCE, making
2287        the task of parsing the list more difficult.
2289 7.4.3. Server key exchange message
2291    When this message will be sent:
2292        This message will be sent immediately after the server
2293        certificate message (or the server hello message, if this is an
2294        anonymous negotiation).
2296        The server key exchange message is sent by the server only when
2297        the server certificate message (if sent) does not contain enough
2298        data to allow the client to exchange a premaster secret. This is
2299        true for the following key exchange methods:
2301            RSA_EXPORT (if the public key in the server certificate is
2302            longer than 512 bits)
2303            DHE_DSS
2304            DHE_DSS_EXPORT
2305            DHE_RSA
2306            DHE_RSA_EXPORT
2307            DH_anon
2309        It is not legal to send the server key exchange message for the
2310        following key exchange methods:
2312            RSA
2313            RSA_EXPORT (when the public key in the server certificate is
2314            less than or equal to 512 bits in length)
2315            DH_DSS
2316            DH_RSA
2320 Dierks & Rescorla            Standards Track                    [Page 43]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
2323    Meaning of this message:
2324        This message conveys cryptographic information to allow the
2325        client to communicate the premaster secret: either an RSA public
2326        key to encrypt the premaster secret with, or a Diffie-Hellman
2327        public key with which the client can complete a key exchange
2328        (with the result being the premaster secret.)
2330    As additional CipherSuites are defined for TLS which include new key
2331    exchange algorithms, the server key exchange message will be sent if
2332    and only if the certificate type associated with the key exchange
2333    algorithm does not provide enough information for the client to
2334    exchange a premaster secret.
2336  Note: According to current US export law, RSA moduli larger than 512
2337        bits may not be used for key exchange in software exported from
2338        the US. With this message, the larger RSA keys encoded in
2339        certificates may be used to sign temporary shorter RSA keys for
2340        the RSA_EXPORT key exchange method.
2342    Structure of this message:
2343        enum { rsa, diffie_hellman } KeyExchangeAlgorithm;
2345        struct {
2346            opaque rsa_modulus<1..2^16-1>;
2347            opaque rsa_exponent<1..2^16-1>;
2348        } ServerRSAParams;
2350        rsa_modulus
2351            The modulus of the server's temporary RSA key.
2353        rsa_exponent
2354            The public exponent of the server's temporary RSA key.
2356        struct {
2357            opaque dh_p<1..2^16-1>;
2358            opaque dh_g<1..2^16-1>;
2359            opaque dh_Ys<1..2^16-1>;
2360        } ServerDHParams;     /* Ephemeral DH parameters */
2362        dh_p
2363            The prime modulus used for the Diffie-Hellman operation.
2365        dh_g
2366            The generator used for the Diffie-Hellman operation.
2368        dh_Ys
2369            The server's Diffie-Hellman public value (g^X mod p).
2374 Dierks & Rescorla            Standards Track                    [Page 44]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
2377        struct {
2378            select (KeyExchangeAlgorithm) {
2379                case diffie_hellman:
2380                    ServerDHParams params;
2381                    Signature signed_params;
2382                case rsa:
2383                    ServerRSAParams params;
2384                    Signature signed_params;
2385            };
2386        } ServerKeyExchange;
2388        struct {
2389            select (KeyExchangeAlgorithm) {
2390                case diffie_hellman:
2391                    ServerDHParams params;
2392                case rsa:
2393                    ServerRSAParams params;
2394            };
2395         } ServerParams;
2397        params
2398            The server's key exchange parameters.
2400        signed_params
2401            For non-anonymous key exchanges, a hash of the corresponding
2402            params value, with the signature appropriate to that hash
2403            applied.
2405        md5_hash
2406            MD5(ClientHello.random + ServerHello.random + ServerParams);
2408        sha_hash
2409            SHA(ClientHello.random + ServerHello.random + ServerParams);
2411        enum { anonymous, rsa, dsa } SignatureAlgorithm;
2414        select (SignatureAlgorithm)
2415        {
2416            case anonymous: struct { };
2417            case rsa:
2418                digitally-signed struct {
2419                    opaque md5_hash[16];
2420                    opaque sha_hash[20];
2421                };
2422            case dsa:
2423                digitally-signed struct {
2424                    opaque sha_hash[20];
2428 Dierks & Rescorla            Standards Track                    [Page 45]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
2431                };
2432        } Signature;
2434 7.4.4. Certificate request
2436    When this message will be sent:
2437        A non-anonymous server can optionally request a certificate from
2438        the client, if appropriate for the selected cipher suite. This
2439        message, if sent, will immediately follow the Server Key Exchange
2440        message (if it is sent; otherwise, the Server Certificate
2441        message).
2443    Structure of this message:
2444        enum {
2445            rsa_sign(1), dss_sign(2), rsa_fixed_dh(3), dss_fixed_dh(4),
2446         rsa_ephemeral_dh_RESERVED(5), dss_ephemeral_dh_RESERVED(6),
2447         fortezza_dms_RESERVED(20),
2448            (255)
2449        } ClientCertificateType;
2451        opaque DistinguishedName<1..2^16-1>;
2453        struct {
2454            ClientCertificateType certificate_types<1..2^8-1>;
2455            DistinguishedName certificate_authorities<0..2^16-1>;
2456        } CertificateRequest;
2458        certificate_types
2459            This field is a list of the types of certificates requested,
2460            sorted in order of the server's preference.
2462        certificate_authorities
2463            A list of the distinguished names of acceptable certificate
2464            authorities. These distinguished names may specify a desired
2465            distinguished name for a root CA or for a subordinate CA;
2466            thus, this message can be used both to describe known roots
2467            and a desired authorization space. If the
2468            certificate_authorities list is empty then the client MAY
2469            send any certificate of the appropriate
2470            ClientCertificateType, unless there is some external
2471            arrangement to the contrary.
2474  ClientCertificateType values are divided into three groups:
2476               1. Values from 0 (zero) through 63 decimal (0x3F)
2477            inclusive are
2478                  reserved for IETF Standards Track protocols.
2482 Dierks & Rescorla            Standards Track                    [Page 46]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
2485               2. Values from 64 decimal (0x40) through 223 decimal
2486            (0xDF) inclusive
2487                  are reserved for assignment for non-Standards Track
2488            methods.
2490               3. Values from 224 decimal (0xE0) through 255 decimal
2491            (0xFF)
2492                  inclusive are reserved for private use.
2494            Additional information describing the role of IANA in the
2495            allocation of ClientCertificateType code points is described
2496            in Section XXX.
2498            Note: Values listed as RESERVED may not be used. They were
2499            used in SSLv3.
2501  Note: DistinguishedName is derived from [X509].
2503  Note: It is a fatal handshake_failure alert for an anonymous server to
2504        request client authentication.
2506 7.4.5. Server hello done
2508    When this message will be sent:
2509        The server hello done message is sent by the server to indicate
2510        the end of the server hello and associated messages. After
2511        sending this message the server will wait for a client response.
2513    Meaning of this message:
2514        This message means that the server is done sending messages to
2515        support the key exchange, and the client can proceed with its
2516        phase of the key exchange.
2518        Upon receipt of the server hello done message the client SHOULD
2519        verify that the server provided a valid certificate if required
2520        and check that the server hello parameters are acceptable.
2522    Structure of this message:
2523        struct { } ServerHelloDone;
2525 7.4.6. Client certificate
2527    When this message will be sent:
2528        This is the first message the client can send after receiving a
2529        server hello done message. This message is only sent if the
2530        server requests a certificate. If no suitable certificate is
2531        available, the client should send a certificate message
2532        containing no certificates: I.e. the certificate_list structure
2536 Dierks & Rescorla            Standards Track                    [Page 47]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
2539        should have a length of zero. If client authentication is
2540        required by the server for the handshake to continue, it may
2541        respond with a fatal handshake failure alert. Client certificates
2542        are sent using the Certificate structure defined in Section
2543        7.4.2.
2546  Note: When using a static Diffie-Hellman based key exchange method
2547        (DH_DSS or DH_RSA), if client authentication is requested, the
2548        Diffie-Hellman group and generator encoded in the client's
2549        certificate must match the server specified Diffie-Hellman
2550        parameters if the client's parameters are to be used for the key
2551        exchange.
2553 7.4.7. Client key exchange message
2555    When this message will be sent:
2556        This message is always sent by the client. It will immediately
2557        follow the client certificate message, if it is sent. Otherwise
2558        it will be the first message sent by the client after it receives
2559        the server hello done message.
2561    Meaning of this message:
2562        With this message, the premaster secret is set, either though
2563        direct transmission of the RSA-encrypted secret, or by the
2564        transmission of Diffie-Hellman parameters which will allow each
2565        side to agree upon the same premaster secret. When the key
2566        exchange method is DH_RSA or DH_DSS, client certification has
2567        been requested, and the client was able to respond with a
2568        certificate which contained a Diffie-Hellman public key whose
2569        parameters (group and generator) matched those specified by the
2570        server in its certificate, this message MUST not contain any
2571        data.
2573    Structure of this message:
2574        The choice of messages depends on which key exchange method has
2575        been selected. See Section 7.4.3 for the KeyExchangeAlgorithm
2576        definition.
2578        struct {
2579            select (KeyExchangeAlgorithm) {
2580                case rsa: EncryptedPreMasterSecret;
2581                case diffie_hellman: ClientDiffieHellmanPublic;
2582            } exchange_keys;
2583        } ClientKeyExchange;
2585 7.4.7.1. RSA encrypted premaster secret message
2590 Dierks & Rescorla            Standards Track                    [Page 48]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
2593    Meaning of this message:
2594        If RSA is being used for key agreement and authentication, the
2595        client generates a 48-byte premaster secret, encrypts it using
2596        the public key from the server's certificate or the temporary RSA
2597        key provided in a server key exchange message, and sends the
2598        result in an encrypted premaster secret message. This structure
2599        is a variant of the client key exchange message, not a message in
2600        itself.
2602    Structure of this message:
2603        struct {
2604            ProtocolVersion client_version;
2605            opaque random[46];
2606        } PreMasterSecret;
2608        client_version
2609            The latest (newest) version supported by the client. This is
2610            used to detect version roll-back attacks. Upon receiving the
2611            premaster secret, the server SHOULD check that this value
2612            matches the value transmitted by the client in the client
2613            hello message.
2615        random
2616            46 securely-generated random bytes.
2618        struct {
2619            public-key-encrypted PreMasterSecret pre_master_secret;
2620        } EncryptedPreMasterSecret;
2622        pre_master_secret
2623            This random value is generated by the client and is used to
2624            generate the master secret, as specified in Section 8.1.
2626  Note: An attack discovered by Daniel Bleichenbacher [BLEI] can be used
2627        to attack a TLS server which is using PKCS#1 encoded RSA. The
2628        attack takes advantage of the fact that by failing in different
2629        ways, a TLS server can be coerced into revealing whether a
2630        particular message, when decrypted, is properly PKCS#1 formatted
2631        or not.
2633        The best way to avoid vulnerability to this attack is to treat
2634        incorrectly formatted messages in a manner indistinguishable from
2635        correctly formatted RSA blocks. Thus, when it receives an
2636        incorrectly formatted RSA block, a server should generate a
2637        random 48-byte value and proceed using it as the premaster
2638        secret. Thus, the server will act identically whether the
2639        received RSA block is correctly encoded or not.
2644 Dierks & Rescorla            Standards Track                    [Page 49]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
2647  Implementation Note: public-key-encrypted data is represented as an
2648        opaque vector <0..2^16-1> (see S. 4.7). Thus the RSA-encrypted
2649        PreMaster Secret in a ClientKeyExchange is preceded by two length
2650        bytes. These bytes are redundant in the case of RSA because the
2651        EncryptedPreMasterSecret is the only data in the
2652        ClientKeyExchange and its length can therefore be unambiguously
2653        determined. The SSLv3 specification was not clear about the
2654        encoding of public-key-encrypted data and therefore many SSLv3
2655        implementations do not include the the length bytes, encoding the
2656        RSA encrypted data directly in the ClientKeyExchange message.
2658        This specification requires correct encoding of the
2659        EncryptedPreMasterSecret complete with length bytes. The
2660        resulting PDU is incompatible with many SSLv3 implementations.
2661        Implementors upgrading from SSLv3 must modify their
2662        implementations to generate and accept the correct encoding.
2663        Implementors who wish to be compatible with both SSLv3 and TLS
2664        should make their implementation's behavior dependent on the
2665        protocol version.
2667  Implementation Note: It is now known that remote timing-based attacks
2668        on SSL are possible, at least when the client and server are on
2669        the same LAN. Accordingly, implementations which use static RSA
2670        keys SHOULD use RSA blinding or some other anti-timing technique,
2671        as described in [TIMING].
2673  Note: The version number in the PreMasterSecret is that offered by the
2674        client, NOT the version negotiated for the connection. This
2675        feature is designed to prevent rollback attacks. Unfortunately,
2676        many implementations use the negotiated version instead and
2677        therefore checking the version number may lead to failure to
2678        interoperate with such incorrect client implementations. Client
2679        implementations MUST and Server implementations MAY check the
2680        version number. In practice, since there are no significant known
2681        security differences between TLS and SSLv3, rollback to SSLv3 is
2682        not believed to be a serious security risk.  Note that if servers
2683        choose to to check the version number, they should randomize the
2684        PreMasterSecret in case of error, rather than generate an alert,
2685        in order to avoid variants on the Bleichenbacher attack. [KPR03]
2687 7.4.7.2. Client Diffie-Hellman public value
2689    Meaning of this message:
2690        This structure conveys the client's Diffie-Hellman public value
2691        (Yc) if it was not already included in the client's certificate.
2692        The encoding used for Yc is determined by the enumerated
2693        PublicValueEncoding. This structure is a variant of the client
2694        key exchange message, not a message in itself.
2698 Dierks & Rescorla            Standards Track                    [Page 50]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
2701    Structure of this message:
2702        enum { implicit, explicit } PublicValueEncoding;
2704        implicit
2705            If the client certificate already contains a suitable Diffie-
2706            Hellman key, then Yc is implicit and does not need to be sent
2707            again. In this case, the Client Key Exchange message will be
2708            sent, but will be empty.
2710        explicit
2711            Yc needs to be sent.
2713        struct {
2714            select (PublicValueEncoding) {
2715                case implicit: struct { };
2716                case explicit: opaque dh_Yc<1..2^16-1>;
2717            } dh_public;
2718        } ClientDiffieHellmanPublic;
2720        dh_Yc
2721            The client's Diffie-Hellman public value (Yc).
2723 7.4.8. Certificate verify
2725    When this message will be sent:
2726        This message is used to provide explicit verification of a client
2727        certificate. This message is only sent following a client
2728        certificate that has signing capability (i.e. all certificates
2729        except those containing fixed Diffie-Hellman parameters). When
2730        sent, it will immediately follow the client key exchange message.
2732    Structure of this message:
2733        struct {
2734             Signature signature;
2735        } CertificateVerify;
2737        The Signature type is defined in 7.4.3.
2739        CertificateVerify.signature.md5_hash
2740            MD5(handshake_messages);
2742        CertificateVerify.signature.sha_hash
2743            SHA(handshake_messages);
2745    Here handshake_messages refers to all handshake messages sent or
2746    received starting at client hello up to but not including this
2747    message, including the type and length fields of the handshake
2748    messages. This is the concatenation of all the Handshake structures
2752 Dierks & Rescorla            Standards Track                    [Page 51]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
2755    as defined in 7.4 exchanged thus far.
2757 7.4.9. Finished
2759    When this message will be sent:
2760        A finished message is always sent immediately after a change
2761        cipher spec message to verify that the key exchange and
2762        authentication processes were successful. It is essential that a
2763        change cipher spec message be received between the other
2764        handshake messages and the Finished message.
2766    Meaning of this message:
2767        The finished message is the first protected with the just-
2768        negotiated algorithms, keys, and secrets. Recipients of finished
2769        messages MUST verify that the contents are correct.  Once a side
2770        has sent its Finished message and received and validated the
2771        Finished message from its peer, it may begin to send and receive
2772        application data over the connection.
2774        struct {
2775            opaque verify_data[12];
2776        } Finished;
2778        verify_data
2779            PRF(master_secret, finished_label, MD5(handshake_messages) +
2780            SHA-1(handshake_messages)) [0..11];
2782        finished_label
2783            For Finished messages sent by the client, the string "client
2784            finished". For Finished messages sent by the server, the
2785            string "server finished".
2787        handshake_messages
2788            All of the data from all handshake messages up to but not
2789            including this message. This is only data visible at the
2790            handshake layer and does not include record layer headers.
2791            This is the concatenation of all the Handshake structures as
2792            defined in 7.4 exchanged thus far.
2794    It is a fatal error if a finished message is not preceded by a change
2795    cipher spec message at the appropriate point in the handshake.
2797    The value handshake_messages includes all handshake messages starting
2798    at client hello up to, but not including, this finished message. This
2799    may be different from handshake_messages in Section 7.4.8 because it
2800    would include the certificate verify message (if sent). Also, the
2801    handshake_messages for the finished message sent by the client will
2802    be different from that for the finished message sent by the server,
2806 Dierks & Rescorla            Standards Track                    [Page 52]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
2809    because the one which is sent second will include the prior one.
2811  Note: Change cipher spec messages, alerts and any other record types
2812        are not handshake messages and are not included in the hash
2813        computations. Also, Hello Request messages are omitted from
2814        handshake hashes.
2816 8. Cryptographic computations
2818    In order to begin connection protection, the TLS Record Protocol
2819    requires specification of a suite of algorithms, a master secret, and
2820    the client and server random values. The authentication, encryption,
2821    and MAC algorithms are determined by the cipher_suite selected by the
2822    server and revealed in the server hello message. The compression
2823    algorithm is negotiated in the hello messages, and the random values
2824    are exchanged in the hello messages. All that remains is to calculate
2825    the master secret.
2827 8.1. Computing the master secret
2829    For all key exchange methods, the same algorithm is used to convert
2830    the pre_master_secret into the master_secret. The pre_master_secret
2831    should be deleted from memory once the master_secret has been
2832    computed.
2834        master_secret = PRF(pre_master_secret, "master secret",
2835                            ClientHello.random + ServerHello.random)
2836        [0..47];
2838    The master secret is always exactly 48 bytes in length. The length of
2839    the premaster secret will vary depending on key exchange method.
2860 Dierks & Rescorla            Standards Track                    [Page 53]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
2863 8.1.1. RSA
2865    When RSA is used for server authentication and key exchange, a
2866    48-byte pre_master_secret is generated by the client, encrypted under
2867    the server's public key, and sent to the server. The server uses its
2868    private key to decrypt the pre_master_secret. Both parties then
2869    convert the pre_master_secret into the master_secret, as specified
2870    above.
2872    RSA digital signatures are performed using PKCS #1 [PKCS1] block type
2873    1. RSA public key encryption is performed using PKCS #1 block type 2.
2875 8.1.2. Diffie-Hellman
2877    A conventional Diffie-Hellman computation is performed. The
2878    negotiated key (Z) is used as the pre_master_secret, and is converted
2879    into the master_secret, as specified above.  Leading 0 bytes of Z are
2880    stripped before it is used as the pre_master_secret.
2882  Note: Diffie-Hellman parameters are specified by the server, and may
2883        be either ephemeral or contained within the server's certificate.
2885 9. Mandatory Cipher Suites
2887    In the absence of an application profile standard specifying
2888    otherwise, a TLS compliant application MUST implement the cipher
2889    suite TLS_RSA_WITH_3DES_EDE_CBC_SHA.
2891    The 40-bit cipher suites are known to be susceptible to exhaustive
2892    search attack by commercial attackers. Implementations of this
2893    document SHOULD disable them by default if they are supported at all.
2894    A future version of this document may remove them entirely.
2896 10. Application data protocol
2898    Application data messages are carried by the Record Layer and are
2899    fragmented, compressed and encrypted based on the current connection
2900    state. The messages are treated as transparent data to the record
2901    layer.
2903 10. IANA Considerations
2905    Section 7.4.3 describes a registry of ClientCertificateType code
2906    points to be maintained by the IANA, as defining a number of such
2907    code point identifiers. ClientCertificateType identifiers with values
2908    in the range 0-63 (decimal) inclusive are assigned via RFC 2434
2909    Standards Action. Values from the range 64-223 (decimal)  inclusive
2910    are assigned via RFC 2434 Specification Required.  Identifier values
2914 Dierks & Rescorla            Standards Track                    [Page 54]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
2917    from 224-255 (decimal) inclusive are reserved for RFC 2434 Private
2918    Use.
2920    Section A.5 describes a registry of cipher suite identifiers to be
2921    maintained by the IANA, as well as defining a number of such cipher
2922    suite identifiers. Cipher suite values with the first byte in the
2923    range 0-191 (decimal) inclusive are assigned via RFC 2434 Standards
2924    Action. Values with the first byte in the range 192-254 (decimal) are
2925    assigned via RFC 2434 Specification Required. Values with the first
2926    byte 255 (decimal) are reserved for RFC 2434 Private Use.
2968 Dierks & Rescorla            Standards Track                    [Page 55]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
2971 A. Protocol constant values
2973    This section describes protocol types and constants.
2975 A.1. Record layer
2977     struct {
2978         uint8 major, minor;
2979     } ProtocolVersion;
2981     ProtocolVersion version = { 3, 2 };     /* TLS v1.1 */
2983     enum {
2984         change_cipher_spec(20), alert(21), handshake(22),
2985         application_data(23), (255)
2986     } ContentType;
2988     struct {
2989         ContentType type;
2990         ProtocolVersion version;
2991         uint16 length;
2992         opaque fragment[TLSPlaintext.length];
2993     } TLSPlaintext;
2995     struct {
2996         ContentType type;
2997         ProtocolVersion version;
2998         uint16 length;
2999         opaque fragment[TLSCompressed.length];
3000     } TLSCompressed;
3002     struct {
3003         ContentType type;
3004         ProtocolVersion version;
3005         uint16 length;
3006         select (CipherSpec.cipher_type) {
3007             case stream: GenericStreamCipher;
3008             case block:  GenericBlockCipher;
3009         } fragment;
3010     } TLSCiphertext;
3012     stream-ciphered struct {
3013         opaque content[TLSCompressed.length];
3014         opaque MAC[CipherSpec.hash_size];
3015     } GenericStreamCipher;
3017     block-ciphered struct {
3018         opaque IV[CipherSpec.block_length];
3022 Dierks & Rescorla            Standards Track                    [Page 56]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
3025         opaque content[TLSCompressed.length];
3026         opaque MAC[CipherSpec.hash_size];
3027         uint8 padding[GenericBlockCipher.padding_length];
3028         uint8 padding_length;
3029     } GenericBlockCipher;
3031 A.2. Change cipher specs message
3033     struct {
3034         enum { change_cipher_spec(1), (255) } type;
3035     } ChangeCipherSpec;
3037 A.3. Alert messages
3039     enum { warning(1), fatal(2), (255) } AlertLevel;
3041         enum {
3042             close_notify(0),
3043             unexpected_message(10),
3044             bad_record_mac(20),
3045             decryption_failed(21),
3046             record_overflow(22),
3047             decompression_failure(30),
3048             handshake_failure(40),
3049          no_certificate_RESERVED (41),
3050             bad_certificate(42),
3051             unsupported_certificate(43),
3052             certificate_revoked(44),
3053             certificate_expired(45),
3054             certificate_unknown(46),
3055             illegal_parameter(47),
3056             unknown_ca(48),
3057             access_denied(49),
3058             decode_error(50),
3059             decrypt_error(51),
3060             export_restriction(60),
3061             protocol_version(70),
3062             insufficient_security(71),
3063             internal_error(80),
3064             user_canceled(90),
3065             no_renegotiation(100),
3066             (255)
3067         } AlertDescription;
3069     struct {
3070         AlertLevel level;
3071         AlertDescription description;
3072     } Alert;
3076 Dierks & Rescorla            Standards Track                    [Page 57]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
3079 A.4. Handshake protocol
3081     enum {
3082         hello_request(0), client_hello(1), server_hello(2),
3083         certificate(11), server_key_exchange (12),
3084         certificate_request(13), server_hello_done(14),
3085         certificate_verify(15), client_key_exchange(16),
3086         finished(20), (255)
3087     } HandshakeType;
3089     struct {
3090         HandshakeType msg_type;
3091         uint24 length;
3092         select (HandshakeType) {
3093             case hello_request:       HelloRequest;
3094             case client_hello:        ClientHello;
3095             case server_hello:        ServerHello;
3096             case certificate:         Certificate;
3097             case server_key_exchange: ServerKeyExchange;
3098             case certificate_request: CertificateRequest;
3099             case server_hello_done:   ServerHelloDone;
3100             case certificate_verify:  CertificateVerify;
3101             case client_key_exchange: ClientKeyExchange;
3102             case finished:            Finished;
3103         } body;
3104     } Handshake;
3106 A.4.1. Hello messages
3108     struct { } HelloRequest;
3110     struct {
3111         uint32 gmt_unix_time;
3112         opaque random_bytes[28];
3113     } Random;
3115     opaque SessionID<0..32>;
3117     uint8 CipherSuite[2];
3119     enum { null(0), (255) } CompressionMethod;
3121     struct {
3122         ProtocolVersion client_version;
3123         Random random;
3124         SessionID session_id;
3125         CipherSuite cipher_suites<2..2^16-1>;
3126         CompressionMethod compression_methods<1..2^8-1>;
3130 Dierks & Rescorla            Standards Track                    [Page 58]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
3133     } ClientHello;
3135     struct {
3136         ProtocolVersion server_version;
3137         Random random;
3138         SessionID session_id;
3139         CipherSuite cipher_suite;
3140         CompressionMethod compression_method;
3141     } ServerHello;
3143 A.4.2. Server authentication and key exchange messages
3145     opaque ASN.1Cert<2^24-1>;
3147     struct {
3148         ASN.1Cert certificate_list<0..2^24-1>;
3149     } Certificate;
3151     enum { rsa, diffie_hellman } KeyExchangeAlgorithm;
3153     struct {
3154         opaque RSA_modulus<1..2^16-1>;
3155         opaque RSA_exponent<1..2^16-1>;
3156     } ServerRSAParams;
3158     struct {
3159         opaque DH_p<1..2^16-1>;
3160         opaque DH_g<1..2^16-1>;
3161         opaque DH_Ys<1..2^16-1>;
3162     } ServerDHParams;
3164     struct {
3165         select (KeyExchangeAlgorithm) {
3166             case diffie_hellman:
3167                 ServerDHParams params;
3168                 Signature signed_params;
3169             case rsa:
3170                 ServerRSAParams params;
3171                 Signature signed_params;
3172         };
3173     } ServerKeyExchange;
3175     enum { anonymous, rsa, dsa } SignatureAlgorithm;
3177     struct {
3178         select (KeyExchangeAlgorithm) {
3179             case diffie_hellman:
3180                 ServerDHParams params;
3184 Dierks & Rescorla            Standards Track                    [Page 59]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
3187             case rsa:
3188                 ServerRSAParams params;
3189         };
3190      } ServerParams;
3192     select (SignatureAlgorithm)
3193     {   case anonymous: struct { };
3194         case rsa:
3195             digitally-signed struct {
3196                 opaque md5_hash[16];
3197                 opaque sha_hash[20];
3198             };
3199         case dsa:
3200             digitally-signed struct {
3201                 opaque sha_hash[20];
3202             };
3203     } Signature;
3205     enum {
3206         rsa_sign(1), dss_sign(2), rsa_fixed_dh(3), dss_fixed_dh(4),
3207      rsa_ephemeral_dh_RESERVED(5), dss_ephemeral_dh_RESERVED(6),
3208      fortezza_dms_RESERVED(20),
3209      (255)
3210     } ClientCertificateType;
3212     opaque DistinguishedName<1..2^16-1>;
3214     struct {
3215         ClientCertificateType certificate_types<1..2^8-1>;
3216         DistinguishedName certificate_authorities<0..2^16-1>;
3217     } CertificateRequest;
3219     struct { } ServerHelloDone;
3221 A.4.3. Client authentication and key exchange messages
3223     struct {
3224         select (KeyExchangeAlgorithm) {
3225             case rsa: EncryptedPreMasterSecret;
3226             case diffie_hellman: DiffieHellmanClientPublicValue;
3227         } exchange_keys;
3228     } ClientKeyExchange;
3230     struct {
3231         ProtocolVersion client_version;
3232         opaque random[46];
3233     } PreMasterSecret;
3238 Dierks & Rescorla            Standards Track                    [Page 60]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
3241     struct {
3242         public-key-encrypted PreMasterSecret pre_master_secret;
3243     } EncryptedPreMasterSecret;
3245     enum { implicit, explicit } PublicValueEncoding;
3247     struct {
3248         select (PublicValueEncoding) {
3249             case implicit: struct {};
3250             case explicit: opaque DH_Yc<1..2^16-1>;
3251         } dh_public;
3252     } ClientDiffieHellmanPublic;
3254     struct {
3255         Signature signature;
3256     } CertificateVerify;
3258 A.4.4. Handshake finalization message
3260     struct {
3261         opaque verify_data[12];
3262     } Finished;
3264 A.5. The CipherSuite
3266    The following values define the CipherSuite codes used in the client
3267    hello and server hello messages.
3269    A CipherSuite defines a cipher specification supported in TLS Version
3270    1.1.
3272    TLS_NULL_WITH_NULL_NULL is specified and is the initial state of a
3273    TLS connection during the first handshake on that channel, but must
3274    not be negotiated, as it provides no more protection than an
3275    unsecured connection.
3277     CipherSuite TLS_NULL_WITH_NULL_NULL                = { 0x00,0x00 };
3279    The following CipherSuite definitions require that the server provide
3280    an RSA certificate that can be used for key exchange. The server may
3281    request either an RSA or a DSS signature-capable certificate in the
3282    certificate request message.
3284     CipherSuite TLS_RSA_WITH_NULL_MD5                  = { 0x00,0x01 };
3285     CipherSuite TLS_RSA_WITH_NULL_SHA                  = { 0x00,0x02 };
3286     CipherSuite TLS_RSA_EXPORT_WITH_RC4_40_MD5         = { 0x00,0x03 };
3287     CipherSuite TLS_RSA_WITH_RC4_128_MD5               = { 0x00,0x04 };
3288     CipherSuite TLS_RSA_WITH_RC4_128_SHA               = { 0x00,0x05 };
3292 Dierks & Rescorla            Standards Track                    [Page 61]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
3295     CipherSuite TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5     = { 0x00,0x06 };
3296     CipherSuite TLS_RSA_WITH_IDEA_CBC_SHA              = { 0x00,0x07 };
3297     CipherSuite TLS_RSA_EXPORT_WITH_DES40_CBC_SHA      = { 0x00,0x08 };
3298     CipherSuite TLS_RSA_WITH_DES_CBC_SHA               = { 0x00,0x09 };
3299     CipherSuite TLS_RSA_WITH_3DES_EDE_CBC_SHA          = { 0x00,0x0A };
3301    The following CipherSuite definitions are used for server-
3302    authenticated (and optionally client-authenticated) Diffie-Hellman.
3303    DH denotes cipher suites in which the server's certificate contains
3304    the Diffie-Hellman parameters signed by the certificate authority
3305    (CA). DHE denotes ephemeral Diffie-Hellman, where the Diffie-Hellman
3306    parameters are signed by a DSS or RSA certificate, which has been
3307    signed by the CA. The signing algorithm used is specified after the
3308    DH or DHE parameter. The server can request an RSA or DSS signature-
3309    capable certificate from the client for client authentication or it
3310    may request a Diffie-Hellman certificate. Any Diffie-Hellman
3311    certificate provided by the client must use the parameters (group and
3312    generator) described by the server.
3314     CipherSuite TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA   = { 0x00,0x0B };
3315     CipherSuite TLS_DH_DSS_WITH_DES_CBC_SHA            = { 0x00,0x0C };
3316     CipherSuite TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA       = { 0x00,0x0D };
3317     CipherSuite TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA   = { 0x00,0x0E };
3318     CipherSuite TLS_DH_RSA_WITH_DES_CBC_SHA            = { 0x00,0x0F };
3319     CipherSuite TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA       = { 0x00,0x10 };
3320     CipherSuite TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA  = { 0x00,0x11 };
3321     CipherSuite TLS_DHE_DSS_WITH_DES_CBC_SHA           = { 0x00,0x12 };
3322     CipherSuite TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA      = { 0x00,0x13 };
3323     CipherSuite TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA  = { 0x00,0x14 };
3324     CipherSuite TLS_DHE_RSA_WITH_DES_CBC_SHA           = { 0x00,0x15 };
3325     CipherSuite TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA      = { 0x00,0x16 };
3327    The following cipher suites are used for completely anonymous Diffie-
3328    Hellman communications in which neither party is authenticated. Note
3329    that this mode is vulnerable to man-in-the-middle attacks and is
3330    therefore deprecated.
3332     CipherSuite TLS_DH_anon_EXPORT_WITH_RC4_40_MD5     = { 0x00,0x17 };
3333     CipherSuite TLS_DH_anon_WITH_RC4_128_MD5           = { 0x00,0x18 };
3334     CipherSuite TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA  = { 0x00,0x19 };
3335     CipherSuite TLS_DH_anon_WITH_DES_CBC_SHA           = { 0x00,0x1A };
3336     CipherSuite TLS_DH_anon_WITH_3DES_EDE_CBC_SHA      = { 0x00,0x1B };
3338  The cipher suite space is divided into three regions:
3340        1. Cipher suite values with first byte 0x00 (zero)
3341           through decimal 191 (0xBF) inclusive are reserved for the IETF
3342           Standards Track protocols.
3346 Dierks & Rescorla            Standards Track                    [Page 62]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
3349        2. Cipher suite values with first byte decimal 192 (0xC0)
3350           through decimal 254 (0xFE) inclusive are reserved
3351           for assignment for non-Standards Track methods.
3353        3. Cipher suite values with first byte 0xFF are
3354           reserved for private use.
3355    Additional information describing the role of IANA in the allocation
3356    of cipher suite code points is described in Section XXX.
3358  Note: The cipher suite values { 0x00, 0x1C } and { 0x00, 0x1D } are
3359    reserved to avoid collision with Fortezza-based cipher suites in SSL
3360    3.
3362 A.6. The Security Parameters
3364    These security parameters are determined by the TLS Handshake
3365    Protocol and provided as parameters to the TLS Record Layer in order
3366    to initialize a connection state. SecurityParameters includes:
3368        enum { null(0), (255) } CompressionMethod;
3370        enum { server, client } ConnectionEnd;
3372        enum { null, rc4, rc2, des, 3des, des40, idea }
3373        BulkCipherAlgorithm;
3375        enum { stream, block } CipherType;
3377        enum { true, false } IsExportable;
3379        enum { null, md5, sha } MACAlgorithm;
3381    /* The algorithms specified in CompressionMethod,
3382    BulkCipherAlgorithm, and MACAlgorithm may be added to. */
3384        struct {
3385            ConnectionEnd entity;
3386            BulkCipherAlgorithm bulk_cipher_algorithm;
3387            CipherType cipher_type;
3388            uint8 key_size;
3389            uint8 key_material_length;
3390            IsExportable is_exportable;
3391            MACAlgorithm mac_algorithm;
3392            uint8 hash_size;
3393            CompressionMethod compression_algorithm;
3394            opaque master_secret[48];
3395            opaque client_random[32];
3396            opaque server_random[32];
3400 Dierks & Rescorla            Standards Track                    [Page 63]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
3403        } SecurityParameters;
3454 Dierks & Rescorla            Standards Track                    [Page 64]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
3457 B. Glossary
3459    application protocol
3460        An application protocol is a protocol that normally layers
3461        directly on top of the transport layer (e.g., TCP/IP). Examples
3462        include HTTP, TELNET, FTP, and SMTP.
3464    asymmetric cipher
3465        See public key cryptography.
3467    authentication
3468        Authentication is the ability of one entity to determine the
3469        identity of another entity.
3471    block cipher
3472        A block cipher is an algorithm that operates on plaintext in
3473        groups of bits, called blocks. 64 bits is a common block size.
3475    bulk cipher
3476        A symmetric encryption algorithm used to encrypt large quantities
3477        of data.
3479    cipher block chaining (CBC)
3480        CBC is a mode in which every plaintext block encrypted with a
3481        block cipher is first exclusive-ORed with the previous ciphertext
3482        block (or, in the case of the first block, with the
3483        initialization vector). For decryption, every block is first
3484        decrypted, then exclusive-ORed with the previous ciphertext block
3485        (or IV).
3487    certificate
3488        As part of the X.509 protocol (a.k.a. ISO Authentication
3489        framework), certificates are assigned by a trusted Certificate
3490        Authority and provide a strong binding between a party's identity
3491        or some other attributes and its public key.
3493    client
3494        The application entity that initiates a TLS connection to a
3495        server. This may or may not imply that the client initiated the
3496        underlying transport connection. The primary operational
3497        difference between the server and client is that the server is
3498        generally authenticated, while the client is only optionally
3499        authenticated.
3501    client write key
3502        The key used to encrypt data written by the client.
3508 Dierks & Rescorla            Standards Track                    [Page 65]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
3511    client write MAC secret
3512        The secret data used to authenticate data written by the client.
3514    connection
3515        A connection is a transport (in the OSI layering model
3516        definition) that provides a suitable type of service. For TLS,
3517        such connections are peer to peer relationships. The connections
3518        are transient. Every connection is associated with one session.
3520    Data Encryption Standard
3521        DES is a very widely used symmetric encryption algorithm. DES is
3522        a block cipher with a 56 bit key and an 8 byte block size. Note
3523        that in TLS, for key generation purposes, DES is treated as
3524        having an 8 byte key length (64 bits), but it still only provides
3525        56 bits of protection. (The low bit of each key byte is presumed
3526        to be set to produce odd parity in that key byte.) DES can also
3527        be operated in a mode where three independent keys and three
3528        encryptions are used for each block of data; this uses 168 bits
3529        of key (24 bytes in the TLS key generation method) and provides
3530        the equivalent of 112 bits of security. [DES], [3DES]
3532    Digital Signature Standard (DSS)
3533        A standard for digital signing, including the Digital Signing
3534        Algorithm, approved by the National Institute of Standards and
3535        Technology, defined in NIST FIPS PUB 186, "Digital Signature
3536        Standard," published May, 1994 by the U.S. Dept. of Commerce.
3537        [DSS]
3539    digital signatures
3540        Digital signatures utilize public key cryptography and one-way
3541        hash functions to produce a signature of the data that can be
3542        authenticated, and is difficult to forge or repudiate.
3544    handshake
3545        An initial negotiation between client and server that establishes
3546        the parameters of their transactions.
3548    Initialization Vector (IV)
3549        When a block cipher is used in CBC mode, the initialization
3550        vector is exclusive-ORed with the first plaintext block prior to
3551        encryption.
3553    IDEA
3554        A 64-bit block cipher designed by Xuejia Lai and James Massey.
3555        [IDEA]
3562 Dierks & Rescorla            Standards Track                    [Page 66]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
3565    Message Authentication Code (MAC)
3566        A Message Authentication Code is a one-way hash computed from a
3567        message and some secret data. It is difficult to forge without
3568        knowing the secret data. Its purpose is to detect if the message
3569        has been altered.
3571    master secret
3572        Secure secret data used for generating encryption keys, MAC
3573        secrets, and IVs.
3575    MD5
3576        MD5 is a secure hashing function that converts an arbitrarily
3577        long data stream into a digest of fixed size (16 bytes). [MD5]
3579    public key cryptography
3580        A class of cryptographic techniques employing two-key ciphers.
3581        Messages encrypted with the public key can only be decrypted with
3582        the associated private key. Conversely, messages signed with the
3583        private key can be verified with the public key.
3585    one-way hash function
3586        A one-way transformation that converts an arbitrary amount of
3587        data into a fixed-length hash. It is computationally hard to
3588        reverse the transformation or to find collisions. MD5 and SHA are
3589        examples of one-way hash functions.
3591    RC2
3592        A block cipher developed by Ron Rivest at RSA Data Security, Inc.
3593        [RSADSI] described in [RC2].
3595    RC4
3596        A stream cipher licensed by RSA Data Security [RSADSI]. A
3597        compatible cipher is described in [RC4].
3599    RSA
3600        A very widely used public-key algorithm that can be used for
3601        either encryption or digital signing. [RSA]
3603    salt
3604        Non-secret random data used to make export encryption keys resist
3605        precomputation attacks.
3607    server
3608        The server is the application entity that responds to requests
3609        for connections from clients. See also under client.
3616 Dierks & Rescorla            Standards Track                    [Page 67]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
3619    session
3620        A TLS session is an association between a client and a server.
3621        Sessions are created by the handshake protocol. Sessions define a
3622        set of cryptographic security parameters, which can be shared
3623        among multiple connections. Sessions are used to avoid the
3624        expensive negotiation of new security parameters for each
3625        connection.
3627    session identifier
3628        A session identifier is a value generated by a server that
3629        identifies a particular session.
3631    server write key
3632        The key used to encrypt data written by the server.
3634    server write MAC secret
3635        The secret data used to authenticate data written by the server.
3637    SHA
3638        The Secure Hash Algorithm is defined in FIPS PUB 180-1. It
3639        produces a 20-byte output. Note that all references to SHA
3640        actually use the modified SHA-1 algorithm. [SHA]
3642    SSL
3643        Netscape's Secure Socket Layer protocol [SSL3]. TLS is based on
3644        SSL Version 3.0
3646    stream cipher
3647        An encryption algorithm that converts a key into a
3648        cryptographically-strong keystream, which is then exclusive-ORed
3649        with the plaintext.
3651    symmetric cipher
3652        See bulk cipher.
3654    Transport Layer Security (TLS)
3655        This protocol; also, the Transport Layer Security working group
3656        of the Internet Engineering Task Force (IETF). See "Comments" at
3657        the end of this document.
3670 Dierks & Rescorla            Standards Track                    [Page 68]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
3673 C. CipherSuite definitions
3675 CipherSuite                      Is       Key          Cipher      Hash
3676                              Exportable Exchange
3678 TLS_NULL_WITH_NULL_NULL               * NULL           NULL        NULL
3679 TLS_RSA_WITH_NULL_MD5                 * RSA            NULL         MD5
3680 TLS_RSA_WITH_NULL_SHA                 * RSA            NULL         SHA
3681 TLS_RSA_EXPORT_WITH_RC4_40_MD5        * RSA_EXPORT     RC4_40       MD5
3682 TLS_RSA_WITH_RC4_128_MD5                RSA            RC4_128      MD5
3683 TLS_RSA_WITH_RC4_128_SHA                RSA            RC4_128      SHA
3684 TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5    * RSA_EXPORT     RC2_CBC_40   MD5
3685 TLS_RSA_WITH_IDEA_CBC_SHA               RSA            IDEA_CBC     SHA
3686 TLS_RSA_EXPORT_WITH_DES40_CBC_SHA     * RSA_EXPORT     DES40_CBC    SHA
3687 TLS_RSA_WITH_DES_CBC_SHA                RSA            DES_CBC      SHA
3688 TLS_RSA_WITH_3DES_EDE_CBC_SHA           RSA            3DES_EDE_CBC SHA
3689 TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA  * DH_DSS_EXPORT  DES40_CBC    SHA
3690 TLS_DH_DSS_WITH_DES_CBC_SHA             DH_DSS         DES_CBC      SHA
3691 TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA        DH_DSS         3DES_EDE_CBC SHA
3692 TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA  * DH_RSA_EXPORT  DES40_CBC    SHA
3693 TLS_DH_RSA_WITH_DES_CBC_SHA             DH_RSA         DES_CBC      SHA
3694 TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA        DH_RSA         3DES_EDE_CBC SHA
3695 TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA * DHE_DSS_EXPORT DES40_CBC    SHA
3696 TLS_DHE_DSS_WITH_DES_CBC_SHA            DHE_DSS        DES_CBC      SHA
3697 TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA       DHE_DSS        3DES_EDE_CBC SHA
3698 TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA * DHE_RSA_EXPORT DES40_CBC    SHA
3699 TLS_DHE_RSA_WITH_DES_CBC_SHA            DHE_RSA        DES_CBC      SHA
3700 TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA       DHE_RSA        3DES_EDE_CBC SHA
3701 TLS_DH_anon_EXPORT_WITH_RC4_40_MD5    * DH_anon_EXPORT RC4_40       MD5
3702 TLS_DH_anon_WITH_RC4_128_MD5            DH_anon        RC4_128      MD5
3703 TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA   DH_anon        DES40_CBC    SHA
3704 TLS_DH_anon_WITH_DES_CBC_SHA            DH_anon        DES_CBC      SHA
3705 TLS_DH_anon_WITH_3DES_EDE_CBC_SHA       DH_anon        3DES_EDE_CBC SHA
3708    * Indicates IsExportable is True
3710       Key
3711       Exchange
3712       Algorithm       Description                        Key size limit
3714       DHE_DSS         Ephemeral DH with DSS signatures   None
3715       DHE_DSS_EXPORT  Ephemeral DH with DSS signatures   DH = 512 bits
3716       DHE_RSA         Ephemeral DH with RSA signatures   None
3717       DHE_RSA_EXPORT  Ephemeral DH with RSA signatures   DH = 512 bits,
3718                                                          RSA = none
3719       DH_anon         Anonymous DH, no signatures        None
3720       DH_anon_EXPORT  Anonymous DH, no signatures        DH = 512 bits
3724 Dierks & Rescorla            Standards Track                    [Page 69]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
3727       DH_DSS          DH with DSS-based certificates     None
3728       DH_DSS_EXPORT   DH with DSS-based certificates     DH = 512 bits
3729       DH_RSA          DH with RSA-based certificates     None
3730       DH_RSA_EXPORT   DH with RSA-based certificates     DH = 512 bits,
3731                                                          RSA = none
3732       NULL            No key exchange                    N/A
3733       RSA             RSA key exchange                   None
3734       RSA_EXPORT      RSA key exchange                   RSA = 512 bits
3736    Key size limit
3737        The key size limit gives the size of the largest public key that
3738        can be legally used for encryption or key agreement in
3739        cipher suites that are exportable.
3741                          Key      Expanded   Effective   IV    Block
3742     Cipher       Type  Material Key Material  Key Bits  Size   Size
3744     NULL       * Stream   0          0           0        0     N/A
3745     IDEA_CBC     Block   16         16         128        8      8
3746     RC2_CBC_40 * Block    5         16          40        8      8
3747     RC4_40     * Stream   5         16          40        0     N/A
3748     RC4_128      Stream  16         16         128        0     N/A
3749     DES40_CBC  * Block    5          8          40        8      8
3750     DES_CBC      Block    8          8          56        8      8
3751     3DES_EDE_CBC Block   24         24         168        8      8
3753    * Indicates IsExportable is true.
3755    Type
3756        Indicates whether this is a stream cipher or a block cipher
3757        running in CBC mode.
3759    Key Material
3760        The number of bytes from the key_block that are used for
3761        generating the write keys.
3763    Expanded Key Material
3764        The number of bytes actually fed into the encryption algorithm
3766    Effective Key Bits
3767        How much entropy material is in the key material being fed into
3768        the encryption routines.
3770    IV Size
3771        How much data needs to be generated for the initialization
3772        vector. Zero for stream ciphers; equal to the block size for
3773        block ciphers.
3778 Dierks & Rescorla            Standards Track                    [Page 70]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
3781    Block Size
3782        The amount of data a block cipher enciphers in one chunk; a
3783        block cipher running in CBC mode can only encrypt an even
3784        multiple of its block size.
3786       Hash      Hash      Padding
3787     function    Size       Size
3788       NULL       0          0
3789       MD5        16         48
3790       SHA        20         40
3832 Dierks & Rescorla            Standards Track                    [Page 71]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
3835 D. Implementation Notes
3837    The TLS protocol cannot prevent many common security mistakes. This
3838    section provides several recommendations to assist implementors.
3840 D.1. Temporary RSA keys
3842    US Export restrictions limit RSA keys used for encryption to 512
3843    bits, but do not place any limit on lengths of RSA keys used for
3844    signing operations. Certificates often need to be larger than 512
3845    bits, since 512-bit RSA keys are not secure enough for high-value
3846    transactions or for applications requiring long-term security. Some
3847    certificates are also designated signing-only, in which case they
3848    cannot be used for key exchange.
3850    When the public key in the certificate cannot be used for encryption,
3851    the server signs a temporary RSA key, which is then exchanged. In
3852    exportable applications, the temporary RSA key should be the maximum
3853    allowable length (i.e., 512 bits). Because 512-bit RSA keys are
3854    relatively insecure, they should be changed often. For typical
3855    electronic commerce applications, it is suggested that keys be
3856    changed daily or every 500 transactions, and more often if possible.
3857    Note that while it is acceptable to use the same temporary key for
3858    multiple transactions, it must be signed each time it is used.
3860    RSA key generation is a time-consuming process. In many cases, a low-
3861    priority process can be assigned the task of key generation.
3863    Whenever a new key is completed, the existing temporary key can be
3864    replaced with the new one.
3866 D.2. Random Number Generation and Seeding
3868    TLS requires a cryptographically-secure pseudorandom number generator
3869    (PRNG). Care must be taken in designing and seeding PRNGs.  PRNGs
3870    based on secure hash operations, most notably MD5 and/or SHA, are
3871    acceptable, but cannot provide more security than the size of the
3872    random number generator state. (For example, MD5-based PRNGs usually
3873    provide 128 bits of state.)
3875    To estimate the amount of seed material being produced, add the
3876    number of bits of unpredictable information in each seed byte. For
3877    example, keystroke timing values taken from a PC compatible's 18.2 Hz
3878    timer provide 1 or 2 secure bits each, even though the total size of
3879    the counter value is 16 bits or more. To seed a 128-bit PRNG, one
3880    would thus require approximately 100 such timer values.
3882 D.3. Certificates and authentication
3886 Dierks & Rescorla            Standards Track                    [Page 72]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
3889    Implementations are responsible for verifying the integrity of
3890    certificates and should generally support certificate revocation
3891    messages. Certificates should always be verified to ensure proper
3892    signing by a trusted Certificate Authority (CA). The selection and
3893    addition of trusted CAs should be done very carefully. Users should
3894    be able to view information about the certificate and root CA.
3896 D.4. CipherSuites
3898    TLS supports a range of key sizes and security levels, including some
3899    which provide no or minimal security. A proper implementation will
3900    probably not support many cipher suites. For example, 40-bit
3901    encryption is easily broken, so implementations requiring strong
3902    security should not allow 40-bit keys. Similarly, anonymous Diffie-
3903    Hellman is strongly discouraged because it cannot prevent man-in-the-
3904    middle attacks. Applications should also enforce minimum and maximum
3905    key sizes. For example, certificate chains containing 512-bit RSA
3906    keys or signatures are not appropriate for high-security
3907    applications.
3940 Dierks & Rescorla            Standards Track                    [Page 73]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
3943 E. Backward Compatibility With SSL
3945    For historical reasons and in order to avoid a profligate consumption
3946    of reserved port numbers, application protocols which are secured by
3947    TLS 1.1, TLS 1.0, SSL 3.0, and SSL 2.0 all frequently share the same
3948    connection port: for example, the https protocol (HTTP secured by SSL
3949    or TLS) uses port 443 regardless of which security protocol it is
3950    using. Thus, some mechanism must be determined to distinguish and
3951    negotiate among the various protocols.
3953    TLS versions 1.1, 1.0, and SSL 3.0 are very similar; thus, supporting
3954    both is easy. TLS clients who wish to negotiate with such older
3955    servers SHOULD send client hello messages using the SSL 3.0 record
3956    format and client hello structure, sending {3, 2} for the version
3957    field to note that they support TLS 1.1. If the server supports only
3958    TLS 1.0 or SSL 3.0, it will respond with a downrev 3.0 server hello;
3959    if it supports TLS 1.1 it will respond with a TLS 1.1 server hello.
3960    The negotiation then proceeds as appropriate for the negotiated
3961    protocol.
3963    Similarly, a TLS 1.1  server which wishes to interoperate with TLS
3964    1.0 or SSL 3.0 clients SHOULD accept SSL 3.0 client hello messages
3965    and respond with a SSL 3.0 server hello if an SSL 3.0 client hello
3966    with a version field of {3, 0} is received, denoting that this client
3967    does not support TLS. Similarly, if a SSL 3.0 or TLS 1.0 hello with a
3968    version field of {3, 1} is received, the server SHOULD respond with a
3969    TLS 1.0 hello with a version field of {3, 1}.
3971    Whenever a client already knows the highest protocol known to a
3972    server (for example, when resuming a session), it SHOULD initiate the
3973    connection in that native protocol.
3975    TLS 1.1 clients that support SSL Version 2.0 servers MUST send SSL
3976    Version 2.0 client hello messages [SSL2]. TLS servers SHOULD accept
3977    either client hello format if they wish to support SSL 2.0 clients on
3978    the same connection port. The only deviations from the Version 2.0
3979    specification are the ability to specify a version with a value of
3980    three and the support for more ciphering types in the CipherSpec.
3982  Warning: The ability to send Version 2.0 client hello messages will be
3983           phased out with all due haste. Implementors SHOULD make every
3984           effort to move forward as quickly as possible. Version 3.0
3985           provides better mechanisms for moving to newer versions.
3987    The following cipher specifications are carryovers from SSL Version
3988    2.0. These are assumed to use RSA for key exchange and
3989    authentication.
3994 Dierks & Rescorla            Standards Track                    [Page 74]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
3997        V2CipherSpec TLS_RC4_128_WITH_MD5          = { 0x01,0x00,0x80 };
3998        V2CipherSpec TLS_RC4_128_EXPORT40_WITH_MD5 = { 0x02,0x00,0x80 };
3999        V2CipherSpec TLS_RC2_CBC_128_CBC_WITH_MD5  = { 0x03,0x00,0x80 };
4000        V2CipherSpec TLS_RC2_CBC_128_CBC_EXPORT40_WITH_MD5
4001                                                   = { 0x04,0x00,0x80 };
4002        V2CipherSpec TLS_IDEA_128_CBC_WITH_MD5     = { 0x05,0x00,0x80 };
4003        V2CipherSpec TLS_DES_64_CBC_WITH_MD5       = { 0x06,0x00,0x40 };
4004        V2CipherSpec TLS_DES_192_EDE3_CBC_WITH_MD5 = { 0x07,0x00,0xC0 };
4006    Cipher specifications native to TLS can be included in Version 2.0
4007    client hello messages using the syntax below. Any V2CipherSpec
4008    element with its first byte equal to zero will be ignored by Version
4009    2.0 servers. Clients sending any of the above V2CipherSpecs SHOULD
4010    also include the TLS equivalent (see Appendix A.5):
4012        V2CipherSpec (see TLS name) = { 0x00, CipherSuite };
4014 E.1. Version 2 client hello
4016    The Version 2.0 client hello message is presented below using this
4017    document's presentation model. The true definition is still assumed
4018    to be the SSL Version 2.0 specification. Note that this message MUST
4019    be sent directly on the wire, not wrapped as an SSLv3 record
4021        uint8 V2CipherSpec[3];
4023        struct {
4024            uint16 msg_length;
4025            uint8 msg_type;
4026            Version version;
4027            uint16 cipher_spec_length;
4028            uint16 session_id_length;
4029            uint16 challenge_length;
4030            V2CipherSpec cipher_specs[V2ClientHello.cipher_spec_length];
4031            opaque session_id[V2ClientHello.session_id_length];
4032            opaque challenge[V2ClientHello.challenge_length;
4033        } V2ClientHello;
4035    msg_length
4036        This field is the length of the following data in bytes. The high
4037        bit MUST be 1 and is not part of the length.
4039    msg_type
4040        This field, in conjunction with the version field, identifies a
4041        version 2 client hello message. The value SHOULD be one (1).
4043    version
4044        The highest version of the protocol supported by the client
4048 Dierks & Rescorla            Standards Track                    [Page 75]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
4051        (equals ProtocolVersion.version, see Appendix A.1).
4053    cipher_spec_length
4054        This field is the total length of the field cipher_specs. It
4055        cannot be zero and MUST be a multiple of the V2CipherSpec length
4056        (3).
4058    session_id_length
4059        This field MUST have a value of zero.
4061    challenge_length
4062        The length in bytes of the client's challenge to the server to
4063        authenticate itself. When using the SSLv2 backward compatible
4064        handshake the client MUST use a 32-byte challenge.
4066    cipher_specs
4067        This is a list of all CipherSpecs the client is willing and able
4068        to use. There MUST be at least one CipherSpec acceptable to the
4069        server.
4071    session_id
4072        This field MUST be empty.
4074    challenge
4075        The client challenge to the server for the server to identify
4076        itself is a (nearly) arbitrary length random. The TLS server will
4077        right justify the challenge data to become the ClientHello.random
4078        data (padded with leading zeroes, if necessary), as specified in
4079        this protocol specification. If the length of the challenge is
4080        greater than 32 bytes, only the last 32 bytes are used. It is
4081        legitimate (but not necessary) for a V3 server to reject a V2
4082        ClientHello that has fewer than 16 bytes of challenge data.
4084  Note: Requests to resume a TLS session MUST use a TLS client hello.
4086 E.2. Avoiding man-in-the-middle version rollback
4088    When TLS clients fall back to Version 2.0 compatibility mode, they
4089    SHOULD use special PKCS #1 block formatting. This is done so that TLS
4090    servers will reject Version 2.0 sessions with TLS-capable clients.
4092    When TLS clients are in Version 2.0 compatibility mode, they set the
4093    right-hand (least-significant) 8 random bytes of the PKCS padding
4094    (not including the terminal null of the padding) for the RSA
4095    encryption of the ENCRYPTED-KEY-DATA field of the CLIENT-MASTER-KEY
4096    to 0x03 (the other padding bytes are random). After decrypting the
4097    ENCRYPTED-KEY-DATA field, servers that support TLS SHOULD issue an
4098    error if these eight padding bytes are 0x03. Version 2.0 servers
4102 Dierks & Rescorla            Standards Track                    [Page 76]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
4105    receiving blocks padded in this manner will proceed normally.
4156 Dierks & Rescorla            Standards Track                    [Page 77]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
4159 F. Security analysis
4161    The TLS protocol is designed to establish a secure connection between
4162    a client and a server communicating over an insecure channel. This
4163    document makes several traditional assumptions, including that
4164    attackers have substantial computational resources and cannot obtain
4165    secret information from sources outside the protocol. Attackers are
4166    assumed to have the ability to capture, modify, delete, replay, and
4167    otherwise tamper with messages sent over the communication channel.
4168    This appendix outlines how TLS has been designed to resist a variety
4169    of attacks.
4171 F.1. Handshake protocol
4173    The handshake protocol is responsible for selecting a CipherSpec and
4174    generating a Master Secret, which together comprise the primary
4175    cryptographic parameters associated with a secure session. The
4176    handshake protocol can also optionally authenticate parties who have
4177    certificates signed by a trusted certificate authority.
4179 F.1.1. Authentication and key exchange
4181    TLS supports three authentication modes: authentication of both
4182    parties, server authentication with an unauthenticated client, and
4183    total anonymity. Whenever the server is authenticated, the channel is
4184    secure against man-in-the-middle attacks, but completely anonymous
4185    sessions are inherently vulnerable to such attacks.  Anonymous
4186    servers cannot authenticate clients. If the server is authenticated,
4187    its certificate message must provide a valid certificate chain
4188    leading to an acceptable certificate authority.  Similarly,
4189    authenticated clients must supply an acceptable certificate to the
4190    server. Each party is responsible for verifying that the other's
4191    certificate is valid and has not expired or been revoked.
4193    The general goal of the key exchange process is to create a
4194    pre_master_secret known to the communicating parties and not to
4195    attackers. The pre_master_secret will be used to generate the
4196    master_secret (see Section 8.1). The master_secret is required to
4197    generate the finished messages, encryption keys, and MAC secrets (see
4198    Sections 7.4.8, 7.4.9 and 6.3). By sending a correct finished
4199    message, parties thus prove that they know the correct
4200    pre_master_secret.
4202 F.1.1.1. Anonymous key exchange
4204    Completely anonymous sessions can be established using RSA or Diffie-
4205    Hellman for key exchange. With anonymous RSA, the client encrypts a
4206    pre_master_secret with the server's uncertified public key extracted
4210 Dierks & Rescorla            Standards Track                    [Page 78]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
4213    from the server key exchange message. The result is sent in a client
4214    key exchange message. Since eavesdroppers do not know the server's
4215    private key, it will be infeasible for them to decode the
4216    pre_master_secret.
4218    Note: No anonymous RSA Cipher Suites are defined in this document.
4220    With Diffie-Hellman, the server's public parameters are contained in
4221    the server key exchange message and the client's are sent in the
4222    client key exchange message. Eavesdroppers who do not know the
4223    private values should not be able to find the Diffie-Hellman result
4224    (i.e. the pre_master_secret).
4226  Warning: Completely anonymous connections only provide protection
4227           against passive eavesdropping. Unless an independent tamper-
4228           proof channel is used to verify that the finished messages
4229           were not replaced by an attacker, server authentication is
4230           required in environments where active man-in-the-middle
4231           attacks are a concern.
4233 F.1.1.2. RSA key exchange and authentication
4235    With RSA, key exchange and server authentication are combined. The
4236    public key may be either contained in the server's certificate or may
4237    be a temporary RSA key sent in a server key exchange message.  When
4238    temporary RSA keys are used, they are signed by the server's RSA
4239    certificate. The signature includes the current ClientHello.random,
4240    so old signatures and temporary keys cannot be replayed. Servers may
4241    use a single temporary RSA key for multiple negotiation sessions.
4243  Note: The temporary RSA key option is useful if servers need large
4244        certificates but must comply with government-imposed size limits
4245        on keys used for key exchange.
4247    Note that if ephemeral RSA is not used, compromise of the server's
4248    static RSA key results in a loss of confidentiality for all sessions
4249    protected under that static key. TLS users desiring Perfect Forward
4250    Secrecy should use DHE cipher suites. The damage done by exposure of
4251    a private key can be limited by changing one's private key (and
4252    certificate) frequently.
4254    After verifying the server's certificate, the client encrypts a
4255    pre_master_secret with the server's public key. By successfully
4256    decoding the pre_master_secret and producing a correct finished
4257    message, the server demonstrates that it knows the private key
4258    corresponding to the server certificate.
4260    When RSA is used for key exchange, clients are authenticated using
4264 Dierks & Rescorla            Standards Track                    [Page 79]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
4267    the certificate verify message (see Section 7.4.8). The client signs
4268    a value derived from the master_secret and all preceding handshake
4269    messages. These handshake messages include the server certificate,
4270    which binds the signature to the server, and ServerHello.random,
4271    which binds the signature to the current handshake process.
4273 F.1.1.3. Diffie-Hellman key exchange with authentication
4275    When Diffie-Hellman key exchange is used, the server can either
4276    supply a certificate containing fixed Diffie-Hellman parameters or
4277    can use the server key exchange message to send a set of temporary
4278    Diffie-Hellman parameters signed with a DSS or RSA certificate.
4279    Temporary parameters are hashed with the hello.random values before
4280    signing to ensure that attackers do not replay old parameters. In
4281    either case, the client can verify the certificate or signature to
4282    ensure that the parameters belong to the server.
4284    If the client has a certificate containing fixed Diffie-Hellman
4285    parameters, its certificate contains the information required to
4286    complete the key exchange. Note that in this case the client and
4287    server will generate the same Diffie-Hellman result (i.e.,
4288    pre_master_secret) every time they communicate. To prevent the
4289    pre_master_secret from staying in memory any longer than necessary,
4290    it should be converted into the master_secret as soon as possible.
4291    Client Diffie-Hellman parameters must be compatible with those
4292    supplied by the server for the key exchange to work.
4294    If the client has a standard DSS or RSA certificate or is
4295    unauthenticated, it sends a set of temporary parameters to the server
4296    in the client key exchange message, then optionally uses a
4297    certificate verify message to authenticate itself.
4299    If the same DH keypair is to be used for multiple handshakes, either
4300    because the client or server has a certificate containing a fixed DH
4301    keypair or because the server is reusing DH keys, care must be taken
4302    to prevent small subgroup attacks. Implementations SHOULD follow the
4303    guidelines found in [SUBGROUP].
4305    Small subgroup attacks are most easily avoided by using one of the
4306    DHE ciphersuites and generating a fresh DH private key (X) for each
4307    handshake. If a suitable base (such as 2) is chosen, g^X mod p can be
4308    computed very quickly so the performance cost is minimized.
4309    Additionally, using a fresh key for each handshake provides Perfect
4310    Forward Secrecy. Implementations SHOULD generate a new X for each
4311    handshake when using DHE ciphersuites.
4313 F.1.2. Version rollback attacks
4318 Dierks & Rescorla            Standards Track                    [Page 80]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
4321    Because TLS includes substantial improvements over SSL Version 2.0,
4322    attackers may try to make TLS-capable clients and servers fall back
4323    to Version 2.0. This attack can occur if (and only if) two TLS-
4324    capable parties use an SSL 2.0 handshake.
4326    Although the solution using non-random PKCS #1 block type 2 message
4327    padding is inelegant, it provides a reasonably secure way for Version
4328    3.0 servers to detect the attack. This solution is not secure against
4329    attackers who can brute force the key and substitute a new ENCRYPTED-
4330    KEY-DATA message containing the same key (but with normal padding)
4331    before the application specified wait threshold has expired. Parties
4332    concerned about attacks of this scale should not be using 40-bit
4333    encryption keys anyway. Altering the padding of the least-significant
4334    8 bytes of the PKCS padding does not impact security for the size of
4335    the signed hashes and RSA key lengths used in the protocol, since
4336    this is essentially equivalent to increasing the input block size by
4337    8 bytes.
4339 F.1.3. Detecting attacks against the handshake protocol
4341    An attacker might try to influence the handshake exchange to make the
4342    parties select different encryption algorithms than they would
4343    normally chooses. Because many implementations will support 40-bit
4344    exportable encryption and some may even support null encryption or
4345    MAC algorithms, this attack is of particular concern.
4347    For this attack, an attacker must actively change one or more
4348    handshake messages. If this occurs, the client and server will
4349    compute different values for the handshake message hashes. As a
4350    result, the parties will not accept each others' finished messages.
4351    Without the master_secret, the attacker cannot repair the finished
4352    messages, so the attack will be discovered.
4354 F.1.4. Resuming sessions
4356    When a connection is established by resuming a session, new
4357    ClientHello.random and ServerHello.random values are hashed with the
4358    session's master_secret. Provided that the master_secret has not been
4359    compromised and that the secure hash operations used to produce the
4360    encryption keys and MAC secrets are secure, the connection should be
4361    secure and effectively independent from previous connections.
4362    Attackers cannot use known encryption keys or MAC secrets to
4363    compromise the master_secret without breaking the secure hash
4364    operations (which use both SHA and MD5).
4366    Sessions cannot be resumed unless both the client and server agree.
4367    If either party suspects that the session may have been compromised,
4368    or that certificates may have expired or been revoked, it should
4372 Dierks & Rescorla            Standards Track                    [Page 81]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
4375    force a full handshake. An upper limit of 24 hours is suggested for
4376    session ID lifetimes, since an attacker who obtains a master_secret
4377    may be able to impersonate the compromised party until the
4378    corresponding session ID is retired. Applications that may be run in
4379    relatively insecure environments should not write session IDs to
4380    stable storage.
4382 F.1.5. MD5 and SHA
4384    TLS uses hash functions very conservatively. Where possible, both MD5
4385    and SHA are used in tandem to ensure that non-catastrophic flaws in
4386    one algorithm will not break the overall protocol.
4388 F.2. Protecting application data
4390    The master_secret is hashed with the ClientHello.random and
4391    ServerHello.random to produce unique data encryption keys and MAC
4392    secrets for each connection.
4394    Outgoing data is protected with a MAC before transmission. To prevent
4395    message replay or modification attacks, the MAC is computed from the
4396    MAC secret, the sequence number, the message length, the message
4397    contents, and two fixed character strings. The message type field is
4398    necessary to ensure that messages intended for one TLS Record Layer
4399    client are not redirected to another. The sequence number ensures
4400    that attempts to delete or reorder messages will be detected. Since
4401    sequence numbers are 64-bits long, they should never overflow.
4402    Messages from one party cannot be inserted into the other's output,
4403    since they use independent MAC secrets. Similarly, the server-write
4404    and client-write keys are independent so stream cipher keys are used
4405    only once.
4407    If an attacker does break an encryption key, all messages encrypted
4408    with it can be read. Similarly, compromise of a MAC key can make
4409    message modification attacks possible. Because MACs are also
4410    encrypted, message-alteration attacks generally require breaking the
4411    encryption algorithm as well as the MAC.
4413  Note: MAC secrets may be larger than encryption keys, so messages can
4414        remain tamper resistant even if encryption keys are broken.
4416 F.3. Explicit IVs
4418        [CBCATT] describes a chosen plaintext attack on TLS that depends
4419        on knowing the IV for a record. Previous versions of TLS [TLS1.0]
4420        used the CBC residue of the previous record as the IV and
4421        therefore enabled this attack. This version uses an explicit IV
4422        in order to protect against this attack.
4426 Dierks & Rescorla            Standards Track                    [Page 82]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
4429 F.4 Security of Composite Cipher Modes
4431        TLS secures transmitted application data via the use of symmetric
4432        encryption and authentication functions defined in the negotiated
4433        ciphersuite.  The objective is to protect both the integrity  and
4434        confidentiality of the transmitted data from malicious actions by
4435        active attackers in the network.  It turns out that the order in
4436        which encryption and authentication functions are applied to the
4437        data plays an important role for achieving this goal [ENCAUTH].
4439        The most robust method, called encrypt-then-authenticate, first
4440        applies encryption to the data and then applies a MAC to the
4441        ciphertext.  This method ensures that the integrity and
4442        confidentiality goals are obtained with ANY pair of encryption
4443        and MAC functions provided that the former is secure against
4444        chosen plaintext attacks and the MAC is secure against chosen-
4445        message attacks.  TLS uses another method, called authenticate-
4446        then-encrypt, in which first a MAC is computed on the plaintext
4447        and then the concatenation of plaintext and MAC is encrypted.
4448        This method has been proven secure for CERTAIN combinations of
4449        encryption functions and MAC functions, but is not guaranteed to
4450        be secure in general. In particular, it has been shown that there
4451        exist perfectly secure encryption functions (secure even in the
4452        information theoretic sense) that combined with any secure MAC
4453        function fail to provide the confidentiality goal against an
4454        active attack.  Therefore, new ciphersuites and operation modes
4455        adopted into TLS need to be analyzed under the authenticate-then-
4456        encrypt method to verify that they achieve the stated integrity
4457        and confidentiality goals.
4459        Currently, the security of the authenticate-then-encrypt method
4460        has been proven for some important cases.  One is the case of
4461        stream ciphers in which a computationally unpredictable pad of
4462        the length of the message plus the length of the MAC tag is
4463        produced using a pseudo-random generator and this pad is xor-ed
4464        with the concatenation of plaintext and MAC tag.  The other is
4465        the case of CBC mode using a secure block cipher.  In this case,
4466        security can be shown if one applies one CBC encryption pass to
4467        the concatenation of plaintext and MAC and uses a new,
4468        independent and unpredictable, IV for each new pair of plaintext
4469        and MAC.  In previous versions of SSL, CBC mode was used properly
4470        EXCEPT that it used a predictable IV in the form of the last
4471        block of the previous ciphertext. This made TLS open to chosen
4472        plaintext attacks.  This verson of the protocol is immune to
4473        those attacks.  For exact details in the encryption modes proven
4474        secure see [ENCAUTH].
4480 Dierks & Rescorla            Standards Track                    [Page 83]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
4483 F.5 Denial of Service
4485        TLS is susceptible to a number of denial of service (DoS)
4486        attacks.  In particular, an attacker who initiates a large number
4487        of TCP connections can cause a server to consume large amounts of
4488        CPU doing RSA decryption. However, because TLS is generally used
4489        over TCP, it is difficult for the attacker to hide his point of
4490        origin if proper TCP SYN randomization is used [SEQNUM] by the
4491        TCP stack.
4493        Because TLS runs over TCP, it is also susceptible to a number of
4494        denial of service attacks on individual connections. In
4495        particular, attackers can forge RSTs, terminating connections, or
4496        forge partial TLS records, causing the connection to stall.
4497        These attacks cannot in general be defended against by a TCP-
4498        using protocol. Implementors or users who are concerned with this
4499        class of attack should use IPsec AH [AH] or ESP [ESP].
4501 F.6. Final notes
4503    For TLS to be able to provide a secure connection, both the client
4504    and server systems, keys, and applications must be secure. In
4505    addition, the implementation must be free of security errors.
4507    The system is only as strong as the weakest key exchange and
4508    authentication algorithm supported, and only trustworthy
4509    cryptographic functions should be used. Short public keys, 40-bit
4510    bulk encryption keys, and anonymous servers should be used with great
4511    caution. Implementations and users must be careful when deciding
4512    which certificates and certificate authorities are acceptable; a
4513    dishonest certificate authority can do tremendous damage.
4534 Dierks & Rescorla            Standards Track                    [Page 84]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
4537 G. Patent Statement
4539    Netscape Communications Corporation (now America Online) has a patent
4540    claim on the Secure Sockets Layer (SSL) work that this standard is
4541    based on. The Internet Standards Process as defined in RFC 2026
4542    requests that a statement be obtained from a Patent holder indicating
4543    that a license will be made available to applicants under reasonable
4544    terms and conditions.
4546        Secure Socket Layer Application Program Apparatus And Method
4547        ("SSL"), No. 5,657,390
4549    Netscape Communications has issued the following statement:
4551        Intellectual Property Rights
4553        Secure Sockets Layer
4555        The United States Patent and Trademark Office ("the PTO")
4556        recently issued U.S. Patent No. 5,657,390 ("the SSL Patent")  to
4557        Netscape for inventions described as Secure Sockets Layers
4558        ("SSL"). The IETF is currently considering adopting SSL as a
4559        transport protocol with security features.  Netscape encourages
4560        the royalty-free adoption and use of the SSL protocol upon the
4561        following terms and conditions:
4563          * If you already have a valid SSL Ref license today which
4564            includes source code from Netscape, an additional patent
4565            license under the SSL patent is not required.
4567          * If you don't have an SSL Ref license, you may have a royalty
4568            free license to build implementations covered by the SSL
4569            Patent Claims or the IETF TLS specification provided that you
4570            do not to assert any patent rights against Netscape or other
4571            companies for the implementation of SSL or the IETF TLS
4572            recommendation.
4574        What are "Patent Claims":
4576        Patent claims are claims in an issued foreign or domestic patent
4577        that:
4579         1) must be infringed in order to implement methods or build
4580            products according to the IETF TLS specification;  or
4582         2) patent claims which require the elements of the SSL patent
4583            claims and/or their equivalents to be infringed.
4588 Dierks & Rescorla            Standards Track                    [Page 85]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
4591    The Internet Society, Internet Architecture Board, Internet
4592    Engineering Steering Group and the Corporation for National Research
4593    Initiatives take no position on the validity or scope of the patents
4594    and patent applications, nor on the appropriateness of the terms of
4595    the assurance. The Internet Society and other groups mentioned above
4596    have not made any determination as to any other intellectual property
4597    rights which may apply to the practice of this standard.  Any further
4598    consideration of these matters is the user's own responsibility.
4600 Security Considerations
4602    Security issues are discussed throughout this memo, especially in
4603    Appendices D, E, and F.
4605 Normative References
4607    [3DES]   W. Tuchman, "Hellman Presents No Shortcut Solutions To DES,"
4608             IEEE Spectrum, v. 16, n. 7, July 1979, pp40-41.
4610    [DES]    ANSI X3.106, "American National Standard for Information
4611             Systems-Data Link Encryption," American National Standards
4612             Institute, 1983.
4614    [DH1]    W. Diffie and M. E. Hellman, "New Directions in
4615             Cryptography," IEEE Transactions on Information Theory, V.
4616             IT-22, n. 6, Jun 1977, pp. 74-84.
4618    [DSS]    NIST FIPS PUB 186, "Digital Signature Standard," National
4619             Institute of Standards and Technology, U.S. Department of
4620             Commerce, May 18, 1994.
4622    [HMAC]   Krawczyk, H., Bellare, M., and R. Canetti, "HMAC: Keyed-
4623             Hashing for Message Authentication," RFC 2104, February
4624             1997.
4626    [IDEA]   X. Lai, "On the Design and Security of Block Ciphers," ETH
4627             Series in Information Processing, v. 1, Konstanz: Hartung-
4628             Gorre Verlag, 1992.
4630    [MD2]    Kaliski, B., "The MD2 Message Digest Algorithm", RFC 1319,
4631             April 1992.
4633    [MD5]    Rivest, R., "The MD5 Message Digest Algorithm", RFC 1321,
4634             April 1992.
4636    [PKCS1]  RSA Laboratories, "PKCS #1: RSA Encryption Standard,"
4637             version 1.5, November 1993.
4642 Dierks & Rescorla            Standards Track                    [Page 86]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
4645    [PKCS6]  RSA Laboratories, "PKCS #6: RSA Extended Certificate Syntax
4646             Standard," version 1.5, November 1993.
4648    [PKCS7]  RSA Laboratories, "PKCS #7: RSA Cryptographic Message Syntax
4649             Standard," version 1.5, November 1993.
4651    [PKIX]   Housley, R., Ford, W., Polk, W. and D. Solo, "Internet
4652             Public Key Infrastructure: Part I: X.509 Certificate and CRL
4653             Profile", RFC 2459, January 1999.
4655    [RC2]    Rivest, R., "A Description of the RC2(r) Encryption
4656             Algorithm", RFC 2268, January 1998.
4658    [RC4]    Thayer, R. and K. Kaukonen, A Stream Cipher Encryption
4659             Algorithm, Work in Progress.
4661    [RSA]    R. Rivest, A. Shamir, and L. M. Adleman, "A Method for
4662             Obtaining Digital Signatures and Public-Key Cryptosystems,"
4663             Communications of the ACM, v. 21, n. 2, Feb 1978, pp.
4664             120-126.
4666    [SHA]    NIST FIPS PUB 180-1, "Secure Hash Standard," National
4667             Institute of Standards and Technology, U.S. Department of
4668             Commerce, Work in Progress, May 31, 1994.
4670    [SSL2]   Hickman, Kipp, "The SSL Protocol", Netscape Communications
4671             Corp., Feb 9, 1995.
4673    [SSL3]   A. Frier, P. Karlton, and P. Kocher, "The SSL 3.0 Protocol",
4674             Netscape Communications Corp., Nov 18, 1996.
4676    [REQ]    Bradner, S., "Key words for use in RFCs to Indicate
4677             Requirement Levels", BCP 14, RFC 2119, March 1997.
4679    [TLS1.0] Dierks, T., and Allen, C., "The TLS Protocol, Version 1.0",
4680             RFC 2246, January 1999.
4682    [TLSEXT] Blake-Wilson, S., Nystrom, M, Hopwood, D., Mikkelsen, J.,
4683             Wright, T., "Transport Layer Security (TLS) Extensions", RFC
4684             3546, June 2003.
4685    [X509]   CCITT. Recommendation X.509: "The Directory - Authentication
4686             Framework". 1988.
4696 Dierks & Rescorla            Standards Track                    [Page 87]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
4699 Informative References
4701    [AH]     Kent, S., and Atkinson, R., "IP Authentication Header", RFC
4702             2402, November 1998.
4704    [BLEI]   Bleichenbacher D., "Chosen Ciphertext Attacks against
4705             Protocols Based on RSA Encryption Standard PKCS #1" in
4706             Advances in Cryptology -- CRYPTO'98, LNCS vol. 1462, pages:
4707             1-12, 1998.
4709    [CBCATT] Moeller, B., "Security of CBC Ciphersuites in SSL/TLS:
4710             Problems and Countermeasures",
4711             http://www.openssl.org/~bodo/tls-cbc.txt.
4713    [CBCTIME] Canvel, B., "Password Interception in a SSL/TLS Channel",
4714             http://lasecwww.epfl.ch/memo_ssl.shtml, 2003.
4716    [ENCAUTH] Krawczyk, H., "The Order of Encryption and Authentication
4717             for Protecting Communications (Or: How Secure is SSL?)",
4718             Crypto 2001.
4720    [ESP]     Kent, S., and Atkinson, R., "IP Encapsulating Security
4721             Payload (ESP)", RFC 2406, November 1998.
4723    [FTP]    Postel J., and J. Reynolds, "File Transfer Protocol", STD 9,
4724             RFC 959, October 1985.
4726    [HTTP]   Berners-Lee, T., Fielding, R., and H. Frystyk, "Hypertext
4727             Transfer Protocol -- HTTP/1.0", RFC 1945, May 1996.
4729    [KPR03]  Klima, V., Pokorny, O., Rosa, T., "Attacking RSA-based
4730             Sessions in SSL/TLS", http://eprint.iacr.org/2003/052/,
4731             March 2003.
4732    [RSADSI] Contact RSA Data Security, Inc., Tel: 415-595-8782
4734    [SCH]    B. Schneier. Applied Cryptography: Protocols, Algorithms,
4735             and Source Code in C, Published by John Wiley & Sons, Inc.
4736             1994.
4738    [SEQNUM] Bellovin. S., "Defending Against Sequence Number Attacks",
4739             RFC 1948, May 1996.
4741    [SUBGROUP] R. Zuccherato, "Methods for Avoiding the Small-Subgroup
4742             Attacks on the Diffie-Hellman Key Agreement Method for
4743             S/MIME", RFC 2785, March 2000.
4745    [TCP]    Postel, J., "Transmission Control Protocol," STD 7, RFC 793,
4746             September 1981.
4750 Dierks & Rescorla            Standards Track                    [Page 88]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
4753    [TIMING] Boneh, D., Brumley, D., "Remote timing attacks are
4754             practical", USENIX Security Symposium 2003.
4756    [XDR]    R. Srinivansan, Sun Microsystems, RFC-1832: XDR: External
4757             Data Representation Standard, August 1995.
4760 Credits
4762    Working Group Chairs
4763    Win Treese
4764    EMail: treese@acm.org
4766    Eric Rescorla
4767    EMail: ekr@rtfm.com
4770    Editors
4772    Tim Dierks                Eric Rescorla
4773    Independent                   RTFM, Inc.
4775    EMail: tim@dierks.org         EMail: ekr@rtfm.com
4779    Other contributors
4781    Christopher Allen (co-editor of TLS 1.0)
4782    Alacrity Ventures
4783    ChristopherA@AlacrityManagement.com
4785    Martin Abadi
4786    University of California, Santa Cruz
4787    abadi@cs.ucsc.edu
4789    Ran Canetti
4790    IBM
4791    canetti@watson.ibm.com
4793    Taher Elgamal
4794    taher@securify.com
4795    Securify
4797    Anil Gangolli
4798    Structured Arts
4800    Kipp Hickman
4804 Dierks & Rescorla            Standards Track                    [Page 89]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
4807    Phil Karlton (co-author of SSLv3)
4809    Paul Kocher (co-author of SSLv3)
4810    Cryptography Research
4811    paul@cryptography.com
4813    Hugo Krawczyk
4814    Technion Israel Institute of Technology
4815    hugo@ee.technion.ac.il
4817    Robert Relyea
4818    Netscape Communications
4819    relyea@netscape.com
4821    Jim Roskind
4822    Netscape Communications
4823    jar@netscape.com
4825    Michael Sabin
4827    Dan Simon
4828    Microsoft, Inc.
4829    dansimon@microsoft.com
4831    Tom Weinstein
4833 Comments
4835    The discussion list for the IETF TLS working group is located at the
4836    e-mail address <ietf-tls@lists.consensus.com>. Information on the
4837    group and information on how to subscribe to the list is at
4838    <http://lists.consensus.com/>.
4840    Archives of the list can be found at:
4841        <http://www.imc.org/ietf-tls/mail-archive/>
4858 Dierks & Rescorla            Standards Track                    [Page 90]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
4861 Full Copyright Statement
4863    The IETF takes no position regarding the validity or scope of any
4864    Intellectual Property Rights or other rights that might be claimed to
4865    pertain to the implementation or use of the technology described in
4866    this document or the extent to which any license under such rights
4867    might or might not be available; nor does it represent that it has
4868    made any independent effort to identify any such rights. Information
4869    on the procedures with respect to rights in RFC documents can be
4870    found in BCP 78 and BCP 79.
4872    Copies of IPR disclosures made to the IETF Secretariat and any
4873    assurances of licenses to be made available, or the result of an
4874    attempt made to obtain a general license or permission for the use of
4875    such proprietary rights by implementers or users of this
4876    specification can be obtained from the IETF on-line IPR repository at
4877    http://www.ietf.org/ipr.
4879    The IETF invites any interested party to bring to its attention any
4880    copyrights, patents or patent applications, or other proprietary
4881    rights that may cover technology that may be required to implement
4882    this standard. Please address the information to the IETF at ietf-
4883    ipr@ietf.org.
4885 Copyright Notice
4886    Copyright (C) The Internet Society (2003). This document is subject
4887    to the rights, licenses and restrictions contained in BCP 78, and
4888    except as set forth therein, the authors retain all their rights.
4890    This document and the information contained herein are provided on an
4891    "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS
4892    OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY AND THE INTERNET
4893    ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED,
4894    INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE
4895    INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED
4896    WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
4912 Dierks & Rescorla            Standards Track                    [Page 91]\fdraft-ietf-tls-rfc2246-bis-08.txt  TLS                       August 2004
4966 Dierks & Rescorla            Standards Track                    [Page 92]\f