From c60814a5ce13932d933b363abc0c60c12783ae2f Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Mon, 13 Oct 2014 14:01:29 +0200 Subject: gpg: Allow importing keys with duplicated long key ids. * g10/keydb.c (keydb_handle): Add field no_caching. (keyblock_cache): Repalce field kid by fpr. (keydb_disable_caching): New. (keydb_search): Use the fingerprint as cache index. * g10/import.c (import_one): Use the fingerprint and not the kid to lookup the key. Call keydb_disable_caching beofre re-searching for update. * tests/openpgp/import.test: Add a test case. Signed-off-by: Werner Koch --- g10/import.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'g10/import.c') diff --git a/g10/import.c b/g10/import.c index ca35ce1b9..be2fd6302 100644 --- a/g10/import.c +++ b/g10/import.c @@ -855,12 +855,15 @@ import_one (ctrl_t ctrl, PKT_public_key *pk_orig; KBNODE node, uidnode; KBNODE keyblock_orig = NULL; + byte fpr2[MAX_FINGERPRINT_LEN]; + size_t fpr2len; u32 keyid[2]; int rc = 0; int new_key = 0; int mod_key = 0; int same_key = 0; int non_self = 0; + size_t an; char pkstrbuf[PUBKEY_STRING_SIZE]; /* get the key and print some info about it */ @@ -870,6 +873,9 @@ import_one (ctrl_t ctrl, pk = node->pkt->pkt.public_key; + fingerprint_from_pk (pk, fpr2, &fpr2len); + for (an = fpr2len; an < MAX_FINGERPRINT_LEN; an++) + fpr2[an] = 0; keyid_from_pk( pk, keyid ); uidnode = find_next_kbnode( keyblock, PKT_USER_ID ); @@ -957,7 +963,7 @@ import_one (ctrl_t ctrl, /* do we have this key already in one of our pubrings ? */ pk_orig = xmalloc_clear( sizeof *pk_orig ); - rc = get_pubkey_fast ( pk_orig, keyid ); + rc = get_pubkey_byfprint_fast (pk_orig, fpr2, fpr2len); if( rc && rc != G10ERR_NO_PUBKEY && rc != G10ERR_UNU_PUBKEY ) { if (!silent) @@ -1033,17 +1039,11 @@ import_one (ctrl_t ctrl, goto leave; } - /* now read the original keyblock */ + /* Now read the original keyblock again so that we can use + that handle for updating the keyblock. */ hd = keydb_new (); - { - byte afp[MAX_FINGERPRINT_LEN]; - size_t an; - - fingerprint_from_pk (pk_orig, afp, &an); - while (an < MAX_FINGERPRINT_LEN) - afp[an++] = 0; - rc = keydb_search_fpr (hd, afp); - } + keydb_disable_caching (hd); + rc = keydb_search_fpr (hd, fpr2); if( rc ) { log_error (_("key %s: can't locate original keyblock: %s\n"), @@ -1051,7 +1051,7 @@ import_one (ctrl_t ctrl, keydb_release (hd); goto leave; } - rc = keydb_get_keyblock (hd, &keyblock_orig ); + rc = keydb_get_keyblock (hd, &keyblock_orig); if (rc) { log_error (_("key %s: can't read original keyblock: %s\n"), -- cgit v1.2.3 From 21c0ea6bafafbcc4a2e07f0ac76275cc0229e9a0 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Mon, 13 Oct 2014 14:54:26 +0200 Subject: gpg: Fix informative printing of user ids. * g10/getkey.c (keyid_list): Add field "fpr". (cache_user_id): Store fpr and check for dups only by fpr. (get_pubkey_byfpr): New. (get_user_id_string): Make static and use xasprintf. (get_long_user_id_string): Use xasprintf. (get_user_id_byfpr): New. (get_user_id_byfpr_native): New. * g10/keyid.c (fingerprint_from_pk): Make arg RET_LEN optional. * g10/import.c (import_one): Use get_user_id_byfpr_native. -- We now cache the userids using the fingerprint. This allows to print the correct user id for keys with a duplicated key id. We should eventually start to retire the use of all the old keyid based functions. However, at some places we only have the keyid and thus some of them will need to be kept (maybe changed with an indication to show that more than several user ids are matching). Signed-off-by: Werner Koch --- g10/import.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'g10/import.c') diff --git a/g10/import.c b/g10/import.c index be2fd6302..8f7595c7f 100644 --- a/g10/import.c +++ b/g10/import.c @@ -1009,9 +1009,9 @@ import_one (ctrl_t ctrl, /* we are ready */ if( !opt.quiet && !silent) { - char *p=get_user_id_native (keyid); - log_info( _("key %s: public key \"%s\" imported\n"), - keystr(keyid),p); + char *p = get_user_id_byfpr_native (fpr2); + log_info (_("key %s: public key \"%s\" imported\n"), + keystr(keyid), p); xfree(p); } if( is_status_enabled() ) @@ -1094,7 +1094,7 @@ import_one (ctrl_t ctrl, /* we are ready */ if( !opt.quiet && !silent) { - char *p=get_user_id_native(keyid); + char *p = get_user_id_byfpr_native (fpr2); if( n_uids == 1 ) log_info( _("key %s: \"%s\" 1 new user ID\n"), keystr(keyid),p); @@ -1145,7 +1145,7 @@ import_one (ctrl_t ctrl, if( !opt.quiet && !silent) { - char *p=get_user_id_native(keyid); + char *p = get_user_id_byfpr_native (fpr2); log_info( _("key %s: \"%s\" not changed\n"),keystr(keyid),p); xfree(p); } -- cgit v1.2.3 From fab89f159bcb36ea7285af661d5756eefa981822 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Mon, 13 Oct 2014 15:00:39 +0200 Subject: gpg: Remove extra RSA import status line. * g10/import.c (stats_s): Remove field "imported_rsa". (import_print_stats): Do not print separate value for RSA. (import_one): Remove the RSA counter. -- RSA is the standard key format and thus there is no more need to have a separate counter. This is a remain from the RSA patent times. Signed-off-by: Werner Koch --- g10/import.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'g10/import.c') diff --git a/g10/import.c b/g10/import.c index 8f7595c7f..16e2b0b4b 100644 --- a/g10/import.c +++ b/g10/import.c @@ -45,7 +45,6 @@ struct stats_s { ulong count; ulong no_user_id; ulong imported; - ulong imported_rsa; ulong n_uids; ulong n_sigs; ulong n_subk; @@ -399,10 +398,8 @@ import_print_stats (void *hd) stats->skipped_new_keys ); if( stats->no_user_id ) log_info(_(" w/o user IDs: %lu\n"), stats->no_user_id ); - if( stats->imported || stats->imported_rsa ) { + if( stats->imported) { log_info(_(" imported: %lu"), stats->imported ); - if (stats->imported_rsa) - log_printf (" (RSA: %lu)", stats->imported_rsa ); log_printf ("\n"); } if( stats->unchanged ) @@ -431,11 +428,10 @@ import_print_stats (void *hd) if( is_status_enabled() ) { char buf[14*20]; - sprintf(buf, "%lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu", + sprintf(buf, "%lu %lu %lu 0 %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu", stats->count, stats->no_user_id, stats->imported, - stats->imported_rsa, stats->unchanged, stats->n_uids, stats->n_subk, @@ -1022,8 +1018,6 @@ import_one (ctrl_t ctrl, print_import_ok (pk, 1); } stats->imported++; - if( is_RSA( pk->pubkey_algo ) ) - stats->imported_rsa++; new_key = 1; } else { /* merge */ -- cgit v1.2.3