SSL and TLS
Slide deck 21. Web security, SSL certificates, the TLS two-layer architecture, the record protocol, the four-phase handshake and the master secret.
Web securitySearch on YouTube
Need for web securitySearch on YouTube
Almost all businesses, most government agencies and many individuals now have web sites. Users access them with graphical web browsers over the Internet. But the Internet and the Web are extremely vulnerable to attack.
The World Wide Web (WWW) is a client-server application that runs over the Internet and TCP/IP intranets. These characteristics of web usage show the need for security tools:
- Web servers are relatively easy to configure and manage.
- Web content is increasingly easy to develop.
- The underlying software is complex. It may hide many potential security flaws.
- An attacker can use a web server as a launching pad into the entire computer complex of the corporation or agency.
- Casual users, untrained in security, are common clients. They do not know the risks, and they do not have the tools or knowledge for countermeasures.
Threats on the webSearch on YouTube
The slide table puts web threats into four groups:
| Category | Threats | Consequences | Countermeasures |
|---|---|---|---|
| Integrity | Modification of user data, Trojan horse browser, modification of memory, modification of message traffic in transit | Loss of information, compromise of machine, vulnerability to all other threats | Cryptographic checksums |
| Confidentiality | Eavesdropping on the net, theft of info from server, theft of data from client, info about network configuration, info about which client talks to server | Loss of information, loss of privacy | Encryption, web proxies |
| Denial of service | Killing of user threads, flooding machine with bogus requests, filling up disk or memory, isolating machine by DNS attacks | Disruptive, annoying, prevents user from getting work done | Difficult to prevent |
| Authentication | Impersonation of legitimate users, data forgery | Misrepresentation of user, belief that false information is valid | Cryptographic techniques |
Threat categories: I-C-D-A. Integrity (cryptographic checksums), Confidentiality (encryption, web proxies), Denial of service (difficult to prevent), Authentication (cryptographic techniques). Denial of service is the only category without a clear countermeasure.
Security approachesSearch on YouTube
Web security can occur at three levels of the protocol stack:
| Level | Stack on the slide | Example | Notes |
|---|---|---|---|
| Network level | HTTP, FTP, SMTP over TCP over IP/IPSec | IPSec | (1) Transparent to end users and applications; (2) a general-purpose solution; (3) includes a traffic filtering capability |
| Transport level | HTTP, FTP, SMTP over SSL or TLS over TCP over IP | SSL, TLS | A more general-purpose solution: security directly above TCP |
| Application level | S/MIME over SMTP; Kerberos over UDP; HTTP over TCP; all over IP | Kerberos, S/MIME | Application-specific security services are embedded in the application |
The rest of the deck is about the transport level.
SSLSearch on YouTube
SSL overviewSearch on YouTube
SSL (Secure Sockets Layer) is an encryption-based Internet security protocol. Netscape Communications Corporation developed it. Its purpose is privacy, authentication and data integrity in Internet communications.
| Goal | Mechanism |
|---|---|
| Authentication between client and server | Handshake protocol |
| High privacy | Encryption-decryption |
| Data integrity | Digitally signed data |
The IETF deprecated SSL and released its successor, TLS, in 1999.
HTTPSSearch on YouTube
SSL-enabled browsers can communicate securely with a server that has a digital certificate. A browser that does not support HTTP over SSL cannot request URLs with HTTPS.
HTTPS is a protocol that combines SSL and HTTP. HTTPS and HTTP are different protocols and use different ports (443 and 80). Thus, a server can run SSL and non-SSL requests at the same time.
SSL certificatesSearch on YouTube
An SSL certificate is a digital document. It binds the identity of a website to a cryptographic key pair (public key and private key). It is a type of X.509 public-key certificate, but it is a server certificate. SSL certificates make an encrypted connection between a web browser and a server with a shared secret key.
The slide diagram has seven steps:
- The browser sends a request to the server.
- The server answers with its certificate (X.509).
- The browser verifies the certificate: validation, trust, integrity, integrity with the domain name.
- The browser generates a symmetric key.
- Client identification: the browser sends the symmetric SSL key, encrypted, to the server.
- The server verifies and decrypts the symmetric key.
- Both sides use symmetric encryption for secure data transfer.
Certificate typesSearch on YouTube
The slide shows two independent lists. The first list gives the trust level, which shows how much the CA checked:
| Validation type | Trust level |
|---|---|
| Domain Validation (DV) | Minimal trust |
| Organization Validated (OV) | Moderate trust |
| Extended Validation (EV) | Maximum trust |
The second list gives the coverage, which shows which names the certificate covers:
| Coverage | Meaning | Example |
|---|---|---|
| Single-domain | Applies to only one domain | www.iiitkottayam.ac.in |
| Wildcard | Applies to one domain and its subdomains | admissions.iiitkottayam.ac.in, icentre.iiitkottayam.ac.in |
| Multi-domain | Applies to multiple unrelated domains | — |
Answer the two lists separately. DV, OV and EV tell you who was checked. Single-domain, wildcard and multi-domain tell you which names are covered.
Example applicationSearch on YouTube
The deck shows a VPN client configuration (illustrative). The user selects SSL-VPN (the other option is IPsec VPN). The user sets the remote gateway (vpn.example.org) and the port 443.
TLS architectureSearch on YouTube
TLS overviewSearch on YouTube
TLS (Transport Layer Security) [RFC 5246] is an Internet standard. It evolved from the commercial protocol SSL. TLS uses TCP to give a reliable end-to-end secure service. Some applications are Web (HTTP+TLS), Email (SMTP+TLS) and File Transfer (FTP+TLS).
The slide timeline gives the versions:
| Published | Name | By | Deprecated |
|---|---|---|---|
| 1995 | SSL 2.0 | Netscape | 2011 |
| 1996 | SSL 3.0 | Netscape | 2015 |
| 1999 | TLS 1.0, RFC 2246 | IETF | 2020 |
| 2006 | TLS 1.1, RFC 4346 | IETF | 2020 |
| 2008 | TLS 1.2, RFC 5246 | IETF | — |
| 2018 | TLS 1.3, RFC 8446 | IETF | — |
Four versions are deprecated: SSL 2.0, SSL 3.0, TLS 1.0 and TLS 1.1. TLS 1.2 (RFC 5246) and TLS 1.3 (RFC 8446) are not deprecated on the slide.
Protocol layersSearch on YouTube
TLS is not one protocol. It is two layers of protocols:
- The Record Protocol gives basic security services to upper-layer protocols such as HTTP.
- TLS defines three higher-layer protocols that manage TLS exchanges: the Handshake Protocol, the Change Cipher Spec Protocol and the Alert Protocol.
- The Heartbeat Protocol is a fourth higher-layer protocol.
The stack, top to bottom: Handshake, Change Cipher Spec, Alert, HTTP and Heartbeat; then the Record Protocol; then TCP; then IP.
| Protocol | Purpose |
|---|---|
| Handshake Protocol | Authentication and key exchange |
| Change Cipher Spec Protocol | Copies the pending state into the current state |
| Alert Protocol | Sends TLS-related alerts to the peer |
| Heartbeat Protocol | Checks that the peer is alive |
| Record Protocol | Confidentiality and integrity for TLS connections |
Think of TLS as a hotel. The record protocol is the guarded corridor that all visitors use. The handshake is the check-in desk that checks passports and gives out keys. Change cipher spec switches the corridor locks to the new keys. The alert protocol is the fire alarm. The heartbeat is the patrol of the watchman.
Connection and sessionSearch on YouTube
| TLS connection | TLS session | |
|---|---|---|
| Definition | A transport that gives a suitable type of service | An association between a client and a server |
| Type | Peer-to-peer relationships | Created by the Handshake Protocol |
| Lifetime | Transient (temporary) | Defines a set of cryptographic security parameters |
| Link | Each connection is associated with one session | Many connections can share the parameters. This avoids an expensive negotiation of new parameters for each connection |
Session stateSearch on YouTube
| Parameter | Meaning |
|---|---|
| Session identifier | An arbitrary byte sequence that the server chooses to identify an active or resumable session state |
| Peer certificate | An X509.v3 certificate of the peer. This element may be null |
| Compression method | The algorithm that compresses data before encryption |
| Cipher spec | The bulk data encryption algorithm and the hash algorithm for the MAC calculation |
| Master secret | A 48-byte secret shared between the client and the server |
| Is resumable | A flag that shows if the session can start new connections |
Connection stateSearch on YouTube
| Parameter | Meaning |
|---|---|
| Server and client random | Byte sequences that the server and client choose for each connection |
| Server write MAC secret | The secret key for MAC operations on data that the server sends |
| Client write MAC secret | The secret key for MAC operations on data that the client sends |
| Server write key | The encryption key for data that the server encrypts and the client decrypts |
| Client write key | The encryption key for data that the client encrypts and the server decrypts |
| Initialization vectors | With a block cipher in CBC mode, each key has an IV. The Handshake Protocol sets the first IV. The final ciphertext block of each record becomes the IV of the next record |
| Sequence numbers | Each party keeps separate sequence numbers for sent and received messages. A change cipher spec message sets them to zero. They may not exceed |
Two numbers to learn: the sequence number limit and the 48-byte master secret. A party sets its sequence number to zero when it sends or receives a change cipher spec message.
Record protocolSearch on YouTube
ServicesSearch on YouTube
The record protocol gives two basic security services for TLS connections:
| Service | Key |
|---|---|
| Confidentiality | The Handshake Protocol defines a shared secret key (SK) for conventional encryption of TLS payloads |
| Message integrity | The Handshake Protocol also defines a shared secret key to form a message authentication code (MAC) |
Operation stepsSearch on YouTube
The steps before transmission are:
- Take an application message as input.
- Fragment the data into manageable blocks.
- Optionally, compress.
- Apply a MAC.
- Encrypt.
- Add a header.
- Transmit the result in a TCP segment.
The steps on received data are:
- Remove the header.
- Decrypt.
- Verify.
- Decompress.
- Reassemble.
- Deliver to the higher-level users.
Send pipeline F-C-M-E-H: Fragment, Compress, MAC, Encrypt, Header. The receive pipeline does the reverse: remove the header, decrypt, verify, decompress, reassemble, deliver.
Pipeline limitsSearch on YouTube
The slide diagram gives these limits:
| Stage | Detail |
|---|---|
| Application data | The record protocol accepts this data |
| Fragment | Block bytes bytes |
| Compress | Optional. It must be lossless. It must not increase the content length by more than 1024 bytes |
| Add MAC | Uses the HMAC algorithm [RFC 2104]. MAC length is 0, 16 or 20 bytes |
| Encrypt | With the MAC, it must not increase the content length by more than 1024 bytes. Thus, the total length must not exceed bytes |
| Append TLS record header | Content type (8 bits), major version (8 bits), minor version (8 bits), compressed length (16 bits) |
The slide also gives the cipher choices:
| Block cipher | Key size | Stream cipher | Key size |
|---|---|---|---|
| AES | 128, 256 | RC4-128 | 128 |
| 3DES | 168 | — | — |
A fragment holds at most bytes. Compression can add up to 1024 bytes, and encryption can add up to 1024 bytes more. Thus, the maximum length is bytes. The header is bits bytes.
Record formatSearch on YouTube
Each record starts with a header of four fields. After the header comes the plaintext (optionally compressed) and a MAC of 0, 16 or 20 bytes. Encryption covers the plaintext and the MAC.
| Field | Size | Meaning |
|---|---|---|
| Content type | 8 bits | change_cipher_spec, alert, handshake or application_data |
| Major version | 8 bits | Major TLS version. The slide says: for TLSv2, it is 3 |
| Minor version | 8 bits | Minor TLS version. The slide says: for TLSv2, it is 1 |
| Compressed length | 16 bits | Final length of the fragment (max bytes) |
The slide values (3, 1) come from Stallings. In the real protocol, version 3.1 is TLS 1.0, and TLS 1.2 sends 3.3. For the exam, give the slide values.
Upper-layer protocolsSearch on YouTube
Change cipher specSearch on YouTube
The Change Cipher Spec Protocol has one message. The message is one byte with the value 1. Its only purpose is to copy the pending state into the current state. This updates the cipher suite for this connection.
Exam line: "one message, one byte, value 1, pending state becomes current state". Write all four parts.
Alert protocolSearch on YouTube
The alert protocol sends TLS-related alerts to the peer entity. Each message has two bytes:
| Field | Size | Values |
|---|---|---|
| Level | 1 byte | Warning (value 1): sends a warning. Fatal (value 2): TLS immediately terminates the connection. Other connections on the same session may continue, but no new connections on this session are possible |
| Alert | 1 byte | A code that shows the specific alert |
| Some fatal alerts | Some warning alerts |
|---|---|
| unexpected_message | bad_certificate |
| bad_record_mac | certificate_revoked |
| decompression_failure | certificate_expired |
| handshake_failure | certificate_unknown |
| decryption_failed | user_canceled |
| record_overflow | no_renegotiation |
| access_denied | — |
The deck shows an alert example from a FortiClient VPN (SSL-VPN) client. A warning dialog shows "Credential or SSLVPN configuration is wrong. (-7200)".
Level values grow with severity: Warning = 1, then Fatal = 2. A warning does not stop the connection. A fatal alert stops it.
Handshake protocolSearch on YouTube
The handshake protocol lets the server and the client:
- authenticate each other,
- negotiate an encryption and MAC algorithm,
- negotiate the cryptographic keys that protect data in a TLS record.
The handshake occurs before the transmission of any application data. Each handshake message has three fields:
| Field | Size | Meaning |
|---|---|---|
| Type | 1 byte | Shows one of 10 messages |
| Length | 3 bytes | The length of the message in bytes |
| Content | bytes | The parameters of this message |
Handshake phasesSearch on YouTube
The client and server need an initial exchange. It makes a logical connection and sets the security capabilities. The exchange has 4 phases:
| Phase | Name | Messages | What happens |
|---|---|---|---|
| 1 | Establish security capabilities | client → server: client_hello; server → client: server_hello | Sets the protocol version, session ID, cipher suite, compression method and initial random numbers |
| 2 | Server authentication and key exchange | server → client: certificate, server_key_exchange, certificate_request, server_hello_done | The server may send a certificate and key exchange, and may request a certificate. The server signals the end of the hello phase |
| 3 | Client authentication and key exchange | client → server: certificate, client_key_exchange, certificate_verify | The client sends a certificate if the server requested one. The client sends the key exchange. The client may send certificate verification |
| 4 | Finish | client → server: change_cipher_spec, finished; server → client: change_cipher_spec, finished | Change the cipher suite and finish the handshake |
The shaded messages on the slide are optional or situation-dependent. They are: certificate, server_key_exchange and certificate_request in phase 2, and certificate and certificate_verify in phase 3.
Phase order: Hello, Server, Client, Finish. Message count: 2 + 4 + 3 + 4 = 13 messages if all optional messages occur.
Heartbeat protocolSearch on YouTube
A heartbeat is a periodic signal from hardware or software. It shows normal operation, or it synchronizes other parts of a system. A heartbeat protocol monitors the availability of a protocol entity. The slide cites RFC 6250; the TLS Heartbeat RFC number is 6520.
- It runs on top of the TLS Record Protocol.
- It has two message types: heartbeat_request and heartbeat_response.
- The two peers agree to use it during Phase 1 of the Handshake Protocol.
The heartbeat has two purposes:
- It tells the sender that the recipient is still alive, even when the TCP connection had no activity for some time.
- It makes activity on the connection during idle periods. This prevents closure by a firewall that does not accept idle connections.
Cryptographic computationsSearch on YouTube
Master secretSearch on YouTube
The shared master secret is a one-time 48-byte value. Secure key exchange makes it for this session. The creation has two stages:
- The parties exchange a pre_master_secret.
- Both parties calculate the master_secret.
There are two ways to exchange the pre_master_secret:
| Method | Flow |
|---|---|
| RSA | The client generates a 48-byte pre_master_secret. The client encrypts it with the public RSA key of the server and sends it. The server decrypts it with its private key |
| Diffie-Hellman | Both client and server generate a Diffie-Hellman public key. After the exchange, each side does the Diffie-Hellman calculation to get the shared pre_master_secret |
Both sides then compute the master secret:
ClientHello.random and ServerHello.random are the two nonces from the initial hello messages. PRF is the pseudorandom function.
Key blockSearch on YouTube
The second item is the generation of cryptographic parameters from the master secret. A CipherSpec needs six values:
| Parameter | Client side | Server side |
|---|---|---|
| MAC secret | client write MAC secret | server write MAC secret |
| Encryption key | client write key | server write key |
| Initialization vector | client write IV | server write IV |
The parties hash the master secret into a sequence of secure bytes of sufficient length. The slide formula is (the symbol ‘ on the slide means concatenation):
key_block =
MD5(master_secret || SHA('A' || master_secret || ServerHello.random || ClientHello.random)) ||
MD5(master_secret || SHA('BB' || master_secret || ServerHello.random || ClientHello.random)) ||
...The labels 'A', 'BB', 'CCC' and so on change for each block. The computation continues until the key_block is long enough.
Pseudorandom functionSearch on YouTube
To make the PRF as secure as possible, TLS uses two hash algorithms in it. The PRF takes a secret value, an identifying label and a seed value. It gives an output of arbitrary length:
The data expansion function P_hash() is a chain of HMACs:
Each output block has a length equal to the hash size. P_hash repeats the chain until it has enough bytes.
Quick self-testSearch on YouTube
Give four characteristics of web usage that show the need for security tools.
Web servers are easy to configure and manage. Web content is easy to develop. The underlying software is complex and can hide security flaws. A web server can be a launching pad into the whole computer complex. Many clients are casual users without security training.
Give the four web threat categories and their countermeasures.
Integrity: cryptographic checksums. Confidentiality: encryption and web proxies. Denial of service: difficult to prevent. Authentication: cryptographic techniques.
Where do IPSec, SSL/TLS, Kerberos and S/MIME sit?
IPSec is at the network level. It is transparent to users and applications, general-purpose, and it can filter traffic. SSL and TLS are at the transport level, directly above TCP. Kerberos and S/MIME are at the application level, inside the application.
Give the three services of SSL and the mechanism for each. Why can HTTPS and HTTP run on the same server?
Authentication: the handshake protocol. High privacy: encryption-decryption. Data integrity: digitally signed data. HTTPS uses port 443 and HTTP uses port 80, so the server can answer both at the same time.
Give the seven steps of the SSL certificate diagram.
- Request to the server. 2. The server answers with its X.509 certificate. 3. The browser verifies it (validation, trust, integrity, integrity with the domain name). 4. The browser generates a symmetric key. 5. The browser sends the encrypted symmetric key to the server. 6. The server verifies and decrypts the symmetric key. 7. Symmetric encryption protects the data transfer.
Give the session state and the connection state parameters.
Session: session identifier, peer certificate, compression method, cipher spec, 48-byte master secret, is resumable. Connection: server and client random, server and client write MAC secrets, server and client write keys, IVs, and sequence numbers. Sequence numbers go to zero at change cipher spec and may not exceed .
Give the record protocol pipeline with all numeric limits.
Fragment into -byte blocks. Optional lossless compression adds at most 1024 bytes. HMAC [RFC 2104] adds a MAC of 0, 16 or 20 bytes. Encryption with the MAC adds at most 1024 bytes, so the total is at most bytes. The header has content type (8 bits), major version (8), minor version (8) and compressed length (16).
What is the change cipher spec message, and what does it do?
It is one message of one byte with the value 1. It copies the pending state into the current state. This updates the cipher suite for the connection.
Give the structure of an alert message. What does a fatal alert stop?
Two bytes: the level (warning = 1, fatal = 2) and a 1-byte alert code. A fatal alert immediately terminates the connection. Other connections on the same session may continue, but no new connections on this session are possible.
Give the four handshake phases and their messages. Which messages are optional?
Phase 1: client_hello, server_hello. Phase 2: certificate, server_key_exchange, certificate_request, server_hello_done. Phase 3: certificate, client_key_exchange, certificate_verify. Phase 4: change_cipher_spec and finished in both directions. Optional: the certificates, server_key_exchange, certificate_request and certificate_verify.
How do RSA and Diffie-Hellman make the pre_master_secret? How do the parties get the master secret?
RSA: the client makes a 48-byte pre_master_secret and encrypts it with the public RSA key of the server. The server decrypts it with its private key. Diffie-Hellman: both sides send DH public keys and each side calculates the shared pre_master_secret. Then master_secret = PRF(pre_master_secret, "master secret", ClientHello.random ServerHello.random).
What are the two purposes of the heartbeat protocol?
It tells the sender that the recipient is still alive when the TCP connection is idle. It also makes activity during idle periods, so a firewall does not close the connection. The peers agree to use it in Phase 1 of the handshake.
- Web threats: integrity (cryptographic checksums), confidentiality (encryption, web proxies), denial of service (difficult to prevent), authentication (cryptographic techniques). Security can be at the network level (IPSec), the transport level (SSL/TLS) or the application level (Kerberos, S/MIME).
- SSL (Netscape) gives privacy, authentication and integrity. The IETF replaced it with TLS in 1999. HTTPS = HTTP + SSL on port 443; HTTP uses port 80.
- An SSL certificate is an X.509 server certificate. DV, OV and EV give the trust level. Single-domain, wildcard and multi-domain give the coverage.
- TLS has two layers: the record protocol, and the handshake, change cipher spec, alert and heartbeat protocols above it. A session holds shared parameters; a connection is transient.
- Record pipeline: fragment ( bytes), compress (optional), MAC (HMAC), encrypt, add a 5-byte header. Maximum length is bytes.
- Change cipher spec is one byte of value 1. An alert is two bytes: level and code. The handshake has four phases before any application data.
- The 48-byte master secret comes from the PRF over the pre_master_secret (RSA or DH) and the two hello randoms. The key block gives the six write secrets.
TLS Handshake Explained - Computerphile
Breaking Down the TLS Handshake
SSL/TLS Handshake Process