Blame SOURCES/gnupg-2.2.18-gpg-allow-import-of-previously-known-keys-even-without-UI.patch

4538af
From: Vincent Breitmoser <look@my.amazin.horse>
4538af
Date: Thu, 13 Jun 2019 21:27:42 +0200
4538af
Subject: gpg: allow import of previously known keys, even without UIDs
4538af
4538af
* g10/import.c (import_one): Accept an incoming OpenPGP certificate that
4538af
has no user id, as long as we already have a local variant of the cert
4538af
that matches the primary key.
4538af
4538af
--
4538af
4538af
This fixes two of the three broken tests in import-incomplete.scm.
4538af
4538af
GnuPG-Bug-id: 4393
4538af
Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
4538af
---
4538af
 g10/import.c | 44 +++++++++++---------------------------------
4538af
 1 file changed, 11 insertions(+), 33 deletions(-)
4538af
4538af
diff --git a/g10/import.c b/g10/import.c
4538af
index 5d3162c..f9acf95 100644
4538af
--- a/g10/import.c
4538af
+++ b/g10/import.c
4538af
@@ -1788,7 +1788,6 @@ import_one_real (ctrl_t ctrl,
4538af
   size_t an;
4538af
   char pkstrbuf[PUBKEY_STRING_SIZE];
4538af
   int merge_keys_done = 0;
4538af
-  int any_filter = 0;
4538af
   KEYDB_HANDLE hd = NULL;
4538af
 
4538af
   if (r_valid)
4538af
@@ -1825,14 +1824,6 @@ import_one_real (ctrl_t ctrl,
4538af
       log_printf ("\n");
4538af
     }
4538af
 
4538af
-
4538af
-  if (!uidnode )
4538af
-    {
4538af
-      if (!silent)
4538af
-        log_error( _("key %s: no user ID\n"), keystr_from_pk(pk));
4538af
-      return 0;
4538af
-    }
4538af
-
4538af
   if (screener && screener (keyblock, screener_arg))
4538af
     {
4538af
       log_error (_("key %s: %s\n"), keystr_from_pk (pk),
4538af
@@ -1907,17 +1898,10 @@ import_one_real (ctrl_t ctrl,
4538af
 	  }
4538af
     }
4538af
 
4538af
-  if (!delete_inv_parts (ctrl, keyblock, keyid, options ) )
4538af
-    {
4538af
-      if (!silent)
4538af
-        {
4538af
-          log_error( _("key %s: no valid user IDs\n"), keystr_from_pk(pk));
4538af
-          if (!opt.quiet )
4538af
-            log_info(_("this may be caused by a missing self-signature\n"));
4538af
-        }
4538af
-      stats->no_user_id++;
4538af
-      return 0;
4538af
-    }
4538af
+  /* Delete invalid parts, and note if we have any valid ones left.
4538af
+   * We will later abort import if this key is new but contains
4538af
+   * no valid uids.  */
4538af
+  delete_inv_parts (ctrl, keyblock, keyid, options);
4538af
 
4538af
   /* Get rid of deleted nodes.  */
4538af
   commit_kbnode (&keyblock);
4538af
@@ -1927,24 +1911,11 @@ import_one_real (ctrl_t ctrl,
4538af
     {
4538af
       apply_keep_uid_filter (ctrl, keyblock, import_filter.keep_uid);
4538af
       commit_kbnode (&keyblock);
4538af
-      any_filter = 1;
4538af
     }
4538af
   if (import_filter.drop_sig)
4538af
     {
4538af
       apply_drop_sig_filter (ctrl, keyblock, import_filter.drop_sig);
4538af
       commit_kbnode (&keyblock);
4538af
-      any_filter = 1;
4538af
-    }
4538af
-
4538af
-  /* If we ran any filter we need to check that at least one user id
4538af
-   * is left in the keyring.  Note that we do not use log_error in
4538af
-   * this case. */
4538af
-  if (any_filter && !any_uid_left (keyblock))
4538af
-    {
4538af
-      if (!opt.quiet )
4538af
-        log_info ( _("key %s: no valid user IDs\n"), keystr_from_pk (pk));
4538af
-      stats->no_user_id++;
4538af
-      return 0;
4538af
     }
4538af
 
4538af
   /* The keyblock is valid and ready for real import.  */
4538af
@@ -2002,6 +1973,13 @@ import_one_real (ctrl_t ctrl,
4538af
       err = 0;
4538af
       stats->skipped_new_keys++;
4538af
     }
4538af
+  else if (err && !any_uid_left (keyblock))
4538af
+    {
4538af
+      if (!silent)
4538af
+        log_info( _("key %s: new key but contains no user ID - skipped\n"), keystr(keyid));
4538af
+      err = 0;
4538af
+      stats->no_user_id++;
4538af
+    }
4538af
   else if (err)  /* Insert this key. */
4538af
     {
4538af
       /* Note: ERR can only be NO_PUBKEY or UNUSABLE_PUBKEY.  */