#include "photoid.h"
#include "version.h"
-void find_keys(char *search, uint64_t keyid, bool ishex,
- bool fingerprint, bool skshash, bool exact, bool verbose)
+void find_keys(char *search, uint64_t keyid, uint8_t *fp, bool ishex,
+ bool isfp, bool fingerprint, bool skshash, bool exact,
+ bool verbose)
{
struct openpgp_publickey *publickey = NULL;
int count = 0;
if (ishex) {
- count = config.dbbackend->fetch_key(keyid, &publickey, false);
+ count = config.dbbackend->fetch_key_id(keyid, &publickey,
+ false);
+ } else if (isfp) {
+ count = config.dbbackend->fetch_key_fp(fp, MAX_FINGERPRINT_LEN,
+ &publickey, false);
} else {
count = config.dbbackend->fetch_key_text(search, &publickey);
}
return;
}
+static uint8_t hex2bin(char c)
+{
+ if (c >= '0' && c <= '9') {
+ return (c - '0');
+ } else if (c >= 'a' && c <= 'f') {
+ return (c - 'a' + 10);
+ } else if (c >= 'A' && c <= 'F') {
+ return (c - 'A' + 10);
+ }
+
+ return 255;
+}
+
void usage(void) {
puts("onak " ONAK_VERSION " - an OpenPGP keyserver.\n");
puts("Usage:\n");
char *search = NULL;
char *end = NULL;
uint64_t keyid = 0;
+ uint8_t fp[MAX_FINGERPRINT_LEN];
+ int i;
bool ishex = false;
+ bool isfp = false;
bool verbose = false;
bool update = false;
bool binary = false;
search = argv[optind+1];
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;
+ for (i = 0; i < MAX_FINGERPRINT_LEN; i++) {
+ fp[i] = (hex2bin(search[2 + i * 2]) << 4) +
+ hex2bin(search[3 + i * 2]);
}
+ isfp = true;
} else if (search != NULL) {
keyid = strtoul(search, &end, 16);
if (*search != 0 &&
}
config.dbbackend->initdb(false);
if (!strcmp("index", argv[optind])) {
- find_keys(search, keyid, ishex, fingerprint, skshash,
+ find_keys(search, keyid, fp, ishex, isfp,
+ fingerprint, skshash,
false, false);
} else if (!strcmp("vindex", argv[optind])) {
- find_keys(search, keyid, ishex, fingerprint, skshash,
+ find_keys(search, keyid, fp, ishex, isfp,
+ fingerprint, skshash,
false, true);
} else if (!strcmp("getphoto", argv[optind])) {
if (!ishex) {
puts("Can't get a key on uid text."
" You must supply a keyid.");
- } else if (config.dbbackend->fetch_key(keyid, &keys,
+ } else if (config.dbbackend->fetch_key_id(keyid, &keys,
false)) {
unsigned char *photo = NULL;
size_t length = 0;
- if (getphoto(keys, 0, &photo, &length)) {
+ if (getphoto(keys, 0, &photo,
+ &length) == ONAK_E_OK) {
fwrite(photo,
1,
length,
config.dbbackend->getfullkeyid(keyid),
false);
} else if (!strcmp("get", argv[optind])) {
- if (!ishex) {
+ if (!(ishex || isfp)) {
puts("Can't get a key on uid text."
- " You must supply a keyid.");
- } else if (config.dbbackend->fetch_key(keyid, &keys,
- false)) {
+ " You must supply a keyid / "
+ "fingerprint.");
+ } else if ((isfp &&
+ config.dbbackend->fetch_key_fp(fp,
+ MAX_FINGERPRINT_LEN,
+ &keys, false)) ||
+ (ishex &&
+ config.dbbackend->fetch_key_id(keyid,
+ &keys, false))) {
logthing(LOGTHING_INFO, "Got key.");
flatten_publickey(keys,
&packets,