The Secure Sockets Layer is an intermediate layer between the application and the transport protocol with the purpose to create secure and reliable communication.
The goal of the protocol is to create an agreement between a client and a server on a set of cryptographic protocols, algorithms and the parameters used for communication between them.
The protocol consists of a sequence of steps:
ClientHello(CipherSuite[], CompressionMethod[], ClientRandom)
One CipherSuite defines three encryption protocols:
ServerHello(CipherSuite, CompressionMethod, ServerRandom)
The server selects the cipher suite and the compression method and sends the information to the client. After this message, the encryption and compression protocols are selected. The rest of the protocols is used to agree on the secret keys.
ServerCertificate(Certificate)
The client generates 48 bytes (time + random) that is the master secret of this session and based on it other keys are generated. The client sends the master-key to the server:
encrypt(ClientMasterSecret, ServerPublicKey)
The Server initiates a key-exchange protocol, for example the Diffie-Hellman protocol. After the exchange of three messages, the server and the client have the master secret. Based on the master secret both parties create the keys used in communication.
Client to Server
hash(AllMessagesSentByClient+MasterSecret)
Server to Client
hash(AllMessagesSentByServer+MasterSecret)
SSL Application Data Protocol
encrypt(ClientRequest + hash(ClientRequest+MasterKey), ClientWriteKey);
encrypt(ServerResponse + hash(ServerResponse), ServerWriteKey);