Cryptography on the 'Net

Books that cover this material well are

1. Background

2. Toolbox

aside 1: using ssh with public/private keys


 Here's the recipe, as of OpenSSH_3.6.1p2, SSH protocols 1.5/2.0, OpenSSL 0x0090701f
 for logging in between two computers (call them "laptop.m.edu" and "remote.m.edu")
 without typing a password...

 see http://www.openssh.com/manual.html (Google "man openssh")

 First we create public/private keys on laptop.m.edu,
 which will be tied to the user and host given in 
 in the shell environment variables.

 on laptop.m.edu :
  $ echo creating key for $LOGNAME@$HOSTNAME
    who@laptop.m.edu
  $ mkdir ~/.ssh/
  $ cd ~/.ssh/
  $ ssh-keygen -t rsa
    Generating public/private rsa key pair.
    Enter file in which to save the key (/laptop/who/.ssh/id_rsa): 
    Enter passphrase (empty for no passphrase): 
    Enter same passphrase again: 
    Your identification has been saved in /laptop/who/.ssh/id_rsa.
    Your public key has been saved in /laptop/who/.ssh/id_rsa.pub.
    The key fingerprint is:
    7e:c6:f9:db:fc:38:4d:e9:73:82:e6:92:7b:59:c0:bd who@laptop.m.edu

 If a passphrase is given, then that phrase must be entered
 to gain access to the private key; this is less convenient
 but safer.  Be clear that without a passphrase, 
 anyone who can gain access to id_rsa can log into your 
 remote accounts.

 Next, copy the public part of this into the file authorized_keys.
 If this is the only key you'll use, you can just do

  $ cp id_rsa.pub authorized_keys

 Finally, copy that authorized_keys file to the remote machine that
 you want to be able to log in to.

  $ scp authorized_keys who@remote.m.edu:.ssh/authorized_keys

 That's it.  Now you should be able to do
 
  who@laptop$ ssh remote.m.edu
  who@remote$ 

 without typing a password (!)

 Another way to do this to to encode your private key with a password
 but use an "agent" program to store it during your login session.
 With this approach, you need to type the passphrase once after
 you login to your laptop - then the running agent knows how to 
 unlock your private key when it needs to.

 What's going on in any of these systems 
 is that ssh uses your private key (in laptop:.ssh/id_rsa)
 to craft a message and send it to the remote machine.  There it uses
 the corresponding public key in authorized_keys to see if you can get in.
 If it doesn't find one, then it asks for a password.
 
 The files look like this

 $ cat id_rsa
 -----BEGIN RSA PRIVATE KEY-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.m.edu

aside 2 - GnuPG

For encrypting email and for command line use, I tend to use gpg,the Gnu Privacy Guard, successor to pgp (Pretty Good Privacy). Besides implementing the various algorithms, it also maintains a database of keys in ~user/.gnupg and can also fetch public keys from standard servers. For example, see http://www.keyserver.net/en/ or subkeys.pgp.net My email (Thunderbird / Mozilla) GUI client uses the command line "gpg" to handle encryption. See http://www.gnupg.org/(en)/documentation/howtos.html and http://www.gnupg.org/gph/en/manual.html Here's how to do a few things from the command line. * generating a key : gpg --gen-key and then answer all the questions. Sample: in "milo" account passphrase = "silk, velvet" * listing keys gpg --list-keys * edit your key (needs passphrase) gpg --edit-key UID * fetching keys from remote server gpg --search mahoney@marlboro.edu (default server on cs is subkeys.pgp.net) see for example www.keyserver.net/en/ * uploading to a server gpg --send-keys * exporting public keys gpg --export UID > public.txt * encrypting and signing a file you need the public key of the recipient My email client (Mozilla Thunderbird) uses gpg to do things, so much of this can happen through a GUI.

3. Abstract Protocols

4. SSH - Application level encryption

5. SSL/TSL - Socket level encryption


Trying this out

Choose at least one of the following cryptographic tasks.
  1. Symmetric Encryption:
    Use any utility you like (openssl, PGP, GnuPG, ...) to encode and decode a text file with a random symmetric 128-bit key of your choice using the RC5 cipher. You could use the command line utility openssl; "man openssl" and "man enc" will give you notes on that utility - or download and install a tool like GnuPG. (http://www.gnupg.org/). Verify that your cipher text is correct by decoding it.
  2. Public/Private Keys:
    Create a public/private RSA key pair for yourself, and use them to create a signed MAC of these lecture notes, that is, a digest (say SHA-1) of the notes, encrypted with your public key. GnuPG is probably the easiest tool to use for this, though I haven't look hard for others.
  3. Message Digests
    Most serious software packages available for download also have digest checks, to ensure that you have the real version. For example, the .md5 files in ftp://ftp.openssl.org/source/. Download one of these packages and verify that the digest matches the archive. Verify that if you uncompress it, modify the source a tiny bit, and recompress it, that the signature no longer matches. From the comman line on bob, "md5sum" or "openssl" can be used to do so; type "man md5sum" for details. Unpack the source, modify one character, recompress it, find the new digest, and verify that it no longer matches the original. How much did the digest change?
  4. Playing with the math.
    Create your own examples with small numbers of either the Diffie-Hellman or RSA algorithm, along the lines of what's in the notes up above. Work your way through the steps, and do out all the calculations either by hand or with a short program in a language of your choice.

Jim Mahoney <mahoney@marlboro.edu>
Last modified: Nov 7 2004