Developing a Secure Peer-to-Peer Chat App Assignment

Assignment Task

Developing a Secure Peer-to-Peer Chat App

You are required to build a secure, asynchronous, peer-to-peer chat application. Network communications must be via TCP. The flow of the program should be:

  1. Start the program.
  2. Ask the user for the following information:
    • A port on the machine to act for incoming connections.
    • The name of a file containing a directory of individuals that can be contacted.
  3. Open Server TCP socket locally on the port specified by the user.
  4. Load the user directory (specification below). This is a JSON serialized dictionary format.
  5. Wait for either an incoming network message or a message to be sent, typed by the user.
  6. If there`s an incoming network message:
    • Connect to the destination using the secure protocol, which must include:
      • The generation of key material as shown below.
      • Mutual authentication of the outgoing connection.
      • Establishment of a secure channel using SHA256 HMAC and AES256 CBC Cryptography.
    • Receive Message – Message format below.
    • Check the control information for consistency.
    • Display the received message to the user.
    • Terminate the connection.
  7. If there`s a message to be sent:
    • Wait for the message to be completed (Your choice of end indication).
    • Request the destination from the user. This should be selected from the directory, but you should also provide a manual option to directly specify IP address, port, and password.
    • Open a socket to the destination.
    • Connect to the destination using the secure protocol, which must include:
      • The generation of key material as shown below.
      • Mutual authentication of the outgoing connection.
      • Establishment of a secure channel using SHA256 HMAC and AES256 CBC Cryptography.
    • Send Message – Message format below.
    • Display transmission success or failure message to the user.
    • Terminate the connection.
  8. Go to step 5.

Message Formats

You should use a Python Dictionary message format that can be serialized as follows:

 

User Directory Format

Type of HMAC in use: SHA256
Type of encryption in use: AES256CBC

You should use a Python List of Dictionaries for the directory format, which can be serialized:

 

Additional Requirements and Information

  • Before starting to write your application, plan the way you will develop features.
  • Use the user name in the CHAP messages to select the incoming information for the key.
  • Passwords should not be used directly for CHAP, HMAC, and crypto keys. Utilizing a key derivation function will be rewarded with higher marks.
  • All messages sent and received should be logged with appropriate security to protect their confidentiality and integrity.
  • All keys MUST be lowercase.
  • All msg_type values must be lowercase.
  • Where there is no explicit body (ack or nack), the body value is the serialized version of the NoneType or None.
  • PDUs MUST be serialized as a string and encoded using utf-8.
  • You may wish to delay the implementation of the user directory functionality to aid simplicity in building the system. However, a user directory is needed for higher marks.
  • Any messages received out of a time window of 25 seconds should be ignored.
  • Use a 32-bit Cyclic Redundancy Check calculation from the zlib library in the Message header.
  • It is highly recommended to use an object-oriented approach.
  • You must only use primitive cryptographic libraries and not utilize protocols such as SSL/TLS.
  • It is highly recommended to use some form of FSM for the management of the communications protocol.
  • Use comments extensively to explain your code.
  • Include a short .txt file that explains any security weaknesses you think are present in the approach.

WhatsApp icon