Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get public key from an OpenPGP smart card without using key servers?

I am working on a use-case where OpenPGP is being used to generate a public key pair on a smart card (Yubikey).

The smart card is then to be shipped off to the user. Trying to emulate this locally the following is being done:

  1. generate keys on smart card
  2. remove GnuPG home directory
  3. access smart card to re-generate GnuPG home directory

The issue is that I cannot test encrypting a file after the above steps have been performed as the public key seems to be missing. fetch doesn't seem to work.

At this stage I do not want to share the public key on any online server. Is there any way of retrieving the public key from the smart card after deleting the key rings?

Below are the steps being followed:

$ gpg --card-edit                                                                                                                                                       

Reader ...........: 1050:0404:X:0
Application ID ...: D2760001240102010006046314290000
Version ..........: 2.1
Manufacturer .....: Yubico
Serial number ....: 04631429
Name of cardholder: sm sm
Language prefs ...: en
Sex ..............: unspecified
URL of public key : [not set]
Login data .......: sm
Signature PIN ....: not forced
Key attributes ...: rsa4096 rsa4096 rsa4096
Max. PIN lengths .: 127 127 127
PIN retry counter : 3 0 3
Signature counter : 0
Signature key ....: 54D4 E469 7056 B390 AE72  CAA1 A507 3320 7876 0302
      created ....: 2017-10-11 13:16:52
Encryption key....: ADA3 2D7F 8D66 4F34 C04A  457C DFEB E3E4 A8F1 8611
      created ....: 2017-10-11 11:14:18
Authentication key: 18B9 7AB4 0723 46F4 C23A  3DD7 E5C0 6A93 049E F6A8
      created ....: 2017-10-11 11:14:18
General key info..: [none]

gpg/card> admin
Admin commands are allowed

gpg/card> generate
Make off-card backup of encryption key? (Y/n) n

gpg: Note: keys are already stored on the card!

Replace existing keys? (y/N) y
What keysize do you want for the Signature key? (4096) 
What keysize do you want for the Encryption key? (4096) 
What keysize do you want for the Authentication key? (4096) 
Key is valid for? (0) 0
Is this correct? (y/N) y
Real name: john doe
Email address: [email protected]
Comment: 
You selected this USER-ID:
    "john doe <<[email protected]>"

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o

gpg: /home/xxx/.gnupg/trustdb.gpg: trustdb created
gpg: key 6825CB0EBDA94110 marked as ultimately trusted
gpg: directory '/home/xxx/.gnupg/openpgp-revocs.d' created
gpg: revocation certificate stored as '/home/xxx/.gnupg/openpgp-revocs.d/6858F119E93FB74BB561DE556825CB0EBDA94110.rev'
public and secret key created and signed.


gpg/card> list

Reader ...........: 1050:0404:X:0
Application ID ...: D2760001240102010006046314290000
Version ..........: 2.1
Manufacturer .....: Yubico
Serial number ....: 04631429
Name of cardholder: sm sm
Language prefs ...: en
Sex ..............: unspecified
URL of public key : [not set]
Login data .......: sm
Signature PIN ....: not forced
Key attributes ...: rsa4096 rsa4096 rsa4096
Max. PIN lengths .: 127 127 127
PIN retry counter : 3 0 3
Signature counter : 4
Signature key ....: 6858 F119 E93F B74B B561  DE55 6825 CB0E BDA9 4110
      created ....: 2017-10-11 13:18:11
Encryption key....: BE05 7FDF 9ACD 05F0 B75A  570F 4711 4B69 A622 C1DC
      created ....: 2017-10-11 13:18:11
Authentication key: 7275 2C47 B1EF BFB5 1E6D  0E65 31C7 7DBE 2D22 7E32
      created ....: 2017-10-11 13:18:11
General key info..: pub  rsa4096/6825CB0EBDA94110 2017-10-11     john doe <<[email protected]>
sec>  rsa4096/6825CB0EBDA94110  created: 2017-10-11  expires: never     
                                card-no: 0006 04631429
ssb>  rsa4096/31C77DBE2D227E32  created: 2017-10-11  expires: never     
                                card-no: 0006 04631429
ssb>  rsa4096/47114B69A622C1DC  created: 2017-10-11  expires: never     
                                card-no: 0006 04631429

gpg/card> quit

$ rm -rf .gnupg/

$ gpg --card-status                                                                                                                                                     
gpg: directory '/home/smalatho/.gnupg' created
gpg: new configuration file '/home/smalatho/.gnupg/dirmngr.conf' created
gpg: new configuration file '/home/smalatho/.gnupg/gpg.conf' created
gpg: keybox '/home/smalatho/.gnupg/pubring.kbx' created
Reader ...........: 1050:0404:X:0
Application ID ...: D2760001240102010006046314290000
Version ..........: 2.1
Manufacturer .....: Yubico
Serial number ....: 04631429
Name of cardholder: sm sm
Language prefs ...: en
Sex ..............: unspecified
URL of public key : [not set]
Login data .......: sm
Signature PIN ....: not forced
Key attributes ...: rsa4096 rsa4096 rsa4096
Max. PIN lengths .: 127 127 127
PIN retry counter : 3 0 3
Signature counter : 4
Signature key ....: 6858 F119 E93F B74B B561  DE55 6825 CB0E BDA9 4110
      created ....: 2017-10-11 13:18:11
Encryption key....: BE05 7FDF 9ACD 05F0 B75A  570F 4711 4B69 A622 C1DC
      created ....: 2017-10-11 13:18:11
Authentication key: 7275 2C47 B1EF BFB5 1E6D  0E65 31C7 7DBE 2D22 7E32
      created ....: 2017-10-11 13:18:11
General key info..: [none]
like image 586
Stelios Avatar asked Oct 11 '17 13:10

Stelios


People also ask

How do I find my PGP key ID?

To find your GPG key ID, look in the ID column next to the newly created key. In most cases, if you are asked for the key ID, you should prepend 0x to the last 8 characters of the key ID, as in 0x6789ABCD .

How do I send my PGP public key?

Send your PGP public keyWhen composing a message, click on Attach > Attach public key. This will attach your PGP public key to the message.


1 Answers

OpenPGP smart cards do not store enough information to reconstruct a full OpenPGP public key. You must import the public key separately -- sharing it on a key servers is one solution, but you can also gpg --export the key and later gpg --import it again for testing.

like image 184
Jens Erat Avatar answered Oct 18 '22 19:10

Jens Erat