Spring 2022 IS496 Programming Assignment 1 - Simple Secure UDP Program


Total Points: 100 points
Goal: Refresh how to compile code, gain experience with network syscalls.
    Write a simple UDP network client and server.
Assigned: January 31, 2022
Due: February 21, 2022 by the end of day (11:59 pm CST).
Grouping: To be developed by a group.
Note: This instruction is based on C/C++. The Python version is available here.

Background

You will be writing a simple and secure communication protocol using UDP client and server. The program will build a UDP connection between two hosts and exchange encryption keys. The client will then send an encrypted message to the server. The server will decrypt the message and reply with the timestamp when it receives the message. You also need to compute the round-trip-time (RTT) of your message. More background information about public key encryption and socket programming is provided in the "Helpful Links" section at the end of this document.

Problem:

Part 1: UDP Practice

In the first part of this assignment, you are asked to build a simple UDP server and client where the server can successfully 1) establish the connection with the client, and 2) send a string (e.g., "Hello World") to the client. The finished code for Part 1 can also be used for Part 2 of this assignment.

We have provided an optional starter skeleton code to get you started on the right track. The starter code files (i.e., udpserver.c/.cpp and udpclient.c/.cpp) can be downloaded from here. Please refer to the "Running the programs on student machines" subsection for additional details about how to test your program on the student machines.

Part 2: Simple Secure UDP Program

Write a simple UDP client that takes in:
Also write a simple UDP server that takes in:
The library pg1lib.h (provided) contains the following methods:

/* Generate and return an encryption key
* (won't generate a new one if one exists already)
* return: this host's encryption key
*/
char* getPubKey();

/* Encrypt a message with peer's encryption key
* char *message: plaintext message to encrypt
* char *pubkey: peer's encryption key (formatted as output to getPubKey())
* return: base64 encoded ciphertext
*/
char* encrypt(char *message, char *pubkey);

/* Decrypt a message with this host's private key
* char *cipher: base64 encoded ciphertext
* return: decrypted plaintext message
*/
char* decrypt(char *cipher);

/* Calculate the checksum for the input data
* char *data: the null terminated data to process
* return: the checksum as an unsigned long
*/
unsigned long checksum(char *data);

Note: You do not need to implement the encryption/decryption and checksum functions listed above, as they are provided in the file pg1lib.h. You can download it from here. Two libraries must be linked: -lcrypto and -lz when you compile the pg1lib.h. If you are not familiar with public key cryptography, please refer to the links provided in the "Helpful Links" section.

The following protocol is to be implemented in your assignment:
  1. The client reads the host name, port number, and the message to be sent from the user input.
  2. The client generates a public key using char* getPubKey(), connects to the server, and sends it its public key.
  3. The server generates its own public key (also using char* getPubKey()), encrypts it using the client's public key and the method char* encrypt(char *message, char *pubkey), and sends the encrypted key as a response back to the client.
  4. The client decrypts the server's public key (char* decrypt(char *cipher)). It then calculates a checksum for the message (using unsigned long checksum(char *data)), and prints the checksum to the screen. It then encrypts the message using the server's public key ( char* encrypt(char *message, char *pubkey)). The client then sends both the encrypted message and the checksum to the server. (The checksum does not need to be encrypted as it cannot be used to reconstruct the original message.) Hint: The checksum is an unsigned long, and you will need to take into account endianness to transmit it correctly.
  5. The server receives the encrypted message as well as the checksum. It decrypts the message (using char* decrypt(char *cipher)), and prints both the message and the received checksum to the screen. Then it calculates the checksum with unsigned long checksum(char *data) from the decrypted message, prints it, and compares it with the received checksum. If the checksum matches, the server sends a confirmation to the client (e.g., an integer of value 1). If the checksum does not match, the server reports an error message, and acknowledges the client (e.g., a long int of value 0).
  6. The client receives the response message from the server, and calculates the round-trip-time (RTT), in microseconds, from the time it sent the message to when it received a response. If the response message confirms the server has received the message without errors (e.g., an integer of value 1), print the RTT to the screen; otherwise, report an error message.
Note: a suggested buffer size is 1024 characters in this assignment. DO NOT output any debugging information, or other informational messages to the screen. Doing so will cost you points!

Running the programs on student machines

You need to run your program using a random command line string. For example:

Server
[netid@is-student02 ~] $ ./udpserver [port]

Client
[netid@is-student00 ~] $ ./udpclient [hostname] [port] [test message]

Note: The client and server should be executed on different student machines (e.g., if the server is running on student 00, then the client should be tested on student 01/02/03). You may use the port numbers assigned to any of your group members to test your code (refer to appendix A).

Demo

Submission

Create a README file that contains a complete listing / explanation of what files are present in the directory and the instructions to compile and run your code (e.g., give a command line example to test your code with a sample file or random string).

Upload a gzipped tar file containing your .c or .cpp files, pg1lib.h, and your README file to the corresponding assignment on Canvas. One submission per group is sufficient. Your source code files must contain the name and netid of each group member or it will not be graded.

Note that you are encouraged to submit a Makefile for your code. If you do not submit one, please make sure to include the instructions on how to compile your code in your README file.

Your code will be evaluated on the student 00/01/02/03 machines based on the following evaluation rubric.

Evaluation Rubric (100 pts)

The points for the assignment are as follows:

Helpful Links

*Socket Programming in Linux : Beej's Guide to Network Programming and UDP Socket Example
*Public-key Cryptography : Public Key and Private Keys and Wikipedia Link


Appendix

Use the port number corresponding to your name in the appendix below.

Table 1. Port Assignments
UDP Port to UseName
41001 Canty, Angel
41002 Guo, Jerry
41003 Lee, Ivy
41004 Shamim, Iman
41005 Shi, Tiancheng
41006 Shuaibi, Alaa
41007 Torres, Michael
41008 Xiao, Justin
41009 Cui, Cilia
41010 Donelson, Curt
41011 Fang, Hongli
41012 He, Richard
41013 He, Xiang
41014 Huang, Chung-An
41015 Huang, Houshuo
41016 Jia, Bo
41017 Jia, Hao
41018 Jiang, Yuxuan
41019 Li, Chang
41020 Li, Ziheng
41021 Liu, Amelia
41022 Liu, River
41023 Wang, Jingwei
41024 Wang, Weiyu
41025 Wang, Xiuyuan
41026 Wang, Zeyu
41027 Xia, Yilin
41028 Xu, Yuting
41029 Xu, Zhizhou
41030 Yang, Qinwen
41031 Zhang, Boyu
41032 Zhang, Jingfang
41033 Zhang, Yunjia
41034 Zhang, Zheng
41035 Zheng, Shaojun