Is there a way to tell GPG, that if it needs to decrypt something, that it can find the private encryption key on one of two smart cards?
My (simplified) setup is as follows:
- Generated a master key offline with an encryption subkey.
- Transferred the encryption subkey to Yubikey 1.
- On Yubikey 1, generated auth and sign subkeys.
- Transferred the encryption subkey to Yubikey 2.
- On Yubikey 2, generated auth and sign subkeys.
So I am left with:
gpg2 --list-keys
/Users/scott/.gnupg/pubring.gpg
-------------------------------
pub 3072R/600955C7 2016-09-09
uid [ultimate] Scott Cariss
uid [ultimate] Scott Cariss (msn.com)
uid [ultimate] Scott Cariss (bigfish.co.uk)
uid [ultimate] [jpeg image of size 12378]
sub 2048R/6FE6415F 2016-09-09
sub 2048R/D6DBBCAC 2016-09-09
sub 2048R/01A208C9 2016-09-09
sub 2048R/8D2A1368 2016-10-23
sub 2048R/65B08C5B 2016-10-23
My encryption subkey is shared between smart cards and have individual auth and sign keys on each smart card.
But when I come to decrypt something it always goes to the first smart card and won't find the encryption key on the other smart card. The gpg-agent/pin entry will just ask me to insert the correct smart card.
UPDATE (Workaround)
As already answered, it is not something that GPG supports but I have found a working solution that works for me.
On Mac OS X I use https://www.controlplaneapp.com/ to detect the arrival of one of my smart cards (yubikeys) and get it to run a script:
#!/bin/bash
{
killall -9 ssh-agent gpg-agent
for keystub in $(/usr/local/MacGPG2/bin/gpg2 --with-keygrip --list-secret-keys {{EMAIL ADDRESS}} | grep Keygrip | awk '{print $3}'); do rm /Users/{{USERNAME}}/.gnupg/private-keys-v1.d/$keystub.key; done;
/usr/local/MacGPG2/bin/gpg2 --card-status
eval $(/usr/local/MacGPG2/bin/gpgconf --launch gpg-agent)
ssh-add -l
} &> /Users/{{USERNAME}}/bin/gpg-card-change-log.txt
exit 0
As the secret keys are all kept offline, there is no harm in deleting them and then running --card-status
which brings in the secret key stubs from the smart card currently plugged in.