home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1997 December / Internet_Info_CD-ROM_Walnut_Creek_December_1997.iso / drafts / draft_ietf_q_t / draft-ietf-tls-protocol-02.txt < prev    next >
Text File  |  1997-03-24  |  163KB  |  3,867 lines

  1.  
  2. Transport Layer Security Working Group                      Tim Dierks
  3. INTERNET-DRAFT                                   Consensus Development
  4. Expires September 22, 1997                           Christopher Allen
  5.                                                  Consensus Development
  6.                                                         March 24, 1997
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.                           The TLS Protocol
  15.                              Version 1.0
  16.  
  17.  
  18.                    <draft-ietf-tls-protocol-02.txt>
  19.  
  20. Status of this memo
  21.  
  22.    This document is an Internet-Draft. Internet-Drafts are working
  23.    documents of the Internet Engineering Task Force (IETF), its areas,
  24.    and its working groups. Note that other groups may also distribute
  25.    working documents as Internet-Drafts.
  26.  
  27.    Internet-Drafts are draft documents valid for a maximum of six
  28.    months and may be updated, replaced, or made obsolete by other
  29.    documents at any time. It is inappropriate to use Internet-Drafts as
  30.    reference material or to cite them other than as work in progress.
  31.  
  32.    To learn the current status of any Internet-Draft, please check the
  33.    1id-abstracts.txt listing contained in the Internet Drafts Shadow
  34.    Directories on ds.internic.net (US East Coast), nic.nordu.net
  35.    (Europe), ftp.isi.edu (US West Coast), or munnari.oz.au (Pacific
  36.    Rim).
  37.  
  38. Abstract
  39.  
  40.    This document specifies Version 1.0 of the Transport Layer Security
  41.    (TLS) protocol, which is at this stage is strictly based on the
  42.    Secure Sockets Layer (SSL) version 3.0 protocol, and is to serve as
  43.    a basis for future discussions. The TLS protocol provides
  44.    communications privacy over the Internet. The protocol allows
  45.    client/server applications to communicate in a way that is designed
  46.    to prevent eavesdropping, tampering, or message forgery.
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57. Dierks, T.                  Expires September, 1997             [Page 1]
  58. INTERNET-DRAFT                     TLS 1.0                    March 1997
  59.  
  60. Table of Contents
  61.  
  62.             Status of this memo                                        1
  63.             Abstract                                                   1
  64.             Table of Contents                                          2
  65.    1.       Introduction                                               3
  66.    2.       Goals                                                      4
  67.    3.       Goals of this document                                     5
  68.    4.       Presentation language                                      5
  69.    4.1.     Basic block size                                           6
  70.    4.2.     Miscellaneous                                              6
  71.    4.3.     Vectors                                                    6
  72.    4.4.     Numbers                                                    7
  73.    4.5.     Enumerateds                                                7
  74.    4.6.     Constructed types                                          8
  75.    4.6.1.   Variants                                                   8
  76.    4.7.     Cryptographic attributes                                   9
  77.    4.8.     Constants                                                 10
  78.    5.       The TLS Record Protocol                                   11
  79.    5.1.     Connection states                                         11
  80.    5.2.     HMAC and the pseudorandom function                        14
  81.    5.3.     Record layer                                              15
  82.    5.3.1.   Fragmentation                                             15
  83.    5.3.2.   Record compression and decompression                      16
  84.    5.3.3.   Record payload protection                                 17
  85.    5.3.3.1. Null or standard stream cipher                            17
  86.    5.3.3.2. CBC block cipher                                          18
  87.    5.4.     Key calculation                                           19
  88.    5.4.1.   Export key generation example                             21
  89.    6.       The TLS Handshake Protocol                                21
  90.    6.1.     Change cipher spec protocol                               22
  91.    6.2.     Alert protocol                                            22
  92.    6.2.1.   Closure alerts                                            23
  93.    6.2.2.   Error alerts                                              24
  94.    6.3.     Handshake Protocol overview                               26
  95.    6.4.     Handshake protocol                                        29
  96.    6.4.1.   Hello messages                                            30
  97.    6.4.1.1. Hello request                                             30
  98.    6.4.1.2. Client hello                                              31
  99.    6.4.1.3. Server hello                                              33
  100.    6.4.2.   Server certificate                                        34
  101.    6.4.3.   Server key exchange message                               36
  102.    6.4.4.   Certificate request                                       38
  103.    6.4.5.   Server hello done                                         39
  104.    6.4.6.   Client certificate                                        39
  105.    6.4.7.   Client key exchange message                               40
  106.    6.4.7.1. RSA encrypted premaster secret message                    40
  107.    6.4.7.2. Client Diffie-Hellman public value                        41
  108.    6.4.8.   Certificate verify                                        41
  109.    6.4.9.   Finished                                                  42
  110.    7.       Cryptographic computations                                43
  111.    7.1.     Computing the master secret                               43
  112.  
  113. Dierks, T.                  Expires September, 1997             [Page 2]
  114. INTERNET-DRAFT                     TLS 1.0                    March 1997
  115.  
  116.    7.1.1.   RSA                                                       44
  117.    7.1.2.   Diffie-Hellman                                            44
  118.    8.       Application data protocol                                 44
  119.    A.       Protocol constant values                                  44
  120.    A.1.     Reserved port assignments                                 44
  121.    A.2.     Record layer                                              45
  122.    A.3.     Change cipher specs message                               46
  123.    A.4.     Alert messages                                            46
  124.    A.5.     Handshake protocol                                        46
  125.    A.5.1.   Hello messages                                            47
  126.    A.5.2.   Server authentication and key exchange messages           47
  127.    A.5.3.   Client authentication and key exchange messages           49
  128.    A.5.4.   Handshake finalization message                            49
  129.    A.6.     The CipherSuite                                           49
  130.    A.7.     The Security Parameters                                   51
  131.    B.       Glossary                                                  51
  132.    C.       CipherSuite definitions                                   55
  133.    D.       Implementation Notes                                      57
  134.    D.1.     Temporary RSA keys                                        57
  135.    D.2.     Random Number Generation and Seeding                      57
  136.    D.3.     Certificates and authentication                           58
  137.    D.4.     CipherSuites                                              58
  138.    E.       Backward Compatibility With SSL                           58
  139.    E.1.     Version 2 client hello                                    59
  140.    E.2.     Avoiding man-in-the-middle version rollback               61
  141.    F.       Security analysis                                         61
  142.    F.1.     Handshake protocol                                        61
  143.    F.1.1.   Authentication and key exchange                           61
  144.    F.1.1.1. Anonymous key exchange                                    62
  145.    F.1.1.2. RSA key exchange and authentication                       62
  146.    F.1.1.3. Diffie-Hellman key exchange with authentication           63
  147.    F.1.2.   Version rollback attacks                                  63
  148.    F.1.3.   Detecting attacks against the handshake protocol          64
  149.    F.1.4.   Resuming sessions                                         64
  150.    F.1.5.   MD5 and SHA                                               64
  151.    F.2.     Protecting application data                               65
  152.    F.3.     Final notes                                               65
  153.    G.       Patent Statement                                          65
  154.             References                                                66
  155.             Credits                                                   68
  156.             Comments                                                  69
  157.  
  158. 1. Introduction
  159.  
  160.    The primary goal of the TLS Protocol is to provide privacy and
  161.    reliability between two communicating applications. The protocol is
  162.    composed of two layers: the TLS Record Protocol and the TLS
  163.    Handshake Protocol. At the lowest level, layered on top of some
  164.    reliable transport protocol (e.g., TCP[TCP]), is the TLS Record
  165.    Protocol. The TLS Record Protocol provides connection security that
  166.    has two basic properties:
  167.  
  168.  
  169. Dierks, T.                  Expires September, 1997             [Page 3]
  170. INTERNET-DRAFT                     TLS 1.0                    March 1997
  171.  
  172.      - The connection is private. Symmetric cryptography is used for
  173.        data encryption (e.g., DES[DES], RC4[RC4], etc.) The keys for
  174.        this symmetric encryption are generated uniquely for each
  175.        connection and are based on a secret negotiated by another
  176.        protocol (such as the TLS Handshake Protocol). The Record
  177. |      Protocol can also be used without encryption.
  178.  
  179.      - The connection is reliable. Message transport includes a message
  180.        integrity check using a keyed MAC. Secure hash functions (e.g.,
  181.        SHA, MD5, etc.) are used for MAC computations. The Record
  182.        Protocol can operate without a MAC, but is generally only used
  183.        in this mode while another protocol is using the Record Protocol
  184.        as a transport for negotiating security parameters.
  185.  
  186.    The TLS Record Protocol is used for encapsulation of various higher
  187.    level protocols. One such encapsulated protocol, the TLS Handshake
  188.    Protocol, allows the server and client to authenticate each other
  189.    and to negotiate an encryption algorithm and cryptographic keys
  190.    before the application protocol transmits or receives its first byte
  191.    of data. The TLS Handshake Protocol provides connection security
  192.    that has three basic properties:
  193.  
  194.      - The peer's identity can be authenticated using asymmetric, or
  195.        public key, cryptography (e.g., RSA[RSA], DSS[DSS], etc.). This
  196.        authentication can be made optional, but is generally required
  197.        for at least one of the peers.
  198.  
  199.      - The negotiation of a shared secret is secure: the negotiated
  200. |      secret is unavailable to eavesdroppers, and for any
  201. |      authenticated connection the secret cannot be obtained, even by
  202. |      an attacker who can place himself in the middle of the
  203. |      connection.
  204.  
  205.      - The negotiation is reliable: no attacker can modify the
  206. |      negotiation communication without being detected by the parties
  207. |      to the communication.
  208.  
  209.    One advantage of TLS is that it is application protocol independent.
  210. |  Higher level protocols can layer on top of the TLS Protocol
  211. ]  transparently. The TLS standard, however, does not specify how
  212. ]  protocols add security with TLS; the decisions on how to initiate
  213. ]  TLS handshaking and how to interpret the authentication certificates
  214. ]  exchanged are left up to the judgement of the designers and
  215. ]  implementors of protocols which run on top of TLS.
  216.  
  217. 2. Goals
  218.  
  219.    The goals of TLS Protocol, in order of their priority, are:
  220.  
  221.     1. Cryptographic security: TLS should be used to establish a secure
  222.        connection between two parties.
  223.  
  224.  
  225. Dierks, T.                  Expires September, 1997             [Page 4]
  226. INTERNET-DRAFT                     TLS 1.0                    March 1997
  227.  
  228.     2. Interoperability: Independent programmers should be able to
  229.        develop applications utilizing TLS that will then be able to
  230.        successfully exchange cryptographic parameters without knowledge
  231.        of one another's code.
  232.  
  233.  Note: It is not the case that all instances of TLS (even in the same
  234.        application domain) will be able to successfully connect. For
  235.        instance, if the server supports a particular hardware token,
  236.        and the client does not have access to such a token, then the
  237. |      connection will not succeed. There is no required set of ciphers
  238. |      for minimal compliance, so some implementations may be unable to
  239. |      communicate.
  240.  
  241.     3. Extensibility: TLS seeks to provide a framework into which new
  242.        public key and bulk encryption methods can be incorporated as
  243.        necessary. This will also accomplish two sub-goals: to prevent
  244.        the need to create a new protocol (and risking the introduction
  245.        of possible new weaknesses) and to avoid the need to implement
  246.        an entire new security library.
  247.  
  248.     4. Relative efficiency: Cryptographic operations tend to be highly
  249.        CPU intensive, particularly public key operations. For this
  250.        reason, the TLS protocol has incorporated an optional session
  251.        caching scheme to reduce the number of connections that need to
  252.        be established from scratch. Additionally, care has been taken
  253.        to reduce network activity.
  254.  
  255. 3. Goals of this document
  256.  
  257. |  This document and the TLS protocol itself are based on the SSL 3.0
  258. |  Protocol Specification as published by Netscape. The differences
  259. |  between this protocol and SSL 3.0 are not dramatic, but they are
  260. |  significant enough that TLS 1.0 and SSL 3.0 do not interoperate
  261. |  (although TLS 1.0 does incorporate a mechanism by which a TLS
  262. |  implementation can back down to SSL 3.0). This document is intended
  263. |  primarily for readers who will be implementing the protocol and
  264. |  those doing cryptographic analysis of it. The spec has been written
  265. |  with this in mind, and it is intended to reflect the needs of those
  266. |  two groups. For that reason, many of the algorithm-dependent data
  267. |  structures and rules are included in the body of the text (as
  268. |  opposed to in an Appendix), providing easier access to them.
  269.  
  270.    This document is not intended to supply any details of service
  271.    definition nor interface definition, although it does cover select
  272.    areas of policy as they are required for the maintenance of solid
  273.    security.
  274.  
  275. 4. Presentation language
  276.  
  277.    This document deals with the formatting of data in an external
  278.    representation. The following very basic and somewhat casually
  279.    defined presentation syntax will be used. The syntax draws from
  280.  
  281. Dierks, T.                  Expires September, 1997             [Page 5]
  282. INTERNET-DRAFT                     TLS 1.0                    March 1997
  283.  
  284.    several sources in its structure. Although it resembles the
  285.    programming language "C" in its syntax and XDR [XDR] in both its
  286.    syntax and intent, it would be risky to draw too many parallels. The
  287.    purpose of this presentation language is to document TLS only, not
  288.    to have general application beyond that particular goal.
  289.  
  290. 4.1. Basic block size
  291.  
  292.    The representation of all data items is explicitly specified. The
  293.    basic data block size is one byte (i.e. 8 bits). Multiple byte data
  294.    items are concatenations of bytes, from left to right, from top to
  295.    bottom. From the bytestream a multi-byte item (a numeric in the
  296.    example) is formed (using C notation) by:
  297.  
  298.        value = (byte[0] << 8*(n-1)) | (byte[1] << 8*(n-2)) |
  299.                ... | byte[n-1];
  300.  
  301.    This byte ordering for multi-byte values is the commonplace network
  302.    byte order or big endian format.
  303.  
  304. 4.2. Miscellaneous
  305.  
  306.    Comments begin with "/*" and end with "*/".
  307.  
  308.    Optional components are denoted by enclosing them in "[[ ]]" double
  309.    brackets.
  310.  
  311.    Single byte entities containing uninterpreted data are of type
  312.    opaque.
  313.  
  314. 4.3. Vectors
  315.  
  316.    A vector (single dimensioned array) is a stream of homogeneous data
  317.    elements. The size of the vector may be specified at documentation
  318.    time or left unspecified until runtime. In either case the length
  319.    declares the number of bytes, not the number of elements, in the
  320.    vector. The syntax for specifying a new type T' that is a fixed
  321.    length vector of type T is
  322.  
  323.        T T'[n];
  324.  
  325.    Here T' occupies n bytes in the data stream, where n is a multiple
  326.    of the size of T. The length of the vector is not included in the
  327.    encoded stream.
  328.  
  329.    In the following example, Datum is defined to be three consecutive
  330.    bytes that the protocol does not interpret, while Data is three
  331.    consecutive Datum, consuming a total of nine bytes.
  332.  
  333.        opaque Datum[3];      /* three uninterpreted bytes */
  334.        Datum Data[9];        /* 3 consecutive 3 byte vectors */
  335.  
  336.  
  337. Dierks, T.                  Expires September, 1997             [Page 6]
  338. INTERNET-DRAFT                     TLS 1.0                    March 1997
  339.  
  340.    Variable length vectors are defined by specifying a subrange of
  341.    legal lengths, inclusively, using the notation <floor..ceiling>.
  342.    When encoded, the actual length precedes the vector's contents in
  343.    the byte stream. The length will be in the form of a number
  344.    consuming as many bytes as required to hold the vector's specified
  345.    maximum (ceiling) length. A variable length vector with an actual
  346.    length field of zero is referred to as an empty vector.
  347.  
  348.        T T'<floor..ceiling>;
  349.  
  350.    In the following example, mandatory is a vector that must contain
  351.    between 300 and 400 bytes of type opaque. It can never be empty. The
  352.    actual length field consumes two bytes, a uint16, sufficient to
  353.    represent the value 400 (see Section 4.4). On the other hand, longer
  354.    can represent up to 800 bytes of data, or 400 uint16 elements, and
  355.    it may be empty. Its encoding will include a two byte actual length
  356.    field prepended to the vector.
  357.  
  358.        opaque mandatory<300..400>;
  359.              /* length field is 2 bytes, cannot be empty */
  360.        uint16 longer<0..800>;
  361.              /* zero to 400 16-bit unsigned integers */
  362.  
  363. 4.4. Numbers
  364.  
  365.    The basic numeric data type is an unsigned byte (uint8). All larger
  366.    numeric data types are formed from fixed length series of bytes
  367.    concatenated as described in Section 4.1 and are also unsigned. The
  368.    following numeric types are predefined.
  369.  
  370.        uint8 uint16[2];
  371.        uint8 uint24[3];
  372.        uint8 uint32[4];
  373.        uint8 uint64[8];
  374.  
  375. |  All values, here and elsewhere in the specification, are stored in
  376. |  "network" or "big-endian" order; the uint32 represented by the hex
  377. |  bytes 01 02 03 04 is equivalent to the decimal value 16909060.
  378.  
  379. 4.5. Enumerateds
  380.  
  381.    An additional sparse data type is available called enum. A field of
  382.    type enum can only assume the values declared in the definition.
  383.    Each definition is a different type. Only enumerateds of the same
  384.    type may be assigned or compared. Every element of an enumerated
  385.    must be assigned a value, as demonstrated in the following example.
  386.    Since the elements of the enumerated are not ordered, they can be
  387.    assigned any unique value, in any order.
  388.  
  389.        enum { e1(v1), e2(v2), ... , en(vn), [[(n)]] } Te;
  390.  
  391.  
  392.  
  393. Dierks, T.                  Expires September, 1997             [Page 7]
  394. INTERNET-DRAFT                     TLS 1.0                    March 1997
  395.  
  396.    Enumerateds occupy as much space in the byte stream as would its
  397.    maximal defined ordinal value. The following definition would cause
  398.    one byte to be used to carry fields of type Color.
  399.  
  400.        enum { red(3), blue(5), white(7) } Color;
  401.  
  402.    One may optionally specify a value without its associated tag to
  403.    force the width definition without defining a superfluous element.
  404.    In the following example, Taste will consume two bytes in the data
  405.    stream but can only assume the values 1, 2 or 4.
  406.  
  407.        enum { sweet(1), sour(2), bitter(4), (32000) } Taste;
  408.  
  409.    The names of the elements of an enumeration are scoped within the
  410.    defined type. In the first example, a fully qualified reference to
  411.    the second element of the enumeration would be Color.blue. Such
  412.    qualification is not required if the target of the assignment is
  413.    well specified.
  414.  
  415.        Color color = Color.blue;     /* overspecified, legal */
  416.        Color color = blue;           /* correct, type implicit */
  417.  
  418.    For enumerateds that are never converted to external representation,
  419.    the numerical information may be omitted.
  420.  
  421.        enum { low, medium, high } Amount;
  422.  
  423. 4.6. Constructed types
  424.  
  425.    Structure types may be constructed from primitive types for
  426.    convenience. Each specification declares a new, unique type. The
  427.    syntax for definition is much like that of C.
  428.  
  429.        struct {
  430.          T1 f1;
  431.          T2 f2;
  432.          ...
  433.          Tn fn;
  434.        } [[T]];
  435.  
  436.    The fields within a structure may be qualified using the type's name
  437.    using a syntax much like that available for enumerateds. For
  438.    example, T.f2 refers to the second field of the previous
  439.    declaration. Structure definitions may be embedded.
  440.  
  441. 4.6.1. Variants
  442.  
  443.    Defined structures may have variants based on some knowledge that is
  444.    available within the environment. The selector must be an enumerated
  445.    type that defines the possible variants the structure defines. There
  446.    must be a case arm for every element of the enumeration declared in
  447.    the select. The body of the variant structure may be given a label
  448.  
  449. Dierks, T.                  Expires September, 1997             [Page 8]
  450. INTERNET-DRAFT                     TLS 1.0                    March 1997
  451.  
  452.    for reference. The mechanism by which the variant is selected at
  453.    runtime is not prescribed by the presentation language.
  454.  
  455.        struct {
  456.            T1 f1;
  457.            T2 f2;
  458.            ....
  459.            Tn fn;
  460.            select (E) {
  461.                case e1: Te1;
  462.                case e2: Te2;
  463.                ....
  464.                case en: Ten;
  465.            } [[fv]];
  466.        } [[Tv]];
  467.  
  468.    For example:
  469.  
  470.        enum { apple, orange } VariantTag;
  471.        struct {
  472.            uint16 number;
  473.            opaque string<0..10>; /* variable length */
  474.        } V1;
  475.        struct {
  476.            uint32 number;
  477.            opaque string[10];    /* fixed length */
  478.        } V2;
  479.        struct {
  480.            select (VariantTag) { /* value of selector is implicit */
  481.                case apple: V1;   /* VariantBody, tag = apple */
  482.                case orange: V2;  /* VariantBody, tag = orange */
  483.            } variant_body;       /* optional label on variant */
  484.        } VariantRecord;
  485.  
  486.    Variant structures may be qualified (narrowed) by specifying a value
  487.    for the selector prior to the type. For example, a
  488.  
  489.        orange VariantRecord
  490.  
  491.    is a narrowed type of a VariantRecord containing a variant_body of
  492.    type V2.
  493.  
  494. 4.7. Cryptographic attributes
  495.  
  496.    The four cryptographic operations digital signing, stream cipher
  497.    encryption, block cipher encryption, and public key encryption are
  498.    designated digitally-signed, stream-ciphered, block-ciphered, and
  499.    public-key-encrypted, respectively. A field's cryptographic
  500.    processing is specified by prepending an appropriate key word
  501.    designation before the field's type specification. Cryptographic
  502.    keys are implied by the current session state (see Section 5.1).
  503.  
  504.  
  505. Dierks, T.                  Expires September, 1997             [Page 9]
  506. INTERNET-DRAFT                     TLS 1.0                    March 1997
  507.  
  508.    In digital signing, one-way hash functions are used as input for a
  509.    signing algorithm. In RSA signing, a 36-byte structure of two hashes
  510.    (one SHA and one MD5) is signed (encrypted with the private key). In
  511.    DSS, the 20 bytes of the SHA hash are run directly through the
  512.    Digital Signing Algorithm with no additional hashing. A
  513.    digitally-signed element is encoded as an opaque vector <0..2^16-1>,
  514.    where the length is specified by the signing algorithm and key.
  515.  
  516.    In stream cipher encryption, the plaintext is exclusive-ORed with an
  517.    identical amount of output generated from a cryptographically-secure
  518.    keyed pseudorandom number generator.
  519.  
  520.    In block cipher encryption, every block of plaintext encrypts to a
  521.    block of ciphertext. All block cipher encryption is done in CBC
  522.    (Cipher Block Chaining) mode, and all items which are block-ciphered
  523.    will be an exact multiple of the cipher block length.
  524.  
  525.    In public key encryption, a public key algorithm is used to encrypt
  526.    data in such a way that it can be decrypted only with the matching
  527.    private key. A public-key-encrypted element is encoded as an opaque
  528.    vector <0..2^16-1>, where the length is specified by the signing
  529.    algorithm and key.
  530.  
  531.    In the following example:
  532.  
  533.        stream-ciphered struct {
  534.            uint8 field1;
  535.            uint8 field2;
  536.            digitally-signed opaque hash[20];
  537.        } UserType;
  538.  
  539.    The contents of hash are used as input for the signing algorithm,
  540.    then the entire structure is encrypted with a stream cipher. The
  541.    length of this structure, in bytes would be equal to 2 bytes for
  542.    field1 and field2, plus two bytes for the length of the signature,
  543.    plus the length of the output of the signing algorithm. This is
  544.    known due to the fact that the algorithm and key used for the
  545.    signing are known prior to encoding or decoding this structure.
  546.  
  547. 4.8. Constants
  548.  
  549.    Typed constants can be defined for purposes of specification by
  550.    declaring a symbol of the desired type and assigning values to it.
  551.    Under-specified types (opaque, variable length vectors, and
  552.    structures that contain opaque) cannot be assigned values. No fields
  553.    of a multi-element structure or vector may be elided.
  554.  
  555.    For example,
  556.  
  557.        struct {
  558.            uint8 f1;
  559.            uint8 f2;
  560.  
  561. Dierks, T.                  Expires September, 1997            [Page 10]
  562. INTERNET-DRAFT                     TLS 1.0                    March 1997
  563.  
  564.        } Example1;
  565.  
  566.        Example1 ex1 = {1, 4};  /* assigns f1 = 1, f2 = 4 */
  567.  
  568. 5. The TLS Record Protocol
  569.  
  570.    The TLS Record Protocol is a layered protocol. At each layer,
  571.    messages may include fields for length, description, and content.
  572.    The Record Protocol takes messages to be transmitted, fragments the
  573.    data into manageable blocks, optionally compresses the data, applies
  574.    a MAC, encrypts, and transmits the result. Received data is
  575.    decrypted, verified, decompressed, and reassembled, then delivered
  576.    to higher level clients.
  577.  
  578. |  Four record protocol clients are described in this document: the
  579. |  handshake protocol, the alert protocol, the change cipher spec
  580. |  protocol, and the application data protocol. In order to allow
  581. |  extension of the TLS protocol, additional record types can be
  582. |  supported by the record protocol. Any new record types should
  583. |  allocate type values immediately beyond the ContentType values for
  584. |  the four record types described here (see Appendix A.2). If a TLS
  585. |  implementation receives a record type it does not understand, it
  586. |  should just ignore it. Any protocol designed for use over TLS must
  587. |  be carefully designed to deal with all possible attacks against it.
  588.  
  589. 5.1. Connection states
  590.  
  591.    A TLS connection state is the operating environment of the TLS
  592.    Record Protocol. It specifies a compression algorithm, encryption
  593.    algorithm, and MAC algorithm. In addition, the parameters for these
  594.    algorithms are known: the MAC secret and the bulk encryption keys
  595.    and IVs for the connection in both the read and the write
  596.    directions. Logically, there are always four connection states
  597.    outstanding: the current read and write states, and the pending read
  598.    and write states. All records are processed under the current read
  599.    and write states. The security parameters for the pending states can
  600.    be set by the TLS Handshake Protocol, and the Handshake Protocol can
  601.    selectively make either of the pending states current, in which case
  602.    the appropriate current state is disposed of and replaced with the
  603.    pending state; the pending state is then reinitialized to an empty
  604.    state. It is illegal to make a state which has not been initialized
  605.    with security parameters a current state (although those security
  606.    parameters may specify that no compression, encryption or MAC
  607.    algorithm is to be used). The initial current state always specifies
  608.    that no encryption, compression, or MAC will be used.
  609.  
  610.    The security parameters for a TLS Connection read and write state
  611.    are set by providing the following values:
  612.  
  613.    connection end
  614.        Whether this entity is considered the "client" or the "server"
  615.        in this connection.
  616.  
  617. Dierks, T.                  Expires September, 1997            [Page 11]
  618. INTERNET-DRAFT                     TLS 1.0                    March 1997
  619.  
  620.    bulk encryption algorithm
  621.        An algorithm to be used for bulk encryption. This specification
  622.        includes the key size of this algorithm, how much of that key is
  623.        secret, whether it is a block or stream cipher, the block size
  624.        of the cipher (if appropriate), and whether it is considered an
  625.        "export" cipher.
  626.  
  627.    MAC algorithm
  628.        An algorithm to be used for message authentication. This
  629. |      specification includes the size of the hash which is returned by
  630. |      the MAC algorithm.
  631.  
  632.    compression algorithm
  633.        An algorithm to be used for data compression. This specification
  634.        must include all information the algorithm requires to do
  635.        compression.
  636.  
  637.    master secret
  638.        A 48 byte secret shared between the two peers in the connection.
  639.  
  640.    client random
  641.        A 32 byte value provided by the client.
  642.  
  643.    server random
  644.        A 32 byte value provided by the server.
  645.  
  646.    These parameters are defined in the presentation language as:
  647.  
  648.        enum { server, client } ConnectionEnd;
  649.  
  650.        enum { null, rc4, rc2, des, 3des, des40 } BulkCipherAlgorithm;
  651.  
  652.        enum { stream, block } CipherType;
  653.  
  654.        enum { true, false } IsExportable;
  655.  
  656.        enum { null, md5, sha } MACAlgorithm;
  657.  
  658.        enum { null(0), (255) } CompressionMethod;
  659.  
  660.        /* The algorithms specified in CompressionMethod,
  661.           BulkCipherAlgorithm, and MACAlgorithm may be added to. */
  662.  
  663.        struct {
  664.            ConnectionEnd          entity;
  665.            BulkCipherAlgorithm    bulk_cipher_algorithm;
  666.            CipherType             cipher_type;
  667.            uint8                  key_size;
  668.            uint8                  key_material_length;
  669.            IsExportable           is_exportable;
  670.            MACAlgorithm           mac_algorithm;
  671.            uint8                  hash_size;
  672.  
  673. Dierks, T.                  Expires September, 1997            [Page 12]
  674. INTERNET-DRAFT                     TLS 1.0                    March 1997
  675.  
  676.            CompressionMethod      compression_algorithm;
  677.            opaque                 master_secret[48];
  678.            opaque                 client_random[32];
  679.            opaque                 server_random[32];
  680.        } SecurityParameters;
  681.  
  682.    The record layer will use the security parameters to generate the
  683.    following six items:
  684.  
  685.        client write MAC secret
  686.        server write MAC secret
  687.        client write key
  688.        server write key
  689.        client write IV (for block ciphers only)
  690.        server write IV (for block ciphers only)
  691.  
  692.    The client write parameters are used by the server when receiving
  693.    and processing records and vice-versa. The algorithm used for
  694.    generating these items from the security parameters is described in
  695.    section 5.4.
  696.  
  697.    Once the security parameters have been set and the keys have been
  698.    generated, the connection states can be instantiated by making them
  699.    the current states. These current states must be updated for each
  700.    record processed. Each connection state includes the following
  701.    elements:
  702.  
  703.    compression state
  704.        The current state of the compression algorithm.
  705.  
  706.    cipher state
  707.        The current state of the encryption algorithm. This will consist
  708.        of the scheduled key for that connection. In addition, for block
  709. |      ciphers running in CBC mode, this will initially contain the IV
  710. |      for that connection state and be updated to contain the
  711. |      ciphertext of the last block encrypted or decrypted as records
  712. |      are processed. For block ciphers in other modes, whatever state
  713. |      is necessary to sustain encryption or decryption must be
  714. |      maintained. For stream ciphers, this will contain whatever the
  715. |      necessary state information is to allow the stream to continue
  716. |      to encrypt or decrypt data.
  717.  
  718.    MAC secret
  719.        The MAC secret for this connection as generated above.
  720.  
  721.    sequence number
  722.        Each connection state contains a sequence number, which is
  723.        maintained seperately for read and write states. The sequence
  724.        number must be set to zero whenever a connection state is made
  725.        the active state. Sequence numbers are of type uint64 and may
  726.        not exceed 2^64-1. A sequence number is incremented after each
  727.        record: specifically, the first record which is transmitted
  728.  
  729. Dierks, T.                  Expires September, 1997            [Page 13]
  730. INTERNET-DRAFT                     TLS 1.0                    March 1997
  731.  
  732.        under a particular connection state should use sequence number
  733.        0.
  734.  
  735. 5.2. HMAC and the pseudorandom function
  736.  
  737. |  A number of operations in the TLS record and handshake layer
  738. |  required a keyed MAC; this is a secure digest of some data protected
  739. |  by a secret. Forging the MAC is infeasible without knowledge of the
  740. |  MAC secret. Finding two data messages which have the same MAC is
  741. |  also cryptographically infeasible. The construction we use for this
  742. |  operation is known as HMAC, described in [HMAC].
  743.  
  744. |  HMAC can be used with a variety of different hash algorithms. TLS
  745. ]  uses it in the handshake with two different algorithms: MD5 and
  746. ]  SHA-1, denoting these as HMAC_MD5(secret, data) and HMAC_SHA(secret,
  747. ]  data). Additional hash algorithms can be defined by cipher suites
  748. ]  and used to protect record data, but these hashes are hard coded
  749. ]  into the description of the handshaking for this version of the
  750. ]  protocol.
  751.  
  752. ]  In addition, a construction is required to do expansion of secrets
  753. ]  into blocks of data for the purposes of key generation or
  754. ]  validation. This pseudo-random function (PRF) takes as input a
  755. ]  secret and a seed and produces an output of arbitrary length.
  756.  
  757. ]  In order to make the PRF as secure as possible, it uses two hash
  758. ]  algorithms in a way which should guarantee its security if either
  759. ]  algorithm remains secure.
  760.  
  761. ]  First, we define a data expansion function, P_hash(secret, data)
  762. ]  which uses a single hash function to expand a secret and seed into
  763. ]  an arbitrary quantity of output:
  764.  
  765. ]      P_hash(secret, seed) = HMAC_hash(secret, A(1) + data) +
  766. ]                             HMAC_hash(secret, A(2) + data) +
  767. ]                             HMAC_hash(secret, A(3) + data) + ...
  768.  
  769. ]  Where + indicates concatenation.
  770.  
  771. ]  A() is defined as:
  772. ]      A(0) = seed
  773. ]      A(i) = HMAC_hash(secret, A(i-1))
  774.  
  775. ]  P_hash can be iterated as many times as is necessary to produce the
  776. ]  required quantity of data. For example, if P_SHA-1 was being used to
  777. ]  create 64 bytes of data, it would have to be iterated 4 times
  778. ]  (through A(4)), creating 80 bytes of output data; the last 16 bytes
  779. ]  of the final iteration would then be discarded, leaving 64 bytes of
  780. ]  output data.
  781.  
  782.  
  783.  
  784.  
  785. Dierks, T.                  Expires September, 1997            [Page 14]
  786. INTERNET-DRAFT                     TLS 1.0                    March 1997
  787.  
  788. ]  TLS's PRF is created by splitting the secret into two halves and
  789. ]  using one half to generate data with P_MD5 and the other half to
  790. ]  generate data with P_SHA1, then exclusive-or'ing the outputs of
  791. ]  these two expansion functions together.
  792.  
  793. ]  S1 and S2 are the two halves of the secret and each is the same
  794. ]  length. S1 is taken from the first half of the secret, S2 from the
  795. ]  second half. Their length is created by rounding up the length of
  796. ]  the overall secret divided by two; thus, if the original secret is
  797. ]  an odd number of bytes long, the last byte of S1 will be the same as
  798. ]  the first byte of S2.
  799.  
  800. ]      L_S = length in bytes of secret;
  801. ]      L_S1 = L_S2 = ceil(L_S / 2);
  802.  
  803. ]  The secret is partitioned into two halves (with the possibility of
  804. ]  one shared byte) as described above, S1 taking the first L_S1 bytes
  805. ]  and S2 the last L_S2 bytes.
  806.  
  807. ]  The PRF is then defined as the result of mixing the two pseudorandom
  808. ]  streams by exclusive-or'ing them together.
  809.  
  810. ]      PRF(secret, seed) = P_MD5(S1, seed) XOR P_SHA-1(S2, seed);
  811.  
  812. ]  Note that because MD5 produces 16 byte outputs and SHA-1 produces 20
  813. ]  byte outputs, the boundaries of their internal iterations will not
  814. ]  be aligned; to generate a 80 byte output will involve P_MD5 being
  815. ]  iterated through A(5), while P_SHA-1 will only iterate through A(4).
  816.  
  817. 5.3. Record layer
  818.  
  819.    The TLS Record Layer receives uninterpreted data from higher layers
  820.    in non-empty blocks of arbitrary size.
  821.  
  822. 5.3.1. Fragmentation
  823.  
  824.    The record layer fragments information blocks into TLSPlaintext
  825.    records of 2^14 bytes or less. Client message boundaries are not
  826.    preserved in the record layer (i.e., multiple client messages of the
  827.    same ContentType may be coalesced into a single TLSPlaintext record,
  828.    or may be fragmented across several records).
  829.  
  830.        struct {
  831.            uint8 major, minor;
  832.        } ProtocolVersion;
  833.  
  834.        enum {
  835.            change_cipher_spec(20), alert(21), handshake(22),
  836.            application_data(23), (255)
  837.        } ContentType;
  838.  
  839.  
  840.  
  841. Dierks, T.                  Expires September, 1997            [Page 15]
  842. INTERNET-DRAFT                     TLS 1.0                    March 1997
  843.  
  844.        struct {
  845.            ContentType type;
  846.            ProtocolVersion version;
  847.            uint16 length;
  848.            opaque fragment[TLSPlaintext.length];
  849.        } TLSPlaintext;
  850.  
  851.    type
  852.        The higher level protocol used to process the enclosed fragment.
  853.  
  854.    version
  855.        The version of the protocol being employed. This document
  856. |      describes TLS Version 1.0, which uses the version { 3, 1 }. The
  857. |      version value 3.1 is historical: TLS version 1.0 is a minor
  858. |      modification to the SSL 3.0 protocol, which bears the version
  859. |      value 3.0. (See Appendix A.1.1).
  860.  
  861.    length
  862.        The length (in bytes) of the following TLSPlaintext.fragment.
  863.        The length should not exceed 2^14.
  864.  
  865.    fragment
  866.        The application data. This data is transparent and treated as an
  867.        independent block to be dealt with by the higher level protocol
  868.        specified by the type field.
  869.  
  870.  Note: Data of different TLS Record layer content types may be
  871.        interleaved. Application data is generally of lower precedence
  872.        for transmission than other content types.
  873.  
  874. 5.3.2. Record compression and decompression
  875.  
  876.    All records are compressed using the compression algorithm defined
  877.    in the current session state. There is always an active compression
  878.    algorithm; however, initially it is defined as
  879.    CompressionMethod.null. The compression algorithm translates a
  880.    TLSPlaintext structure into a TLSCompressed structure. Compression
  881.    functions are initialized with default state information whenever a
  882.    connection state is made active.
  883.  
  884.    Compression must be lossless and may not increase the content length
  885.    by more than 1024 bytes. If the decompression function encounters a
  886.    TLSCompressed.fragment that would decompress to a length in excess
  887.    of 2^14 bytes, it should report a fatal decompression failure error.
  888.  
  889.        struct {
  890.            ContentType type;       /* same as TLSPlaintext.type */
  891.            ProtocolVersion version;/* same as TLSPlaintext.version */
  892.            uint16 length;
  893.            opaque fragment[TLSCompressed.length];
  894.        } TLSCompressed;
  895.  
  896.  
  897. Dierks, T.                  Expires September, 1997            [Page 16]
  898. INTERNET-DRAFT                     TLS 1.0                    March 1997
  899.  
  900.    length
  901.        The length (in bytes) of the following TLSCompressed.fragment.
  902.        The length should not exceed 2^14 + 1024.
  903.  
  904.    fragment
  905.        The compressed form of TLSPlaintext.fragment.
  906.  
  907.  Note: A CompressionMethod.null operation is an identity operation; no
  908.        fields are altered.
  909.  
  910.    Implementation note:
  911.        Decompression functions are responsible for ensuring that
  912.        messages cannot cause internal buffer overflows.
  913.  
  914. 5.3.3. Record payload protection
  915.  
  916.    The encryption and MAC functions translate a TLSCompressed structure
  917.    into a TLSCiphertext. The decryption functions reverse the process.
  918.    Transmissions also include a sequence number so that missing,
  919.    altered, or extra messages are detectable.
  920.  
  921.        struct {
  922.            ContentType type;
  923.            ProtocolVersion version;
  924.            uint16 length;
  925.            select (CipherSpec.cipher_type) {
  926.                case stream: GenericStreamCipher;
  927.                case block: GenericBlockCipher;
  928.            } fragment;
  929.        } TLSCiphertext;
  930.  
  931.    type
  932.        The type field is identical to TLSCompressed.type.
  933.  
  934.    version
  935.        The version field is identical to TLSCompressed.version.
  936.  
  937.    length
  938.        The length (in bytes) of the following TLSCiphertext.fragment.
  939.        The length may not exceed 2^14 + 2048.
  940.  
  941.    fragment
  942.        The encrypted form of TLSCompressed.fragment, with the MAC.
  943.  
  944. 5.3.3.1. Null or standard stream cipher
  945.  
  946.    Stream ciphers (including BulkCipherAlgorithm.null - see Appendix
  947.    A.7) convert TLSCompressed.fragment structures to and from stream
  948.    TLSCiphertext.fragment structures.
  949.  
  950.  
  951.  
  952.  
  953. Dierks, T.                  Expires September, 1997            [Page 17]
  954. INTERNET-DRAFT                     TLS 1.0                    March 1997
  955.  
  956.        stream-ciphered struct {
  957.            opaque content[TLSCompressed.length];
  958.            opaque MAC[CipherSpec.hash_size];
  959.        } GenericStreamCipher;
  960.  
  961.    The MAC is generated as:
  962.  
  963. |      HMAC_hash(MAC_write_secret, seq_num + TLSCompressed.version +
  964. |                    TLSCompressed.type + TLSCompressed.length +
  965. |                    TLSCompressed.fragment));
  966.  
  967.    where "+" denotes concatenation.
  968.  
  969.    seq_num
  970.        The sequence number for this record.
  971.  
  972.    hash
  973.        The hashing algorithm specified by
  974.        SecurityParameters.mac_algorithm.
  975.  
  976.    Note that the MAC is computed before encryption. The stream cipher
  977.    encrypts the entire block, including the MAC. For stream ciphers
  978.    that do not use a synchronization vector (such as RC4), the stream
  979.    cipher state from the end of one record is simply used on the
  980.    subsequent packet. If the CipherSuite is TLS_NULL_WITH_NULL_NULL,
  981.    encryption consists of the identity operation (i.e., the data is not
  982.    encrypted and the MAC size is zero implying that no MAC is used).
  983.    TLSCiphertext.length is TLSCompressed.length plus
  984.    CipherSpec.hash_size.
  985.  
  986. 5.3.3.2. CBC block cipher
  987.  
  988.    For block ciphers (such as RC2 or DES), the encryption and MAC
  989.    functions convert TLSCompressed.fragment structures to and from
  990.    block TLSCiphertext.fragment structures.
  991.  
  992.        block-ciphered struct {
  993.            opaque content[TLSCompressed.length];
  994.            opaque MAC[CipherSpec.hash_size];
  995.            uint8 padding[GenericBlockCipher.padding_length];
  996.            uint8 padding_length;
  997.        } GenericBlockCipher;
  998.  
  999.    The MAC is generated as described in Section 5.3.3.1.
  1000.  
  1001.    padding
  1002.        Padding that is added to force the length of the plaintext to be
  1003. |      an even multiple of the block cipher's block length. The padding
  1004. |      may be any length up to 255 bytes long, as long as it results in
  1005. |      the TLSCiphertext.length being an even multiple of the block
  1006. |      length. Lengths longer than necessary might be desirable to
  1007. |      frustrate attacks on a protocol based on analysis of the lengths
  1008.  
  1009. Dierks, T.                  Expires September, 1997            [Page 18]
  1010. INTERNET-DRAFT                     TLS 1.0                    March 1997
  1011.  
  1012. |      of exchanged messages. The padding data must be filled with the
  1013. |      padding length repeated to fill the array.
  1014.  
  1015.    padding_length
  1016.        The length of the padding must be less than the cipher's block
  1017.        length and may be zero. The padding length should be such that
  1018.        the total size of the GenericBlockCipher structure is a multiple
  1019.        of the cipher's block length.
  1020.  
  1021.    The encrypted data length (TLSCiphertext.length) is one more than
  1022.    the sum of TLSCompressed.length, CipherSpec.hash_size, and
  1023.    padding_length.
  1024.  
  1025. Example: If the block length is 8 bytes, the content length
  1026. |        (TLSCompressed.length) is 61 bytes, and the MAC length is 20
  1027. |        bytes, the length before padding is 82 bytes. Thus, the
  1028. |        padding length modulo 8 must be equal to 6 in order to make
  1029. |        the total length an even multiple of 8 bytes (the block
  1030. |        length). The padding length can be 6, 14, 22, and so on,
  1031. |        through 254. If the padding length were the minimum necessary,
  1032. |        6, the padding would be 6 bytes, each containing the value 6.
  1033.  
  1034. |Note: With block ciphers in CBC mode (Cipher Block Chaining) the
  1035.        initialization vector (IV) for the first record is generated
  1036.        with the other keys and secrets when the security parameters are
  1037.        set. The IV for subsequent records is the last ciphertext block
  1038.        from the previous record.
  1039.  
  1040. 5.4. Key calculation
  1041.  
  1042.    The Record Protocol requires an algorithm to generate keys, IVs, and
  1043.    MAC secrets from the security parameters provided by the handshake
  1044.    protocol.
  1045.  
  1046.    The master secret is hashed into a sequence of secure bytes, which
  1047.    are assigned to the MAC secrets, keys, and non-export IVs required
  1048.    by the current connection state (see Appendix A.7). CipherSpecs
  1049.    require a client write MAC secret, a server write MAC secret, a
  1050.    client write key, a server write key, a client write IV, and a
  1051.    server write IV, which are generated from the master secret in that
  1052.    order. Unused values are empty.
  1053.  
  1054.    When generating keys and MAC secrets, the master secret is used as
  1055.    an entropy source, and the random values provide unencrypted salt
  1056.    material and IVs for exportable ciphers.
  1057.  
  1058.    To generate the key material, compute
  1059.  
  1060. ]      key_block = PRF(SecurityParameters.master_secret,
  1061. ]                         SecurityParameters.server_random +
  1062. ]                         SecurityParameters.client_random);
  1063.  
  1064.  
  1065. Dierks, T.                  Expires September, 1997            [Page 19]
  1066. INTERNET-DRAFT                     TLS 1.0                    March 1997
  1067.  
  1068.    until enough output has been generated. Then the key_block is
  1069.    partitioned as follows:
  1070.  
  1071.        client_write_MAC_secret[SecurityParameters.hash_size]
  1072.        server_write_MAC_secret[SecurityParameters.hash_size]
  1073.        client_write_key[SecurityParameters.key_material]
  1074.        server_write_key[SecurityParameters.key_material]
  1075.        client_write_IV[SecurityParameters.IV_size]
  1076.        server_write_IV[SecurityParameters.IV_size]
  1077.  
  1078.    The client_write_IV and server_write_IV are only generated for
  1079.    non-export block ciphers. For exportable block ciphers, the
  1080.    initialization vectors are generated later, as described below. Any
  1081.    extra key_block material is discarded.
  1082.  
  1083.    Implementation note:
  1084.        The cipher spec which is defined in this document which requires
  1085.        the most material is 3DES_EDE_CBC_SHA: it requires 2 x 24 byte
  1086.        keys, 2 x 20 byte MAC secrets, and 2 x 8 byte IVs, for a total
  1087. ]      of 104 bytes of key material.
  1088.  
  1089.    Exportable encryption algorithms (for which CipherSpec.is_exportable
  1090.    is true) require additional processing as follows to derive their
  1091.    final write keys:
  1092.  
  1093. |      final_client_write_key =
  1094. |      PRF(SecurityParameters.client_write_key,
  1095. |                                 SecurityParameters.client_random +
  1096. |                                 SecurityParameters.server_random);
  1097. |      final_server_write_key =
  1098. |      PRF(SecurityParameters.server_write_key,
  1099. |                                 SecurityParameters.client_random +
  1100. |                                 SecurityParameters.server_random);
  1101.  
  1102. |  Exportable encryption algorithms derive their IVs solely from the
  1103. ]  random values from the hello messages:
  1104.  
  1105. |      iv_block = PRF("", SecurityParameters.client_random +
  1106. |                         SecurityParameters.server_random);
  1107.  
  1108. |  The iv_block is partitioned into two initialization vectors as the
  1109. |  key_block was above:
  1110.  
  1111. |      client_write_IV[SecurityParameters.IV_size]
  1112. |      server_write_IV[SecurityParameters.IV_size]
  1113.  
  1114. |  Note that the PRF is used without a secret in this case: this just
  1115. |  means that the secret has a length of zero bytes and contributes
  1116. |  nothing to the hashing in the PRF.
  1117.  
  1118.  
  1119.  
  1120.  
  1121. Dierks, T.                  Expires September, 1997            [Page 20]
  1122. INTERNET-DRAFT                     TLS 1.0                    March 1997
  1123.  
  1124. 5.4.1. Export key generation example
  1125.  
  1126.    TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5 requires five random bytes for
  1127.    each of the two encryption keys and 16 bytes for each of the MAC
  1128. ]  keys, for a total of 42 bytes of key material. The PRF output is
  1129. ]  stored in the key_block. The key_block is partitioned, and the write
  1130. ]  keys are salted because this is an exportable encryption algorithm.
  1131.  
  1132. |      key_block               = PRF(master_secret,
  1133. |                                    master_secret +
  1134. |                                    server_random +
  1135. |                                    client_random)[0..41]
  1136.        client_write_MAC_secret = key_block[0..15]
  1137.        server_write_MAC_secret = key_block[16..31]
  1138.        client_write_key        = key_block[32..36]
  1139.        server_write_key        = key_block[37..41]
  1140. |      final_client_write_key  = PRF(client_write_key,
  1141. |                                    client_random +
  1142. |                                    server_random)[0..15]
  1143. |      final_server_write_key  = PRF(server_write_key,
  1144. |                                    client_random +
  1145. |                                    server_random)[0..15]
  1146. |      iv_block                = PRF("", client_random +
  1147. |                                    server_random)[0..15]
  1148. |      client_write_IV = iv_block[0..7]
  1149. |      server_write_IV = iv_block[8..15]
  1150.  
  1151. 6. The TLS Handshake Protocol
  1152.  
  1153.    The TLS Handshake Protocol consists of a suite of three
  1154.    sub-protocols which are used to allow peers to agree upon security
  1155.    parameters for the record layer, authenticate themselves,
  1156.    instantiate negotiated security parameters, and report error
  1157.    conditions to each other.
  1158.  
  1159.    The Handshake Protocol is responsible for negotiating a session,
  1160.    which consists of the following items:
  1161.  
  1162.    session identifier
  1163.        An arbitrary byte sequence chosen by the server to identify an
  1164.        active or resumable session state.
  1165.  
  1166.    peer certificate
  1167.        X509v3[X509] certificate of the peer. This element of the state
  1168.        may be null.
  1169.  
  1170.    compression method
  1171.        The algorithm used to compress data prior to encryption.
  1172.  
  1173.    cipher spec
  1174.        Specifies the bulk data encryption algorithm (such as null, DES,
  1175.        etc.) and a MAC algorithm (such as MD5 or SHA). It also defines
  1176.  
  1177. Dierks, T.                  Expires September, 1997            [Page 21]
  1178. INTERNET-DRAFT                     TLS 1.0                    March 1997
  1179.  
  1180.        cryptographic attributes such as the hash_size. (See Appendix
  1181.        A.7 for formal definition)
  1182.  
  1183.    master secret
  1184.        48-byte secret shared between the client and server.
  1185.  
  1186.    is resumable
  1187.        A flag indicating whether the session can be used to initiate
  1188.        new connections.
  1189.  
  1190.    These items are then used to create security parameters for use by
  1191.    the Record Layer when protecting application data. Many connections
  1192.    can be instantiated using the same session through the resumption
  1193.    feature of the TLS Handshake Protocol.
  1194.  
  1195. 6.1. Change cipher spec protocol
  1196.  
  1197.    The change cipher spec protocol exists to signal transitions in
  1198.    ciphering strategies. The protocol consists of a single message,
  1199.    which is encrypted and compressed under the current (not the
  1200.    pending) connection state. The message consists of a single byte of
  1201.    value 1.
  1202.  
  1203.        struct {
  1204.            enum { change_cipher_spec(1), (255) } type;
  1205.        } ChangeCipherSpec;
  1206.  
  1207.    The change cipher spec message is sent by both the client and server
  1208.    to notify the receiving party that subsequent records will be
  1209.    protected under the newly negotiated CipherSpec and keys. Reception
  1210.    of this message causes the receiver to instruct the Record Layer to
  1211.    immediately copy the read pending state into the read current state.
  1212.    Immediately after sending this message, the sender should instruct
  1213.    the record layer to make the write pending state the write active
  1214.    state. (See section 5.1.) The change cipher spec message is sent
  1215.    during the handshake after the security parameters have been agreed
  1216.    upon, but before the verifying finished message is sent (see section
  1217.    6.4.9).
  1218.  
  1219. 6.2. Alert protocol
  1220.  
  1221.    One of the content types supported by the TLS Record layer is the
  1222.    alert type. Alert messages convey the severity of the message and a
  1223.    description of the alert. Alert messages with a level of fatal
  1224.    result in the immediate termination of the connection. In this case,
  1225.    other connections corresponding to the session may continue, but the
  1226.    session identifier must be invalidated, preventing the failed
  1227.    session from being used to establish new connections. Like other
  1228.    messages, alert messages are encrypted and compressed, as specified
  1229.    by the current connection state.
  1230.  
  1231.  
  1232.  
  1233. Dierks, T.                  Expires September, 1997            [Page 22]
  1234. INTERNET-DRAFT                     TLS 1.0                    March 1997
  1235.  
  1236.        enum { warning(1), fatal(2), (255) } AlertLevel;
  1237.  
  1238.        enum {
  1239.            close_notify(0),
  1240.            unexpected_message(10),
  1241.            bad_record_mac(20),
  1242. |          decryption_failed(21),
  1243. |          record_overflow(22),
  1244.            decompression_failure(30),
  1245.            handshake_failure(40),
  1246.            no_certificate(41),
  1247.            bad_certificate(42),
  1248.            unsupported_certificate(43),
  1249.            certificate_revoked(44),
  1250.            certificate_expired(45),
  1251.            certificate_unknown(46),
  1252.            illegal_parameter(47),
  1253. |          unknown_ca(48),
  1254. |          access_denied(49),
  1255. |          decode_error(50),
  1256. |          decrypt_error(51),
  1257. |          export_restriction(60),
  1258. |          protocol_version(70),
  1259. |          insufficient_security(71),
  1260. |          internal_error(80),
  1261. |          user_canceled(90),
  1262. |          no_renegotiation(100),
  1263.            (255)
  1264.        } AlertDescription;
  1265.  
  1266.        struct {
  1267.            AlertLevel level;
  1268.            AlertDescription description;
  1269.        } Alert;
  1270.  
  1271. 6.2.1. Closure alerts
  1272.  
  1273.    The client and the server must share knowledge that the connection
  1274.    is ending in order to avoid a truncation attack. Either party may
  1275.    initiate the exchange of closing messages.
  1276.  
  1277.    close_notify
  1278.        This message notifies the recipient that the sender will not
  1279.        send any more messages on this connection. The session becomes
  1280.        unresumable if any connection is terminated without proper
  1281.        close_notify messages with level equal to warning.
  1282.  
  1283.    Either party may initiate a close by sending a close_notify alert.
  1284.    Any data received after a closure alert is ignored.
  1285.  
  1286.  
  1287.  
  1288.  
  1289. Dierks, T.                  Expires September, 1997            [Page 23]
  1290. INTERNET-DRAFT                     TLS 1.0                    March 1997
  1291.  
  1292.    Each party is required to send a close_notify alert before closing
  1293.    the write side of the connection. It is required that the other
  1294.    party respond with a close_notify alert of its own and close down
  1295.    the connection immediately, discarding any pending writes. It is not
  1296.    required for the initiator of the close to wait for the responding
  1297.    close_notify alert before closing the read side of the connection.
  1298.  
  1299.    NB: It is assumed that closing a connection reliably delivers
  1300.        pending data before destroying the transport.
  1301.  
  1302. 6.2.2. Error alerts
  1303.  
  1304.    Error handling in the TLS Handshake protocol is very simple. When an
  1305.    error is detected, the detecting party sends a message to the other
  1306.    party. Upon transmission or receipt of an fatal alert message, both
  1307.    parties immediately close the connection. Servers and clients are
  1308.    required to forget any session-identifiers, keys, and secrets
  1309.    associated with a failed connection. The following error alerts are
  1310.    defined:
  1311.  
  1312.    unexpected_message
  1313.        An inappropriate message was received. This alert is always
  1314.        fatal and should never be observed in communication between
  1315.        proper implementations.
  1316.  
  1317.    bad_record_mac
  1318.        This alert is returned if a record is received with an incorrect
  1319.        MAC. This message is always fatal.
  1320.  
  1321. |  decryption_failed
  1322. |      A TLSCiphertext decrypted in an invalid way: either it wasn`t an
  1323. |      even multiple of the block length or its padding values, when
  1324. |      checked, weren`t correct. This message is always fatal.
  1325.  
  1326. |  record_overflow
  1327. |      A TLSCiphertext record was received which had a length more than
  1328. |      2^14+2048 bytes, or a record decrypted to a TLSCompressed record
  1329. |      with more than 2^14+1024 bytes. This message is always fatal.
  1330.  
  1331.    decompression_failure
  1332.        The decompression function received improper input (e.g. data
  1333.        that would expand to excessive length). This message is always
  1334.        fatal.
  1335.  
  1336.    handshake_failure
  1337.        Reception of a handshake_failure alert message indicates that
  1338.        the sender was unable to negotiate an acceptable set of security
  1339.        parameters given the options available. This is a fatal error.
  1340.  
  1341.    no_certificate
  1342.        A no_certificate alert message may be sent in response to a
  1343.        certification request if no appropriate certificate is
  1344.  
  1345. Dierks, T.                  Expires September, 1997            [Page 24]
  1346. INTERNET-DRAFT                     TLS 1.0                    March 1997
  1347.  
  1348.        available.
  1349.  
  1350.    bad_certificate
  1351.        A certificate was corrupt, contained signatures that did not
  1352.        verify correctly, etc.
  1353.  
  1354.    unsupported_certificate
  1355.        A certificate was of an unsupported type.
  1356.  
  1357.    certificate_revoked
  1358.        A certificate was revoked by its signer.
  1359.  
  1360.    certificate_expired
  1361.        A certificate has expired or is not currently valid.
  1362.  
  1363.    certificate_unknown
  1364.        Some other (unspecified) issue arose in processing the
  1365.        certificate, rendering it unacceptable.
  1366.  
  1367.    illegal_parameter
  1368.        A field in the handshake was out of range or inconsistent with
  1369.        other fields. This is always fatal.
  1370.  
  1371. |  unknown_ca
  1372. |      A valid certificate chain or partial chain was received, but the
  1373. |      certificate was not accepted because the CA certificate could
  1374. |      not be located or couldn`t be matched with a known, trusted CA.
  1375. |      This message is always fatal.
  1376.  
  1377. |  access_denied
  1378. |      A valid certificate was received, but when access control was
  1379. |      applied, the sender decided not to proceed with negotiation.
  1380. |      This message is always fatal.
  1381.  
  1382. |  decode_error
  1383. |      A message could not be decoded because some field was out of the
  1384. |      specified range or the length of the message was incorrect. This
  1385. |      message is always fatal.
  1386.  
  1387. |  export_restriction
  1388. |      A negotiation not in compliance with export restrictions was
  1389. |      detected; for example, attemption to transfer a 1024 bit
  1390. |      ephemeral RSA key for the RSA_EXPORT handshake method. This
  1391. |      message is always fatal.
  1392.  
  1393. |  protocol_version
  1394. |      The protocol version the client has attempted to negotiate is
  1395. |      recognized, but not supported. (For example, old protocol
  1396. |      versions might be avoided for security reasons). This message is
  1397. |      always fatal.
  1398.  
  1399.  
  1400.  
  1401. Dierks, T.                  Expires September, 1997            [Page 25]
  1402. INTERNET-DRAFT                     TLS 1.0                    March 1997
  1403.  
  1404. |  insufficient_security
  1405. |      Returned instead of handshake_failure when a negotiation has
  1406. |      failed specifically because the server requires ciphers more
  1407. |      secure than those supported by the client. This message is
  1408. |      always fatal.
  1409.  
  1410. |  internal_error
  1411. |      An internal error unrelated to the peer or the correctness of
  1412. |      the protocol makes it impossible to continue (such as a memory
  1413. |      allocation failure). This message is always fatal.
  1414.  
  1415. |  user_cancelled
  1416. |      This handshake is being cancelled for some reason unrelated to a
  1417. |      protocol failure. If the user cancels an operation after the
  1418. |      handshake is complete, just closing the connection by sending a
  1419. |      close_notify is more appropriate. This alert should be followed
  1420. |      by a close_notify. This message is generally a warning.
  1421.  
  1422. |  no_renegotiation
  1423. |      Sent by the client in response to a hello request or by the
  1424. |      server in response to a client hello after initial handshaking.
  1425. |      Either of these would normally lead to renegotiation; when that
  1426. |      is not appropriate, the reciepient should respond with this
  1427. |      alert; at that point, the original reqester can decide whether
  1428. |      to proceed with the connection. One case where this would be
  1429. |      appropriate would be where a server has spawned a process to
  1430. |      satisfy a request; the process might receive secuirty parameters
  1431. |      (key length, authentication, etc.) at startup and it might be
  1432. |      difficult to communicate changes to these parameters after that
  1433. |      point. This message is always a warning.
  1434.  
  1435.    For all errors where an alert level is not explicitly specified, the
  1436.    sending party may determine at its discretion whether this is a
  1437.    fatal error or not; if an alert with a level of warning is received,
  1438.    the receiving party may decide at its discretion whether to treat
  1439.    this as a fatal error or not. However, all messages which are
  1440.    transmitted with a level of fatal must be treated as fatal messages.
  1441.  
  1442. 6.3. Handshake Protocol overview
  1443.  
  1444.    The cryptographic parameters of the session state are produced by
  1445.    the TLS Handshake Protocol, which operates on top of the TLS Record
  1446.    Layer. When a TLS client and server first start communicating, they
  1447.    agree on a protocol version, select cryptographic algorithms,
  1448.    optionally authenticate each other, and use public-key encryption
  1449.    techniques to generate shared secrets.
  1450.  
  1451. |  The TLS Handshake Protocol has the following goals:
  1452.  
  1453.      - Exchange hello messages to agree on algorithms, exchange random
  1454.        values, and check for session resumption.
  1455.  
  1456.  
  1457. Dierks, T.                  Expires September, 1997            [Page 26]
  1458. INTERNET-DRAFT                     TLS 1.0                    March 1997
  1459.  
  1460.      - Exchange the necessary cryptographic parameters to allow the
  1461.        client and server to agree on a premaster secret.
  1462.  
  1463.      - Exchange certificates and cryptographic information to allow the
  1464.        client and server to authenticate themselves.
  1465.  
  1466.      - Generate a master secret from the premaster secret and exchanged
  1467.        random values.
  1468.  
  1469.      - Provide security paramers to the record layer.
  1470.  
  1471.      - Allow the client and server to verify that their peer has
  1472.        calculated the same security parameters and that the handshake
  1473.        occured without tampering by an attacker.
  1474.  
  1475. ]  Note that higher layers should not be overly reliant on TLS always
  1476. ]  negotiating the strongest possible connection between two peers:
  1477. ]  there are a number of ways a man in the middle attacker can attempt
  1478. ]  to make two entities drop down to the least secure method they
  1479. ]  support. The protocol has been designed to minimize this risk, but
  1480. ]  there are still attacks available: for example, an attacker could
  1481. ]  block access to the port a secure service runs on, or attempt to get
  1482. ]  the peers to negotiate an unauthenticated connection. The
  1483. ]  fundamental rule is that higher levels must be cognizant of what
  1484. ]  their security requirements are and never transmit information over
  1485. ]  a channel less secure than what they require. The TLS protocol is
  1486. ]  secure, in that any cipher suite offers its promised level of
  1487. ]  security: if you negotiate 3DES with a 1024 bit RSA key exchange
  1488. ]  with a host whose certificate you have verified, you can expect to
  1489. ]  be that secure. However, you should never send data over a link
  1490. ]  encrypted with 40 bit security unless you feel that data is worth no
  1491. ]  more than the effort required to break that encryption.
  1492.  
  1493.    These goals are achieved by the handshake protocol, which can be
  1494.    summarized as follows: The client sends a client hello message to
  1495.    which the server must respond with a server hello message, or else a
  1496.    fatal error will occur and the connection will fail. The client
  1497.    hello and server hello are used to establish security enhancement
  1498.    capabilities between client and server. The client hello and server
  1499.    hello establish the following attributes: Protocol Version, Session
  1500.    ID, Cipher Suite, and Compression Method. Additionally, two random
  1501.    values are generated and exchanged: ClientHello.random and
  1502.    ServerHello.random.
  1503.  
  1504.    The actual key exchange uses up to four messages: the server
  1505.    certificate, the server key exchange, the client certificate, and
  1506.    the client key exchange. New key exchange methods can be created by
  1507.    specifing a format for these messages and defining the use of the
  1508.    messages to allow the client and server to agree upon a shared
  1509.    secret. This secret should be quite long; currently defined key
  1510.    exchange methods exchange secrets which range from 48 to 128 bytes
  1511.    in length.
  1512.  
  1513. Dierks, T.                  Expires September, 1997            [Page 27]
  1514. INTERNET-DRAFT                     TLS 1.0                    March 1997
  1515.  
  1516.    Following the hello messages, the server will send its certificate,
  1517.    if it is to be authenticated. Additionally, a server key exchange
  1518.    message may be sent, if it is required (e.g. if their server has no
  1519.    certificate, or if its certificate is for signing only). If the
  1520.    server is authenticated, it may request a certificate from the
  1521.    client, if that is appropriate to the cipher suite selected. Now the
  1522.    server will send the server hello done message, indicating that the
  1523.    hello-message phase of the handshake is complete. The server will
  1524.    then wait for a client response. If the server has sent a
  1525.    certificate request message, the client must send either the
  1526.    certificate message or a no_certificate alert. The client key
  1527.    exchange message is now sent, and the content of that message will
  1528.    depend on the public key algorithm selected between the client hello
  1529.    and the server hello. If the client has sent a certificate with
  1530.    signing ability, a digitally-signed certificate verify message is
  1531.    sent to explicitly verify the certificate.
  1532.  
  1533.    At this point, a change cipher spec message is sent by the client,
  1534.    and the client copies the pending Cipher Spec into the current
  1535.    Cipher Spec. The client then immediately sends the finished message
  1536.    under the new algorithms, keys, and secrets. In response, the server
  1537.    will send its own change cipher spec message, transfer the pending
  1538.    to the current Cipher Spec, and send its finished message under the
  1539.    new Cipher Spec. At this point, the handshake is complete and the
  1540.    client and server may begin to exchange application layer data. (See
  1541.    flow chart below.)
  1542.  
  1543.       Client                                               Server
  1544.  
  1545.       ClientHello                  -------->
  1546.                                                       ServerHello
  1547.                                                      Certificate*
  1548.                                                ServerKeyExchange*
  1549.                                               CertificateRequest*
  1550.                                    <--------      ServerHelloDone
  1551.       Certificate*
  1552.       ClientKeyExchange
  1553.       CertificateVerify*
  1554.       [ChangeCipherSpec]
  1555.       Finished                     -------->
  1556.                                                [ChangeCipherSpec]
  1557.                                    <--------             Finished
  1558.       Application Data             <------->     Application Data
  1559.  
  1560.    * Indicates optional or situation-dependent messages that are not
  1561.    always sent.
  1562.  
  1563.  Note: To help avoid pipeline stalls, ChangeCipherSpec is an
  1564.        independent TLS Protocol content type, and is not actually a TLS
  1565.        handshake message.
  1566.  
  1567.  
  1568.  
  1569. Dierks, T.                  Expires September, 1997            [Page 28]
  1570. INTERNET-DRAFT                     TLS 1.0                    March 1997
  1571.  
  1572.    When the client and server decide to resume a previous session or
  1573.    duplicate an existing session (instead of negotiating new security
  1574.    parameters) the message flow is as follows:
  1575.  
  1576.    The client sends a ClientHello using the Session ID of the session
  1577.    to be resumed. The server then checks its session cache for a match.
  1578.    If a match is found, and the server is willing to re-establish the
  1579.    connection under the specified session state, it will send a
  1580.    ServerHello with the same Session ID value. At this point, both
  1581.    client and server must send change cipher spec messages and proceed
  1582.    directly to finished messages. Once the re-establishment is
  1583.    complete, the client and server may begin to exchange application
  1584.    layer data. (See flow chart below.) If a Session ID match is not
  1585.    found, the server generates a new session ID and the TLS client and
  1586.    server perform a full handshake.
  1587.  
  1588.       Client                                                Server
  1589.  
  1590.       ClientHello                   -------->
  1591.                                                        ServerHello
  1592.                                                 [ChangeCipherSpec]
  1593.                                     <--------             Finished
  1594.       [ChangeCipherSpec]
  1595.       Finished                      -------->
  1596.       Application Data              <------->     Application Data
  1597.  
  1598.    The contents and significance of each message will be presented in
  1599.    detail in the following sections.
  1600.  
  1601. 6.4. Handshake protocol
  1602.  
  1603.    The TLS Handshake Protocol is one of the defined higher level
  1604.    clients of the TLS Record Protocol. This protocol is used to
  1605.    negotiate the secure attributes of a session. Handshake messages are
  1606.    supplied to the TLS Record Layer, where they are encapsulated within
  1607.    one or more TLSPlaintext structures, which are processed and
  1608.    transmitted as specified by the current active session state.
  1609.  
  1610.        enum {
  1611.            hello_request(0), client_hello(1), server_hello(2),
  1612.            certificate(11), server_key_exchange (12),
  1613.            certificate_request(13), server_hello_done(14),
  1614.            certificate_verify(15), client_key_exchange(16),
  1615.            finished(20), (255)
  1616.        } HandshakeType;
  1617.  
  1618.        struct {
  1619.            HandshakeType msg_type;    /* handshake type */
  1620.            uint24 length;             /* bytes in message */
  1621.            select (HandshakeType) {
  1622.                case hello_request:       HelloRequest;
  1623.                case client_hello:        ClientHello;
  1624.  
  1625. Dierks, T.                  Expires September, 1997            [Page 29]
  1626. INTERNET-DRAFT                     TLS 1.0                    March 1997
  1627.  
  1628.                case server_hello:        ServerHello;
  1629.                case certificate:         Certificate;
  1630.                case server_key_exchange: ServerKeyExchange;
  1631.                case certificate_request: CertificateRequest;
  1632.                case server_hello_done:   ServerHelloDone;
  1633.                case certificate_verify:  CertificateVerify;
  1634.                case client_key_exchange: ClientKeyExchange;
  1635.                case finished:            Finished;
  1636.            } body;
  1637.        } Handshake;
  1638.  
  1639.    The handshake protocol messages are presented in the order they must
  1640.    be sent; sending handshake messages in an unexpected order results
  1641. |  in a fatal error. Unneeded handshake messages can be omitted,
  1642. |  however. The one exception is the Hello request message, which may
  1643. |  be sent by the server at any time.
  1644.  
  1645. 6.4.1. Hello messages
  1646.  
  1647.    The hello phase messages are used to exchange security enhancement
  1648.    capabilities between the client and server. When a new session
  1649.    begins, the Record Layer's connection state encryption, hash, and
  1650.    compression algorithms are initialized to null. The current
  1651.    connection state is used for renegotiation messages.
  1652.  
  1653. 6.4.1.1. Hello request
  1654.  
  1655.    When this message will be sent:
  1656.        The hello request message may be sent by the server at any time.
  1657.  
  1658.    Meaning of this message:
  1659.        Hello request is a simple notification that the client should
  1660.        begin the negotiation process anew by sending a client hello
  1661.        message when convenient. This message will be ignored by the
  1662.        client if the client is currently negotiating a session. This
  1663.        message may be ignored by the client if it does not wish to
  1664.        renegotiate a session. Since handshake messages are intended to
  1665.        have transmission precedence over application data, it is
  1666.        expected that the negotiation will begin before no more than a
  1667.        few records are received from the client. If the server sends a
  1668.        hello request but does not recieve a client hello in response,
  1669.        it may close the connection with a fatal alert.
  1670.  
  1671.    After sending a hello request, servers should not repeat the request
  1672.    until the subsequent handshake negotiation is complete.
  1673.  
  1674.    Structure of this message:
  1675.        struct { } HelloRequest;
  1676.  
  1677.  Note: This message should never be included in the message hashes
  1678.        which are maintained throughout the handshake and used in the
  1679.        finished messages and the certificate verify message.
  1680.  
  1681. Dierks, T.                  Expires September, 1997            [Page 30]
  1682. INTERNET-DRAFT                     TLS 1.0                    March 1997
  1683.  
  1684. 6.4.1.2. Client hello
  1685.  
  1686.    When this message will be sent:
  1687.        When a client first connects to a server it is required to send
  1688.        the client hello as its first message. The client can also send
  1689.        a client hello in response to a hello request or on its own
  1690.        initiative in order to renegotiate the security parameters in an
  1691.        existing connection.
  1692.  
  1693.    Structure of this message:
  1694.        The client hello message includes a random structure, which is
  1695.        used later in the protocol.
  1696.  
  1697.        struct {
  1698.           uint32 gmt_unix_time;
  1699.           opaque random_bytes[28];
  1700.        } Random;
  1701.  
  1702.    gmt_unix_time
  1703.        The current time and date in standard UNIX 32-bit format
  1704.        according to the sender's internal clock. Clocks are not
  1705.        required to be set correctly by the basic TLS Protocol; higher
  1706.        level or application protocols may define additional
  1707.        requirements.
  1708.  
  1709.    random_bytes
  1710.        28 bytes generated by a secure random number generator.
  1711.  
  1712.    The client hello message includes a variable length session
  1713.    identifier. If not empty, the value identifies a session between the
  1714.    same client and server whose security parameters the client wishes
  1715.    to reuse. The session identifier may be from an earlier connection,
  1716.    this connection, or another currently active connection. The second
  1717.    option is useful if the client only wishes to update the random
  1718.    structures and derived values of a connection, while the third
  1719. |  option makes it possible to establish several independent secure
  1720. |  connections without repeating the full handshake protocol. These
  1721. |  independant connections may occur sequentially or simultaneously; a
  1722. |  SessionID becomes valid when the handshake negotiating it completes
  1723. |  with the exchange of Finished messages and persists until removed
  1724. |  due to aging or because a fatal error was encountered on a
  1725. |  connection associated with the session. The actual contents of the
  1726. |  SessionID are defined by the server.
  1727.  
  1728.        opaque SessionID<0..32>;
  1729.  
  1730.    Warning:
  1731. |      Because the SessionID is transmitted without encryption or
  1732. |      immediate MAC protection, servers must not place confidential
  1733. |      information in session identifiers or let the contents of fake
  1734. |      session identifiers cause any breach of security. (Note that the
  1735. |      contents of the handshake as a whole, including the SessionID,
  1736.  
  1737. Dierks, T.                  Expires September, 1997            [Page 31]
  1738. INTERNET-DRAFT                     TLS 1.0                    March 1997
  1739.  
  1740. |      is protected by the Finished messages exchanged at the end of
  1741. |      the handshake.)
  1742.  
  1743.    The CipherSuite list, passed from the client to the server in the
  1744.    client hello message, contains the combinations of cryptographic
  1745.    algorithms supported by the client in order of the client's
  1746.    preference (first choice first). Each CipherSuite defines a key
  1747.    exchange algorithm, a bulk encryption algorithm (including secret
  1748.    key length) and a MAC algorithm. The server will select a cipher
  1749.    suite or, if no acceptable choices are presented, return a handshake
  1750.    failure alert and close the connection.
  1751.  
  1752.        uint8 CipherSuite[2];    /* Cryptographic suite selector */
  1753.  
  1754.    The client hello includes a list of compression algorithms supported
  1755.    by the client, ordered according to the client's preference.
  1756.  
  1757.        enum { null(0), (255) } CompressionMethod;
  1758.  
  1759. ]  It also contains a vendor identification string, intended to
  1760. ]  identify the manufacturer, platform, and/or version of the TLS
  1761. ]  implementation running on the Client. While these are the intended
  1762. ]  uses, this field is not specified and may contain any data thought
  1763. ]  useful by the implementor, or no data at all. This string consists
  1764. ]  of between 0 and 64 ISO Latin 1 characters.
  1765.  
  1766. ]      opaque VendorID<0..64>;  /* Vendor-specified ID string */
  1767.  
  1768.        struct {
  1769.            ProtocolVersion client_version;
  1770.            Random random;
  1771.            SessionID session_id;
  1772.            CipherSuite cipher_suites<2..2^16-1>;
  1773.            CompressionMethod compression_methods<1..2^8-1>;
  1774. ]          VendorID client_vendor;
  1775.        } ClientHello;
  1776.  
  1777.    client_version
  1778.        The version of the TLS protocol by which the client wishes to
  1779.        communicate during this session. This should be the latest
  1780.        (highest valued) version supported by the client. For this
  1781. |      version of the specification, the version will be 3.1 (See
  1782.        Appendix E for details about backward compatibility).
  1783.  
  1784.    random
  1785.        A client-generated random structure.
  1786.  
  1787.    session_id
  1788.        The ID of a session the client wishes to use for this
  1789.        connection. This field should be empty if no session_id is
  1790.        available or the client wishes to generate new security
  1791.        parameters.
  1792.  
  1793. Dierks, T.                  Expires September, 1997            [Page 32]
  1794. INTERNET-DRAFT                     TLS 1.0                    March 1997
  1795.  
  1796.    cipher_suites
  1797.        This is a list of the cryptographic options supported by the
  1798.        client, with the client's first preference first. If the
  1799.        session_id field is not empty (implying a session resumption
  1800.        request) this vector must include at least the cipher_suite from
  1801.        that session. Values are defined in Appendix A.6.
  1802.  
  1803.    compression_methods
  1804.        This is a list of the compression methods supported by the
  1805.        client, sorted by client preference. If the session_id field is
  1806.        not empty (implying a session resumption request) it must
  1807.        include the compression_method from that session. This vector
  1808.        must contain, and all implementations must support,
  1809.        CompressionMethod.null. Thus, a client and server will always be
  1810.        able to agree on a compression method.
  1811.  
  1812. ]  client_vendor
  1813. ]      This freeform string contains ISO Latin 1 characters specifying
  1814. ]      the implementation of TLS being used by the client. This is
  1815. ]      intended solely for compatibility and debugging work and should
  1816. ]      not be used by the server as a part of the protocol.
  1817.  
  1818.    After sending the client hello message, the client waits for a
  1819.    server hello message. Any other handshake message returned by the
  1820.    server except for a hello request is treated as a fatal error.
  1821.  
  1822.    Forward compatibility note:
  1823.        In the interests of forward compatibility, it is permitted for a
  1824.        client hello message to include extra data after the compression
  1825.        methods. This data must be included in the handshake hashes, but
  1826.        must otherwise be ignored. This is the only handshake message
  1827.        for which this is legal; for all other messages, the amount of
  1828.        data in the message must match the description of the message
  1829.        precisely.
  1830.  
  1831. 6.4.1.3. Server hello
  1832.  
  1833.    When this message will be sent:
  1834.        The server will send this message in response to a client hello
  1835.        message when it was able to find an acceptable set of
  1836.        algorithms. If it cannot find such a match, it will respond with
  1837.        a handshake failure alert.
  1838.  
  1839.    Structure of this message:
  1840.        struct {
  1841.            ProtocolVersion server_version;
  1842.            Random random;
  1843.            SessionID session_id;
  1844.            CipherSuite cipher_suite;
  1845.            CompressionMethod compression_method;
  1846. ]          VendorID server_vendor;
  1847.        } ServerHello;
  1848.  
  1849. Dierks, T.                  Expires September, 1997            [Page 33]
  1850. INTERNET-DRAFT                     TLS 1.0                    March 1997
  1851.  
  1852.    server_version
  1853.        This field will contain the lower of that suggested by the
  1854.        client in the client hello and the highest supported by the
  1855. |      server. For this version of the specification, the version is
  1856. |      3.1 (See Appendix E for details about backward compatibility).
  1857.  
  1858.    random
  1859.        This structure is generated by the server and must be different
  1860.        from (and independent of) ClientHello.random.
  1861.  
  1862.    session_id
  1863.        This is the identity of the session corresponding to this
  1864.        connection. If the ClientHello.session_id was non-empty, the
  1865.        server will look in its session cache for a match. If a match is
  1866.        found and the server is willing to establish the new connection
  1867.        using the specified session state, the server will respond with
  1868.        the same value as was supplied by the client. This indicates a
  1869.        resumed session and dictates that the parties must proceed
  1870.        directly to the finished messages. Otherwise this field will
  1871.        contain a different value identifying the new session. The
  1872.        server may return an empty session_id to indicate that the
  1873. ]      session will not be cached and therefore cannot be resumed. If a
  1874. ]      session is resumed, it must be resumed using the same cipher
  1875. ]      suite it was originally negotiated with.
  1876.  
  1877.    cipher_suite
  1878.        The single cipher suite selected by the server from the list in
  1879.        ClientHello.cipher_suites. For resumed sessions this field is
  1880.        the value from the state of the session being resumed.
  1881.  
  1882.    compression_method
  1883.        The single compression algorithm selected by the server from the
  1884.        list in ClientHello.compression_methods. For resumed sessions
  1885.        this field is the value from the resumed session state.
  1886.  
  1887. ]  server_vendor
  1888. ]      This freeform string contains ISO Latin 1 characters specifying
  1889. ]      the implementation of TLS being used by the server. This is
  1890. ]      intended solely for compatibility and debugging work and should
  1891. ]      not be used by the client as a part of the protocol.
  1892.  
  1893. 6.4.2. Server certificate
  1894.  
  1895.    When this message will be sent:
  1896.        The server must send a certificate whenever the agreed-upon key
  1897.        exchange method is not an anonymous one. This message will
  1898.        always immediately follow the server hello message.
  1899.  
  1900.    Meaning of this message:
  1901.        The certificate type must be appropriate for the selected cipher
  1902.        suite's key exchange algorithm, and is generally an X.509v3
  1903.        certificate. It must contain a key which matches the key
  1904.  
  1905. Dierks, T.                  Expires September, 1997            [Page 34]
  1906. INTERNET-DRAFT                     TLS 1.0                    March 1997
  1907.  
  1908.        exchange method, as follows. Unless otherwise specified, the
  1909.        signing algorithm for the certificate must be the same as the
  1910.        algorithm for the certificate key. Unless otherwise specified,
  1911.        the public key may be of any length.
  1912.  
  1913.        Key Exchange Algorithm  Certificate Key Type
  1914.  
  1915.        RSA                     RSA public key; the certificate must
  1916.                                allow the key to be used for encryption.
  1917.  
  1918.        RSA_EXPORT              RSA public key of length greater than
  1919.                                512 bits which can be used for signing,
  1920.                                or a key of 512 bits or shorter which
  1921.                                Can be used for encryption or signing.
  1922.  
  1923.        DHE_DSS                 DSS public key.
  1924.  
  1925.        DHE_DSS_EXPORT          DSS public key.
  1926.  
  1927.        DHE_RSA                 RSA public key which can be used for
  1928.                                signing.
  1929.  
  1930.        DHE_RSA_EXPORT          RSA public key which can be used for
  1931.                                signing.
  1932.  
  1933.        DH_DSS                  Diffie-Hellman key. The algorithm used
  1934.                                to sign the certificate should be DSS.
  1935.  
  1936.        DH_RSA                  Diffie-Hellman key. The algorithm used
  1937.                                to sign the certificate should be RSA.
  1938.  
  1939. ]  All certificate profiles, key and cryptographic formats are defined
  1940. ]  by the IETF PKIX working group [PKIX].
  1941.  
  1942.    As CipherSuites which specify new key exchange methods are specified
  1943.    for the TLS Protocol, they will imply certificate format and the
  1944.    required encoded keying information.
  1945.  
  1946.    Structure of this message:
  1947.        opaque ASN.1Cert<1..2^24-1>;
  1948.        struct {
  1949.            ASN.1Cert certificate_list<0..2^24-1>;
  1950.        } Certificate;
  1951.  
  1952.    certificate_list
  1953. |      This is a sequence (chain) of X.509v3 certificates. The sender's
  1954. |      certificate must come first in the list. Each following
  1955. |      certificate must directly certify the one preceding it. Because
  1956. |      certificate validation requires that root keys be distributed
  1957. |      independantly, the self-signed certificate which specifies the
  1958. |      root certificate authority may optionally be omitted from the
  1959. |      chain, under the assumption that the remote end must already
  1960.  
  1961. Dierks, T.                  Expires September, 1997            [Page 35]
  1962. INTERNET-DRAFT                     TLS 1.0                    March 1997
  1963.  
  1964. |      possess it in order to validate it in any case.
  1965.  
  1966.    The same message type and structure will be used for the client's
  1967. |  response to a certificate request message. Note that a client may
  1968. |  send no certificates if it does not have an appropriate certificate
  1969. |  to send in response to the server's authentication request.
  1970.  
  1971.  Note: PKCS #7 [PKCS7] is not used as the format for the certificate
  1972.        vector because PKCS #6 [PKCS6] extended certificates are not
  1973.        used. Also PKCS #7 defines a SET rather than a SEQUENCE, making
  1974.        the task of parsing the list more difficult.
  1975.  
  1976. 6.4.3. Server key exchange message
  1977.  
  1978.    When this message will be sent:
  1979. |      This message will be sent immediately after the server
  1980. |      certificate message (or the server hello message, if this is an
  1981. |      anonymous negotiation).
  1982.  
  1983.        The server key exchange message is sent by the server only when
  1984.        the server certificate message (if sent) does not contain enough
  1985.        data to allow the client to exchange a premaster secret. This is
  1986.        true for the following key exchange methods:
  1987.  
  1988.            RSA_EXPORT (if the public key in the server certificate is
  1989.            longer than 512 bits)
  1990.            DHE_DSS
  1991.            DHE_DSS_EXPORT
  1992.            DHE_RSA
  1993.            DHE_RSA_EXPORT
  1994.            DH_anon
  1995.  
  1996.        It is not legal to send the server key exchange message for the
  1997.        following key exchange methods:
  1998.  
  1999.            RSA
  2000.            RSA_EXPORT (when the public key in the server certificate is
  2001.            less than or equal to 512 bits in length)
  2002.            DH_DSS
  2003.            DH_RSA
  2004.  
  2005.    Meaning of this message:
  2006.        This message conveys cryptographic information to allow the
  2007.        client to communicate the premaster secret: either an RSA public
  2008.        key to encrypt the premaster secret with, or a Diffie-Hellman
  2009.        public key with which the client can complete a key exchange
  2010.        (with the result being the premaster secret.)
  2011.  
  2012.    As additional CipherSuites are defined for TLS which include new key
  2013.    exchange algorithms, the server key exchange message will be sent if
  2014.    and only if the certificate type associated with the key exchange
  2015.    algorithm does not provide enough information for the client to
  2016.  
  2017. Dierks, T.                  Expires September, 1997            [Page 36]
  2018. INTERNET-DRAFT                     TLS 1.0                    March 1997
  2019.  
  2020.    exchange a premaster secret.
  2021.  
  2022.  Note: According to current US export law, RSA moduli larger than 512
  2023.        bits may not be used for key exchange in software exported from
  2024.        the US. With this message, the larger RSA keys encoded in
  2025.        certificates may be used to sign temporary shorter RSA keys for
  2026.        the RSA_EXPORT key exchange method.
  2027.  
  2028.    Structure of this message:
  2029.        enum { rsa, diffie_hellman } KeyExchangeAlgorithm;
  2030.  
  2031.        struct {
  2032.            opaque rsa_modulus<1..2^16-1>;
  2033.            opaque rsa_exponent<1..2^16-1>;
  2034.        } ServerRSAParams;
  2035.  
  2036.        rsa_modulus
  2037.            The modulus of the server's temporary RSA key.
  2038.  
  2039.        rsa_exponent
  2040.            The public exponent of the server's temporary RSA key.
  2041.  
  2042.        struct {
  2043.            opaque dh_p<1..2^16-1>;
  2044.            opaque dh_g<1..2^16-1>;
  2045.            opaque dh_Ys<1..2^16-1>;
  2046.        } ServerDHParams;     /* Ephemeral DH parameters */
  2047.  
  2048.        dh_p
  2049.            The prime modulus used for the Diffie-Hellman operation.
  2050.  
  2051.        dh_g
  2052.            The generator used for the Diffie-Hellman operation.
  2053.  
  2054.        dh_Ys
  2055.            The server's Diffie-Hellman public value (g^X mod p).
  2056.  
  2057.        struct {
  2058.            select (KeyExchangeAlgorithm) {
  2059.                case diffie_hellman:
  2060.                    ServerDHParams params;
  2061.                    Signature signed_params;
  2062.                case rsa:
  2063.                    ServerRSAParams params;
  2064.                    Signature signed_params;
  2065.            };
  2066.        } ServerKeyExchange;
  2067.  
  2068.        params
  2069.            The server's key exchange parameters.
  2070.  
  2071.  
  2072.  
  2073. Dierks, T.                  Expires September, 1997            [Page 37]
  2074. INTERNET-DRAFT                     TLS 1.0                    March 1997
  2075.  
  2076.        signed_params
  2077.            For non-anonymous key exchanges, a hash of the corresponding
  2078.            params value, with the signature appropriate to that hash
  2079.            applied.
  2080.  
  2081.        md5_hash
  2082.            MD5(ClientHello.random + ServerHello.random + ServerParams);
  2083.  
  2084.        sha_hash
  2085.            SHA(ClientHello.random + ServerHello.random + ServerParams);
  2086.  
  2087.        enum { anonymous, rsa, dsa } SignatureAlgorithm;
  2088.  
  2089.        select (SignatureAlgorithm)
  2090.        {   case anonymous: struct { };
  2091.            case rsa:
  2092.                digitally-signed struct {
  2093.                    opaque md5_hash[16];
  2094.                    opaque sha_hash[20];
  2095.                };
  2096.            case dsa:
  2097.                digitally-signed struct {
  2098.                    opaque sha_hash[20];
  2099.                };
  2100.        } Signature;
  2101.  
  2102. 6.4.4. Certificate request
  2103.  
  2104.    When this message will be sent:
  2105.        A non-anonymous server can optionally request a certificate from
  2106. |      the client, if appropriate for the selected cipher suite. This
  2107. |      message, if sent, will immediately follow the Server Key
  2108. |      Exchange message (if it is sent; otherwise, the Server
  2109. |      Certificate message).
  2110.  
  2111. ]  Structure of this message:
  2112. ]      enum {
  2113. ]          rsa_sign(1), dss_sign(2), rsa_fixed_dh(3), dss_fixed_dh(4),
  2114.            (255)
  2115.        } ClientCertificateType;
  2116.  
  2117.        opaque DistinguishedName<1..2^16-1>;
  2118.  
  2119.        struct {
  2120.            ClientCertificateType certificate_types<1..2^8-1>;
  2121.            DistinguishedName certificate_authorities<3..2^16-1>;
  2122.        } CertificateRequest;
  2123.  
  2124.        certificate_types
  2125.            This field is a list of the types of certificates requested,
  2126.            sorted in order of the server's preference.
  2127.  
  2128.  
  2129. Dierks, T.                  Expires September, 1997            [Page 38]
  2130. INTERNET-DRAFT                     TLS 1.0                    March 1997
  2131.  
  2132.        certificate_authorities
  2133.            A list of the distinguished names of acceptable certificate
  2134. |          authorities. These distinguished names may specify a desired
  2135. |          distinguished name for a root CA or for a subordinate CA;
  2136. |          thus, this message can be used both to describe known roots
  2137. |          and a desired authorization space.
  2138.  
  2139.  Note: DistinguishedName is derived from [X509].
  2140.  
  2141.  Note: It is a fatal handshake_failure alert for an anonymous server to
  2142.        request client identification.
  2143.  
  2144. 6.4.5. Server hello done
  2145.  
  2146.    When this message will be sent:
  2147.        The server hello done message is sent by the server to indicate
  2148.        the end of the server hello and associated messages. After
  2149.        sending this message the server will wait for a client response.
  2150.  
  2151.    Meaning of this message:
  2152.        This message means that the server is done sending messages to
  2153.        support the key exchange, and the client can proceed with its
  2154.        phase of the key exchange.
  2155.  
  2156.        Upon receipt of the server hello done message the client should
  2157.        verify that the server provided a valid certificate if required
  2158.        and check that the server hello parameters are acceptable.
  2159.  
  2160.    Structure of this message:
  2161.        struct { } ServerHelloDone;
  2162.  
  2163. 6.4.6. Client certificate
  2164.  
  2165.    When this message will be sent:
  2166.        This is the first message the client can send after receiving a
  2167.        server hello done message. This message is only sent if the
  2168.        server requests a certificate. If no suitable certificate is
  2169. |      available, the client should send a certificate message
  2170. |      containing no certificates. If client authentication is required
  2171. |      by the server for the handshake to continue, it may respond with
  2172. |      a fatal handshake failure alert. Client certificates are sent
  2173. |      using the Certificate structure defined in Section 6.4.2.
  2174.  
  2175.  Note: When using a static Diffie-Hellman based key exchange method
  2176.        (DH_DSS or DH_RSA), if client authentication is requested, the
  2177.        Diffie-Hellman group and generator encoded in the client's
  2178.        certificate must match the server specified Diffie-Hellman
  2179.        parameters if the client's parameters are to be used for the key
  2180.        exchange.
  2181.  
  2182.  
  2183.  
  2184.  
  2185. Dierks, T.                  Expires September, 1997            [Page 39]
  2186. INTERNET-DRAFT                     TLS 1.0                    March 1997
  2187.  
  2188. 6.4.7. Client key exchange message
  2189.  
  2190.    When this message will be sent:
  2191.        This message is always sent by the client. It will immediately
  2192. |      follow the client certificate message, if it is sent. Otherwise
  2193. |      it will be the first message sent by the client after it
  2194. |      receives the server hello done message.
  2195.  
  2196.    Meaning of this message:
  2197.        With this message, the premaster secret is set, either though
  2198.        direct transmisson of the RSA-encrypted secret, or by the
  2199.        transmission of Diffie-Hellman parameters which will allow each
  2200.        side to agree upon the same premaster secret. When the key
  2201.        exchange method is DH_RSA or DH_DSS, client certification has
  2202.        been requested, and the client was able to respond with a
  2203.        certificate which contained a Diffie-Hellman public key whose
  2204.        parameters (group and generator) matched those specified by the
  2205.        server in its certificate, this message will not contain any
  2206.        data.
  2207.  
  2208.    Structure of this message:
  2209.        The choice of messages depends on which key exchange method has
  2210.        been selected. See Section 6.4.3 for the KeyExchangeAlgorithm
  2211.        definition.
  2212.  
  2213.        struct {
  2214.            select (KeyExchangeAlgorithm) {
  2215.                case rsa: EncryptedPreMasterSecret;
  2216.                case diffie_hellman: ClientDiffieHellmanPublic;
  2217.            } exchange_keys;
  2218.        } ClientKeyExchange;
  2219.  
  2220. 6.4.7.1. RSA encrypted premaster secret message
  2221.  
  2222.    Meaning of this message:
  2223.        If RSA is being used for key agreement and authentication, the
  2224.        client generates a 48-byte premaster secret, encrypts it using
  2225.        the public key from the server's certificate or the temporary
  2226.        RSA key provided in a server key exchange message, and sends the
  2227.        result in an encrypted premaster secret message. This structure
  2228.        is a variant of the client key exchange message, not a message
  2229.        in itself.
  2230.  
  2231.    Structure of this message:
  2232.        struct {
  2233.            ProtocolVersion client_version;
  2234.            opaque random[46];
  2235.        } PreMasterSecret;
  2236.  
  2237.        client_version
  2238.            The latest (newest) version supported by the client. This is
  2239. |          used to detect version roll-back attacks. Upon receiving the
  2240.  
  2241. Dierks, T.                  Expires September, 1997            [Page 40]
  2242. INTERNET-DRAFT                     TLS 1.0                    March 1997
  2243.  
  2244. |          premaster secret, the server should check that this value
  2245. |          matches the value transmitted by the client in the client
  2246. |          hello message.
  2247.  
  2248.        random
  2249.            46 securely-generated random bytes.
  2250.  
  2251.        struct {
  2252.            public-key-encrypted PreMasterSecret pre_master_secret;
  2253.        } EncryptedPreMasterSecret;
  2254.  
  2255.        pre_master_secret
  2256.            This random value is generated by the client and is used to
  2257.            generate the master secret, as specified in Section 7.1.
  2258.  
  2259. 6.4.7.2. Client Diffie-Hellman public value
  2260.  
  2261.    Meaning of this message:
  2262.        This structure conveys the client's Diffie-Hellman public value
  2263.        (Yc) if it was not already included in the client's certificate.
  2264.        The encoding used for Yc is determined by the enumerated
  2265.        PublicValueEncoding. This structure is a variant of the client
  2266.        key exchange message, not a message in itself.
  2267.  
  2268.    Structure of this message:
  2269.        enum { implicit, explicit } PublicValueEncoding;
  2270.  
  2271.        implicit
  2272.            If the client certificate already contains a suitable
  2273.            Diffie-Hellman key, then Yc is implicit and does not need to
  2274. |          be sent again. In this case, the Client Key Exchange message
  2275. |          will be sent, but will be empty.
  2276.  
  2277.        explicit
  2278.            Yc needs to be sent.
  2279.  
  2280.        struct {
  2281.            select (PublicValueEncoding) {
  2282.                case implicit: struct { };
  2283.                case explicit: opaque dh_Yc<1..2^16-1>;
  2284.            } dh_public;
  2285.        } ClientDiffieHellmanPublic;
  2286.  
  2287.        dh_Yc
  2288.            The client's Diffie-Hellman public value (Yc).
  2289.  
  2290. 6.4.8. Certificate verify
  2291.  
  2292.    When this message will be sent:
  2293.        This message is used to provide explicit verification of a
  2294.        client certificate. This message is only sent following a client
  2295.        certificate that has signing capability (i.e. all certificates
  2296.  
  2297. Dierks, T.                  Expires September, 1997            [Page 41]
  2298. INTERNET-DRAFT                     TLS 1.0                    March 1997
  2299.  
  2300.        except those containing fixed Diffie-Hellman parameters). When
  2301.        sent, it will immediately follow the client key exchange
  2302.        message.
  2303.  
  2304.    Structure of this message:
  2305.        struct {
  2306.             Signature signature;
  2307.        } CertificateVerify;
  2308.  
  2309.        The Signature type is defined in 6.4.3.
  2310.  
  2311.        CertificateVerify.signature.md5_hash
  2312. |          HMAC_MD5(master_secret, handshake_messages);
  2313.  
  2314.        Certificate.signature.sha_hash
  2315. |          HMAC_SHA(master_secret, handshake_messages);
  2316.  
  2317.    Here handshake_messages refers to all handshake messages sent or
  2318.    received starting at client hello up to but not including this
  2319.    message, including the type and length fields of the handshake
  2320.    messages. This is the concatenation of all the Handshake structures
  2321.    as defined in 6.4 exchanged thus far.
  2322.  
  2323. 6.4.9. Finished
  2324.  
  2325.    When this message will be sent:
  2326.        A finished message is always sent immediately after a change
  2327.        cipher spec message to verify that the key exchange and
  2328.        authentication processes were successful. It is essential that a
  2329.        change cipher spec message be received between the other
  2330.        handshake messages and the Finished message.
  2331.  
  2332.    Meaning of this message:
  2333.        The finished message is the first protected with the
  2334. ]      just-negotiated algorithms, keys, and secrets. Recipients of
  2335. ]      finished messages must verify that the contents are correct.
  2336. ]      Once a side has sent its Finished message and received and
  2337. ]      validated the Finished message from its peer, it may begin to
  2338. ]      send and receive application data over the connection.
  2339.  
  2340.        enum { client(0x434C4E54), server(0x53525652) } Sender;
  2341.  
  2342.        struct {
  2343.            opaque md5_hash[16];
  2344.            opaque sha_hash[20];
  2345.        } Finished;
  2346.  
  2347.        md5_hash
  2348. |          HMAC_MD5(master_secret, handshake_messages + Sender);
  2349.  
  2350.  
  2351.  
  2352.  
  2353. Dierks, T.                  Expires September, 1997            [Page 42]
  2354. INTERNET-DRAFT                     TLS 1.0                    March 1997
  2355.  
  2356.        sha_hash
  2357. |          HMAC_SHA(master_secret, handshake_messages + Sender);
  2358.  
  2359.        handshake_messages
  2360.            All of the data from all handshake messages up to but not
  2361.            including this message. This is only data visible at the
  2362.            handshake layer and does not include record layer headers.
  2363.            This is the concatenation of all the Handshake structures as
  2364.            defined in 6.4 exchanged thus far.
  2365.  
  2366.    It is a fatal error if a finished message is not preceeded by a
  2367.    change cipher spec message at the appropriate point in the
  2368.    handshake.
  2369.  
  2370.    The hash contained in finished messages sent by the server
  2371.    incorporate Sender.server; those sent by the client incorporate
  2372.    Sender.client. The value handshake_messages includes all handshake
  2373.    messages starting at client hello up to, but not including, this
  2374.    finished message. This may be different from handshake_messages in
  2375.    Section 6.4.8 because it would include the certificate verify
  2376.    message (if sent). Also, the handshake_messages for the finished
  2377.    message sent by the client will be different from that for the
  2378.    finished message sent by the server, because the one which is sent
  2379.    second will include the prior one.
  2380.  
  2381.  Note: Change cipher spec messages are not handshake messages and are
  2382. |      not included in the hash computations. Also, Hello Request
  2383. |      messages are omitted from handshake hashes.
  2384.  
  2385. 7. Cryptographic computations
  2386.  
  2387.    In order to begin connection protection, the TLS Record Protocol
  2388.    requires specification of a suite of algorithms, a master secret,
  2389.    and the client and server random values. The authentication,
  2390.    encryption, and MAC algorithms are determined by the cipher_suite
  2391.    selected by the server and revealed in the server hello message. The
  2392.    compression algorithm is negotiated in the hello messages, and the
  2393.    random values are exchanged in the hello messages. All that remains
  2394.    is to calculate the master secret.
  2395.  
  2396. 7.1. Computing the master secret
  2397.  
  2398.    For all key exchange methods, the same algorithm is used to convert
  2399.    the pre_master_secret into the master_secret. The pre_master_secret
  2400.    should be deleted from memory once the master_secret has been
  2401.    computed.
  2402.  
  2403. ]      master_secret = PRF(pre_master_secret,
  2404. ]                          ClientHello.random + ServerHello.random);
  2405.  
  2406.  
  2407.  
  2408.  
  2409. Dierks, T.                  Expires September, 1997            [Page 43]
  2410. INTERNET-DRAFT                     TLS 1.0                    March 1997
  2411.  
  2412.    The master secret is always exactly 48 bytes in length. The length
  2413.    of the premaster secret will vary depending on key exchange method.
  2414.  
  2415. 7.1.1. RSA
  2416.  
  2417.    When RSA is used for server authentication and key exchange, a
  2418.    48-byte pre_master_secret is generated by the client, encrypted
  2419.    under the server's public key, and sent to the server. The server
  2420.    uses its private key to decrypt the pre_master_secret. Both parties
  2421.    then convert the pre_master_secret into the master_secret, as
  2422.    specified above.
  2423.  
  2424.    RSA digital signatures are performed using PKCS #1 [PKCS1] block
  2425.    type 1. RSA public key encryption is performed using PKCS #1 block
  2426.    type 2.
  2427.  
  2428. 7.1.2. Diffie-Hellman
  2429.  
  2430.    A conventional Diffie-Hellman computation is performed. The
  2431.    negotiated key (Z) is used as the pre_master_secret, and is
  2432.    converted into the master_secret, as specified above.
  2433.  
  2434.  Note: Diffie-Hellman parameters are specified by the server, and may
  2435.        be either ephemeral or contained within the server's
  2436.        certificate.
  2437.  
  2438. 8. Application data protocol
  2439.  
  2440.    Application data messages are carried by the Record Layer and are
  2441.    fragmented, compressed and encrypted based on the current connection
  2442.    state. The messages are treated as transparent data to the record
  2443.    layer.
  2444.  
  2445. A. Protocol constant values
  2446.  
  2447.    This section describes protocol types and constants.
  2448.  
  2449. A.1. Reserved port assignments
  2450.  
  2451.    At the present time TLS is implemented using TCP/IP as the base
  2452. |  networking technology, although the protocol should be useful over
  2453. |  any transport which can provide a reliable stream connection. The
  2454.    IANA reserved the following Internet Protocol [IP] port numbers for
  2455.    use in conjunction with the SSL 3.0 Protocol, which we presume will
  2456.    be used by TLS as well.
  2457.  
  2458.    443 Reserved for use by Hypertext Transfer Protocol with SSL (https)
  2459.  
  2460.    465 Reserved for use by Simple Mail Transfer Protocol with SSL
  2461.        (ssmtp).
  2462.  
  2463.  
  2464.  
  2465. Dierks, T.                  Expires September, 1997            [Page 44]
  2466. INTERNET-DRAFT                     TLS 1.0                    March 1997
  2467.  
  2468.    563 Reserved for use by Network News Transfer Protocol with SSL
  2469.        (snntp).
  2470.  
  2471.    636 Reserved for Light Directory Access Protocol with SSL (ssl-ldap)
  2472.  
  2473.    990 Reserved (pending) for File Transfer Protocol with SSL (ftps)
  2474.  
  2475.    995 Reserved for Post Office Protocol with SSL (spop3)
  2476.  
  2477. A.2. Record layer
  2478.  
  2479.     struct {
  2480.         uint8 major, minor;
  2481.     } ProtocolVersion;
  2482.  
  2483. |   ProtocolVersion version = { 3, 1 };     /* TLS v1.0 */
  2484.  
  2485.     enum {
  2486.         change_cipher_spec(20), alert(21), handshake(22),
  2487.         application_data(23), (255)
  2488.     } ContentType;
  2489.  
  2490.     struct {
  2491.         ContentType type;
  2492.         ProtocolVersion version;
  2493.         uint16 length;
  2494.         opaque fragment[TLSPlaintext.length];
  2495.     } TLSPlaintext;
  2496.  
  2497.     struct {
  2498.         ContentType type;
  2499.         ProtocolVersion version;
  2500.         uint16 length;
  2501.         opaque fragment[TLSCompressed.length];
  2502.     } TLSCompressed;
  2503.  
  2504.     struct {
  2505.         ContentType type;
  2506.         ProtocolVersion version;
  2507.         uint16 length;
  2508.         select (CipherSpec.cipher_type) {
  2509.             case stream: GenericStreamCipher;
  2510.             case block:  GenericBlockCipher;
  2511.         } fragment;
  2512.     } TLSCiphertext;
  2513.  
  2514.     stream-ciphered struct {
  2515.         opaque content[TLSCompressed.length];
  2516.         opaque MAC[CipherSpec.hash_size];
  2517.     } GenericStreamCipher;
  2518.  
  2519.     block-ciphered struct {
  2520.  
  2521. Dierks, T.                  Expires September, 1997            [Page 45]
  2522. INTERNET-DRAFT                     TLS 1.0                    March 1997
  2523.  
  2524.         opaque content[TLSCompressed.length];
  2525.         opaque MAC[CipherSpec.hash_size];
  2526.         uint8 padding[GenericBlockCipher.padding_length];
  2527.         uint8 padding_length;
  2528.     } GenericBlockCipher;
  2529.  
  2530. A.3. Change cipher specs message
  2531.  
  2532.     struct {
  2533.         enum { change_cipher_spec(1), (255) } type;
  2534.     } ChangeCipherSpec;
  2535.  
  2536. A.4. Alert messages
  2537.  
  2538.     enum { warning(1), fatal(2), (255) } AlertLevel;
  2539.  
  2540.     enum {
  2541.         close_notify(0),
  2542.         unexpected_message(10),
  2543.         bad_record_mac(20),
  2544.         decompression_failure(30),
  2545.         handshake_failure(40),
  2546.         no_certificate(41),
  2547.         bad_certificate(42),
  2548.         unsupported_certificate(43),
  2549.         certificate_revoked(44),
  2550.         certificate_expired(45),
  2551.         certificate_unknown(46),
  2552.         illegal_parameter (47),
  2553.         (255)
  2554.     } AlertDescription;
  2555.  
  2556.     struct {
  2557.         AlertLevel level;
  2558.         AlertDescription description;
  2559.     } Alert;
  2560.  
  2561. A.5. Handshake protocol
  2562.  
  2563.     enum {
  2564.         hello_request(0), client_hello(1), server_hello(2),
  2565.         certificate(11), server_key_exchange (12),
  2566.         certificate_request(13), server_done(14),
  2567.         certificate_verify(15), client_key_exchange(16),
  2568.         finished(20), (255)
  2569.     } HandshakeType;
  2570.  
  2571.     struct {
  2572.         HandshakeType msg_type;
  2573.         uint24 length;
  2574.         select (HandshakeType) {
  2575.             case hello_request: HelloRequest;
  2576.  
  2577. Dierks, T.                  Expires September, 1997            [Page 46]
  2578. INTERNET-DRAFT                     TLS 1.0                    March 1997
  2579.  
  2580.             case client_hello: ClientHello;
  2581.             case server_hello: ServerHello;
  2582.             case certificate: Certificate;
  2583.             case server_key_exchange: ServerKeyExchange;
  2584.             case certificate_request: CertificateRequest;
  2585.             case server_done: ServerHelloDone;
  2586.             case certificate_verify: CertificateVerify;
  2587.             case client_key_exchange: ClientKeyExchange;
  2588.             case finished: Finished;
  2589.         } body;
  2590.     } Handshake;
  2591.  
  2592. A.5.1. Hello messages
  2593.  
  2594.     struct { } HelloRequest;
  2595.  
  2596.     struct {
  2597.         uint32 gmt_unix_time;
  2598.         opaque random_bytes[28];
  2599.     } Random;
  2600.  
  2601.     opaque SessionID<0..32>;
  2602.  
  2603.     uint8 CipherSuite[2];
  2604.  
  2605.     enum { null(0), (255) } CompressionMethod;
  2606.  
  2607.     struct {
  2608.         ProtocolVersion client_version;
  2609.         Random random;
  2610.         SessionID session_id;
  2611.         CipherSuite cipher_suites<0..2^16-1>;
  2612.         CompressionMethod compression_methods<0..2^8-1>;
  2613. ]       VendorID client_vendor;
  2614.     } ClientHello;
  2615.  
  2616.     struct {
  2617.         ProtocolVersion server_version;
  2618.         Random random;
  2619.         SessionID session_id;
  2620.         CipherSuite cipher_suite;
  2621.         CompressionMethod compression_method;
  2622. ]       VendorID server_vendor;
  2623.     } ServerHello;
  2624.  
  2625. A.5.2. Server authentication and key exchange messages
  2626.  
  2627.     opaque ASN.1Cert<2^24-1>;
  2628.  
  2629.     struct {
  2630.         ASN.1Cert certificate_list<1..2^24-1>;
  2631.     } Certificate;
  2632.  
  2633. Dierks, T.                  Expires September, 1997            [Page 47]
  2634. INTERNET-DRAFT                     TLS 1.0                    March 1997
  2635.  
  2636.     enum { rsa, diffie_hellman } KeyExchangeAlgorithm;
  2637.  
  2638.     struct {
  2639.         opaque RSA_modulus<1..2^16-1>;
  2640.         opaque RSA_exponent<1..2^16-1>;
  2641.     } ServerRSAParams;
  2642.  
  2643.     struct {
  2644.         opaque DH_p<1..2^16-1>;
  2645.         opaque DH_g<1..2^16-1>;
  2646.         opaque DH_Ys<1..2^16-1>;
  2647.     } ServerDHParams;
  2648.  
  2649.     struct {
  2650.         select (KeyExchangeAlgorithm) {
  2651.             case diffie_hellman:
  2652.                 ServerDHParams params;
  2653.                 Signature signed_params;
  2654.             case rsa:
  2655.                 ServerRSAParams params;
  2656.                 Signature signed_params;
  2657.         };
  2658.     } ServerKeyExchange;
  2659.  
  2660.     enum { anonymous, rsa, dsa } SignatureAlgorithm;
  2661.  
  2662.     select (SignatureAlgorithm)
  2663.     {   case anonymous: struct { };
  2664.         case rsa:
  2665.             digitally-signed struct {
  2666.                 opaque md5_hash[16];
  2667.                 opaque sha_hash[20];
  2668.             };
  2669.         case dsa:
  2670.             digitally-signed struct {
  2671.                 opaque sha_hash[20];
  2672.             };
  2673.     } Signature;
  2674.  
  2675. ]   enum {
  2676. ]       rsa_sign(1), dss_sign(2), rsa_fixed_dh(3), dss_fixed_dh(4),
  2677. ]       (255)
  2678. ]   } ClientCertificateType;
  2679.  
  2680.     opaque DistinguishedName<1..2^16-1>;
  2681.  
  2682.     struct {
  2683.         CertificateType certificate_types<1..2^8-1>;
  2684.         DistinguishedName certificate_authorities<3..2^16-1>;
  2685.     } CertificateRequest;
  2686.  
  2687.     struct { } ServerHelloDone;
  2688.  
  2689. Dierks, T.                  Expires September, 1997            [Page 48]
  2690. INTERNET-DRAFT                     TLS 1.0                    March 1997
  2691.  
  2692. A.5.3. Client authentication and key exchange messages
  2693.  
  2694.     struct {
  2695.         select (KeyExchangeAlgorithm) {
  2696.             case rsa: EncryptedPreMasterSecret;
  2697.             case diffie_hellman: DiffieHellmanClientPublicValue;
  2698.         } exchange_keys;
  2699.     } ClientKeyExchange;
  2700.  
  2701.     struct {
  2702.         ProtocolVersion client_version;
  2703.         opaque random[46];
  2704.     } PreMasterSecret;
  2705.  
  2706.     struct {
  2707.         public-key-encrypted PreMasterSecret pre_master_secret;
  2708.     } EncryptedPreMasterSecret;
  2709.  
  2710.     enum { implicit, explicit } PublicValueEncoding;
  2711.  
  2712.     struct {
  2713.         select (PublicValueEncoding) {
  2714.             case implicit: struct {};
  2715.             case explicit: opaque DH_Yc<1..2^16-1>;
  2716.         } dh_public;
  2717.     } ClientDiffieHellmanPublic;
  2718.  
  2719.     struct {
  2720.         Signature signature;
  2721.     } CertificateVerify;
  2722.  
  2723. A.5.4. Handshake finalization message
  2724.  
  2725.     struct {
  2726.         opaque md5_hash[16];
  2727.         opaque sha_hash[20];
  2728.     } Finished;
  2729.  
  2730. A.6. The CipherSuite
  2731.  
  2732.    The following values define the CipherSuite codes used in the client
  2733.    hello and server hello messages.
  2734.  
  2735.    A CipherSuite defines a cipher specification supported in TLS
  2736.    Version 1.0.
  2737.  
  2738.     CipherSuite TLS_NULL_WITH_NULL_NULL                = { 0x00,0x00 };
  2739.  
  2740.    The following CipherSuite definitions require that the server
  2741.    provide an RSA certificate that can be used for key exchange. The
  2742.    server may request either an RSA or a DSS signature-capable
  2743.    certificate in the certificate request message.
  2744.  
  2745. Dierks, T.                  Expires September, 1997            [Page 49]
  2746. INTERNET-DRAFT                     TLS 1.0                    March 1997
  2747.  
  2748.     CipherSuite TLS_RSA_WITH_NULL_MD5                  = { 0x00,0x01 };
  2749.     CipherSuite TLS_RSA_WITH_NULL_SHA                  = { 0x00,0x02 };
  2750.     CipherSuite TLS_RSA_EXPORT_WITH_RC4_40_MD5         = { 0x00,0x03 };
  2751.     CipherSuite TLS_RSA_WITH_RC4_128_MD5               = { 0x00,0x04 };
  2752.     CipherSuite TLS_RSA_WITH_RC4_128_SHA               = { 0x00,0x05 };
  2753.     CipherSuite TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5     = { 0x00,0x06 };
  2754.     CipherSuite TLS_RSA_WITH_IDEA_CBC_SHA              = { 0x00,0x07 };
  2755.     CipherSuite TLS_RSA_EXPORT_WITH_DES40_CBC_SHA      = { 0x00,0x08 };
  2756.     CipherSuite TLS_RSA_WITH_DES_CBC_SHA               = { 0x00,0x09 };
  2757.     CipherSuite TLS_RSA_WITH_3DES_EDE_CBC_SHA          = { 0x00,0x0A };
  2758.  
  2759.    The following CipherSuite definitions are used for
  2760.    server-authenticated (and optionally client-authenticated)
  2761.    Diffie-Hellman. DH denotes cipher suites in which the server's
  2762.    certificate contains the Diffie-Hellman parameters signed by the
  2763.    certificate authority (CA). DHE denotes ephemeral Diffie-Hellman,
  2764.    where the Diffie-Hellman parameters are signed by a DSS or RSA
  2765.    certificate, which has been signed by the CA. The signing algorithm
  2766. |  used is specified after the DH or DHE parameter. The server can
  2767. |  request an RSA or DSS signature-capable certificate from the client
  2768. |  for client authentication or it may request a Diffie-Hellman
  2769. |  certificate. Any Diffie-Hellman certificate provided by the client
  2770. |  must use the parameters (group and generator) described by the
  2771. |  server.
  2772.  
  2773.     CipherSuite TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA   = { 0x00,0x0B };
  2774.     CipherSuite TLS_DH_DSS_WITH_DES_CBC_SHA            = { 0x00,0x0C };
  2775.     CipherSuite TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA       = { 0x00,0x0D };
  2776.     CipherSuite TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA   = { 0x00,0x0E };
  2777.     CipherSuite TLS_DH_RSA_WITH_DES_CBC_SHA            = { 0x00,0x0F };
  2778.     CipherSuite TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA       = { 0x00,0x10 };
  2779.     CipherSuite TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA  = { 0x00,0x11 };
  2780.     CipherSuite TLS_DHE_DSS_WITH_DES_CBC_SHA           = { 0x00,0x12 };
  2781.     CipherSuite TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA      = { 0x00,0x13 };
  2782.     CipherSuite TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA  = { 0x00,0x14 };
  2783.     CipherSuite TLS_DHE_RSA_WITH_DES_CBC_SHA           = { 0x00,0x15 };
  2784.     CipherSuite TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA      = { 0x00,0x16 };
  2785.  
  2786.    The following cipher suites are used for completely anonymous
  2787.    Diffie-Hellman communications in which neither party is
  2788.    authenticated. Note that this mode is vulnerable to
  2789. |  man-in-the-middle attacks and is therefore deprecated.
  2790.  
  2791.     CipherSuite TLS_DH_anon_EXPORT_WITH_RC4_40_MD5     = { 0x00,0x17 };
  2792.     CipherSuite TLS_DH_anon_WITH_RC4_128_MD5           = { 0x00,0x18 };
  2793.     CipherSuite TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA  = { 0x00,0x19 };
  2794.     CipherSuite TLS_DH_anon_WITH_DES_CBC_SHA           = { 0x00,0x1A };
  2795.     CipherSuite TLS_DH_anon_WITH_3DES_EDE_CBC_SHA      = { 0x00,0x1B };
  2796.  
  2797.  Note: All cipher suites whose first byte is 0xFF are considered
  2798.        private and can be used for defining local/experimental
  2799.        algorithms. Interoperability of such types is a local matter.
  2800.  
  2801. Dierks, T.                  Expires September, 1997            [Page 50]
  2802. INTERNET-DRAFT                     TLS 1.0                    March 1997
  2803.  
  2804.  Note: Additional cipher suites will be considered for implementation
  2805.        only with submission of notarized letters from two independent
  2806. ]      entities. Consensus Development Corp. will act as an interim
  2807.        registration office, until a public standards body assumes
  2808. ]      control of TLS cipher suites.
  2809.  
  2810. A.7. The Security Parameters
  2811.  
  2812.    These security parameters are determined by the TLS Handshake
  2813.    Protocol and provided as parameters to the TLS Record Layer in order
  2814.    to initialize a connection state. SecurityParameters includes:
  2815.  
  2816.        enum { null(0), (255) } CompressionMethod;
  2817.  
  2818.        enum { server, client } ConnectionEnd;
  2819.  
  2820.        enum { null, rc4, rc2, des, 3des, des40 } BulkCipherAlgorithm;
  2821.  
  2822.        enum { stream, block } CipherType;
  2823.  
  2824.        enum { true, false } IsExportable;
  2825.  
  2826.        enum { null, md5, sha } MACAlgorithm;
  2827.  
  2828.    /* The algorithms specified in CompressionMethod,
  2829.    BulkCipherAlgorithm, and MACAlgorithm may be added to. */
  2830.  
  2831.        struct {
  2832.            ConnectionEnd entity;
  2833.            BulkCipherAlgorithm bulk_cipher_algorithm;
  2834.            CipherType cipher_type;
  2835.            uint8 key_size;
  2836.            uint8 key_material_length;
  2837.            IsExportable is_exportable;
  2838.            MACAlgorithm mac_algorithm;
  2839.            uint8 hash_size;
  2840.            uint8 whitener_length;
  2841.            CompressionMethod compression_algorithm;
  2842.            opaque master_secret[48];
  2843.            opaque client_random[32];
  2844.            opaque server_random[32];
  2845.        } SecurityParameters;
  2846.  
  2847. B. Glossary
  2848.  
  2849.    application protocol
  2850.        An application protocol is a protocol that normally layers
  2851.        directly on top of the transport layer (e.g., TCP/IP). Examples
  2852.        include HTTP, TELNET, FTP, and SMTP.
  2853.  
  2854.  
  2855.  
  2856.  
  2857. Dierks, T.                  Expires September, 1997            [Page 51]
  2858. INTERNET-DRAFT                     TLS 1.0                    March 1997
  2859.  
  2860.    asymmetric cipher
  2861.        See public key cryptography.
  2862.  
  2863.    authentication
  2864.        Authentication is the ability of one entity to determine the
  2865.        identity of another entity.
  2866.  
  2867.    block cipher
  2868.        A block cipher is an algorithm that operates on plaintext in
  2869.        groups of bits, called blocks. 64 bits is a typical block size.
  2870.  
  2871.    bulk cipher
  2872.        A symmetric encryption algorithm used to encrypt large
  2873.        quantities of data.
  2874.  
  2875. |  cipher block chaining (CBC)
  2876. |      CBC is a mode in which every plaintext block encrypted with a
  2877. |      block cipher is first exclusive-ORed with the previous
  2878. |      ciphertext block (or, in the case of the first block, with the
  2879. |      initialization vector). For decryption, every block is first
  2880. |      decrypted, then exclusive-ORed with the previous ciphertext
  2881. |      block (or IV).
  2882.  
  2883.    certificate
  2884.        As part of the X.509 protocol (a.k.a. ISO Authentication
  2885.        framework), certificates are assigned by a trusted Certificate
  2886.        Authority and provide verification of a party's identity and may
  2887.        also supply its public key.
  2888.  
  2889.    client
  2890.        The application entity that initiates a connection to a server
  2891.  
  2892.    client write key
  2893.        The key used to encrypt data written by the client.
  2894.  
  2895.    client write MAC secret
  2896.        The secret data used to authenticate data written by the client.
  2897.  
  2898.    connection
  2899.        A connection is a transport (in the OSI layering model
  2900.        definition) that provides a suitable type of service. For TLS,
  2901.        such connections are peer to peer relationships. The connections
  2902.        are transient. Every connection is associated with one session.
  2903.  
  2904.    Data Encryption Standard
  2905.        DES is a very widely used symmetric encryption algorithm. DES is
  2906. |      a block cipher with a 56 bit key and an 8 byte block size. Note
  2907. |      that in TLS, for key generation purposes, DES is treated as
  2908. |      having an 8 byte key length (64 bits), but it still only
  2909. |      provides 56 bits of protection. DES can also be operated in a
  2910. |      mode where three independant keys and three encryptions are used
  2911. |      for each block of data; this uses 168 bits of key (24 bytes in
  2912.  
  2913. Dierks, T.                  Expires September, 1997            [Page 52]
  2914. INTERNET-DRAFT                     TLS 1.0                    March 1997
  2915.  
  2916. |      the TLS key generation method) and provides the equivalent of
  2917. |      112 bits of security. [DES], [3DES]
  2918.  
  2919.    Digital Signature Standard (DSS)
  2920.        A standard for digital signing, including the Digital Signing
  2921.        Algorithm, approved by the National Institute of Standards and
  2922.        Technology, defined in NIST FIPS PUB 186, "Digital Signature
  2923.        Standard," published May, 1994 by the U.S. Dept. of Commerce.
  2924.        [DSS]
  2925.  
  2926.    digital signatures
  2927.        Digital signatures utilize public key cryptography and one-way
  2928.        hash functions to produce a signature of the data that can be
  2929.        authenticated, and is difficult to forge or repudiate.
  2930.  
  2931.    handshake
  2932.        An initial negotiation between client and server that
  2933.        establishes the parameters of their transactions.
  2934.  
  2935.    Initialization Vector (IV)
  2936.        When a block cipher is used in CBC mode, the initialization
  2937.        vector is exclusive-ORed with the first plaintext block prior to
  2938.        encryption.
  2939.  
  2940.    IDEA
  2941.        A 64-bit block cipher designed by Xuejia Lai and James Massey.
  2942.        [IDEA]
  2943.  
  2944.    Message Authentication Code (MAC)
  2945.        A Message Authentication Code is a one-way hash computed from a
  2946. |      message and some secret data. It is difficult to forge without
  2947. |      knowing the secret data and it is difficult to find messages
  2948. |      which hash to the same MAC. Its purpose is to detect if the
  2949. |      message has been altered.
  2950.  
  2951.    master secret
  2952.        Secure secret data used for generating encryption keys, MAC
  2953.        secrets, and IVs.
  2954.  
  2955.    MD5
  2956.        MD5 is a secure hashing function that converts an arbitrarily
  2957. |      long data stream into a digest of fixed size (16 bytes). [MD5]
  2958.  
  2959.    public key cryptography
  2960.        A class of cryptographic techniques employing two-key ciphers.
  2961.        Messages encrypted with the public key can only be decrypted
  2962.        with the associated private key. Conversely, messages signed
  2963.        with the private key can be verified with the public key.
  2964.  
  2965.    one-way hash function
  2966.        A one-way transformation that converts an arbitrary amount of
  2967.        data into a fixed-length hash. It is computationally hard to
  2968.  
  2969. Dierks, T.                  Expires September, 1997            [Page 53]
  2970. INTERNET-DRAFT                     TLS 1.0                    March 1997
  2971.  
  2972.        reverse the transformation or to find collisions. MD5 and SHA
  2973.        are examples of one-way hash functions.
  2974.  
  2975.    RC2, RC4
  2976.        Proprietary bulk ciphers from RSA Data Security, Inc. (There is
  2977.        no good reference to these as they are unpublished works;
  2978.        however, see [RSADSI]). RC2 is block cipher and RC4 is a stream
  2979.        cipher.
  2980.  
  2981.    RSA
  2982.        A very widely used public-key algorithm that can be used for
  2983.        either encryption or digital signing. [RSA]
  2984.  
  2985.    salt
  2986.        Non-secret random data used to make export encryption keys
  2987.        resist precomputation attacks.
  2988.  
  2989.    server
  2990.        The server is the application entity that responds to requests
  2991.        for connections from clients. The server is passive, waiting for
  2992.        requests from clients.
  2993.  
  2994.    session
  2995.        A TLS session is an association between a client and a server.
  2996.        Sessions are created by the handshake protocol. Sessions define
  2997.        a set of cryptographic security parameters, which can be shared
  2998.        among multiple connections. Sessions are used to avoid the
  2999.        expensive negotiation of new security parameters for each
  3000.        connection.
  3001.  
  3002.    session identifier
  3003.        A session identifier is a value generated by a server that
  3004.        identifies a particular session.
  3005.  
  3006.    server write key
  3007.        The key used to encrypt data written by the server.
  3008.  
  3009.    server write MAC secret
  3010.        The secret data used to authenticate data written by the server.
  3011.  
  3012.    SHA
  3013.        The Secure Hash Algorithm is defined in FIPS PUB 180-1. It
  3014. |      produces a 20-byte output. Note that all references to SHA
  3015. |      actually use the modified SHA-1 algorithm. [SHA]
  3016.  
  3017.    SSL
  3018.        Netscape's Secure Socket Layer protocol [SSL3]. TLS is based on
  3019.        SSL Version 3.0
  3020.  
  3021.    stream cipher
  3022.        An encryption algorithm that converts a key into a
  3023.        cryptographically-strong keystream, which is then exclusive-ORed
  3024.  
  3025. Dierks, T.                  Expires September, 1997            [Page 54]
  3026. INTERNET-DRAFT                     TLS 1.0                    March 1997
  3027.  
  3028.        with the plaintext.
  3029.  
  3030.    symmetric cipher
  3031.        See bulk cipher.
  3032.  
  3033. |  Transport Layer Security (TLS)
  3034. |      This protocol; also, the Transport Layer Security working group
  3035. |      of the Internet Engineering Task Force (IETF). See "Comments" at
  3036. |      the end of this document.
  3037.  
  3038. C. CipherSuite definitions
  3039.  
  3040. CipherSuite                 Is         Key            Cipher       Hash
  3041.                             Exportable Exchange
  3042.  
  3043. TLS_NULL_WITH_NULL_NULL               * NULL           NULL        NULL
  3044. TLS_RSA_WITH_NULL_MD5                 * RSA            NULL         MD5
  3045. TLS_RSA_WITH_NULL_SHA                 * RSA            NULL         SHA
  3046. TLS_RSA_EXPORT_WITH_RC4_40_MD5        * RSA_EXPORT     RC4_40       MD5
  3047. TLS_RSA_WITH_RC4_128_MD5                RSA            RC4_128      MD5
  3048. TLS_RSA_WITH_RC4_128_SHA                RSA            RC4_128      SHA
  3049. TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5    * RSA_EXPORT     RC2_CBC_40   MD5
  3050. TLS_RSA_WITH_IDEA_CBC_SHA               RSA            IDEA_CBC     SHA
  3051. TLS_RSA_EXPORT_WITH_DES40_CBC_SHA     * RSA_EXPORT     DES40_CBC    SHA
  3052. TLS_RSA_WITH_DES_CBC_SHA                RSA            DES_CBC      SHA
  3053. TLS_RSA_WITH_3DES_EDE_CBC_SHA           RSA            3DES_EDE_CBC SHA
  3054. TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA  * DH_DSS_EXPORT  DES40_CBC    SHA
  3055. TLS_DH_DSS_WITH_DES_CBC_SHA             DH_DSS         DES_CBC      SHA
  3056. TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA        DH_DSS         3DES_EDE_CBC SHA
  3057. TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA  * DH_RSA_EXPORT  DES40_CBC    SHA
  3058. TLS_DH_RSA_WITH_DES_CBC_SHA             DH_RSA         DES_CBC      SHA
  3059. TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA        DH_RSA         3DES_EDE_CBC SHA
  3060. TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA * DHE_DSS_EXPORT DES40_CBC    SHA
  3061. TLS_DHE_DSS_WITH_DES_CBC_SHA            DHE_DSS        DES_CBC      SHA
  3062. TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA       DHE_DSS        3DES_EDE_CBC SHA
  3063. TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA * DHE_RSA_EXPORT DES40_CBC    SHA
  3064. TLS_DHE_RSA_WITH_DES_CBC_SHA            DHE_RSA        DES_CBC      SHA
  3065. TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA       DHE_RSA        3DES_EDE_CBC SHA
  3066. TLS_DH_anon_EXPORT_WITH_RC4_40_MD5    * DH_anon_EXPORT RC4_40       MD5
  3067. TLS_DH_anon_WITH_RC4_128_MD5            DH_anon        RC4_128      MD5
  3068. TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA   DH_anon        DES40_CBC    SHA
  3069. TLS_DH_anon_WITH_DES_CBC_SHA            DH_anon        DES_CBC      SHA
  3070. TLS_DH_anon_WITH_3DES_EDE_CBC_SHA       DH_anon        3DES_EDE_CBC SHA
  3071.  
  3072.    * Indicates IsExportable is True
  3073.  
  3074.       Key
  3075.       Exchange
  3076.       Algorithm       Description                        Key size limit
  3077.  
  3078.       DHE_DSS         Ephemeral DH with DSS signatures   None
  3079.       DHE_DSS_EXPORT  Ephemeral DH with DSS signatures   DH = 512 bits
  3080.  
  3081. Dierks, T.                  Expires September, 1997            [Page 55]
  3082. INTERNET-DRAFT                     TLS 1.0                    March 1997
  3083.  
  3084.       DHE_RSA         Ephemeral DH with RSA signatures   None
  3085.       DHE_RSA_EXPORT  Ephemeral DH with RSA signatures   DH = 512 bits,
  3086.                                                          RSA = none
  3087.       DH_anon         Anonymous DH, no signatures        None
  3088.       DH_anon_EXPORT  Anonymous DH, no signatures        DH = 512 bits
  3089.       DH_DSS          DH with DSS-based certificates     None
  3090.       DH_DSS_EXPORT   DH with DSS-based certificates     DH = 512 bits
  3091.       DH_RSA          DH with RSA-based certificates     None
  3092.       DH_RSA_EXPORT   DH with RSA-based certificates     DH = 512 bits,
  3093.                                                          RSA = none
  3094.       NULL            No key exchange                    N/A
  3095.       RSA             RSA key exchange                   None
  3096.       RSA_EXPORT      RSA key exchange                   RSA = 512 bits
  3097.  
  3098.    Key size limit
  3099.        The key size limit gives the size of the largest public key that
  3100.        can be legally used for encryption in cipher suites that are
  3101.        exportable.
  3102.  
  3103.                          Key      Expanded   Effective   IV    Block
  3104.     Cipher       Type  Material Key Material  Key Bits  Size   Size
  3105.  
  3106.     NULL       * Stream   0          0           0        0     N/A
  3107.     IDEA_CBC     Block   16         16         128        8      8
  3108.     RC2_CBC_40 * Block    5         16          40        8      8
  3109.     RC4_40     * Stream   5         16          40        0     N/A
  3110.     RC4_128      Stream  16         16         128        0     N/A
  3111.     DES40_CBC  * Block    5          8          40        8      8
  3112.     DES_CBC      Block    8          8          56        8      8
  3113.     3DES_EDE_CBC Block   24         24         168        8      8
  3114.  
  3115.    * Indicates IsExportable is true.
  3116.  
  3117.    Key Material
  3118.        The number of bytes from the key_block that are used for
  3119.        generating the write keys.
  3120.  
  3121.    Expanded Key Material
  3122.        The number of bytes actually fed into the encryption algorithm
  3123.  
  3124.    Effective Key Bits
  3125.        How much entropy material is in the key material being fed into
  3126.        the encryption routines.
  3127.  
  3128.       Hash      Hash      Padding
  3129.     function    Size       Size
  3130.       NULL       0          0
  3131.       MD5        16         48
  3132.       SHA        20         40
  3133.  
  3134.  
  3135.  
  3136.  
  3137. Dierks, T.                  Expires September, 1997            [Page 56]
  3138. INTERNET-DRAFT                     TLS 1.0                    March 1997
  3139.  
  3140.    Appendix D
  3141.  
  3142. D. Implementation Notes
  3143.  
  3144.    The TLS protocol cannot prevent many common security mistakes. This
  3145.    section provides several recommendations to assist implementers.
  3146.  
  3147. D.1. Temporary RSA keys
  3148.  
  3149.    US Export restrictions limit RSA keys used for encryption to 512
  3150.    bits, but do not place any limit on lengths of RSA keys used for
  3151.    signing operations. Certificates often need to be larger than 512
  3152.    bits, since 512-bit RSA keys are not secure enough for high-value
  3153.    transactions or for applications requiring long-term security. Some
  3154.    certificates are also designated signing-only, in which case they
  3155.    cannot be used for key exchange.
  3156.  
  3157.    When the public key in the certificate cannot be used for
  3158.    encryption, the server signs a temporary RSA key, which is then
  3159.    exchanged. In exportable applications, the temporary RSA key should
  3160.    be the maximum allowable length (i.e., 512 bits). Because 512-bit
  3161.    RSA keys are relatively insecure, they should be changed often. For
  3162.    typical electronic commerce applications, it is suggested that keys
  3163.    be changed daily or every 500 transactions, and more often if
  3164.    possible. Note that while it is acceptable to use the same temporary
  3165.    key for multiple transactions, it must be signed each time it is
  3166.    used.
  3167.  
  3168.    RSA key generation is a time-consuming process. In many cases, a
  3169.    low-priority process can be assigned the task of key generation.
  3170.  
  3171.    Whenever a new key is completed, the existing temporary key can be
  3172.    replaced with the new one.
  3173.  
  3174. D.2. Random Number Generation and Seeding
  3175.  
  3176.    TLS requires a cryptographically-secure pseudorandom number
  3177.    generator (PRNG). Care must be taken in designing and seeding PRNGs.
  3178.    PRNGs based on secure hash operations, most notably MD5 and/or SHA,
  3179.    are acceptable, but cannot provide more security than the size of
  3180.    the random number generator state. (For example, MD5-based PRNGs
  3181.    usually provide 128 bits of state.)
  3182.  
  3183.    To estimate the amount of seed material being produced, add the
  3184.    number of bits of unpredictable information in each seed byte. For
  3185.    example, keystroke timing values taken from a PC compatible's 18.2
  3186.    Hz timer provide 1 or 2 secure bits each, even though the total size
  3187.    of the counter value is 16 bits or more. To seed a 128-bit PRNG, one
  3188.    would thus require approximately 100 such timer values.
  3189.  
  3190.  
  3191.  
  3192.  
  3193. Dierks, T.                  Expires September, 1997            [Page 57]
  3194. INTERNET-DRAFT                     TLS 1.0                    March 1997
  3195.  
  3196. Warning: The seeding functions in RSAREF and versions of BSAFE prior to
  3197.          3.0 are order-independent. For example, if 1000 seed bits are
  3198.          supplied, one at a time, in 1000 separate calls to the seed
  3199.          function, the PRNG will end up in a state which depends only
  3200.          on the number of 0 or 1 seed bits in the seed data (i.e.,
  3201.          there are 1001 possible final states). Applications using
  3202.          BSAFE or RSAREF must take extra care to ensure proper seeding.
  3203. |        This may be accomplished by accumulating seed bits into a
  3204. |        buffer and processing them all at once or by processing an
  3205. |        incrementing counter with every seed bit; either method will
  3206. |        reintroduce order dependance into the seeding process.
  3207.  
  3208. D.3. Certificates and authentication
  3209.  
  3210.    Implementations are responsible for verifying the integrity of
  3211.    certificates and should generally support certificate revocation
  3212.    messages. Certificates should always be verified to ensure proper
  3213.    signing by a trusted Certificate Authority (CA). The selection and
  3214.    addition of trusted CAs should be done very carefully. Users should
  3215.    be able to view information about the certificate and root CA.
  3216.  
  3217. D.4. CipherSuites
  3218.  
  3219.    TLS supports a range of key sizes and security levels, including
  3220.    some which provide no or minimal security. A proper implementation
  3221.    will probably not support many cipher suites. For example, 40-bit
  3222.    encryption is easily broken, so implementations requiring strong
  3223.    security should not allow 40-bit keys. Similarly, anonymous
  3224.    Diffie-Hellman is strongly discouraged because it cannot prevent
  3225.    man-in-the-middle attacks. Applications should also enforce minimum
  3226.    and maximum key sizes. For example, certificate chains containing
  3227.    512-bit RSA keys or signatures are not appropriate for high-security
  3228.    applications.
  3229.  
  3230. E. Backward Compatibility With SSL
  3231.  
  3232. |  For historical reasons and in order to avoid a profligate
  3233. |  consumption of reserved port numbers, application protocols which
  3234. |  are secured by TLS 1.0, SSL 3.0, and SSL 2.0 all frequently share
  3235. |  the same connection port: for example, the https protocol (HTTP
  3236. |  secured by SSL or TLS) uses port 443 regardless of which security
  3237. |  protocol it is using. Thus, some mechanism must be determined to
  3238. |  distinguish and negotiate among the various protocols.
  3239.  
  3240. |  TLS version 1.0 and SSL 3.0 are very similar; thus, supporting both
  3241. |  is easy. TLS clients who wish to negotiate with SSL 3.0 servers
  3242. |  should send client hello messages using the SSL 3.0 record format
  3243. |  and client hello structure, sending {3, 1} for the version field to
  3244. |  note that they support TLS 1.0. If the server supports only SSL 3.0,
  3245. |  it will respond with an SSL 3.0 server hello; if it supports TLS,
  3246. |  with a TLS server hello. The negotiation then proceeds as
  3247. |  appropriate for the negotiated protocol.
  3248.  
  3249. Dierks, T.                  Expires September, 1997            [Page 58]
  3250. INTERNET-DRAFT                     TLS 1.0                    March 1997
  3251.  
  3252. |  Similarly, a TLS server which wishes to interoperate with SSL 3.0
  3253. |  clients should accept SSL 3.0 client hello messages and respond with
  3254. |  an SSL 3.0 server hello if an SSL 3.0 client hello is received which
  3255. |  has a version field of {3, 0}, denoting that this client does not
  3256. |  support TLS.
  3257.  
  3258. |  Whenever a client already knows the highest protocol known to a
  3259. |  server (for example, when resuming a session), it should initiate
  3260. |  the connection in that native protocol.
  3261.  
  3262. |  TLS 1.0 clients that support SSL Version 2.0 servers must send SSL
  3263. |  Version 2.0 client hello messages [SSL-2]. TLS servers should accept
  3264. |  either client hello format if they wish to support SSL 2.0 clients
  3265. |  on the same connection port. The only deviations from the Version
  3266. |  2.0 specification are the ability to specify a version with a value
  3267. |  of three and the support for more ciphering types in the CipherSpec.
  3268.  
  3269. Warning: The ability to send Version 2.0 client hello messages will be
  3270.          phased out with all due haste. Implementers should make every
  3271.          effort to move forward as quickly as possible. Version 3.0
  3272.          provides better mechanisms for moving to newer versions.
  3273.  
  3274.    The following cipher specifications are carryovers from SSL Version
  3275.    2.0. These are assumed to use RSA for key exchange and
  3276.    authentication.
  3277.  
  3278. |      V2CipherSpec TLS_RC4_128_WITH_MD5          = { 0x01,0x00,0x80 };
  3279. |      V2CipherSpec TLS_RC4_128_EXPORT40_WITH_MD5 = { 0x02,0x00,0x80 };
  3280. |      V2CipherSpec TLS_RC2_CBC_128_CBC_WITH_MD5  = { 0x03,0x00,0x80 };
  3281. |      V2CipherSpec TLS_RC2_CBC_128_CBC_EXPORT40_WITH_MD5
  3282. |                                                 = { 0x04,0x00,0x80 };
  3283. |      V2CipherSpec TLS_IDEA_128_CBC_WITH_MD5     = { 0x05,0x00,0x80 };
  3284. |      V2CipherSpec TLS_DES_64_CBC_WITH_MD5       = { 0x06,0x00,0x40 };
  3285. |      V2CipherSpec TLS_DES_192_EDE3_CBC_WITH_MD5 = { 0x07,0x00,0xC0 };
  3286.  
  3287. |  Cipher specifications native to TLS can be included in Version 2.0
  3288. |  client hello messages using the syntax below. Any V2CipherSpec
  3289. |  element with its first byte equal to zero will be ignored by Version
  3290. |  2.0 servers. Clients sending any of the above V2CipherSpecs should
  3291. |  also include the TLS equivalent (see Appendix A.6):
  3292.  
  3293. |      V2CipherSpec (see TLS name) = { 0x00, CipherSuite };
  3294.  
  3295. E.1. Version 2 client hello
  3296.  
  3297.    The Version 2.0 client hello message is presented below using this
  3298.    document's presentation model. The true definition is still assumed
  3299.    to be the SSL Version 2.0 specification.
  3300.  
  3301.        uint8 V2CipherSpec[3];
  3302.  
  3303.  
  3304.  
  3305. Dierks, T.                  Expires September, 1997            [Page 59]
  3306. INTERNET-DRAFT                     TLS 1.0                    March 1997
  3307.  
  3308.        struct {
  3309.            unit8 msg_type;
  3310.            Version version;
  3311.            uint16 cipher_spec_length;
  3312.            uint16 session_id_length;
  3313.            uint16 challenge_length;
  3314.            V2CipherSpec cipher_specs[V2ClientHello.cipher_spec_length];
  3315.            opaque session_id[V2ClientHello.session_id_length];
  3316.            Random challenge;
  3317.        } V2ClientHello;
  3318.  
  3319.    msg_type
  3320.        This field, in conjunction with the version field, identifies a
  3321.        version 2 client hello message. The value should be one (1).
  3322.  
  3323.    version
  3324.        The highest version of the protocol supported by the client
  3325.        (equals ProtocolVersion.version, see Appendix A.1.1).
  3326.  
  3327.    cipher_spec_length
  3328.        This field is the total length of the field cipher_specs. It
  3329.        cannot be zero and must be a multiple of the V2CipherSpec length
  3330.        (3).
  3331.  
  3332.    session_id_length
  3333.        This field must have a value of either zero or 16. If zero, the
  3334.        client is creating a new session. If 16, the session_id field
  3335.        will contain the 16 bytes of session identification.
  3336.  
  3337.    challenge_length
  3338.        The length in bytes of the client's challenge to the server to
  3339.        authenticate itself. This value must be 32.
  3340.  
  3341.    cipher_specs
  3342.        This is a list of all CipherSpecs the client is willing and able
  3343.        to use. There must be at least one CipherSpec acceptable to the
  3344.        server.
  3345.  
  3346.    session_id
  3347.        If this field's length is not zero, it will contain the
  3348.        identification for a session that the client wishes to resume.
  3349.  
  3350.    challenge
  3351.        The client challenge to the server for the server to identify
  3352.        itself is a (nearly) arbitrary length random. The Version 3.0
  3353.        server will right justify the challenge data to become the
  3354.        ClientHello.random data (padded with leading zeroes, if
  3355.        necessary), as specified in this Version 3.0 protocol. If the
  3356.        length of the challenge is greater than 32 bytes, only the last
  3357.        32 bytes are used. It is legitimate (but not necessary) for a V3
  3358.        server to reject a V2 ClientHello that has fewer than 16 bytes
  3359.        of challenge data.
  3360.  
  3361. Dierks, T.                  Expires September, 1997            [Page 60]
  3362. INTERNET-DRAFT                     TLS 1.0                    March 1997
  3363.  
  3364. |Note: Requests to resume a TLS session should use a TLS client hello.
  3365.  
  3366. E.2. Avoiding man-in-the-middle version rollback
  3367.  
  3368. |  When TLS clients fall back to Version 2.0 compatibility mode, they
  3369. |  should use special PKCS #1 block formatting. This is done so that
  3370. |  TLS servers will reject Version 2.0 sessions with TLS-capable
  3371. |  clients.
  3372.  
  3373. |  When TLS clients are in Version 2.0 compatibility mode, they set the
  3374.    right-hand (least-significant) 8 random bytes of the PKCS padding
  3375.    (not including the terminal null of the padding) for the RSA
  3376.    encryption of the ENCRYPTED-KEY-DATA field of the CLIENT-MASTER-KEY
  3377.    to 0x03 (the other padding bytes are random). After decrypting the
  3378.    ENCRYPTED-KEY-DATA field, servers that support TLS should issue an
  3379.    error if these eight padding bytes are 0x03. Version 2.0 servers
  3380.    receiving blocks padded in this manner will proceed normally.
  3381.  
  3382.    Appendix F
  3383.  
  3384. F. Security analysis
  3385.  
  3386.    The TLS protocol is designed to establish a secure connection
  3387.    between a client and a server communicating over an insecure
  3388.    channel. This document makes several traditional assumptions,
  3389.    including that attackers have substantial computational resources
  3390.    and cannot obtain secret information from sources outside the
  3391.    protocol. Attackers are assumed to have the ability to capture,
  3392.    modify, delete, replay, and otherwise tamper with messages sent over
  3393.    the communication channel. This appendix outlines how TLS has been
  3394.    designed to resist a variety of attacks.
  3395.  
  3396. F.1. Handshake protocol
  3397.  
  3398.    The handshake protocol is responsible for selecting a CipherSpec and
  3399.    generating a Master Secret, which together comprise the primary
  3400.    cryptographic parameters associated with a secure session. The
  3401.    handshake protocol can also optionally authenticate parties who have
  3402.    certificates signed by a trusted certificate authority.
  3403.  
  3404. F.1.1. Authentication and key exchange
  3405.  
  3406.    TLS supports three authentication modes: authentication of both
  3407.    parties, server authentication with an unauthenticated client, and
  3408.    total anonymity. Whenever the server is authenticated, the channel
  3409.    should be secure against man-in-the-middle attacks, but completely
  3410.    anonymous sessions are inherently vulnerable to such attacks.
  3411.    Anonymous servers cannot authenticate clients, since the client
  3412.    signature in the certificate verify message may require a server
  3413.    certificate to bind the signature to a particular server. If the
  3414.    server is authenticated, its certificate message must provide a
  3415.    valid certificate chain leading to an acceptable certificate
  3416.  
  3417. Dierks, T.                  Expires September, 1997            [Page 61]
  3418. INTERNET-DRAFT                     TLS 1.0                    March 1997
  3419.  
  3420.    authority. Similarly, authenticated clients must supply an
  3421.    acceptable certificate to the server. Each party is responsible for
  3422.    verifying that the other's certificate is valid and has not expired
  3423.    or been revoked.
  3424.  
  3425.    The general goal of the key exchange process is to create a
  3426.    pre_master_secret known to the communicating parties and not to
  3427.    attackers. The pre_master_secret will be used to generate the
  3428.    master_secret (see Section 7.1). The master_secret is required to
  3429. |  generate the certificate verify and finished messages, encryption
  3430.    keys, and MAC secrets (see Sections 6.4.8, 6.4.9 and 5.4). By
  3431.    sending a correct finished message, parties thus prove that they
  3432.    know the correct pre_master_secret.
  3433.  
  3434. F.1.1.1. Anonymous key exchange
  3435.  
  3436.    Completely anonymous sessions can be established using RSA or
  3437.    Diffie-Hellman for key exchange. With anonymous RSA, the client
  3438.    encrypts a pre_master_secret with the server's uncertified public
  3439.    key extracted from the server key exchange message. The result is
  3440.    sent in a client key exchange message. Since eavesdroppers do not
  3441.    know the server's private key, it will be infeasible for them to
  3442.    decode the pre_master_secret. (Note that no anonymous RSA Cipher
  3443.    Suites are defined in this document).
  3444.  
  3445.    With Diffie-Hellman, the server's public parameters are contained in
  3446.    the server key exchange message and the client's are sent in the
  3447.    client key exchange message. Eavesdroppers who do not know the
  3448.    private values should not be able to find the Diffie-Hellman result
  3449.    (i.e. the pre_master_secret).
  3450.  
  3451. Warning: Completely anonymous connections only provide protection
  3452.          against passive eavesdropping. Unless an independent
  3453.          tamper-proof channel is used to verify that the finished
  3454.          messages were not replaced by an attacker, server
  3455.          authentication is required in environments where active
  3456.          man-in-the-middle attacks are a concern.
  3457.  
  3458. F.1.1.2. RSA key exchange and authentication
  3459.  
  3460.    With RSA, key exchange and server authentication are combined. The
  3461.    public key may be either contained in the server's certificate or
  3462.    may be a temporary RSA key sent in a server key exchange message.
  3463.    When temporary RSA keys are used, they are signed by the server's
  3464.    RSA or DSS certificate. The signature includes the current
  3465.    ClientHello.random, so old signatures and temporary keys cannot be
  3466.    replayed. Servers may use a single temporary RSA key for multiple
  3467.    negotiation sessions.
  3468.  
  3469.  Note: The temporary RSA key option is useful if servers need large
  3470.        certificates but must comply with government-imposed size limits
  3471.        on keys used for key exchange.
  3472.  
  3473. Dierks, T.                  Expires September, 1997            [Page 62]
  3474. INTERNET-DRAFT                     TLS 1.0                    March 1997
  3475.  
  3476.    After verifying the server's certificate, the client encrypts a
  3477.    pre_master_secret with the server's public key. By successfully
  3478.    decoding the pre_master_secret and producing a correct finished
  3479.    message, the server demonstrates that it knows the private key
  3480.    corresponding to the server certificate.
  3481.  
  3482.    When RSA is used for key exchange, clients are authenticated using
  3483.    the certificate verify message (see Section 6.4.8). The client signs
  3484.    a value derived from the master_secret and all preceding handshake
  3485.    messages. These handshake messages include the server certificate,
  3486.    which binds the signature to the server, and ServerHello.random,
  3487.    which binds the signature to the current handshake process.
  3488.  
  3489. F.1.1.3. Diffie-Hellman key exchange with authentication
  3490.  
  3491.    When Diffie-Hellman key exchange is used, the server can either
  3492.    supply a certificate containing fixed Diffie-Hellman parameters or
  3493.    can use the server key exchange message to send a set of temporary
  3494.    Diffie-Hellman parameters signed with a DSS or RSA certificate.
  3495.    Temporary parameters are hashed with the hello.random values before
  3496.    signing to ensure that attackers do not replay old parameters. In
  3497.    either case, the client can verify the certificate or signature to
  3498.    ensure that the parameters belong to the server.
  3499.  
  3500.    If the client has a certificate containing fixed Diffie-Hellman
  3501.    parameters, its certificate contains the information required to
  3502.    complete the key exchange. Note that in this case the client and
  3503.    server will generate the same Diffie-Hellman result (i.e.,
  3504.    pre_master_secret) every time they communicate. To prevent the
  3505.    pre_master_secret from staying in memory any longer than necessary,
  3506.    it should be converted into the master_secret as soon as possible.
  3507.    Client Diffie-Hellman parameters must be compatible with those
  3508.    supplied by the server for the key exchange to work.
  3509.  
  3510.    If the client has a standard DSS or RSA certificate or is
  3511.    unauthenticated, it sends a set of temporary parameters to the
  3512.    server in the client key exchange message, then optionally uses a
  3513.    certificate verify message to authenticate itself.
  3514.  
  3515. F.1.2. Version rollback attacks
  3516.  
  3517.    Because TLS includes substantial improvements over SSL Version 2.0,
  3518.    attackers may try to make TLS-capable clients and servers fall back
  3519.    to Version 2.0. This attack can occur if (and only if) two
  3520.    TLS-capable parties use an SSL 2.0 handshake.
  3521.  
  3522.    Although the solution using non-random PKCS #1 block type 2 message
  3523.    padding is inelegant, it provides a reasonably secure way for
  3524.    Version 3.0 servers to detect the attack. This solution is not
  3525.    secure against attackers who can brute force the key and substitute
  3526.    a new ENCRYPTED-KEY-DATA message containing the same key (but with
  3527.    normal padding) before the application specified wait threshold has
  3528.  
  3529. Dierks, T.                  Expires September, 1997            [Page 63]
  3530. INTERNET-DRAFT                     TLS 1.0                    March 1997
  3531.  
  3532.    expired. Parties concerned about attacks of this scale should not be
  3533.    using 40-bit encryption keys anyway. Altering the padding of the
  3534.    least-significant 8 bytes of the PKCS padding does not impact
  3535. |  security for the size of the signed hashes and RSA key lengths used
  3536. |  in the protocol, since this is essentially equivalent to increasing
  3537. |  the input block size by 8 bytes.
  3538.  
  3539. F.1.3. Detecting attacks against the handshake protocol
  3540.  
  3541.    An attacker might try to influence the handshake exchange to make
  3542.    the parties select different encryption algorithms than they would
  3543.    normally choose. Because many implementations will support 40-bit
  3544.    exportable encryption and some may even support null encryption or
  3545.    MAC algorithms, this attack is of particular concern.
  3546.  
  3547.    For this attack, an attacker must actively change one or more
  3548.    handshake messages. If this occurs, the client and server will
  3549.    compute different values for the handshake message hashes. As a
  3550.    result, the parties will not accept each others' finished messages.
  3551.    Without the master_secret, the attacker cannot repair the finished
  3552.    messages, so the attack will be discovered.
  3553.  
  3554. F.1.4. Resuming sessions
  3555.  
  3556.    When a connection is established by resuming a session, new
  3557.    ClientHello.random and ServerHello.random values are hashed with the
  3558.    session's master_secret. Provided that the master_secret has not
  3559.    been compromised and that the secure hash operations used to produce
  3560.    the encryption keys and MAC secrets are secure, the connection
  3561.    should be secure and effectively independent from previous
  3562.    connections. Attackers cannot use known encryption keys or MAC
  3563.    secrets to compromise the master_secret without breaking the secure
  3564.    hash operations (which use both SHA and MD5).
  3565.  
  3566.    Sessions cannot be resumed unless both the client and server agree.
  3567.    If either party suspects that the session may have been compromised,
  3568.    or that certificates may have expired or been revoked, it should
  3569.    force a full handshake. An upper limit of 24 hours is suggested for
  3570.    session ID lifetimes, since an attacker who obtains a master_secret
  3571.    may be able to impersonate the compromised party until the
  3572.    corresponding session ID is retired. Applications that may be run in
  3573.    relatively insecure environments should not write session IDs to
  3574.    stable storage.
  3575.  
  3576. F.1.5. MD5 and SHA
  3577.  
  3578.    TLS uses hash functions very conservatively. Where possible, both
  3579.    MD5 and SHA are used in tandem to ensure that non-catastrophic flaws
  3580.    in one algorithm will not break the overall protocol.
  3581.  
  3582.  
  3583.  
  3584.  
  3585. Dierks, T.                  Expires September, 1997            [Page 64]
  3586. INTERNET-DRAFT                     TLS 1.0                    March 1997
  3587.  
  3588. F.2. Protecting application data
  3589.  
  3590.    The master_secret is hashed with the ClientHello.random and
  3591.    ServerHello.random to produce unique data encryption keys and MAC
  3592.    secrets for each connection.
  3593.  
  3594.    Outgoing data is protected with a MAC before transmission. To
  3595.    prevent message replay or modification attacks, the MAC is computed
  3596.    from the MAC secret, the sequence number, the message length, the
  3597.    message contents, and two fixed character strings. The message type
  3598.    field is necessary to ensure that messages intended for one TLS
  3599.    Record Layer client are not redirected to another. The sequence
  3600.    number ensures that attempts to delete or reorder messages will be
  3601.    detected. Since sequence numbers are 64-bits long, they should never
  3602.    overflow. Messages from one party cannot be inserted into the
  3603.    other's output, since they use independent MAC secrets. Similarly,
  3604.    the server-write and client-write keys are independent so stream
  3605.    cipher keys are used only once.
  3606.  
  3607.    If an attacker does break an encryption key, all messages encrypted
  3608.    with it can be read. Similarly, compromise of a MAC key can make
  3609.    message modification attacks possible. Because MACs are also
  3610.    encrypted, message-alteration attacks generally require breaking the
  3611.    encryption algorithm as well as the MAC.
  3612.  
  3613.  Note: MAC secrets may be larger than encryption keys, so messages can
  3614.        remain tamper resistant even if encryption keys are broken.
  3615.  
  3616. F.3. Final notes
  3617.  
  3618.    For TLS to be able to provide a secure connection, both the client
  3619.    and server systems, keys, and applications must be secure. In
  3620.    addition, the implementation must be free of security errors.
  3621.  
  3622.    The system is only as strong as the weakest key exchange and
  3623.    authentication algorithm supported, and only trustworthy
  3624.    cryptographic functions should be used. Short public keys, 40-bit
  3625.    bulk encryption keys, and anonymous servers should be used with
  3626.    great caution. Implementations and users must be careful when
  3627.    deciding which certificates and certificate authorities are
  3628.    acceptable; a dishonest certificate authority can do tremendous
  3629.    damage.
  3630.  
  3631.    Appendix G
  3632.  
  3633. G. Patent Statement
  3634.  
  3635.    This version of the TLS protocol relies on the use of patented
  3636.    public key encryption technology for authentication and encryption.
  3637.    The Internet Standards Process as defined in RFC 1310 requires a
  3638.    written statement from the Patent holder that a license will be made
  3639.    available to applicants under reasonable terms and conditions prior
  3640.  
  3641. Dierks, T.                  Expires September, 1997            [Page 65]
  3642. INTERNET-DRAFT                     TLS 1.0                    March 1997
  3643.  
  3644.    to approving a specification as a Proposed, Draft or Internet
  3645.    Standard. The Massachusetts Institute of Technology has granted RSA
  3646.    Data Security, Inc., exclusive sub-licensing rights to the following
  3647.    patent issued in the United States:
  3648.  
  3649.        Cryptographic Communications System and Method ("RSA"), No.
  3650.        4,405,829
  3651.  
  3652.    The Board of Trustees of the Leland Stanford Junior University have
  3653.    granted Caro-Kann Corporation, a wholly owned subsidiary
  3654.    corporation, exclusive sub-licensing rights to the following patents
  3655.    issued in the United States, and all of their corresponding foreign
  3656.    patents:
  3657.  
  3658.        Cryptographic Apparatus and Method ("Diffie-Hellman"), No.
  3659.        4,200,770
  3660.  
  3661.        Public Key Cryptographic Apparatus and Method
  3662.        ("Hellman-Merkle"), No. 4,218,582
  3663.  
  3664.    The Internet Society, Internet Architecture Board, Internet
  3665.    Engineering Steering Group and the Corporation for National Research
  3666.    Initiatives take no position on the validity or scope of the patents
  3667.    and patent applications, nor on the appropriateness of the terms of
  3668.    the assurance. The Internet Society and other groups mentioned above
  3669.    have not made any determination as to any other intellectual
  3670.    property rights which may apply to the practice of this standard.
  3671.    Any further consideration of these matters is the user's own
  3672.    responsibility.
  3673.  
  3674. References
  3675.  
  3676.    [3DES] W. Tuchman, "Hellman Presents No Shortcut Solutions To DES,"
  3677.    IEEE Spectrum, v. 16, n. 7, July 1979, pp40-41.
  3678.  
  3679.    [DES] ANSI X3.106, "American National Standard for Information
  3680.    Systems-Data Link Encryption," American National Standards
  3681.    Institute, 1983.
  3682.  
  3683.    [DH1] W. Diffie and M. E. Hellman, "New Directions in Cryptography,"
  3684.    IEEE Transactions on Information Theory, V. IT-22, n. 6, Jun 1977,
  3685.    pp. 74-84.
  3686.  
  3687.    [DSS] NIST FIPS PUB 186, "Digital Signature Standard," National
  3688.    Institute of Standards and Technology, U.S. Department of Commerce,
  3689.    18 May 1994.
  3690.  
  3691.    [FTP] J. Postel and J. Reynolds, RFC 959: File Transfer Protocol,
  3692.    October 1985.
  3693.  
  3694.  
  3695.  
  3696.  
  3697. Dierks, T.                  Expires September, 1997            [Page 66]
  3698. INTERNET-DRAFT                     TLS 1.0                    March 1997
  3699.  
  3700.    [HTTP] T. Berners-Lee, R. Fielding, H. Frystyk, Hypertext Transfer
  3701.    Protocol -- HTTP/1.0, October, 1995.
  3702.  
  3703. ]  [HMAC] H. Krawczyk, RFC 2104, HMAC: Keyed-Hashing for Message
  3704. ]  Authentication, February, 1997.
  3705.  
  3706.    [IDEA] X. Lai, "On the Design and Security of Block Ciphers," ETH
  3707.    Series in Information Processing, v. 1, Konstanz: Hartung-Gorre
  3708.    Verlag, 1992.
  3709.  
  3710.    [MD2] R. Rivest. RFC 1319: The MD2 Message Digest Algorithm. April
  3711.    1992.
  3712.  
  3713.    [MD5] R. Rivest. RFC 1321: The MD5 Message Digest Algorithm. April
  3714.    1992.
  3715.  
  3716.    [PKCS1] RSA Laboratories, "PKCS #1: RSA Encryption Standard,"
  3717.    version 1.5, November 1993.
  3718.  
  3719.    [PKCS6] RSA Laboratories, "PKCS #6: RSA Extended Certificate Syntax
  3720.    Standard," version 1.5, November 1993.
  3721.  
  3722.    [PKCS7] RSA Laboratories, "PKCS #7: RSA Cryptographic Message Syntax
  3723.    Standard," version 1.5, November 1993.
  3724.  
  3725. ]  [PKIX] R. Housley, W. Ford, W. Polk, D. Solo, Internet Public Key
  3726. ]  Infrastructure: Part I: X.509 Certificate and CRL Profile,
  3727. ]  <draft-ietf-pkix-ipki-part1-03.txt>, December 1996.
  3728.  
  3729.    [RSA] R. Rivest, A. Shamir, and L. M. Adleman, "A Method for
  3730.    Obtaining Digital Signatures and Public-Key Cryptosystems,"
  3731.    Communications of the ACM, v. 21, n. 2, Feb 1978, pp. 120-126.
  3732.  
  3733.    [RSADSI] Contact RSA Data Security, Inc., Tel: 415-595-8782 [SCH] B.
  3734.    Schneier. Applied Cryptography: Protocols, Algorithms, and Source
  3735.    Code in C, Published by John Wiley & Sons, Inc. 1994.
  3736.  
  3737.    [SHA] NIST FIPS PUB 180-1, "Secure Hash Standard," National
  3738.    Institute of Standards and Technology, U.S. Department of Commerce,
  3739.    DRAFT, 31 May 1994.
  3740.  
  3741.    [SSL3] Frier, Karton and Kocher,
  3742.    internet-draft-tls-ssl-version3-00.txt: "The SSL 3.0 Protocol", Nov
  3743.    18 1996.
  3744.  
  3745.    [TCP] ISI for DARPA, RFC 793: Transport Control Protocol, September
  3746.    1981.
  3747.  
  3748.    [TEL] J. Postel and J. Reynolds, RFC 854/5, May, 1993.
  3749.  
  3750.  
  3751.  
  3752.  
  3753. Dierks, T.                  Expires September, 1997            [Page 67]
  3754. INTERNET-DRAFT                     TLS 1.0                    March 1997
  3755.  
  3756.    [X509] CCITT. Recommendation X.509: "The Directory - Authentication
  3757.    Framework". 1988.
  3758.  
  3759.    [XDR] R. Srinivansan, Sun Microsystems, RFC-1832: XDR: External Data
  3760.    Representation Standard, August 1995.
  3761.  
  3762. Credits
  3763.  
  3764. Working Group Chair
  3765.  
  3766.       Win Treese
  3767.       Open Market
  3768.       treeseopenmarket.com
  3769.  
  3770. Editors
  3771.  
  3772.       Tim Dierks                    Christopher Allen
  3773.       Consensus Development         Consensus Development
  3774.       timd@consensus.com            christophera@consensus.com
  3775.  
  3776. Authors
  3777.  
  3778.       Alan O. Freier                Paul C. Kocher
  3779.       Netscape Communications       Independent Consultant
  3780.       freier@netscape.com           pck@netcom.com
  3781.  
  3782.       Philip L. Karlton             Tim Dierks
  3783.       Netscape Communications       Consensus Development
  3784.       karlton@netscape.com          timd@consensus.com
  3785.  
  3786.  
  3787. Other contributors
  3788.  
  3789.       Martin Abadi                  Robert Relyea
  3790.       Digital Equipment Corporation Netscape Communications
  3791.       ma@pa.dec.com                 relyea@netscape.com
  3792.  
  3793.       Taher Elgamal                 Jim Roskind
  3794.       Netscape Communications       Netscape Communications
  3795.       elgamal@netscape.com          jar@netscape.com
  3796.  
  3797.       Anil Gangolli                 Micheal J. Sabin, Ph. D.
  3798.       Netscape Communications       Consulting Engineer
  3799.       gangolli@netscape.com         msabin@netcom.com
  3800.  
  3801.       Kipp E.B. Hickman             Tom Weinstein
  3802.       Netscape Communications       Netscape Communications
  3803.       kipp@netscape.com             tomw@netscape.com
  3804.  
  3805. Early reviewers
  3806.  
  3807.  
  3808.  
  3809. Dierks, T.                  Expires September, 1997            [Page 68]
  3810. INTERNET-DRAFT                     TLS 1.0                    March 1997
  3811.  
  3812.       Robert Baldwin                Clyde Monma
  3813.       RSA Data Security, Inc.       Bellcore
  3814.       baldwin@rsa.com               clyde@bellcore.com
  3815.  
  3816.       George Cox                    Eric Murray
  3817.       Intel Corporation             ericm@lne.com
  3818.       cox@ibeam.jf.intel.com
  3819.  
  3820.       Cheri Dowell                  Avi Rubin
  3821.       Sun Microsystems              Bellcore
  3822.       cheri@eng.sun.com             rubin@bellcore.com
  3823.  
  3824.       Stuart Haber                  Don Stephenson
  3825.       Bellcore                      Sun Microsystems
  3826.       stuart@bellcore.com           don.stephenson@eng.sun.com
  3827.  
  3828.       Burt Kaliski                  Joe Tardo
  3829.       RSA Data Security, Inc.       General Magic
  3830.       burt@rsa.com                  tardo@genmagic.com
  3831.  
  3832. Comments
  3833.  
  3834. ]  Comments on this draft should be sent to the editors, Tim Dierks and
  3835. ]  Christopher Allen at the address <ietf-tls-editors@consensus.com>,
  3836. ]  or to the IETF Transport Layer Security (TLS) Working Group.
  3837.  
  3838. ]  The discussion list for the IETF TLS working group is located at the
  3839. ]  e-mail address <ietf-tls@consensus.com>. Information on the group
  3840. ]  and information on how to subscribe to the list is at
  3841. ]  <http://www.consensus.com/ietf-tls/>.
  3842.  
  3843. ]  You can subscribe to the list by sending a message to
  3844. ]  <ietf-tls@consensus.com> with the subject "SUBSCRIBE". You can
  3845. ]  subscribe to a digested variant of the list by sending a message to
  3846. ]  <ietf-tls@consensus.com> with the subject "SUBSCRIBE DIGEST". To
  3847. ]  remove yourself from the list, send a message to
  3848. ]  <ietf-tls@consensus.com> with the subject "UNSUBSCRIBE".
  3849.  
  3850.    Archives of the list are at:
  3851. ]      <http://www.imc.org/ietf-tls/mail-archive/>
  3852.  
  3853.  
  3854.  
  3855.  
  3856.  
  3857.  
  3858.  
  3859.  
  3860.  
  3861.  
  3862.  
  3863.  
  3864.  
  3865. Dierks, T.                  Expires September, 1997            [Page 69]
  3866.  
  3867.