Question: You are required to build a secure, asynchronous, peer-to-peer chat application. Network communications must via TCP. The flow of the program should be: 1. Start
You are required to build a secure, asynchronous, peer-to-peer chat application. Network communications must via TCP. The flow of the program should be:
1. Start the program
2. Ask the user for the following information:
a. A port on the machine to act for incoming connections
b. The name of a file containing a directory of individuals that can be contacted
3. Open Server TCP socket locally on port specified by the user
4. Load user directory (specification below) a. This is a JSON serialised dictionary format.
5. Wait for either an incoming network message or a message to be sent, typed by the user
6. If an incoming network message
a. Connect to the destination using the secure protocol, which must include
i. The generation of key material should be as shown below
ii. Mutual authentication of the outgoing connection
iii. Establishment of a secure channel using SHA256 HMAC and AES256 CBC Cryptography
b. Receive Message Message format below.
c. Check the control information for consistency d. Display received message to the user
e. Terminate Connection
7. If message to be sent
a. Wait for the message to be completed Your choice of end indication (special character, return key, character sequence)
b. Request destination from user. This should be selected from the directory, but you should also provide a manual option to directly specify IP address, port, and password
c. Open socket to destination d. Connect to the destination using the secure protocol, which must include
i. The generation of key material should be as shown below ii. Mutual authentication outgoing connection
iii. Establishment of a secure channel using SHA256 HMAC and AES256 CBC Cryptography
e. Send Message Message format below.
f. Display transmission success or failure message to user g. Terminate Connection
8. Go to step 5.
Key Material Generation Once the common user secret is known and the DHSK is generated, these items should be put through a SHA256 HMAC with the user secret as the password and the DHSK as the input

The output of the SHA256 hash (including the HMAC) will produce 32 bytes of data (represented as 64 hexadecimal characters). These outputs CAN be used directly with the cryptographic libraries in PyCryptoDome except for the IV, which must only be 16 bytes. Given SHA256 returns 32 bytes, use the first 16 bytes (0-15) of the bytes type object, which can be sliced using list slicing notation or a split function. The SAME IV is used every time a message is encrypted and decrypted
Message Formats You should use a Python Dictionary message format that can be serialised as follows: 'hmac_type': val, Type of HMAC in use, SHA256 User Directory Format You should use a Python List of Dictionaries for the directory format, which can be serialised: Directory =[ \{'username': val, 'password': val, 'port': val, 'ip':' val '\}, \{'username': val, 'password': val, 'port': val, 'ip':' val '\}, ]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
