From: Jonathan McDowell Date: Sun, 1 Apr 2012 22:02:24 +0000 (-0700) Subject: Allow retrieval of key by full fingerprint X-Git-Tag: onak-0.4.1~8 X-Git-Url: https://the.earth.li/gitweb/?a=commitdiff_plain;h=9bcf53c1662548d457920cd415a2c7266c1128e2;p=onak.git 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. --- 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