]> the.earth.li Git - onak.git/commitdiff
Allow retrieval of key by full fingerprint
authorJonathan McDowell <noodles@earth.li>
Sun, 1 Apr 2012 22:02:24 +0000 (15:02 -0700)
committerJonathan McDowell <noodles@earth.li>
Sun, 1 Apr 2012 22:02:24 +0000 (15:02 -0700)
  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
onak.c
t/all-060-get-fingerprint.t [new file with mode: 0755]

index cdd8c72c23e52bbe2a7d102302abee1d492d8422..273afc225c04d567636d92bcfc50d44eaa541752 100644 (file)
--- 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 b295fea2126ca772fc96869d59bd180cdd7b8f31..e4f3105ec9f4fd5e45b740b40f7d20e0e8f9af94 100644 (file)
--- 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 (executable)
index 0000000..920e9a3
--- /dev/null
@@ -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