简体   繁体   中英

How would you reconstruct a public key from the key s-expression and creation timestamp?

I'm specifically asking in relation to this answer where a user is trying to recreate the public key solely from the information in an openPGP Smartcard (due to losing the public key):

https://stackoverflow.com/a/69903994/17503333

The answer states that you should be able to reconstruct the public key from the information retrieved from the gpg-connect-agent through gpg and libcrypt itself, but does not specify how :

Take the creation time from the KEY-TIME lines. I used /decode and /hex above only for readability. You should use

 > /datafile out > scd readkey OPENPGP.1 OK > /bye

instead which writes the s-expression with the public key to the file out. The Libgcrypt functions take those s-expressions as arguments. Now you need to feed it to gpg to create the public key part and the self-signatures.

Is there any way to do this? There isn't any specific instructions online that specify what tools/functions within librypt and gpg to use to recreate the public key.

This may be done as following (assumming all required data is returned by the readkey):

  • You should parse s-exp and extract all key fields, this could be the guide: https://people.csail.mit.edu/rivest/sexp.html
  • Then you should build up in hex editor OpenPGP's public key packet, using RFC 4880 as a guide, filling all required fields.
  • Make sure you didn't make a mistake and fingerprint is correct (using the RFC 4880 on 'how to calculate fingerprint' as a guide).
  • Add self-signature for the key, using smart card to sign and build up the signature packet.
  • repeat the same for subkeys.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM