Reference no: EM133390158
Implement Simulation of TLS
In this assignment, the task is to implement a simulation of TLS in any coding language of your choice, including the two key exchange methods (RSA and Diffie-Hellman). The implementation is only a simulation of what happens in real-life. You can use variables, classes, methods to represent the operations done by the client and the server. No actual deployment of websites is necessary.
The TLS handshake required to be implemented will proceed as follows.
1- The client generates a nonce of size 32 bytes. You may use an existing random number generator or library for this step. The client sends the nonce to the server along with a flag that is set to 1 if RSA will be used for key exchange, and set to zero if Diffie-Hellman will be used. You may randomly set this flag.
2- The server responds with another nonce of size 32 bytes and a flag indicating the choice of key exchange algorithm. You may randomly generate the nonce as in Step 1 and randomly generate the choice of key exchange algorithm as well.
3- The server randomly generates a pair of RSA public/private keys and sends to the client {public key, hash(public key)}. This constitutes the certificate. You may use libraries for key generation and hashing.
4- Upon receiving this certificate, the client re-hashes the public key and compares with the hash that is sent. If they match the client proceeds to Step 5. Otherwise, the process ends here with an error message.
5- The client proceeds with exchanging the pre-master secret (PS) depending on whether RSA or Diffie-Hellman were chosen in Step 2. The details of this step are in the lecture slides. You may use libraries to generate all keys and calculate all RSA/Diffie-Hellman values in this step.
6- Once both sides calculate PS, they use it along with the first two nonces as a seed to a pseudorandom number generator to generate the 4 communication keys. You are free to implement this step in any way using libraries. Let's call the 4 keys {CC, IC, CS, IS}, representing the encryption key of the client, CC, the MAC key of the client, IC, the encryption key of the server CS, and the MAC key of the server, IS.
7- The client the sends the server hash(nonce_client, nonce_server, premaster secret, CC, IC). The server sends to the client hash(nonce_client, nonce_server, premaster secret, CS, IS). Each side will verify the values they received and print either a success or failure message.
Note that to simulate the process of sending anything between two entities, you may just assume that the values being sent (for example if you code them as variables) become available at the receiving side. This can be simulated for example by passing parameters to a method or function or simply just using the variables in the sequence of operations. No actual communication (for example using socket programming or otherwise) is required.