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

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