diff options
author | Neal H. Walfield <neal@g10code.com> | 2015-12-02 20:51:52 +0100 |
---|---|---|
committer | Neal H. Walfield <neal@g10code.com> | 2015-12-03 00:00:54 +0100 |
commit | cedbd4709eed6fead9d1b271f96860c00547c77c (patch) | |
tree | fe95c27b0c0c7da51f0ef66bc0e1aa43444c514a /g10/gpg.c | |
parent | build: Require at least Libassuan 2.4.1. (diff) | |
download | gnupg2-cedbd4709eed6fead9d1b271f96860c00547c77c.tar.xz gnupg2-cedbd4709eed6fead9d1b271f96860c00547c77c.zip |
gpg: Use the matching key if the search description is exact.
* g10/gpg.c (check_user_ids): If the search description is for an
exact match (a keyid or fingerprint that ends in '!'), then use the
matching key, not the primary key.
* tests/openpgp/Makefile.am (TESTS): Add use-exact-key.test.
(priv_keys): Add privkeys/00FE67F28A52A8AA08FFAED20AF832DA916D1985.asc,
privkeys/1DF48228FEFF3EC2481B106E0ACA8C465C662CC5.asc,
privkeys/A2832820DC9F40751BDCD375BB0945BA33EC6B4C.asc,
privkeys/ADE710D74409777B7729A7653373D820F67892E0.asc and
privkeys/CEFC51AF91F68A2904FBFF62C4F075A4785B803F.asc.
(sample_keys): Add
samplekeys/E657FB607BB4F21C90BB6651BC067AF28BC90111.asc.
* tests/openpgp/privkeys/00FE67F28A52A8AA08FFAED20AF832DA916D1985.asc:
New file.
* tests/openpgp/privkeys/1DF48228FEFF3EC2481B106E0ACA8C465C662CC5.asc:
New file.
* tests/openpgp/privkeys/A2832820DC9F40751BDCD375BB0945BA33EC6B4C.asc:
New file.
* tests/openpgp/privkeys/ADE710D74409777B7729A7653373D820F67892E0.asc:
New file.
* tests/openpgp/privkeys/CEFC51AF91F68A2904FBFF62C4F075A4785B803F.asc:
New file.
* tests/openpgp/samplekeys/E657FB607BB4F21C90BB6651BC067AF28BC90111.asc:
New file.
* tests/openpgp/use-exact-key.test: New file.
* tests/openpgp/version.test: Install the new private keys.
--
Signed-off-by: Neal H. Walfield <neal@g10code.com>
Reported-by: Reported-by: Kristian Fiskerstrand
<kristian.fiskerstrand@sumptuouscapital.com>
Fixes-commit: 10cca02
Diffstat (limited to 'g10/gpg.c')
-rw-r--r-- | g10/gpg.c | 35 |
1 files changed, 31 insertions, 4 deletions
@@ -2196,19 +2196,46 @@ check_user_ids (strlist_t *sp, } pk = kb->pkt->pkt.public_key; - fingerprint_from_pk (pk, fingerprint_bin, &fingerprint_bin_len); - assert (fingerprint_bin_len == sizeof (fingerprint_bin)); - bin2hex (fingerprint_bin, MAX_FINGERPRINT_LEN, fingerprint); if ((desc.mode == KEYDB_SEARCH_MODE_SHORT_KID || desc.mode == KEYDB_SEARCH_MODE_LONG_KID || desc.mode == KEYDB_SEARCH_MODE_FPR16 || desc.mode == KEYDB_SEARCH_MODE_FPR20) && strchr (t->d, '!')) + /* Exact search. In this case we want to set FINGERPRINT not + to the primary key, but the key (primary or sub) that + matched the search criteria. Note: there will always be + exactly one match. */ { - int i = strlen (fingerprint); + kbnode_t n = kb; + PKT_public_key *match = NULL; + int i; + + do + { + if ((n->flag & 1)) + /* The matched node. */ + { + assert (! match); + match = n->pkt->pkt.public_key; + } + } + while ((n = find_next_kbnode (n, PKT_PUBLIC_SUBKEY))); + assert (match); + + fingerprint_from_pk (match, fingerprint_bin, &fingerprint_bin_len); + assert (fingerprint_bin_len == sizeof (fingerprint_bin)); + bin2hex (fingerprint_bin, MAX_FINGERPRINT_LEN, fingerprint); + + i = strlen (fingerprint); fingerprint[i] = '!'; fingerprint[i + 1] = '\0'; } + else + { + fingerprint_from_pk (pk, fingerprint_bin, &fingerprint_bin_len); + assert (fingerprint_bin_len == sizeof (fingerprint_bin)); + bin2hex (fingerprint_bin, MAX_FINGERPRINT_LEN, fingerprint); + } add_to_strlist (&s2, fingerprint); s2->flags = s->flags; |