CTS 2311 (Unix/Linux Security) Project #5
Using GnuPG and Crypto Tools


Due: by the start of class on the date shown on the syllabus


For this project you will practice using some of the crypto tools we covered in class, including SSL / TLS, GnuPG (gpg/pgp), OpenSSL, and other tools.


  1. Using gpg (or “Gnupg”) and MD5 to verify downloaded software:
    1. Download the latest gnupg (gpg) signed tarball (for example, “gnupg-2.1.9.tar.bz2”) and the matching GPG signature file (in this case, “gnupg-2.1.9.tar.bz2.sig”).
    2. Verify the signature.  This will require importing the appropriate gpg public key into your keyringWhat was the Key ID?  What exact command line did you use to import that key?  What was the exact command line you used to verify the file's signature, and what was the resulting output?
    3. Verify the SHA1 checksum.  For this software, you can find that at Integrity Check - GnuPG.org.  One way to verify the sum is to create the file gnupg-2.0.19.tar.bz2.sha1 with the sum found on this web page, using the format described in the sha1sum(1) man page: the sum, two spaces (or space and asterisk), and the file name.  What exact command(s) did you use, and what was the resulting output?
    4. Prepend a line of junk to the tarball:
      cp tarball tarball-original
      echo 'yikes!' >> tarball
    5. Verify the SHA1 checksum and the gpg signature again, using the same command lines as before.  What were the results this time?

      The SHA1 checksum should fail but the gpg verify may succeed!  This is because the signed tarball is self-contained; changes to other files won't have any effect on it.  What would have happened if gnupg had used a detatched signature (a tiny *.sig file, and a separate tarball)?

      It is harder if you want to make a change to the signed tarball.  This is because of a “feature” of gpg: signed files have delimiters at the start and end of the actual signed stuff.  Anything that appears before or after that in the file is ignored, so appending some garbage to the end won't matter.  (This was designed to make it easy to save a signed file sent in the body of an email message, so gpg ignores the mail headers and signature block.)

      If you want to make an error in a signed binary file, you could tail the original file, deleting the beginning 10 lines or so.  Or you could use some binary file editor to make any change to the middle.  See wikipedia.org/wiki/Comparison_of_hex_editors for a list of binary/hex editors you could use.  An easy to use console editor is called hexedit.  (You just use the arrow keys to move over the part to change and start typing.  When done hit control-X to save and quit.)  Some GUI ones are bundled with KDE and gnome.

      Now if you verify with gpg you should see the error message it produces.

    6. Examine the yum repository configuration files on your host.  Which repos (if any) are configured to required gpg signatures for packages?  Which ones (if any) don't require gpg signatures?  Where does your system store the public gpg keys needed for your yum repositories?
  2. Using md5sum, gpg to encrypt and sign a file:
    1. Create a short text file to encrypt, with the following exact text:
      echo 'Hello from Unix/Linux Security class.' > secret.txt
      echo 'Secret text file for crypto project, CTS-2311' >> secret.txt
    2. Generate an MD5 checksum for secret.txt in the file secret.txt.md5 (the whole output or running md5sum).  Repeat with sha1sum, saving the checksum in the file secret.txt.sha1What were the two checksums?
    3. Next, encrypt the file using gpg's symmetric encryption, saving the result as an text file.  Rename the resulting file as “secret.txt-sym.asc”.  Use the password “secret”.  What was the exact command line you used?  What is the default symmetric encryption algorithm used?  What would be the command line option to use AES encryption with gpg instead of the default algorithm?
    4. Add your instructor's public gpg key to your keyring.  (Hint: Look for my email address.)  What is the key ID?  Where did you obtain this key from?
    5. Using your instructor's gpg key, encrypt the file “secret.txt”, in text (ASCII) format, with the name “secret.txt.gpg.asc”.  Did that work?  If so, what was the exact command line you used to do this?  If not, what is the most likely reason?
    6. Now generate a new gpg key for yourself.  Create a key of type “DSA and Elgamal”, with the default key length, with an expiration in 3 months, with your name, Hawkmail email address, and the comment “CTS-2311 project - do not use”.  (This will be a temporary key, just used for this project, and you don't want others using it!)  Select any passphrase you wish for this key.  What is the key ID and fingerprint for your new key?  Finally, export your (public) key as a text file named “your name.key”.
    7. Using your new key, digitally sign “secret.txt”, using a plaintext (ASCII), detached signature in the file “secret.txt.sig”.  What was the exact command line used?
    8. Verify the signature and file.  What is the exact command line used?  Add a line of text to the end of “secret.txt” (say with “echo oops >>secret.txt”), and verify again.  What is the output this time?
    9. Include attachments for the following files when sending this assignment via email to your instructor:
      • secret.txt
      • secret.txt.md5
      • secret.txt.sha1
      • secret.txt-sym.asc
      • secret.txt.gpg.asc
      • secret.txt.sig
      • your name.key
  3. Using OpenSSL:
    1. Use OpenSSL to generate an MD5 hash of the word “secret”, suitable for use in the /etc/shadow file as a password.  (That is, so you could copy the output of the command, and paste it into the password field of /etc/shadow, and it should work, but don't do that.)  What is the exact command line used?  What is the password hash generated?
    2. While OpenSSL supports SHA512, it cannot use it to generate passwords.  Until it does, you can use the Python script sha512passwd to do so:
      #!/bin/sh -
      # This was found at  https://serverfault.com/questions/330069
      # ("how-to-create-an-sha-512-hashed-password-for-shadow")
      if [ $# = 0 ]
      then echo "Usage: ${0##*/} <password>" >&2
           exit 1
      printf '%s' "$*" | python -c "\
      import crypt,random,string
      print crypt.crypt(raw_input(), '\$6\$' + \
      ''.join([random.choice(string.ascii_letters + string.digits) \
      for _ in range(16)]))"

      Using that script, generate a SHA512 hash of the word “secret”, suitable for use in the /etc/shadow file as a password.  What is the password hash generated?


Read the man pages for the commands (and file formats) used, and don't forget to search Internet resources on how to use these tools.  There are some “cook-book” resources on our class web page at #SecTools you should find useful, and additional examples in the class lecture notes.

To be turned in:

A description of each task you performed and the answers to the questions asked above, as well as the various files you created in part 2.  You can send as email to (preferred).  If email is a problem for some reason, you may turn in a hard-copy.  In this case the pages should be readable, dated, and stapled together.  Your name should appear on the first page. 

Don't turn in your whole journal, just a copy of the relevant sections.  It is common in fact to keep the journal as a text file on the system (with a paper backup of course).

Please see your syllabus for more information about submitting projects.