linsam wrote:
I've been using a yubikey4 for some months now and just today decided to set the option to require a touch in addition to pin when signing or decrypting in gpg.
Unfortunately, I forgot my admin pin and after 3 tries I am locked out of admin access for my key.
As I understand it, I have to reset the OpenPGP app to recover, and doing so will wipe the private keys from the yubikey4.
Also as far as I can tell, to transition from an old OpenPGP key to a new one, people generally cross sign the old and new keys, and write a key transition statement that is signed by both the old and new key. However, as near as I can tell, I cannot have both a new and old key on the yubikey4 at the same time[*], so I don't see how I can do cross signing nor the double signed transition statement.
How can I update my key in an acceptable fashion?
Some additional information: I did not create a backup when I generated the original key. I have not locked myself out of signing/decrypting with the old key yet (PW1 is still good, only the admin pin is at 0 attempts remaining)
EDIT: Resetting the PGP applet will wipe out any keys currently stored. This should only be performed if you cannot remember your PIN/PUK, or you've already had the applet locked out. So, first things first, resetting the OpenPGP Applet (
source):
- Check versions:
GPG >= v2.0.22
Code:
gpg2 --version
EDIT: this is only required on yubikeys prior to the YubiKey4: The below indicates v1.0.6; this is the minimum required.
Code:
gpg-connect-agent --hex "scd apdu 00 f1 00 00" /bye
D[0000] 01 00 06 90 00
- Reset the applet:
Create a file and paste the following into it:
Code:
/hex
scd serialno
scd apdu 00 20 00 81 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 81 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 81 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 81 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 83 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 83 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 83 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 83 08 40 40 40 40 40 40 40 40
scd apdu 00 e6 00 00
scd apdu 00 44 00 00
/echo Card has been successfully reset.
Now run it.
Code:
gpg-connect-agent -r FILE
So the way to deal with the transition is to generate the key on your computer and then move it to the yubikey. In general, you should be doing this anyway, as otherwise you're unable to make a backup of the master key (this would mean that if the yubikey is lost or damaged, so is your master, and you have to start accumulating signatures from scratch).
Generate your key on the computer. Use 2048 bit keys or make sure you're using the versions listed in the link that follows. Even though the yubikey4 supports 4096bit RSA, there's a problem in currently-shipped versions of libgcrypt that reduces the effective entropy and can cause the default encryption key to be mathematically related to the master key; this is a Bad Thing™ (
CVE-2016-6316). Once you've generated the key, open it and inspect:
Code:
gpg2 --edit-key --expert <keyid>
You should see your master key with "Usage: SC" and a key with "Usage: E". This is your master and your encryption key respectively. The first thing you should do is generate a separate signing key:
Code:
gpg2 --edit-key robert@klebes.info
gpg (GnuPG) 2.1.11; Copyright (C) 2016 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Secret key is available.
sec rsa2048/0xC13607BD83A9E927
created: 2016-08-25 expires: 2017-08-25 usage: SC
trust: ultimate validity: ultimate
ssb rsa2048/0x970B4C0FC47073FE
created: 2016-08-25 expires: 2017-08-25 usage: E
[ultimate] (1). Robert Klebes <robert@klebes.info>
[ultimate] (2) Robert Klebes <rob.klebes@gmail.com>
[ultimate] (3) Robert Klebes <rfk3806@rit.edu>
[ultimate] (4) Robert Klebes (Keybase User: sporkwitch) <sporkwitch@keybase.io>
gpg> addkey
Secret parts of primary key are stored on-card.
Please select what kind of key you want:
(3) DSA (sign only)
(4) RSA (sign only)
(5) Elgamal (encrypt only)
(6) RSA (encrypt only)
(7) DSA (set your own capabilities)
(8) RSA (set your own capabilities)
(10) ECC (sign only)
(11) ECC (set your own capabilities)
(12) ECC (encrypt only)
(13) Existing key
Your selection? 4
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) 2048
Requested keysize is 2048 bits
Please specify how long the key should be valid.
0 = key does not expire
<n> = key expires in n days
<n>w = key expires in n weeks
<n>m = key expires in n months
<n>y = key expires in n years
Key is valid for? (0) 1y
Key expires at Sun 27 Aug 2017 14:49:19 EDT
Is this correct? (y/N) y
Really create? (y/N) y
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
sec rsa2048/0xC13607BD83A9E927
created: 2016-08-25 expires: 2017-08-25 usage: SC
card-no: 0006 03647658
trust: ultimate validity: ultimate
ssb rsa2048/0x970B4C0FC47073FE
created: 2016-08-25 expires: 2017-08-25 usage: E
ssb rsa2048/0xAD5F52AC4DEB718E
created: 2016-08-27 expires: 2017-08-27 usage: S
[ultimate] (1). Robert Klebes <robert@klebes.info>
[ultimate] (2) Robert Klebes <rob.klebes@gmail.com>
[ultimate] (3) Robert Klebes <rfk3806@rit.edu>
[ultimate] (4) Robert Klebes (Keybase User: sporkwitch) <sporkwitch@keybase.io>
And if you want an authentication key (authentication keys should be separate from signing keys, otherwise there's the possibility of a malicious system tricking you into signing something when you were meant to be authenticating):
Code:
gpg> addkey
Secret parts of primary key are stored on-card.
Please select what kind of key you want:
(3) DSA (sign only)
(4) RSA (sign only)
(5) Elgamal (encrypt only)
(6) RSA (encrypt only)
(7) DSA (set your own capabilities)
(8) RSA (set your own capabilities)
(10) ECC (sign only)
(11) ECC (set your own capabilities)
(12) ECC (encrypt only)
(13) Existing key
Your selection? 8
Possible actions for a RSA key: Sign Encrypt Authenticate
Current allowed actions: Sign Encrypt
(S) Toggle the sign capability
(E) Toggle the encrypt capability
(A) Toggle the authenticate capability
(Q) Finished
Your selection? s
Possible actions for a RSA key: Sign Encrypt Authenticate
Current allowed actions: Encrypt
(S) Toggle the sign capability
(E) Toggle the encrypt capability
(A) Toggle the authenticate capability
(Q) Finished
Your selection? e
Possible actions for a RSA key: Sign Encrypt Authenticate
Current allowed actions:
(S) Toggle the sign capability
(E) Toggle the encrypt capability
(A) Toggle the authenticate capability
(Q) Finished
Your selection? a
Possible actions for a RSA key: Sign Encrypt Authenticate
Current allowed actions: Authenticate
(S) Toggle the sign capability
(E) Toggle the encrypt capability
(A) Toggle the authenticate capability
(Q) Finished
Your selection? q
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) 2048
Requested keysize is 2048 bits
Please specify how long the key should be valid.
0 = key does not expire
<n> = key expires in n days
<n>w = key expires in n weeks
<n>m = key expires in n months
<n>y = key expires in n years
Key is valid for? (0) 1y
Key expires at Sun 27 Aug 2017 14:53:57 EDT
Is this correct? (y/N) y
Really create? (y/N) y
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
sec rsa2048/0xC13607BD83A9E927
created: 2016-08-25 expires: 2017-08-25 usage: SC
card-no: 0006 03647658
trust: ultimate validity: ultimate
ssb rsa2048/0x970B4C0FC47073FE
created: 2016-08-25 expires: 2017-08-25 usage: E
ssb rsa2048/0xAD5F52AC4DEB718E
created: 2016-08-27 expires: 2017-08-27 usage: S
ssb rsa2048/0xCD560758CC50C8A8
created: 2016-08-27 expires: 2017-08-27 usage: A
[ultimate] (1). Robert Klebes <robert@klebes.info>
[ultimate] (2) Robert Klebes <rob.klebes@gmail.com>
[ultimate] (3) Robert Klebes <rfk3806@rit.edu>
[ultimate] (4) Robert Klebes (Keybase User: sporkwitch) <sporkwitch@keybase.io>
Once this is done, you should now have a sane key setup in your machine's gpg keyring, as well as the old key still residing on your yubikey. You can now use the old key to sign the new one in gpg as normal. Once you've done this, you can then sign the old key with the new:
Code:
gpg2 -u <newkeyid> --edit-key <oldkeyid>
Similarly, you can create a text document discussing the transition. This should include (but is not limited to) the old keyid (with full fingerprint), the new keyid (with full fingerprint), and the date of supersession. You can sign this statement with both keys via the -u flag to specify which key to use.
Last steps.
If this is your only copy of the old master key, you should revoke it now, and in the revocation statement you should include a supersession statement (include the date of supersession and the full fingerprint of the new key).
EDIT: if you have the master backed up somewhere, you should make the new key a revoker on it (edit the old key and use "addrevoker"), and hold off on revoking the old key for a short while after posting the supersession statement. This helps keep it from looking as suspicious as an immediate creation -> revocation would.Before moving the new keys onto the yubikey, you should make a backup (
EDIT: this should be kept somewhere safe, such as on an encrypted flash drive and stored in a safe):
Code:
gpg2 --export-secret-keys --armour <newkeyid> > privkey.bak.asc
Next we want to get the master key off of this system:
Code:
gpg2 --export-secret-subkeys <newkeyid> > subkeys.asc
gpg2 --delete-secret-key <newkeyid>
gpg2 --import subkeys.asc
shred --remove subkeys.asc
Check the key and you should now
only see the Encryption, Signing, and (if you made one) Authentication subkeys.
Finally, we can move the keys to the yubikey. Simply open your new key for editing again and use the "keytocard" command to move the signing, encryption, and authentication keys to the yubikey.
Congratulations, you're done! You've now migrated to a new key and have a secure setup. In the event your yubikey is lost, you still have a backup of the master key, and more importantly, the master key itself has not been compromised; you can simply revoke the keys on the yubikey and generate new ones, without losing the signatures others have placed on your key.
I hope that helped :)
[b]EDIT: Final note: only a key with the C(ertification) usage can be used to sign keys (including the signature required to extend the expiry or add new subkeys), and per RFC 4880, only the master key should be permitted to Certify. This means that you will need to use the backup in order to perform those actions or sign other people's keys. This is feasible because, in general, these activities are relatively rare. A more secure setup would involve the use of a second token (such as yubikey) in which you store the master key, so that your master is not exposed when you need to use it (in theory it would take destructive methods and probably a SEM to extract the secret key from the secure module, and let's be honest, that means your adversary is a government, in which case they've got far more effective methods of getting you to turn it over, and you've got far bigger problems than losing your keys).