From 877c6762df3edceded947ddec1c9c0e9bf34f057 Mon Sep 17 00:00:00 2001 From: Julian Gilbey Date: Thu, 18 Apr 2019 16:30:38 +0100 Subject: [PATCH] Handle the same secret key appearing in multiple public keyrings Allow for S/MIME keys and the possibility of missing subkeys Co-authored-by: Richard Russon --- ncrypt/crypt_gpgme.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/ncrypt/crypt_gpgme.c b/ncrypt/crypt_gpgme.c index d3980b211..e29d806db 100644 --- a/ncrypt/crypt_gpgme.c +++ b/ncrypt/crypt_gpgme.c @@ -1118,6 +1118,7 @@ static int set_signer(gpgme_ctx_t ctx, bool for_smime) gpgme_error_t err; gpgme_ctx_t listctx; gpgme_key_t key, key2; + char *fpr = NULL, *fpr2 = NULL; if (!signid || !*signid) return 0; @@ -1132,14 +1133,26 @@ static int set_signer(gpgme_ctx_t ctx, bool for_smime) mutt_error(_("secret key '%s' not found: %s"), signid, gpgme_strerror(err)); return -1; } - err = gpgme_op_keylist_next(listctx, &key2); - if (err == 0) + fpr = "fpr1"; + if (key->subkeys) + fpr = key->subkeys->fpr ? key->subkeys->fpr : key->subkeys->keyid; + while (gpgme_op_keylist_next(listctx, &key2) == 0) { - gpgme_key_unref(key); - gpgme_key_unref(key2); - gpgme_release(listctx); - mutt_error(_("ambiguous specification of secret key '%s'"), signid); - return -1; + fpr2 = "fpr2"; + if (key2->subkeys) + fpr2 = key2->subkeys->fpr ? key2->subkeys->fpr : key2->subkeys->keyid; + if (mutt_str_strcmp(fpr, fpr2)) + { + gpgme_key_unref(key); + gpgme_key_unref(key2); + gpgme_release(listctx); + mutt_error(_("ambiguous specification of secret key `%s'\n"), signid); + return -1; + } + else + { + gpgme_key_unref(key2); + } } gpgme_op_keylist_end(listctx); gpgme_release(listctx); -- 2.40.0