20-CS-5153 Network Security Spring 2017
Lab 2

Secret Key, Public Key, Hash Algorithms, IPSec, Kerberos, Authentication, more

Adding Authentication and Encryption

Due: Feburary 13, 2017 (submit instructions: here)

    To add encryption and decryption routines to the solution of Lab 1 for encrypted communication with the monitor.

Connect to the monitor on port 8180 of helios.ececs.uc.edu for this assignment.
Lab Problem:
Write C++ or Java code to support encrypted communication with the Monitor. This code should be added to the code you wrote for Lab 1. The protocol for encrypted transmissions is as follows:
  • Get a key. Using Diffie-Hellman, grab p and g from this file which was generated using this code. In case of difficulty,



    Big numbers, huh?

    From Michal Kouril, the numbers above in hex are:



  • Generate and send your public key to the monitor. Do this when sending the "IDENT" command. In this case the arguments of the "IDENT" command are your identity first then the public key. Here is the protocol from HW2 for reference.

    RESULT: IDENT <MonitorKey> Indicates that the Monitor is demanding that the next Command from the Participant be IDENT and that encryption is enabled. The Monitor sends its Diffie-Hellman public key as a string of characters in <MonitorKey>. The participant should convert this string to a BigInteger, radix 32, to make use of it properly.

  • The result returned by the monitor will be IDENT <MonitorKey> as specified in the table above. So, if your message parser sees an IDENT followed by an argument it should use the argument to generate a shared secret by converting to a BigInteger, radix 32, and applying Diffie-Hellman. This secret will be used to drive your encryption and decryption algorithms. See the cryptography section of the protocol document for details.
The particular cryptosystem the monitor expects you to use is described below. It uses the Secure Hash Algorithm (SHA-1) described in this article to generate message digests. The Java language has SHA-1 built in.

The cryptosystem is set up as follows: split the bits of the shared secret into two halves: a left key half and a right key half (left is lower order bytes).

To encrypt, first add a "guard" byte of value 42. Then, for each block of plaintext, divide the block into a left and right half. Find the message digest of the concatenation of the left plaintext half and the left key half. XOR the digest with the right plaintext half. This produces the right ciphertext half. Find the message digest of the ciphertext right half concatenated with the key right half. XOR the digest with the plaintext left half. This gives the ciphertext left half. Output the ciphertext left half then the ciphertext right half.

To decrypt, strip the guard byte. For each ciphertext block, split the block into a left half and a right half. Find the message digest of the ciphertext right half concatenated with the key right half. XOR the result with the ciphertext left half to obtain the plaintext left half. Find the message digest of the plaintext left half and the key left half. XOR the result with the ciphertext right half to get the plaintext right half. The monitor recognizes block sizes of 40 bytes. Messages may have to be padded to get this blocksize.

Sample (incomplete) code is given in Karn.java. Use of the class defined in this file is illustrated by KarnTestServer.java and KarnTestClient.java. Use as follows in Unix:

    java KarnTestServer &
    java KarnTestClient "The quick brown fox jumped over the lazy dog's back"
You will need Karn.class to do this until you have built your own Karn class. You will also need DiffieHellmanExchange.java, DHKey (you may have to rename it to DHKey if you save the link - sometimes it saves as DHKey.bin), and PlantDHKey.java. Compile PlantDHKey.java first, then DiffieHellman.java, then the Karn Client and the Karn Server.