Encrypted Usb Key

I’ve recently gotten into crypto-currencies (I host a p2pool node at pool.sw.gy). With that comes the burden of properly securing private keys for wallets. These are unusually high-value targets for miscreants and fairly easily discovered once a system is accessible. Additionally, with all of the unbelievably scary news leaking out about NSA programs and capabilities, I’ve decided to move to using PGP wherever possible. Both of these things require properly securing digital secrets. If a keyfile is compromised, an attacker can masquerade as you and cause damage (social, financial, or otherwise).

In order to help properly secure these things, I decided that keeping an encrypted USB key with the information on it would be the best way to go about this. By keeping this key on my person, I can be sure that even in the event of a break-in (I live in Los Angeles, so that possibility isn’t as remote as I’d like), my private keys will not be compromised. I would be out the cost of hardware rather than the cost of my online presence. In this post, I’ll cover the rationale behind my choice of software and the steps needed to set everything up. These instructions assume you’re using a UNIX-like system (as everything on this blog does).

First, A Choice of Software

There are a three different software choices for encrypting a USB stick in a manner that is easy for day to day use. The worst kind of security is burdensome security, as it tends to be neglected once it becomes annoying.

First, we have cryptsetup. This option provides a utility to setup disk encryption based on the dm-crypt kernel module. With this option, no additional meta-data is stored on the encrypted volume, meaning that a casual observer would see the drive as being an unformatted volume. This could provide some level of plausible deniability (though a duress partition would be a better fit for that purpose).

Next we have cryptsetup combined with LUKS. This provides some additional conveniences for the user at the cost of the plausible deniability angle. The LUKS additions store meta-data on the volume that signals the presence of encrypted data. As an illustration of this, plugging in a USB stick with a LUKS volume will present the user with a dialog asking for the passphrase to unlock it. That is a pretty good clue as to what is on the drive. Some of the additional perks given by LUKS are:

  • Multiple keys per volume
  • Support for passphrase revocation
  • Standardization may allow for broader software compatibility

Finally, there is ecryptfs. This is a file-based solution, which means you will be leaking ALL file meta-data. On the otherhand, this allows you to pick and choose which files are encrypted and portentially use different passphrases for different files. This solution is FUSE-based, so non-privileged accounts can make use of it.

For my purposes, the bare cryptsetup option is most attractive. I like the idea that if I lose my USB key, and a somewhat savvy attacker finds it, there will be no obvious clues that it is holding encrypted (and therefore valuable / sensitive) data.

Install the Requirements

First, you’ll need to install cryptsetup. As usual, I found that the apt package is pretty far out of date. I decided to install from source to get access to the latest features and bug fixes.

Grab the latest tarball from google code. It’s a good idea to verify the signature, though a sophisticated attacker would be sure to update the published signature to match their malware, so you can’t place too much faith in that. At the time of this writing, the most recent version is 1.6.3

$ wget https://cryptsetup.googlecode.com/files/cryptsetup-1.6.3.tar.bz2
$ tar -jxvf cryptsetup-1.6.3.tar.bz2
$ cd cryptsetup-1.6.3/
$ ./configure

At this point, I discovered that my system was missing, indicated by:

configure: error: You need the device-mapper library.

Luckily this is an easy fix:

    $ sudo apt-get install libdevmapper-dev

Running ./configure again, I discovered that I needed a newer version of popt:

configure: error: You need popt 1.7 or newer to compile.

Again, Ubuntu’s libpopt0 package is outdated, so we’ll need to build from source. You can find a copy of the source for popt 1.7 here.

Building this library is pretty straight forward - just do the usual UNIX dance.

$ tar -zxvf popt_1.7.orig.tar.gz # What's with this weird file name??
$ cd popt-1.7/
$ ./configure --prefix=/usr
$ make
$ sudo make install

Now hop back over to the cryptsetup directory and fire off configure again.

Sweet! This time it worked! Onward!

$ make
$ make check # Just to be sure :-)
$ make install

At this point, cryptsetup should be installed and functional.

Create the USB Key

Now, plug in the USB stick you want to use. You can tail dmesg to determine which device it has been mapped to.

$ dmesg | tail
$ sudo cryptsetup create SOME_NAME /dev/sdb1
Enter passphrase: *** Use a good passphrase here ***
$ sudo mkfs.ext4 /dev/mapper/SOME_NAME
$ sudo mount /dev/mapper/SOME_NAME /mnt

At this point, your USB stick is ready for use! Place copies of your sensitive files in /mnt. Once you’re finished placing data here, get rid of the evidence:

$ sudo umount /mnt
$ sudo cryptsetup remove SOME_NAME
$ history -c
$ exit

Later, to use the drive again, repeat the steps above (except the mkfs part of course):

$ sudo cryptsetup create SOME_NAME /dev/sdb1
$ sudo mount /dev/mapper/SOME_NAME /mnt

When finished, perform the same steps as above:

$ sudo umount /mnt
$ sudo cryptsetup remove SOME_NAME
$ history -c
$ exit

Note that in the above, /dev/sdb1 is where my USB stick was mounted - be sure to change this to match your system. The SOME_NAME identifier above is ephemeral and not important.

Caveats, Summary, Etc

In this post we learned about encrypted volumes, specifically as a USB stick. With this setup, we have some level of plausible deniability. Keep in mind the following points as you venture into a more security minded future:

  1. Don’t forget your passphrase. It’s not recoverable!
  2. Don’t leave your USB stick mounted and idling in machines that you aren’t watching - this defeats the purpose and an attacker could exfil all your secret stuff!
  3. Don’t let this USB stick be the only source for critical data! USB sticks can and do die, so keep an (encrypted) off-site backup someplace for disaster recovery.

That’s all, have fun and be safe!