Learn how to protect your e-mail and files you want to keep private using Pretty Good Privacy (PGP) encryption.
Early last month I promised to get back to the topic of enhancing your digital security and privacy with PGP or its Free Software derivative, GnuPG. Both use a kind of cryptography referred to as “public-key” or “asymmetric.” With PGP or GnuPG, you gain the capability to encrypt or sign data in such a way that decrypting it is impractically difficult for any eavesdroppers, and altering data you’ve cryptographically signed without being detected is virtually impossible.
We’re all used to dealing with some sort of encryption in our everyday net dealings. SSL, for instance, is used to secure Internet traffic between your computer’s e-mail or Web client and a remote server. From our perspective as end users, this kind of encryption is a very passive process. We make sure to stick an “s” at the end of “http” when we type in a URL, or we point our e-mail client at port 993 or 995 of an IMAP or POP server when we’re setting it up, and then we forget all about it. If the browser shows a little padlock icon somewhere, we decide our information is safe from eavesdroppers on the network.
Though it also uses public-key cryptography, SSL as we experience it in a Web browser is based on a model of authentication that relies heavily on third-parties, referred to as “certification authorities (CAs),” that effectively vouch for the authenticity of a Web site’s cryptographic credentials. SSL browsing is transparent to us largely because browser programmers make a few assumptions on our behalf, including how much trust we should place in the CA that signed a Web site’s certificate.
PGP and GnuPG provide a much less passive experience, and it requires a little explanation and some setup before we can get into using it. We’re going to use the Mac OS X implementation of GnuPG to help with our explanation, and we’re going to do this in two parts. In this installment, we’ll cover the basics of setting up the cryptographic keys we’ll use to secure our data, and later we’ll deal with using GnuPG to encrypt and sign e-mail.
GnuPG Cryptography in a Nutshell
Before we jump into making keys and using them, it will help to offer a broad outline of how all the pieces relate to each other in GnuPG’s public-key scheme. GnuPG and PGP both use the OpenPGP protocol, so if you become familiar with the GnuPG and later decide you need some of the more advanced features provided by a commercial PGP offering, the concepts you pick up here will still apply.
The math involved in OpenPGP is more than we want to deal with, but the mechanics of daily use are easy to understand, if a little more involved than most of us are used to. In short, here are the basics:
- You first create a private key with a password only you know. You should keep this key safe, avoiding letting others have it. For maximum security, some people recommend storing the key on removable media, such as a USB thumbdrive. You should also assign a secure password to your key. Even if someone does get a copy of it, they can’t use it without the password.
- When you create your private key, GnuPG also generates a public key you distribute to others. Anyone can have a copy of this key without posing any risk to your privacy. Anyone who wants to send you encrypted messages needs to have a copy. It’s not uncommon to see people distribute their public keys via their personal Web pages, or through a public key server. The most secure method, however, is to deliver a copy of the public key by hand so people know it definitely came from you and not an impostor who somehow gained control of your server or uploaded a bogus key in your name to a keyserver.
These two keys are called a “keypair.” The keypair is used to perform three basic operations:
- You can encrypt data with GnuPG that’s meant only for you. Nobody can read it without having your private key and knowing the password for it. If you keep the file that represents your private key safe and use a strong password, it will be very hard — practically impossible — for anyone to decrypt your data.
- You can encrypt data with GnuPG that’s meant for someone else to decrypt. Each of you will use your individual private keys. If data between the two of you is intercepted, it’s useless without access to the recipient’s private key and knowledge of its password.
- You can sign data. When you sign an e-mail message or a file, it becomes impossible for that file to be altered without GnuPG being able to detect the alteration. Software companies and projects often use GnuPG signing when they distribute updates so their customers and users can be absolutely sure that the software they’re receiving is authentic … not potentially malicious software uploaded to a compromised server.
MacGPG, which provides a GUI for GnuPG, is available as a no-cost download. Its and its underlying software, GNU Privacy Guard, are Free Software provided under the GNU General Public License (GPL), just like Linux and Samba.
We’ll save an in-depth tutorial on using Mac GPG for e-mail for later, because covering both how GnuPG works and setting it up for mail would slow us down quite a bit, but you will need MacGPG to get through this week’s column.
At the MacGPG site, you’ll see a list of files. You should download the following:
- GNU Privacy Guard (make sure to download the version listed for your version of OS X, there are downloads for OS X 10.1, 10.2, 10.3, and 10.4+)
- GPG Keychain Access
You can optionally download these packages, but we won’t be doing anything with them this week:
If you want to use GPG to secure e-mail you send using Apple’s Mail.app, you’ll also want to download GPGMail, but we won’t use it until next time, and installing it now will just cause Mail.app to complain that GPG isn’t set up yet, so save installation for later.
You can install MacGPG by running the installer found in the “GnuPG Mac OS X” disk image you downloaded. MacGPG itself provides program files that run from the terminal.
You can install the GPG Keychain Access program, which is what you’ll be using to generate and manage cryptographic keys, by opening the “GPG Keychain Access” zip archive you downloaded and dragging the app file of the same name into your Applications folder.
Generating a Key with GPG Keychain Access
As I mentioned earlier, the root of GPG is the notion of a “key pair.” To encrypt or sign data with GPG, you have to have a public key you share with others and a private key, which has a password only you know. If you want to ensure maximum security and privacy, you should choose that password with the same seriousness you’d choose a password for the administrative or root account on a production server: Avoid words you could find in the dictionary, avoid clever misspellings (like “m1ke” instead of “mike,”) and use a mix of letters, numbers and symbols.
Before we can do anything with GPG, we have to have a key pair, and that’s where GPG Keychain Access fits in.
Go ahead and launch GPG Keychain Access by doubleclicking on its icon once you have it moved into your Applications folder. It will immediately present a warning that you don’t have “a private or secret key.” It will offer the option to either “Import,” “Quit,” or “Generate.” Click “Generate.”
Unless you set it to do otherwise, GPG Keychain Access provides an assistant to generate your keys. When you click “Generate,” that assistant will launch. Click “Continue.”
Next, it will ask what kind of key you want to generate. The default is “DSA and ElGamal,” which allows you to use your key to both encrypt and sign your data. Keep it set to the default and click “Continue.”
Next, it asks how large the key should be (in bytes). The default is 1024, which is fine. Click “Continue.”
Next, you’ll be asked for an Expiration Date. This setting is optional … though the key won’t stop working for purposes of decrypting or verifying data, you won’t be able to encrypt or sign with it once it has expired. In sensitive security settings, it’s not uncommon for there to be short lifespans for assorted keys and passcodes. In some military units, for instance, radio network signs and countersigns are retired in a matter of days. In less sensitive applications, it may not be as much of an issue. The GNU Privacy Handbook says this:
“There are two reasons why you may choose an expiration date. First, you may intend for the key to have a limited lifetime. For example, it is being used for an event such as a political campaign and will no longer be useful after the campaign is over. Another reason is that if you lose control of the key and do not have a revocation certificate with which to revoke the key, having an expiration date on the master key ensures that the key will eventually fall into disuse.”
Once you’ve decided on an expiration date (or decided to assign none at all,) click “Continue.”
Next, you’ll be presented with the personally identifying information to be embedded in your key. GPG Keychain Access pre-populates this form with information from your Mac address book:
- your name
- your e-mail address
- a comment
The comment can be used in a number of ways. Some people include a URL where more contact information may be found, or the username or i.d. they wish to associate with their key.
Finally, you need to pick a passphrase. As I noted earlier, it should be a fairly strong one using letters, numbers and symbols, avoiding dictionary words or even variations on dictionary words. If you’re at a loss for a good passphrase, the Mac Password Generator is free and offers several ways to generate strong passphrases.
Once you pick the passphrase, you’re given one last look at all the settings you picked for your key, and the keypair is generated. GPG Keychain Access will show a list of keys that will include the new key.
Now you’ve got a GnuPG keypair. You can use them to encrypt data, decrypt data others have sent to you, or sign data in such a way that the signed information can’t be altered without detection when checked with GnuPG.
You also need to share your public key with others. The best way to do this using Mac GnuPG is to use the GPG Keychain Access program to export a text version of your public key so you can distribute it to others, either via a printed copy, over a Web page only you can edit, or in whatever way you and the people using your key feel is adequately verifiable.
To get that text version of your public key, click the key you just created in the GPG Keychain Access window, click the “Export” button in the GPG Keychain Access toolbar, and pick a filename to export the public key data to. Open the file it produces and you’ll see the ASCII version of your public key. It’ll look something like this:
-----BEGIN PGP PUBLIC KEY BLOCK----- Version: GnuPG v1.4.8 (Darwin) mQGiBEdrcboRBAC/LI6bqRQlDCH3k7/08QKdHomZTAv1Ak/JLg+16BjwFCBqkMrf nlhXxtP6LcSM3+hyIZ501qrg2nG1Z1XrnW2P5tg4T9Ya17fjNVgCGsEks2LO1xF5 0xpj8vIZeoS6aJl/D7WfUfYgZuTZwHo+IoGDzzhgAee9A3yA28yGxuaSnwCg7vXZ YQ5B5Y4c6LLq84Oz3XHLg4kEAICTmtTiVci/IflYoWhr6KPUPxHucWSR+8vEbIna C/ogi3DgjD7813OGEblJWJF2pvdaptocDjT4leaxWJAmuPNGtcKDkMy/u/RVmFJ+ G+Eg/U8ute/9tYI1T5/OMvUdKks0TUriKS++A7JfmVrU9X8b666VyprUdqTnQdwj HHyPBACO1vo72DoZmgVZYkaVFF3gChWhKk/VJjOA5Nz3vpY5hCZXfFIpbz7jscAE 9herqLnCVfCeQ2pEuJKcIM4Uacgl/MykXhQqm6sieWYmyXVK9sr8WPxFTyi73xtN 3qpx8FrJgiqV4YIgRaGcBhI4066FsL/xZCZ0jmYY6ycgrsLJhrQiTWljaGFlbCBI YWxsIDxtcGhAcHVkZGluZ2Jvd2wub3JnPohgBBMRAgAgBQJHa3G6AhsjBgsJCAcD AgQVAggDBBYCAwECHgECF4AACgkQCtklesGxa3ihwwCgqh1ZXKug1e0MRxKctKQW t1VhIVAAn1fGy1CiZ0mVdNbvztw5ggovS6nTuQENBEdrcboQBACU3wZQYpgZ2gu6 aPusJ0AgnR2ZspVBOnVWlWmIghreOg5VDrXfDJ6M0uazbMytYackNRpiECeszFzG /w1YnHxTVocZzlsMpqdbrp81qcIFFl+xZNNSOT3ousAavR/4PsWTvPFfCTME7F5B lGBqJOTIywCut8oIE3RgehJHJTwD6wADBQP/XCkEmkTPoDD+/RRQUUfHJHJvsY3r +q8j4YnVk2xC0ZBH1DoTTG3/VUXCoAxhd60K11DaIoy9GNnSFjjuWsiLpPJSWlbR iFR14Kvick+9I/N3D7gJQ8C+ODQVGK1QB9fTOUxV5ZqQsNCgZSjUVV6zq4h5gnsx kx/J4q3LheSYsqqISQQYEQIACQUCR2txugIbDAAKCRAK2SV6wbFrePx5AKChN472 XkxN6aV5udvqBDsUi5+gCfSNhpfpvJDQtSijeM91eHW+m8QWI= =fMWD -----END PGP PUBLIC KEY BLOCK-----
That block of text can be imported into other GnuPG (or PGP) users’ keychains so when they exchange data with you in the future, they can verify your identity and encrypt or decrypt data.
All we have now is a keypair. What we’re missing is how to use this with e-mail, files whose contents we wish to keep private, or information we wish to distribute in such a way that its recipients can be assured of its authenticity. We also need to learn how to take steps to affirm the connection of our keypair to our identities so that other people who wish to exchange signed or encrypted data with us can be assured that they’re really communicating with us and not an imposter. We’ll cover all of that in the next installment.
Michael Hall has been using, maintaining and writing about networks for nearly 15 years. He’s the managing editor of Enterprise Networking Planet and he blogs about Internet privacy and security at Open Networks Today.