Spring 2021 CSE30264 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: February 15, 2021
Due: March 1, 2021 by the end of day (11:59 pm Eastern).
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:

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 /escnfs/courses/sp21-cse-30264.01/public/program1/C/pg1lib.h. You can also download it from here. Feel free to copy pg1lib.h to your own directory. 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 generates a public key using char* getPubKey(), connects to the server, and sends it its public key.
  2. 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.
  3. The client decrypts the server's public key (char* decrypt(char *cipher)). It then reads a file (or string) into a temporary buffer (a suggested buffer size is 4096 characters in this assignment), 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.
  4. The server receives the encrypted message as well as the checksum. It first records the local timestamp when it received the message, and decrypts the message (using char* decrypt(char *cipher)). Next, the server prints the date and time, 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 the timestamp back to the client. If the checksum does not match, the server reports an error message, and acknowledges the client (e.g., a long int of value 0).
  5. The client receives the response message from the server. If the message is a valid timestamp, print the date and time; otherwise, report an error message. It also calculates and prints the round-trip-time (RTT), in microseconds, from the time it sent the message to when it received a response.
DO NOT output any debugging information, or other informational messages to the screen. Doing so will cost you points!

There are three test files (File1.txt, File2.txt, File3.txt) in: /escnfs/courses/sp21-cse-30264.01/public/program1/C/. You can also download them from here.
You need to run your program using these test files and a random command line string. For example:

Server
[netid@student02 ~] $ ./udpserver 41100

Client
[netid@student00 ~] $ ./udpclient student02.cse.nd.edu 41100 File1.txt
[netid@student00 ~] $ ./udpclient student02.cse.nd.edu 41100 "This is a test"

Note: The client and server should be executed on different student machines (e.g., if the server is running on student 02, then the client should be tested on student 00/05/06). 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 your .c or .cpp files, pg1lib.h, and your README file to your dropbox (i.e., /escnfs/courses/sp21-cse-30264.01/dropbox/yournetid/program1/ ). Only one group member needs to submit the work for each group. 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 one of the student 00/02/05/06 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 Joshua Agron
41002 Matthew Ahrens
41003 Emma Ascolese
41004 Julia Blanchard
41005 Brian Cariddi
41006 Maria Carroll
41007 Mark Cheng
41008 Clara Cheong
41009 Megha Devaraj
41010 Theodore Donegan
41011 Ahmed Farag
41012 William Gentry
41013 John Gordley
41014 Emily Grow
41015 Alejandro Jose Gutierrez Elizondo
41016 Jake Hracho
41017 Melka Konshie
41018 Tyler Krasny
41019 Zachary Kreft
41020 Jonathan David Lamptey
41021 Sabin Litchfield
41022 Nicholas Locascio
41023 Keegan MacDonell
41024 John Masciopinto
41025 Jacob Mazur
41026 Mary McCann
41027 Daniel McFarlane
41028 Evan Mercurio
41029 Conor Murphy
41030 Peter Oliver
41031 Ryan Pairitz
41032 Thomas Renfrew
41033 John Rundle
41034 Matthew Shan
41035 Luke Siela
41036 Dane Williams