From 6f3d11d8837b00e3a1c4fa881066855c0321d6b2 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Thu, 22 Jan 2015 12:14:48 +0100 Subject: [PATCH] gpg: Add dedicated error code for PGP-2 keys. * g10/parse-packet.c (parse_key): Return GPG_ERR_LEGACY_KEY for PGP2 keys. * g10/import.c (read_block): Simplify by checking GPG_ERR_LEGACY_KEY. * g10/getkey.c (lookup): Silence error message for PGP-2 keys. * common/util.h (GPG_ERR_LEGACY_KEY): Add replacement for older libgpg-error. Signed-off-by: Werner Koch --- common/util.h | 1 + g10/getkey.c | 5 ++--- g10/import.c | 6 ++---- g10/keyring.c | 4 +--- g10/parse-packet.c | 2 +- 5 files changed, 7 insertions(+), 11 deletions(-) diff --git a/common/util.h b/common/util.h index 94878bc36..24107f533 100644 --- a/common/util.h +++ b/common/util.h @@ -38,6 +38,7 @@ /* These error codes are used but not defined in the required libgpg-error version. Define them here. */ #if GPG_ERROR_VERSION_NUMBER < 0x011200 /* 1.18 */ +# define GPG_ERR_LEGACY_KEY 222 # define GPG_ERR_OBJ_TERM_STATE 225 # define GPG_ERR_FORBIDDEN 251 #endif diff --git a/g10/getkey.c b/g10/getkey.c index d240dd7d1..62d2d3306 100644 --- a/g10/getkey.c +++ b/g10/getkey.c @@ -403,8 +403,6 @@ get_pubkey (PKT_public_key * pk, u32 * keyid) if (!rc) goto leave; - log_debug ("looking up key %08X%08X failed: %s\n", keyid[0], keyid[1], - gpg_strerror (rc)); rc = GPG_ERR_NO_PUBKEY; leave: @@ -2573,7 +2571,8 @@ lookup (getkey_ctx_t ctx, kbnode_t *ret_keyblock, int want_secret) } found: - if (rc && gpg_err_code (rc) != GPG_ERR_NOT_FOUND) + if (rc && gpg_err_code (rc) != GPG_ERR_NOT_FOUND + && gpg_err_code (rc) != GPG_ERR_LEGACY_KEY) log_error ("keydb_search failed: %s\n", gpg_strerror (rc)); if (!rc) diff --git a/g10/import.c b/g10/import.c index 56121dbb1..de2252069 100644 --- a/g10/import.c +++ b/g10/import.c @@ -544,11 +544,9 @@ read_block( IOBUF a, PACKET **pending_pkt, kbnode_t *ret_root, int *r_v3keys) in_v3key = 0; while ((rc=parse_packet(a, pkt)) != -1) { - if (rc && (gpg_err_code (rc) == GPG_ERR_INV_PACKET + if (rc && (gpg_err_code (rc) == GPG_ERR_LEGACY_KEY && (pkt->pkttype == PKT_PUBLIC_KEY - || pkt->pkttype == PKT_SECRET_KEY) - && (pkt->pkt.public_key->version == 2 - || pkt->pkt.public_key->version == 3))) + || pkt->pkttype == PKT_SECRET_KEY))) { in_v3key = 1; ++*r_v3keys; diff --git a/g10/keyring.c b/g10/keyring.c index 7ac3478ad..34829e711 100644 --- a/g10/keyring.c +++ b/g10/keyring.c @@ -350,7 +350,7 @@ keyring_lock (KEYRING_HANDLE hd, int yes) /* - * Return the last found keyring. Caller must free it. + * Return the last found keyblock. Caller must free it. * The returned keyblock has the kbode flag bit 0 set for the node with * the public key used to locate the keyblock or flag bit 1 set for * the user ID node. @@ -1409,8 +1409,6 @@ keyring_rebuild_cache (void *token,int noisy) goto leave; } - log_debug ("keblock with version %d\n", - keyblock->pkt->pkt.public_key->version); if (keyblock->pkt->pkt.public_key->version < 4) { /* We do not copy/cache v3 keys or any other unknown diff --git a/g10/parse-packet.c b/g10/parse-packet.c index ae215c413..73c4434c1 100644 --- a/g10/parse-packet.c +++ b/g10/parse-packet.c @@ -1963,7 +1963,7 @@ parse_key (IOBUF inp, int pkttype, unsigned long pktlen, if (list_mode) es_fprintf (listfp, ":key packet: [obsolete version %d]\n", version); pk->version = version; - err = gpg_error (GPG_ERR_INV_PACKET); + err = gpg_error (GPG_ERR_LEGACY_KEY); goto leave; } else