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/keydb.h | 1 + 1 file changed, 1 insertion(+) (limited to 'g10/keydb.h') diff --git a/g10/keydb.h b/g10/keydb.h index 78d151a51..55f8fc22b 100644 --- a/g10/keydb.h +++ b/g10/keydb.h @@ -135,6 +135,7 @@ gpg_error_t keydb_add_resource (const char *url, unsigned int flags); KEYDB_HANDLE keydb_new (void); void keydb_release (KEYDB_HANDLE hd); +void keydb_disable_caching (KEYDB_HANDLE hd); const char *keydb_get_resource_name (KEYDB_HANDLE hd); gpg_error_t keydb_get_keyblock (KEYDB_HANDLE hd, KBNODE *ret_kb); gpg_error_t keydb_update_keyblock (KEYDB_HANDLE hd, kbnode_t kb); -- 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/keydb.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'g10/keydb.h') diff --git a/g10/keydb.h b/g10/keydb.h index 55f8fc22b..c61e0ae18 100644 --- a/g10/keydb.h +++ b/g10/keydb.h @@ -222,6 +222,7 @@ int get_pubkey_bynames( GETKEY_CTX *rx, PKT_public_key *pk, int get_pubkey_next( GETKEY_CTX ctx, PKT_public_key *pk, KBNODE *ret_keyblock ); void get_pubkey_end( GETKEY_CTX ctx ); gpg_error_t get_seckey (PKT_public_key *pk, u32 *keyid); +gpg_error_t get_pubkey_byfpr (PKT_public_key *pk, const byte *fpr); int get_pubkey_byfprint( PKT_public_key *pk, const byte *fprint, size_t fprint_len ); int get_pubkey_byfprint_fast (PKT_public_key *pk, @@ -252,11 +253,12 @@ gpg_error_t enum_secret_keys (void **context, PKT_public_key *pk); void setup_main_keyids (kbnode_t keyblock); void merge_keys_and_selfsig( KBNODE keyblock ); -char*get_user_id_string( u32 *keyid ); char*get_user_id_string_native( u32 *keyid ); char*get_long_user_id_string( u32 *keyid ); char*get_user_id( u32 *keyid, size_t *rn ); char*get_user_id_native( u32 *keyid ); +char *get_user_id_byfpr (const byte *fpr, size_t *rn); +char *get_user_id_byfpr_native (const byte *fpr); KEYDB_HANDLE get_ctx_handle(GETKEY_CTX ctx); void release_akl(void); int parse_auto_key_locate(char *options); -- cgit v1.2.3