Improve GTK-DOC coverage.
[gnutls.git] / doc / protocol / draft-ietf-tls-rfc2246-bis-10.txt
blobcbd1c036134185d8035f2ab3a5b9f7932a9ed28a
2                                                               Tim Dierks
3                                                              Independent
4                                                            Eric Rescorla
5 INTERNET-DRAFT                                                RTFM, Inc.
6 <draft-ietf-tls-rfc2246-bis-10.txt>    April 2005 (Expires October 2005)
8                             The TLS Protocol
9                               Version 1.1
11 Status of this Memo
13 By submitting this Internet-Draft, I certify that any applicable
14 patent or other IPR claims of which I am aware have been disclosed,
15 and any of which I become aware will be disclosed, in accordance with
16 RFC 3668.
18 Internet-Drafts are working documents of the Internet Engineering
19 Task Force (IETF), its areas, and its working groups. Note that other
20 groups may also distribute working documents as Internet-Drafts.
22 Internet-Drafts are draft documents valid for a maximum of six months
23 and may be updated, replaced, or obsoleted by other documents at any
24 time. It is inappropriate to use Internet-Drafts as reference
25 material or to cite them other than a "work in progress."
27 The list of current Internet-Drafts can be accessed at
28 http://www.ietf.org/1id-abstracts.html
30 The list of Internet-Draft Shadow Directories can be accessed at
31 http://www.ietf.org/shadow.html
33 Copyright Notice
35    Copyright (C) The Internet Society (1999-2004).  All Rights Reserved.
37 Abstract
39    This document specifies Version 1.1 of the Transport Layer Security
40    (TLS) protocol. The TLS protocol provides communications security
41    over the Internet. The protocol allows client/server applications to
42    communicate in a way that is designed to prevent eavesdropping,
43    tampering, or message forgery.
45 Table of Contents
47    1.        Introduction
48    5 1.1       Requirements Terminology
49    6 2.        Goals
53 Dierks & Rescorla            Standards Track                     [Page 1]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
56    7 3.        Goals of this document
57    7 4.        Presentation language
58    8 4.1.      Basic block size
59    9 4.2.      Miscellaneous
60    9 4.3.      Vectors
61    9 4.4.      Numbers
62    10 4.5.      Enumerateds
63    10 4.6.      Constructed types
64    11 4.6.1.    Variants
65    12 4.7.      Cryptographic attributes
66    13 4.8.      Constants
67    14 5.        HMAC and the pseudorandom function
68    14 6.        The TLS Record Protocol
69    16 6.1.      Connection states
70    17 6.2.      Record layer
71    19 6.2.1.    Fragmentation
72    19 6.2.2.    Record compression and decompression
73    20 6.2.3.    Record payload protection
74    21 6.2.3.1.  Null or standard stream cipher
75    22 6.2.3.2.  CBC block cipher
76    22 6.3.      Key calculation
77    25 7.        The TLS Handshaking Protocols
78    26 7.1.      Change cipher spec protocol
79    27 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    32 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    45 7.4.5.    Server hello done
92    46 7.4.6.    Client certificate
93    47 7.4.7.    Client key exchange message
94    47 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    51 8.        Cryptographic computations
99    52 8.1.      Computing the master secret
100    52 8.1.1.    RSA
101    54 8.1.2.    Diffie-Hellman
102    54 9.        Mandatory Cipher Suites
103    54 A.        Protocol constant values
107 Dierks & Rescorla            Standards Track                     [Page 2]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
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    64 B.        Glossary
121    66 C.        CipherSuite definitions
122    70 D.        Implementation Notes
123    72 D.1       Random Number Generation and Seeding
124    72 D.2       Certificates and authentication
125    72 D.3       CipherSuites
126    72 E.        Backward Compatibility With SSL
127    73 E.1.      Version 2 client hello
128    74 E.2.      Avoiding man-in-the-middle version rollback
129    75 F.        Security analysis
130    77 F.1.      Handshake protocol
131    77 F.1.1.    Authentication and key exchange
132    77 F.1.1.1.  Anonymous key exchange
133    77 F.1.1.2.  RSA key exchange and authentication
134    78 F.1.1.3.  Diffie-Hellman key exchange with authentication
135    79 F.1.2.    Version rollback attacks
136    79 F.1.3.    Detecting attacks against the handshake protocol
137    80 F.1.4.    Resuming sessions
138    80 F.1.5.    MD5 and SHA
139    81 F.2.      Protecting application data
140    81 F.3.      Explicit IVs
141    81 F.4       Security of Composite Cipher Modes
142    82 F.5       Denial of Service
143    83 F.6.      Final notes
144    83
147 Change history
149    03-Dec-04 ekr@rtfm.com
150     * Removed export cipher suites
152    26-Oct-04 ekr@rtfm.com
153     * Numerous cleanups from Last Call comments
155    10-Aug-04 ekr@rtfm.com
156     * Added clarifying material about interleaved application data.
161 Dierks & Rescorla            Standards Track                     [Page 3]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
164    27-Jul-04 ekr@rtfm.com
165     * Premature closes no longer cause a session to be nonresumable.
166       Response to WG consensus.
168     * Added IANA considerations and registry for cipher suites
169       and ClientCertificateTypes
171    26-Jun-03 ekr@rtfm.com
172     * Incorporated Last Call comments from Franke Marcus, Jack Lloyd,
173     Brad Wetmore, and others.
175    22-Apr-03 ekr@rtfm.com
176     * coverage of the Vaudenay, Boneh-Brumley, and KPR attacks
177     * cleaned up IV text a bit.
178     * Added discussion of Denial of Service attacks.
180    11-Feb-02 ekr@rtfm.com
181     * Clarified the behavior of empty certificate lists [Nelson Bolyard]
182     * Added text explaining the security implications of authenticate
183       then encrypt.
184     * Cleaned up the explicit IV text.
185     * Added some more acknowledgement names
187    02-Nov-02 ekr@rtfm.com
188     * Changed this to be TLS 1.1.
189     * Added fixes for the Rogaway and Vaudenay CBC attacks
190     * Separated references into normative and informative
192    01-Mar-02 ekr@rtfm.com
193     * Tightened up the language in F.1.1.2 [Peter Watkins]
194     * Fixed smart quotes [Bodo Moeller]
195     * Changed handling of padding errors to prevent CBC-based attack
196       [Bodo Moeller]
197     * Fixed certificate_list spec in the appendix [Aman Sawrup]
198     * Fixed a bug in the V2 definitions [Aman Sawrup]
199     * Fixed S 7.2.1 to point out that you don't need a close notify
200       if you just sent some other fatal alert [Andreas Sterbenz]
201     * Marked alert 41 reserved [Andreas Sterbenz]
202     * Changed S 7.4.2 to point out that 512-bit keys cannot be used for
203       signing [Andreas Sterbenz]
204     * Added reserved client key types from SSLv3 [Andreas Sterbenz]
205     * Changed EXPORT40 to "40-bit EXPORT" in S 9 [Andreas Sterbenz]
206     * Removed RSA patent statement [Andreas Sterbenz]
207     * Removed references to BSAFE and RSAREF [Andreas Sterbenz]
209    14-Feb-02 ekr@rtfm.com
210     * Re-converted to I-D from RFC
211     * Made RSA/3DES the mandatory cipher suite.
215 Dierks & Rescorla            Standards Track                     [Page 4]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
218     * Added discussion of the EncryptedPMS encoding and PMS version number
219       issues to 7.4.7.1
220     * Removed the requirement in 7.4.1.3 that the Server random must be
221       different from the Client random, since these are randomly generated
222       and we don't expect servers to reject Server random values which
223       coincidentally are the same as the Client random.
224     * Replaced may/should/must with MAY/SHOULD/MUST where appropriate.
225       In many cases, shoulds became MUSTs, where I believed that was the
226       actual sense of the text. Added an RFC 2119 bulletin.
227    * Clarified the meaning of "empty certificate" message. [Peter Gutmann]
228    * Redid the CertificateRequest grammar to allow no distinguished names.
229      [Peter Gutmann]
230    * Removed the reference to requiring the master secret to generate
231      the CertificateVerify in F.1.1 [Bodo Moeller]
232    * Deprecated EXPORT40.
233    * Fixed a bunch of errors in the SSLv2 backward compatible client hello.
235 1. Introduction
237    The primary goal of the TLS Protocol is to provide privacy and data
238    integrity between two communicating applications. The protocol is
239    composed of two layers: the TLS Record Protocol and the TLS Handshake
240    Protocol. At the lowest level, layered on top of some reliable
241    transport protocol (e.g., TCP[TCP]), is the TLS Record Protocol. The
242    TLS Record Protocol provides connection security that has two basic
243    properties:
245      -  The connection is private. Symmetric cryptography is used for
246        data encryption (e.g., DES [DES], RC4 [RC4], etc.). The keys for
247        this symmetric encryption are generated uniquely for each
248        connection and are based on a secret negotiated by another
249        protocol (such as the TLS Handshake Protocol). The Record
250        Protocol can also be used without encryption.
252      -  The connection is reliable. Message transport includes a message
253        integrity check using a keyed MAC. Secure hash functions (e.g.,
254        SHA, MD5, etc.) are used for MAC computations. The Record
255        Protocol can operate without a MAC, but is generally only used in
256        this mode while another protocol is using the Record Protocol as
257        a transport for negotiating security parameters.
259    The TLS Record Protocol is used for encapsulation of various higher
260    level protocols. One such encapsulated protocol, the TLS Handshake
261    Protocol, allows the server and client to authenticate each other and
262    to negotiate an encryption algorithm and cryptographic keys before
263    the application protocol transmits or receives its first byte of
264    data. The TLS Handshake Protocol provides connection security that
265    has three basic properties:
269 Dierks & Rescorla            Standards Track                     [Page 5]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
272      -  The peer's identity can be authenticated using asymmetric, or
273        public key, cryptography (e.g., RSA [RSA], DSS [DSS], etc.). This
274        authentication can be made optional, but is generally required
275        for at least one of the peers.
277      -  The negotiation of a shared secret is secure: the negotiated
278        secret is unavailable to eavesdroppers, and for any authenticated
279        connection the secret cannot be obtained, even by an attacker who
280        can place himself in the middle of the connection.
282      -  The negotiation is reliable: no attacker can modify the
283        negotiation communication without being detected by the parties
284        to the communication.
286    One advantage of TLS is that it is application protocol independent.
287    Higher level protocols can layer on top of the TLS Protocol
288    transparently. The TLS standard, however, does not specify how
289    protocols add security with TLS; the decisions on how to initiate TLS
290    handshaking and how to interpret the authentication certificates
291    exchanged are left up to the judgment of the designers and
292    implementors of protocols which run on top of TLS.
294    This document is a revision of the TLS 1.0 [TLS1.0] protocol which
295    contains some small security improvements, clarifications, and
296    editorial improvements. The major changes are:
298      - The implicit Initialization Vector (IV) is replaced with an
299    explicit
300        IV to protect against CBC attacks [CBCATT].
302      - Handling of padding errors is changed to use the bad_record_mac
303        alert rather than the decryption_failed alert to protect against
304        CBC attacks.
306      - IANA registries are defined for protocol parameters.
308      - Premature closes no longer cause a session to be nonresumable.
310      - Additional informational notes were added for various new attacks
311        on TLS.
313    In addition, a number of minor clarifications and editorial
314    improvements were made.
318 1.1 Requirements Terminology
323 Dierks & Rescorla            Standards Track                     [Page 6]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
326    Keywords "MUST", "MUST NOT", "REQUIRED", "SHOULD", "SHOULD NOT" and
327    "MAY" that appear in this document are to be interpreted as described
328    in RFC 2119 [REQ].
330 2. Goals
332    The goals of TLS Protocol, in order of their priority, are:
334     1. Cryptographic security: TLS should be used to establish a secure
335        connection between two parties.
337     2. Interoperability: Independent programmers should be able to
338        develop applications utilizing TLS that will then be able to
339        successfully exchange cryptographic parameters without knowledge
340        of one another's code.
342     3. Extensibility: TLS seeks to provide a framework into which new
343        public key and bulk encryption methods can be incorporated as
344        necessary. This will also accomplish two sub-goals: to prevent
345        the need to create a new protocol (and risking the introduction
346        of possible new weaknesses) and to avoid the need to implement an
347        entire new security library.
349     4. Relative efficiency: Cryptographic operations tend to be highly
350        CPU intensive, particularly public key operations. For this
351        reason, the TLS protocol has incorporated an optional session
352        caching scheme to reduce the number of connections that need to
353        be established from scratch. Additionally, care has been taken to
354        reduce network activity.
356 3. Goals of this document
358    This document and the TLS protocol itself are based on the SSL 3.0
359    Protocol Specification as published by Netscape. The differences
360    between this protocol and SSL 3.0 are not dramatic, but they are
361    significant enough that TLS 1.1, TLS 1.0,  and SSL 3.0 do not
362    interoperate (although each protocol incorporates a mechanism by
363    which an implementation can back down prior versions. This document
364    is intended primarily for readers who will be implementing the
365    protocol and those doing cryptographic analysis of it. The
366    specification has been written with this in mind, and it is intended
367    to reflect the needs of those two groups. For that reason, many of
368    the algorithm-dependent data structures and rules are included in the
369    body of the text (as opposed to in an appendix), providing easier
370    access to them.
372    This document is not intended to supply any details of service
373    definition nor interface definition, although it does cover select
377 Dierks & Rescorla            Standards Track                     [Page 7]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
380    areas of policy as they are required for the maintenance of solid
381    security.
383 4. Presentation language
385    This document deals with the formatting of data in an external
386    representation. The following very basic and somewhat casually
387    defined presentation syntax will be used. The syntax draws from
388    several sources in its structure. Although it resembles the
389    programming language "C" in its syntax and XDR [XDR] in both its
390    syntax and intent, it would be risky to draw too many parallels. The
391    purpose of this presentation language is to document TLS only, not to
392    have general application beyond that particular goal.
431 Dierks & Rescorla            Standards Track                     [Page 8]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
434 4.1. Basic block size
436    The representation of all data items is explicitly specified. The
437    basic data block size is one byte (i.e. 8 bits). Multiple byte data
438    items are concatenations of bytes, from left to right, from top to
439    bottom. From the bytestream a multi-byte item (a numeric in the
440    example) is formed (using C notation) by:
442        value = (byte[0] << 8*(n-1)) | (byte[1] << 8*(n-2)) |
443                ... | byte[n-1];
445    This byte ordering for multi-byte values is the commonplace network
446    byte order or big endian format.
448 4.2. Miscellaneous
450    Comments begin with "/*" and end with "*/".
452    Optional components are denoted by enclosing them in "[[ ]]" double
453    brackets.
455    Single byte entities containing uninterpreted data are of type
456    opaque.
458 4.3. Vectors
460    A vector (single dimensioned array) is a stream of homogeneous data
461    elements. The size of the vector may be specified at documentation
462    time or left unspecified until runtime. In either case the length
463    declares the number of bytes, not the number of elements, in the
464    vector. The syntax for specifying a new type T' that is a fixed
465    length vector of type T is
467        T T'[n];
469    Here T' occupies n bytes in the data stream, where n is a multiple of
470    the size of T. The length of the vector is not included in the
471    encoded stream.
473    In the following example, Datum is defined to be three consecutive
474    bytes that the protocol does not interpret, while Data is three
475    consecutive Datum, consuming a total of nine bytes.
477        opaque Datum[3];      /* three uninterpreted bytes */
478        Datum Data[9];        /* 3 consecutive 3 byte vectors */
485 Dierks & Rescorla            Standards Track                     [Page 9]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
488    Variable length vectors are defined by specifying a subrange of legal
489    lengths, inclusively, using the notation <floor..ceiling>.  When
490    encoded, the actual length precedes the vector's contents in the byte
491    stream. The length will be in the form of a number consuming as many
492    bytes as required to hold the vector's specified maximum (ceiling)
493    length. A variable length vector with an actual length field of zero
494    is referred to as an empty vector.
496        T T'<floor..ceiling>;
498    In the following example, mandatory is a vector that must contain
499    between 300 and 400 bytes of type opaque. It can never be empty. The
500    actual length field consumes two bytes, a uint16, sufficient to
501    represent the value 400 (see Section 4.4). On the other hand, longer
502    can represent up to 800 bytes of data, or 400 uint16 elements, and it
503    may be empty. Its encoding will include a two byte actual length
504    field prepended to the vector. The length of an encoded vector must
505    be an even multiple of the length of a single element (for example, a
506    17 byte vector of uint16 would be illegal).
508        opaque mandatory<300..400>;
509              /* length field is 2 bytes, cannot be empty */
510        uint16 longer<0..800>;
511              /* zero to 400 16-bit unsigned integers */
513 4.4. Numbers
515    The basic numeric data type is an unsigned byte (uint8). All larger
516    numeric data types are formed from fixed length series of bytes
517    concatenated as described in Section 4.1 and are also unsigned. The
518    following numeric types are predefined.
520        uint8 uint16[2];
521        uint8 uint24[3];
522        uint8 uint32[4];
523        uint8 uint64[8];
525    All values, here and elsewhere in the specification, are stored in
526    "network" or "big-endian" order; the uint32 represented by the hex
527    bytes 01 02 03 04 is equivalent to the decimal value 16909060.
529 4.5. Enumerateds
531    An additional sparse data type is available called enum. A field of
532    type enum can only assume the values declared in the definition.
533    Each definition is a different type. Only enumerateds of the same
534    type may be assigned or compared. Every element of an enumerated must
539 Dierks & Rescorla            Standards Track                    [Page 10]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
542    be assigned a value, as demonstrated in the following example.  Since
543    the elements of the enumerated are not ordered, they can be assigned
544    any unique value, in any order.
546        enum { e1(v1), e2(v2), ... , en(vn) [[, (n)]] } Te;
548    Enumerateds occupy as much space in the byte stream as would its
549    maximal defined ordinal value. The following definition would cause
550    one byte to be used to carry fields of type Color.
552        enum { red(3), blue(5), white(7) } Color;
554    One may optionally specify a value without its associated tag to
555    force the width definition without defining a superfluous element.
556    In the following example, Taste will consume two bytes in the data
557    stream but can only assume the values 1, 2 or 4.
559        enum { sweet(1), sour(2), bitter(4), (32000) } Taste;
561    The names of the elements of an enumeration are scoped within the
562    defined type. In the first example, a fully qualified reference to
563    the second element of the enumeration would be Color.blue. Such
564    qualification is not required if the target of the assignment is well
565    specified.
567        Color color = Color.blue;     /* overspecified, legal */
568        Color color = blue;           /* correct, type implicit */
570    For enumerateds that are never converted to external representation,
571    the numerical information may be omitted.
573        enum { low, medium, high } Amount;
575 4.6. Constructed types
577    Structure types may be constructed from primitive types for
578    convenience. Each specification declares a new, unique type. The
579    syntax for definition is much like that of C.
581        struct {
582          T1 f1;
583          T2 f2;
584          ...
585          Tn fn;
586        } [[T]];
593 Dierks & Rescorla            Standards Track                    [Page 11]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
596    The fields within a structure may be qualified using the type's name
597    using a syntax much like that available for enumerateds. For example,
598    T.f2 refers to the second field of the previous declaration.
599    Structure definitions may be embedded.
601 4.6.1. Variants
603    Defined structures may have variants based on some knowledge that is
604    available within the environment. The selector must be an enumerated
605    type that defines the possible variants the structure defines. There
606    must be a case arm for every element of the enumeration declared in
607    the select. The body of the variant structure may be given a label
608    for reference. The mechanism by which the variant is selected at
609    runtime is not prescribed by the presentation language.
611        struct {
612            T1 f1;
613            T2 f2;
614            ....
615            Tn fn;
616            select (E) {
617                case e1: Te1;
618                case e2: Te2;
619                ....
620                case en: Ten;
621            } [[fv]];
622        } [[Tv]];
624    For example:
626        enum { apple, orange } VariantTag;
627        struct {
628            uint16 number;
629            opaque string<0..10>; /* variable length */
630        } V1;
631        struct {
632            uint32 number;
633            opaque string[10];    /* fixed length */
634        } V2;
635        struct {
636            select (VariantTag) { /* value of selector is implicit */
637                case apple: V1;   /* VariantBody, tag = apple */
638                case orange: V2;  /* VariantBody, tag = orange */
639            } variant_body;       /* optional label on variant */
640        } VariantRecord;
642    Variant structures may be qualified (narrowed) by specifying a value
643    for the selector prior to the type. For example, a
647 Dierks & Rescorla            Standards Track                    [Page 12]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
650        orange VariantRecord
652    is a narrowed type of a VariantRecord containing a variant_body of
653    type V2.
655 4.7. Cryptographic attributes
657    The four cryptographic operations digital signing, stream cipher
658    encryption, block cipher encryption, and public key encryption are
659    designated digitally-signed, stream-ciphered, block-ciphered, and
660    public-key-encrypted, respectively. A field's cryptographic
661    processing is specified by prepending an appropriate key word
662    designation before the field's type specification. Cryptographic keys
663    are implied by the current session state (see Section 6.1).
665    In digital signing, one-way hash functions are used as input for a
666    signing algorithm. A digitally-signed element is encoded as an opaque
667    vector <0..2^16-1>, where the length is specified by the signing
668    algorithm and key.
670    In RSA signing, a 36-byte structure of two hashes (one SHA and one
671    MD5) is signed (encrypted with the private key). It is encoded with
672    PKCS #1 block type 0 or type 1 as described in [PKCS1].
674    In DSS, the 20 bytes of the SHA hash are run directly through the
675    Digital Signing Algorithm with no additional hashing. This produces
676    two values, r and s. The DSS signature is an opaque vector, as above,
677    the contents of which are the DER encoding of:
679        Dss-Sig-Value  ::=  SEQUENCE  {
680             r       INTEGER,
681             s       INTEGER
682        }
684    In stream cipher encryption, the plaintext is exclusive-ORed with an
685    identical amount of output generated from a cryptographically-secure
686    keyed pseudorandom number generator.
688    In block cipher encryption, every block of plaintext encrypts to a
689    block of ciphertext. All block cipher encryption is done in CBC
690    (Cipher Block Chaining) mode, and all items which are block-ciphered
691    will be an exact multiple of the cipher block length.
693    In public key encryption, a public key algorithm is used to encrypt
694    data in such a way that it can be decrypted only with the matching
695    private key. A public-key-encrypted element is encoded as an opaque
696    vector <0..2^16-1>, where the length is specified by the signing
697    algorithm and key.
701 Dierks & Rescorla            Standards Track                    [Page 13]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
704    An RSA encrypted value is encoded with PKCS #1 block type 2 as
705    described in [PKCS1].
707    In the following example:
709        stream-ciphered struct {
710            uint8 field1;
711            uint8 field2;
712            digitally-signed opaque hash[20];
713        } UserType;
715    The contents of hash are used as input for the signing algorithm,
716    then the entire structure is encrypted with a stream cipher. The
717    length of this structure, in bytes would be equal to 2 bytes for
718    field1 and field2, plus two bytes for the length of the signature,
719    plus the length of the output of the signing algorithm. This is known
720    due to the fact that the algorithm and key used for the signing are
721    known prior to encoding or decoding this structure.
723 4.8. Constants
725    Typed constants can be defined for purposes of specification by
726    declaring a symbol of the desired type and assigning values to it.
727    Under-specified types (opaque, variable length vectors, and
728    structures that contain opaque) cannot be assigned values. No fields
729    of a multi-element structure or vector may be elided.
731    For example,
733        struct {
734            uint8 f1;
735            uint8 f2;
736        } Example1;
738        Example1 ex1 = {1, 4};  /* assigns f1 = 1, f2 = 4 */
740 5. HMAC and the pseudorandom function
742    A number of operations in the TLS record and handshake layer required
743    a keyed MAC; this is a secure digest of some data protected by a
744    secret. Forging the MAC is infeasible without knowledge of the MAC
745    secret. The construction we use for this operation is known as HMAC,
746    described in [HMAC].
748    HMAC can be used with a variety of different hash algorithms. TLS
749    uses it in the handshake with two different algorithms: MD5 and
750    SHA-1, denoting these as HMAC_MD5(secret, data) and HMAC_SHA(secret,
755 Dierks & Rescorla            Standards Track                    [Page 14]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
758    data). Additional hash algorithms can be defined by cipher suites and
759    used to protect record data, but MD5 and SHA-1 are hard coded into
760    the description of the handshaking for this version of the protocol.
762    In addition, a construction is required to do expansion of secrets
763    into blocks of data for the purposes of key generation or validation.
764    This pseudo-random function (PRF) takes as input a secret, a seed,
765    and an identifying label and produces an output of arbitrary length.
767    In order to make the PRF as secure as possible, it uses two hash
768    algorithms in a way which should guarantee its security if either
769    algorithm remains secure.
771    First, we define a data expansion function, P_hash(secret, data)
772    which uses a single hash function to expand a secret and seed into an
773    arbitrary quantity of output:
775        P_hash(secret, seed) = HMAC_hash(secret, A(1) + seed) +
776                               HMAC_hash(secret, A(2) + seed) +
777                               HMAC_hash(secret, A(3) + seed) + ...
779    Where + indicates concatenation.
781    A() is defined as:
782        A(0) = seed
783        A(i) = HMAC_hash(secret, A(i-1))
785    P_hash can be iterated as many times as is necessary to produce the
786    required quantity of data. For example, if P_SHA-1 was being used to
787    create 64 bytes of data, it would have to be iterated 4 times
788    (through A(4)), creating 80 bytes of output data; the last 16 bytes
789    of the final iteration would then be discarded, leaving 64 bytes of
790    output data.
792    TLS's PRF is created by splitting the secret into two halves and
793    using one half to generate data with P_MD5 and the other half to
794    generate data with P_SHA-1, then exclusive-or'ing the outputs of
795    these two expansion functions together.
797    S1 and S2 are the two halves of the secret and each is the same
798    length. S1 is taken from the first half of the secret, S2 from the
799    second half. Their length is created by rounding up the length of the
800    overall secret divided by two; thus, if the original secret is an odd
801    number of bytes long, the last byte of S1 will be the same as the
802    first byte of S2.
804        L_S = length in bytes of secret;
805        L_S1 = L_S2 = ceil(L_S / 2);
809 Dierks & Rescorla            Standards Track                    [Page 15]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
812    The secret is partitioned into two halves (with the possibility of
813    one shared byte) as described above, S1 taking the first L_S1 bytes
814    and S2 the last L_S2 bytes.
816    The PRF is then defined as the result of mixing the two pseudorandom
817    streams by exclusive-or'ing them together.
819        PRF(secret, label, seed) = P_MD5(S1, label + seed) XOR
820                                   P_SHA-1(S2, label + seed);
822    The label is an ASCII string. It should be included in the exact form
823    it is given without a length byte or trailing null character.  For
824    example, the label "slithy toves" would be processed by hashing the
825    following bytes:
827        73 6C 69 74 68 79 20 74 6F 76 65 73
829    Note that because MD5 produces 16 byte outputs and SHA-1 produces 20
830    byte outputs, the boundaries of their internal iterations will not be
831    aligned; to generate a 80 byte output will involve P_MD5 being
832    iterated through A(5), while P_SHA-1 will only iterate through A(4).
834 6. The TLS Record Protocol
836    The TLS Record Protocol is a layered protocol. At each layer,
837    messages may include fields for length, description, and content.
838    The Record Protocol takes messages to be transmitted, fragments the
839    data into manageable blocks, optionally compresses the data, applies
840    a MAC, encrypts, and transmits the result. Received data is
841    decrypted, verified, decompressed, and reassembled, then delivered to
842    higher level clients.
844    Four record protocol clients are described in this document: the
845    handshake protocol, the alert protocol, the change cipher spec
846    protocol, and the application data protocol. In order to allow
847    extension of the TLS protocol, additional record types can be
848    supported by the record protocol. Any new record types SHOULD
849    allocate type values immediately beyond the ContentType values for
850    the four record types described here (see Appendix A.1). All such
851    values must be defined by RFC 2434 Standards Action.  Section 11 for
852    IANA Considerations for ContentType values.
854    If a TLS implementation receives a record type it does not
855    understand, it SHOULD just ignore it. Any protocol designed for use
856    over TLS MUST be carefully designed to deal with all possible attacks
857    against it.  Note that because the type and length of a record are
858    not protected by encryption, care SHOULD be taken to minimize the
859    value of traffic analysis of these values.
863 Dierks & Rescorla            Standards Track                    [Page 16]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
866 6.1. Connection states
868    A TLS connection state is the operating environment of the TLS Record
869    Protocol. It specifies a compression algorithm, encryption algorithm,
870    and MAC algorithm. In addition, the parameters for these algorithms
871    are known: the MAC secret and the bulk encryption keys for the
872    connection in both the read and the write directions. Logically,
873    there are always four connection states outstanding: the current read
874    and write states, and the pending read and write states. All records
875    are processed under the current read and write states. The security
876    parameters for the pending states can be set by the TLS Handshake
877    Protocol, and the Change Cipher Spec can selectively make either of
878    the pending states current, in which case the appropriate current
879    state is disposed of and replaced with the pending state; the pending
880    state is then reinitialized to an empty state. It is illegal to make
881    a state which has not been initialized with security parameters a
882    current state. The initial current state always specifies that no
883    encryption, compression, or MAC will be used.
885    The security parameters for a TLS Connection read and write state are
886    set by providing the following values:
888    connection end
889        Whether this entity is considered the "client" or the "server" in
890        this connection.
892    bulk encryption algorithm
893        An algorithm to be used for bulk encryption. This specification
894        includes the key size of this algorithm, how much of that key is
895        secret, whether it is a block or stream cipher, the block size of
896        the cipher (if appropriate).
898    MAC algorithm
899        An algorithm to be used for message authentication. This
900        specification includes the size of the hash which is returned by
901        the MAC algorithm.
903    compression algorithm
904        An algorithm to be used for data compression. This specification
905        must include all information the algorithm requires to do
906        compression.
908    master secret
909        A 48 byte secret shared between the two peers in the connection.
911    client random
912        A 32 byte value provided by the client.
917 Dierks & Rescorla            Standards Track                    [Page 17]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
920    server random
921        A 32 byte value provided by the server.
923    These parameters are defined in the presentation language as:
925        enum { server, client } ConnectionEnd;
927        enum { null, rc4, rc2, des, 3des, des40 } BulkCipherAlgorithm;
929        enum { stream, block } CipherType;
931        enum { null, md5, sha } MACAlgorithm;
933        enum { null(0), (255) } CompressionMethod;
935        /* The algorithms specified in CompressionMethod,
936           BulkCipherAlgorithm, and MACAlgorithm may be added to. */
938        struct {
939            ConnectionEnd          entity;
940            BulkCipherAlgorithm    bulk_cipher_algorithm;
941            CipherType             cipher_type;
942            uint8                  key_size;
943            uint8                  key_material_length;
944            MACAlgorithm           mac_algorithm;
945            uint8                  hash_size;
946            CompressionMethod      compression_algorithm;
947            opaque                 master_secret[48];
948            opaque                 client_random[32];
949            opaque                 server_random[32];
950        } SecurityParameters;
952    The record layer will use the security parameters to generate the
953    following four items:
955        client write MAC secret
956        server write MAC secret
957        client write key
958        server write key
960    The client write parameters are used by the server when receiving and
961    processing records and vice-versa. The algorithm used for generating
962    these items from the security parameters is described in section 6.3.
964    Once the security parameters have been set and the keys have been
965    generated, the connection states can be instantiated by making them
966    the current states. These current states MUST be updated for each
967    record processed. Each connection state includes the following
971 Dierks & Rescorla            Standards Track                    [Page 18]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
974    elements:
976    compression state
977        The current state of the compression algorithm.
979    cipher state
980        The current state of the encryption algorithm. This will consist
981        of the scheduled key for that connection. For stream ciphers,
982        this will also contain whatever the necessary state information
983        is to allow the stream to continue to encrypt or decrypt data.
985    MAC secret
986        The MAC secret for this connection as generated above.
988    sequence number
989        Each connection state contains a sequence number, which is
990        maintained separately for read and write states. The sequence
991        number MUST be set to zero whenever a connection state is made
992        the active state. Sequence numbers are of type uint64 and may not
993        exceed 2^64-1. Sequence numbers do not wrap. If a TLS
994        implementation would need to wrap a sequence number it must
995        renegotiate instead. A sequence number is incremented after each
996        record: specifically, the first record which is transmitted under
997        a particular connection state MUST use sequence number 0.
999 6.2. Record layer
1001    The TLS Record Layer receives uninterpreted data from higher layers
1002    in non-empty blocks of arbitrary size.
1004 6.2.1. Fragmentation
1006    The record layer fragments information blocks into TLSPlaintext
1007    records carrying data in chunks of 2^14 bytes or less. Client message
1008    boundaries are not preserved in the record layer (i.e., multiple
1009    client messages of the same ContentType MAY be coalesced into a
1010    single TLSPlaintext record, or a single message MAY be fragmented
1011    across several records).
1014        struct {
1015            uint8 major, minor;
1016        } ProtocolVersion;
1018        enum {
1019            change_cipher_spec(20), alert(21), handshake(22),
1020            application_data(23), (255)
1021        } ContentType;
1025 Dierks & Rescorla            Standards Track                    [Page 19]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
1028        struct {
1029            ContentType type;
1030            ProtocolVersion version;
1031            uint16 length;
1032            opaque fragment[TLSPlaintext.length];
1033        } TLSPlaintext;
1035    type
1036        The higher level protocol used to process the enclosed fragment.
1038    version
1039        The version of the protocol being employed. This document
1040        describes TLS Version 1.1, which uses the version { 3, 2 }. The
1041        version value 3.2 is historical: TLS version 1.1 is a minor
1042        modification to the TLS 1.0 protocol, which was itself a minor
1043        modification to the SSL 3.0 protocol, which bears the version
1044        value 3.0. (See Appendix A.1).
1046    length
1047        The length (in bytes) of the following TLSPlaintext.fragment.
1048        The length should not exceed 2^14.
1050    fragment
1051        The application data. This data is transparent and treated as an
1052        independent block to be dealt with by the higher level protocol
1053        specified by the type field.
1055  Note: Data of different TLS Record layer content types MAY be
1056        interleaved. Application data is generally of higher precedence
1057        for transmission than other content types and therefore handshake
1058        records may be held if application data is pending.  However,
1059        records MUST be delivered to the network in the same order as
1060        they are protected by the record layer. Recipients MUST receive
1061        and process interleaved application layer traffic during
1062        handshakes subsequent to the first one on a connection.
1064 6.2.2. Record compression and decompression
1066    All records are compressed using the compression algorithm defined in
1067    the current session state. There is always an active compression
1068    algorithm; however, initially it is defined as
1069    CompressionMethod.null. The compression algorithm translates a
1070    TLSPlaintext structure into a TLSCompressed structure. Compression
1071    functions are initialized with default state information whenever a
1072    connection state is made active.
1079 Dierks & Rescorla            Standards Track                    [Page 20]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
1082    Compression must be lossless and may not increase the content length
1083    by more than 1024 bytes. If the decompression function encounters a
1084    TLSCompressed.fragment that would decompress to a length in excess of
1085    2^14 bytes, it should report a fatal decompression failure error.
1087        struct {
1088            ContentType type;       /* same as TLSPlaintext.type */
1089            ProtocolVersion version;/* same as TLSPlaintext.version */
1090            uint16 length;
1091            opaque fragment[TLSCompressed.length];
1092        } TLSCompressed;
1094    length
1095        The length (in bytes) of the following TLSCompressed.fragment.
1096        The length should not exceed 2^14 + 1024.
1098    fragment
1099        The compressed form of TLSPlaintext.fragment.
1101  Note: A CompressionMethod.null operation is an identity operation; no
1102        fields are altered.
1104    Implementation note:
1105        Decompression functions are responsible for ensuring that
1106        messages cannot cause internal buffer overflows.
1108 6.2.3. Record payload protection
1110    The encryption and MAC functions translate a TLSCompressed structure
1111    into a TLSCiphertext. The decryption functions reverse the process.
1112    The MAC of the record also includes a sequence number so that
1113    missing, extra or repeated messages are detectable.
1115        struct {
1116            ContentType type;
1117            ProtocolVersion version;
1118            uint16 length;
1119            select (CipherSpec.cipher_type) {
1120                case stream: GenericStreamCipher;
1121                case block: GenericBlockCipher;
1122            } fragment;
1123        } TLSCiphertext;
1125    type
1126        The type field is identical to TLSCompressed.type.
1128    version
1129        The version field is identical to TLSCompressed.version.
1133 Dierks & Rescorla            Standards Track                    [Page 21]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
1136    length
1137        The length (in bytes) of the following TLSCiphertext.fragment.
1138        The length may not exceed 2^14 + 2048.
1140    fragment
1141        The encrypted form of TLSCompressed.fragment, with the MAC.
1143 6.2.3.1. Null or standard stream cipher
1145    Stream ciphers (including BulkCipherAlgorithm.null - see Appendix
1146    A.6) convert TLSCompressed.fragment structures to and from stream
1147    TLSCiphertext.fragment structures.
1149        stream-ciphered struct {
1150            opaque content[TLSCompressed.length];
1151            opaque MAC[CipherSpec.hash_size];
1152        } GenericStreamCipher;
1154    The MAC is generated as:
1156        HMAC_hash(MAC_write_secret, seq_num + TLSCompressed.type +
1157                      TLSCompressed.version + TLSCompressed.length +
1158                      TLSCompressed.fragment));
1160    where "+" denotes concatenation.
1162    seq_num
1163        The sequence number for this record.
1165    hash
1166        The hashing algorithm specified by
1167        SecurityParameters.mac_algorithm.
1169    Note that the MAC is computed before encryption. The stream cipher
1170    encrypts the entire block, including the MAC. For stream ciphers that
1171    do not use a synchronization vector (such as RC4), the stream cipher
1172    state from the end of one record is simply used on the subsequent
1173    packet. If the CipherSuite is TLS_NULL_WITH_NULL_NULL, encryption
1174    consists of the identity operation (i.e., the data is not encrypted
1175    and the MAC size is zero implying that no MAC is used).
1176    TLSCiphertext.length is TLSCompressed.length plus
1177    CipherSpec.hash_size.
1179 6.2.3.2. CBC block cipher
1181    For block ciphers (such as RC2 or DES), the encryption and MAC
1182    functions convert TLSCompressed.fragment structures to and from block
1183    TLSCiphertext.fragment structures.
1187 Dierks & Rescorla            Standards Track                    [Page 22]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
1190        block-ciphered struct {
1191            opaque IV[CipherSpec.block_length];
1192            opaque content[TLSCompressed.length];
1193            opaque MAC[CipherSpec.hash_size];
1194            uint8 padding[GenericBlockCipher.padding_length];
1195            uint8 padding_length;
1196        } GenericBlockCipher;
1198    The MAC is generated as described in Section 6.2.3.1.
1200    IV
1201        Unlike previous versions of SSL and TLS, TLS 1.1 uses an explicit
1202        IV in order to prevent the attacks described by [CBCATT].
1203        We recommend the following equivalently strong procedures.
1204        For clarity we use the following notation.
1206        IV -- the transmitted value of the IV field in the
1207            GenericBlockCipher structure.
1208        CBC residue -- the last ciphertext block of the previous record
1209        mask -- the actual value which the cipher XORs with the
1210            plaintext prior to encryption of the first cipher block
1211            of the record.
1213        In prior versions of TLS, there was no IV field and the CBC residue
1214        and mask were one and the same. See Sections 6.1, 6.2.3.2 and 6.3,
1215        of [TLS1.0] for details of TLS 1.0 IV handling.
1217        One of the following two algorithms SHOULD be used to generate the
1218        per-record IV:
1220        (1) Generate a cryptographically strong random string R of
1221            length CipherSpec.block_length. Place R
1222            in the IV field. Set the mask to R. Thus, the first
1223            cipher block will be encrypted as E(R XOR Data).
1225        (2) Generate a cryptographically strong random number R of
1226            length CipherSpec.block_length and prepend it to the plaintext
1227            prior to encryption. In
1228            this case either:
1230            (a)   The cipher may use a fixed mask such as zero.
1231            (b) The CBC residue from the previous record may be used
1232                as the mask. This preserves maximum code compatibility
1233             with TLS 1.0 and SSL 3. It also has the advantage that
1234             it does not require the ability to quickly reset the IV,
1235             which is known to be a   problem on some systems.
1237             In either case, the data (R || data) is fed into the
1241 Dierks & Rescorla            Standards Track                    [Page 23]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
1244             encryption process. The first cipher block (containing
1245             E(mask XOR R) is placed in the IV field. The first
1246             block of content contains E(IV XOR data)
1248        The following alternative procedure MAY be used: However, it has
1249        not been demonstrated to be equivalently cryptographically strong
1250        to the above procedures. The sender prepends a fixed block F to
1251        the plaintext (or alternatively a block generated with a weak
1252        PRNG). He then encrypts as in (2) above, using the CBC residue
1253        from the previous block as the mask for the prepended block. Note
1254        that in this case the mask for the first record transmitted by
1255        the application (the Finished) MUST be generated using a
1256        cryptographically strong PRNG.
1258        The decryption operation for all three alternatives is the same.
1259        The receiver decrypts the entire GenericBlockCipher structure and
1260        then discards the first cipher block, corresponding to the IV
1261        component.
1263    padding
1264        Padding that is added to force the length of the plaintext to be
1265        an integral multiple of the block cipher's block length. The
1266        padding MAY be any length up to 255 bytes long, as long as it
1267        results in the TLSCiphertext.length being an integral multiple of
1268        the block length. Lengths longer than necessary might be
1269        desirable to frustrate attacks on a protocol based on analysis of
1270        the lengths of exchanged messages. Each uint8 in the padding data
1271        vector MUST be filled with the padding length value. The receiver
1272        MUST check this padding and SHOULD use the bad_record_mac alert
1273        to indicate padding errors.
1275    padding_length
1276        The padding length MUST be such that the total size of the
1277        GenericBlockCipher structure is a multiple of the cipher's block
1278        length. Legal values range from zero to 255, inclusive. This
1279        length specifies the length of the padding field exclusive of the
1280        padding_length field itself.
1282    The encrypted data length (TLSCiphertext.length) is one more than the
1283    sum of TLSCompressed.length, CipherSpec.hash_size, and
1284    padding_length.
1286  Example: If the block length is 8 bytes, the content length
1287           (TLSCompressed.length) is 61 bytes, and the MAC length is 20
1288           bytes, the length before padding is 82 bytes (this does not
1289           include the IV, which may or may not be encrypted, as
1290           discussed above). Thus, the padding length modulo 8 must be
1291           equal to 6 in order to make the total length an even multiple
1295 Dierks & Rescorla            Standards Track                    [Page 24]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
1298           of 8 bytes (the block length). The padding length can be 6,
1299           14, 22, and so on, through 254. If the padding length were the
1300           minimum necessary, 6, the padding would be 6 bytes, each
1301           containing the value 6.  Thus, the last 8 octets of the
1302           GenericBlockCipher before block encryption would be xx 06 06
1303           06 06 06 06 06, where xx is the last octet of the MAC.
1305  Note: With block ciphers in CBC mode (Cipher Block Chaining),
1306        it is critical that the entire plaintext of the record be known
1307        before any ciphertext is transmitted. Otherwise it is possible
1308        for the attacker to mount the attack described in [CBCATT].
1310  Implementation Note: Canvel et. al. [CBCTIME] have demonstrated a
1311        timing attack on CBC padding based on the time required to
1312        compute the MAC. In order to defend against this attack,
1313        implementations MUST ensure that record processing time is
1314        essentially the same whether or not the padding is correct.  In
1315        general, the best way to to do this is to compute the MAC even if
1316        the padding is incorrect, and only then reject the packet. For
1317        instance, if the pad appears to be incorrect the implementation
1318        might assume a zero-length pad and then compute the MAC. This
1319        leaves a small timing channel, since MAC performance depends to
1320        some extent on the size of the data fragment, but it is not
1321        believed to be large enough to be exploitable due to the large
1322        block size of existing MACs and the small size of the timing
1323        signal.
1325 6.3. Key calculation
1327    The Record Protocol requires an algorithm to generate keys, and MAC
1328    secrets from the security parameters provided by the handshake
1329    protocol.
1331    The master secret is hashed into a sequence of secure bytes, which
1332    are assigned to the MAC secrets and keys required by the current
1333    connection state (see Appendix A.6). CipherSpecs require a client
1334    write MAC secret, a server write MAC secret, a client write key, and
1335    a server write key, which are generated from the master secret in
1336    that order. Unused values are empty.
1338    When generating keys and MAC secrets, the master secret is used as an
1339    entropy source.
1341    To generate the key material, compute
1343        key_block = PRF(SecurityParameters.master_secret,
1344                           "key expansion",
1345                           SecurityParameters.server_random +
1349 Dierks & Rescorla            Standards Track                    [Page 25]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
1352                           SecurityParameters.client_random);
1354    until enough output has been generated. Then the key_block is
1355    partitioned as follows:
1357        client_write_MAC_secret[SecurityParameters.hash_size]
1358        server_write_MAC_secret[SecurityParameters.hash_size]
1359        client_write_key[SecurityParameters.key_material_length]
1360        server_write_key[SecurityParameters.key_material_length]
1363    Implementation note:
1364        The currently defined which requires the most material is
1365        AES_256_CBC_SHA, defined in [TLSAES]. It requires 2 x 32 byte
1366        keys and 2 x 20 byte MAC secrets, for a total 104 bytes of key
1367        material.
1369 7. The TLS Handshaking Protocols
1371        TLS has three subprotocols which are used to allow peers to agree
1372        upon security parameters for the record layer, authenticate
1373        themselves, instantiate negotiated security parameters, and
1374        report error conditions to each other.
1376        The Handshake Protocol is responsible for negotiating a session,
1377        which consists of the following items:
1379        session identifier
1380        An arbitrary byte sequence chosen by the server to identify an
1381        active or resumable session state.
1383    peer certificate
1384        X509v3 [X509] certificate of the peer. This element of the state
1385        may be null.
1387    compression method
1388        The algorithm used to compress data prior to encryption.
1390    cipher spec
1391        Specifies the bulk data encryption algorithm (such as null, DES,
1392        etc.) and a MAC algorithm (such as MD5 or SHA). It also defines
1393        cryptographic attributes such as the hash_size. (See Appendix A.6
1394        for formal definition)
1396    master secret
1397        48-byte secret shared between the client and server.
1399    is resumable
1403 Dierks & Rescorla            Standards Track                    [Page 26]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
1406        A flag indicating whether the session can be used to initiate new
1407        connections.
1409    These items are then used to create security parameters for use by
1410    the Record Layer when protecting application data. Many connections
1411    can be instantiated using the same session through the resumption
1412    feature of the TLS Handshake Protocol.
1414 7.1. Change cipher spec protocol
1416    The change cipher spec protocol exists to signal transitions in
1417    ciphering strategies. The protocol consists of a single message,
1418    which is encrypted and compressed under the current (not the pending)
1419    connection state. The message consists of a single byte of value 1.
1421        struct {
1422            enum { change_cipher_spec(1), (255) } type;
1423        } ChangeCipherSpec;
1425    The change cipher spec message is sent by both the client and server
1426    to notify the receiving party that subsequent records will be
1427    protected under the newly negotiated CipherSpec and keys. Reception
1428    of this message causes the receiver to instruct the Record Layer to
1429    immediately copy the read pending state into the read current state.
1430    Immediately after sending this message, the sender MUST instruct the
1431    record layer to make the write pending state the write active state.
1432    (See section 6.1.) The change cipher spec message is sent during the
1433    handshake after the security parameters have been agreed upon, but
1434    before the verifying finished message is sent (see section 7.4.9).
1436  Note: if a rehandshake occurs while data is flowing on a connection,
1437    the communicating parties may continue to send data using the old
1438    CipherSpec However, once the ChangeCipherSpec has been sent, the new
1439    CipherSpec MUST be used. The first side to send the ChangeCipherSpec
1440    does not know that the other side has finished computing the new
1441    keying material (e.g. if it has to perform a time consuming public
1442    key operation). Thus, a small window of time during which the
1443    recipient must buffer the data MAY exist. In practice, with modern
1444    machines this interval is likely to be fairly short.
1446 7.2. Alert protocol
1448    One of the content types supported by the TLS Record layer is the
1449    alert type. Alert messages convey the severity of the message and a
1450    description of the alert. Alert messages with a level of fatal result
1451    in the immediate termination of the connection. In this case, other
1452    connections corresponding to the session may continue, but the
1453    session identifier MUST be invalidated, preventing the failed session
1457 Dierks & Rescorla            Standards Track                    [Page 27]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
1460    from being used to establish new connections. Like other messages,
1461    alert messages are encrypted and compressed, as specified by the
1462    current connection state.
1464        enum { warning(1), fatal(2), (255) } AlertLevel;
1466        enum {
1467            close_notify(0),
1468            unexpected_message(10),
1469            bad_record_mac(20),
1470            decryption_failed(21),
1471            record_overflow(22),
1472            decompression_failure(30),
1473            handshake_failure(40),
1474            no_certificate_RESERVED (41),
1475            bad_certificate(42),
1476            unsupported_certificate(43),
1477            certificate_revoked(44),
1478            certificate_expired(45),
1479            certificate_unknown(46),
1480            illegal_parameter(47),
1481            unknown_ca(48),
1482            access_denied(49),
1483            decode_error(50),
1484            decrypt_error(51),
1485            export_restriction_RESERVED(60),
1486            protocol_version(70),
1487            insufficient_security(71),
1488            internal_error(80),
1489            user_canceled(90),
1490            no_renegotiation(100),
1491            (255)
1492        } AlertDescription;
1494        struct {
1495            AlertLevel level;
1496            AlertDescription description;
1497        } Alert;
1499 7.2.1. Closure alerts
1501    The client and the server must share knowledge that the connection is
1502    ending in order to avoid a truncation attack. Either party may
1503    initiate the exchange of closing messages.
1505    close_notify
1506        This message notifies the recipient that the sender will not send
1507        any more messages on this connection. Note that as of TLS 1.1,
1511 Dierks & Rescorla            Standards Track                    [Page 28]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
1514        failure to properly close a connection no longer requires that a
1515        session not be resumed. This is a change from TLS 1.0 to conform
1516        with widespread implementation practice.
1518    Either party may initiate a close by sending a close_notify alert.
1519    Any data received after a closure alert is ignored.
1521    Unless some other fatal alert has been transmitted, each party is
1522    required to send a close_notify alert before closing the write side
1523    of the connection. The other party MUST respond with a close_notify
1524    alert of its own and close down the connection immediately,
1525    discarding any pending writes. It is not required for the initiator
1526    of the close to wait for the responding close_notify alert before
1527    closing the read side of the connection.
1529    If the application protocol using TLS provides that any data may be
1530    carried over the underlying transport after the TLS connection is
1531    closed, the TLS implementation must receive the responding
1532    close_notify alert before indicating to the application layer that
1533    the TLS connection has ended. If the application protocol will not
1534    transfer any additional data, but will only close the underlying
1535    transport connection, then the implementation MAY choose to close the
1536    transport without waiting for the responding close_notify. No part of
1537    this standard should be taken to dictate the manner in which a usage
1538    profile for TLS manages its data transport, including when
1539    connections are opened or closed.
1541    NB: It is assumed that closing a connection reliably delivers
1542        pending data before destroying the transport.
1544 7.2.2. Error alerts
1546    Error handling in the TLS Handshake protocol is very simple. When an
1547    error is detected, the detecting party sends a message to the other
1548    party. Upon transmission or receipt of an fatal alert message, both
1549    parties immediately close the connection. Servers and clients MUST
1550    forget any session-identifiers, keys, and secrets associated with a
1551    failed connection. Thus, any connection terminated with a fatal alert
1552    MUST NOT be resumed. The following error alerts are defined:
1554    unexpected_message
1555        An inappropriate message was received. This alert is always fatal
1556        and should never be observed in communication between proper
1557        implementations.
1559    bad_record_mac
1560        This alert is returned if a record is received with an incorrect
1561        MAC. This alert also MUST be returned if an alert is sent because
1565 Dierks & Rescorla            Standards Track                    [Page 29]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
1568        a TLSCiphertext decrypted in an invalid way: either it wasn't an
1569        even multiple of the block length, or its padding values, when
1570        checked, weren't correct. This message is always fatal.
1572    decryption_failed
1573        This alert MAY be returned if a TLSCiphertext decrypted in an
1574        invalid way: either it wasn't an even multiple of the block
1575        length, or its padding values, when checked, weren't correct.
1576        This message is always fatal.
1578        NB: Differentiating between bad_record_mac and decryption_failed
1579        alerts may permit certain attacks against CBC mode as used in TLS
1580        [CBCATT]. It is preferable to uniformly use the bad_record_mac
1581        alert to hide the specific type of the error.
1584    record_overflow
1585        A TLSCiphertext record was received which had a length more than
1586        2^14+2048 bytes, or a record decrypted to a TLSCompressed record
1587        with more than 2^14+1024 bytes. This message is always fatal.
1589    decompression_failure
1590        The decompression function received improper input (e.g. data
1591        that would expand to excessive length). This message is always
1592        fatal.
1594    handshake_failure
1595        Reception of a handshake_failure alert message indicates that the
1596        sender was unable to negotiate an acceptable set of security
1597        parameters given the options available. This is a fatal error.
1599    no_certificate_RESERVED
1600        This alert was used in SSLv3 but not in TLS. It should not be
1601        sent by compliant implementations.
1603    bad_certificate
1604        A certificate was corrupt, contained signatures that did not
1605        verify correctly, etc.
1607    unsupported_certificate
1608        A certificate was of an unsupported type.
1610    certificate_revoked
1611        A certificate was revoked by its signer.
1613    certificate_expired
1614        A certificate has expired or is not currently valid.
1619 Dierks & Rescorla            Standards Track                    [Page 30]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
1622    certificate_unknown
1623        Some other (unspecified) issue arose in processing the
1624        certificate, rendering it unacceptable.
1626    illegal_parameter
1627        A field in the handshake was out of range or inconsistent with
1628        other fields. This is always fatal.
1630    unknown_ca
1631        A valid certificate chain or partial chain was received, but the
1632        certificate was not accepted because the CA certificate could not
1633        be located or couldn't be matched with a known, trusted CA.  This
1634        message is always fatal.
1636    access_denied
1637        A valid certificate was received, but when access control was
1638        applied, the sender decided not to proceed with negotiation.
1639        This message is always fatal.
1641    decode_error
1642        A message could not be decoded because some field was out of the
1643        specified range or the length of the message was incorrect. This
1644        message is always fatal.
1646    decrypt_error
1647        A handshake cryptographic operation failed, including being
1648        unable to correctly verify a signature, decrypt a key exchange,
1649        or validate a finished message.
1651    export_restriction_RESERVED
1652        This alert was used in TLS 1.0 but not TLS 1.1.
1654    protocol_version
1655        The protocol version the client has attempted to negotiate is
1656        recognized, but not supported. (For example, old protocol
1657        versions might be avoided for security reasons). This message is
1658        always fatal.
1660    insufficient_security
1661        Returned instead of handshake_failure when a negotiation has
1662        failed specifically because the server requires ciphers more
1663        secure than those supported by the client. This message is always
1664        fatal.
1666    internal_error
1667        An internal error unrelated to the peer or the correctness of the
1668        protocol makes it impossible to continue (such as a memory
1669        allocation failure). This message is always fatal.
1673 Dierks & Rescorla            Standards Track                    [Page 31]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
1676    user_canceled
1677        This handshake is being canceled for some reason unrelated to a
1678        protocol failure. If the user cancels an operation after the
1679        handshake is complete, just closing the connection by sending a
1680        close_notify is more appropriate. This alert should be followed
1681        by a close_notify. This message is generally a warning.
1683    no_renegotiation
1684        Sent by the client in response to a hello request or by the
1685        server in response to a client hello after initial handshaking.
1686        Either of these would normally lead to renegotiation; when that
1687        is not appropriate, the recipient should respond with this alert;
1688        at that point, the original requester can decide whether to
1689        proceed with the connection. One case where this would be
1690        appropriate would be where a server has spawned a process to
1691        satisfy a request; the process might receive security parameters
1692        (key length, authentication, etc.) at startup and it might be
1693        difficult to communicate changes to these parameters after that
1694        point. This message is always a warning.
1696    For all errors where an alert level is not explicitly specified, the
1697    sending party MAY determine at its discretion whether this is a fatal
1698    error or not; if an alert with a level of warning is received, the
1699    receiving party MAY decide at its discretion whether to treat this as
1700    a fatal error or not. However, all messages which are transmitted
1701    with a level of fatal MUST be treated as fatal messages.
1703    New alerts values MUST be defined by RFC 2434 Standards Action. See
1704    Section 11 for IANA Considerations for alert values.
1706 7.3. Handshake Protocol overview
1708    The cryptographic parameters of the session state are produced by the
1709    TLS Handshake Protocol, which operates on top of the TLS Record
1710    Layer. When a TLS client and server first start communicating, they
1711    agree on a protocol version, select cryptographic algorithms,
1712    optionally authenticate each other, and use public-key encryption
1713    techniques to generate shared secrets.
1715    The TLS Handshake Protocol involves the following steps:
1717      -  Exchange hello messages to agree on algorithms, exchange random
1718        values, and check for session resumption.
1720      -  Exchange the necessary cryptographic parameters to allow the
1721        client and server to agree on a premaster secret.
1723      -  Exchange certificates and cryptographic information to allow the
1727 Dierks & Rescorla            Standards Track                    [Page 32]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
1730        client and server to authenticate themselves.
1732      -  Generate a master secret from the premaster secret and exchanged
1733        random values.
1735      -  Provide security parameters to the record layer.
1737      -  Allow the client and server to verify that their peer has
1738        calculated the same security parameters and that the handshake
1739        occurred without tampering by an attacker.
1741    Note that higher layers should not be overly reliant on TLS always
1742    negotiating the strongest possible connection between two peers:
1743    there are a number of ways a man in the middle attacker can attempt
1744    to make two entities drop down to the least secure method they
1745    support. The protocol has been designed to minimize this risk, but
1746    there are still attacks available: for example, an attacker could
1747    block access to the port a secure service runs on, or attempt to get
1748    the peers to negotiate an unauthenticated connection. The fundamental
1749    rule is that higher levels must be cognizant of what their security
1750    requirements are and never transmit information over a channel less
1751    secure than what they require. The TLS protocol is secure, in that
1752    any cipher suite offers its promised level of security: if you
1753    negotiate 3DES with a 1024 bit RSA key exchange with a host whose
1754    certificate you have verified, you can expect to be that secure.
1781 Dierks & Rescorla            Standards Track                    [Page 33]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
1784    However, you SHOULD never send data over a link encrypted with 40 bit
1785    security unless you feel that data is worth no more than the effort
1786    required to break that encryption.
1788    These goals are achieved by the handshake protocol, which can be
1789    summarized as follows: The client sends a client hello message to
1790    which the server must respond with a server hello message, or else a
1791    fatal error will occur and the connection will fail. The client hello
1792    and server hello are used to establish security enhancement
1793    capabilities between client and server. The client hello and server
1794    hello establish the following attributes: Protocol Version, Session
1795    ID, Cipher Suite, and Compression Method. Additionally, two random
1796    values are generated and exchanged: ClientHello.random and
1797    ServerHello.random.
1799    The actual key exchange uses up to four messages: the server
1800    certificate, the server key exchange, the client certificate, and the
1801    client key exchange. New key exchange methods can be created by
1802    specifying a format for these messages and defining the use of the
1803    messages to allow the client and server to agree upon a shared
1804    secret. This secret MUST be quite long; currently defined key
1805    exchange methods exchange secrets which range from 48 to 128 bytes in
1806    length.
1808    Following the hello messages, the server will send its certificate,
1809    if it is to be authenticated. Additionally, a server key exchange
1810    message may be sent, if it is required (e.g. if their server has no
1811    certificate, or if its certificate is for signing only). If the
1812    server is authenticated, it may request a certificate from the
1813    client, if that is appropriate to the cipher suite selected. Now the
1814    server will send the server hello done message, indicating that the
1815    hello-message phase of the handshake is complete. The server will
1816    then wait for a client response. If the server has sent a certificate
1817    request message, the client must send the certificate message. The
1818    client key exchange message is now sent, and the content of that
1819    message will depend on the public key algorithm selected between the
1820    client hello and the server hello. If the client has sent a
1821    certificate with signing ability, a digitally-signed certificate
1822    verify message is sent to explicitly verify the certificate.
1824    At this point, a change cipher spec message is sent by the client,
1825    and the client copies the pending Cipher Spec into the current Cipher
1826    Spec. The client then immediately sends the finished message under
1827    the new algorithms, keys, and secrets. In response, the server will
1828    send its own change cipher spec message, transfer the pending to the
1829    current Cipher Spec, and send its finished message under the new
1835 Dierks & Rescorla            Standards Track                    [Page 34]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
1838    Cipher Spec. At this point, the handshake is complete and the client
1839    and server may begin to exchange application layer data. (See flow
1840    chart below.) Application data MUST NOT be sent prior to the
1841    completion of the first handshake (before a cipher suite other
1842    TLS_NULL_WITH_NULL_NULL is established).
1843       Client                                               Server
1845       ClientHello                  -------->
1846                                                       ServerHello
1847                                                      Certificate*
1848                                                ServerKeyExchange*
1849                                               CertificateRequest*
1850                                    <--------      ServerHelloDone
1851       Certificate*
1852       ClientKeyExchange
1853       CertificateVerify*
1854       [ChangeCipherSpec]
1855       Finished                     -------->
1856                                                [ChangeCipherSpec]
1857                                    <--------             Finished
1858       Application Data             <------->     Application Data
1860              Fig. 1 - Message flow for a full handshake
1862    * Indicates optional or situation-dependent messages that are not
1863    always sent.
1865   Note: To help avoid pipeline stalls, ChangeCipherSpec is an
1866        independent TLS Protocol content type, and is not actually a TLS
1867        handshake message.
1869    When the client and server decide to resume a previous session or
1870    duplicate an existing session (instead of negotiating new security
1871    parameters) the message flow is as follows:
1873    The client sends a ClientHello using the Session ID of the session to
1874    be resumed. The server then checks its session cache for a match.  If
1875    a match is found, and the server is willing to re-establish the
1876    connection under the specified session state, it will send a
1877    ServerHello with the same Session ID value. At this point, both
1878    client and server MUST send change cipher spec messages and proceed
1879    directly to finished messages. Once the re-establishment is complete,
1880    the client and server MAY begin to exchange application layer data.
1881    (See flow chart below.) If a Session ID match is not found, the
1882    server generates a new session ID and the TLS client and server
1883    perform a full handshake.
1889 Dierks & Rescorla            Standards Track                    [Page 35]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
1892       Client                                                Server
1894       ClientHello                   -------->
1895                                                        ServerHello
1896                                                 [ChangeCipherSpec]
1897                                     <--------             Finished
1898       [ChangeCipherSpec]
1899       Finished                      -------->
1900       Application Data              <------->     Application Data
1902           Fig. 2 - Message flow for an abbreviated handshake
1904    The contents and significance of each message will be presented in
1905    detail in the following sections.
1907 7.4. Handshake protocol
1909    The TLS Handshake Protocol is one of the defined higher level clients
1910    of the TLS Record Protocol. This protocol is used to negotiate the
1911    secure attributes of a session. Handshake messages are supplied to
1912    the TLS Record Layer, where they are encapsulated within one or more
1913    TLSPlaintext structures, which are processed and transmitted as
1914    specified by the current active session state.
1916        enum {
1917            hello_request(0), client_hello(1), server_hello(2),
1918            certificate(11), server_key_exchange (12),
1919            certificate_request(13), server_hello_done(14),
1920            certificate_verify(15), client_key_exchange(16),
1921            finished(20), (255)
1922        } HandshakeType;
1924        struct {
1925            HandshakeType msg_type;    /* handshake type */
1926            uint24 length;             /* bytes in message */
1927            select (HandshakeType) {
1928                case hello_request:       HelloRequest;
1929                case client_hello:        ClientHello;
1930                case server_hello:        ServerHello;
1931                case certificate:         Certificate;
1932                case server_key_exchange: ServerKeyExchange;
1933                case certificate_request: CertificateRequest;
1934                case server_hello_done:   ServerHelloDone;
1935                case certificate_verify:  CertificateVerify;
1936                case client_key_exchange: ClientKeyExchange;
1937                case finished:            Finished;
1938            } body;
1939        } Handshake;
1943 Dierks & Rescorla            Standards Track                    [Page 36]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
1946    The handshake protocol messages are presented below in the order they
1947    MUST be sent; sending handshake messages in an unexpected order
1948    results in a fatal error. Unneeded handshake messages can be omitted,
1949    however. Note one exception to the ordering: the Certificate message
1950    is used twice in the handshake (from server to client, then from
1951    client to server), but described only in its first position. The one
1952    message which is not bound by these ordering rules is the Hello
1953    Request message, which can be sent at any time, but which should be
1954    ignored by the client if it arrives in the middle of a handshake.
1956    New Handshake message type values MUST be defined via RFC 2434
1957    Standards Action. See Section 11 for IANA Considerations for these
1958    values.
1960 7.4.1. Hello messages
1962    The hello phase messages are used to exchange security enhancement
1963    capabilities between the client and server. When a new session
1964    begins, the Record Layer's connection state encryption, hash, and
1965    compression algorithms are initialized to null. The current
1966    connection state is used for renegotiation messages.
1968 7.4.1.1. Hello request
1970    When this message will be sent:
1971        The hello request message MAY be sent by the server at any time.
1973    Meaning of this message:
1974        Hello request is a simple notification that the client should
1975        begin the negotiation process anew by sending a client hello
1976        message when convenient. This message will be ignored by the
1977        client if the client is currently negotiating a session. This
1978        message may be ignored by the client if it does not wish to
1979        renegotiate a session, or the client may, if it wishes, respond
1980        with a no_renegotiation alert. Since handshake messages are
1981        intended to have transmission precedence over application data,
1982        it is expected that the negotiation will begin before no more
1983        than a few records are received from the client. If the server
1984        sends a hello request but does not receive a client hello in
1985        response, it may close the connection with a fatal alert.
1987    After sending a hello request, servers SHOULD not repeat the request
1988    until the subsequent handshake negotiation is complete.
1990    Structure of this message:
1991        struct { } HelloRequest;
1997 Dierks & Rescorla            Standards Track                    [Page 37]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
2000  Note: This message MUST NOT be included in the message hashes which are
2001        maintained throughout the handshake and used in the finished
2002        messages and the certificate verify message.
2004 7.4.1.2. Client hello
2006    When this message will be sent:
2007        When a client first connects to a server it is required to send
2008        the client hello as its first message. The client can also send a
2009        client hello in response to a hello request or on its own
2010        initiative in order to renegotiate the security parameters in an
2011        existing connection.
2013        Structure of this message:
2014            The client hello message includes a random structure, which is
2015            used later in the protocol.
2017            struct {
2018               uint32 gmt_unix_time;
2019               opaque random_bytes[28];
2020            } Random;
2022        gmt_unix_time
2023        The current time and date in standard UNIX 32-bit format (seconds
2024        since the midnight starting Jan 1, 1970, GMT) according to the
2025        sender's internal clock. Clocks are not required to be set
2026        correctly by the basic TLS Protocol; higher level or application
2027        protocols may define additional requirements.
2029    random_bytes
2030        28 bytes generated by a secure random number generator.
2032    The client hello message includes a variable length session
2033    identifier. If not empty, the value identifies a session between the
2034    same client and server whose security parameters the client wishes to
2035    reuse. The session identifier MAY be from an earlier connection, this
2036    connection, or another currently active connection. The second option
2037    is useful if the client only wishes to update the random structures
2038    and derived values of a connection, while the third option makes it
2039    possible to establish several independent secure connections without
2040    repeating the full handshake protocol. These independent connections
2041    may occur sequentially or simultaneously; a SessionID becomes valid
2042    when the handshake negotiating it completes with the exchange of
2043    Finished messages and persists until removed due to aging or because
2044    a fatal error was encountered on a connection associated with the
2045    session. The actual contents of the SessionID are defined by the
2046    server.
2051 Dierks & Rescorla            Standards Track                    [Page 38]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
2054        opaque SessionID<0..32>;
2056    Warning:
2057        Because the SessionID is transmitted without encryption or
2058        immediate MAC protection, servers MUST not place confidential
2059        information in session identifiers or let the contents of fake
2060        session identifiers cause any breach of security. (Note that the
2061        content of the handshake as a whole, including the SessionID, is
2062        protected by the Finished messages exchanged at the end of the
2063        handshake.)
2065    The CipherSuite list, passed from the client to the server in the
2066    client hello message, contains the combinations of cryptographic
2067    algorithms supported by the client in order of the client's
2068    preference (favorite choice first). Each CipherSuite defines a key
2069    exchange algorithm, a bulk encryption algorithm (including secret key
2070    length) and a MAC algorithm. The server will select a cipher suite
2071    or, if no acceptable choices are presented, return a handshake
2072    failure alert and close the connection.
2074        uint8 CipherSuite[2];    /* Cryptographic suite selector */
2076    The client hello includes a list of compression algorithms supported
2077    by the client, ordered according to the client's preference.
2079        enum { null(0), (255) } CompressionMethod;
2081        struct {
2082            ProtocolVersion client_version;
2083            Random random;
2084            SessionID session_id;
2085            CipherSuite cipher_suites<2..2^16-1>;
2086            CompressionMethod compression_methods<1..2^8-1>;
2087        } ClientHello;
2089    client_version
2090        The version of the TLS protocol by which the client wishes to
2091        communicate during this session. This SHOULD be the latest
2092        (highest valued) version supported by the client. For this
2093        version of the specification, the version will be 3.2 (See
2094        Appendix E for details about backward compatibility).
2096    random
2097        A client-generated random structure.
2099    session_id
2100        The ID of a session the client wishes to use for this connection.
2101        This field should be empty if no session_id is available or the
2105 Dierks & Rescorla            Standards Track                    [Page 39]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
2108        client wishes to generate new security parameters.
2110    cipher_suites
2111        This is a list of the cryptographic options supported by the
2112        client, with the client's first preference first. If the
2113        session_id field is not empty (implying a session resumption
2114        request) this vector MUST include at least the cipher_suite from
2115        that session. Values are defined in Appendix A.5.
2117    compression_methods
2118        This is a list of the compression methods supported by the
2119        client, sorted by client preference. If the session_id field is
2120        not empty (implying a session resumption request) it must include
2121        the compression_method from that session. This vector must
2122        contain, and all implementations must support,
2123        CompressionMethod.null. Thus, a client and server will always be
2124        able to agree on a compression method.
2126    After sending the client hello message, the client waits for a server
2127    hello message. Any other handshake message returned by the server
2128    except for a hello request is treated as a fatal error.
2130    Forward compatibility note:
2131        In the interests of forward compatibility, it is permitted for a
2132        client hello message to include extra data after the compression
2133        methods. This data MUST be included in the handshake hashes, but
2134        must otherwise be ignored. This is the only handshake message for
2135        which this is legal; for all other messages, the amount of data
2136        in the message MUST match the description of the message
2137        precisely.
2139 Note: For the intended use of trailing data in the ClientHello, see RFC
2140        3546 [TLSEXT].
2142 7.4.1.3. Server hello
2144    When this message will be sent:
2145        The server will send this message in response to a client hello
2146        message when it was able to find an acceptable set of algorithms.
2147        If it cannot find such a match, it will respond with a handshake
2148        failure alert.
2150    Structure of this message:
2151        struct {
2152            ProtocolVersion server_version;
2153            Random random;
2154            SessionID session_id;
2155            CipherSuite cipher_suite;
2159 Dierks & Rescorla            Standards Track                    [Page 40]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
2162            CompressionMethod compression_method;
2163        } ServerHello;
2165    server_version
2166        This field will contain the lower of that suggested by the client
2167        in the client hello and the highest supported by the server. For
2168        this version of the specification, the version is 3.2 (See
2169        Appendix E for details about backward compatibility).
2171    random
2172        This structure is generated by the server and MUST be
2173        independently generated from the ClientHello.random.
2175    session_id
2176        This is the identity of the session corresponding to this
2177        connection. If the ClientHello.session_id was non-empty, the
2178        server will look in its session cache for a match. If a match is
2179        found and the server is willing to establish the new connection
2180        using the specified session state, the server will respond with
2181        the same value as was supplied by the client. This indicates a
2182        resumed session and dictates that the parties must proceed
2183        directly to the finished messages. Otherwise this field will
2184        contain a different value identifying the new session. The server
2185        may return an empty session_id to indicate that the session will
2186        not be cached and therefore cannot be resumed. If a session is
2187        resumed, it must be resumed using the same cipher suite it was
2188        originally negotiated with.
2190    cipher_suite
2191        The single cipher suite selected by the server from the list in
2192        ClientHello.cipher_suites. For resumed sessions this field is the
2193        value from the state of the session being resumed.
2195    compression_method
2196        The single compression algorithm selected by the server from the
2197        list in ClientHello.compression_methods. For resumed sessions
2198        this field is the value from the resumed session state.
2200 7.4.2. Server certificate
2202    When this message will be sent:
2203        The server MUST send a certificate whenever the agreed-upon key
2204        exchange method is not an anonymous one. This message will always
2205        immediately follow the server hello message.
2207    Meaning of this message:
2208        The certificate type MUST be appropriate for the selected cipher
2209        suite's key exchange algorithm, and is generally an X.509v3
2213 Dierks & Rescorla            Standards Track                    [Page 41]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
2216        certificate. It MUST contain a key which matches the key exchange
2217        method, as follows. Unless otherwise specified, the signing
2218        algorithm for the certificate MUST be the same as the algorithm
2219        for the certificate key. Unless otherwise specified, the public
2220        key MAY be of any length.
2222        Key Exchange Algorithm  Certificate Key Type
2224        RSA                     RSA public key; the certificate MUST
2225                                allow the key to be used for encryption.
2227        DHE_DSS                 DSS public key.
2229        DHE_RSA                 RSA public key which can be used for
2230                                signing.
2232        DH_DSS                  Diffie-Hellman key. The algorithm used
2233                                to sign the certificate MUST be DSS.
2235        DH_RSA                  Diffie-Hellman key. The algorithm used
2236                                to sign the certificate MUST be RSA.
2238    All certificate profiles, key and cryptographic formats are defined
2239    by the IETF PKIX working group [PKIX]. When a key usage extension is
2240    present, the digitalSignature bit MUST be set for the key to be
2241    eligible for signing, as described above, and the keyEncipherment bit
2242    MUST be present to allow encryption, as described above. The
2243    keyAgreement bit must be set on Diffie-Hellman certificates.
2245    As CipherSuites which specify new key exchange methods are specified
2246    for the TLS Protocol, they will imply certificate format and the
2247    required encoded keying information.
2249    Structure of this message:
2250        opaque ASN.1Cert<1..2^24-1>;
2252        struct {
2253            ASN.1Cert certificate_list<0..2^24-1>;
2254        } Certificate;
2256    certificate_list
2257        This is a sequence (chain) of X.509v3 certificates. The sender's
2258        certificate must come first in the list. Each following
2259        certificate must directly certify the one preceding it. Because
2260        certificate validation requires that root keys be distributed
2261        independently, the self-signed certificate which specifies the
2262        root certificate authority may optionally be omitted from the
2263        chain, under the assumption that the remote end must already
2267 Dierks & Rescorla            Standards Track                    [Page 42]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
2270        possess it in order to validate it in any case.
2272    The same message type and structure will be used for the client's
2273    response to a certificate request message. Note that a client MAY
2274    send no certificates if it does not have an appropriate certificate
2275    to send in response to the server's authentication request.
2277  Note: PKCS #7 [PKCS7] is not used as the format for the certificate
2278        vector because PKCS #6 [PKCS6] extended certificates are not
2279        used. Also PKCS #7 defines a SET rather than a SEQUENCE, making
2280        the task of parsing the list more difficult.
2282 7.4.3. Server key exchange message
2284    When this message will be sent:
2285        This message will be sent immediately after the server
2286        certificate message (or the server hello message, if this is an
2287        anonymous negotiation).
2289        The server key exchange message is sent by the server only when
2290        the server certificate message (if sent) does not contain enough
2291        data to allow the client to exchange a premaster secret. This is
2292        true for the following key exchange methods:
2294            DHE_DSS
2295            DHE_RSA
2296            DH_anon
2298        It is not legal to send the server key exchange message for the
2299        following key exchange methods:
2301            RSA
2302            DH_DSS
2303            DH_RSA
2305    Meaning of this message:
2306        This message conveys cryptographic information to allow the
2307        client to communicate the premaster secret: either an RSA public
2308        key to encrypt the premaster secret with, or a Diffie-Hellman
2309        public key with which the client can complete a key exchange
2310        (with the result being the premaster secret.)
2312    As additional CipherSuites are defined for TLS which include new key
2313    exchange algorithms, the server key exchange message will be sent if
2314    and only if the certificate type associated with the key exchange
2315    algorithm does not provide enough information for the client to
2316    exchange a premaster secret.
2321 Dierks & Rescorla            Standards Track                    [Page 43]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
2324    Structure of this message:
2325        enum { rsa, diffie_hellman } KeyExchangeAlgorithm;
2327        struct {
2328            opaque rsa_modulus<1..2^16-1>;
2329            opaque rsa_exponent<1..2^16-1>;
2330        } ServerRSAParams;
2332        rsa_modulus
2333            The modulus of the server's temporary RSA key.
2335        rsa_exponent
2336            The public exponent of the server's temporary RSA key.
2338        struct {
2339            opaque dh_p<1..2^16-1>;
2340            opaque dh_g<1..2^16-1>;
2341            opaque dh_Ys<1..2^16-1>;
2342        } ServerDHParams;     /* Ephemeral DH parameters */
2344        dh_p
2345            The prime modulus used for the Diffie-Hellman operation.
2347        dh_g
2348            The generator used for the Diffie-Hellman operation.
2350        dh_Ys
2351            The server's Diffie-Hellman public value (g^X mod p).
2353        struct {
2354            select (KeyExchangeAlgorithm) {
2355                case diffie_hellman:
2356                    ServerDHParams params;
2357                    Signature signed_params;
2358                case rsa:
2359                    ServerRSAParams params;
2360                    Signature signed_params;
2361            };
2362        } ServerKeyExchange;
2364        struct {
2365            select (KeyExchangeAlgorithm) {
2366                case diffie_hellman:
2367                    ServerDHParams params;
2368                case rsa:
2369                    ServerRSAParams params;
2370            };
2371         } ServerParams;
2375 Dierks & Rescorla            Standards Track                    [Page 44]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
2378        params
2379            The server's key exchange parameters.
2381        signed_params
2382            For non-anonymous key exchanges, a hash of the corresponding
2383            params value, with the signature appropriate to that hash
2384            applied.
2386        md5_hash
2387            MD5(ClientHello.random + ServerHello.random + ServerParams);
2389        sha_hash
2390            SHA(ClientHello.random + ServerHello.random + ServerParams);
2392        enum { anonymous, rsa, dsa } SignatureAlgorithm;
2395        select (SignatureAlgorithm)
2396        {
2397            case anonymous: struct { };
2398            case rsa:
2399                digitally-signed struct {
2400                    opaque md5_hash[16];
2401                    opaque sha_hash[20];
2402                };
2403            case dsa:
2404                digitally-signed struct {
2405                    opaque sha_hash[20];
2406                };
2407        } Signature;
2409 7.4.4. Certificate request
2411    When this message will be sent:
2412        A non-anonymous server can optionally request a certificate from
2413        the client, if appropriate for the selected cipher suite. This
2414        message, if sent, will immediately follow the Server Key Exchange
2415        message (if it is sent; otherwise, the Server Certificate
2416        message).
2418    Structure of this message:
2419        enum {
2420            rsa_sign(1), dss_sign(2), rsa_fixed_dh(3), dss_fixed_dh(4),
2421         rsa_ephemeral_dh_RESERVED(5), dss_ephemeral_dh_RESERVED(6),
2422         fortezza_dms_RESERVED(20),
2423            (255)
2424        } ClientCertificateType;
2429 Dierks & Rescorla            Standards Track                    [Page 45]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
2432        opaque DistinguishedName<1..2^16-1>;
2434        struct {
2435            ClientCertificateType certificate_types<1..2^8-1>;
2436            DistinguishedName certificate_authorities<0..2^16-1>;
2437        } CertificateRequest;
2439        certificate_types
2440            This field is a list of the types of certificates requested,
2441            sorted in order of the server's preference.
2443        certificate_authorities
2444            A list of the distinguished names of acceptable certificate
2445            authorities. These distinguished names may specify a desired
2446            distinguished name for a root CA or for a subordinate CA;
2447            thus, this message can be used both to describe known roots
2448            and a desired authorization space. If the
2449            certificate_authorities list is empty then the client MAY
2450            send any certificate of the appropriate
2451            ClientCertificateType, unless there is some external
2452            arrangement to the contrary.
2455  ClientCertificateType values are divided into three groups:
2457               1. Values from 0 (zero) through 63 decimal (0x3F) inclusive are
2458                  reserved for IETF Standards Track protocols.
2460               2. Values from 64 decimal (0x40) through 223 decimal (0xDF) inclusive
2461                  are reserved for assignment for non-Standards Track methods.
2463               3. Values from 224 decimal (0xE0) through 255 decimal (0xFF)
2464                  inclusive are reserved for private use.
2466            Additional information describing the role of IANA in the
2467            allocation of ClientCertificateType code points is described
2468            in Section 11.
2470            Note: Values listed as RESERVED may not be used. They were used in SSLv3.
2472  Note: DistinguishedName is derived from [X509]. DistinguishedNames are
2473            represented in DER-encoded format.
2475  Note: It is a fatal handshake_failure alert for an anonymous server to
2476        request client authentication.
2478 7.4.5. Server hello done
2483 Dierks & Rescorla            Standards Track                    [Page 46]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
2486    When this message will be sent:
2487        The server hello done message is sent by the server to indicate
2488        the end of the server hello and associated messages. After
2489        sending this message the server will wait for a client response.
2491    Meaning of this message:
2492        This message means that the server is done sending messages to
2493        support the key exchange, and the client can proceed with its
2494        phase of the key exchange.
2496        Upon receipt of the server hello done message the client SHOULD
2497        verify that the server provided a valid certificate if required
2498        and check that the server hello parameters are acceptable.
2500    Structure of this message:
2501        struct { } ServerHelloDone;
2503 7.4.6. Client certificate
2505    When this message will be sent:
2506        This is the first message the client can send after receiving a
2507        server hello done message. This message is only sent if the
2508        server requests a certificate. If no suitable certificate is
2509        available, the client should send a certificate message
2510        containing no certificates: I.e. the certificate_list structure
2511        should have a length of zero. If client authentication is
2512        required by the server for the handshake to continue, it may
2513        respond with a fatal handshake failure alert. Client certificates
2514        are sent using the Certificate structure defined in Section
2515        7.4.2.
2518  Note: When using a static Diffie-Hellman based key exchange method
2519        (DH_DSS or DH_RSA), if client authentication is requested, the
2520        Diffie-Hellman group and generator encoded in the client's
2521        certificate must match the server specified Diffie-Hellman
2522        parameters if the client's parameters are to be used for the key
2523        exchange.
2525 7.4.7. Client key exchange message
2527    When this message will be sent:
2528        This message is always sent by the client. It will immediately
2529        follow the client certificate message, if it is sent. Otherwise
2530        it will be the first message sent by the client after it receives
2531        the server hello done message.
2533    Meaning of this message:
2537 Dierks & Rescorla            Standards Track                    [Page 47]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
2540        With this message, the premaster secret is set, either though
2541        direct transmission of the RSA-encrypted secret, or by the
2542        transmission of Diffie-Hellman parameters which will allow each
2543        side to agree upon the same premaster secret. When the key
2544        exchange method is DH_RSA or DH_DSS, client certification has
2545        been requested, and the client was able to respond with a
2546        certificate which contained a Diffie-Hellman public key whose
2547        parameters (group and generator) matched those specified by the
2548        server in its certificate, this message MUST not contain any
2549        data.
2551    Structure of this message:
2552        The choice of messages depends on which key exchange method has
2553        been selected. See Section 7.4.3 for the KeyExchangeAlgorithm
2554        definition.
2556        struct {
2557            select (KeyExchangeAlgorithm) {
2558                case rsa: EncryptedPreMasterSecret;
2559                case diffie_hellman: ClientDiffieHellmanPublic;
2560            } exchange_keys;
2561        } ClientKeyExchange;
2563 7.4.7.1. RSA encrypted premaster secret message
2565    Meaning of this message:
2566        If RSA is being used for key agreement and authentication, the
2567        client generates a 48-byte premaster secret, encrypts it using
2568        the public key from the server's certificate or the temporary RSA
2569        key provided in a server key exchange message, and sends the
2570        result in an encrypted premaster secret message. This structure
2571        is a variant of the client key exchange message, not a message in
2572        itself.
2574    Structure of this message:
2575        struct {
2576            ProtocolVersion client_version;
2577            opaque random[46];
2578        } PreMasterSecret;
2580        client_version
2581            The latest (newest) version supported by the client. This is
2582            used to detect version roll-back attacks. Upon receiving the
2583            premaster secret, the server SHOULD check that this value
2584            matches the value transmitted by the client in the client
2585            hello message.
2587        random
2591 Dierks & Rescorla            Standards Track                    [Page 48]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
2594            46 securely-generated random bytes.
2596        struct {
2597            public-key-encrypted PreMasterSecret pre_master_secret;
2598        } EncryptedPreMasterSecret;
2600        pre_master_secret
2601            This random value is generated by the client and is used to
2602            generate the master secret, as specified in Section 8.1.
2604  Note: An attack discovered by Daniel Bleichenbacher [BLEI] can be used
2605        to attack a TLS server which is using PKCS#1 encoded RSA. The
2606        attack takes advantage of the fact that by failing in different
2607        ways, a TLS server can be coerced into revealing whether a
2608        particular message, when decrypted, is properly PKCS#1 formatted
2609        or not.
2611        The best way to avoid vulnerability to this attack is to treat
2612        incorrectly formatted messages in a manner indistinguishable from
2613        correctly formatted RSA blocks. Thus, when it receives an
2614        incorrectly formatted RSA block, a server should generate a
2615        random 48-byte value and proceed using it as the premaster
2616        secret. Thus, the server will act identically whether the
2617        received RSA block is correctly encoded or not.
2619  Implementation Note: public-key-encrypted data is represented as an
2620        opaque vector <0..2^16-1> (see S. 4.7). Thus the RSA-encrypted
2621        PreMaster Secret in a ClientKeyExchange is preceded by two length
2622        bytes. These bytes are redundant in the case of RSA because the
2623        EncryptedPreMasterSecret is the only data in the
2624        ClientKeyExchange and its length can therefore be unambiguously
2625        determined. The SSLv3 specification was not clear about the
2626        encoding of public-key-encrypted data and therefore many SSLv3
2627        implementations do not include the the length bytes, encoding the
2628        RSA encrypted data directly in the ClientKeyExchange message.
2630        This specification requires correct encoding of the
2631        EncryptedPreMasterSecret complete with length bytes. The
2632        resulting PDU is incompatible with many SSLv3 implementations.
2633        Implementors upgrading from SSLv3 must modify their
2634        implementations to generate and accept the correct encoding.
2635        Implementors who wish to be compatible with both SSLv3 and TLS
2636        should make their implementation's behavior dependent on the
2637        protocol version.
2639  Implementation Note: It is now known that remote timing-based attacks
2640        on SSL are possible, at least when the client and server are on
2641        the same LAN. Accordingly, implementations which use static RSA
2645 Dierks & Rescorla            Standards Track                    [Page 49]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
2648        keys SHOULD use RSA blinding or some other anti-timing technique,
2649        as described in [TIMING].
2651  Note: The version number in the PreMasterSecret is that offered by the
2652        client, NOT the version negotiated for the connection. This
2653        feature is designed to prevent rollback attacks. Unfortunately,
2654        many implementations use the negotiated version instead and
2655        therefore checking the version number may lead to failure to
2656        interoperate with such incorrect client implementations. Client
2657        implementations MUST and Server implementations MAY check the
2658        version number. In practice, since there are no significant known
2659        security differences between TLS and SSLv3, rollback to SSLv3 is
2660        not believed to be a serious security risk.  Note that if servers
2661        choose to to check the version number, they should randomize the
2662        PreMasterSecret in case of error, rather than generate an alert,
2663        in order to avoid variants on the Bleichenbacher attack. [KPR03]
2665 7.4.7.2. Client Diffie-Hellman public value
2667    Meaning of this message:
2668        This structure conveys the client's Diffie-Hellman public value
2669        (Yc) if it was not already included in the client's certificate.
2670        The encoding used for Yc is determined by the enumerated
2671        PublicValueEncoding. This structure is a variant of the client
2672        key exchange message, not a message in itself.
2674    Structure of this message:
2675        enum { implicit, explicit } PublicValueEncoding;
2677        implicit
2678            If the client certificate already contains a suitable Diffie-
2679            Hellman key, then Yc is implicit and does not need to be sent
2680            again. In this case, the Client Key Exchange message will be
2681            sent, but will be empty.
2683        explicit
2684            Yc needs to be sent.
2686        struct {
2687            select (PublicValueEncoding) {
2688                case implicit: struct { };
2689                case explicit: opaque dh_Yc<1..2^16-1>;
2690            } dh_public;
2691        } ClientDiffieHellmanPublic;
2693        dh_Yc
2694            The client's Diffie-Hellman public value (Yc).
2699 Dierks & Rescorla            Standards Track                    [Page 50]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
2702 7.4.8. Certificate verify
2704    When this message will be sent:
2705        This message is used to provide explicit verification of a client
2706        certificate. This message is only sent following a client
2707        certificate that has signing capability (i.e. all certificates
2708        except those containing fixed Diffie-Hellman parameters). When
2709        sent, it will immediately follow the client key exchange message.
2711    Structure of this message:
2712        struct {
2713             Signature signature;
2714        } CertificateVerify;
2716        The Signature type is defined in 7.4.3.
2718        CertificateVerify.signature.md5_hash
2719            MD5(handshake_messages);
2721        CertificateVerify.signature.sha_hash
2722            SHA(handshake_messages);
2724    Here handshake_messages refers to all handshake messages sent or
2725    received starting at client hello up to but not including this
2726    message, including the type and length fields of the handshake
2727    messages. This is the concatenation of all the Handshake structures
2728    as defined in 7.4 exchanged thus far.
2730 7.4.9. Finished
2732    When this message will be sent:
2733        A finished message is always sent immediately after a change
2734        cipher spec message to verify that the key exchange and
2735        authentication processes were successful. It is essential that a
2736        change cipher spec message be received between the other
2737        handshake messages and the Finished message.
2739    Meaning of this message:
2740        The finished message is the first protected with the just-
2741        negotiated algorithms, keys, and secrets. Recipients of finished
2742        messages MUST verify that the contents are correct.  Once a side
2743        has sent its Finished message and received and validated the
2744        Finished message from its peer, it may begin to send and receive
2745        application data over the connection.
2747        struct {
2748            opaque verify_data[12];
2749        } Finished;
2753 Dierks & Rescorla            Standards Track                    [Page 51]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
2756        verify_data
2757            PRF(master_secret, finished_label, MD5(handshake_messages) +
2758            SHA-1(handshake_messages)) [0..11];
2760        finished_label
2761            For Finished messages sent by the client, the string "client
2762            finished". For Finished messages sent by the server, the
2763            string "server finished".
2765        handshake_messages
2766            All of the data from all messages in this handshake (not
2767            including any HelloRequest messages) up to but not including
2768            this message. This is only data visible at the handshake
2769            layer and does not include record layer headers.  This is the
2770            concatenation of all the Handshake structures as defined in
2771            7.4 exchanged thus far.
2773    It is a fatal error if a finished message is not preceded by a change
2774    cipher spec message at the appropriate point in the handshake.
2776    The value handshake_messages includes all handshake messages starting
2777    at client hello up to, but not including, this finished message. This
2778    may be different from handshake_messages in Section 7.4.8 because it
2779    would include the certificate verify message (if sent). Also, the
2780    handshake_messages for the finished message sent by the client will
2781    be different from that for the finished message sent by the server,
2782    because the one which is sent second will include the prior one.
2784  Note: Change cipher spec messages, alerts and any other record types
2785        are not handshake messages and are not included in the hash
2786        computations. Also, Hello Request messages are omitted from
2787        handshake hashes.
2789 8. Cryptographic computations
2791    In order to begin connection protection, the TLS Record Protocol
2792    requires specification of a suite of algorithms, a master secret, and
2793    the client and server random values. The authentication, encryption,
2794    and MAC algorithms are determined by the cipher_suite selected by the
2795    server and revealed in the server hello message. The compression
2796    algorithm is negotiated in the hello messages, and the random values
2797    are exchanged in the hello messages. All that remains is to calculate
2798    the master secret.
2800 8.1. Computing the master secret
2802    For all key exchange methods, the same algorithm is used to convert
2803    the pre_master_secret into the master_secret. The pre_master_secret
2807 Dierks & Rescorla            Standards Track                    [Page 52]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
2810    should be deleted from memory once the master_secret has been
2811    computed.
2813        master_secret = PRF(pre_master_secret, "master secret",
2814                            ClientHello.random + ServerHello.random)
2815        [0..47];
2817    The master secret is always exactly 48 bytes in length. The length of
2818    the premaster secret will vary depending on key exchange method.
2861 Dierks & Rescorla            Standards Track                    [Page 53]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
2864 8.1.1. RSA
2866    When RSA is used for server authentication and key exchange, a
2867    48-byte pre_master_secret is generated by the client, encrypted under
2868    the server's public key, and sent to the server. The server uses its
2869    private key to decrypt the pre_master_secret. Both parties then
2870    convert the pre_master_secret into the master_secret, as specified
2871    above.
2873    RSA digital signatures are performed using PKCS #1 [PKCS1] block type
2874    1. RSA public key encryption is performed using PKCS #1 block type 2.
2876 8.1.2. Diffie-Hellman
2878    A conventional Diffie-Hellman computation is performed. The
2879    negotiated key (Z) is used as the pre_master_secret, and is converted
2880    into the master_secret, as specified above.  Leading 0 bytes of Z are
2881    stripped before it is used as the pre_master_secret.
2883  Note: Diffie-Hellman parameters are specified by the server, and may
2884        be either ephemeral or contained within the server's certificate.
2886 9. Mandatory Cipher Suites
2888    In the absence of an application profile standard specifying
2889    otherwise, a TLS compliant application MUST implement the cipher
2890    suite TLS_RSA_WITH_3DES_EDE_CBC_SHA.
2892 10. Application data protocol
2894    Application data messages are carried by the Record Layer and are
2895    fragmented, compressed and encrypted based on the current connection
2896    state. The messages are treated as transparent data to the record
2897    layer.
2899 10. IANA Considerations
2901    Section 7.4.3 describes a TLS ClientCertificateType Registry to be
2902    maintained by the IANA, as defining a number of such code point
2903    identifiers. ClientCertificateType identifiers with values in the
2904    range 0-63 (decimal) inclusive are assigned via RFC 2434 Standards
2905    Action. Values from the range 64-223 (decimal) inclusive are assigned
2906    via [RFC 2434] Specification Required.  Identifier values from
2907    224-255 (decimal) inclusive are reserved for RFC 2434 Private Use.
2908    The registry will be initially populated with the values in this
2909    document.
2911    Section A.5 describes a TLS Cipher Suite Registry to be maintained by
2915 Dierks & Rescorla            Standards Track                    [Page 54]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
2918    the IANA, as well as defining a number of such cipher suite
2919    identifiers. Cipher suite values with the first byte in the range
2920    0-191 (decimal) inclusive are assigned via RFC 2434 Standards Action.
2921    Values with the first byte in the range 192-254 (decimal) are
2922    assigned via RFC 2434 Specification Required. Values with the first
2923    byte 255 (decimal) are reserved for RFC 2434 Private Use. The
2924    registry will be initially populated with the values from this
2925    document, [TLSAES], and [TLSKRB].
2927    Section 6 requires that all ContentType values be defined by RFC 2434
2928    Standards Action. IANA SHOULD create a TLS ContentType registry,
2929    initially populated with values from this document. Future values
2930    MUST be allocated via Standards Action as described in [RFC 2434].
2932    Section 7.2.2 requires that all Alert values be defined by RFC 2434
2933    Standards Action. IANA SHOULD create a TLS Alert registry, initially
2934    populated with values from this document and [TLSEXT]. Future values
2935    MUST be allocated via Standards Action as described in [RFC 2434].
2937    Section 7.4 requires that all HandshakeType values be defined by RFC
2938    2434 Standards Action. IANA SHOULD create a TLS HandshakeType
2939    registry, initially populated with values from this document,
2940    [TLSEXT], and [TLSKRB].  Future values MUST be allocated via
2941    Standards Action as described in [RFC 2434].
2969 Dierks & Rescorla            Standards Track                    [Page 55]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
2972 A. Protocol constant values
2974    This section describes protocol types and constants.
2976 A.1. Record layer
2978     struct {
2979         uint8 major, minor;
2980     } ProtocolVersion;
2982     ProtocolVersion version = { 3, 2 };     /* TLS v1.1 */
2984     enum {
2985         change_cipher_spec(20), alert(21), handshake(22),
2986         application_data(23), (255)
2987     } ContentType;
2989     struct {
2990         ContentType type;
2991         ProtocolVersion version;
2992         uint16 length;
2993         opaque fragment[TLSPlaintext.length];
2994     } TLSPlaintext;
2996     struct {
2997         ContentType type;
2998         ProtocolVersion version;
2999         uint16 length;
3000         opaque fragment[TLSCompressed.length];
3001     } TLSCompressed;
3003     struct {
3004         ContentType type;
3005         ProtocolVersion version;
3006         uint16 length;
3007         select (CipherSpec.cipher_type) {
3008             case stream: GenericStreamCipher;
3009             case block:  GenericBlockCipher;
3010         } fragment;
3011     } TLSCiphertext;
3013     stream-ciphered struct {
3014         opaque content[TLSCompressed.length];
3015         opaque MAC[CipherSpec.hash_size];
3016     } GenericStreamCipher;
3018     block-ciphered struct {
3019         opaque IV[CipherSpec.block_length];
3023 Dierks & Rescorla            Standards Track                    [Page 56]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
3026         opaque content[TLSCompressed.length];
3027         opaque MAC[CipherSpec.hash_size];
3028         uint8 padding[GenericBlockCipher.padding_length];
3029         uint8 padding_length;
3030     } GenericBlockCipher;
3032 A.2. Change cipher specs message
3034     struct {
3035         enum { change_cipher_spec(1), (255) } type;
3036     } ChangeCipherSpec;
3038 A.3. Alert messages
3040     enum { warning(1), fatal(2), (255) } AlertLevel;
3042         enum {
3043             close_notify(0),
3044             unexpected_message(10),
3045             bad_record_mac(20),
3046             decryption_failed(21),
3047             record_overflow(22),
3048             decompression_failure(30),
3049             handshake_failure(40),
3050             no_certificate_RESERVED (41),
3051             bad_certificate(42),
3052             unsupported_certificate(43),
3053             certificate_revoked(44),
3054             certificate_expired(45),
3055             certificate_unknown(46),
3056             illegal_parameter(47),
3057             unknown_ca(48),
3058             access_denied(49),
3059             decode_error(50),
3060             decrypt_error(51),
3061             export_restriction_RESERVED(60),
3062             protocol_version(70),
3063             insufficient_security(71),
3064             internal_error(80),
3065             user_canceled(90),
3066             no_renegotiation(100),
3067             (255)
3068         } AlertDescription;
3070     struct {
3071         AlertLevel level;
3072         AlertDescription description;
3073     } Alert;
3077 Dierks & Rescorla            Standards Track                    [Page 57]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
3080 A.4. Handshake protocol
3082     enum {
3083         hello_request(0), client_hello(1), server_hello(2),
3084         certificate(11), server_key_exchange (12),
3085         certificate_request(13), server_hello_done(14),
3086         certificate_verify(15), client_key_exchange(16),
3087         finished(20), (255)
3088     } HandshakeType;
3090     struct {
3091         HandshakeType msg_type;
3092         uint24 length;
3093         select (HandshakeType) {
3094             case hello_request:       HelloRequest;
3095             case client_hello:        ClientHello;
3096             case server_hello:        ServerHello;
3097             case certificate:         Certificate;
3098             case server_key_exchange: ServerKeyExchange;
3099             case certificate_request: CertificateRequest;
3100             case server_hello_done:   ServerHelloDone;
3101             case certificate_verify:  CertificateVerify;
3102             case client_key_exchange: ClientKeyExchange;
3103             case finished:            Finished;
3104         } body;
3105     } Handshake;
3107 A.4.1. Hello messages
3109     struct { } HelloRequest;
3111     struct {
3112         uint32 gmt_unix_time;
3113         opaque random_bytes[28];
3114     } Random;
3116     opaque SessionID<0..32>;
3118     uint8 CipherSuite[2];
3120     enum { null(0), (255) } CompressionMethod;
3122     struct {
3123         ProtocolVersion client_version;
3124         Random random;
3125         SessionID session_id;
3126         CipherSuite cipher_suites<2..2^16-1>;
3127         CompressionMethod compression_methods<1..2^8-1>;
3131 Dierks & Rescorla            Standards Track                    [Page 58]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
3134     } ClientHello;
3136     struct {
3137         ProtocolVersion server_version;
3138         Random random;
3139         SessionID session_id;
3140         CipherSuite cipher_suite;
3141         CompressionMethod compression_method;
3142     } ServerHello;
3144 A.4.2. Server authentication and key exchange messages
3146     opaque ASN.1Cert<2^24-1>;
3148     struct {
3149         ASN.1Cert certificate_list<0..2^24-1>;
3150     } Certificate;
3152     enum { rsa, diffie_hellman } KeyExchangeAlgorithm;
3154     struct {
3155         opaque RSA_modulus<1..2^16-1>;
3156         opaque RSA_exponent<1..2^16-1>;
3157     } ServerRSAParams;
3159     struct {
3160         opaque DH_p<1..2^16-1>;
3161         opaque DH_g<1..2^16-1>;
3162         opaque DH_Ys<1..2^16-1>;
3163     } ServerDHParams;
3165     struct {
3166         select (KeyExchangeAlgorithm) {
3167             case diffie_hellman:
3168                 ServerDHParams params;
3169                 Signature signed_params;
3170             case rsa:
3171                 ServerRSAParams params;
3172                 Signature signed_params;
3173         };
3174     } ServerKeyExchange;
3176     enum { anonymous, rsa, dsa } SignatureAlgorithm;
3178     struct {
3179         select (KeyExchangeAlgorithm) {
3180             case diffie_hellman:
3181                 ServerDHParams params;
3185 Dierks & Rescorla            Standards Track                    [Page 59]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
3188             case rsa:
3189                 ServerRSAParams params;
3190         };
3191      } ServerParams;
3193     select (SignatureAlgorithm)
3194     {   case anonymous: struct { };
3195         case rsa:
3196             digitally-signed struct {
3197                 opaque md5_hash[16];
3198                 opaque sha_hash[20];
3199             };
3200         case dsa:
3201             digitally-signed struct {
3202                 opaque sha_hash[20];
3203             };
3204     } Signature;
3206     enum {
3207         rsa_sign(1), dss_sign(2), rsa_fixed_dh(3), dss_fixed_dh(4),
3208      rsa_ephemeral_dh_RESERVED(5), dss_ephemeral_dh_RESERVED(6),
3209      fortezza_dms_RESERVED(20),
3210      (255)
3211     } ClientCertificateType;
3213     opaque DistinguishedName<1..2^16-1>;
3215     struct {
3216         ClientCertificateType certificate_types<1..2^8-1>;
3217         DistinguishedName certificate_authorities<0..2^16-1>;
3218     } CertificateRequest;
3220     struct { } ServerHelloDone;
3222 A.4.3. Client authentication and key exchange messages
3224     struct {
3225         select (KeyExchangeAlgorithm) {
3226             case rsa: EncryptedPreMasterSecret;
3227             case diffie_hellman: DiffieHellmanClientPublicValue;
3228         } exchange_keys;
3229     } ClientKeyExchange;
3231     struct {
3232         ProtocolVersion client_version;
3233         opaque random[46];
3234     } PreMasterSecret;
3239 Dierks & Rescorla            Standards Track                    [Page 60]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
3242     struct {
3243         public-key-encrypted PreMasterSecret pre_master_secret;
3244     } EncryptedPreMasterSecret;
3246     enum { implicit, explicit } PublicValueEncoding;
3248     struct {
3249         select (PublicValueEncoding) {
3250             case implicit: struct {};
3251             case explicit: opaque DH_Yc<1..2^16-1>;
3252         } dh_public;
3253     } ClientDiffieHellmanPublic;
3255     struct {
3256         Signature signature;
3257     } CertificateVerify;
3259 A.4.4. Handshake finalization message
3261     struct {
3262         opaque verify_data[12];
3263     } Finished;
3265 A.5. The CipherSuite
3267    The following values define the CipherSuite codes used in the client
3268    hello and server hello messages.
3270    A CipherSuite defines a cipher specification supported in TLS Version
3271    1.1.
3273    TLS_NULL_WITH_NULL_NULL is specified and is the initial state of a
3274    TLS connection during the first handshake on that channel, but must
3275    not be negotiated, as it provides no more protection than an
3276    unsecured connection.
3278     CipherSuite TLS_NULL_WITH_NULL_NULL                = { 0x00,0x00 };
3280    The following CipherSuite definitions require that the server provide
3281    an RSA certificate that can be used for key exchange. The server may
3282    request either an RSA or a DSS signature-capable certificate in the
3283    certificate request message.
3285     CipherSuite TLS_RSA_WITH_NULL_MD5                  = { 0x00,0x01 };
3286     CipherSuite TLS_RSA_WITH_NULL_SHA                  = { 0x00,0x02 };
3287     CipherSuite TLS_RSA_WITH_RC4_128_MD5               = { 0x00,0x04 };
3288     CipherSuite TLS_RSA_WITH_RC4_128_SHA               = { 0x00,0x05 };
3289     CipherSuite TLS_RSA_WITH_IDEA_CBC_SHA              = { 0x00,0x07 };
3293 Dierks & Rescorla            Standards Track                    [Page 61]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
3296     CipherSuite TLS_RSA_WITH_DES_CBC_SHA               = { 0x00,0x09 };
3297     CipherSuite TLS_RSA_WITH_3DES_EDE_CBC_SHA          = { 0x00,0x0A };
3299    The following CipherSuite definitions are used for server-
3300    authenticated (and optionally client-authenticated) Diffie-Hellman.
3301    DH denotes cipher suites in which the server's certificate contains
3302    the Diffie-Hellman parameters signed by the certificate authority
3303    (CA). DHE denotes ephemeral Diffie-Hellman, where the Diffie-Hellman
3304    parameters are signed by a DSS or RSA certificate, which has been
3305    signed by the CA. The signing algorithm used is specified after the
3306    DH or DHE parameter. The server can request an RSA or DSS signature-
3307    capable certificate from the client for client authentication or it
3308    may request a Diffie-Hellman certificate. Any Diffie-Hellman
3309    certificate provided by the client must use the parameters (group and
3310    generator) described by the server.
3312     CipherSuite TLS_DH_DSS_WITH_DES_CBC_SHA            = { 0x00,0x0C };
3313     CipherSuite TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA       = { 0x00,0x0D };
3314     CipherSuite TLS_DH_RSA_WITH_DES_CBC_SHA            = { 0x00,0x0F };
3315     CipherSuite TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA       = { 0x00,0x10 };
3316     CipherSuite TLS_DHE_DSS_WITH_DES_CBC_SHA           = { 0x00,0x12 };
3317     CipherSuite TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA      = { 0x00,0x13 };
3318     CipherSuite TLS_DHE_RSA_WITH_DES_CBC_SHA           = { 0x00,0x15 };
3319     CipherSuite TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA      = { 0x00,0x16 };
3321    The following cipher suites are used for completely anonymous Diffie-
3322    Hellman communications in which neither party is authenticated. Note
3323    that this mode is vulnerable to man-in-the-middle attacks and is
3324    therefore deprecated.
3326     CipherSuite TLS_DH_anon_WITH_RC4_128_MD5           = { 0x00,0x18 };
3327     CipherSuite TLS_DH_anon_WITH_DES_CBC_SHA           = { 0x00,0x1A };
3328     CipherSuite TLS_DH_anon_WITH_3DES_EDE_CBC_SHA      = { 0x00,0x1B };
3330    When SSLv3 and TLS 1.0 were designed, the United States restricted
3331    the export of cryptographic software containing certain strong
3332    encryption algorithms. A series of cipher suites were designed to
3333    operate at reduced key lengths in order to comply with those
3334    regulations. Due to advances in computer performance, these
3335    algorithms are now unacceptably weak and export restrictions have
3336    since been loosened. TLS 1.1 implementations MUST NOT negotiate these
3337    cipher suites in TLS 1.1 mode. However, for backward compatibility
3338    they may be offered in the ClientHello for use with TLS 1.0 or SSLv3
3339    only servers. TLS 1.1 clients MUST check that the server did not
3340    choose one of these cipher suites during the handshake. These
3341    ciphersuites are listed below for informational purposes and to
3342    reserve the numbers.
3347 Dierks & Rescorla            Standards Track                    [Page 62]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
3350     CipherSuite TLS_RSA_EXPORT_WITH_RC4_40_MD5         = { 0x00,0x03 };
3351     CipherSuite TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5     = { 0x00,0x06 };
3352     CipherSuite TLS_RSA_EXPORT_WITH_DES40_CBC_SHA      = { 0x00,0x08 };
3353     CipherSuite TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA   = { 0x00,0x0B };
3354     CipherSuite TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA   = { 0x00,0x0E };
3355     CipherSuite TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA  = { 0x00,0x11 };
3356     CipherSuite TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA  = { 0x00,0x14 };
3357     CipherSuite TLS_DH_anon_EXPORT_WITH_RC4_40_MD5     = { 0x00,0x17 };
3358     CipherSuite TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA  = { 0x00,0x19 };
3360    The following cipher suites were defined in [TLSKRB] and are included
3361    here for completeness. See [TLSKRB] for details:
3363     CipherSuite      TLS_KRB5_WITH_DES_CBC_SHA            = { 0x00,0x1E };
3364     CipherSuite      TLS_KRB5_WITH_3DES_EDE_CBC_SHA       = { 0x00,0x1F };
3365     CipherSuite      TLS_KRB5_WITH_RC4_128_SHA            = { 0x00,0x20 };
3366     CipherSuite      TLS_KRB5_WITH_IDEA_CBC_SHA           = { 0x00,0x21 };
3367     CipherSuite      TLS_KRB5_WITH_DES_CBC_MD5            = { 0x00,0x22 };
3368     CipherSuite      TLS_KRB5_WITH_3DES_EDE_CBC_MD5       = { 0x00,0x23 };
3369     CipherSuite      TLS_KRB5_WITH_RC4_128_MD5            = { 0x00,0x24 };
3370     CipherSuite      TLS_KRB5_WITH_IDEA_CBC_MD5           = { 0x00,0x25 };
3372    The following exportable cipher suites were defined in [TLSKRB] and
3373    are included here for completeness. TLS 1.1 implementations MUST NOT
3374    negotiate these cipher suites.
3376     CipherSuite      TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA  = { 0x00,0x26
3377    };
3378     CipherSuite      TLS_KRB5_EXPORT_WITH_RC2_CBC_40_SHA  = { 0x00,0x27
3379    };
3380     CipherSuite      TLS_KRB5_EXPORT_WITH_RC4_40_SHA      = { 0x00,0x28
3381    };
3382     CipherSuite      TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5  = { 0x00,0x29
3383    };
3384     CipherSuite      TLS_KRB5_EXPORT_WITH_RC2_CBC_40_MD5  = { 0x00,0x2A
3385    };
3386     CipherSuite      TLS_KRB5_EXPORT_WITH_RC4_40_MD5      = { 0x00,0x2B
3387    };
3389    The following cipher suites were defined in [TLSAES] and are included
3390    here for completeness. See [TLSAES] for details:
3392       CipherSuite TLS_RSA_WITH_AES_128_CBC_SHA      = { 0x00, 0x2F };
3393       CipherSuite TLS_DH_DSS_WITH_AES_128_CBC_SHA   = { 0x00, 0x30 };
3394       CipherSuite TLS_DH_RSA_WITH_AES_128_CBC_SHA   = { 0x00, 0x31 };
3395       CipherSuite TLS_DHE_DSS_WITH_AES_128_CBC_SHA  = { 0x00, 0x32 };
3396       CipherSuite TLS_DHE_RSA_WITH_AES_128_CBC_SHA  = { 0x00, 0x33 };
3397       CipherSuite TLS_DH_anon_WITH_AES_128_CBC_SHA  = { 0x00, 0x34 };
3401 Dierks & Rescorla            Standards Track                    [Page 63]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
3404       CipherSuite TLS_RSA_WITH_AES_256_CBC_SHA      = { 0x00, 0x35 };
3405       CipherSuite TLS_DH_DSS_WITH_AES_256_CBC_SHA   = { 0x00, 0x36 };
3406       CipherSuite TLS_DH_RSA_WITH_AES_256_CBC_SHA   = { 0x00, 0x37 };
3407       CipherSuite TLS_DHE_DSS_WITH_AES_256_CBC_SHA  = { 0x00, 0x38 };
3408       CipherSuite TLS_DHE_RSA_WITH_AES_256_CBC_SHA  = { 0x00, 0x39 };
3409       CipherSuite TLS_DH_anon_WITH_AES_256_CBC_SHA  = { 0x00, 0x3A };
3411  The cipher suite space is divided into three regions:
3413        1. Cipher suite values with first byte 0x00 (zero)
3414           through decimal 191 (0xBF) inclusive are reserved for the IETF
3415           Standards Track protocols.
3417        2. Cipher suite values with first byte decimal 192 (0xC0)
3418           through decimal 254 (0xFE) inclusive are reserved
3419           for assignment for non-Standards Track methods.
3421        3. Cipher suite values with first byte 0xFF are
3422           reserved for private use.
3423    Additional information describing the role of IANA in the allocation
3424    of cipher suite code points is described in Section 11.
3426  Note: The cipher suite values { 0x00, 0x1C } and { 0x00, 0x1D } are
3427    reserved to avoid collision with Fortezza-based cipher suites in SSL
3428    3.
3430 A.6. The Security Parameters
3432    These security parameters are determined by the TLS Handshake
3433    Protocol and provided as parameters to the TLS Record Layer in order
3434    to initialize a connection state. SecurityParameters includes:
3436        enum { null(0), (255) } CompressionMethod;
3438        enum { server, client } ConnectionEnd;
3440        enum { null, rc4, rc2, des, 3des, des40, idea }
3441        BulkCipherAlgorithm;
3443        enum { stream, block } CipherType;
3445        enum { null, md5, sha } MACAlgorithm;
3447    /* The algorithms specified in CompressionMethod,
3448    BulkCipherAlgorithm, and MACAlgorithm may be added to. */
3450        struct {
3451            ConnectionEnd entity;
3455 Dierks & Rescorla            Standards Track                    [Page 64]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
3458            BulkCipherAlgorithm bulk_cipher_algorithm;
3459            CipherType cipher_type;
3460            uint8 key_size;
3461            uint8 key_material_length;
3462            MACAlgorithm mac_algorithm;
3463            uint8 hash_size;
3464            CompressionMethod compression_algorithm;
3465            opaque master_secret[48];
3466            opaque client_random[32];
3467            opaque server_random[32];
3468        } SecurityParameters;
3509 Dierks & Rescorla            Standards Track                    [Page 65]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
3512 B. Glossary
3514    application protocol
3515        An application protocol is a protocol that normally layers
3516        directly on top of the transport layer (e.g., TCP/IP). Examples
3517        include HTTP, TELNET, FTP, and SMTP.
3519    asymmetric cipher
3520        See public key cryptography.
3522    authentication
3523        Authentication is the ability of one entity to determine the
3524        identity of another entity.
3526    block cipher
3527        A block cipher is an algorithm that operates on plaintext in
3528        groups of bits, called blocks. 64 bits is a common block size.
3530    bulk cipher
3531        A symmetric encryption algorithm used to encrypt large quantities
3532        of data.
3534    cipher block chaining (CBC)
3535        CBC is a mode in which every plaintext block encrypted with a
3536        block cipher is first exclusive-ORed with the previous ciphertext
3537        block (or, in the case of the first block, with the
3538        initialization vector). For decryption, every block is first
3539        decrypted, then exclusive-ORed with the previous ciphertext block
3540        (or IV).
3542    certificate
3543        As part of the X.509 protocol (a.k.a. ISO Authentication
3544        framework), certificates are assigned by a trusted Certificate
3545        Authority and provide a strong binding between a party's identity
3546        or some other attributes and its public key.
3548    client
3549        The application entity that initiates a TLS connection to a
3550        server. This may or may not imply that the client initiated the
3551        underlying transport connection. The primary operational
3552        difference between the server and client is that the server is
3553        generally authenticated, while the client is only optionally
3554        authenticated.
3556    client write key
3557        The key used to encrypt data written by the client.
3563 Dierks & Rescorla            Standards Track                    [Page 66]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
3566    client write MAC secret
3567        The secret data used to authenticate data written by the client.
3569    connection
3570        A connection is a transport (in the OSI layering model
3571        definition) that provides a suitable type of service. For TLS,
3572        such connections are peer to peer relationships. The connections
3573        are transient. Every connection is associated with one session.
3575    Data Encryption Standard
3576        DES is a very widely used symmetric encryption algorithm. DES is
3577        a block cipher with a 56 bit key and an 8 byte block size. Note
3578        that in TLS, for key generation purposes, DES is treated as
3579        having an 8 byte key length (64 bits), but it still only provides
3580        56 bits of protection. (The low bit of each key byte is presumed
3581        to be set to produce odd parity in that key byte.) DES can also
3582        be operated in a mode where three independent keys and three
3583        encryptions are used for each block of data; this uses 168 bits
3584        of key (24 bytes in the TLS key generation method) and provides
3585        the equivalent of 112 bits of security. [DES], [3DES]
3587    Digital Signature Standard (DSS)
3588        A standard for digital signing, including the Digital Signing
3589        Algorithm, approved by the National Institute of Standards and
3590        Technology, defined in NIST FIPS PUB 186, "Digital Signature
3591        Standard," published May, 1994 by the U.S. Dept. of Commerce.
3592        [DSS]
3594    digital signatures
3595        Digital signatures utilize public key cryptography and one-way
3596        hash functions to produce a signature of the data that can be
3597        authenticated, and is difficult to forge or repudiate.
3599    handshake
3600        An initial negotiation between client and server that establishes
3601        the parameters of their transactions.
3603    Initialization Vector (IV)
3604        When a block cipher is used in CBC mode, the initialization
3605        vector is exclusive-ORed with the first plaintext block prior to
3606        encryption.
3608    IDEA
3609        A 64-bit block cipher designed by Xuejia Lai and James Massey.
3610        [IDEA]
3617 Dierks & Rescorla            Standards Track                    [Page 67]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
3620    Message Authentication Code (MAC)
3621        A Message Authentication Code is a one-way hash computed from a
3622        message and some secret data. It is difficult to forge without
3623        knowing the secret data. Its purpose is to detect if the message
3624        has been altered.
3626    master secret
3627        Secure secret data used for generating encryption keys, MAC
3628        secrets, and IVs.
3630    MD5
3631        MD5 is a secure hashing function that converts an arbitrarily
3632        long data stream into a digest of fixed size (16 bytes). [MD5]
3634    public key cryptography
3635        A class of cryptographic techniques employing two-key ciphers.
3636        Messages encrypted with the public key can only be decrypted with
3637        the associated private key. Conversely, messages signed with the
3638        private key can be verified with the public key.
3640    one-way hash function
3641        A one-way transformation that converts an arbitrary amount of
3642        data into a fixed-length hash. It is computationally hard to
3643        reverse the transformation or to find collisions. MD5 and SHA are
3644        examples of one-way hash functions.
3646    RC2
3647        A block cipher developed by Ron Rivest at RSA Data Security, Inc.
3648        [RSADSI] described in [RC2].
3650    RC4
3651        A stream cipher invented by Ron Rivest. A compatible cipher is
3652        described in [RC4].
3654    RSA
3655        A very widely used public-key algorithm that can be used for
3656        either encryption or digital signing. [RSA]
3658    server
3659        The server is the application entity that responds to requests
3660        for connections from clients. See also under client.
3662    session
3663        A TLS session is an association between a client and a server.
3664        Sessions are created by the handshake protocol. Sessions define a
3665        set of cryptographic security parameters, which can be shared
3666        among multiple connections. Sessions are used to avoid the
3667        expensive negotiation of new security parameters for each
3671 Dierks & Rescorla            Standards Track                    [Page 68]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
3674        connection.
3676    session identifier
3677        A session identifier is a value generated by a server that
3678        identifies a particular session.
3680    server write key
3681        The key used to encrypt data written by the server.
3683    server write MAC secret
3684        The secret data used to authenticate data written by the server.
3686    SHA
3687        The Secure Hash Algorithm is defined in FIPS PUB 180-2. It
3688        produces a 20-byte output. Note that all references to SHA
3689        actually use the modified SHA-1 algorithm. [SHA]
3691    SSL
3692        Netscape's Secure Socket Layer protocol [SSL3]. TLS is based on
3693        SSL Version 3.0
3695    stream cipher
3696        An encryption algorithm that converts a key into a
3697        cryptographically-strong keystream, which is then exclusive-ORed
3698        with the plaintext.
3700    symmetric cipher
3701        See bulk cipher.
3703    Transport Layer Security (TLS)
3704        This protocol; also, the Transport Layer Security working group
3705        of the Internet Engineering Task Force (IETF). See "Comments" at
3706        the end of this document.
3725 Dierks & Rescorla            Standards Track                    [Page 69]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
3728 C. CipherSuite definitions
3730 CipherSuite                             Key          Cipher      Hash
3731                                         Exchange
3733 TLS_NULL_WITH_NULL_NULL                 NULL           NULL        NULL
3734 TLS_RSA_WITH_NULL_MD5                   RSA            NULL         MD5
3735 TLS_RSA_WITH_NULL_SHA                   RSA            NULL         SHA
3736 TLS_RSA_WITH_RC4_128_MD5                RSA            RC4_128      MD5
3737 TLS_RSA_WITH_RC4_128_SHA                RSA            RC4_128      SHA
3738 TLS_RSA_WITH_IDEA_CBC_SHA               RSA            IDEA_CBC     SHA
3739 TLS_RSA_WITH_DES_CBC_SHA                RSA            DES_CBC      SHA
3740 TLS_RSA_WITH_3DES_EDE_CBC_SHA           RSA            3DES_EDE_CBC SHA
3741 TLS_DH_DSS_WITH_DES_CBC_SHA             DH_DSS         DES_CBC      SHA
3742 TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA        DH_DSS         3DES_EDE_CBC SHA
3743 TLS_DH_RSA_WITH_DES_CBC_SHA             DH_RSA         DES_CBC      SHA
3744 TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA        DH_RSA         3DES_EDE_CBC SHA
3745 TLS_DHE_DSS_WITH_DES_CBC_SHA            DHE_DSS        DES_CBC      SHA
3746 TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA       DHE_DSS        3DES_EDE_CBC SHA
3747 TLS_DHE_RSA_WITH_DES_CBC_SHA            DHE_RSA        DES_CBC      SHA
3748 TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA       DHE_RSA        3DES_EDE_CBC SHA
3749 TLS_DH_anon_WITH_RC4_128_MD5            DH_anon        RC4_128      MD5
3750 TLS_DH_anon_WITH_DES_CBC_SHA            DH_anon        DES_CBC      SHA
3751 TLS_DH_anon_WITH_3DES_EDE_CBC_SHA       DH_anon        3DES_EDE_CBC SHA
3753       Key
3754       Exchange
3755       Algorithm       Description                        Key size limit
3757       DHE_DSS         Ephemeral DH with DSS signatures   None
3758       DHE_RSA         Ephemeral DH with RSA signatures   None
3759       DH_anon         Anonymous DH, no signatures        None
3760       DH_DSS          DH with DSS-based certificates     None
3761       DH_RSA          DH with RSA-based certificates     None
3762                                                          RSA = none
3763       NULL            No key exchange                    N/A
3764       RSA             RSA key exchange                   None
3766                          Key      Expanded     IV    Block
3767     Cipher       Type  Material Key Material   Size   Size
3769     NULL         Stream   0          0         0     N/A
3770     IDEA_CBC     Block   16         16         8      8
3771     RC2_CBC_40   Block    5         16         8      8
3772     RC4_40       Stream   5         16         0     N/A
3773     RC4_128      Stream  16         16         0     N/A
3774     DES40_CBC    Block    5          8         8      8
3775     DES_CBC      Block    8          8         8      8
3779 Dierks & Rescorla            Standards Track                    [Page 70]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
3782     3DES_EDE_CBC Block   24         24         8      8
3784    Type
3785        Indicates whether this is a stream cipher or a block cipher
3786        running in CBC mode.
3788    Key Material
3789        The number of bytes from the key_block that are used for
3790        generating the write keys.
3792    Expanded Key Material
3793        The number of bytes actually fed into the encryption algorithm
3795    IV Size
3796        How much data needs to be generated for the initialization
3797        vector. Zero for stream ciphers; equal to the block size for
3798        block ciphers.
3800    Block Size
3801        The amount of data a block cipher enciphers in one chunk; a
3802        block cipher running in CBC mode can only encrypt an even
3803        multiple of its block size.
3805       Hash      Hash      Padding
3806     function    Size       Size
3807       NULL       0          0
3808       MD5        16         48
3809       SHA        20         40
3833 Dierks & Rescorla            Standards Track                    [Page 71]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
3836 D. Implementation Notes
3838    The TLS protocol cannot prevent many common security mistakes. This
3839    section provides several recommendations to assist implementors.
3841 D.1 Random Number Generation and Seeding
3843    TLS requires a cryptographically-secure pseudorandom number generator
3844    (PRNG). Care must be taken in designing and seeding PRNGs.  PRNGs
3845    based on secure hash operations, most notably MD5 and/or SHA, are
3846    acceptable, but cannot provide more security than the size of the
3847    random number generator state. (For example, MD5-based PRNGs usually
3848    provide 128 bits of state.)
3850    To estimate the amount of seed material being produced, add the
3851    number of bits of unpredictable information in each seed byte. For
3852    example, keystroke timing values taken from a PC compatible's 18.2 Hz
3853    timer provide 1 or 2 secure bits each, even though the total size of
3854    the counter value is 16 bits or more. To seed a 128-bit PRNG, one
3855    would thus require approximately 100 such timer values.
3857    [RANDOM] provides guidance on the generation of random values.
3859 D.2 Certificates and authentication
3861    Implementations are responsible for verifying the integrity of
3862    certificates and should generally support certificate revocation
3863    messages. Certificates should always be verified to ensure proper
3864    signing by a trusted Certificate Authority (CA). The selection and
3865    addition of trusted CAs should be done very carefully. Users should
3866    be able to view information about the certificate and root CA.
3868 D.3 CipherSuites
3870    TLS supports a range of key sizes and security levels, including some
3871    which provide no or minimal security. A proper implementation will
3872    probably not support many cipher suites. For example, 40-bit
3873    encryption is easily broken, so implementations requiring strong
3874    security should not allow 40-bit keys. Similarly, anonymous Diffie-
3875    Hellman is strongly discouraged because it cannot prevent man-in-the-
3876    middle attacks. Applications should also enforce minimum and maximum
3877    key sizes. For example, certificate chains containing 512-bit RSA
3878    keys or signatures are not appropriate for high-security
3879    applications.
3887 Dierks & Rescorla            Standards Track                    [Page 72]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
3890 E. Backward Compatibility With SSL
3892    For historical reasons and in order to avoid a profligate consumption
3893    of reserved port numbers, application protocols which are secured by
3894    TLS 1.1, TLS 1.0, SSL 3.0, and SSL 2.0 all frequently share the same
3895    connection port: for example, the https protocol (HTTP secured by SSL
3896    or TLS) uses port 443 regardless of which security protocol it is
3897    using. Thus, some mechanism must be determined to distinguish and
3898    negotiate among the various protocols.
3900    TLS versions 1.1, 1.0, and SSL 3.0 are very similar; thus, supporting
3901    both is easy. TLS clients who wish to negotiate with such older
3902    servers SHOULD send client hello messages using the SSL 3.0 record
3903    format and client hello structure, sending {3, 2} for the version
3904    field to note that they support TLS 1.1. If the server supports only
3905    TLS 1.0 or SSL 3.0, it will respond with a downrev 3.0 server hello;
3906    if it supports TLS 1.1 it will respond with a TLS 1.1 server hello.
3907    The negotiation then proceeds as appropriate for the negotiated
3908    protocol.
3910    Similarly, a TLS 1.1  server which wishes to interoperate with TLS
3911    1.0 or SSL 3.0 clients SHOULD accept SSL 3.0 client hello messages
3912    and respond with a SSL 3.0 server hello if an SSL 3.0 client hello
3913    with a version field of {3, 0} is received, denoting that this client
3914    does not support TLS. Similarly, if a SSL 3.0 or TLS 1.0 hello with a
3915    version field of {3, 1} is received, the server SHOULD respond with a
3916    TLS 1.0 hello with a version field of {3, 1}.
3918    Whenever a client already knows the highest protocol known to a
3919    server (for example, when resuming a session), it SHOULD initiate the
3920    connection in that native protocol.
3922    TLS 1.1 clients that support SSL Version 2.0 servers MUST send SSL
3923    Version 2.0 client hello messages [SSL2]. TLS servers SHOULD accept
3924    either client hello format if they wish to support SSL 2.0 clients on
3925    the same connection port. The only deviations from the Version 2.0
3926    specification are the ability to specify a version with a value of
3927    three and the support for more ciphering types in the CipherSpec.
3929  Warning: The ability to send Version 2.0 client hello messages will be
3930           phased out with all due haste. Implementors SHOULD make every
3931           effort to move forward as quickly as possible. Version 3.0
3932           provides better mechanisms for moving to newer versions.
3934    The following cipher specifications are carryovers from SSL Version
3935    2.0. These are assumed to use RSA for key exchange and
3936    authentication.
3941 Dierks & Rescorla            Standards Track                    [Page 73]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
3944        V2CipherSpec TLS_RC4_128_WITH_MD5          = { 0x01,0x00,0x80 };
3945        V2CipherSpec TLS_RC4_128_EXPORT40_WITH_MD5 = { 0x02,0x00,0x80 };
3946        V2CipherSpec TLS_RC2_CBC_128_CBC_WITH_MD5  = { 0x03,0x00,0x80 };
3947        V2CipherSpec TLS_RC2_CBC_128_CBC_EXPORT40_WITH_MD5
3948                                                   = { 0x04,0x00,0x80 };
3949        V2CipherSpec TLS_IDEA_128_CBC_WITH_MD5     = { 0x05,0x00,0x80 };
3950        V2CipherSpec TLS_DES_64_CBC_WITH_MD5       = { 0x06,0x00,0x40 };
3951        V2CipherSpec TLS_DES_192_EDE3_CBC_WITH_MD5 = { 0x07,0x00,0xC0 };
3953    Cipher specifications native to TLS can be included in Version 2.0
3954    client hello messages using the syntax below. Any V2CipherSpec
3955    element with its first byte equal to zero will be ignored by Version
3956    2.0 servers. Clients sending any of the above V2CipherSpecs SHOULD
3957    also include the TLS equivalent (see Appendix A.5):
3959        V2CipherSpec (see TLS name) = { 0x00, CipherSuite };
3961  Note: TLS 1.1 clients may generate the SSLv2 EXPORT cipher suites in
3962    handshakes for backward compatibility but MUST NOT negotiate them in
3963    TLS 1.1 mode.
3965 E.1. Version 2 client hello
3967    The Version 2.0 client hello message is presented below using this
3968    document's presentation model. The true definition is still assumed
3969    to be the SSL Version 2.0 specification. Note that this message MUST
3970    be sent directly on the wire, not wrapped as an SSLv3 record
3972        uint8 V2CipherSpec[3];
3974        struct {
3975            uint16 msg_length;
3976            uint8 msg_type;
3977            Version version;
3978            uint16 cipher_spec_length;
3979            uint16 session_id_length;
3980            uint16 challenge_length;
3981            V2CipherSpec cipher_specs[V2ClientHello.cipher_spec_length];
3982            opaque session_id[V2ClientHello.session_id_length];
3983            opaque challenge[V2ClientHello.challenge_length;
3984        } V2ClientHello;
3986    msg_length
3987        This field is the length of the following data in bytes. The high
3988        bit MUST be 1 and is not part of the length.
3990    msg_type
3991        This field, in conjunction with the version field, identifies a
3995 Dierks & Rescorla            Standards Track                    [Page 74]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
3998        version 2 client hello message. The value SHOULD be one (1).
4000    version
4001        The highest version of the protocol supported by the client
4002        (equals ProtocolVersion.version, see Appendix A.1).
4004    cipher_spec_length
4005        This field is the total length of the field cipher_specs. It
4006        cannot be zero and MUST be a multiple of the V2CipherSpec length
4007        (3).
4009    session_id_length
4010        This field MUST have a value of zero.
4012    challenge_length
4013        The length in bytes of the client's challenge to the server to
4014        authenticate itself. When using the SSLv2 backward compatible
4015        handshake the client MUST use a 32-byte challenge.
4017    cipher_specs
4018        This is a list of all CipherSpecs the client is willing and able
4019        to use. There MUST be at least one CipherSpec acceptable to the
4020        server.
4022    session_id
4023        This field MUST be empty.
4025    challenge
4026        The client challenge to the server for the server to identify
4027        itself is a (nearly) arbitrary length random. The TLS server will
4028        right justify the challenge data to become the ClientHello.random
4029        data (padded with leading zeroes, if necessary), as specified in
4030        this protocol specification. If the length of the challenge is
4031        greater than 32 bytes, only the last 32 bytes are used. It is
4032        legitimate (but not necessary) for a V3 server to reject a V2
4033        ClientHello that has fewer than 16 bytes of challenge data.
4035  Note: Requests to resume a TLS session MUST use a TLS client hello.
4037 E.2. Avoiding man-in-the-middle version rollback
4039    When TLS clients fall back to Version 2.0 compatibility mode, they
4040    SHOULD use special PKCS #1 block formatting. This is done so that TLS
4041    servers will reject Version 2.0 sessions with TLS-capable clients.
4043    When TLS clients are in Version 2.0 compatibility mode, they set the
4044    right-hand (least-significant) 8 random bytes of the PKCS padding
4045    (not including the terminal null of the padding) for the RSA
4049 Dierks & Rescorla            Standards Track                    [Page 75]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
4052    encryption of the ENCRYPTED-KEY-DATA field of the CLIENT-MASTER-KEY
4053    to 0x03 (the other padding bytes are random). After decrypting the
4054    ENCRYPTED-KEY-DATA field, servers that support TLS SHOULD issue an
4055    error if these eight padding bytes are 0x03. Version 2.0 servers
4056    receiving blocks padded in this manner will proceed normally.
4103 Dierks & Rescorla            Standards Track                    [Page 76]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
4106 F. Security analysis
4108    The TLS protocol is designed to establish a secure connection between
4109    a client and a server communicating over an insecure channel. This
4110    document makes several traditional assumptions, including that
4111    attackers have substantial computational resources and cannot obtain
4112    secret information from sources outside the protocol. Attackers are
4113    assumed to have the ability to capture, modify, delete, replay, and
4114    otherwise tamper with messages sent over the communication channel.
4115    This appendix outlines how TLS has been designed to resist a variety
4116    of attacks.
4118 F.1. Handshake protocol
4120    The handshake protocol is responsible for selecting a CipherSpec and
4121    generating a Master Secret, which together comprise the primary
4122    cryptographic parameters associated with a secure session. The
4123    handshake protocol can also optionally authenticate parties who have
4124    certificates signed by a trusted certificate authority.
4126 F.1.1. Authentication and key exchange
4128    TLS supports three authentication modes: authentication of both
4129    parties, server authentication with an unauthenticated client, and
4130    total anonymity. Whenever the server is authenticated, the channel is
4131    secure against man-in-the-middle attacks, but completely anonymous
4132    sessions are inherently vulnerable to such attacks.  Anonymous
4133    servers cannot authenticate clients. If the server is authenticated,
4134    its certificate message must provide a valid certificate chain
4135    leading to an acceptable certificate authority.  Similarly,
4136    authenticated clients must supply an acceptable certificate to the
4137    server. Each party is responsible for verifying that the other's
4138    certificate is valid and has not expired or been revoked.
4140    The general goal of the key exchange process is to create a
4141    pre_master_secret known to the communicating parties and not to
4142    attackers. The pre_master_secret will be used to generate the
4143    master_secret (see Section 8.1). The master_secret is required to
4144    generate the finished messages, encryption keys, and MAC secrets (see
4145    Sections 7.4.8, 7.4.9 and 6.3). By sending a correct finished
4146    message, parties thus prove that they know the correct
4147    pre_master_secret.
4149 F.1.1.1. Anonymous key exchange
4151    Completely anonymous sessions can be established using RSA or Diffie-
4152    Hellman for key exchange. With anonymous RSA, the client encrypts a
4153    pre_master_secret with the server's uncertified public key extracted
4157 Dierks & Rescorla            Standards Track                    [Page 77]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
4160    from the server key exchange message. The result is sent in a client
4161    key exchange message. Since eavesdroppers do not know the server's
4162    private key, it will be infeasible for them to decode the
4163    pre_master_secret.
4165    Note: No anonymous RSA Cipher Suites are defined in this document.
4167    With Diffie-Hellman, the server's public parameters are contained in
4168    the server key exchange message and the client's are sent in the
4169    client key exchange message. Eavesdroppers who do not know the
4170    private values should not be able to find the Diffie-Hellman result
4171    (i.e. the pre_master_secret).
4173  Warning: Completely anonymous connections only provide protection
4174           against passive eavesdropping. Unless an independent tamper-
4175           proof channel is used to verify that the finished messages
4176           were not replaced by an attacker, server authentication is
4177           required in environments where active man-in-the-middle
4178           attacks are a concern.
4180 F.1.1.2. RSA key exchange and authentication
4182    With RSA, key exchange and server authentication are combined. The
4183    public key may be either contained in the server's certificate or may
4184    be a temporary RSA key sent in a server key exchange message.  When
4185    temporary RSA keys are used, they are signed by the server's RSA
4186    certificate. The signature includes the current ClientHello.random,
4187    so old signatures and temporary keys cannot be replayed. Servers may
4188    use a single temporary RSA key for multiple negotiation sessions.
4190  Note: The temporary RSA key option is useful if servers need large
4191        certificates but must comply with government-imposed size limits
4192        on keys used for key exchange.
4194    Note that if ephemeral RSA is not used, compromise of the server's
4195    static RSA key results in a loss of confidentiality for all sessions
4196    protected under that static key. TLS users desiring Perfect Forward
4197    Secrecy should use DHE cipher suites. The damage done by exposure of
4198    a private key can be limited by changing one's private key (and
4199    certificate) frequently.
4201    After verifying the server's certificate, the client encrypts a
4202    pre_master_secret with the server's public key. By successfully
4203    decoding the pre_master_secret and producing a correct finished
4204    message, the server demonstrates that it knows the private key
4205    corresponding to the server certificate.
4207    When RSA is used for key exchange, clients are authenticated using
4211 Dierks & Rescorla            Standards Track                    [Page 78]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
4214    the certificate verify message (see Section 7.4.8). The client signs
4215    a value derived from the master_secret and all preceding handshake
4216    messages. These handshake messages include the server certificate,
4217    which binds the signature to the server, and ServerHello.random,
4218    which binds the signature to the current handshake process.
4220 F.1.1.3. Diffie-Hellman key exchange with authentication
4222    When Diffie-Hellman key exchange is used, the server can either
4223    supply a certificate containing fixed Diffie-Hellman parameters or
4224    can use the server key exchange message to send a set of temporary
4225    Diffie-Hellman parameters signed with a DSS or RSA certificate.
4226    Temporary parameters are hashed with the hello.random values before
4227    signing to ensure that attackers do not replay old parameters. In
4228    either case, the client can verify the certificate or signature to
4229    ensure that the parameters belong to the server.
4231    If the client has a certificate containing fixed Diffie-Hellman
4232    parameters, its certificate contains the information required to
4233    complete the key exchange. Note that in this case the client and
4234    server will generate the same Diffie-Hellman result (i.e.,
4235    pre_master_secret) every time they communicate. To prevent the
4236    pre_master_secret from staying in memory any longer than necessary,
4237    it should be converted into the master_secret as soon as possible.
4238    Client Diffie-Hellman parameters must be compatible with those
4239    supplied by the server for the key exchange to work.
4241    If the client has a standard DSS or RSA certificate or is
4242    unauthenticated, it sends a set of temporary parameters to the server
4243    in the client key exchange message, then optionally uses a
4244    certificate verify message to authenticate itself.
4246    If the same DH keypair is to be used for multiple handshakes, either
4247    because the client or server has a certificate containing a fixed DH
4248    keypair or because the server is reusing DH keys, care must be taken
4249    to prevent small subgroup attacks. Implementations SHOULD follow the
4250    guidelines found in [SUBGROUP].
4252    Small subgroup attacks are most easily avoided by using one of the
4253    DHE ciphersuites and generating a fresh DH private key (X) for each
4254    handshake. If a suitable base (such as 2) is chosen, g^X mod p can be
4255    computed very quickly so the performance cost is minimized.
4256    Additionally, using a fresh key for each handshake provides Perfect
4257    Forward Secrecy. Implementations SHOULD generate a new X for each
4258    handshake when using DHE ciphersuites.
4260 F.1.2. Version rollback attacks
4265 Dierks & Rescorla            Standards Track                    [Page 79]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
4268    Because TLS includes substantial improvements over SSL Version 2.0,
4269    attackers may try to make TLS-capable clients and servers fall back
4270    to Version 2.0. This attack can occur if (and only if) two TLS-
4271    capable parties use an SSL 2.0 handshake.
4273    Although the solution using non-random PKCS #1 block type 2 message
4274    padding is inelegant, it provides a reasonably secure way for Version
4275    3.0 servers to detect the attack. This solution is not secure against
4276    attackers who can brute force the key and substitute a new ENCRYPTED-
4277    KEY-DATA message containing the same key (but with normal padding)
4278    before the application specified wait threshold has expired. Parties
4279    concerned about attacks of this scale should not be using 40-bit
4280    encryption keys anyway. Altering the padding of the least-significant
4281    8 bytes of the PKCS padding does not impact security for the size of
4282    the signed hashes and RSA key lengths used in the protocol, since
4283    this is essentially equivalent to increasing the input block size by
4284    8 bytes.
4286 F.1.3. Detecting attacks against the handshake protocol
4288    An attacker might try to influence the handshake exchange to make the
4289    parties select different encryption algorithms than they would
4290    normally chooses.
4292    For this attack, an attacker must actively change one or more
4293    handshake messages. If this occurs, the client and server will
4294    compute different values for the handshake message hashes. As a
4295    result, the parties will not accept each others' finished messages.
4296    Without the master_secret, the attacker cannot repair the finished
4297    messages, so the attack will be discovered.
4299 F.1.4. Resuming sessions
4301    When a connection is established by resuming a session, new
4302    ClientHello.random and ServerHello.random values are hashed with the
4303    session's master_secret. Provided that the master_secret has not been
4304    compromised and that the secure hash operations used to produce the
4305    encryption keys and MAC secrets are secure, the connection should be
4306    secure and effectively independent from previous connections.
4307    Attackers cannot use known encryption keys or MAC secrets to
4308    compromise the master_secret without breaking the secure hash
4309    operations (which use both SHA and MD5).
4311    Sessions cannot be resumed unless both the client and server agree.
4312    If either party suspects that the session may have been compromised,
4313    or that certificates may have expired or been revoked, it should
4314    force a full handshake. An upper limit of 24 hours is suggested for
4315    session ID lifetimes, since an attacker who obtains a master_secret
4319 Dierks & Rescorla            Standards Track                    [Page 80]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
4322    may be able to impersonate the compromised party until the
4323    corresponding session ID is retired. Applications that may be run in
4324    relatively insecure environments should not write session IDs to
4325    stable storage.
4327 F.1.5. MD5 and SHA
4329    TLS uses hash functions very conservatively. Where possible, both MD5
4330    and SHA are used in tandem to ensure that non-catastrophic flaws in
4331    one algorithm will not break the overall protocol.
4333 F.2. Protecting application data
4335    The master_secret is hashed with the ClientHello.random and
4336    ServerHello.random to produce unique data encryption keys and MAC
4337    secrets for each connection.
4339    Outgoing data is protected with a MAC before transmission. To prevent
4340    message replay or modification attacks, the MAC is computed from the
4341    MAC secret, the sequence number, the message length, the message
4342    contents, and two fixed character strings. The message type field is
4343    necessary to ensure that messages intended for one TLS Record Layer
4344    client are not redirected to another. The sequence number ensures
4345    that attempts to delete or reorder messages will be detected. Since
4346    sequence numbers are 64-bits long, they should never overflow.
4347    Messages from one party cannot be inserted into the other's output,
4348    since they use independent MAC secrets. Similarly, the server-write
4349    and client-write keys are independent so stream cipher keys are used
4350    only once.
4352    If an attacker does break an encryption key, all messages encrypted
4353    with it can be read. Similarly, compromise of a MAC key can make
4354    message modification attacks possible. Because MACs are also
4355    encrypted, message-alteration attacks generally require breaking the
4356    encryption algorithm as well as the MAC.
4358  Note: MAC secrets may be larger than encryption keys, so messages can
4359        remain tamper resistant even if encryption keys are broken.
4361 F.3. Explicit IVs
4363        [CBCATT] describes a chosen plaintext attack on TLS that depends
4364        on knowing the IV for a record. Previous versions of TLS [TLS1.0]
4365        used the CBC residue of the previous record as the IV and
4366        therefore enabled this attack. This version uses an explicit IV
4367        in order to protect against this attack.
4373 Dierks & Rescorla            Standards Track                    [Page 81]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
4376 F.4 Security of Composite Cipher Modes
4378        TLS secures transmitted application data via the use of symmetric
4379        encryption and authentication functions defined in the negotiated
4380        ciphersuite.  The objective is to protect both the integrity  and
4381        confidentiality of the transmitted data from malicious actions by
4382        active attackers in the network.  It turns out that the order in
4383        which encryption and authentication functions are applied to the
4384        data plays an important role for achieving this goal [ENCAUTH].
4386        The most robust method, called encrypt-then-authenticate, first
4387        applies encryption to the data and then applies a MAC to the
4388        ciphertext.  This method ensures that the integrity and
4389        confidentiality goals are obtained with ANY pair of encryption
4390        and MAC functions provided that the former is secure against
4391        chosen plaintext attacks and the MAC is secure against chosen-
4392        message attacks.  TLS uses another method, called authenticate-
4393        then-encrypt, in which first a MAC is computed on the plaintext
4394        and then the concatenation of plaintext and MAC is encrypted.
4395        This method has been proven secure for CERTAIN combinations of
4396        encryption functions and MAC functions, but is not guaranteed to
4397        be secure in general. In particular, it has been shown that there
4398        exist perfectly secure encryption functions (secure even in the
4399        information theoretic sense) that combined with any secure MAC
4400        function fail to provide the confidentiality goal against an
4401        active attack.  Therefore, new ciphersuites and operation modes
4402        adopted into TLS need to be analyzed under the authenticate-then-
4403        encrypt method to verify that they achieve the stated integrity
4404        and confidentiality goals.
4406        Currently, the security of the authenticate-then-encrypt method
4407        has been proven for some important cases.  One is the case of
4408        stream ciphers in which a computationally unpredictable pad of
4409        the length of the message plus the length of the MAC tag is
4410        produced using a pseudo-random generator and this pad is xor-ed
4411        with the concatenation of plaintext and MAC tag.  The other is
4412        the case of CBC mode using a secure block cipher.  In this case,
4413        security can be shown if one applies one CBC encryption pass to
4414        the concatenation of plaintext and MAC and uses a new,
4415        independent and unpredictable, IV for each new pair of plaintext
4416        and MAC.  In previous versions of SSL, CBC mode was used properly
4417        EXCEPT that it used a predictable IV in the form of the last
4418        block of the previous ciphertext. This made TLS open to chosen
4419        plaintext attacks.  This verson of the protocol is immune to
4420        those attacks.  For exact details in the encryption modes proven
4421        secure see [ENCAUTH].
4427 Dierks & Rescorla            Standards Track                    [Page 82]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
4430 F.5 Denial of Service
4432        TLS is susceptible to a number of denial of service (DoS)
4433        attacks.  In particular, an attacker who initiates a large number
4434        of TCP connections can cause a server to consume large amounts of
4435        CPU doing RSA decryption. However, because TLS is generally used
4436        over TCP, it is difficult for the attacker to hide his point of
4437        origin if proper TCP SYN randomization is used [SEQNUM] by the
4438        TCP stack.
4440        Because TLS runs over TCP, it is also susceptible to a number of
4441        denial of service attacks on individual connections. In
4442        particular, attackers can forge RSTs, terminating connections, or
4443        forge partial TLS records, causing the connection to stall.
4444        These attacks cannot in general be defended against by a TCP-
4445        using protocol. Implementors or users who are concerned with this
4446        class of attack should use IPsec AH [AH] or ESP [ESP].
4448 F.6. Final notes
4450    For TLS to be able to provide a secure connection, both the client
4451    and server systems, keys, and applications must be secure. In
4452    addition, the implementation must be free of security errors.
4454    The system is only as strong as the weakest key exchange and
4455    authentication algorithm supported, and only trustworthy
4456    cryptographic functions should be used. Short public keys, 40-bit
4457    bulk encryption keys, and anonymous servers should be used with great
4458    caution. Implementations and users must be careful when deciding
4459    which certificates and certificate authorities are acceptable; a
4460    dishonest certificate authority can do tremendous damage.
4481 Dierks & Rescorla            Standards Track                    [Page 83]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
4484 Security Considerations
4486    Security issues are discussed throughout this memo, especially in
4487    Appendices D, E, and F.
4489 Normative References
4491    [3DES]   W. Tuchman, "Hellman Presents No Shortcut Solutions To DES,"
4492             IEEE Spectrum, v. 16, n. 7, July 1979, pp40-41.
4494    [DES]    ANSI X3.106, "American National Standard for Information
4495             Systems-Data Link Encryption," American National Standards
4496             Institute, 1983.
4498    [DSS]    NIST FIPS PUB 186-2, "Digital Signature Standard," National
4499             Institute of Standards and Technology, U.S. Department of
4500             Commerce, 2000.
4502    [HMAC]   Krawczyk, H., Bellare, M., and R. Canetti, "HMAC: Keyed-
4503             Hashing for Message Authentication," RFC 2104, February
4504             1997.
4506    [IDEA]   X. Lai, "On the Design and Security of Block Ciphers," ETH
4507             Series in Information Processing, v. 1, Konstanz: Hartung-
4508             Gorre Verlag, 1992.
4510    [MD2]    Kaliski, B., "The MD2 Message Digest Algorithm", RFC 1319,
4511             April 1992.
4513    [MD5]    Rivest, R., "The MD5 Message Digest Algorithm", RFC 1321,
4514             April 1992.
4516    [PKCS1]  J. Jonsson, B. Kaliski, "3447 Public-Key Cryptography
4517             Standards (PKCS) #1: RSA Cryptography Specifications Version
4518             2.1", RFC 3447, February 2003"
4520    [PKIX]   Housley, R., Ford, W., Polk, W. and D. Solo, "Internet
4521             Public Key Infrastructure: Part I: X.509 Certificate and CRL
4522             Profile", RFC 3280, April 2002.
4524    [RC2]    Rivest, R., "A Description of the RC2(r) Encryption
4525             Algorithm", RFC 2268, January 1998.
4527    [SCH]    B. Schneier. "Applied Cryptography: Protocols, Algorithms,
4528             and Source Code in C, 2ed", Published by John Wiley & Sons,
4529             Inc. 1996.
4535 Dierks & Rescorla            Standards Track                    [Page 84]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
4538    [SHA]    NIST FIPS PUB 180-2, "Secure Hash Standard," National
4539             Institute of Standards and Technology, U.S. Department of
4540             Commerce., August 2001.
4542    [REQ]    Bradner, S., "Key words for use in RFCs to Indicate
4543             Requirement Levels", BCP 14, RFC 2119, March 1997.
4545    [RFC2434] T. Narten, H. Alvestrand, "Guidelines for Writing an IANA
4546             Considerations Section in RFCs", RFC 3434, October 1998.
4548    [TLSAES] Chown, P. "Advanced Encryption Standard (AES) Ciphersuites
4549             for Transport Layer Security (TLS)", RFC 3268, Junr 2002.
4551    [TLSEXT] Blake-Wilson, S., Nystrom, M, Hopwood, D., Mikkelsen, J.,
4552             Wright, T., "Transport Layer Security (TLS) Extensions", RFC
4553             3546, June 2003.        [TLSKRB] A. Medvinsky, M. Hur,
4554             "Addition of Kerberos Cipher Suites to Transport Layer
4555             Security (TLS)", RFC 2712, October 1999.
4558 Informative References
4560    [AH]     Kent, S., and Atkinson, R., "IP Authentication Header", RFC
4561             2402, November 1998.
4563    [BLEI]   Bleichenbacher D., "Chosen Ciphertext Attacks against
4564             Protocols Based on RSA Encryption Standard PKCS #1" in
4565             Advances in Cryptology -- CRYPTO'98, LNCS vol. 1462, pages:
4566             1-12, 1998.
4568    [CBCATT] Moeller, B., "Security of CBC Ciphersuites in SSL/TLS:
4569             Problems and Countermeasures",
4570             http://www.openssl.org/~bodo/tls-cbc.txt.
4572    [CBCTIME] Canvel, B., "Password Interception in a SSL/TLS Channel",
4573             http://lasecwww.epfl.ch/memo_ssl.shtml, 2003.
4575    [ENCAUTH] Krawczyk, H., "The Order of Encryption and Authentication
4576             for Protecting Communications (Or: How Secure is SSL?)",
4577             Crypto 2001.
4579    [ESP]     Kent, S., and Atkinson, R., "IP Encapsulating Security
4580             Payload (ESP)", RFC 2406, November 1998.
4582    [FTP]    Postel J., and J. Reynolds, "File Transfer Protocol", STD 9,
4583             RFC 959, October 1985.
4585    [HTTP]   Berners-Lee, T., Fielding, R., and H. Frystyk, "Hypertext
4589 Dierks & Rescorla            Standards Track                    [Page 85]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
4592             Transfer Protocol -- HTTP/1.0", RFC 1945, May 1996.
4594    [KPR03]  Klima, V., Pokorny, O., Rosa, T., "Attacking RSA-based
4595             Sessions in SSL/TLS", http://eprint.iacr.org/2003/052/,
4596             March 2003.
4598    [PKCS6]  RSA Laboratories, "PKCS #6: RSA Extended Certificate Syntax
4599             Standard," version 1.5, November 1993.
4601    [PKCS7]  RSA Laboratories, "PKCS #7: RSA Cryptographic Message Syntax
4602             Standard," version 1.5, November 1993.
4604             [RANDOM] D. Eastlake 3rd, S. Crocker, J. Schiller.
4605             "Randomness Recommendations for Security", RFC 1750,
4606             December 1994.
4608    [RSA]    R. Rivest, A. Shamir, and L. M. Adleman, "A Method for
4609             Obtaining Digital Signatures and Public-Key Cryptosystems,"
4610             Communications of the ACM, v. 21, n. 2, Feb 1978, pp.
4611             120-126.
4613    [SEQNUM] Bellovin. S., "Defending Against Sequence Number Attacks",
4614             RFC 1948, May 1996.
4616    [SSL2]   Hickman, Kipp, "The SSL Protocol", Netscape Communications
4617             Corp., Feb 9, 1995.
4619    [SSL3]   A. Frier, P. Karlton, and P. Kocher, "The SSL 3.0 Protocol",
4620             Netscape Communications Corp., Nov 18, 1996.
4622    [SUBGROUP] R. Zuccherato, "Methods for Avoiding the Small-Subgroup
4623             Attacks on the Diffie-Hellman Key Agreement Method for
4624             S/MIME", RFC 2785, March 2000.
4626    [TCP]    Postel, J., "Transmission Control Protocol," STD 7, RFC 793,
4627             September 1981.
4629    [TIMING] Boneh, D., Brumley, D., "Remote timing attacks are
4630             practical", USENIX Security Symposium 2003.
4632    [TLS1.0] Dierks, T., and Allen, C., "The TLS Protocol, Version 1.0",
4633             RFC 2246, January 1999.
4635    [X509]   CCITT. Recommendation X.509: "The Directory - Authentication
4636             Framework". 1988.
4638    [XDR]    R. Srinivansan, Sun Microsystems, RFC-1832: XDR: External
4639             Data Representation Standard, August 1995.
4643 Dierks & Rescorla            Standards Track                    [Page 86]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
4646 Credits
4648    Working Group Chairs
4649    Win Treese
4650    EMail: treese@acm.org
4652    Eric Rescorla
4653    EMail: ekr@rtfm.com
4656    Editors
4658    Tim Dierks                Eric Rescorla
4659    Independent                   RTFM, Inc.
4661    EMail: tim@dierks.org         EMail: ekr@rtfm.com
4665    Other contributors
4667    Christopher Allen (co-editor of TLS 1.0)
4668    Alacrity Ventures
4669    ChristopherA@AlacrityManagement.com
4671    Martin Abadi
4672    University of California, Santa Cruz
4673    abadi@cs.ucsc.edu
4675    Ran Canetti
4676    IBM
4677    canetti@watson.ibm.com
4679    Taher Elgamal
4680    taher@securify.com
4681    Securify
4683    Anil Gangolli
4684    anil@busybuddha.org
4686    Kipp Hickman
4688    Phil Karlton (co-author of SSLv3)
4690    Paul Kocher (co-author of SSLv3)
4691    Cryptography Research
4692    paul@cryptography.com
4697 Dierks & Rescorla            Standards Track                    [Page 87]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
4700    Hugo Krawczyk
4701    Technion Israel Institute of Technology
4702    hugo@ee.technion.ac.il
4704    Robert Relyea
4705    Netscape Communications
4706    relyea@netscape.com
4708    Jim Roskind
4709    Netscape Communications
4710    jar@netscape.com
4712    Michael Sabin
4714    Dan Simon
4715    Microsoft, Inc.
4716    dansimon@microsoft.com
4718    Tom Weinstein
4720 Comments
4722    The discussion list for the IETF TLS working group is located at the
4723    e-mail address <ietf-tls@lists.consensus.com>. Information on the
4724    group and information on how to subscribe to the list is at
4725    <http://lists.consensus.com/>.
4727    Archives of the list can be found at:
4728        <http://www.imc.org/ietf-tls/mail-archive/>
4751 Dierks & Rescorla            Standards Track                    [Page 88]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
4754 Full Copyright Statement
4756    The IETF takes no position regarding the validity or scope of any
4757    Intellectual Property Rights or other rights that might be claimed to
4758    pertain to the implementation or use of the technology described in
4759    this document or the extent to which any license under such rights
4760    might or might not be available; nor does it represent that it has
4761    made any independent effort to identify any such rights. Information
4762    on the procedures with respect to rights in RFC documents can be
4763    found in BCP 78 and BCP 79.
4765    Copies of IPR disclosures made to the IETF Secretariat and any
4766    assurances of licenses to be made available, or the result of an
4767    attempt made to obtain a general license or permission for the use of
4768    such proprietary rights by implementers or users of this
4769    specification can be obtained from the IETF on-line IPR repository at
4770    http://www.ietf.org/ipr.
4772    The IETF invites any interested party to bring to its attention any
4773    copyrights, patents or patent applications, or other proprietary
4774    rights that may cover technology that may be required to implement
4775    this standard. Please address the information to the IETF at ietf-
4776    ipr@ietf.org.
4778 Copyright Notice
4779    Copyright (C) The Internet Society (2003). This document is subject
4780    to the rights, licenses and restrictions contained in BCP 78, and
4781    except as set forth therein, the authors retain all their rights.
4783    This document and the information contained herein are provided on an
4784    "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS
4785    OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY AND THE INTERNET
4786    ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED,
4787    INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE
4788    INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED
4789    WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
4805 Dierks & Rescorla            Standards Track                    [Page 89]\fdraft-ietf-tls-rfc2246-bis-10.txt  TLS                        April 2005
4859 Dierks & Rescorla            Standards Track                    [Page 90]\f