]> granicus.if.org Git - neomutt/commitdiff
Handle the same secret key appearing in multiple public keyrings
authorJulian Gilbey <julian-git@d-and-j.net>
Thu, 18 Apr 2019 15:30:38 +0000 (16:30 +0100)
committerRichard Russon <rich@flatcap.org>
Sun, 5 May 2019 00:00:38 +0000 (01:00 +0100)
Allow for S/MIME keys and the possibility of missing subkeys

Co-authored-by: Richard Russon <rich@flatcap.org>
ncrypt/crypt_gpgme.c

index d3980b2114eccc4cef03b723b5792ffe263224d1..e29d806db1c9fcadec623d77f153493a56438073 100644 (file)
@@ -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);