Skip to main content

Raymii.org Logo (IEC resistor symbol)logo

Quis custodiet ipsos custodes?
Home | About | All pages | RSS Feed | Gopher

Keep messages secure with GPG

Published: 22-03-2015 | Author: Ben Everard | Text only version of this article


Table of Contents


This article was originaly published in Linux Voice, issue 1, April 2014.This issue is now available under a Creative Commons BY-SA license. In anutshell: you can modify and share all content from the magazine (apart fromadverts), even for commercial purposes, providing you credit Linux Voice as theoriginal source, and retain the same license.

This remix is converted manually to Markdown and HTML for ease of archiving andcopy-pasting.

If you like this article, consider sponsoring me by trying out a Digital OceanVPS. With this link you'll get $100 credit for 60 days). (referral link)

Other converted Linux Voice articles can be found here.


Keep messages secure with GPG

The Feds (and GCHQ, and the NSA) are snooping on our communications, but we canfight back with encryption

GnuPG logo

Normal email is one of the least secure forms of communication available - lesssecure even than post cards. These mails can typically be read by anyone on thesame network as you, anyone at the ISP, anyone at your mail provider, anyone atthe recipient's ISP and anyone on the same network as the recipient, as well asanyone with access to the various networks between the two ISPs.

If you use SSL or TLS to connect to your inbox, then it improves things alittle, but it's still vulnerable as soon as it leaves your mail provider.

PGP (Pretty Good Privacy) is a program designed to remove these weaknesses. Ituses the normal email system, but adds a layer of encryption to protect them intransit. These days, PGP is usually used to refer to the OpenPGP format forthese encrypted messages, rather than the PGP program specifically.

The OpenPGP format uses two different types of encryption: symmetric key andpublic key. In symmetric key encryption the same key (basically just a binarystring that's used as a password) is used to encrypt and decrypt the message.

In public key encryption, two different keys are used (one to encrypt and one todecrypt). The phrase 'private key' can refer to either the key in symmetricencryption, or the secret key in public key encryption. To avoid this ambiguity,we won't use the phrase in this article, but you may come across it in software.

When encrypting a message with an OpenPGP-compatible program, the softwaregenerates a random symmetric key and encrypts the text. This ciphertext formsthe bulk of the message. The problem is that the recipient of the message has toknow the key, but it can't be included in the message otherwise anyone whointercepts the message will be able to read it.

This is where public key encryption comes into play. Everyone who uses PGP firstcreates a public/secret key pair. The public key is made public while the secretkey is known only to the user. However, anything encrypted with the public keycan be decrypted only with the secret key and visa versa.

Public and private keys

The solution is to encrypt the key for the message with the recipient's publickey. When they receive the message, they can then decrypt the key for themessage, and then decrypt the message itself. This is a bit convoluted, but it'smuch less processor- intensive than encrypting the whole message using publickey encryption.

You can use OpenPGP in most mail clients, but we'll look at doing it in webmail.Since OpenPGP is purely a text format, you could generate the encrypted messageelsewhere and copy and paste it into your email. That's exactly what we'll do,but instead of copy and paste, we'll use a browser extension to convert theplaintext to encrypted ciphertext.

Mailvelope (www.mailvelope.com) works with Chrome/Chromium and Firefox, and itcomes pre-configured to work with some of the most popular webmail providers(Gmail, Yahoo, Outlook.com and GMX).

Installing it is no more challenging than downloading the extension from itsReleases section and opening the file with the appropriate web browser.

The first step is to generate a public/secret key pair. In Chrome/Chromium, youcan get to this by clicking on the padlock icon that should have appeared to theright of the address bar.

In Firefox, this options menu is a little more hidden. First, you'll need to goto View > Toolbars > Add-on bar. This will make the Add-on bar appear at thebottom of the screen, and then you should find the padlock icon on the right-hand side of this. This icon will bring up a menu, and you'll need to selectOptions (see the image).

gpg1

In the Options screen, you can create a new public/secret (private) key pair byselecting Generate Keys.

Once you've done this, you can go to the Display Keys screen to see it. Thisscreen will show all the keys that Mailvelope knows, whether they're otherpeople's public keys or your own public/secret key pairs.

Before you can receive emails, you have to send your key to the people you wantto communicate with. The key file can be exported from the Display Keys screen(you can also export your public/private key pair here and import them intoanother mail program).

Getting the public key to the recipient can be a challenge. The best way to dothis is to physically transport the key, as you can be completely sure that theygot it correctly. The easiest way is just to email them the keyfile. However,it's possible for some malicious attacker to intercept this message and changethe keyfile.

There are two other options: key servers and webs of trust. Key servers aredatabases of keys that you can add your keys to, and retrieve other people'skeys from. For example, try http://keyserver.pgp.com or http://pgp.mit.edu.Of course, it is possible that some attacker could take control of one or moreof these key servers and put fake keys in them.

Webs of trust have a decentralised method of verifying keys. It's done by peopledigitally signing the keys of people they've met and exchanged keys with. If youneed to communicate with someone, you can then tap into this web of trust andsee who trusts them. Perhaps someone you trust also trusts them. Perhaps someoneyou trust trusts someone who trusts them. If this chain is short enough, thenyou can be confident that you can trust the person. Unfortunately, Mailvelopedoesn't currently support webs of trust.

Keep it secret, keep it safe

As is so often the case, the decision on which way to distribute your key comesdown to security versus convenience.

If you're concerned, you could always follow up with another method such as aphone call to confirm the key.

Once someone has sent you their key, you just need to load it into Mailvelopeusing the Import Keys screen in the Options. Getting set up with keys is thehardest (or at least, most inconvenient) part of using any OpenPGP-basedcommunication.

Once you've done this, it's easy. With the Mailvelope extension running, justuse your mail provider's web page as normal (if your mail provider isn't alreadyon the Mailvelope watch list, you'll need to add it in the Options).

gpg2

When you get to the compose page, you'll see a floating icon of a pen and paper.Click on this and it will open a new window to let you enter the text for themessage. Once you've written the message, click on the padlock, and add one ormore people to the list that it's encrypted for, then Transfer to put theciphertext into the email.

If you receive an encrypted message, Mailvelope will display a decrypt icon;click on this to enter the passphrase you entered when you generated the key.This password gives you some security even if an attacker gets access to yourmachine.

Provided you exchange keys securely, and keep your keys safe, OpenPGP providessecurity that is thought to be unbreakable with current technology.

Boxout 1, Using other mail clients

We've described the process for working with Mailvelope, but the process isalmost identical for all OpenPGP-compliant software.

You shouldn't have any problems following along using Thunderbird or Evolution,or even AGP and K9 for Android or Cyanogenmod.

Regardless of the software, you'll still have to go through the same process ofgenerating and exchanging keys before you can communicate with someone.

As mentioned in the main text, you should be able to transfer keys between thesepieces of software so you can access the same mail account through differentprograms.

Mailpile is a mail client designed to bring PGP to the masses by making iteasier to set up OpenPGP encryption, even for new users. The project raised justover $163,000 in crowdfunding and is currently in development, and you can trackits progress at www.mailpile.is.

Boxout 2, Digital Signing

gpg3

OpenPGP encryption ensures that only the intended recipient can read themessage; however, it doesn't guarantee that they receive the message, or provewho sent the message.

Encryption can't help with the first of these, but there is something you can doabout the latter measure. In many OpenPGP mail clients (and the gpg command linetool), you can add a digital signature to a clear-text message.

It does this by leaving the message in plain text, but also encrypting a hash ofthe message with your secret key. This encrypted hash is known as a digitalsignature.

Since it's encrypted with your secret key, it can be decrypted with your publickey. Any recipient that knows your public key can then decrypt this hash andcheck it against the message. If they match, the recipient knows that it reallycame from you.

Tags: articles, gpg, linux-voice, linux-voice-issue-1-2014, mail, mailvelope, pgp, secure