TLS Flashcards
Which security properties can TLS provide?
It provides:
- server authN wth implicit asymmetric challenge response
- client authN (optional) with explcit asymm CR
- data integrity and data authN
- protection from replay and filtering attacks thanks to TCP and implicit sequence number
TLS architecture
TLS lays over TCP and uses the TLS Record Protocol to encapsulate application data.
The Record Protocol is used by:
- TLS handshake protocol: to negotiate crypto parameter
- TLS alert protocol: to send alertss about an error during the connection (ex. wrong MAC value)
- TLS change cipher spec: to start protecting the exchanged messages with the negotiated crypto parameters
Are the finished messages and the change cipher spec protocol the same?
No.
The Change Cipher Spec Protocol is used to change keys or algorithms without closing the channel. This is crucial because, after transferring a significant amount of data with the same algorithm and key (e.g., for encryption), the attacker has more opportunities to perform cryptanalysis. The more data that is encrypted with the same cipher-key pair, the higher the probability of determining the key. This protocol allows the system manager to change the keys after a certain amount of time or data exchanged, without closing the channel. It is also used at the beginning to transition the channel from unprotected to protected.
- finished: to authN the handshake -> the finished message is a MAC computed using the master secret and it is computed over all the messages exchanged before -> the finisched of the client and of the server will be different cause the server computes it considering also the client’s finished. It does not consider the change cipher spec.
How does the alert protocol work?
The Alert Protocol is used whenever there is an issue. When an alert record is sent then the connection is closed.
Sessions and connections in TLS
Session
It is a logical association between a client and a server which is created during the TLS Handshake.
Multiple connections can be associated to the same session and use the cryptographic parameters negotiated during the handshake.
Connection
It is a transient channel which is part of a session and it is between a server and a client.
TLS data protection
Application data are encapsulated with the TLS Record Protocol.
It mandatorily computes the MAC for integrity and optionally encrypts the obtained structure for confidentiality with symmetric enc algos and using an authN-then-encrypt schema.
The flows is the following:
- a TLS record is created with an empty MAC field (fixed sixe based on the chosen function) and random padding
- the MAC is computed over the data (that can be compressed or not) and inserted in the field. The directional MAC key is used
- the Enc key is used (with IV if needed) to encrypt the record
MAC = message_digest (key, seq_number || type || version || length || fragment)
TLS keys
They are 4 directional keys, 2 for MAC and 2 for Encryption.
During the handshake the client generates a pre-master secret that, only for the first connection, is combined with the random numbers to generate the master secret. Pre-master and master secrets will be used during the whole session.
The keys derive from the combination of master and random numbers and are re-generated at each connection.
TLS sequence number
Implicit, 2^64 values, then the session is closed.
It helps in avoiding replay and filtering attacks.
PFS in TLS
If a server has a certificate valid for both signature and encryption, then such a certificate can be used both for authentication (via a signature) and key exchange (asymmetric encryption of the session key).
But if an attacker copies all the encrypted traffic and later discovers the long-term private key, then
they can decrypt all the traffic…past, present, and future!
For this reason, the concept of perfect forward secrecy has been introduced. It ensures that:
* The compromise of the secret key used in the KE (Key Exchange) compromises only the current (and potentially future) traffic, but not the past traffic.
* It can be implemented using techniques such as ephemeral key exchange mechanisms (e.g., Diffie- Hellman Ephemeral (DHE) or Elliptic Curve Diffie-Hellman Ephemeral (ECDHE)).
Perfect forward secrecy is optional in TLS 1.2 but compulsory in TLS 1.3.
Ephemeral keys
A technique to reach PFS is to use ephemeral keys, that are key pair generated on-the-fly and signed with the long provate key (in this case of the server).
- if E keys are used this can be considered server authN
- the on the fly key pair won’t actually have a X.509 certificate
- the long term private key will only be used to sign data (keyUsage = digitalSignature) while the E key will be used to perform encryption
TLS1.2 handshake
ClientHello
TLS version + ciphersuite list + compression method lists + 28B ClientRandom + sessionID
Each ciphersuite is in the from:SSL_KeyExchangeAlgorithm_WITH_SymmetricEncryptionAlgorithm_HashAlgorithm(for MAC) ;
ServerHello
chosen TLS version + chosen ciphersuite list + chosen compression method lists + 28B ServerRandom + chosen sessionID
Certificate
Server X.509 certificate with the certificate chain to verify it.
[ServerKeyExchange]
Only if Ephemeral keys are used, here the server sends to the client the ephemeral public key encrypted with its long term secret key.
This is the only message explicitly signed by the server
[CertificateRequest]
The server asks the client for its certificate and shares the list of its trusted CAs.
[Client Certificate]
The client shares its X.509 certificate.
Client Key Exchange
The client encrypts the pre-master secret with the received pub key.
[Certificate Verify]
The client performs a signature over the digest computed over all the messages before this one. The server will compute the digest and verify the signature with the claimed client public key.
C: ChangeCipherSpec
Allows to pass from the previous unprotected messages to the protection of the next messages with the negotiated algorithms and keys
C: Finished
The client computes and hash with the master secret over the exchanged messaged but the changecipherSpec.
It prevents rollback man-in-the-middle attacks (version downgrade or cipher suite downgrade)
S: ChangeCipherSpec
S: Finished
The server computes and hash with the master secret over the exchanged messaged but the changecipherSpec
TLS resumed session
The client sends a session ID ≠ 0 in the ClientHello and the session is resumed if the server responds with the same sessionID in the ServerHello.
If the session is resumed then the new keys are generated with the new randoms and the master secret of the session.
TLS link teardown
If the client wants to close a connection it uses the Alert protocol:
- the client sends the alert close_notify
that is protected by the MAC
- it waits for the ACK from the server: alert close_notify
that is protected by a MAC too.
- they both check the MAC value and effectively close the connection if the value is the expected one.
The acknowledgment is needed to avoid closing a connectin if a fake request to do so is received.
TLS setup time
TLS1.2
It takes 2RTT, 1 if False Start is used
- (C→S) SYN
– (S→C) SYN-ACK - (C→S) ACK + ClientHello
– (S→C) ServerHello + Certificate - (C→S) ClientKeyExchange + ChangeCipherSpec + Finished
– (S→C) ChangeCipherSpec + Finished
TLS1.3
Basically, it’s a 1-RTT handshake that can be reduced to 0-RTT upon resumption of a previous session (or by using Pre-Shared Key, which is rare).
TLS versions