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.
} 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 &&
}
} 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 &&
--- /dev/null
+#!/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