14. Transport Layer Security Protocol

The most widely used security protocol.

History:

Overview

Three higher-level protocols:

TLS record protocol provides basic services to the higher-level protocols. Stack:

|----------------------------------------|
| TLS       | TLS change |  TLS  | HTTP/ |
| Handshake |   cipher   | alert | Other |
|----------------------------------------|
|           TLS record protocol          |
|----------------------------------------|
|                  TCP                   |
|----------------------------------------|
|                  IP                    |
|----------------------------------------|

TLS Record Protocol

TLS offers:

These services may be provided by a symmetric encryption algorithm (confidentiality) and MAC (authentication/integrity). TLS 1.2 and above offer authenticated encryption modes (CCM, GCM), combining these two services into one.

The handshake protocol establishes the symmetric session keys used by the record protocol.

The record protocol also deals with dividing messages into blocks and re-assembling received blocks and possibly with compressing/decompressing block contents.

Format

                HEADER
|--------------------------------------|
| Content |  Major  |  Minor  | Length |
|  type   | version | version |        |
|--------------------------------------|

          ENCRYPTED CONTENTS
|--------------------------------------|
|              Plaintext               |
|        (possibly compressed)         |
|      (not available in TLS 1.3)      |
|--------------------------------------|
|                 MAC                  |
|  (unless authentication encryption)  |
|--------------------------------------|

Content type can be change-cipher-spec, alert, handshake or application-data.

TLS 1.3 does not allow the cipher suite to be changed to prevent downgrade attacks - a new session must be created.

Major version is 3 for TLS and minor version 1 to 4 for TLS 1.0 to 1.3.

Length of data is in octets.

Operation

MAC algorithm:

Encryption algorithm:

Authenticated encryption algorithm:

TLS Handshake Protocol

For:

Many variations supported - many were dropped to in TLS 1.3.

Phases

Cipher Suites

Specify the public key algorithms used for key establishment and symmetric algorithms used for authenticated encryption/key computation.

There were over 300 standardized cipher suites, many of which were discarded in TLS 1.3.

TLS 1.3 requires cipher suites to be Authenticated Encryption with Associated Data (AEAD). AEAD means that there is some associated data that must be sent in plain text (not confidential) but should be authenticated - for example, sequence numbers and other header information.

e.g. TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384:

e.g. TLS_RSA_WITH_3DES_EDE_CBC_SHA:

Handshake algorithms:

DH-RSA: permanent DH parameters part of the server certificate (signed with RSA), so there is no forwards secrecy.

Record algorithms:

Forwards Secrecy:

Handshake

Client hello (phase 1):

Server hello (phase 1):

Server key exchange (phase 2):

Client key exchange (phase 3):

Change cipher suite (phase 4):

Ephemeral Diffie-Hellman Handshake Variant

Server key exchange; server sends:

The response is signed by the server using their private key. The client must check this.

Client key exchange; client sends their ephemeral Diffie-Hellman value. Signed if the client has their own certificate.

Pre-master secret (pms\text{pms}) is the shared Diffie-Hellman secret that both parties have computed from the key exchange.

Steps:

  1. Client hello: TLS version, supported cipher suites, client nonce NCN_C
  2. Server hello: server certificate, chosen cipher suite, server nonce NSN_S
  3. Server signature: NCN_C, NSN_S and server’s DH parameter signed using server private key
  4. Client checks server signature, sends client’s DH parameter
  5. Pre-master secret calculated using DH parameters
  6. Session keys computed with PRF
  7. Client finished message: encrypted with session key
  8. Server finished message: encrypted with session key

RSA Handshake Variant

  1. Client hello: TLS version, supported cipher suites, client nonce NCN_C
  2. Server hello: server certificate, chosen cipher suite, server nonce NSN_S
  3. Client checks server certificate
  4. Pre-master secret key transport: client randomly chooses pre-master secret pms\text{pms}, encrypted with server’s public key
  5. Session keys computed with PRF
  6. Client finished message: encrypted with session key
  7. Server finished message: encrypted with session key

Other Handshake Variants

Diffie-Hellman: static/fixed Diffie-Hellman with certified keys. If the client does not have a certificate, they use an ephemeral Diffie-Hellman key.

Anonymous Diffie-Hellman: ephemeral Diffie-Hellman, but keys are not signed at all - only protects against passive eavesdropping.

Session Key Generation

Master secret ms\text{ms} generated using the pre-master secret and a pseudorandom function PRF\mathrm{PRF}:

ms=PRF(pms,“master secret”,NCNS) \text{ms} = \mathrm{PRF}(\text{pms}, \text{\textquotedblleft master secret\textquotedblright}, N_C \| N_S)

The pms\text{pms} to ms\text{ms} conversion is required to ensure the ms\text{ms} is in the right format as pms\text{pms} may vary depending on the key transfer algorithm.

To generate the key material (the amount depends on cipher suite):

k=PRF(ms,“key expansion”,NCNS) k = \mathrm{PRF}(\text{ms}, \text{\textquotedblleft key expansion\textquotedblright}, N_C \| N_S)

Independent session keys are partitioned from kk in each direction; a write key and a read key are used on each side.

Depending on cipher suite, key material may include encryption key, MAC key and IV.

The PRF\mathrm{PRF} is built from a HMAC specified by the TLS standard - SHA-2 in TLS 1.2 and a combination of MD5 and SHA-1 in TLS 1.0/1.1.

e.g. for TLS 1.2:

A(i)={nonce,i=0HMAC(key,A(i1)),otherwise A(i) = \begin{cases} \text{nonce}, & i = 0 \\ \mathrm{HMAC}(\text{key}, A(i - 1)), & \text{otherwise} \end{cases}
PRF(key,label,nonce)=HMAC(key,A(1)labelnonce)HMAC(key,A(2)labelnonce) \begin{aligned} \mathrm{PRF}(\text{key}, \text{label}, \text{nonce}) = & \mathrm{HMAC}(\text{key}, A(1) \| \text{label} \| \text{nonce}) \| \\ & \mathrm{HMAC}(\text{key}, A(2) \| \text{label} \| \text{nonce}) \| \\ & \vdots \end{aligned}

TLS Alert Protocol

Alert messages of varying degrees of severity:

If alert messages are handled improperly, users may be vulnerable to truncation attacks.

Attacks

Backwards Compatibility

Insecure versions of TLS are depreciated slowly:

TLS 1.2 is secure as long as a good cipher suite is used:

TLS 1.2 supported by 99.5% of websites, TLS 1.3 (released 2018) ~50% as of August 2021. See SSL Pulse for up-to-date statistics.

BEAST (Browser Exploit Against SSL/TLS)

Exploits non-standardized IV use in CBC mode encryption: IVs are chained from previous ciphertexts; attack could recover plaintext byte-by-byte.

Theoretical attack found in 2002 but required the full block to be guessed. In 2011 researchers found a method where they could have all but one byte in the block to be known, requiring only that byte to be guessed.

TLS 1.1 requires random IVs, and most browsers added mitigation strategies by putting only one byte of data in the first block (and padding the rest with random data) and the remaining bytes into the second block, forcing a randomized IV.

CRIME (Compression Ratio Info-leak Made Easy) and BREACH (Browser Reconnaissance and Exfiltration via Adaptive Compression of Hypertext)

Side channel attacks based on compression: different inputs result in different amounts of compression.

CRIME is based on compression in the TLS level, BREACH on compression at the HTTP level.

CRIME: attacker has ability to control part of request. If request gets smaller, the attacker-controlled content is probably matches part of source content (e.g. cookies).

TLS 1.3 does not allow compression. Disabling compression at a HTTP level results in a large performance hit.

POODLE (Padding Oracle On Downgraded Legacy Encryption)

A padding oracle enables an attacker to know if a message in a ciphertext was correctly padded.

Encryption in CBC mode can provide a padding oracle due to its error propagation properties: servers (after decrypt all blocks and validating the padding) may sometimes return an ‘invalid padding’ error.

Main mitigation is to have a uniform error response so that attacker cannot distinguish between padding and MAC errors.

Theoretical in 2002, practical in 2014 with POODLE, which forced a downgrade into SSL 3.0.

Heartbleed

Implementation error in OpenSSL found in 2014: improper input validation due to missing bounds check in heartbeat messages allowed memory leakage.

Heartbeats allow clients/servers to send a few bytes of data that the partner should echo back: OpenSSL did not validate that the length field matched actual length of the heartbeat, so the allocated memory could include freed data that contained sensitive data (e.g usernames/passwords, private keys).

Other Attacks

TLS 1.3

Drafted 2014, adopted as RFC 8446 in August 2018.

TLS 1.3 did a large spring cleaning, removing:

TLS 1.3 also added:

Handshake:

  1. Client hello:
    • TLS version, supported cipher suites
    • Key share:
      • Guesses selected cipher suite (s), sends key share (s)
      • If guess was wrong, server sends retry hello request
  2. Server hello:
    • Selected TLS version, cipher suite
    • Key share
      • Everything after this in the handshake can be encrypted
    • Server certificate (and optionally the certificates up the chain)
    • Hash of handshake messages signed with server certificate
  3. Client handshake finished
    • Hash of handshake messages signed with session key

0-RTT Overview

Even faster handshakes using pre-shared key (resumption master secret) obtained for the purpose of 0-RTT after a previous (and recent) connection.

TLS 1.3 1-RTT (with ephemeral Diffie-Hellman key exchange):

TLS 1.2 1-RTT session resumption:

TLS 1.3 0-RTT:

Limitations: