When a client connects to an SSL or TLS server, the SSL/TLS Handshake begins. The Handshake establishes the protocols that will be used during the communication, selects the cryptographic algorithms, authenticates the parties, and uses public key cryptography to create a master secret , from which encryption and authentication keys are derived.
The master secret for the session is created by the server using a premaster secret sent from the client.
The master secret is used to generate four more secrets (keys):
An encryption key used for sending data from the client to the server.
An encryption key used for sending data from the server to the client.
An authentication key used for sending data from the client to the server.
An authentication key used for sending data from the server to the client.
The Handshake is performed by a complex exchange between the client and the server. Optional items are indicated in brackets:
The client opens a connection and sends the ClientHello.
The server sends a ServerHello.
[The server sends its certificate.]
[The server sends a ServerKeyExchange.]
[The server sends a CertificateRequest.]
The server sends a ServerHelloDone (TLS only).
[The client sends its certificate.]
The client sends a ClientKeyExchange.
[The client sends a CertificateVerify.]
The client and server both send ChangeCipherSpec messages.
The client and server both send finished messages.
Application data flows.
With the exception of the secrets that are encrypted with the recipient’s public key, the entire Handshake is sent unencrypted, in the clear. The secrets are then used to encrypt all subsequent communications.
The SSL/TLS ClientHello is a message that contains the information shown in Table B-1.
Table B-1. ClientHello message
After the client sends the ClientHello, it waits for the ServerHello message.
When the SSL/TLS server receives the ClientHello, it responds with either a handshake_failure alert or a ServerHello message.
The ServerHello message has the form shown in Table B-2.
Table B-2. ServerHello message
Notice that the server chooses the cipher suite and compression method to be used for the SSL/TLS connection. If the server does not implement or will not use any of the cipher suites and compression methods offered by the client, the server can simply send a handshake_failure alert and terminate the session.
After sending the ServerHello, the server may optionally send its certificate. The certificate consists of one or more X.509 v1, v2, or v3 certificates. (If the server uses the Fortezza cipher suite, the server certificate sent is a modified X.509 certificate.)
The server sends the server key exchange message if the server has no certificate or if it has a certificate that is used only for signing. This might happen in one of three cases:
The server is using the Diffie-Hellman key exchange protocol.
The server is using RSA, but has a signature-only RSA key.
The server is using the Fortezza/DMS encryption suite.
The key exchange message consists of the fields shown in Table B-3.
Table B-3. Server key exchange parameters
Signatures may be RSA signatures, DSA signatures, or anonymous (in which case there are no signatures). Servers that have no signatures offer no protection against man-in-the-middle or server substitution attacks.[230]
SSL 3.0 and TLS define three modes of Diffie-Hellman operations for the initial key exchange:
In this mode, the server generates its Diffie-Hellman public value and the Diffie-Hellman parameters and sends them to the client. The client then sends back its client value. This mode is susceptible to the man-in-the-middle attack, because the server’s parameters and public value are not authenticated. (In a man-in-the-middle attack, an attacker could simply conduct anonymous Diffie-Hellman with both parties.)
In this mode, the server’s certificate contains its fixed Diffie-Hellman parameters instead of an RSA or DSS public key. Because SSL 3.0 allows only one key per server, a server that is configured to operate in fixed Diffie-Hellman mode cannot interoperate with SSL clients that expect to perform RSA key exchanges.
In this mode, the server generates its own Diffie-Hellman parameters, then uses a pre-existing RSA or DSS public key to sign the parameters, which are then sent to the client. This third mode appears to be the most secure SSL 3.0 operating mode.
Few commercial products implement the Diffie-Hellman SSL/TLS key exchange algorithms.
If the server wishes to authenticate the client, it can send a Certificate Request to the client. Certificate Requests consist of five parts, shown in Table B-4.
Table B-4. Certificate Request message
If requested by the server, the client sends any certificates that were requested. If no certificate is available, the client sends the no certificate alert.
It is up to the server to decide what to do if a no certificate alert is received. The server could continue the transaction with an anonymous client. Alternatively, the server could terminate the connection by sending a data handshake failure alert.
The client can send one of three kinds of key exchange messages, depending on the particular public key algorithm that has been selected. These are shown in Table B-5.
Table B-5. Server key exchange parameters
If the client sends a public certificate that has signing capability (such as an RSA or a DSS certificate), the client now sends a CertificateVerify message. This message consists of two message authentication codes, one calculated with the MD5 algorithm and one calculated with SHA. They are:
CertificateVerify.signature.md5_hash MD5(ClientHello.random + ServerHello.random + ServerParams); CertificateVerify.signature.sha_hash SHA(ClientHello.random + ServerHello.random + ServerParams);
The handshake_messages refers to all handshake messages starting with the ClientHello up to but not including the CertificateVerify message.
After the CertificateVerify is sent, the ChangeCipherSpec message is sent. After the message is sent, all following messages are encrypted according to the specified cipher suite and compressed according to the compression method.
Finally, both the client and the server send finished messages. The finished message consists of the result of a pseudorandom function (another hash) that takes as arguments the master secret, the finished_label , and both the MD5 and SHA-1 of the handshake message.
The finished message verifies that both the client and server are in proper synchronization. If they aren’t, then the SSL link is terminated.