RFC 6101

The Secure Sockets Layer (SSL) Protocol Version 3.0

๐Ÿ“… published August 2011, from ietf

The Secure Sockets Layer (SSL) Protocol Version 3.0 ๐ŸŽ€

Part 1 of 13 ๐Ÿ’–

Okay bestie, let's start with the title block ๐ŸŒธ This is RFC 6101, published by the Internet Engineering Task Force (IETF) in August 2011. The authors are A. Freier, P. Karlton (both from Netscape Communications) and P. Kocher (an Independent Consultant). It's classed as Historic, with ISSN 2070-1721. The header doesn't list any Obsoletes or Updates entries, so it doesn't replace or change anything else. ๐Ÿฆ‹

Abstract โœจ

Okay so this doc is a historical record of the SSL 3.0 protocol. The original Abstract is kept below, and it's giving classic 90s security energy ๐Ÿ’…

This document specifies version 3.0 of the Secure Sockets Layer (SSL 3.0) protocol, a security protocol that provides communications privacy over the Internet. The protocol lets client/server applications talk to each other in a way that is designed to stop eavesdropping, tampering, or message forgery. ๐Ÿ”

Foreword ๐ŸŒˆ

Okay, this part is the tea โ˜• SSL 3.0 is a seriously widely implemented protocol and a total pioneer in secure communications. It's also the basis for Transport Layer Security (TLS) ๐Ÿ‘‘ But the IETF never formally published it, except in several expired Internet-Drafts. That made it really hard to cite, so this document describes what's known as the last published version of SSL 3.0, the version dated November 18, 1996 ๐Ÿ“

There were no changes to the original document other than trivial editorial changes and the addition of a "Security Considerations" section. However, some parts of the original that no longer apply were left out. That includes the "Patent Statement" section, the "Reserved Ports Assignment" section, and the cipher-suite registrator note in the "The CipherSuite" section. โœ‚๏ธ

The "US export rules" discussed in the document don't apply today, but they're kept intact so you can see the context behind the protocol design decisions. ๐Ÿงš

The "Goals of This Document" section lists goals for adopters of SSL 3.0, not goals of the IETF. Tea spilled ๐Ÿซ–

The authors and editors were kept as they were in the original document. The editor of this document is Nikos Mavrogiannopoulos (nikos.mavrogiannopoulos@esat.kuleuven.be). The editor would like to thank Dan Harkins, Linda Dunbar, Sean Turner, and Geoffrey Keating for reviewing the document and giving helpful comments. Thank you, legends ๐Ÿซถ

Status of This Memo ๐Ÿ“œ

This document is not an Internet Standards Track specification. It's published for the historical record ๐Ÿ“š

This document defines a Historic Document for the Internet community. It's a product of the Internet Engineering Task Force (IETF) and represents the consensus of the IETF community. It has received public review and has been approved for publication by the Internet Engineering Steering Group (IESG). Not every document the IESG approves is a candidate for any level of Internet Standard, so see Section 2 of RFC 5741 for that. ๐Ÿ’…

Information about the current status of this document, any errata, and how to give feedback on it can be found at http://www.rfc-editor.org/info/rfc6101. ๐Ÿ”—

Copyright (c) 2011 IETF Trust and the persons identified as the document authors. All rights reserved. ๐Ÿ’œ

This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (http://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, because they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions, and they are provided without warranty as described in the Simplified BSD License. ๐ŸŽ€

This document may contain material from IETF Documents or IETF Contributions published or made publicly available before November 10, 2008. The person(s) controlling the copyright in some of this material may not have granted the IETF Trust the right to allow modifications of that material outside the IETF Standards Process. Without an adequate license from the person(s) controlling the copyright in those materials, this document may not be modified outside the IETF Standards Process, and derivative works of it may not be created outside the IETF Standards Process. The only exceptions are formatting it for publication as an RFC or translating it into languages other than English. ๐ŸŒธ

Table of Contents ๐Ÿ—บ๏ธ

Here's the full map for the whole doc. Parts 2 through 13 will walk through each of these sections in order ๐Ÿงš

1. Introduction ....................................................5
2. Goals ...........................................................5
3. Goals of This Document ..........................................6
4. Presentation Language ...........................................6
   4.1. Basic Block Size ...........................................7
   4.2. Miscellaneous ..............................................7
   4.3. Vectors ....................................................7
   4.4. Numbers ....................................................8
   4.5. Enumerateds ................................................8
   4.6. Constructed Types ..........................................9
        4.6.1. Variants ...........................................10
   4.7. Cryptographic Attributes ..................................11
   4.8. Constants .................................................12
5. SSL Protocol ...................................................12
   5.1. Session and Connection States .............................12
   5.2. Record Layer ..............................................14
        5.2.1. Fragmentation ......................................14
        5.2.2. Record Compression and Decompression ...............15
        5.2.3. Record Payload Protection and the CipherSpec .......16
   5.3. Change Cipher Spec Protocol ...............................18
   5.4. Alert Protocol ............................................18
        5.4.1. Closure Alerts .....................................19
        5.4.2. Error Alerts .......................................20
   5.5. Handshake Protocol Overview ...............................21
   5.6. Handshake Protocol ........................................23
        5.6.1. Hello messages .....................................24
        5.6.2. Server Certificate .................................28
        5.6.3. Server Key Exchange Message ........................28
        5.6.4. Certificate Request ................................30
        5.6.5. Server Hello Done ..................................31
        5.6.6. Client Certificate .................................31
        5.6.7. Client Key Exchange Message ........................31
        5.6.8. Certificate Verify .................................34
        5.6.9. Finished ...........................................35
   5.7. Application Data Protocol .................................36
6. Cryptographic Computations .....................................36
   6.1. Asymmetric Cryptographic Computations .....................36
        6.1.1. RSA ................................................36
        6.1.2. Diffie-Hellman .....................................37
        6.1.3. FORTEZZA ...........................................37
   6.2. Symmetric Cryptographic Calculations and the CipherSpec ...37
        6.2.1. The Master Secret ..................................37
        6.2.2. Converting the Master Secret into Keys and
               MAC Secrets ........................................37
7. Security Considerations ........................................39
8. Informative References .........................................40
Appendix A. Protocol Constant Values ..............................42
  A.1. Record Layer ...............................................42
  A.2. Change Cipher Specs Message ................................43
  A.3. Alert Messages .............................................43
  A.4. Handshake Protocol .........................................44
    A.4.1. Hello Messages .........................................44
    A.4.2. Server Authentication and Key Exchange Messages ........45
  A.5. Client Authentication and Key Exchange Messages ............46
    A.5.1. Handshake Finalization Message .........................47
  A.6. The CipherSuite ............................................47
  A.7. The CipherSpec .............................................49
Appendix B. Glossary ..............................................50
Appendix C. CipherSuite Definitions ...............................53
Appendix D. Implementation Notes ..................................56
  D.1. Temporary RSA Keys .........................................56
  D.2. Random Number Generation and Seeding .......................56
  D.3. Certificates and Authentication ............................57
  D.4. CipherSuites ...............................................57
  D.5. FORTEZZA ...................................................57
    D.5.1. Notes on Use of FORTEZZA Hardware ......................57
    D.5.2. FORTEZZA Cipher Suites .................................58
    D.5.3. FORTEZZA Session Resumption ............................58
Appendix E. Version 2.0 Backward Compatibility ....................59
  E.1. Version 2 Client Hello .....................................59
  E.2. Avoiding Man-in-the-Middle Version Rollback ..............61
Appendix F. Security Analysis .....................................61
  F.1. Handshake Protocol .........................................61
    F.1.1. Authentication and Key Exchange ........................61
    F.1.2. Version Rollback Attacks ...............................64
    F.1.3. Detecting Attacks against the Handshake Protocol .......64
    F.1.4. Resuming Sessions ......................................65
    F.1.5. MD5 and SHA ............................................65
  F.2. Protecting Application Data ................................65
  F.3. Final Notes ................................................66
Appendix G. Acknowledgements ......................................66
  G.1. Other Contributors .........................................66
  G.2. Early Reviewers ............................................67

1. Introduction โœจ

Okay so, the whole point of SSL is to give two apps privacy and reliability when they talk to each other ๐Ÿ”’๐Ÿ’–. It's built in two layers. At the bottom, sitting on top of some reliable transport (like TCP [RFC0793]), is the SSL record protocol ๐Ÿงฑ. That layer wraps up various higher-level protocols. One of those is the SSL handshake protocol, which is the bit where the server and client check who each other are and agree on an encryption algorithm and keys before the application sends or receives its very first byte of data ๐Ÿคโœจ. SSL doesn't care which application protocol you're running, which is so iconic, because a higher-level protocol can slide on top of it totally transparently ๐Ÿฆ‹.

SSL gives your connection three main vibes:

  • The connection is private ๐Ÿ™ˆ. After a first handshake, encryption is used to set up a secret key. Symmetric cryptography handles the actual data encryption (e.g., DES [DES], 3DES [3DES], RC4 [SCH]).
  • The peer's identity can be authenticated using asymmetric (public key) cryptography (e.g., RSA [RSA], DSS [DSS]) ๐Ÿชช๐Ÿ’….
  • The connection is reliable ๐Ÿ’ช. Every message gets an integrity check using a keyed Message Authentication Code (MAC) [RFC2104]. Secure hash functions (e.g., SHA, MD5) are used for the MAC computations ๐Ÿ”ฅ.

2. Goals ๐ŸŽฏ

Here's the priority list for SSL protocol version 3.0, from most to least important:

  1. Cryptographic security ๐Ÿ‘‘ Basically, SSL should be used to set up a secure connection between two parties. That's the main job, no cap.
  2. Interoperability ๐Ÿซถ Independent programmers should be able to build applications using SSL 3.0 that successfully swap cryptographic parameters without ever seeing each other's code. Like, strangers can still be besties ๐Ÿ’œ.

Note: Not every SSL instance (even inside the same application domain) will be able to connect successfully ๐Ÿ˜ญ. Say the server supports a particular hardware token but the client doesn't have access to that token. Then the connection won't work, and that's just how it goes ๐Ÿ’€.

  1. Extensibility ๐Ÿงš SSL is meant to be a framework where new public key and bulk encryption methods can be plugged in whenever they're needed ๐Ÿ”Œ. This also covers two sub-goals: avoiding the need to invent a brand-new protocol (which could bring in new weaknesses ๐Ÿ˜ฌ), and avoiding the need to implement an entire new security library. Lowkey genius ๐Ÿง .
  2. Relative efficiency โšก Cryptographic operations are super CPU-heavy, especially the public key ones ๐Ÿฅต. So SSL includes an optional session caching scheme, which means fewer connections have to be set up from scratch โœจ. On top of that, a lot of care went into cutting down on network activity ๐ŸŒธ.

3. Goals of This Document ๐Ÿ“–

The SSL protocol version 3.0 specification is written mainly for people who are going to implement the protocol and for people doing cryptographic analysis of it ๐Ÿง. The spec was written with those two groups in mind and is meant to meet their needs. That's why a lot of the algorithm-dependent data structures and rules live right in the body of the text instead of being tucked into an appendix ๐Ÿ“š. Easy access, bestie ๐Ÿ’….

This document doesn't try to give any details about service definition or interface definition ๐Ÿ™…. It does, however, cover select areas of policy whenever they're needed to keep security solid ๐Ÿ”.

4. Presentation Language ๐ŸŽ€

This document is all about how data gets formatted in an external representation ๐Ÿ“ฆ. The presentation syntax below is very basic and kinda casually defined. Its structure pulls from several sources. It looks a lot like the programming language "C", and it's similar to External Data Representation (XDR) [RFC1832] in both syntax and intent. Still, it would be risky to push those parallels too far ๐Ÿ™ƒ. This presentation language only exists to document SSL, so it isn't meant to be used for anything beyond that goal ๐Ÿ’œ.

4.1. Basic Block Size ๐Ÿงฉ

Every data item is explicitly specified. The basic data block size is one byte (that's 8 bits) ๐Ÿ”ข. Multi-byte data items are just concatenations of bytes, read from left to right and top to bottom ๐Ÿ“–. A multi-byte item (a numeric, in the example) is formed from the byte stream using C notation like this:

value = (byte[0] << 8*(n-1)) | (byte[1] << 8*(n-2)) | ...
| byte[n-1];

This byte ordering for multi-byte values is the commonplace network byte order, also called big-endian format ๐ŸŒˆ.

4.2. Miscellaneous ๐Ÿ“

Comments start with "/" and end with "/" ๐Ÿ’ฌ. Optional components get wrapped in "[[ ]]" double brackets. Single-byte entities holding uninterpreted data are of type opaque ๐Ÿซฅ.

4.3. Vectors ๐Ÿญ

A vector (a single-dimensioned array) is a stream of homogeneous data elements ๐Ÿงƒ. The size of a vector can be specified at documentation time or left unspecified until runtime. Either way, the length counts the number of bytes in the vector, not the number of elements ๐Ÿ“. The syntax for declaring a new type T' that's a fixed-length vector of type T is:

T T'[n];

Here, T' takes up n bytes in the data stream, where n is a multiple of the size of T. The length of the vector isn't included in the encoded stream ๐Ÿ™Œ.

Here's an example. Datum is defined as three consecutive bytes that the protocol doesn't interpret, and Data is three consecutive Datum, which adds up to nine bytes total โœจ:

opaque Datum[3];      /* three uninterpreted bytes */
Datum Data[9];        /* 3 consecutive 3 byte vectors */

Variable-length vectors are defined by giving a subrange of legal lengths, inclusive, using the <floor..ceiling> notation ๐ŸŽข. When encoded, the actual length comes before the vector's contents in the byte stream. That length is a number that takes up as many bytes as it needs to hold the vector's specified maximum (ceiling) length. A variable-length vector whose actual length field is zero is called an empty vector ๐Ÿซง.

T T'<floor..ceiling>;

In the next example, mandatory is a vector that has to contain between 300 and 400 bytes of type opaque. It can never be empty ๐Ÿšซ. Its actual length field takes two bytes, a uint16, which is enough to represent the value 400 (see Section 4.4) ๐Ÿ”Ž. longer, on the other hand, can hold up to 800 bytes of data, or 400 uint16 elements, and it's allowed to be empty ๐ŸŒท. Its encoding includes a two-byte actual length field prepended to the vector ๐Ÿ’–.

opaque mandatory<300..400>;
      /* length field is 2 bytes, cannot be empty */
uint16 longer<0..800>;
      /* zero to 400 16-bit unsigned integers */

4.4. Numbers ๐Ÿ”ข

The basic numeric data type is an unsigned byte (uint8) ๐Ÿซง. Every larger numeric data type is formed from fixed-length series of bytes concatenated as described in Section 4.1, and they're all unsigned too ๐Ÿ’…. These numeric types are predefined:

uint8 uint16[2];
uint8 uint24[3];
uint8 uint32[4];
uint8 uint64[8];

4.5. Enumerateds ๐ŸŒŸ

There's an extra sparse data type called enum ๐Ÿ‘€. A field of type enum can only take on the values declared in its definition. Each definition is its own type, so only enumerateds of the same type can be assigned or compared with each other ๐Ÿšซ. Every element of an enumerated must be given a value, like in this example. The elements aren't ordered, so they can be assigned any unique value, in any order ๐ŸŽฒ:

enum { e1(v1), e2(v2), ... , en(vn), [[(n)]] } Te;

Enumerateds take up as much space in the byte stream as their maximal defined ordinal value needs. This definition would make fields of type Color use one byte ๐ŸŽจ:

enum { red(3), blue(5), white(7) } Color;

You can also leave out the tag and just write a value. That forces the width without defining an extra element ๐Ÿง. In the next example, Taste uses two bytes in the data stream, but it can only be 1, 2, or 4 ๐Ÿฌ:

enum { sweet(1), sour(2), bitter(4), (32000) } Taste;

The names of an enumeration's elements are scoped to the defined type. In the first example, the fully qualified way to reference the second element would be Color.blue ๐Ÿ’™. You don't have to qualify it if the assignment target is already well specified โœจ:

Color color = Color.blue;     /* overspecified, legal */
Color color = blue;           /* correct, type implicit */

For enumerateds that are never converted to an external representation, the numerical information can be left out ๐Ÿซถ:

enum { low, medium, high } Amount;

4.6. Constructed Types ๐Ÿ—๏ธ

Structure types can be built from primitive types for convenience ๐Ÿงฑ. Every specification declares a new, unique type. The definition syntax looks a lot like C ๐Ÿ’œ:

struct {
    T1 f1;
    T2 f2;
    ...
    Tn fn;
} [[T]];

You can qualify the fields within a structure using the type's name, kind of like with enumerateds. For example, T.f2 refers to the second field of the previous declaration ๐ŸŽฏ. Structure definitions can also be embedded inside each other ๐Ÿช†.

4.6.1. Variants ๐Ÿฆ‹

Defined structures can have variants based on some knowledge that's available in the environment โœจ. The selector has to be an enumerated type that defines the possible variants the structure can take. There must be a case arm for every element of the enumeration declared in the select ๐Ÿšจ. The body of the variant structure can be given a label so it can be referenced later ๐Ÿท๏ธ. How the variant actually gets selected at runtime isn't prescribed by the presentation language, so that part's up to the implementation ๐Ÿคทโ€โ™€๏ธ.

struct {
    T1 f1;
    T2 f2;
     ....
    Tn fn;
    select (E) {
        case e1: Te1;
        case e2: Te2;
            ....
        case en: Ten;
    } [[fv]];
} [[Tv]];

For example:

enum { apple, orange } VariantTag;
struct {
    uint16 number;
    opaque string<0..10>; /* variable length */
} V1;

struct {
    uint32 number;
    opaque string[10];    /* fixed length */
} V2;
struct {
    select (VariantTag) { /* value of selector is implicit */
        case apple: V1;   /* VariantBody, tag = apple */
        case orange: V2;  /* VariantBody, tag = orange */
    } variant_body;       /* optional label on variant */
} VariantRecord;

Variant structures can be narrowed by giving a value for the selector before the type ๐ŸŽ€. For example:

orange VariantRecord

is a narrowed type of VariantRecord that holds a variant_body of type V2 ๐Ÿ’…โœจ.

4.7. Cryptographic Attributes โœจ

okay so bestie, this is where the crypto glow-up happens ๐Ÿ’… There are four cryptographic operations: digital signing, stream cipher encryption, block cipher encryption, and public key encryption. They're called digitally-signed, stream-ciphered, block-ciphered, and public-key-encrypted, respectively. To tag a field with one, you put that keyword right before the field's type. The keys aren't written out anywhere because they're implied by the current session state (see Section 5.1) ๐Ÿ”

For digital signing, one-way hash functions are fed into a signing algorithm. With RSA signing, a 36-byte structure holding two hashes (one SHA and one MD5) gets signed, which means it's encrypted with the private key. With DSS, the 20 bytes of the SHA hash go straight through the Digital Signature Algorithm with no extra hashing ๐Ÿ˜ค

Stream cipher encryption is giving XOR energy ๐Ÿฆ‹ The plaintext is exclusive-ORed with an identical amount of output generated from a cryptographically secure keyed pseudorandom number generator.

Block cipher encryption means every block of plaintext encrypts to a block of ciphertext. Plaintext almost never fits neatly into the block size (usually 64 bits), so the end of any short block gets padded with some regular pattern, usually all zeroes ๐Ÿงš

Public key encryption uses one-way functions with secret "trapdoors" to encrypt the outgoing data. Data encrypted with the public key of a key pair can only be decrypted with the private key, and vice versa ๐Ÿ”‘

Here's an example, and it's so cute:

stream-ciphered struct {
    uint8 field1;
    uint8 field2;
    digitally-signed opaque hash[20];
} UserType;

So the contents of hash are used as input for the signing algorithm, and then the entire structure gets encrypted with a stream cipher. Iconic ๐ŸŽ€

4.8. Constants ๐ŸŒธ

You can define typed constants for specification purposes by declaring a symbol of the type you want and assigning values to it. Under-specified types (opaque, variable-length vectors, and structures that contain opaque) can't be assigned values. And no fields of a multi-element structure or vector may be elided, so every single one has to show up ๐Ÿ™ˆ

For example:

struct {
    uint8 f1;
    uint8 f2;
} Example1;

Example1 ex1 = {1, 4};/* assigns f1 = 1, f2 = 4 */

5. SSL Protocol ๐Ÿซถ

SSL is a layered protocol, and at each layer, messages may include fields for length, description, and content. SSL takes the messages to be sent, fragments the data into manageable blocks, optionally compresses it, applies a MAC, encrypts, and transmits the result. On the receiving end, the data gets decrypted, verified, decompressed, and reassembled, then delivered to the higher level clients ๐Ÿ“ฆ

5.1. Session and Connection States ๐Ÿ’œ

An SSL session is stateful, and it's the job of the SSL handshake protocol to coordinate the states of the client and server. That's how each side's protocol state machine can keep running consistently, even though the state isn't exactly parallel between them. Logically, the state is represented twice: once as the current operating state, and (during the handshake protocol) again as the pending state. There are also separate read and write states. When the client or server receives a change cipher spec message, it copies the pending read state into the current read state. When it sends one, it copies the pending write state into the current write state. Once the handshake negotiation is complete, the client and server exchange change cipher spec messages (see Section 5.3), and then they communicate using the newly agreed-upon cipher spec ๐Ÿ”ฅ

An SSL session can include multiple secure connections, and parties can also have multiple simultaneous sessions. Multitasking queen ๐Ÿ‘‘

The session state includes these elements:

  • session identifier: An arbitrary byte sequence chosen by the server to identify an active or resumable session state.
  • peer certificate: The X509.v3 [X509] certificate of the peer. This element of the state may be null.
  • compression method: The algorithm used to compress data before encryption.
  • cipher spec: Specifies the bulk data encryption algorithm (such as null, DES, etc.) and a MAC algorithm (such as MD5 or SHA). It also defines cryptographic attributes such as the hash_size. (See Appendix A.7 for formal definition.)
  • master secret: A 48-byte secret shared between the client and server.
  • is resumable: A flag indicating whether the session can be used to initiate new connections.

The connection state includes these elements:

  • server and client random: Byte sequences chosen by the server and client for each connection.
  • server write MAC secret: The secret used in MAC operations on data written by the server.
  • client write MAC secret: The secret used in MAC operations on data written by the client.
  • server write key: The bulk cipher key for data encrypted by the server and decrypted by the client.
  • client write key: The bulk cipher key for data encrypted by the client and decrypted by the server.
  • initialization vectors: When a block cipher in Cipher Block Chaining (CBC) mode is used, an initialization vector (IV) is maintained for each key. This field is first initialized by the SSL handshake protocol. After that, the final ciphertext block from each record is preserved for use with the following record.
  • sequence numbers: Each party maintains separate sequence numbers for transmitted and received messages for each connection. When a party sends or receives a change cipher spec message, the appropriate sequence number is set to zero. Sequence numbers are of type uint64 and may not exceed 2^64-1 โœจ

5.2. Record Layer ๐Ÿฆ‹

The SSL record layer receives uninterpreted data from higher layers in non-empty blocks of arbitrary size.

5.2.1. Fragmentation ๐Ÿ“

The record layer fragments information blocks into SSLPlaintext records of 2^14 bytes or less. Client message boundaries aren't preserved in the record layer, so multiple client messages of the same ContentType may get coalesced into a single SSLPlaintext record (i.e., the boundaries just vanish, bestie ๐Ÿซ ).

struct {
    uint8 major, minor;
} ProtocolVersion;

enum {
    change_cipher_spec(20), alert(21), handshake(22),
    application_data(23), (255)
} ContentType;

struct {
    ContentType type;
    ProtocolVersion version;
    uint16 length;
    opaque fragment[SSLPlaintext.length];
} SSLPlaintext;
  • type: The higher level protocol used to process the enclosed fragment.
  • version: The version of the protocol being used. This document describes SSL version 3.0 (see Appendix A.1).
  • length: The length (in bytes) of the following SSLPlaintext.fragment. The length should not exceed 2^14.
  • fragment: The application data. This data is transparent and treated as an independent block to be dealt with by the higher level protocol specified by the type field.
Note: Data of different SSL record layer content types may be interleaved. Application data is generally lower in precedence for transmission than other content types. ๐Ÿ’…

5.2.2. Record Compression and Decompression ๐ŸŒˆ

All records are compressed using the compression algorithm defined in the current session state. There's always an active compression algorithm, but initially it's defined as CompressionMethod.null. The compression algorithm translates an SSLPlaintext structure into an SSLCompressed structure. Compression functions erase their state information whenever the CipherSpec is replaced.

Note: The CipherSpec is part of the session state described in Section 5.1. References to fields of the CipherSpec are made throughout this document using presentation syntax. A more complete description of the CipherSpec is shown in Appendix A.7.

Compression must be lossless and may not increase the content length by more than 1024 bytes. If the decompression function encounters an SSLCompressed.fragment that would decompress to a length over 2^14 bytes, it should issue a fatal decompression_failure alert (Section 5.4.2). Yikes ๐Ÿ˜ญ

struct {
    ContentType type;       /* same as SSLPlaintext.type */
    ProtocolVersion version;/* same as SSLPlaintext.version */
    uint16 length;
    opaque fragment[SSLCompressed.length];
} SSLCompressed;
  • length: The length (in bytes) of the following SSLCompressed.fragment. The length should not exceed 2^14 + 1024.
  • fragment: The compressed form of SSLPlaintext.fragment.
Note: A CompressionMethod.null operation is an identity operation, so no fields are altered (see Appendix A.4.1.)

Implementation note: Decompression functions are responsible for making sure that messages can't cause internal buffer overflows. Safety first, always ๐Ÿ›ก๏ธ

5.2.3. Record Payload Protection and the CipherSpec ๐Ÿ”

All records are protected using the encryption and MAC algorithms defined in the current CipherSpec. There's always an active CipherSpec, but initially it's SSL_NULL_WITH_NULL_NULL, which doesn't provide any security ๐Ÿ’€

Once the handshake is complete, the two parties have shared secrets that they use to encrypt records and compute keyed Message Authentication Codes (MACs) on their contents. The techniques used for the encryption and MAC operations are defined by the CipherSpec and constrained by CipherSpec.cipher_type. The encryption and MAC functions translate an SSLCompressed structure into an SSLCiphertext, and the decryption functions reverse the process. Transmissions also include a sequence number, so missing, altered, or extra messages are detectable ๐Ÿ‘€

struct {
    ContentType type;
    ProtocolVersion version;
    uint16 length;
    select (CipherSpec.cipher_type) {
        case stream: GenericStreamCipher;
        case block: GenericBlockCipher;
    } fragment;
} SSLCiphertext;
  • type: The type field is identical to SSLCompressed.type.
  • version: The version field is identical to SSLCompressed.version.
  • length: The length (in bytes) of the following SSLCiphertext.fragment. The length may not exceed 2^14 + 2048.
  • fragment: The encrypted form of SSLCompressed.fragment, including the MAC.

5.2.3.1. Null or Standard Stream Cipher

okay so stream ciphers (this includes BulkCipherAlgorithm.null, see Appendix A.7 ๐ŸŒธ) are the ones that take SSLCompressed.fragment structures and turn them into SSLCiphertext.fragment structures, and back again ๐Ÿ’–

        stream-ciphered struct {
            opaque content[SSLCompressed.length];
            opaque MAC[CipherSpec.hash_size];
        } GenericStreamCipher;

the MAC gets generated like this ๐Ÿ”ฅ

        hash(MAC_write_secret + pad_2 +
             hash(MAC_write_secret + pad_1 + seq_num +
                  SSLCompressed.type + SSLCompressed.length +
                  SSLCompressed.fragment));

where "+" means concatenation ๐ŸŽ€

  • pad_1: the character 0x36 repeated 48 times for MD5 or 40 times for SHA. โœจ
  • pad_2: the character 0x5c repeated 48 times for MD5 or 40 times for SHA. ๐Ÿ’…
  • seq_num: the sequence number for this message. ๐Ÿฆ‹
  • hash: the hashing algorithm derived from the cipher suite. ๐Ÿงš

the MAC is computed before encryption, so the stream cipher encrypts the entire block, MAC included ๐Ÿ™ˆ for stream ciphers that don't use a synchronization vector (RC4 is one), the stream cipher state from the end of one record is simply carried over to the next packet. it's giving continuity ๐Ÿ’œ

If the CipherSuite is SSL_NULL_WITH_NULL_NULL, encryption is just the identity operation. The data isn't encrypted and the MAC size is zero, which means no MAC is used. ๐Ÿ’€

and SSLCiphertext.length is SSLCompressed.length plus CipherSpec.hash_size ๐ŸŒˆ

5.2.3.2. CBC Block Cipher

for block ciphers (like RC2 or DES), the encryption and MAC functions convert SSLCompressed.fragment structures to and from block SSLCiphertext.fragment structures. bestie this is the block-sized version and it's so iconic ๐Ÿ‘‘

        block-ciphered struct {
            opaque content[SSLCompressed.length];
            opaque MAC[CipherSpec.hash_size];
            uint8 padding[GenericBlockCipher.padding_length];
            uint8 padding_length;
        } GenericBlockCipher;

the MAC is generated as described in Section 5.2.3.1 ๐Ÿง

  • padding: padding that gets added to force the length of the plaintext to be a multiple of the block cipher's block length. ๐Ÿ“
  • padding_length: the length of the padding must be less than the cipher's block length and may be zero. The padding length should be such that the total size of the GenericBlockCipher structure is a multiple of the cipher's block length. โญ

the encrypted data length (SSLCiphertext.length) is one more than the sum of SSLCompressed.length, CipherSpec.hash_size, and padding_length ๐Ÿฆ‹

Note: with CBC, the initialization vector (IV) for the first record is provided by the handshake protocol. The IV for subsequent records is the last ciphertext block from the previous record. โœจ


5.3. Change Cipher Spec Protocol

the change cipher spec protocol exists to signal transitions in ciphering strategies ๐Ÿฆ‹ it's a single message, and it's encrypted and compressed under the current (not the pending) CipherSpec. the message is one single byte with the value 1 ๐ŸŒธ

        struct {
            enum { change_cipher_spec(1), (255) } type;
        } ChangeCipherSpec;

both the client and the server send this message to tell the receiving party that subsequent records will be protected under the just-negotiated CipherSpec and keys ๐Ÿ’– when it's received, the receiver copies the read pending state into the read current state. the client sends a change cipher spec message after the handshake key exchange and certificate verify messages (if any), and the server sends one after successfully processing the key exchange message it got from the client. ๐Ÿซถ an unexpected change cipher spec message should generate an unexpected_message alert (Section 5.4.2). when resuming a previous session, the change cipher spec message is sent after the hello messages. ๐ŸŒˆ


5.4. Alert Protocol

one of the content types the SSL record layer supports is the alert type ๐Ÿšจ alert messages convey the severity of the message and a description of the alert. alert messages with a level of fatal result in the immediate termination of the connection. in that case, other connections belonging to the session may continue, but the session identifier must be invalidated, so the failed session can't be used to set up new connections ๐Ÿ’€ like other messages, alert messages are encrypted and compressed, as specified by the current connection state. ๐Ÿ”

        enum { warning(1), fatal(2), (255) } AlertLevel;

        enum {
            close_notify(0),
            unexpected_message(10),
            bad_record_mac(20),
            decompression_failure(30),
            handshake_failure(40),
            no_certificate(41),
            bad_certificate(42),
            unsupported_certificate(43),
            certificate_revoked(44),
            certificate_expired(45),
            certificate_unknown(46),
            illegal_parameter (47)
            (255)
        } AlertDescription;

        struct {
            AlertLevel level;
            AlertDescription description;
        } Alert;

5.4.1. Closure Alerts

the client and the server must both know the connection is ending, so they can avoid a truncation attack ๐Ÿ™…โ€โ™€๏ธ either party may start the exchange of closing messages.

  • close_notify: this message tells the recipient that the sender won't send any more messages on this connection. The session becomes unresumable if any connection is terminated without proper close_notify messages with level equal to warning. ๐Ÿ˜ญ

either party can start a close by sending a close_notify alert. any data received after a closure alert gets ignored ๐Ÿงธ

each party is required to send a close_notify alert before closing the write side of the connection. the other party is required to respond with a close_notify alert of its own and close down the connection immediately, throwing away any pending writes. the initiator of the close isn't required to wait for that responding close_notify alert before closing the read side of the connection. ๐Ÿƒ

NB: it's assumed that closing a connection reliably delivers pending data before destroying the transport. ๐ŸŒท

5.4.2. Error Alerts

error handling in the SSL handshake protocol is very simple, bestie ๐Ÿ’… when an error is detected, the detecting party sends a message to the other party. once a fatal alert message is sent or received, both parties immediately close the connection. servers and clients are required to forget any session identifiers, keys, and secrets associated with a failed connection. the following error alerts are defined:

  • unexpected_message: an inappropriate message was received. This alert is always fatal and should never be observed in communication between proper implementations. ๐Ÿ™ˆ
  • bad_record_mac: this alert is returned if a record is received with an incorrect MAC. This message is always fatal. ๐Ÿ’”
  • decompression_failure: the decompression function received improper input (e.g., data that would expand to excessive length). This message is always fatal. ๐ŸŒช๏ธ
  • handshake_failure: reception of a handshake_failure alert message indicates that the sender was unable to negotiate an acceptable set of security parameters given the options available. This is a fatal error. ๐Ÿ˜ค
  • no_certificate: a no_certificate alert message may be sent in response to a certification request if no appropriate certificate is available. ๐ŸŽ€
  • bad_certificate: a certificate was corrupt, contained signatures that did not verify correctly, etc. ๐Ÿ“œ
  • unsupported_certificate: a certificate was of an unsupported type. ๐Ÿงฉ
  • certificate_revoked: a certificate was revoked by its signer. โŒ
  • certificate_expired: a certificate has expired or is not currently valid. โฐ
  • certificate_unknown: some other (unspecified) issue arose in processing the certificate, rendering it unacceptable. ๐ŸŒซ๏ธ
  • illegal_parameter: a field in the handshake was out of range or inconsistent with other fields. This is always fatal. ๐Ÿšซ

5.5. Handshake Protocol Overview ๐Ÿค

okay so the session state's crypto parameters are cooked up by the SSL handshake protocol, which runs on top of the SSL record layer ๐Ÿ’…. When a client and server first start talking, they agree on a protocol version, pick their cryptographic algorithms, optionally authenticate each other, and use public key encryption to generate shared secrets ๐Ÿ”. The handshake goes like this: the client sends a client hello message, and the server must reply with a server hello message, or else a fatal error happens and the connection fails ๐Ÿ’€. The hello messages set up the security enhancement capabilities, and they establish Protocol Version, Session ID, Cipher Suite, and Compression Method. Two random values also get generated and swapped: ClientHello.random and ServerHello.random ๐ŸŽฒ

After the hellos, the server sends its certificate if it's going to be authenticated ๐Ÿ“œ. A server key exchange message may also be sent if it's needed, like if the server has no certificate or if its certificate is for signing only ๐Ÿ™ˆ. If the server is authenticated, it may ask the client for a certificate, as long as that makes sense for the chosen cipher suite ๐Ÿชช. Then the server sends the server hello done message, which means the hello phase is finished, and it waits for the client to respond ๐ŸŽ€. If the server sent a certificate request, the client must send either a certificate message or a no_certificate alert. Next comes the client key exchange message, and what's inside depends on the public key algorithm picked during the hellos โœจ. If the client sent a certificate with signing ability, a digitally-signed certificate verify message goes out to explicitly verify that certificate ๐Ÿ–‹๏ธ

Now the client sends a change cipher spec message and copies the pending CipherSpec into the current CipherSpec ๐Ÿฆ‹. It immediately sends the finished message under the new algorithms, keys, and secrets ๐Ÿ”‘. The server responds with its own change cipher spec message, moves the pending CipherSpec to the current one, and sends its finished message under the new CipherSpec ๐ŸŒธ. At this point the handshake is complete, and the client and server may start exchanging application layer data ๐ŸŽ‰ (see the flow chart below ๐Ÿ‘‡).

      Client                                                Server

      ClientHello                   -------->
                                                       ServerHello
                                                      Certificate*
                                                ServerKeyExchange*
                                               CertificateRequest*
                                    <--------      ServerHelloDone
      Certificate*
      ClientKeyExchange
      CertificateVerify*
      [ChangeCipherSpec]
      Finished                      -------->
                                                [ChangeCipherSpec]
                                    <--------             Finished
      Application Data              <------->     Application Data

      * Indicates optional or situation-dependent messages that are not
        always sent.
๐Ÿ‘€ Quick note: to help avoid pipeline stalls, ChangeCipherSpec is its own independent SSL protocol content type. It is not actually an SSL handshake message, so don't mix them up!

When the client and server want to resume a previous session or duplicate an existing one (instead of negotiating fresh security parameters), the flow looks different ๐Ÿ”. The client sends a ClientHello using the session ID of the session it wants to resume. The server checks its session cache for a match ๐Ÿ”. If it finds one and is willing to re-establish the connection under that session state, it sends a ServerHello with the same session ID value ๐Ÿ’œ. Then both client and server must send change cipher spec messages and go straight to finished messages ๐Ÿƒโ€โ™€๏ธ. Once re-establishment is done, they can start exchanging application layer data (see the flow chart below ๐Ÿ‘‡). If there's no session ID match, the server generates a new session ID, and the SSL client and server do a full handshake instead ๐Ÿงš

      Client                                                Server

      ClientHello                   -------->
                                                       ServerHello
                                              [change cipher spec]
                                    <--------             Finished
      change cipher spec
      Finished                      -------->
      Application Data              <------->     Application Data

The contents and meaning of each message get the full breakdown in the sections that follow ๐Ÿ“šโœจ

5.6. Handshake Protocol ๐Ÿงฉ

The SSL handshake protocol is one of the defined higher level clients of the SSL record protocol ๐Ÿ’–. It negotiates the secure attributes of a session. Handshake messages get handed to the SSL record layer, where they're wrapped in one or more SSLPlaintext structures. Those get processed and sent according to the current active session state ๐Ÿš€

        enum {
            hello_request(0), client_hello(1), server_hello(2),
            certificate(11), server_key_exchange (12),
            certificate_request(13), server_hello_done(14),
            certificate_verify(15), client_key_exchange(16),
            finished(20), (255)
        } HandshakeType;

        struct {
            HandshakeType msg_type;    /* handshake type */
            uint24 length;             /* bytes in message */
            select (HandshakeType) {
                case hello_request: HelloRequest;
                case client_hello: ClientHello;
                case server_hello: ServerHello;
                case certificate: Certificate;
                case server_key_exchange: ServerKeyExchange;
                case certificate_request: CertificateRequest;
                case server_hello_done: ServerHelloDone;
                case certificate_verify: CertificateVerify;
                case client_key_exchange: ClientKeyExchange;
                case finished: Finished;
            } body;
        } Handshake;

The handshake protocol messages have to be sent in the order they're listed. Sending them in an unexpected order is a fatal error, so keep those vibes in order ๐Ÿซถ

5.6.1. Hello messages ๐Ÿ‘‹

The hello phase messages are how the client and server swap security enhancement capabilities ๐Ÿค. When a new session begins, the CipherSpec encryption, hash, and compression algorithms are all initialized to null ๐Ÿซฅ. The current CipherSpec is used for renegotiation messages ๐Ÿ”„

5.6.1.1. Hello Request ๐Ÿ“ฃ

The server can send a hello request message at any time ๐Ÿ™‹โ€โ™€๏ธ. The client will ignore it if the handshake protocol is already underway, though ๐Ÿ™…โ€โ™€๏ธ. It's basically a simple notification that says "hey, start negotiating again by sending a client hello whenever you're ready" ๐Ÿ’Œ

โฑ๏ธ Note: handshake messages are meant to take transmission priority over application data. So the negotiation is expected to begin within no more than one or two times the transmission time of a maximum-length application data message.

After sending a hello request, servers should not repeat it until the next handshake negotiation is complete ๐Ÿ›‘. A client that gets a hello request while it's already in a handshake negotiation state should just ignore the message ๐Ÿ™ˆ

The structure of a hello request message is:

        struct { } HelloRequest;

5.6.1.2. Client Hello ๐Ÿ’Œ

okay so when a client first connects to a server, it has to send the client hello as its very first message ๐Ÿซถ It can also send one in response to a hello request, or just on its own initiative, to renegotiate the security parameters in an existing connection. The client hello carries a random structure that gets used later on, so it's giving main character energy ๐Ÿ’…

      struct {
          uint32 gmt_unix_time;
          opaque random_bytes[28];
      } Random;
  • gmt_unix_time: the current time and date in standard UNIX 32-bit format, according to the sender's internal clock. Clocks are not required to be set correctly by the basic SSL protocol. Higher level or application protocols may define additional requirements โฐ
  • random_bytes: 28 bytes generated by a secure random number generator ๐ŸŽฒ

The client hello also includes a variable-length session identifier ๐Ÿฆ‹ If it isn't empty, it identifies a session between the same client and server whose security parameters the client wants to reuse. That session can come from an earlier connection, from this connection, or from another connection that's currently active. The second option is useful if the client only wants to refresh the random structures and derived values of a connection. The third option lets you set up several simultaneous independent secure connections without redoing the full handshake protocol, which is so efficient ๐Ÿงš The actual contents of the SessionID are defined by the server.

        opaque SessionID<0..32>;
Warning: Servers must not place confidential information in session identifiers, or let the contents of fake session identifiers cause any breach of security. Seriously, don't do it ๐Ÿ™ˆ

The CipherSuite list goes from the client to the server in the client hello, and it's basically the client's wishlist of cryptographic algorithms, ordered by preference (first choice first) ๐Ÿ’œ Each CipherSuite defines both a key exchange algorithm and a CipherSpec. The server picks one suite. If none of the choices are acceptable, it returns a handshake failure alert and closes the connection ๐Ÿ’€

        uint8 CipherSuite[2];  /* Cryptographic suite selector */

The client hello also includes a list of compression algorithms the client supports, ordered by its preference. If the server doesn't support any of them, the session must fail ๐Ÿฅฒ

        enum { null(0), (255) } CompressionMethod;

Issue: which compression methods to support is still under investigation ๐Ÿ”

The structure of the client hello looks like this ๐Ÿ‘€

        struct {
            ProtocolVersion client_version;
            Random random;
            SessionID session_id;
            CipherSuite cipher_suites<2..2^16-1>;
            CompressionMethod compression_methods<1..2^8-1>;
        } ClientHello;
  • client_version: the version of the SSL protocol the client wants to use for this session. It should be the most recent (highest valued) version the client supports. For this version of the specification, the version will be 3.0 (see Appendix E for details about backward compatibility) ๐ŸŒˆ
  • random: a client-generated random structure ๐ŸŽ€
  • session_id: the ID of a session the client wants to use for this connection. This field should be empty if no session_id is available, or if the client wants to generate new security parameters ๐Ÿ“
  • cipher_suites: the list of cryptographic options the client supports, sorted with the client's first preference first. If the session_id field is not empty (which implies a session resumption request), this vector must include at least the cipher_suite from that session. Values are defined in Appendix A.6 ๐Ÿ”
  • compression_methods: the list of compression methods the client supports, sorted by client preference. If the session_id field is not empty (again, a session resumption request), this vector must include at least the compression_method from that session. All implementations must support CompressionMethod.null ๐Ÿซง

After sending the client hello, the client waits for a server hello message โณ Any other handshake message the server returns, except for a hello request, is treated as a fatal error ๐Ÿšจ

Implementation note: application data may not be sent before a finished message has been sent. Transmitted application data is known to be insecure until a valid finished message has been received. This absolute restriction is relaxed if there is a current, non-null encryption on this connection ๐Ÿ”’

Forward compatibility note: for the sake of forward compatibility, it's permitted for a client hello message to include extra data after the compression methods. That data must be included in the handshake hashes, but otherwise it must be ignored ๐Ÿง

5.6.1.3. Server Hello ๐ŸŒธ

The server processes the client hello and responds with either a handshake_failure alert or a server hello message ๐Ÿ’…

        struct {
            ProtocolVersion server_version;
            Random random;
            SessionID session_id;
            CipherSuite cipher_suite;
            CompressionMethod compression_method;
        } ServerHello;
  • server_version: this field will contain the lower of the version suggested by the client in the client hello and the highest version supported by the server. For this version of the specification, the version will be 3.0 (see Appendix E for details about backward compatibility) โœจ
  • random: this structure is generated by the server and must be different from (and independent of) ClientHello.random ๐ŸŽฒ
  • session_id: the identity of the session corresponding to this connection. If ClientHello.session_id was non-empty, the server will look in its session cache for a match. If a match is found and the server is willing to establish the new connection using the specified session state, the server will respond with the same value the client supplied. This indicates a resumed session and dictates that the parties must proceed directly to the finished messages ๐ŸŽ‰ Otherwise, this field will contain a different value identifying the new session. The server may return an empty session_id to indicate that the session will not be cached, and therefore cannot be resumed ๐Ÿซ 
  • cipher_suite: the single cipher suite the server selected from the list in ClientHello.cipher_suites. For resumed sessions, this field is the value from the state of the session being resumed ๐Ÿ”
  • compression_method: the single compression algorithm the server selected from the list in ClientHello.compression_methods. For resumed sessions, this field is the value from the resumed session state ๐Ÿซง

5.6.2. Server Certificate ๐Ÿ“œ

If the server is to be authenticated (which is generally the case), the server sends its certificate immediately after the server hello message ๐Ÿชช The certificate type must be appropriate for the selected cipher suite's key exchange algorithm. It's generally an X.509.v3 certificate, or a modified X.509 certificate in the case of FORTEZZA(tm) [FOR]. The same message type is used for the client's response to a certificate request message ๐Ÿ™Œ

        opaque ASN.1Cert<1..2^24-1>;
        struct {
            ASN.1Cert certificate_list<1..2^24-1>;
        } Certificate;
  • certificate_list: a sequence (chain) of X.509.v3 certificates, ordered with the sender's certificate first, followed by any certificate authority certificates proceeding sequentially upward ๐Ÿ”—

Note: PKCS #7 [PKCS7] is not used as the format for the certificate vector, because PKCS #6 [PKCS6] extended certificates are not used. Also, PKCS #7 defines a Set rather than a Sequence, which makes parsing the list harder ๐Ÿ˜ญ

5.6.3. Server Key Exchange Message ๐Ÿ—๏ธ

The server key exchange message is sent by the server if it has no certificate, if it has a certificate that's only used for signing (for example, DSS [DSS] certificates or signing-only RSA [RSA] certificates), or if FORTEZZA KEA key exchange is used. This message is not used if the server certificate contains Diffie-Hellman [DH1] parameters ๐Ÿง 

Note: according to current US export law, RSA moduli larger than 512 bits may not be used for key exchange in software exported from the US. With this message, larger RSA keys may be used as signature-only certificates to sign temporary shorter RSA keys for key exchange ๐Ÿ‡บ๐Ÿ‡ธ

        enum { rsa, diffie_hellman, fortezza_kea }
               KeyExchangeAlgorithm;

        struct {
            opaque rsa_modulus<1..2^16-1>;
            opaque rsa_exponent<1..2^16-1>;
        } ServerRSAParams;
  • rsa_modulus: the modulus of the server's temporary RSA key ๐Ÿ”ข
  • rsa_exponent: the public exponent of the server's temporary RSA key ๐Ÿ”ข
        struct {
            opaque dh_p<1..2^16-1>;
            opaque dh_g<1..2^16-1>;
            opaque dh_Ys<1..2^16-1>;
        } ServerDHParams;     /* Ephemeral DH parameters */
  • dh_p: the prime modulus used for the Diffie-Hellman operation ๐Ÿงฎ
  • dh_g: the generator used for the Diffie-Hellman operation ๐Ÿงฎ
  • dh_Ys: the server's Diffie-Hellman public value (gX mod p) ๐Ÿ”‘
        struct {
            opaque r_s [128];
        } ServerFortezzaParams;
  • r_s: server random number for FORTEZZA KEA (Key Exchange Algorithm) ๐ŸŽฒ
        struct {
            select (KeyExchangeAlgorithm) {
                case diffie_hellman:
                    ServerDHParams params;
                    Signature signed_params;
                case rsa:
                    ServerRSAParams params;
                    Signature signed_params;
                case fortezza_kea:
                    ServerFortezzaParams params;
            };
        } ServerKeyExchange;
  • params: the server's key exchange parameters ๐Ÿ—‚๏ธ
  • signed_params: a hash of the corresponding params value, with the signature appropriate to that hash applied โœ๏ธ
  • md5_hash: MD5(ClientHello.random + ServerHello.random + ServerParams);
  • sha_hash: SHA(ClientHello.random + ServerHello.random + ServerParams);
        enum { anonymous, rsa, dsa } SignatureAlgorithm;

        digitally-signed struct {
            select(SignatureAlgorithm) {
                case anonymous: struct { };
                case rsa:
                    opaque md5_hash[16];
                    opaque sha_hash[20];
                case dsa:
                    opaque sha_hash[20];
            };
        } Signature;

5.6.4. Certificate Request ๐Ÿ™‹โ€โ™€๏ธ

A non-anonymous server can optionally request a certificate from the client, if that's appropriate for the selected cipher suite ๐Ÿ’–

        enum {
            rsa_sign(1), dss_sign(2), rsa_fixed_dh(3), dss_fixed_dh(4),
            rsa_ephemeral_dh(5), dss_ephemeral_dh(6), fortezza_kea(20),
            (255)
        } ClientCertificateType;

        opaque DistinguishedName<1..2^16-1>;

        struct {
            ClientCertificateType certificate_types<1..2^8-1>;
            DistinguishedName certificate_authorities<3..2^16-1>;
        } CertificateRequest;
  • certificate_types: a list of the types of certificates requested, sorted in order of the server's preference ๐Ÿท๏ธ
  • certificate_authorities: a list of the distinguished names of acceptable certificate authorities ๐Ÿ›๏ธ

Note: DistinguishedName is derived from [X509] ๐Ÿ“Ž

Note: it is a fatal handshake_failure alert for an anonymous server to request client identification ๐Ÿšซ

5.6.5. Server Hello Done โœจ

okay so the server hello done message is how the server says "bestie, that's everything from my hello and friends, I'm done" ๐Ÿ’… it's sent to mark the end of the server hello and its associated messages. after sending it, the server just waits for a client response ๐Ÿซถ

struct { } ServerHelloDone;

once the client gets this one, it should check that the server gave a valid certificate if one was required, and that the server hello parameters are acceptable ๐Ÿ”

5.6.6. Client Certificate ๐ŸŽ€

this is the first message the client can send after getting a server hello done message ๐Ÿฆ‹ it only gets sent if the server asks for a certificate. if the client doesn't have a suitable one, it should send a no_certificate alert instead. that alert is only a warning tho, so lowkey chill ๐Ÿ˜Œ but the server may still respond with a fatal handshake failure alert if client authentication is required ๐Ÿ˜ญ client certificates are sent using the certificate defined in Section 5.6.2 ๐Ÿ’œ

Note: Client Diffie-Hellman certificates must match the server specified Diffie-Hellman parameters. ๐ŸŒธ

5.6.7. Client Key Exchange Message ๐Ÿ”‘

the messages you use depend on which public key algorithm(s) got selected. see Section 5.6.3 for the KeyExchangeAlgorithm definition ๐Ÿงš

struct {
    select (KeyExchangeAlgorithm) {
        case rsa: EncryptedPreMasterSecret;
        case diffie_hellman: ClientDiffieHellmanPublic;
        case fortezza_kea: FortezzaKeys;
    } exchange_keys;
} ClientKeyExchange;

the info needed to pick the right record structure lives in the pending session state (see Section 5.1) โœจ

5.6.7.1. RSA Encrypted Premaster Secret Message ๐Ÿ”

if RSA is being used for key agreement and authentication, the client generates a 48-byte premaster secret, encrypts it under the public key from the server's certificate (or the temporary RSA key from a server key exchange message), and sends the result in an encrypted premaster secret message ๐Ÿ’–

struct {
    ProtocolVersion client_version;
    opaque random[46];
} PreMasterSecret;
  • client_version: the latest (newest) version the client supports. this is used to detect version roll-back attacks ๐Ÿ‘€
  • random: 46 securely-generated random bytes ๐ŸŽฒ
struct {
    public-key-encrypted PreMasterSecret pre_master_secret;
} EncryptedPreMasterSecret;
  • pre_master_secret: this random value is generated by the client and is used to generate the master secret, as specified in Section 6.1 ๐Ÿ“

5.6.7.2. FORTEZZA Key Exchange Message ๐Ÿฆ‹

okay this one is giving secret agent energy ๐Ÿ•ต๏ธโ€โ™€๏ธ under FORTEZZA, the client derives a token encryption key (TEK) using the FORTEZZA Key Exchange Algorithm (KEA). the client's KEA calculation uses the public key in the server's certificate along with private parameters in the client's token. the client sends public parameters the server needs to generate the TEK, using its own private parameters. then the client generates session keys, wraps them using the TEK, and sends the results to the server. it also generates IVs for the session keys and TEK and sends those too. finally, the client generates a random 48-byte premaster secret, encrypts it using the TEK, and sends the result ๐Ÿ’Œ

struct {
    opaque y_c<0..128>;
    opaque r_c[128];
    opaque y_signature[40];
    opaque wrapped_client_write_key[12];
    opaque wrapped_server_write_key[12];
    opaque client_write_iv[24];
    opaque server_write_iv[24];
    opaque master_secret_iv[24];
    block-ciphered opaque encrypted_pre_master_secret[48];
} FortezzaKeys;
  • y_signature: this is the signature of the KEA public key, signed with the client's DSS private key ๐Ÿ–‹๏ธ
  • y_c: the client's Yc value (public key) for the KEA calculation. if the client has sent a certificate and its KEA public key is suitable, this value must be empty, because the certificate already contains this value. if the client sent a certificate without a suitable public key, y_c is used and y_signature is the KEA public key signed with the client's DSS private key. for this value to be used, it must be between 64 and 128 bytes ๐Ÿ“
  • r_c: the client's Rc value for the KEA calculation ๐Ÿ”ข
  • wrapped_client_write_key: this is the client's write key, wrapped by the TEK ๐ŸŽ
  • wrapped_server_write_key: this is the server's write key, wrapped by the TEK ๐ŸŽ
  • client_write_iv: the IV for the client write key ๐ŸŒˆ
  • server_write_iv: the IV for the server write key ๐ŸŒˆ
  • master_secret_iv: this is the IV for the TEK used to encrypt the premaster secret ๐Ÿ”
  • pre_master_secret: a random value, generated by the client and used to generate the master secret, as specified in Section 6.1. in the structure above, it is encrypted using the TEK ๐Ÿ’œ

5.6.7.3. Client Diffie-Hellman Public Value ๐Ÿ’Ž

this structure carries the client's Diffie-Hellman public value (Yc), but only if it wasn't already included in the client's certificate. the encoding used for Yc is decided by the enumerated PublicValueEncoding ๐Ÿง

enum { implicit, explicit } PublicValueEncoding;
  • implicit: if the client certificate already contains the public value, then it's implicit and Yc doesn't need to be sent again ๐Ÿ™…โ€โ™€๏ธ
  • explicit: Yc needs to be sent ๐Ÿ“จ
struct {
    select (PublicValueEncoding) {
        case implicit: struct { };
        case explicit: opaque dh_Yc<1..2^16-1>;
    } dh_public;
} ClientDiffieHellmanPublic;
  • dh_Yc: the client's Diffie-Hellman public value (Yc) ๐ŸŒท

5.6.8. Certificate Verify ๐Ÿ“œ

this message is used to give explicit verification of a client certificate. it's only sent after any client certificate that has signing capability (so, all certificates except those containing fixed Diffie-Hellman parameters) ๐Ÿ–Š๏ธ

          struct {
               Signature signature;
          } CertificateVerify;

        CertificateVerify.signature.md5_hash
                   MD5(master_secret + pad_2 +
                       MD5(handshake_messages + master_secret + pad_1));
        Certificate.signature.sha_hash
                   SHA(master_secret + pad_2 +
                       SHA(handshake_messages + master_secret + pad_1));
  • pad_1: this is identical to the pad_1 defined in Section 5.2.3.1 ๐Ÿงฉ
  • pad_2: this is identical to the pad_2 defined in Section 5.2.3.1 ๐Ÿงฉ

here, handshake_messages refers to all handshake messages starting at client hello, up to but not including this message ๐Ÿ“š

5.6.9. Finished ๐Ÿ

a finished message is always sent right after a change cipher spec message, to verify that the key exchange and authentication processes went well ๐ŸŽ‰ it's the first message protected with the just-negotiated algorithms, keys, and secrets. no acknowledgment of the finished message is required, so parties may start sending encrypted data straight after sending it. recipients of finished messages must verify that the contents are correct โœ…

enum { client(0x434C4E54), server(0x53525652) } Sender;

struct {
    opaque md5_hash[16];
    opaque sha_hash[20];
} Finished;
  • md5_hash:
MD5(master_secret + pad2 + MD5(handshake_messages + Sender
      + master_secret + pad1));
  • sha_hash:
SHA(master_secret + pad2 + SHA(handshake_messages + Sender
      + master_secret + pad1));
  • handshake_messages: all of the data from all handshake messages up to but not including this message. this is only data visible at the handshake layer and doesn't include record layer headers ๐Ÿ—‚๏ธ

it's a fatal error if a finished message isn't preceded by a change cipher spec message at the appropriate point in the handshake ๐Ÿ’€

the hash in finished messages sent by the server incorporates Sender.server, and those sent by the client incorporate Sender.client ๐Ÿซถ the value handshake_messages includes all handshake messages starting at client hello up to but not including this finished message. this may be different from handshake_messages in Section 5.6.8, because it would include the certificate verify message (if sent) ๐ŸŒˆ

Note: Change cipher spec messages are not handshake messages and are not included in the hash computations. ๐Ÿ™ˆ

5.7. Application Data Protocol ๐Ÿ“ฆ

application data messages are carried by the record layer and get fragmented, compressed, and encrypted based on the current connection state. the record layer treats these messages as transparent data ๐Ÿฆ‹

6. Cryptographic Computations ๐Ÿ”

the key exchange, authentication, encryption, and MAC algorithms are all determined by the cipher_suite the server selects and reveals in the server hello message ๐Ÿ‘‘

6.1. Asymmetric Cryptographic Computations ๐Ÿ—๏ธ

the asymmetric algorithms are used in the handshake protocol to authenticate parties and to generate shared keys and secrets ๐Ÿ’œ

for Diffie-Hellman, RSA, and FORTEZZA, the same algorithm is used to convert the pre_master_secret into the master_secret. the pre_master_secret should be deleted from memory once the master_secret has been computed ๐Ÿงน

master_secret =
  MD5(pre_master_secret + SHA('A' + pre_master_secret +
      ClientHello.random + ServerHello.random)) +
  MD5(pre_master_secret + SHA('BB' + pre_master_secret +
      ClientHello.random + ServerHello.random)) +
  MD5(pre_master_secret + SHA('CCC' + pre_master_secret +
      ClientHello.random + ServerHello.random));

6.1.1. RSA ๐Ÿ”

when RSA is used for server authentication and key exchange, a 48-byte pre_master_secret is generated by the client, encrypted under the server's public key, and sent to the server. the server uses its private key to decrypt the pre_master_secret. both parties then convert the pre_master_secret into the master_secret, as specified above ๐ŸŽ€

RSA digital signatures are performed using PKCS #1 [PKCS1] block type 1. RSA public key encryption is performed using PKCS #1 block type 2 ๐Ÿง 

6.1.2. Diffie-Hellman ๐ŸŒธ

a conventional Diffie-Hellman computation is performed. the negotiated key (Z) is used as the pre_master_secret, and is converted into the master_secret, as specified above ๐ŸŒท

Note: Diffie-Hellman parameters are specified by the server, and may be either ephemeral or contained within the server's certificate. ๐Ÿ“

6.1.3. FORTEZZA ๐Ÿ•ต๏ธโ€โ™€๏ธ

a random 48-byte pre_master_secret is sent encrypted under the TEK and its IV. the server decrypts the pre_master_secret and converts it into a master_secret, as specified above. bulk cipher keys and IVs for encryption are generated by the client's token and exchanged in the key exchange message. the master_secret is only used for MAC computations ๐Ÿ’…

6.2. Symmetric Cryptographic Calculations and the CipherSpec ๐ŸŽ€

the technique used to encrypt and verify the integrity of SSL records is specified by the currently active CipherSpec. a typical example would be to encrypt data using DES and generate authentication codes using MD5 ๐Ÿ’ซ the encryption and MAC algorithms are set to SSL_NULL_WITH_NULL_NULL at the beginning of the SSL handshake protocol, which means no message authentication or encryption is performed yet. the handshake protocol is used to negotiate a more secure CipherSpec and to generate cryptographic keys ๐Ÿ”‘โœจ

6.2.1. The Master Secret โœจ

okay so before any records can get encrypted or integrity-checked, the client and server need to make a secret that ONLY the two of them know ๐Ÿคซ this is a 48-byte value called the master secret, and it's the seed for basically all the keys and secrets used for encryption and MAC computations ๐Ÿ” bestie, FORTEZZA is the exception ๐Ÿ’… it has its own way of making encryption keys, and the master secret is only used for its MAC computations ๐Ÿซถ

6.2.2. Converting the Master Secret into Keys and MAC Secrets ๐Ÿฆ‹

the master secret gets hashed into a long stream of secure bytes, and those bytes get split up into the MAC secrets, keys, and non-export IVs that the current CipherSpec needs (check out Appendix A.7 for that) ๐ŸŒธ the CipherSpec needs six things: a client write MAC secret, a server write MAC secret, a client write key, a server write key, a client write IV, and a server write IV ๐Ÿ’– they're generated from the master secret in exactly that order โœจ anything that isn't needed, like the FORTEZZA keys that get sent in the KeyExchange message, just stays empty ๐Ÿงš the key definition process gets these inputs to work with:

opaque MasterSecret[48]
ClientHello.random
ServerHello.random

when we're making keys and MAC secrets, the master secret acts as the entropy source ๐Ÿ”ฅ and the two random values bring in the unencrypted salt material and the IVs for exportable ciphers ๐ŸŽ€

to make the key material, you compute this:

key_block =
  MD5(master_secret + SHA(`A' + master_secret +
                          ServerHello.random +
                          ClientHello.random)) +
  MD5(master_secret + SHA(`BB' + master_secret +
                          ServerHello.random +
                          ClientHello.random)) +
  MD5(master_secret + SHA(`CCC' + master_secret +
                          ServerHello.random +
                          ClientHello.random)) + [...];

you keep going until there's enough output ๐ŸŒˆ then you partition the key_block like this:

client_write_MAC_secret[CipherSpec.hash_size]
server_write_MAC_secret[CipherSpec.hash_size]
client_write_key[CipherSpec.key_material]
server_write_key[CipherSpec.key_material]
client_write_IV[CipherSpec.IV_size] /* non-export ciphers */
server_write_IV[CipherSpec.IV_size] /* non-export ciphers */

any leftover key_block material just gets tossed ๐Ÿ—‘๏ธ

exportable encryption algorithms (the ones where CipherSpec.is_exportable is true) need some extra steps to get their final write keys ๐Ÿ™ˆ

final_client_write_key = MD5(client_write_key +
                             ClientHello.random +
                             ServerHello.random);
final_server_write_key = MD5(server_write_key +
                             ServerHello.random +
                             ClientHello.random);

exportable algorithms also get their IVs from the random messages ๐Ÿ‘‘

client_write_IV = MD5(ClientHello.random + ServerHello.random);
server_write_IV = MD5(ServerHello.random + ClientHello.random);

and the MD5 outputs get trimmed down to the right size by dropping the least-significant bytes ๐Ÿ’œ

6.2.2.1. Export Key Generation Example ๐Ÿ“

let's do SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5 as an example, it's giving math but make it cute ๐Ÿงฎ it needs five random bytes for each of the two encryption keys and 16 bytes for each of the MAC keys, which adds up to 42 bytes of key material total ๐Ÿ’… MD5 spits out 16 bytes per call, so you need three MD5 calls ๐Ÿ”ฅ the outputs get glued together into a 48-byte key_block, with the first MD5 call filling bytes zero through 15, the second filling 16 through 31, and so on โœจ then you split up the key_block, and the write keys get salted because this is an exportable encryption algorithm ๐Ÿซถ

client_write_MAC_secret = key_block[0..15]
server_write_MAC_secret = key_block[16..31]
client_write_key      = key_block[32..36]
server_write_key      = key_block[37..41]
final_client_write_key = MD5(client_write_key +
                             ClientHello.random +
                             ServerHello.random)[0..15];
final_server_write_key = MD5(server_write_key +
                             ServerHello.random +
                             ClientHello.random)[0..15];
client_write_IV = MD5(ClientHello.random +
                      ServerHello.random)[0..7];
server_write_IV = MD5(ServerHello.random +
                      ClientHello.random)[0..7];

7. Security Considerations ๐Ÿ”’

okay this one's serious bestie ๐Ÿ˜ญ the full thing lives in Appendix F, so go check it out ๐Ÿซถ

8. Informative References ๐Ÿ“š

these are the extra reads that the document leans on, so here's the whole reading list ๐Ÿงš

  • [DH1] Diffie, W. and M. Hellman, "New Directions in Cryptography", IEEE Transactions on Information Theory V. IT-22, n. 6, pp. 74-84, June 1977.
  • [SSL-2] Hickman, K., "The SSL Protocol", February 1995.
  • [3DES] Tuchman, W., "Hellman Presents No Shortcut Solutions To DES", IEEE Spectrum, v. 16, n. 7, pp 40-41, July 1979.
  • [DES] ANSI X3.106, "American National Standard for Information Systems-Data Link Encryption", American National Standards Institute, 1983.
  • [DSS] NIST FIPS PUB 186, "Digital Signature Standard", National Institute of Standards and Technology U.S. Department of Commerce, May 1994.
  • [FOR] NSA X22, "FORTEZZA: Application Implementers Guide", Document # PD4002103-1.01, April 1995.
  • [RFC0959] Postel, J. and J. Reynolds, "File Transfer Protocol", STD 9, RFC 959, October 1985.
  • [RFC0791] Postel, J., "Internet Protocol", STD 5, RFC 791, September 1981.
  • [RFC1945] Berners-Lee, T., Fielding, R., and H. Nielsen, "Hypertext Transfer Protocol -- HTTP/1.0", RFC 1945, May 1996.
  • [RFC1321] Rivest, R., "The MD5 Message-Digest Algorithm", RFC 1321, April 1992.
  • [RFC0793] Postel, J., "Transmission Control Protocol", STD 7, RFC 793, September 1981.
  • [RFC0854] Postel, J. and J. Reynolds, "Telnet Protocol Specification", STD 8, RFC 854, May 1983.
  • [RFC1832] Srinivasan, R., "XDR: External Data Representation Standard", RFC 1832, August 1995.
  • [RFC2104] Krawczyk, H., Bellare, M., and R. Canetti, "HMAC: Keyed-Hashing for Message Authentication", RFC 2104, February 1997.
  • [IDEA] Lai, X., "On the Design and Security of Block Ciphers", ETH Series in Information Processing, v. 1, Konstanz: Hartung-Gorre Verlag, 1992.
  • [PKCS1] RSA Laboratories, "PKCS #1: RSA Encryption Standard version 1.5", November 1993.
  • [PKCS6] RSA Laboratories, "PKCS #6: RSA Extended Certificate Syntax Standard version 1.5", November 1993.
  • [PKCS7] RSA Laboratories, "PKCS #7: RSA Cryptographic Message Syntax Standard version 1.5", November 1993.
  • [RSA] Rivest, R., Shamir, A., and L. Adleman, "A Method for Obtaining Digital Signatures and Public-Key Cryptosystems", Communications of the ACM v. 21, n. 2 pp. 120-126., February 1978.
  • [SCH] Schneier, B., "Applied Cryptography: Protocols, Algorithms, and Source Code in C", John Wiley & Sons, 1994.
  • [SHA] NIST FIPS PUB 180-1, "Secure Hash Standard", May 1994.

National Institute of Standards and Technology, U.S. Department of Commerce, DRAFT

  • [X509] CCITT, "The Directory - Authentication Framework", Recommendation X.509 , 1988.
  • [RSADSI] RSA Data Security, Inc., "Unpublished works".

Appendix A. Protocol Constant Values ๐ŸŽ€

this section is where all the protocol types and constants live, so it's basically the cheat sheet ๐Ÿงš

A.1. Record Layer ๐ŸŒธ

struct {
    uint8 major, minor;
} ProtocolVersion;

ProtocolVersion version = { 3,0 };

enum {
    change_cipher_spec(20), alert(21), handshake(22),
    application_data(23), (255)
} ContentType;

struct {
    ContentType type;
    ProtocolVersion version;
    uint16 length;
    opaque fragment[SSLPlaintext.length];
} SSLPlaintext;

struct {
    ContentType type;
    ProtocolVersion version;
    uint16 length;
    opaque fragment[SSLCompressed.length];
} SSLCompressed;

struct {
    ContentType type;
    ProtocolVersion version;
    uint16 length;
    select (CipherSpec.cipher_type) {
        case stream: GenericStreamCipher;
        case block:  GenericBlockCipher;
    } fragment;
} SSLCiphertext;

stream-ciphered struct {
    opaque content[SSLCompressed.length];
    opaque MAC[CipherSpec.hash_size];
} GenericStreamCipher;

block-ciphered struct {
    opaque content[SSLCompressed.length];
    opaque MAC[CipherSpec.hash_size];
    uint8 padding[GenericBlockCipher.padding_length];
    uint8 padding_length;
} GenericBlockCipher;

A.2. Change Cipher Specs Message ๐Ÿ’–

struct {
    enum { change_cipher_spec(1), (255) } type;
} ChangeCipherSpec;

A.3. Alert Messages ๐Ÿšจ

enum { warning(1), fatal(2), (255) } AlertLevel;

enum {
    close_notify(0),
    unexpected_message(10),
    bad_record_mac(20),
    decompression_failure(30),
    handshake_failure(40),
    no_certificate(41),
    bad_certificate(42),
    unsupported_certificate(43),
    certificate_revoked(44),
    certificate_expired(45),
    certificate_unknown(46),
    illegal_parameter (47),
    (255)
} AlertDescription;

struct {
    AlertLevel level;
    AlertDescription description;
} Alert;

A.4. Handshake Protocol ๐Ÿค

enum {
    hello_request(0), client_hello(1), server_hello(2),
    certificate(11), server_key_exchange (12),
    certificate_request(13), server_done(14),
    certificate_verify(15), client_key_exchange(16),
    finished(20), (255)
} HandshakeType;

struct {
    HandshakeType msg_type;
    uint24 length;
    select (HandshakeType) {
        case hello_request: HelloRequest;
        case client_hello: ClientHello;
        case server_hello: ServerHello;
        case certificate: Certificate;
        case server_key_exchange: ServerKeyExchange;
        case certificate_request: CertificateRequest;
        case server_done: ServerHelloDone;
        case certificate_verify: CertificateVerify;
        case client_key_exchange: ClientKeyExchange;
        case finished: Finished;
    } body;
} Handshake;

A.4.1. Hello Messages ๐Ÿ‘‹

struct { } HelloRequest;

struct {
    uint32 gmt_unix_time;
    opaque random_bytes[28];
} Random;

opaque SessionID<0..32>;

uint8 CipherSuite[2];

enum { null(0), (255) } CompressionMethod;

struct {
    ProtocolVersion client_version;
    Random random;
    SessionID session_id;
    CipherSuite cipher_suites<0..2^16-1>;
    CompressionMethod compression_methods<0..2^8-1>;

} ClientHello;

struct {
    ProtocolVersion server_version;
    Random random;
    SessionID session_id;
    CipherSuite cipher_suite;
    CompressionMethod compression_method;
} ServerHello;

A.4.2. Server Authentication and Key Exchange Messages โœจ

Okay bestie, this is where the server shows its ID and the two sides start doing the key exchange dance ๐Ÿ’ƒ

opaque ASN.1Cert<2^24-1>;

struct {
    ASN.1Cert certificate_list<1..2^24-1>;
} Certificate;

enum { rsa, diffie_hellman, fortezza_kea } KeyExchangeAlgorithm;

struct {
    opaque RSA_modulus<1..2^16-1>;
    opaque RSA_exponent<1..2^16-1>;
} ServerRSAParams;

struct {
    opaque DH_p<1..2^16-1>;
    opaque DH_g<1..2^16-1>;
    opaque DH_Ys<1..2^16-1>;
} ServerDHParams;

struct {
    opaque r_s [128]
} ServerFortezzaParams

struct {
    select (KeyExchangeAlgorithm) {
        case diffie_hellman:
            ServerDHParams params;
            Signature signed_params;
        case rsa:
            ServerRSAParams params;
            Signature signed_params;
        case fortezza_kea:
            ServerFortezzaParams params;
    };
} ServerKeyExchange;
enum { anonymous, rsa, dsa } SignatureAlgorithm;

digitally-signed struct {
    select(SignatureAlgorithm) {
        case anonymous: struct { };
        case rsa:
            opaque md5_hash[16];
            opaque sha_hash[20];
        case dsa:
            opaque sha_hash[20];
    };
} Signature;


enum {
    RSA_sign(1), DSS_sign(2), RSA_fixed_DH(3),
    DSS_fixed_DH(4), RSA_ephemeral_DH(5), DSS_ephemeral_DH(6),
    FORTEZZA_MISSI(20), (255)
} CertificateType;

opaque DistinguishedName<1..2^16-1>;

struct {
    CertificateType certificate_types<1..2^8-1>;
    DistinguishedName certificate_authorities<3..2^16-1>;
} CertificateRequest;

struct { } ServerHelloDone;

A.5. Client Authentication and Key Exchange Messages ๐Ÿซถ

struct {
    select (KeyExchangeAlgorithm) {
        case rsa: EncryptedPreMasterSecret;
        case diffie_hellman: DiffieHellmanClientPublicValue;
        case fortezza_kea: FortezzaKeys;
    } exchange_keys;
} ClientKeyExchange;

struct {
    ProtocolVersion client_version;
    opaque random[46];
} PreMasterSecret;

struct {
    public-key-encrypted PreMasterSecret pre_master_secret;
} EncryptedPreMasterSecret;
struct {
    opaque y_c<0..128>;
    opaque r_c[128];
    opaque y_signature[40];
    opaque wrapped_client_write_key[12];
    opaque wrapped_server_write_key[12];
    opaque client_write_iv[24];
    opaque server_write_iv[24];
    opaque master_secret_iv[24];
    opaque encrypted_preMasterSecret[48];
} FortezzaKeys;

enum { implicit, explicit } PublicValueEncoding;

struct {
    select (PublicValueEncoding) {
        case implicit: struct {};
        case explicit: opaque DH_Yc<1..2^16-1>;
    } dh_public;
} ClientDiffieHellmanPublic;

struct {
    Signature signature;
} CertificateVerify;

A.5.1. Handshake Finalization Message ๐Ÿ’–

struct {
    opaque md5_hash[16];
    opaque sha_hash[20];
} Finished;

A.6. The CipherSuite ๐ŸŽ€

Here are the CipherSuite codes that show up in the client hello and server hello messages. A CipherSuite is basically a named cipher spec that SSL version 3.0 supports ๐Ÿงš

CipherSuite SSL_NULL_WITH_NULL_NULL                = { 0x00,0x00 };

Next up, these CipherSuite definitions need the server to have an RSA certificate that can handle key exchange. The server is allowed to ask for either an RSA or a DSS signature-capable certificate in the certificate request message ๐Ÿ”

CipherSuite SSL_RSA_WITH_NULL_MD5                  = { 0x00,0x01 };
CipherSuite SSL_RSA_WITH_NULL_SHA                  = { 0x00,0x02 };
CipherSuite SSL_RSA_EXPORT_WITH_RC4_40_MD5         = { 0x00,0x03 };
CipherSuite SSL_RSA_WITH_RC4_128_MD5               = { 0x00,0x04 };
CipherSuite SSL_RSA_WITH_RC4_128_SHA               = { 0x00,0x05 };
CipherSuite SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5     = { 0x00,0x06 };
CipherSuite SSL_RSA_WITH_IDEA_CBC_SHA              = { 0x00,0x07 };
CipherSuite SSL_RSA_EXPORT_WITH_DES40_CBC_SHA      = { 0x00,0x08 };
CipherSuite SSL_RSA_WITH_DES_CBC_SHA               = { 0x00,0x09 };
CipherSuite SSL_RSA_WITH_3DES_EDE_CBC_SHA          = { 0x00,0x0A };

These next suites are for server-authenticated Diffie-Hellman, and the client can optionally be authenticated too. ๐ŸŒธ Quick decoder ring: DH means the server's certificate carries the Diffie-Hellman parameters, signed by the certificate authority (CA). DHE means ephemeral Diffie-Hellman, where the parameters get signed by a DSS or RSA certificate, and that certificate has been signed by the CA. The signing algorithm is written after the DH or DHE part of the name. In every case the client must have the same type of certificate, and it must use the Diffie-Hellman parameters the server picked.

CipherSuite SSL_DH_DSS_EXPORT_WITH_DES40_CBC_SHA   = { 0x00,0x0B };
CipherSuite SSL_DH_DSS_WITH_DES_CBC_SHA            = { 0x00,0x0C };
CipherSuite SSL_DH_DSS_WITH_3DES_EDE_CBC_SHA       = { 0x00,0x0D };
CipherSuite SSL_DH_RSA_EXPORT_WITH_DES40_CBC_SHA   = { 0x00,0x0E };
CipherSuite SSL_DH_RSA_WITH_DES_CBC_SHA            = { 0x00,0x0F };
CipherSuite SSL_DH_RSA_WITH_3DES_EDE_CBC_SHA       = { 0x00,0x10 };
CipherSuite SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA  = { 0x00,0x11 };
CipherSuite SSL_DHE_DSS_WITH_DES_CBC_SHA           = { 0x00,0x12 };
CipherSuite SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA      = { 0x00,0x13 };
CipherSuite SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA  = { 0x00,0x14 };
CipherSuite SSL_DHE_RSA_WITH_DES_CBC_SHA           = { 0x00,0x15 };
CipherSuite SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA      = { 0x00,0x16 };

Now the completely anonymous Diffie-Hellman suites, where neither party gets authenticated. ๐Ÿ™ˆ

Heads up, bestie: this mode is open to man-in-the-middle attacks, so it is strongly discouraged. Please don't go near it.
CipherSuite SSL_DH_anon_EXPORT_WITH_RC4_40_MD5     = { 0x00,0x17 };
CipherSuite SSL_DH_anon_WITH_RC4_128_MD5           = { 0x00,0x18 };
CipherSuite SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA  = { 0x00,0x19 };
CipherSuite SSL_DH_anon_WITH_DES_CBC_SHA           = { 0x00,0x1A };
CipherSuite SSL_DH_anon_WITH_3DES_EDE_CBC_SHA      = { 0x00,0x1B };

The last batch is for the FORTEZZA token ๐Ÿ‘‘

CipherSuite SSL_FORTEZZA_KEA_WITH_NULL_SHA         = { 0X00,0X1C };
CipherSuite SSL_FORTEZZA_KEA_WITH_FORTEZZA_CBC_SHA = { 0x00,0x1D };
CipherSuite SSL_FORTEZZA_KEA_WITH_RC4_128_SHA      = { 0x00,0x1E };

Note: any cipher suite whose first byte is 0xFF counts as private, so it's free for local or experimental algorithms. Whether two sides with such suites can interoperate is up to them, not the spec ๐Ÿงช

A.7. The CipherSpec ๐Ÿฆ‹

A cipher suite identifies a CipherSpec. These structures are part of the SSL session state, and the CipherSpec includes the following โœจ

enum { stream, block } CipherType;

enum { true, false } IsExportable;

enum { null, rc4, rc2, des, 3des, des40, fortezza }
    BulkCipherAlgorithm;

enum { null, md5, sha } MACAlgorithm;

struct {
    BulkCipherAlgorithm bulk_cipher_algorithm;
    MACAlgorithm mac_algorithm;
    CipherType cipher_type;
    IsExportable is_exportable
    uint8 hash_size;
    uint8 key_material;
    uint8 IV_size;
} CipherSpec;

Appendix B. Glossary โœจ

Okay bestie, this is the glossary, aka the decoder ring for every term in this doc ๐Ÿ’– Let's go!

application protocol: An application protocol is a protocol that normally layers directly on top of the transport layer (e.g., TCP/IP [RFC0793]/[RFC0791]). Examples include HTTP [RFC1945], TELNET [RFC0959], FTP [RFC0854], and SMTP. ๐ŸŒธ

asymmetric cipher: See public key cryptography. ๐Ÿฆ‹

authentication: Authentication is the ability of one entity to determine the identity of another entity. ๐Ÿซถ

block cipher: A block cipher is an algorithm that operates on plaintext in groups of bits, called blocks. 64 bits is a typical block size. ๐Ÿงš

bulk cipher: A symmetric encryption algorithm used to encrypt large quantities of data. ๐Ÿ’œ

cipher block chaining (CBC) mode: CBC is a mode in which every plaintext block encrypted with the block cipher is first exclusive-ORed with the previous ciphertext block (or, in the case of the first block, with the initialization vector). It's giving chain reaction, no cap ๐Ÿ”—โœจ

certificate: As part of the X.509 protocol (a.k.a. ISO Authentication framework), certificates are assigned by a trusted certificate authority and provide verification of a party's identity and may also supply its public key. Very trustworthy vibes ๐ŸŽ€

client: The application entity that initiates a connection to a server. ๐Ÿ’…

client write key: The key used to encrypt data written by the client. ๐Ÿ”‘

client write MAC secret: The secret data used to authenticate data written by the client. ๐Ÿคซ

connection: A connection is a transport (in the OSI layering model definition) that provides a suitable type of service. For SSL, such connections are peer-to-peer relationships. The connections are transient. Every connection is associated with one session. Connections come and go, but each one belongs to a session, periodt ๐ŸŒˆ

Data Encryption Standard (DES): DES is a very widely used symmetric encryption algorithm. DES is a block cipher [DES] [3DES]. Iconic classic ๐Ÿ‘‘

Digital Signature Standard: (DSS) A standard for digital signing, including the Digital Signature Algorithm, approved by the National Institute of Standards and Technology, defined in NIST FIPS PUB 186, "Digital Signature Standard," published May, 1994 by the U.S. Dept. of Commerce. Official paperwork energy ๐Ÿ“œ

digital signatures: Digital signatures utilize public key cryptography and one-way hash functions to produce a signature of the data that can be authenticated, and is difficult to forge or repudiate. โœ๏ธ๐Ÿ’–

FORTEZZA: A PCMCIA card that provides both encryption and digital signing. A card that does two jobs, slay ๐Ÿ’ณ

handshake: An initial negotiation between client and server that establishes the parameters of their transactions. It's the opening small talk before the real convo ๐Ÿค

Initialization Vector (IV): When a block cipher is used in CBC mode, the initialization vector is exclusive-ORed with the first plaintext block prior to encryption. ๐Ÿ“

IDEA: A 64-bit block cipher designed by Xuejia Lai and James Massey [IDEA]. ๐Ÿง 

Message Authentication Code (MAC): A Message Authentication Code is a one-way hash computed from a message and some secret data. Its purpose is to detect if the message has been altered. Did somebody touch my message?! ๐Ÿ‘€

master secret: Secure secret data used for generating encryption keys, MAC secrets, and IVs. The VIP of the secrets ๐Ÿ‘‘๐Ÿ”

MD5: MD5 [RFC1321] is a secure hashing function that converts an arbitrarily long data stream into a digest of fixed size. ๐ŸŒ™

public key cryptography: A class of cryptographic techniques employing two-key ciphers. Messages encrypted with the public key can only be decrypted with the associated private key. Conversely, messages signed with the private key can be verified with the public key. Two keys, one vibe ๐Ÿ—๏ธโœจ

one-way hash function: A one-way transformation that converts an arbitrary amount of data into a fixed-length hash. It is computationally hard to reverse the transformation or to find collisions. MD5 and SHA are examples of one-way hash functions. Easy to make, nearly impossible to undo ๐Ÿง

RC2, RC4: Proprietary bulk ciphers from RSA Data Security, Inc. (There is no good reference to these as they are unpublished works; however, see [RSADSI]). RC2 is a block cipher and RC4 is a stream cipher. Mysterious and unpublished, lowkey iconic ๐Ÿ•ต๏ธโ€โ™€๏ธ

RSA: A very widely used public key algorithm that can be used for either encryption or digital signing. Main character of public key crypto ๐ŸŽฌ

salt: Non-secret random data used to make export encryption keys resist precomputation attacks. Not secret, but still doing important work ๐Ÿง‚

server: The server is the application entity that responds to requests for connections from clients. The server is passive, waiting for requests from clients. The chill one who waits for the group chat to ping ๐Ÿ›‹๏ธ

session: An SSL session is an association between a client and a server. Sessions are created by the handshake protocol. Sessions define a set of cryptographic security parameters, which can be shared among multiple connections. Sessions are used to avoid the expensive negotiation of new security parameters for each connection. Saves everyone from renegotiating the whole vibe every time ๐Ÿ’…๐ŸŒธ

session identifier: A session identifier is a value generated by a server that identifies a particular session. Basically the session's name tag ๐Ÿท๏ธ

server write key: The key used to encrypt data written by the server. ๐Ÿ”

server write MAC secret: The secret data used to authenticate data written by the server. ๐Ÿค

SHA: The Secure Hash Algorithm is defined in FIPS PUB 180-1. It produces a 20-byte output [SHA]. ๐Ÿฅฐ

stream cipher: An encryption algorithm that converts a key into a cryptographically strong keystream, which is then exclusive-ORed with the plaintext. Keeps flowing like a playlist ๐ŸŽง

symmetric cipher: See bulk cipher. Same energy, different name ๐Ÿฆ‹

Appendix C. CipherSuite Definitions โœจ

okay so this is the big cipher suite roster, bestie ๐Ÿ’… every row is a little combo of key exchange, cipher, and hash. The * marks the ones that are exportable, meaning they're the weaker, export-grade options ๐Ÿ™ˆ

CipherSuite                  Is         Key            Cipher       Hash
                             Exportable Exchange

SSL_NULL_WITH_NULL_NULL               * NULL           NULL         NULL
SSL_RSA_WITH_NULL_MD5                 * RSA            NULL         MD5
SSL_RSA_WITH_NULL_SHA                 * RSA            NULL         SHA
SSL_RSA_EXPORT_WITH_RC4_40_MD5        * RSA_EXPORT     RC4_40       MD5
SSL_RSA_WITH_RC4_128_MD5                RSA            RC4_128      MD5
SSL_RSA_WITH_RC4_128_SHA                RSA            RC4_128      SHA
SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5    * RSA_EXPORT     RC2_CBC_40   MD5
SSL_RSA_WITH_IDEA_CBC_SHA               RSA            IDEA_CBC     SHA
SSL_RSA_EXPORT_WITH_DES40_CBC_SHA     * RSA_EXPORT     DES40_CBC    SHA
SSL_RSA_WITH_DES_CBC_SHA                RSA            DES_CBC      SHA
SSL_RSA_WITH_3DES_EDE_CBC_SHA           RSA            3DES_EDE_CBC SHA
SSL_DH_DSS_EXPORT_WITH_DES40_CBC_SHA  * DH_DSS_EXPORT  DES40_CBC    SHA
SSL_DH_DSS_WITH_DES_CBC_SHA             DH_DSS         DES_CBC      SHA
SSL_DH_DSS_WITH_3DES_EDE_CBC_SHA        DH_DSS         3DES_EDE_CBC SHA
SSL_DH_RSA_EXPORT_WITH_DES40_CBC_SHA  * DH_RSA_EXPORT  DES40_CBC    SHA
SSL_DH_RSA_WITH_DES_CBC_SHA             DH_RSA         DES_CBC      SHA
SSL_DH_RSA_WITH_3DES_EDE_CBC_SHA        DH_RSA         3DES_EDE_CBC SHA
SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA * DHE_DSS_EXPORT DES40_CBC    SHA
SSL_DHE_DSS_WITH_DES_CBC_SHA            DHE_DSS        DES_CBC      SHA
SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA       DHE_DSS        3DES_EDE_CBC SHA
SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA * DHE_RSA_EXPORT DES40_CBC    SHA
SSL_DHE_RSA_WITH_DES_CBC_SHA            DHE_RSA        DES_CBC      SHA
SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA       DHE_RSA        3DES_EDE_CBC SHA
SSL_DH_anon_EXPORT_WITH_RC4_40_MD5    * DH_anon_EXPORT RC4_40       MD5
SSL_DH_anon_WITH_RC4_128_MD5            DH_anon        RC4_128      MD5
SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA   DH_anon        DES40_CBC    SHA
SSL_DH_anon_WITH_DES_CBC_SHA            DH_anon        DES_CBC      SHA
SSL_DH_anon_WITH_3DES_EDE_CBC_SHA       DH_anon        3DES_EDE_CBC SHA
SSL_FORTEZZA_KEA_WITH_NULL_SHA          FORTEZZA_KEA   NULL         SHA
SSL_FORTEZZA_KEA_WITH_FORTEZZA_CBC_SHA  FORTEZZA_KEA   FORTEZZA_CBC SHA
SSL_FORTEZZA_KEA_WITH_RC4_128_SHA       FORTEZZA_KEA   RC4_128      SHA

Now let's look at what each key exchange algorithm actually means ๐Ÿง  Here's the lowdown on the key exchange cheat sheet:

   +----------------+------------------------------+-------------------+
   |  Key Exchange  |          Description         |   Key Size Limit  |
   |    Algorithm   |                              |                   |
   +----------------+------------------------------+-------------------+
   |     DHE_DSS    |     Ephemeral DH with DSS    |        None       |
   |                |          signatures          |                   |
   | DHE_DSS_EXPORT |     Ephemeral DH with DSS    |   DH = 512 bits   |
   |                |          signatures          |                   |
   |     DHE_RSA    |     Ephemeral DH with RSA    |        None       |
   |                |          signatures          |                   |
   | DHE_RSA_EXPORT |     Ephemeral DH with RSA    |   DH = 512 bits,  |
   |                |          signatures          |     RSA = none    |
   |     DH_anon    |  Anonymous DH, no signatures |        None       |
   | DH_anon_EXPORT |  Anonymous DH, no signatures |   DH = 512 bits   |
   |     DH_DSS     |       DH with DSS-based      |        None       |
   |                |         certificates         |                   |
   |  DH_DSS_EXPORT |       DH with DSS-based      |   DH = 512 bits   |
   |                |         certificates         |                   |
   |     DH_RSA     |       DH with RSA-based      |        None       |
   |                |         certificates         |                   |
   |  DH_RSA_EXPORT |       DH with RSA-based      |   DH = 512 bits,  |
   |                |         certificates         |     RSA = none    |
   |  FORTEZZA_KEA  |     FORTEZZA KEA. Details    |        N/A        |
   |                |          unpublished         |                   |
   |      NULL      |        No key exchange       |        N/A        |
   |       RSA      |       RSA key exchange       |        None       |
   |   RSA_EXPORT   |       RSA key exchange       |   RSA = 512 bits  |
   +----------------+------------------------------+-------------------+

                                  Table 1

The key size limit is the biggest size of public key that's legally allowed for encryption in exportable cipher suites. Basically the ceiling, bestie ๐ŸŽ€

Next up is the cipher table, which is where all the good stuff about each cipher's sizes lives โœจ

   +--------------+--------+-----+-------+-------+-------+------+------+
   | Cipher       | Cipher | IsE |  Key  |  Exp. | Effec |  IV  | Bloc |
   |              |  Type  | xpo | Mater |  Key  |  tive | Size |   k  |
   |              |        | rta |  ial  | Mater |  Key  |      | Size |
   |              |        | ble |       |  ial  |  Bits |      |      |
   +--------------+--------+-----+-------+-------+-------+------+------+
   | NULL         | Stream |  *  |   0   |   0   |   0   |   0  |  N/A |
   | FORTEZZA_CBC |  Block |     |   NA  |   12  |   96  |  20  |   8  |
   |              |        |     |  (**) |  (**) |  (**) | (**) |      |
   | IDEA_CBC     |  Block |     |   16  |   16  |  128  |   8  |   8  |
   | RC2_CBC_40   |  Block |  *  |   5   |   16  |   40  |   8  |   8  |
   | RC4_40       | Stream |  *  |   5   |   16  |   40  |   0  |  N/A |
   | RC4_128      | Stream |     |   16  |   16  |  128  |   0  |  N/A |
   | DES40_CBC    |  Block |  *  |   5   |   8   |   40  |   8  |   8  |
   | DES_CBC      |  Block |     |   8   |   8   |   56  |   8  |   8  |
   | 3DES_EDE_CBC |  Block |     |   24  |   24  |  168  |   8  |   8  |
   +--------------+--------+-----+-------+-------+-------+------+------+

                     * Indicates IsExportable is true.
        ** FORTEZZA uses its own key and IV generation algorithms.

                                  Table 2

Here's what those columns are actually saying, no cap ๐Ÿ’–

Key Material is how many bytes from the key_block get used for making the write keys.

Expanded Key Material is how many bytes actually get fed into the encryption algorithm.

Effective Key Bits is how much entropy is hiding in the key material going into the encryption routines. Very important, very iconic ๐Ÿ‘‘

And the last table is the hash situation ๐Ÿฆ‹

               +---------------+-----------+--------------+
               | Hash Function | Hash Size | Padding Size |
               +---------------+-----------+--------------+
               |      NULL     |     0     |       0      |
               |      MD5      |     16    |      48      |
               |      SHA      |     20    |      40      |
               +---------------+-----------+--------------+

                                  Table 3

Appendix D. Implementation Notes ๐ŸŒธ

okay implementers, this part is the protective big-sis talk ๐Ÿซถ SSL can't stop every common security mistake on its own, so this section gives you some tips to keep your stuff safe. Please read it, it matters ๐Ÿ˜ญ

D.1. Temporary RSA Keys

So here's the export drama ๐Ÿ’€ US export rules cap RSA keys used for encryption at 512 bits, but there's no limit at all on the RSA keys used for signing. Certificates usually need to be bigger than 512 bits, because 512-bit RSA keys aren't strong enough for high-value transactions or for anything that needs long-term security. Some certificates are also signing-only, which means they can't be used for key exchange at all.

When the certificate's public key can't be used for encryption, the server signs a temporary RSA key, and that's the one that gets exchanged. In exportable applications, the temporary RSA key should be the maximum allowed length, which is 512 bits. Since 512-bit RSA keys are pretty insecure, they should get swapped out often. For typical electronic commerce apps, the suggestion is to change keys daily or every 500 transactions, and more often if you can ๐Ÿ”ฅ It's fine to reuse the same temporary key for several transactions, but it must be signed every single time it's used.

RSA key generation takes a lot of time and effort, so in lots of cases a low-priority process can be handed the job. Whenever a new key finishes generating, the old temporary key can be replaced with the new one โœจ

D.2. Random Number Generation and Seeding

SSL needs a cryptographically secure pseudorandom number generator (PRNG), and this part is serious business ๐Ÿงš You have to be careful when you design and seed PRNGs. PRNGs built on secure hash operations, most notably MD5 and/or SHA, are acceptable, but they can't give you more security than the size of the random number generator state. For example, MD5-based PRNGs usually have 128 bits of state.

To estimate how much seed material you're making, add up the number of bits of unpredictable information in each seed byte. For example, keystroke timing values from a PC-compatible's 18.2 Hz timer only give you 1 or 2 secure bits each, even though the counter value is 16 bits or more. So to seed a 128-bit PRNG, you'd need about 100 of those timer values ๐Ÿ’…

Note: The seeding functions in RSAREF and versions of BSAFE prior to 3.0 are order independent. For example, if 1000 seed bits are supplied one at a time, in 1000 separate calls to the seed function, the PRNG ends up in a state that depends only on the number of 0 or 1 seed bits in the seed data (so there are 1001 possible final states). Applications using BSAFE or RSAREF must take extra care to ensure proper seeding. ๐Ÿ™ˆ

D.3. Certificates and Authentication

Implementations are responsible for checking the integrity of certificates, and they should generally support certificate revocation messages ๐ŸŽ€ Certificates should always get verified to make sure a trusted certificate authority (CA) actually signed them. Picking and adding trusted CAs should be done very carefully. Users should be able to look at info about the certificate and the root CA too, because transparency is everything ๐ŸŒˆ

D.4. CipherSuites

SSL supports a whole range of key sizes and security levels, including some that give you no security or just a tiny bit. A proper implementation will probably not support many cipher suites ๐Ÿ“ For example, 40-bit encryption gets broken easily, so implementations that need strong security shouldn't allow 40-bit keys. Anonymous Diffie-Hellman is also strongly discouraged, because it can't prevent man-in-the-middle attacks ๐Ÿ˜ญ Applications should also enforce minimum and maximum key sizes. For instance, certificate chains with 512-bit RSA keys or signatures aren't appropriate for high-security applications ๐Ÿ”ฅ

D.5. FORTEZZA

This section covers implementation details for the cipher suites that use the FORTEZZA hardware encryption system ๐Ÿ’œ

D.5.1. Notes on Use of FORTEZZA Hardware โœจ

okay so a full explanation of everything about FORTEZZA hardware is outside the scope of this doc ๐Ÿ™ˆ but there are a few special SSL requirements that deserve a shoutout ๐Ÿ“ฃ

because SSL is full duplex ๐Ÿ”, two crypto states have to be kept going, one for reading and one for writing. there are also a bunch of situations that can make the crypto state on the FORTEZZA card disappear ๐Ÿ˜ญ so it's recommended that you save the current crypto state after processing a record, and load it before processing the next one ๐Ÿ’พ

after the client generates the TEK ๐Ÿ”‘, it also generates two message encryption keys (MEKs), one for reading and one for writing ๐Ÿ’œ. after making each of those keys, the client must generate a matching IV and then save the crypto state. the client also uses the TEK to generate an IV and encrypt the premaster secret ๐Ÿซถ. all three IVs get sent to the server, along with the wrapped keys and the encrypted premaster secret in the client key exchange message ๐Ÿ’Œ. at this point the TEK isn't needed anymore, so it may be discarded ๐Ÿ—‘๏ธ

on the server side ๐Ÿ–ฅ๏ธ, the server uses the master IV and the TEK to decrypt the premaster secret. it also loads the wrapped MEKs into the card. the server loads both IVs to check that they match the keys. however, since the card can't encrypt after loading an IV, the server must generate a new IV for the server write key. this IV gets discarded ๐Ÿ’…

when encrypting the first encrypted record (and only that record) โ˜๏ธ, the server adds 8 bytes of random data to the beginning of the fragment. the client throws those 8 bytes away after decryption. the whole point is to get the state on the client and server back in sync, since they ended up with different IVs ๐Ÿ”„๐Ÿงš

D.5.2. FORTEZZA Cipher Suites ๐Ÿ‘‘

  1. FORTEZZA_NULL_WITH_NULL_SHA: this one uses the full FORTEZZA key exchange, including sending server and client write keys and IVs ๐Ÿ”

D.5.3. FORTEZZA Session Resumption ๐ŸŽ€

there are two possibilities for restarting a FORTEZZA session: 1) never restart a FORTEZZA session, or 2) restart a session with the previously negotiated keys and IVs ๐Ÿฆ‹

Never restarting a FORTEZZA session:

clients who never restart FORTEZZA sessions should never send session IDs that were previously used in a FORTEZZA session as part of the ClientHello ๐Ÿ™…โ€โ™€๏ธ. servers who never restart FORTEZZA sessions should never send a previous session id on the ServerHello if the negotiated session is FORTEZZA ๐Ÿšซ

Restart a session:

you cannot restart FORTEZZA on a session that has never done a complete FORTEZZA key exchange. so you can't restart FORTEZZA if the session was an RSA/RC4 session that got renegotiated for FORTEZZA ๐Ÿ˜ค. if you do want to restart a FORTEZZA session, you must save the MEKs and IVs from the initial key exchange for that session and reuse them for any new connections on that session ๐Ÿ”. this is not recommended, but it is possible ๐Ÿ™ˆ


Appendix E. Version 2.0 Backward Compatibility ๐Ÿ•ฐ๏ธ

okay so version 3.0 clients that support version 2.0 servers must send version 2.0 client hello messages [SSL-2] ๐Ÿ“จ. version 3.0 servers should accept either client hello format ๐Ÿค. the only differences from the version 2.0 spec are the ability to specify a version with a value of three โœจ and support for more ciphering types in the CipherSpec ๐Ÿ’–

Warning: The ability to send version 2.0 client hello messages will be phased out with all due haste. Implementers should make every effort to move forward as quickly as possible. Version 3.0 provides better mechanisms for transitioning to newer versions. ๐Ÿšจ

the following cipher specifications are carryovers from SSL version 2.0 ๐Ÿง“. they're assumed to use RSA for key exchange and authentication ๐Ÿ”‘:

     V2CipherSpec SSL_RC4_128_WITH_MD5          = { 0x01,0x00,0x80 };
     V2CipherSpec SSL_RC4_128_EXPORT40_WITH_MD5 = { 0x02,0x00,0x80 };
     V2CipherSpec SSL_RC2_CBC_128_CBC_WITH_MD5  = { 0x03,0x00,0x80 };
     V2CipherSpec SSL_RC2_CBC_128_CBC_EXPORT40_WITH_MD5
                                                = { 0x04,0x00,0x80 };
     V2CipherSpec SSL_IDEA_128_CBC_WITH_MD5     = { 0x05,0x00,0x80 };
     V2CipherSpec SSL_DES_64_CBC_WITH_MD5       = { 0x06,0x00,0x40 };
     V2CipherSpec SSL_DES_192_EDE3_CBC_WITH_MD5 = { 0x07,0x00,0xC0 };

cipher specifications introduced in version 3.0 can be put into version 2.0 client hello messages using the syntax below ๐Ÿงฉ. any V2CipherSpec element whose first byte is zero gets ignored by version 2.0 servers ๐Ÿ™ˆ. clients sending any of the V2CipherSpecs above should also include the version 3.0 equivalent (see Appendix A.6) ๐Ÿ’…:

     V2CipherSpec (see Version 3.0 name) = { 0x00, CipherSuite };

E.1. Version 2 Client Hello ๐Ÿ“

the version 2.0 client hello message is shown below using this document's presentation model ๐ŸŽ€. the true definition is still assumed to be the SSL version 2.0 spec ๐Ÿ“œ:

     uint8 V2CipherSpec[3];

     struct {
         unit8 msg_type;
         Version version;
         uint16 cipher_spec_length;
         uint16 session_id_length;
         uint16 challenge_length;
         V2CipherSpec cipher_specs[V2ClientHello.cipher_spec_length];
         opaque session_id[V2ClientHello.session_id_length];
         Random challenge;
     } V2ClientHello;

here's the breakdown ๐Ÿ”:

  • session msg_type: this field, together with the version field, identifies a version 2 client hello message. the value should equal one (1) 1๏ธโƒฃ
  • version: the highest version of the protocol the client supports (equals ProtocolVersion.version; see Appendix A.1) ๐Ÿ†™
  • cipher_spec_length: the total length of the field cipher_specs. it cannot be zero and must be a multiple of the V2CipherSpec length (3) ๐Ÿ”ข
  • session_id_length: this field must have a value of either zero or 16. if it's zero, the client is creating a new session ๐ŸŒฑ. if it's 16, the session_id field will hold the 16 bytes of session identification ๐Ÿชช
  • challenge_length: the length in bytes of the client's challenge to the server to authenticate itself. this value must be 32 ๐Ÿ’ฏ
  • cipher_specs: a list of all the CipherSpecs the client is willing and able to use. there must be at least one CipherSpec acceptable to the server ๐Ÿค
  • session_id: if this field's length isn't zero, it holds the identification for a session the client wants to resume ๐Ÿ”
  • challenge: the client's challenge for the server to identify itself is a (nearly) arbitrary length random value. the version 3.0 server will right justify the challenge data to become the ClientHello.random data (padded with leading zeroes, if necessary), as specified in this version 3.0 protocol. if the challenge is longer than 32 bytes, only the last 32 bytes get used. it's legit (but not necessary) for a V3 server to reject a V2 ClientHello that has fewer than 16 bytes of challenge data ๐Ÿ™…โ€โ™€๏ธ

Note: requests to resume an SSL 3.0 session should use an SSL 3.0 client hello ๐Ÿ’ก

E.2. Avoiding Man-in-the-Middle Version Rollback ๐Ÿ•ต๏ธโ€โ™€๏ธ

when SSL version 3.0 clients fall back to version 2.0 compatibility mode, they use special PKCS #1 block formatting ๐Ÿงฑ. this is done so that version 3.0 servers will reject version 2.0 sessions with version 3.0-capable clients ๐Ÿšซ

when version 3.0 clients are in version 2.0 compatibility mode, they set the right-hand (least-significant) 8 random bytes of the PKCS padding (not including the terminal null of the padding) for the RSA encryption of the ENCRYPTED-KEY-DATA field of the CLIENT-MASTER-KEY to 0x03 (the other padding bytes are random) ๐ŸŽฒ. after decrypting the ENCRYPTED-KEY-DATA field, servers that support SSL 3.0 should issue an error if these eight padding bytes are 0x03 โš ๏ธ. version 2.0 servers receiving blocks padded this way will carry on normally ๐Ÿ‘Œ


Appendix F. Security Analysis ๐Ÿ›ก๏ธ

the SSL protocol is designed to set up a secure connection between a client and a server that are talking over an insecure channel ๐ŸŒ. this document makes several traditional assumptions, including that attackers have substantial computational resources and can't get secret information from sources outside the protocol ๐Ÿง . attackers are assumed to be able to capture, modify, delete, replay, and otherwise tamper with messages sent over the channel ๐Ÿ˜ˆ. this appendix outlines how SSL has been designed to resist a bunch of attacks ๐Ÿ’ช

F.1. Handshake Protocol ๐Ÿค

the handshake protocol is responsible for selecting a CipherSpec and generating a MasterSecret. together those make up the primary cryptographic parameters for a secure session ๐Ÿ”. the handshake protocol can also optionally authenticate parties who have certificates signed by a trusted certificate authority ๐Ÿชช

F.1.1. Authentication and Key Exchange ๐Ÿ”‘

SSL supports three authentication modes: authentication of both parties, server authentication with an unauthenticated client, and total anonymity ๐ŸŽญ. whenever the server is authenticated, the channel should be secure against man-in-the-middle attacks, but completely anonymous sessions are inherently vulnerable to those ๐Ÿ˜ฌ

anonymous servers can't authenticate clients, since the client signature in the certificate verify message may need a server certificate to bind the signature to a particular server ๐Ÿ™ƒ. if the server is authenticated, its certificate message must provide a valid certificate chain leading to an acceptable certificate authority ๐Ÿ“œ. similarly, authenticated clients must supply an acceptable certificate to the server ๐Ÿชช. each party is responsible for checking that the other's certificate is valid and hasn't expired or been revoked ๐Ÿ”

the general goal of the key exchange process is to create a pre_master_secret that the communicating parties know and attackers don't ๐Ÿคซ. the pre_master_secret will be used to generate the master_secret (see Section 6.1) ๐Ÿ”„. the master_secret is required to generate the finished messages, encryption keys, and MAC secrets (see Sections 5.6.9 and 6.2.2) ๐Ÿ—๏ธ. by sending a correct finished message, parties prove that they know the correct pre_master_secret โœ…

F.1.1.1. Anonymous Key Exchange ๐ŸŽญ

completely anonymous sessions can be set up using RSA, Diffie-Hellman, or FORTEZZA for key exchange ๐ŸŒˆ. with anonymous RSA, the client encrypts a pre_master_secret with the server's uncertified public key taken from the server key exchange message ๐Ÿ”. the result is sent in a client key exchange message. since eavesdroppers don't know the server's private key, it will be infeasible for them to decode the pre_master_secret ๐Ÿ™…โ€โ™€๏ธ

with Diffie-Hellman or FORTEZZA, the server's public parameters are in the server key exchange message, and the client's are sent in the client key exchange message ๐Ÿ“ฌ. eavesdroppers who don't know the private values should not be able to find the Diffie-Hellman result (i.e., the pre_master_secret) or the FORTEZZA token encryption key (TEK) ๐Ÿ‘€

Warning: Completely anonymous connections only protect against passive eavesdropping. Unless an independent tamper-proof channel is used to verify that the finished messages weren't replaced by an attacker, server authentication is required in environments where active man-in-the-middle attacks are a concern. ๐Ÿšจ๐Ÿ’€

F.1.1.2. RSA Key Exchange and Authentication

okay so with RSA, key exchange and server authentication happen in one go ๐Ÿ’… The public key can either live inside the server's certificate, or it can be a temporary RSA key sent in a server key exchange message. ๐ŸŽ€ When temporary RSA keys are used, the server's RSA or DSS certificate signs them. The signature includes the current ClientHello.random, so old signatures and temporary keys can't be replayed ๐Ÿ™ˆ Servers may use a single temporary RSA key for multiple negotiation sessions.

Note: The temporary RSA key option is useful if servers need large certificates but must comply with government-imposed size limits on keys used for key exchange.

After the client verifies the server's certificate, it encrypts a pre_master_secret with the server's public key ๐Ÿ” If the server can decode the pre_master_secret and produce a correct finished message, it proves it knows the private key that matches the server certificate. That's the vibe check passed โœจ

When RSA is used for key exchange, clients get authenticated through the certificate verify message (see Section 5.6.8) ๐Ÿ’œ The client signs a value derived from the master_secret and all the handshake messages before it. Those messages include the server certificate, which ties the signature to the server, and ServerHello.random, which ties it to this particular handshake. Iconic binding behaviour ๐Ÿซถ

F.1.1.3. Diffie-Hellman Key Exchange with Authentication

When Diffie-Hellman key exchange is in play, the server can either supply a certificate with fixed Diffie-Hellman parameters, or use the server key exchange message to send a set of temporary Diffie-Hellman parameters that are signed with a DSS or RSA certificate ๐Ÿฆ‹ Temporary parameters get hashed together with the hello.random values before signing, so attackers can't replay old parameters. Either way, the client can verify the certificate or signature and make sure those parameters really belong to the server ๐ŸŒธ

If the client has a certificate with fixed Diffie-Hellman parameters, that certificate holds everything needed to finish the key exchange โœจ Heads up, though: in this case the client and server will generate the same Diffie-Hellman result (i.e., pre_master_secret) every single time they talk. ๐Ÿ˜ญ To stop the pre_master_secret from hanging around in memory longer than it needs to, it should be turned into the master_secret as soon as possible. Also, the client's Diffie-Hellman parameters must be compatible with the ones the server supplied, or the key exchange just won't work ๐Ÿ™…โ€โ™€๏ธ

If the client has a standard DSS or RSA certificate, or it's unauthenticated, it sends a set of temporary parameters to the server in the client key exchange message. It can then optionally use a certificate verify message to authenticate itself ๐Ÿ’…

F.1.1.4. FORTEZZA

Okay, FORTEZZA's design is classified, so we can't spill the tea on the internals ๐Ÿคซ But at the protocol level, it's kind of similar to Diffie-Hellman with fixed public values stored in certificates ๐ŸŽ€ The result of the key exchange is the token encryption key (TEK). The TEK is used to wrap the data encryption keys, the client write key, the server write key, and the master secret encryption key. The data encryption keys are not derived from the pre_master_secret, because unwrapped keys aren't accessible outside the token ๐Ÿงš The encrypted pre_master_secret gets sent to the server in a client key exchange message.

F.1.2. Version Rollback Attacks

SSL version 3.0 has some seriously big improvements over SSL version 2.0, so attackers may try to trick version 3.0-capable clients and servers into falling back to version 2.0 ๐Ÿ‘€ This attack is happening if and only if two version 3.0-capable parties use an SSL 2.0 handshake. Main character villain energy, but it's very specific ๐Ÿ™„

Although the solution using non-random PKCS #1 block type 2 message padding is kind of inelegant, it gives version 3.0 servers a reasonably secure way to detect the attack ๐ŸŒˆ This solution is not secure against attackers who can brute force the key and substitute a new ENCRYPTED-KEY-DATA message containing the same key (but with normal padding) before the application-specified wait threshold has expired. Parties worried about attacks at this scale should not be using 40-bit encryption keys anyway ๐Ÿ’€ Altering the padding of the least significant 8 bytes of the PKCS padding does not impact security, since it's essentially the same as increasing the input block size by 8 bytes. Math that slaps ๐Ÿ”ฅ

F.1.3. Detecting Attacks against the Handshake Protocol

An attacker might try to influence the handshake exchange so the parties pick different encryption algorithms than they normally would ๐Ÿ˜ฑ This one is a big deal, because many implementations support 40-bit exportable encryption, and some may even support null encryption or MAC algorithms. ๐Ÿ™ˆ

For this attack, the attacker has to actively change one or more handshake messages. If that happens, the client and server compute different values for the handshake message hashes. As a result, the parties won't accept each other's finished messages ๐Ÿšซ Without the master_secret, the attacker can't repair the finished messages, so the attack gets caught. Caught in 4K ๐Ÿ“ธ

F.1.4. Resuming Sessions

When a connection gets established by resuming a session, the new ClientHello.random and ServerHello.random values are hashed with the session's master_secret ๐Ÿฆ‹ As long as the master_secret hasn't been compromised, and the secure hash operations used to produce the encryption keys and MAC secrets are secure, the connection should be secure and effectively independent from previous connections ๐Ÿ’– Attackers can't use known encryption keys or MAC secrets to compromise the master_secret without breaking the secure hash operations (which use both SHA and MD5). That's a whole lot of protection, bestie ๐Ÿซถ

Sessions can't be resumed unless both the client and server agree ๐Ÿค If either party suspects the session may have been compromised, or that certificates may have expired or been revoked, it should force a full handshake. An upper limit of 24 hours is suggested for session ID lifetimes, since an attacker who gets a master_secret may be able to impersonate the compromised party until the corresponding session ID is retired โฐ Applications that might run in relatively insecure environments should not write session IDs to stable storage. Keep those IDs off the hard drive, periodt ๐Ÿ’…

F.1.5. MD5 and SHA

SSL uses hash functions very conservatively, which is so responsible of it ๐Ÿฅน Wherever possible, MD5 and SHA are used in tandem, so non-catastrophic flaws in one algorithm won't break the overall protocol. Double-checking that never hurt anybody ๐Ÿงš

F.2. Protecting Application Data

Here's the glow-up: the master_secret gets hashed with the ClientHello.random and ServerHello.random to produce unique data encryption keys and MAC secrets for each connection โœจ FORTEZZA encryption keys are generated by the token, and they are not derived from the master_secret ๐Ÿ”‘

Outgoing data is protected with a MAC before it's transmitted ๐Ÿ›ก๏ธ To prevent message replay or modification attacks, the MAC is computed from the MAC secret, the sequence number, the message length, the message contents, and two fixed-character strings. The message type field is necessary to make sure messages meant for one SSL record layer client don't get redirected to another ๐ŸŽฏ The sequence number makes sure that attempts to delete or reorder messages will be detected. Since sequence numbers are 64 bits long, they should never overflow ๐Ÿ™Œ Messages from one party can't be inserted into the other's output, since they use independent MAC secrets. Similarly, the server-write and client-write keys are independent, so stream cipher keys are only used once. Iconic separation of duties ๐Ÿ‘‘

If an attacker does break an encryption key, every message encrypted with it can be read ๐Ÿ˜ฌ Similarly, compromising a MAC key can make message modification attacks possible. Because MACs are also encrypted, message-alteration attacks generally require breaking the encryption algorithm as well as the MAC ๐Ÿ”

Note: MAC secrets may be larger than encryption keys, so messages can remain tamper resistant even if encryption keys are broken. ๐Ÿฆ‹

F.3. Final Notes

Real talk: for SSL to be able to provide a secure connection, the client and server systems, keys, and applications must all be secure ๐Ÿ’… On top of that, the implementation must be free of security errors. No loopholes allowed ๐Ÿ™…โ€โ™€๏ธ

The system is only as strong as the weakest key exchange and authentication algorithm it supports, and only trustworthy cryptographic functions should be used ๐Ÿ”ฅ Short public keys, 40-bit bulk encryption keys, and anonymous servers should be used with great caution. Implementations and users must be careful when deciding which certificates and certificate authorities are acceptable, because a dishonest certificate authority can do tremendous damage ๐Ÿ’€ This is the part where we all need to be very, very serious, okay? ๐Ÿ˜ญ

Appendix G. Acknowledgements โœจ

G.1. Other Contributors

Huge thanks to these amazing humans who helped make this happen ๐Ÿซถ

Martin Abadi                  Robert Relyea
Digital Equipment Corporation Netscape Communications
ma@pa.dec.com                 relyea@netscape.com

Taher Elgamal                 Jim Roskind
Netscape Communications       Netscape Communications
elgamal@netscape.com          jar@netscape.com

Anil Gangolli                 Micheal J. Sabin, Ph.D.
Netscape Communications       Consulting Engineer
gangolli@netscape.com         msabin@netcom.com

Kipp E.B. Hickman             Tom Weinstein
Netscape Communications       Netscape Communications
kipp@netscape.com             tomw@netscape.com

G.2. Early Reviewers

Early reviewers who gave feedback on the drafts ๐ŸŒธ

Robert Baldwin                Clyde Monma
RSA Data Security, Inc.       Bellcore
baldwin@rsa.com               clyde@bellcore.com

George Cox                    Eric Murray
Intel Corporation             ericm@lne.com
cox@ibeam.jf.intel.com

Cheri Dowell                  Avi Rubin
Sun Microsystems              Bellcore
cheri@eng.sun.com             rubin@bellcore.com

Stuart Haber                  Don Stephenson
Bellcore                      Sun Microsystems
stuart@bellcore.com           don.stephenson@eng.sun.com

Burt Kaliski                  Joe Tardo
RSA Data Security, Inc.       General Magic
burt@rsa.com                  tardo@genmagic.com

Authors' Addresses ๐Ÿ“ฎ

Alan O. Freier
Netscape Communications


Philip Karlton
Netscape Communications


Paul C. Kocher
Independent Consultant

That's the whole thing, bestie! ๐ŸŒˆ๐ŸŽ€ RFC 6101 is officially wrapped up. You got through all of it ๐Ÿ’–

๐Ÿ“ฆ where this page comes from