From 936ee01d0da88019a04be28f2dcfe70d60bcb275 Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Sat, 13 Aug 2016 17:12:49 -0400 Subject: [PATCH] SAVE: Obtain the public key after key generation. There are no recipients after key generation completes so do a LISTKEYS on the generated signing key to determine the public encryption key. Fixes KEYINFO not showing any public key. This also changes the GENKEY status message to append both the signing and encryption key after genkey completes. --- doc/pwmd.html | 5 +++-- doc/pwmd.texi | 5 +++-- src/crypto.c | 34 ++++++++++++++++++++++++++++------ 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/doc/pwmd.html b/doc/pwmd.html index d8e94bb1..522d7ba2 100644 --- a/doc/pwmd.html +++ b/doc/pwmd.html @@ -1636,9 +1636,10 @@ status message is sent is determined by the keepalive_interval status message is sent is determined by the keepalive_interval (see Configuration) setting. GENKEY -Sent to the current client during key generation. How often this +[<sigkey_fpr> <pubkey_fpr>]Sent to the current client during key generation. How often this status message is sent is determined by the keepalive_interval -(see Configuration) setting. +(see Configuration) setting. The sigkey_fpr and pubkey_fpr +parameters are added when key generation has completed. INQUIRE_MAXLEN <bytes>Sent to the client from gpg-agent when inquiring data. This specifies the maximum number of bytes allowed for the client to send and diff --git a/doc/pwmd.texi b/doc/pwmd.texi index e837db47..83b1a54c 100644 --- a/doc/pwmd.texi +++ b/doc/pwmd.texi @@ -639,10 +639,11 @@ status message is sent is determined by the @code{keepalive_interval} @item GENKEY @cindex GENKEY -@tab +@tab @code{[ ]} @tab Sent to the current client during key generation. How often this status message is sent is determined by the @code{keepalive_interval} -(@pxref{Configuration}) setting. +(@pxref{Configuration}) setting. The @var{sigkey_fpr} and @var{pubkey_fpr} +parameters are added when key generation has completed. @item INQUIRE_MAXLEN @cindex INQUIRE_MAXLEN diff --git a/src/crypto.c b/src/crypto.c index f0e69eb2..d422f84e 100644 --- a/src/crypto.c +++ b/src/crypto.c @@ -507,7 +507,8 @@ fail: return rc; } -/* Converts a 40 byte key id to the 16 byte form. */ +/* Converts a 40 byte key id to the 16 byte form. Needed for comparison of + * gpgme_subkey_t->fpr. */ void crypto_keyid_to_16b (char **keys) { @@ -1035,15 +1036,36 @@ crypto_genkey (struct client_s *client, struct crypto_s *crypto, if (!rc) { + gpgme_key_t *keys = NULL; + result = gpgme_op_genkey_result (crypto->ctx); - crypto->save.pubkey = strv_cat (crypto->save.pubkey, - str_dup (result->fpr)); - crypto_keyid_to_16b (crypto->save.pubkey); crypto->save.sigkey = strv_cat (crypto->save.sigkey, str_dup (result->fpr)); crypto_keyid_to_16b (crypto->save.sigkey); - rc = send_status (client ? client->ctx : NULL, STATUS_GENKEY, "%s", - result->fpr); + + rc = crypto_list_keys (crypto, crypto->save.sigkey, 1, &keys); + if (!rc) + { + gpgme_subkey_t key = keys[0]->subkeys; + + for (; key; key = key->next) + { + if (key->can_encrypt) + break; + } + + pthread_cleanup_push ((void *)crypto_free_key_list, keys); + rc = send_status (client ? client->ctx : NULL, STATUS_GENKEY, "%s %s", + crypto->save.sigkey[0], key ? key->fpr : ""); + if (!rc) + { + crypto->save.pubkey = strv_cat (crypto->save.pubkey, + str_dup (key->fpr)); + crypto_keyid_to_16b (crypto->save.pubkey); + } + + pthread_cleanup_pop (1); + } } return rc; -- 2.11.4.GIT