Implementing a secure exchange protocol with OpenSSL

 

 

 

 

Work done by CHEBBAH Mehdi


 

Table of Contents


Introduction

In this tutorial we will implement a hybrid secure exchange protocol that guarantees the following security services:

For this we will try to implement the system whose design has been previously established:

 

Implementation

Concerning this part, we will divide it into 3 phases:

Phase 1: Creation of key pairs

In this phase each of the two protagonists will create their own key pair a public key and a private key (PKi and SKi)

1. Script for creating key pairs
Obtained results:
  1. Creation of two files skA.pem and pkA.pem in the current directory (of Alice)

Re-execute the script in Bob's directory changing skA.pem and pkA.pem to skB.pem and pkB.pem respectively.

Note:

Phase 2: Session key exchange

In the opening of the session Alice will randomly generate a session key that will be communicated to Bob, this key will be encrypted using Bob's public key, the signature will be guaranteed in this transfer (this is the role of asymmetric encryption in this hybrid system)

1. Session key generation and encryption script
Obtained results:
  1. Create a kAB file containing the session key.
  2. Creation of a kAB.crypt file containing the kAB cryptogram.
  3. Creation of a kAB.md5.sign file containing the session key's hash signature.
Note:

The two files (kAB.crypt and kAB.md5.sign) will be sent to Bob and deleted from Alice's directory

 

2. Decryption script and verification of non-repudiation and integrity of the session key
Obtained results:
  1. Creation of a kAB file containing the session key sent by Alice
  2. display a success message ('The key has been correctly transmitted.') in case the transmission is correct (the received session key is the same as the one sent). Or the display of a failure message ('Attention, the key has been modified.') in case the sent file and the received file are different.

Phase 3: Exchange of messages

After the establishment of the two previous phases it is now possible to send messages between Alice and Bob using symmetric encryption for confidentiality and private key encryption for signature

1. Messages encryption script
Obtained results:
  1. Creation of the file Message.crypte containing the message encrypted with the session key kAB.
  2. Creation of the file Message.md5.sign containing the signature of the message hash
Note:

The two files (Message.crypt and Message.md5.sign) will be sent to Bob and then deleted from Alice's directory

 

2. Messages decryption script
Obtained results:
  1. Creation of the file Message.txt containing the message received from Alice.
  2. Display a success message ('The message is transmitted with success. You can read it in Message.txt') in case the transmission is correct (the received message is the same as the sent message). Or the display of a failure message ('Message transmission failed (The message has been modified).') in case the sent message and the received message are different.
Note:

Bob can now read the message sent by Alice.