Skip to content

Instantly share code, notes, and snippets.

@sts10
Last active February 8, 2018 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sts10/3b7ecd4bee15705762e634d6a203a6e3 to your computer and use it in GitHub Desktop.
Save sts10/3b7ecd4bee15705762e634d6a203a6e3 to your computer and use it in GitHub Desktop.
Question about OpenPGP and YubiKey

Below is a step-by-step guide to test whether I could get a secret PGP key off of my YubiKey.

  1. On Computer 1, generate a GPG key pair.
  2. More your secret key to a YubiKey, following the instructions on this wedpage under "Generating the key on your local system"
  3. On computer 2, import the public key of the key pair.
  4. Still on computer 2, insert your YubiKey. Then create a stub for the secret key by running gpg --card-status source
  5. Unplug YubiKey.
  6. On computer 2, run gpg --export-secret-keys -a KEYID > secret.asc, filling in the KEYID with the key id.
  7. A private key is now in the file secret.asc

Question: is the key in secret.asc the private key of the key pair? Did we just successfully get a secret key off of a YubiKey without it even being plugged in? Or is the key in the secrets.asc merely some "stub" placeholder?

In an attempet to answer these questions, I took the following steps. I never plugged the YubiKey into the computer.

  1. On computer 2, with the YubiKey unplugged, run mkdir export && cd export
  2. gpg --export -a KEYID > public.asc
  3. gpg --export-secret-keys -a KEYID > secret.asc
  4. Using a GUI application, delete key pair from this computer
  5. Import key pair from export folder
  6. Encrypt a test file for this key pair: gpg -e test.txt, then when prompted, enter KEYID
  7. Attempt to decrypt this file: gpg -d test.txt.gpg

Thankfully, step 14 seems to fail with the following error:

gpg: public key decryption failed: Card error
gpg: decryption failed: No secret key

which seems to mean the secret key we exported in step 6 is not the real secret key contained on the YubiKey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment