| 1 |
Using an OpenPGP smartcard for LUKS dm-crypt devices in Debian |
| 2 |
============================================================== |
| 3 |
|
| 4 |
The Debian cryptsetup package provides the keyscript `decrypt_gnupg-sc` |
| 5 |
for setups with a keyfile that is encrypted using an OpenPGP smartcard. |
| 6 |
|
| 7 |
The following example assumes that you store the encrypted keyfile in |
| 8 |
`/etc/keys/cryptkey.gpg`. LUKS device is `/dev/<luks_device>`. |
| 9 |
|
| 10 |
First, you'll have to create the keyfile and encrypt it with your key |
| 11 |
0xDEADBEEF: |
| 12 |
|
| 13 |
dd if=/dev/random bs=1 count=256 | gpg --recipient 0xDEADBEEF \ |
| 14 |
--output /etc/keys/cryptkey.gpg --encrypt |
| 15 |
|
| 16 |
Next the LUKS device needs to be formated with the key. For that, the |
| 17 |
`decrypt_gnupg-sc` keyscript can be used: |
| 18 |
|
| 19 |
/lib/cryptsetup/scripts/decrypt_gnupg-sc /etc/keys/cryptkey.gpg | \ |
| 20 |
cryptsetup --key-file=- luksFormat /dev/<luks_device> |
| 21 |
|
| 22 |
In order to unlock the encrypted LUKS device automatically during boot process, |
| 23 |
add the following to `/etc/crypttab`: |
| 24 |
|
| 25 |
cdev1 /dev/<luks_device> /etc/keys/cryptkey.gpg luks,keyscript=decrypt_gnupg-sc |
| 26 |
|
| 27 |
In order to avoid data loss if the smartcard is damaged or lost, you may |
| 28 |
want to decrypt `/etc/keys/cryptkey.gpg` and store the plaintext in a safe |
| 29 |
place. Or alternatively, use another slot with your backup key: |
| 30 |
|
| 31 |
cryptsetup luksAddKey /dev/<luks_device> /path/to/backup.key |
| 32 |
|
| 33 |
|
| 34 |
Decrypting the keyfile at initramfs stage |
| 35 |
----------------------------------------- |
| 36 |
|
| 37 |
If the device is to be unlocked at initramfs stage (such as for the root |
| 38 |
FS or the resume device), you need to copy the public part of the |
| 39 |
encryption key to `/etc/cryptsetup-initramfs/pubring.gpg`: |
| 40 |
|
| 41 |
gpg --export 0xDEADBEEF >/etc/cryptsetup-initramfs/pubring.gpg |
| 42 |
|
| 43 |
Then the provided initramfs hooks should do all additionally required |
| 44 |
work for you when the initramfs is created or updated. |
| 45 |
|
| 46 |
Be warned though, that for such devices the OpenPGP encrypted key is copied |
| 47 |
to the initramfs by the initramfs cryptgnupg-sc hook. If you don't want this, |
| 48 |
you should take a look at the initramfs cryptgnupg-sc hook, which is located |
| 49 |
at `/usr/share/initramfs-tools/hooks/cryptgnupg-sc`. |
| 50 |
|
| 51 |
Moreover, note that unlocking at initramfs stage is currently not compatible |
| 52 |
with plymouth or other bootsplash, as a curses-based prompt is used for PIN |
| 53 |
entry. |
| 54 |
|
| 55 |
-- Guilhem Moulin <[email protected]> Sun, 23 Sep 2018 03:28:31 +0200 |