Introduction to Java
CS9053 Section I
Thursday 6 PM – 8:30 PM
April 8th, 2023
Due: April 14th, 2024 11:59 PM
Networks: Build a Chat Application
This assignment is going to require a bit more development than usual.
You are going to use the network to build a simple chat application, using your knowledge of the Java networking API.
Most design issues are up to you, but you will be creating a ChatServer class that creates a window with a JTextArea that displays debug info including who has connected. You will then be creating a ChatClient
What is going to happen is that you are going to start a ChatServer that accepts connections on port 9898 (make sure you don’t have another application accepting connections on this port). This server should be able to accept multiple connections.
Each Chat client should be able to connect to a server on port 9898. Once the chat client is connected, anything a user types in the chat client should be able to be seen by all other connected clients.
The tricky part is this: each connection has a handshake protocol:
• When the ChatClient connects to the ChatServer, the ChatClient sends a message “HELLO”.
• When the ChatServer receives a “HELLO” message, the ChatServer Sends a reply message to the ChatClient that says “CONNECTED.”
• When the ChatClient receives the “CONNECTED” message, it sends an “AES Seed” to the ChatServerEncryption with the ChatServer’s public key
• When the ChatServer receives the encrypted “AES Seed”, the ChatServer decrypts the encrypted message with its Private Key
• The ChatServer and ChatClient both generate an AES Key and use the AES Key to send encrypted messages to each other
• This AES Key is the encrypted channel for communications between the ChatServer and ChatClient
All the encryption methods are taken care for you and form a group of static methods in the encryption.Encryption class:
public static String encrypt(Key key, String input) – given an encryption key and a plaintext String, returns an encrypted String
public static String decrypt(Key key, String cipherText) – given an encryption key and encrypted text, returns a decrypted (plaintext) String
public static byte[] pkEncrypt(Key key, byte[] plaintext) – given an asymmetric key and an array of 16 plaintext bytes, returns an array of 128 encrypted bytes
public static byte[] pkDecrypt(Key key, byte[] ciphertext) – given an asymmetrc key and an array of 128 encrypted bytes, returns an array of 16 plaintext bytes
public static Key generateAESKey(byte[] sequence) – Given a 16 byte sequence, returns an AES (symmetric) encryption key
public static byte[] generateSeed() – generates a random 16 byte sequence that can be used as a seed to generate an AES encryption key
public static PrivateKeyreadPrivateKey(String filename) – reads an RSA PKCS8 file and returns a private key
public static PublicKeyreadPublicKey(String keyString) – takes an RSA keyString and returns a public key
To make life a little easier for you, the code in the ChatServeralready reads in its Private Key and the code in the ChatClientalready reads in the ChatServer’s Public Key.