From 9bcf53c1662548d457920cd415a2c7266c1128e2 Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Sun, 1 Apr 2012 15:02:24 -0700 Subject: [PATCH] Allow retrieval of key by full fingerprint GPG 1.4.12 switches to using the full fingerprint of a key when requesting a refresh (commit 6fe25e5602fabe92c68e5ba30e4777221e8612df). We were only supporting retrieval by 32 or 64 bit key ID. Detect when we're passed a fingerprint and truncate it to the last 64 bits so we can look it up. In the future we probably want to extend to being able to do lookups by full fingerprint. --- lookup.c | 12 +++++++++++- onak.c | 12 +++++++++++- t/all-060-get-fingerprint.t | 14 ++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100755 t/all-060-get-fingerprint.t diff --git a/lookup.c b/lookup.c index cdd8c72..273afc2 100644 --- a/lookup.c +++ b/lookup.c @@ -123,7 +123,17 @@ int main(int argc, char *argv[]) } else if (!strcmp(params[i], "search")) { search = params[i+1]; params[i+1] = NULL; - if (search != NULL) { + if (search != NULL && strlen(search) == 42 && + search[0] == '0' && search[1] == 'x') { + /* + * Fingerprint. Truncate to last 64 bits for + * now. + */ + keyid = strtoull(&search[26], &end, 16); + if (end != NULL && *end == 0) { + ishex = true; + } + } else if (search != NULL) { keyid = strtoull(search, &end, 16); if (*search != 0 && end != NULL && diff --git a/onak.c b/onak.c index b295fea..e4f3105 100644 --- a/onak.c +++ b/onak.c @@ -288,7 +288,17 @@ int main(int argc, char *argv[]) } } else if ((argc - optind) == 2) { search = argv[optind+1]; - if (search != NULL) { + if (search != NULL && strlen(search) == 42 && + search[0] == '0' && search[1] == 'x') { + /* + * Fingerprint. Truncate to last 64 bits for + * now. + */ + keyid = strtoull(&search[26], &end, 16); + if (end != NULL && *end == 0) { + ishex = true; + } + } else if (search != NULL) { keyid = strtoul(search, &end, 16); if (*search != 0 && end != NULL && diff --git a/t/all-060-get-fingerprint.t b/t/all-060-get-fingerprint.t new file mode 100755 index 0000000..920e9a3 --- /dev/null +++ b/t/all-060-get-fingerprint.t @@ -0,0 +1,14 @@ +#!/bin/sh +# Check we can retrieve a key by key fingerprint + +set -e + +cd t +../onak -b -c test.conf add < ../keys/noodles.key +if ! ../onak -c test.conf get 0x0E3A94C3E83002DAB88CCA1694FA372B2DA8B985 2> /dev/null | \ + grep -q -- '-----BEGIN PGP PUBLIC KEY BLOCK-----'; then + echo "* Did not correctly retrieve key by keyid." + exit 1 +fi + +exit 0 -- 2.39.5