<<

MASTERCLASS GNUPG MASTERCLASS You wouldn’t want other people opening your letters and BEN EVERARD your data is no different. Encrypt it today! SECURE EMAIL WITH GNUPG AND Send encrypted emails from your favourite email .

our typical email is about as secure as a The first thing that you need to do is create a to JOHN LANE postcard, which is good news if you’re a represent your identity in the OpenPGP world. You’d Ygovernment agency. But you wouldn’t use a typically create one key per identity that you have. postcard for most things sent in the post; you’d use a Most people would have one identity, being sealed envelope. Email is no different; you just need themselves as a person. However, some may find an envelope – and it’s called “”. having separate personal and professional identities Since the early 1990s, the main way to encrypt useful. It’s a personal choice, but starting with a single email has been PGP, which stands for “Pretty Good key will help while you’re learning. ”. It’s a protocol for the secure encryption of Launch Seahorse and click on the large plus-sign email that has since evolved into an open standard icon that’s just below the menu. Select ‘PGP Key’ and called OpenPGP. work your way through the screens that follow to supply your name and email address and then My lovely horse generate the key. The GNU Privacy Guard (GnuPG), is a free, GPL-licensed You can, optionally, use the Advanced Key Options implementation of the OpenPGP standard (there are to add a comment that can help others identify your other implementations, both free and commercial – key and to select the cipher, its strength and set when the PGP name now refers to a commercial product the key should expire. owned by Symantec). An easy way to get started with The final step requires you to supply a passphrase encryption is to use Seahorse, a GTK graphical user – you’ll need to supply this later on when you use your Seahorse makes it easy to manage PGP keys, and its interface for GnuPG that should be available in your key. After doing so, a new key is generated in the step-by-step key creation chosen distribution’s package repository. It’s installed background. There’s no feedback while this is dialog is a good way to get by default on , where it’s called “Passwords happening (which gives the impression that it isn’t started. and Keys”. working) but, eventually, you should see your key in the main Seahorse window (select ‘GnuPG Keys’ in the main window to see it).

Get the key… Key generation can take a few minutes, because the algorithms need to collect sufficient entropy (randomness) to generate a secure key. If your system struggles to provide this, you can install a package called haveged from your distribution’s repository; it’s a daemon that gathers entropy from unpredictable background system events and will quickly deliver the entropy needed to satisfy key generation. Once you have a key, you can right-click to view its properties, which will show you the details that you supplied when creating it, plus its Key ID. This is shown as an eight-digit hexadecimal number but the

110 www.linuxvoice.com GNUPG MASTERCLASS

actual key ID is 64 bits. The lower 32 bits are usually sufficient to identify a key (you can see the full key ID on the Details tab). Key servers offer a convenient way to possible. To help with this, Seahorse’s Key distribute your key and to obtain others’ keys, Properties screen displays a human-readable Know the secret… but they don’t prove authenticity in they way “Key Fingerprint” that can be easily Your key is complex: it contains a secret part that you that an SSL would. PGP compared. You can then indicate your trust uses a “Web of Trust” model instead, where by selecting a trust level from the drop-down should keep for yourself, plus a public part that you trust is left to the users. This means that it’s menu on the same screen. If you want to can share with others. Someone wishing to send you up to you to decide if a key obtained from a share that trust publicly then you can use the encrypted email will need your public key. If you look key really does belong to who you “Trust” tab to sign the key. A popular way to at the Details tab, you’ll see that you actually have two think it does. You should use offline methods build your web of trust is to attend a keys; the first one is your primary key and the other to establish a key’s authenticity, in-person if key-signing party, as we explain on page 113. one is a subkey. The subkey is used for encryption and the primary key is used for GnuPG’s other purpose: signing. You can sign other people’s keys to affirm your trust and you can sign emails and other files to affirm their authenticity, which others may verify using your public key. For your key to be useful, its public part needs to be accessible by anyone who may want to send encrypted documents to you, or anyone wishing to verify a document or key that you’ve signed. You could personally issue your public key to those that need it but it’s better to publish it to a key server. Likewise, you can use a key server to get any public keys that you You can sign a key that you trust, but be honest about how much you trust it. need. Seahorse will do this for you if you select its Remote > Sync And Publish Keys menu option. You can browse key servers that have web them with any applications that support GnuPG, and interfaces – try http://pool.sks-keyservers. your is an obvious candidate here. net:11371 which, as its URL suggests, is actually a Enigmail is a GnuPG add-on for PRO TIP pool of many key servers. Some key servers may offer that you can install by selecting Thunderbird’s Tools > an option to upload keys directly through the . Add-ons from its menu bar and searching for Seahorse can also be used to manage SSH keys Key servers propagate changes so, if you’re looking ‘enigmail’. and X.509 certificates. for a key, you can use any server. Seahorse will help you manage your own keys as Encrypting email well as any public keys that you’ve downloaded and, It adds a new menu with options for encryption and because it’s a front-end to GnuPG, they’re stored at signing, plus key management that provides similar ~/.gnupg within your home directory. You can use functionality to Seahorse (try both and see which you prefer). It automatically decrypts or verifies inbound email using your keys once you’ve configured your PRO TIP email account to use it. Use Thunderbird’s Edit > PGP keys are often Account Settings to do that – you’ll notice there is a referred to as a ‘key pair’ new OpenPGP Security settings page there with a and the secret and public check a box that enables OpenPGP support. parts as a ‘Private Key’ and a ‘Public Key’. By default, Enigmail locates your key with your email address, and this should be sufficient unless you have multiple of either. You can, however, use the Account Settings screen to explicitly select a key if you need to. You can also configure default behaviour there, such as whether to sign “You may find it useful to have or encrypt . separate personal and private With the configuration done, you can write your identities for use with GnuPGP.” first email. Adele” is “The friendly OpenPGP email robot” and it can help you test your setup. Just send a message to adele-en@ gnupp.de and you’ll get a reply that will highlight any Enigmail uses your secret key to open encrypted issues with your ability to send encrypted messages. messages that you receive, like this from “Adele”, which You can attach your public key to the message if you confirms that sending encrypted messages works too. haven’t published it to a key server.

www.linuxvoice.com 111 MASTERCLASS GNUPG USE GNUPG ENCRYPTION FROM THE COMMAND

owering the desktop applications and plugins JOHN LANE we’ve just looked at is libgcrypt, the GnuPG Pcryptographic library, and gpg, is its command line utility. If you’ve already installed a GUI tool then you’ll already have gpg; if not, you can install it from your repository and confirm the version that you have: $ sudo -get install gpg $ gpg --version gpg (GnuPG) 2.0.26 libgcrypt 1.6.2 You’ll need to create a key if you’re starting out and, There are pass phrase dialogs for GTK 2, Qt 4, and if you as gpg affords you more control than the graphical aren’t running a graphical desktop, Curses. tools that we looked at previously, it’s worth using it to create your key if you’re comfortable on the command Use the file as input to batch mode: line. The simplest way to create a key is to use gpg $ gpg --gen-key --verbose --batch alice.keygen interactively and follow its prompts: gpg: key 4A924D1C marked as ultimately trusted $ gpg --gen-key The --verbose argument is there to show what’s going Alternatively, you can write your settings into a text on. The last line of output shows your key ID. file, say alice.keygen, like this: Your key is written into files in your ~/.gnupg Key-Type: RSA directory; the secret part in secring.gpg and the public Key-Length: 4096 part in pubring.gpg. Collectively these files are your Key-Usage: sign Key Ring and, as you use gpg, you’ll also store other Subkey-Type: RSA people’s public keys in there. Central to this key Subkey-Length: 3072 sharing is the Key Server, and you can tell gpg which Subkey-Usage: encrypt one to use by adding an entry to its configuration file, Preferences: SHA512 SHA384 SHA256 SHA224 AES256 ~/.gnupg/gpg.conf: AES192 AES CAST5 ZLIB BZIP2 ZIP Uncompressed keyserver hkp://pool.sks-keyservers.net Name-Real: Alice You should send your public key to the key server Name-Comment: Alice from example.com, the well-known so others can find it and you can retrieve their public participant in examples. key using their email address or key ID: Name-Email: [email protected] $ gpg --send-key 4A924D1C Passphrase: your secret is safe with me $ gpg --search-keys [email protected] This example creates a 4096-bit RSA primary $ gpg --recv-key 4E4A3DB3 signing key and a 3072-bit subkey for encryption. Longer keys are harder to crack, but they may not be Who do you trust? compatible with all software, so as an example we’ve The fact that anyone can upload to key servers means given our subkey a different size. The long list of that you should challenge the authenticity of any key Preferences contains our preferred hash, cipher and that you acquire. An individual who believes a key to compression algorithms. If you omit the Passphrase be genuine can sign it to acknowledge that view, but entry from the file, you’ll be prompted to enter it. Either it’s still your decision to trust their opinion. Likewise, way, your passphrase protects your key – choose it you can also sign keys that you trust. If you don’t want wisely and don’t forget it! to sign a key, you can still record your own trust level. This “Explicit Trust” is private to you, and you use the GnuPG Modern key editor to do it: $ gpg --edit-key [email protected] GnuPG version 2.1 was released on to its gpg-agent. The secret keyring file gpg> trust 6 November 2014 after a long beta. The 2.0.6 secring.gpg is no longer used and pubring. Please decide how far you trust this user to correctly verify version series retains the “Stable” moniker, gpg is now pubring.kbx, as the release notes other users’ keys with this new release being called “Modern”. explain. See ://www.gnupg.org/faq/ It has many new features, but most whats-new-in-2.1.. (by looking at passports, checking fingerprints from different notable is that it manages private keys It’s unlikely to be in your distro yet, unless sources, etc.) differently, delegating responsibility entirely you use a rolling release like Arch . 1 = I don’t know or won’t say 2 = I do NOT trust

112 www.linuxvoice.com GNUPG MASTERCLASS

gpg-key2ps quickly produces these key slips for you to print out, which are useful if you’re getting your key signed.

3 = I trust marginally 4 = I trust fully The GPG agent and Pinentry 5 = I trust ultimately The gpg-agent is a daemon that manages pinentry-program /usr/bin/pinentry-curses m = back to the main menu secret keys for gpg, which starts it You can start the agent manually: Your decision? 3 automatically on demand, making it $ eval $(gpg-agent --daemon) something that you don’t normally need to be To re-start it after changing configuration: concerned about. Pinentry is a helper tool $ pkill -- HUP gpg-agent Using your key used by gpg when it requires a user to enter You can also ask it to reload itself like this: Once you have a key, you can get on with the a passphrase. The agent reads configuration $ echo RELOADAGENT | gpg-connect-agent nitty-gritty details of its use, the main ones being from an optional file ~/.gnupg/gpg-agent. Should you want to terminate it: signing and encryption. Let’s look at signing first. conf, and one reason to use it is to specify $ pkill --signal TERM gpg-agent the pinentry path if gpg has difficulty finding The agent can also serve in place of the There are two ways to do it; the first method produces it, which an entry like this will achieve: ssh-agent see man gpg-agent for more. a signed copy of an input file that is compressed and signed. It works like this: $ gpg --sign mydocument.odt The need to decrypt can be avoided with a which leaves the original file intact and creates a new “detached signature”. This signs the document as binary file with a .gpg extension that is a compressed before but only writes a signature file that you can and signed copy. The signature can be verified: pass along with the original file to anyone who needs $ gpg --verify mydocument.odt.gpg it and they will be able to verify its authenticity using gpg: Signature made Tue 25 Nov 2014 16:38:36 UTC using RSA the signature file: key ID 89572049 $ gpg --output mydocument.sig --detach-sig mydocument.odt gpg: Good signature from “Alice (Alice from example.com, the $ gpg --verify mydocument.sig mydocument.odt well-known participant in examples.) ” gpg: Signature made Tue 25 Nov 2014 16:50:39 UTC using RSA [ultimate] key ID 89572049 You have to use --decrypt to recover the original gpg: Good signature from “Alice (Alice from example.com, the document, even though it’s only compressed inside well-known participant in examples.) ” the binary container file: [ultimate] $ gpg --decrypt --output mydocument.odt mydocument.odt.gpg Validating software packages Many open source applications sign their packages Key signing party so that their authenticity can be validated. As an example, we’ll validate the latest GnuPG source: A key signing party is any event where individuals can meet $ ftp://ftp.gnupg.org/gcrypt/gnupg/gnupg-2.1.0.tar.bz2 to verify each others’ identities before signing each others’ keys to build their web of trust. You need to bring along $ wget ftp://ftp.gnupg.org/gcrypt/gnupg/gnupg-2.1.0.tar.bz2.sig some form of identification, a photo ID like a driving licence $ gpg --verify gnupg-2.1.0.tar.bz2.sig gnupg-2.1.0.tar.bz2 or passport, and a hard-copy of your “Key Fingerprint” We downloaded the package and its signature but which you can output from your secret key: will also need the public keys belonging to those who $ gpg --list-secret-keys --fingerprint signed the package, as gpg will report an error if it If you’re on a Debian derivative, the signing-party package contains a utility that prints a page containing can’t find them: multiple copies of your fingerprint that you can cut into gpg: Signature made Wed 05 Nov 2014 15:44:27 UTC using RSA slips and use at a keysigining event: key ID 4F25E3B6 $ gpg-key2ps -p a4 BC5EDAFF > keysheet.ps gpg: Can’t check signature: No public key At the event you’ll verify each individual’s identity and You can the key (assign trust if you want collect their email address and key fingerprint. After the event, you should obtain, verify and sign their keys and then to) and then verify again: send each person an encrypted copy of their key that you $ gpg --recv-keys 4F25E3B6 signed, which they should use to update their key and $ gpg --verify gnupg-2.1.0.tar.bz2.sig gnupg-2.1.0.tar.bz2 upload it to their keyserver. Here’s how: gpg: Good signature from ... $ gpg --search-keys [email protected] We’ve covered the basics of key management, $ gpg --fingerprint [email protected] $ gpg --sign-key [email protected] document signing and encryption, but there’s much $ gpg -a --export [email protected] | gpg --encrypt -r bob@ more to GnuPG and OpenPGP in general. How far you example.com -a | mail [email protected] go depends on how paranoid you are! It’s up to you how much identity verification you do, but you’re more likely to be trusted if you’re known to take it John Lane provides technical solutions to business seriously. If you’re interested in key signing, like problems. He has yet to find something that Linux can’t biglumber.com and keysigning.org have event listings. solve.

www.linuxvoice.com 113