gpg: Do not bail out on v5 keys in the local keyring.
authorWerner Koch <wk@gnupg.org>
Mon, 18 Mar 2019 13:10:16 +0000 (14:10 +0100)
committerDaniel Kahn Gillmor <dkg@fifthhorseman.net>
Fri, 1 Jul 2022 16:06:43 +0000 (17:06 +0100)
* g10/parse-packet.c (parse_key): Return GPG_ERR_UNKNOWN_VERSION
instead of invalid packet.
* g10/keydb.c (parse_keyblock_image): Do not map the unknown version
error to invalid keyring.
(keydb_search): Skip unknown version errors simlar to legacy keys.
* g10/keyring.c (keyring_rebuild_cache): Skip keys with unknown
versions.
* g10/import.c (read_block): Handle unknown version.
--

When using gpg 2.3 the local keyring may contain v5 keys.  This patch
allows the use of such a keyring also with a 2.2 version which does
not support v5 keys.  We will probably need some more tweaking here
but this covers the most common cases of listing keys and also
importing v5 keys.

Signed-off-by: Werner Koch <wk@gnupg.org>
(cherry picked from commit de70a2f377c1647417fb8a2b6476c3744a901296)

Gbp-Pq: Topic from-2.2.14
Gbp-Pq: Name gpg-Do-not-bail-out-on-v5-keys-in-the-local-keyring.patch

g10/import.c
g10/keydb.c
g10/keylist.c
g10/keyring.c
g10/parse-packet.c

index f76ca0c21b524db59e57261a84d07abe33b2bccd..aeab4e0d5d6aa81b646ebba476ad87d4e71aba80 100644 (file)
@@ -860,12 +860,14 @@ read_block( IOBUF a, int with_meta,
   skip_sigs = 0;
   while ((rc=parse_packet (&parsectx, pkt)) != -1)
     {
-      if (rc && (gpg_err_code (rc) == GPG_ERR_LEGACY_KEY
+      if (rc && ((gpg_err_code (rc) == GPG_ERR_LEGACY_KEY
+                 || gpg_err_code (rc) == GPG_ERR_UNKNOWN_VERSION)
                  && (pkt->pkttype == PKT_PUBLIC_KEY
                      || pkt->pkttype == PKT_SECRET_KEY)))
         {
           in_v3key = 1;
-          ++*r_v3keys;
+          if (gpg_err_code (rc) != GPG_ERR_UNKNOWN_VERSION)
+            ++*r_v3keys;
           free_packet (pkt, &parsectx);
           init_packet (pkt);
           continue;
index 03fadfd542df725aa98990cbe159c9f8185564fb..0475f8561a12c252f5ff6663ddf346b212941b84 100644 (file)
@@ -1249,9 +1249,12 @@ parse_keyblock_image (iobuf_t iobuf, int pk_no, int uid_no,
        }
       if (err)
         {
-          log_error ("parse_keyblock_image: read error: %s\n",
-                     gpg_strerror (err));
-          err = gpg_error (GPG_ERR_INV_KEYRING);
+          if (gpg_err_code (err) != GPG_ERR_UNKNOWN_VERSION)
+            {
+              log_error ("parse_keyblock_image: read error: %s\n",
+                         gpg_strerror (err));
+              err = gpg_error (GPG_ERR_INV_KEYRING);
+            }
           break;
         }
 
@@ -1955,7 +1958,9 @@ keydb_search (KEYDB_HANDLE hd, KEYDB_SEARCH_DESC *desc,
             rc = keybox_search (hd->active[hd->current].u.kb, desc,
                                 ndesc, KEYBOX_BLOBTYPE_PGP,
                                 descindex, &hd->skipped_long_blobs);
-          while (rc == GPG_ERR_LEGACY_KEY);
+          while (gpg_err_code (rc) == GPG_ERR_LEGACY_KEY
+                 || gpg_err_code (rc) == GPG_ERR_UNKNOWN_VERSION)
+            ;
           break;
         }
 
index 7b3fde188a13b9d43f998db09af22b760ab43053..85fcdbaff3a9fe24ad689873ca18a0c525398bbc 100644 (file)
@@ -527,6 +527,8 @@ list_all (ctrl_t ctrl, int secret, int mark_secret)
        {
           if (gpg_err_code (rc) == GPG_ERR_LEGACY_KEY)
             continue;  /* Skip legacy keys.  */
+          if (gpg_err_code (rc) == GPG_ERR_UNKNOWN_VERSION)
+            continue;  /* Skip keys with unknown versions.  */
          log_error ("keydb_get_keyblock failed: %s\n", gpg_strerror (rc));
          goto leave;
        }
index 25ef50747173f13b8f2cd76903b3a84bf3c3bdbf..a8dd462652e26c7ca7f082809ceba6ec602abd81 100644 (file)
@@ -1476,6 +1476,8 @@ keyring_rebuild_cache (ctrl_t ctrl, void *token, int noisy)
         {
           if (gpg_err_code (rc) == GPG_ERR_LEGACY_KEY)
             continue;  /* Skip legacy keys.  */
+          if (gpg_err_code (rc) == GPG_ERR_UNKNOWN_VERSION)
+            continue;  /* Skip keys with unknown version.  */
           log_error ("keyring_get_keyblock failed: %s\n", gpg_strerror (rc));
           goto leave;
         }
index ff348ec693df133f32ef48e1fc682b62f7cbada4..05f63e928aeb445aa7667e4727a5faaa277f5430 100644 (file)
@@ -2296,7 +2296,7 @@ parse_key (IOBUF inp, int pkttype, unsigned long pktlen,
       log_error ("packet(%d) with unknown version %d\n", pkttype, version);
       if (list_mode)
         es_fputs (":key packet: [unknown version]\n", listfp);
-      err = gpg_error (GPG_ERR_INV_PACKET);
+      err = gpg_error (GPG_ERR_UNKNOWN_VERSION);
       goto leave;
     }