CSS411 Cryptography

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.

26 min read

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:

CategoryThreatsConsequencesCountermeasures
IntegrityModification of user data, Trojan horse browser, modification of memory, modification of message traffic in transitLoss of information, compromise of machine, vulnerability to all other threatsCryptographic checksums
ConfidentialityEavesdropping on the net, theft of info from server, theft of data from client, info about network configuration, info about which client talks to serverLoss of information, loss of privacyEncryption, web proxies
Denial of serviceKilling of user threads, flooding machine with bogus requests, filling up disk or memory, isolating machine by DNS attacksDisruptive, annoying, prevents user from getting work doneDifficult to prevent
AuthenticationImpersonation of legitimate users, data forgeryMisrepresentation of user, belief that false information is validCryptographic 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:

LevelStack on the slideExampleNotes
Network levelHTTP, FTP, SMTP over TCP over IP/IPSecIPSec(1) Transparent to end users and applications; (2) a general-purpose solution; (3) includes a traffic filtering capability
Transport levelHTTP, FTP, SMTP over SSL or TLS over TCP over IPSSL, TLSA more general-purpose solution: security directly above TCP
Application levelS/MIME over SMTP; Kerberos over UDP; HTTP over TCP; all over IPKerberos, S/MIMEApplication-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.

GoalMechanism
Authentication between client and serverHandshake protocol
High privacyEncryption-decryption
Data integrityDigitally 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:

  1. The browser sends a request to the server.
  2. The server answers with its certificate (X.509).
  3. The browser verifies the certificate: validation, trust, integrity, integrity with the domain name.
  4. The browser generates a symmetric key.
  5. Client identification: the browser sends the symmetric SSL key, encrypted, to the server.
  6. The server verifies and decrypts the symmetric key.
  7. 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 typeTrust 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:

CoverageMeaningExample
Single-domainApplies to only one domainwww.iiitkottayam.ac.in
WildcardApplies to one domain and its subdomainsadmissions.iiitkottayam.ac.in, icentre.iiitkottayam.ac.in
Multi-domainApplies 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:

PublishedNameByDeprecated
1995SSL 2.0Netscape2011
1996SSL 3.0Netscape2015
1999TLS 1.0, RFC 2246IETF2020
2006TLS 1.1, RFC 4346IETF2020
2008TLS 1.2, RFC 5246IETF—
2018TLS 1.3, RFC 8446IETF—

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.

ProtocolPurpose
Handshake ProtocolAuthentication and key exchange
Change Cipher Spec ProtocolCopies the pending state into the current state
Alert ProtocolSends TLS-related alerts to the peer
Heartbeat ProtocolChecks that the peer is alive
Record ProtocolConfidentiality 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 connectionTLS session
DefinitionA transport that gives a suitable type of serviceAn association between a client and a server
TypePeer-to-peer relationshipsCreated by the Handshake Protocol
LifetimeTransient (temporary)Defines a set of cryptographic security parameters
LinkEach connection is associated with one sessionMany connections can share the parameters. This avoids an expensive negotiation of new parameters for each connection

Session stateSearch on YouTube

ParameterMeaning
Session identifierAn arbitrary byte sequence that the server chooses to identify an active or resumable session state
Peer certificateAn X509.v3 certificate of the peer. This element may be null
Compression methodThe algorithm that compresses data before encryption
Cipher specThe bulk data encryption algorithm and the hash algorithm for the MAC calculation
Master secretA 48-byte secret shared between the client and the server
Is resumableA flag that shows if the session can start new connections

Connection stateSearch on YouTube

ParameterMeaning
Server and client randomByte sequences that the server and client choose for each connection
Server write MAC secretThe secret key for MAC operations on data that the server sends
Client write MAC secretThe secret key for MAC operations on data that the client sends
Server write keyThe encryption key for data that the server encrypts and the client decrypts
Client write keyThe encryption key for data that the client encrypts and the server decrypts
Initialization vectorsWith 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 numbersEach party keeps separate sequence numbers for sent and received messages. A change cipher spec message sets them to zero. They may not exceed 264−12^{64} - 1

Two numbers to learn: the sequence number limit 264−12^{64} - 1 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:

ServiceKey
ConfidentialityThe Handshake Protocol defines a shared secret key (SK) for conventional encryption of TLS payloads
Message integrityThe Handshake Protocol also defines a shared secret key to form a message authentication code (MAC)

Operation stepsSearch on YouTube

The steps before transmission are:

  1. Take an application message as input.
  2. Fragment the data into manageable blocks.
  3. Optionally, compress.
  4. Apply a MAC.
  5. Encrypt.
  6. Add a header.
  7. Transmit the result in a TCP segment.

The steps on received data are:

  1. Remove the header.
  2. Decrypt.
  3. Verify.
  4. Decompress.
  5. Reassemble.
  6. 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:

StageDetail
Application dataThe record protocol accepts this data
FragmentBlock =214= 2^{14} bytes =16384= 16384 bytes
CompressOptional. It must be lossless. It must not increase the content length by more than 1024 bytes
Add MACUses the HMAC algorithm [RFC 2104]. MAC length is 0, 16 or 20 bytes
EncryptWith the MAC, it must not increase the content length by more than 1024 bytes. Thus, the total length must not exceed 214+20482^{14} + 2048 bytes
Append TLS record headerContent type (8 bits), major version (8 bits), minor version (8 bits), compressed length (16 bits)

The slide also gives the cipher choices:

Block cipherKey sizeStream cipherKey size
AES128, 256RC4-128128
3DES168——

A fragment holds at most 2142^{14} bytes. Compression can add up to 1024 bytes, and encryption can add up to 1024 bytes more. Thus, the maximum length is 214+2048=184322^{14} + 2048 = 18432 bytes. The header is 8+8+8+16=408+8+8+16 = 40 bits =5= 5 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.

FieldSizeMeaning
Content type8 bitschange_cipher_spec, alert, handshake or application_data
Major version8 bitsMajor TLS version. The slide says: for TLSv2, it is 3
Minor version8 bitsMinor TLS version. The slide says: for TLSv2, it is 1
Compressed length16 bitsFinal length of the fragment (max 214+20482^{14}+2048 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:

FieldSizeValues
Level1 byteWarning (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
Alert1 byteA code that shows the specific alert
Some fatal alertsSome warning alerts
unexpected_messagebad_certificate
bad_record_maccertificate_revoked
decompression_failurecertificate_expired
handshake_failurecertificate_unknown
decryption_faileduser_canceled
record_overflowno_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:

FieldSizeMeaning
Type1 byteShows one of 10 messages
Length3 bytesThe length of the message in bytes
Content≥0\ge 0 bytesThe 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:

PhaseNameMessagesWhat happens
1Establish security capabilitiesclient → server: client_hello; server → client: server_helloSets the protocol version, session ID, cipher suite, compression method and initial random numbers
2Server authentication and key exchangeserver → client: certificate, server_key_exchange, certificate_request, server_hello_doneThe server may send a certificate and key exchange, and may request a certificate. The server signals the end of the hello phase
3Client authentication and key exchangeclient → server: certificate, client_key_exchange, certificate_verifyThe client sends a certificate if the server requested one. The client sends the key exchange. The client may send certificate verification
4Finishclient → server: change_cipher_spec, finished; server → client: change_cipher_spec, finishedChange the cipher suite and finish the handshake
ClientServerclient_helloserver_hellocertificateserver_key_exchangecertificate_requestserver_hello_donecertificateclient_key_exchangecertificate_verifychange_cipher_specfinishedchange_cipher_specfinishedPhase 1security capabilitiesPhase 2server auth, key exchangePhase 3client auth, key exchangePhase 4finishApplication data flows only after phase 4.
TLS handshake: four phases with up to 13 messages. Dashed arrows are optional or situation-dependent messages.

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:

  1. It tells the sender that the recipient is still alive, even when the TCP connection had no activity for some time.
  2. 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:

  1. The parties exchange a pre_master_secret.
  2. Both parties calculate the master_secret.

There are two ways to exchange the pre_master_secret:

MethodFlow
RSAThe 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-HellmanBoth 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:

master_secret=PRF(pre_master_secret, "master secret", ClientHello.random∥ServerHello.random)\text{master\_secret} = \text{PRF}(\text{pre\_master\_secret},\ \text{"master secret"},\ \text{ClientHello.random} \Vert \text{ServerHello.random})

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:

ParameterClient sideServer side
MAC secretclient write MAC secretserver write MAC secret
Encryption keyclient write keyserver write key
Initialization vectorclient write IVserver 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:

PRF(secret,label,seed)=P_hash(secret,label∥seed)\text{PRF}(\text{secret}, \text{label}, \text{seed}) = \text{P\_hash}(\text{secret}, \text{label} \Vert \text{seed})

The data expansion function P_hash() is a chain of HMACs:

A(0)=seed,A(i)=HMAC(secret,A(i−1))A(0) = \text{seed}, \qquad A(i) = \text{HMAC}(\text{secret}, A(i-1))

P_hash(secret,seed)=HMAC(secret,A(1)∥seed)∥HMAC(secret,A(2)∥seed)∥⋯\text{P\_hash}(\text{secret}, \text{seed}) = \text{HMAC}(\text{secret}, A(1) \Vert \text{seed}) \Vert \text{HMAC}(\text{secret}, A(2) \Vert \text{seed}) \Vert \cdots

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.
  1. 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 264−12^{64}-1.

Give the record protocol pipeline with all numeric limits.

Fragment into 214=163842^{14} = 16384-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 214+20482^{14}+2048 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 ∥\Vert 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 (2142^{14} bytes), compress (optional), MAC (HMAC), encrypt, add a 5-byte header. Maximum length is 214+20482^{14}+2048 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.