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-01.txt < prev    next >
Text File  |  1997-03-07  |  158KB  |  3,753 lines

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