Christopher Baines

Government Digital Service

HTTP and Security

  • How does HTTPS fit together
    • Where does it fit in
    • The handshake
  • Security
    • Integrity
    • Secrecy
    • Authenticity
  • The future, TLS 1.3

Protocols involved

HTTP (HyperText Transport Protocol)
TLS (Transport Layer Security)
TCP (Transmission Control Protocol)
IP (the Internet Protocol)
IEEE 802.3 (Ethernet) / IEEE 802.11 (Wi-Fi) / ...

Transport Layer Security (TLS)

  • Evolution of the SSL protocol
  • Several versions exist:
    • SSL 1.0 (never released)
    • SSL 2.0 (released in 1995)
    • SSL 3.0 (released in 1996)
    • TLS 1.0 (standardised in 1999)
    • TLS 1.1 (standardised in 2006)
    • TLS 1.2 (standardised in 2008)
    • TLS 1.3 (draft)

The Handshake

TLS 1.2 Full Handshake

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.
RFC 5246

Cipher Suites

This is the initial state of the TLS connection:
TLS_NULL_WITH_NULL_NULL
This is an example of a modern cipher suite:
TLS_ECDHE_WITH_AES_128_GCM_SHA256
ECDHE
Eliptic Curve Diffie Hellman Ephemeral
AES 128 GCM
Advanced Encryption Standard with 128 bit blocks using Galois/Counter Mode
SHA256
Secure Hash Algorithm with a digest of 256 bits

TLS Session Resumption

  • Important to consider when looking at speed and security
  • Two modes:
    • Session IDs (data stored client-side and server-side)
    • Session Tickets (data stored client-side)

TLS 1.2 with session resumption

Client                                                Server

ClientHello                   -------->
                                                 ServerHello
                                          [ChangeCipherSpec]
                              <--------             Finished
[ChangeCipherSpec]
Finished                      -------->
Application Data              <------->     Application Data
					
RFC 5246

Integrity

Methods used to provide integrity

Digital Signatures
Use public key cryptography to produce signatures that can be authenticated, and that are difficult to forge.
Authenticated Encryption with Associated Data (AEAD)
These provide secrecy as expected from a cipher, but in a way that also provides integrity and authenticity.
Message Authentication Codes
One way hash function computed from a message and secret data. It must be difficult to forge.

Secrecy

Security of application data in TLS

  • For secrecy, the data sent over TLS is encrypted with a semetric cipher, e.g. AES.
  • This is only secure if somehow the client and the server can agree on a key to use, without anyone else finding out.

Using RSA for the key exchange

RSA
Public key cryptosystem, first published by Ron Rivest, Adi Shamir, and Leonard Adleman.


  • The client generates a random value to be used as the key.
  • The client then encrypts this value with the server public key, and sends it to the server.
  • The server then decrypts the value, and uses it in the connection.

Forward Secrecy

A protocol is said to have perfect forward secrecy if compromise of long-term keys does not compromise past session keys.

Diffie Hellman

  • Public key distribution system
  • It has come to be known by those who first published it, Whitfield Diffie and Martin Hellman.

Modular Arithmetic

\[(4 + 4) \bmod 5 = 3\]
                *
0 1 2 3 4 5 6 7 8 9 10
0 1 2 3 4 0 1 2 3 0 1
\[(2 * 3) \bmod 5 = 1\]
            *
0 1 2 3 4 5 6 7 8 9 10
0 1 2 3 4 0 1 0 1 2 3
Alice and bob agree to use a modulus \(p = 23\) and base \(g = 5\).

Alice chooses a secret integer \(a = 6\)
Alice then computes the public integer \(A = g^a \bmod p\)
\(\implies\) \(5^6 \bmod 23 = 8\)


Bob chooses a secret integer \(b = 15\)
Bob then computes the public integer \(B = g^b \bmod p\)
\(\implies\) \(5^{15} \bmod 23 = 19\)


Alice and Bob share their public integers \(A\) and \(B\)

Alice then computes the shared secret \(s = B^a \bmod p = 19^6 \bmod 23 = 2\)
Bob then computes the shared secret \(s = A^b \bmod p = 8^{15} \bmod 23 = 2\)
When Alice computes the shared secret \(s\)

\(s = B^a \bmod p\)
\(B = g^b \bmod p\)

substituting \(s = (g^b \bmod p)^a \bmod p\)

This can be simplified to:

\(s = g^{ab} \bmod p\)

Cracking Diffie Hellman


\(b = log_g B \bmod p\)

\(s = A^b \bmod p\)

Guess at b (Bobs secret, which is 15) Calculation
\(guess\) \(A^{guess} \bmod p = ...\)
\(2\) \(8^2 \bmod 23 = 18\)
\(3\) \(8^3 \bmod 23 = 6\)
\(4\) \(8^4 \bmod 23 = 2\)
\(5\) \(8^5 \bmod 23 = 16\)
...

Back to ciphersuites... and Eliptic Curve Diffie Hellman

  • You probably won't use Diffie Hellman in its original form.
  • The approach generalises to finite cyclic groups.
  • A preferred form is using eliptic curve groups, rather than a group of multiplicative group of integers modulo n.

Authenticity

TLS 1.2 Full Handshake

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.
RFC 5246

HTTP Strict Transport Security (HSTS)

Strict-Transport-Security: max-age=31536000
Strict-Transport-Security: max-age=31536000; includeSubDomains
Strict-Transport-Security: max-age=31536000; includeSubDomains;
preload

The Future

TLS 1.3

TLS 1.3 Handshake

Client                                               Server

ClientHello
+ key_share               -------->
                                                ServerHello
                                                + key_share
                                      {EncryptedExtensions}
                                      {CertificateRequest*}
                                             {Certificate*}
                                       {CertificateVerify*}
                                                 {Finished}
                          <--------     [Application Data*]
{Certificate*}
{CertificateVerify*}
{Finished}                -------->
                          <--------        [NewSessionTicket]
[Application Data]        <------->      [Application Data]
					
Draft TLS 1.3 Spec

TLSv1.3 0-RTT Resumption

Client                                               Server

ClientHello
+ early_data
+ key_share*
+ psk_key_exchange_modes
+ pre_shared_key
(Application Data*)     -------->
                                                ServerHello
                                           + pre_shared_key
                                               + key_share*
                                      {EncryptedExtensions}
                                              + early_data*
                                                 {Finished}
                        <--------       [Application Data*]
(EndOfEarlyData)
{Finished}              -------->

[Application Data]      <------->        [Application Data]
					
Draft TLS 1.3 Spec

An overall view of HTTP and security

Mathematical Problems
Factoring, Discrete log
Cryptographic Primitives
RSA, Diffie-Hellman, DSA, AES, SHA-1, ...
Protocols
TLS, ...
Library Implementations
OpenSSL, GnuTLS, ...
Software Applications
Firefox, Chromium, Apache, NGinx, ...

Christopher Baines

Government Digital Service