This is a read-only archive. Find the latest Linux articles, documentation, and answers at the new Linux.com!

Linux.com

Feature

CLI magic: The keys to GnuPG

By Joe Barr on June 28, 2004 (8:00:00 AM)

Share    Print    Comments   

The GNU Privacy Guard (a.k.a. GnuPG, or simply gpg) is a free software implementation of Philip Zimmermann's notorious, powerful, and popular program PGP (Pretty Good Privacy). GnuPG is cooler than a secret decoder ring, so get out of that GUI recliner for a few minutes and come learn a couple of secret spy crypto command line tricks.
GnuPG has two main uses. The first is to encrypt data to ensure its privacy. The second is to "sign" data so that others can determine it is authentic and unmodified.

GnuPG is widely used, so it is included as standard fare in most modern distributions. If it didn't come with yours, you can download source code or binary versions from the GnuPG Web site.

Gimme two keys and hold the mayo

GnuPG uses two keys: a public key for encrypting data, and a private (secret) key for decrypting it. Anyone who has a copy of your public key can use it to encrypt data that only you can read. Nobody can read your mail -- at least not very easily -- with your public key; your private key is required for that.

We'll get started by generating a key-pair. The command to do so is:

gpg --gen-key

That generates the following response:

gpg (GnuPG) 1.2.4; Copyright (C) 2003 Free Software Foundation, Inc.
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions. See the file COPYING for details.

Please select what kind of key you want:
   (1) DSA and ElGamal (default)
   (2) DSA (sign only)
   (4) RSA (sign only)
Your selection?

Select option (1), the default. It is suitable for most users. Do not ask why option (3) -- which creates an ElGamal type key not suitable for making signatures -- is not shown, and I won't be forced to kill you.

Next, we set the key size:

DSA keypair will have 1024 bits.
About to generate a new ELG-E keypair.
      minimum keysize is 768 bits
      default keysize is 1024 bits
   highest suggested keysize is 2048 bits
What keysize do you want? (1024)

Just press Enter for the default 1024 bits. If you need more security than that affords, you shouldn't be reading a tips for noobies resource for your security planning. And remember, no matter what size you choose, there is no unbreakable cipher. The best you can do is buy time.

Speaking of time, the next question is how long we want this key-pair to be good for.

Please specify how long the key should be valid.
      0 = key does not expire
     <n> = key expires in n days
    <n>w = key expires in n weeks
    <n>m = key expires in n months
    <n>y = key expires in n years
Key is valid for? (0)

Once more, choose the default for "does not expire."

Confirm your choice by entering y when asked, then we can move on to telling GnuPG who we are.

The next prompt states:

You need a User-ID to identify your key; the software constructs the user id
from Real Name, Comment and Email Address in this form:
   "Heinrich Heine (Der Dichter) <heinrichh@duesseldorf.de>"

Real name:

First of all, ignore that line describing what the final result looks like. If you don't, you'll never enter the data correctly. For "Real Name" enter your name as it normally appears in your email. In my case, that would simply be "Joe Barr."

Next, enter your email address, but do not enclose it in angle brackets as shown in the example of the finished identification. Just use "joe@pjprimer.com" or whatever your email address happens to be.

Finally, press Enter when asked for a comment. Your finished product will then be displayed, and it should be in the form shown in the beginning. You can change any of the items that are used to build it, and then you can move on to the passphrase.

The passphrase is critical. Think about it before entering something. It needs to be a word or phrase that someone who knows you can't easily guess, but it also needs to be easy for you to remember and to enter. It's needed whenever you sign something, like an outgoing email, or when you encrypt or decrypt data.

Some email clients -- like Evolution -- allow you to enter the passphrase only once per session. That can save you a lot of keystrokes. So can not selecting the first paragraph of Ulysses as your passphrase. Strike a good balance and make it something you can easily remember. It's not as easy to come up with a good passphrase as you might think, but it's important that you do so. If someone comes across your private key, your passphrase is the only thing standing between them and all of your secrets. Guard it carefully. If possible, select one you won't have to write down.

After you enter and reenter the passphrase, the following will appear:

We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
++++++++++++++++++++++++++++++.+++++++++++++++.++++++++++...++++++++++
++++++++++.+++++++++++++++..++++++++++++++++++++++++++++++++++++++++++
+++.......+++++
public and secret key created and signed.
key marked as ultimately trusted.

pub 1024D/FFFFFFFF 2004-06-22 Joe Barr <joe@pjprimer.com>
     Key fingerprint = 1111 2222 3333 4444 5555 6666 7777 8888 9999
sub 1024g/00000000 2004-06-22

You've now generated your first key-pair. That leaves just one more thing to do: You need to create a revocation certificate.

Revoke this!

It's not uncommon for people to lose passphrases or secret keys. When that happens -- or if you just want to cancel an existing public key for any reason -- you can use a revocation certificate to cancel it. Of course, if you've lost your passphrase or secret keys, you won't be able to create the certificate, so that's why it's a good idea to do it now.

To generate the certificate -- and to output it in printable form to a file called revoke.asc -- enter the following command. The key-id portion of the command can be be either the public key ID (FFFFFFFF in our example above) or a large enough chunk of the identification line associated with it to uniquely distinguish it from any other keys on the key-ring:

gpg --output revoke.asc --gen-revoke key-id

GnuPG responds by asking if you want to create the certificate, and if you say yes, it asks why:

Please select the reason for the revocation:
   0 = No reason specified
   1 = Key has been compromised
   2 = Key is superseded
   3 = Key is no longer used
   Q = Cancel
(Probably you want to select 1 here)
Your decision?

As always, select the recommended option. When asked for the optional description, I usually enter something simple like "Revocation certificate for identification line." Confirm that all is well and then it's time to enter your passphrase. That done, GnuPG says:

ASCII armored output forced.
Revocation certificate created.

Please move it to a medium which you can hide away; if Mallory gets
access to this certificate he can use it to make your key unusable.
It is smart to print this certificate and store it away, just in case
your media become unreadable. But have some caution: The print system of
your machine might store the data and make it available to others!

Heed the warning and keep both hardcopy and digital version of the certificate in a secure location.

That's all for this time. In a future column we'll revisit GnuPG and learn what you can do with it once you have a key-pair.

Share    Print    Comments   

Comments

on CLI magic: The keys to GnuPG

Note: Comments are owned by the poster. We are not responsible for their content.

Key ID size

Posted by: Joe Barr on June 29, 2004 10:43 PM
(Note: I am posting this comment from a reader who sent it by email instead of hassle with the registration requirement.)




Just wanted to point out that with all recent versions of gpg (those creating v4 keys, to be exact), the key ID is the lowest 64 bits of the
fingerprint. So in the example, your key ID would be hex 88889999.

#

Re:Key ID size

Posted by: Administrator on June 30, 2004 09:33 AM
Great column. GPG runs easily from the command line & if your email client has good integration, you'll rarely need to do much with it. But for those who need a GUI crutch, <A HREF="http://www.gnupg.org/(en)/related_software/gpa/index.html" title="gnupg.org">GPA</a gnupg.org> does nicely.

When using PGP, I used to just go for the highest suggested keysize possible. I now chuckle when I get signed email from people who go higher than that still. It is often wasted space + computation time. The GPG handbook says:

Key size nevertheless affects encryption and decryption speed since the cost of these algorithms is exponential in the size of the key. Larger keys also take more time to generate and take more space to store. Ultimately, there are diminishing returns on the extra security a large key provides you. After all, if the key is large enough to resist a brute-force attack, an eavesdropper will merely switch to some other method for obtaining your plaintext data. Examples of other methods include robbing your home or office and mugging you. 1024 bits is thus the recommended key size. If you genuinely need a larger key size then you probably already know this and should be consulting an expert in data security.

I would suggest NOT keeping your key on the harddrive. Instead, keep it on<nobr> <wbr></nobr>/mnt/floppy or a USB stick. Added bonus: You'll be able to use GPG from anywhere. For the TRULY paranoid, use the <A HREF="http://tinfoilhat.shmoo.com/" title="shmoo.com">Tinfoil Hat Linux</a shmoo.com> bootable distribution on untrusted machines.

The passphrase is often the weak link. It is difficult to get a passphrase with the same security or better as your key. See <A HREF="http://www.stack.nl/~galactus/remailers/passphrase-faq.html" title="stack.nl">the passphrase FAQ</a stack.nl>

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya