The Lizard Lords are displeased. The previously developed method of communication via TCP has been breached by humans and messages between Lizards have been intercepted. The Lizard Lords have decided they need a secure way to transmit messages between secret Lizard agents. This is your last chance to be spared the guillotine. You have been tasked with the development of a prototype for a secure communication channel that cannot be broken (not until quantum computers come along?) to demonstrate to the powers that be how humans may be stopped from making any use of intercepted messages.
The aim of this exercise is to familiarize you with asymmetrical encryption. In an asymmetric key encryption scheme, anyone can encrypt messages using the public key of the receiver, but only the receiver can decrypt because only they have access to the private key which is used to unroll the encryption. If the private key of some communication endpoint is obtained, any message pointed towards that endpoint can be decrypted if the public-private key algorithm is known.
To complete this exercise, you will be downloading the provided code skeletons and making use of the OpenSSL APIs to create public and private RSA keys in one process A. This process A shall communicate with a second process B via named pipes. Process A shall send its public key to process B using the pipe. Process B then encrypts a message taken via STDIN using this key and sends it back to the first process using another pipe. Then process A decrypts this message and displays it.
- Use this website to generate RSA keys of size 2048 bits.
- Save the public key generated into a text file “publicKey.txt” and private key in another text file “privateKey.txt’.
- Take a screenshot of both the files containing the RSA keys side by side.
- Create a named pipe “pipeEx9” using the following command.
$ mkfifo pipeEx9
- In “cpp”, read the public and a private key from the text files and display the generated keys to the screen. Make use of the helper functions to read the keys. Then send its public key using the named pipe to the second program described in step 6.
- In “cpp”, read the public key of the receiver using the named pipe and display it to the screen.
- cpp will take in a string message via STDIN and print it to the console after encryption. After the message is encrypted in sender.cpp, this message will be sent to receiver.cpp via the pipeEx9 created in step 4.
- cpp will print the received encrypted message, decrypt it and print the decrypted message which should be the same as the initial message passed via STDIN to sender.cpp.
- Take a screenshot of the programs running side by side which should look like the picture below.
Three pre-implemented helper functions have been provided along with the templates. You can use these to assist in your coding or implement your own functions for reading and converting the keys.
- char* readKey(string fileName) – reads the key from the text file and stores it in a char pointer
- RSA* convertPrivateKeyToRSA(FILE* fp)- converts private key from opened file (FILE*) to RSA format
- RSA* convertPublicKeyToRSA(FILE* fp)- converts public key from opened file (FILE*) to RSA format
You may need to read a char* as a FILE* to use the above functions, this can be done using POSIX string streams. https://www.gnu.org/software/libc/manual/html_node/String–Streams.html
When compiling with OpenSSL, include the necessary libraries as shown in the following command.
$ g++ source_code.cpp -lssl -lcrypto -o source_codeS