* keysubkeys takes a public key structure and returns an array of the
* subkey keyids for that key.
*/
-uint64_t *keysubkeys(struct openpgp_publickey *key)
+struct openpgp_fingerprint *keysubkeys(struct openpgp_publickey *key)
{
struct openpgp_signedpacket_list *cursubkey = NULL;
- uint64_t *subkeys = NULL;
+ struct openpgp_fingerprint *subkeys = NULL;
int count = 0;
if (key != NULL && key->subkeys != NULL) {
subkeys = malloc((spsize(key->subkeys) + 1) *
- sizeof (uint64_t));
+ sizeof (struct openpgp_fingerprint));
cursubkey = key->subkeys;
while (cursubkey != NULL) {
- get_packetid(cursubkey->packet, &subkeys[count++]);
+ get_fingerprint(cursubkey->packet, &subkeys[count++]);
cursubkey = cursubkey -> next;
}
- subkeys[count] = 0;
+ subkeys[count].length = 0;
}
return subkeys;
char **keyuids(struct openpgp_publickey *key, char **primary);
/**
- * keysubkeys - Takes a key and returns an array of its subkey keyids.
+ * keysubkeys - Takes a key & returns an array of its subkey fingerprints
* @key: The key to get the subkeys of.
*
* keysubkeys takes a public key structure and returns an array of the
- * subkey keyids for that key.
+ * subkey fingerprints for that key.
*/
-uint64_t *keysubkeys(struct openpgp_publickey *key);
+struct openpgp_fingerprint *keysubkeys(struct openpgp_publickey *key);
/**
* parse_subpackets - Parse the subpackets of a Type 4 signature.
DBT key, data;
DBC *cursor = NULL;
uint32_t shortkeyid = 0;
- uint64_t *subkeyids = NULL;
+ struct openpgp_fingerprint *subkeyids = NULL;
int ret = 0;
int i;
char **uids = NULL;
struct ll *curword = NULL;
bool deadlock = false;
struct skshash hash;
+ uint64_t subkeyid;
if (!intrans) {
db4_starttrans(dbctx);
subkeyids = keysubkeys(publickey);
i = 0;
- while (subkeyids != NULL && subkeyids[i] != 0) {
+ while (subkeyids != NULL && subkeyids[i].length != 0) {
+ subkeyid = fingerprint2keyid(&subkeyids[i]);
memset(&key, 0, sizeof(key));
- key.data = &subkeyids[i];
- key.size = sizeof(subkeyids[i]);
+ key.data = &subkeyid;
+ key.size = sizeof(subkeyid);
privctx->subkeydb->del(privctx->subkeydb,
privctx->txn, &key, 0);
if (ret != 0) {
}
}
- shortkeyid = subkeyids[i++] & 0xFFFFFFFF;
+ shortkeyid = subkeyid & 0xFFFFFFFF;
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
deadlock = true;
}
}
+ i++;
}
if (subkeyids != NULL) {
free(subkeyids);
DBT data;
uint64_t keyid = 0;
uint32_t shortkeyid = 0;
- uint64_t *subkeyids = NULL;
+ struct openpgp_fingerprint *subkeyids = NULL;
char **uids = NULL;
char *primary = NULL;
unsigned char worddb_data[12];
struct ll *curword = NULL;
bool deadlock = false;
struct skshash hash;
+ uint64_t subkeyid;
if (get_keyid(publickey, &keyid) != ONAK_E_OK) {
logthing(LOGTHING_ERROR, "Couldn't find key ID for key.");
if (!deadlock) {
subkeyids = keysubkeys(publickey);
i = 0;
- while (subkeyids != NULL && subkeyids[i] != 0) {
+ while (subkeyids != NULL && subkeyids[i].length != 0) {
+ subkeyid = fingerprint2keyid(&subkeyids[i]);
/* Store the subkey ID -> main key ID mapping */
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
- key.data = &subkeyids[i];
- key.size = sizeof(subkeyids[i]);
+ key.data = &subkeyid;
+ key.size = sizeof(subkeyid);
data.data = &keyid;
data.size = sizeof(keyid);
}
/* Store the short subkey ID -> main key ID mapping */
- shortkeyid = subkeyids[i++] & 0xFFFFFFFF;
+ shortkeyid = subkeyid & 0xFFFFFFFF;
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
deadlock = true;
}
}
+ i++;
}
if (subkeyids != NULL) {
free(subkeyids);
uint64_t keyid;
struct ll *wordlist = NULL, *wl = NULL;
struct skshash hash;
- uint64_t *subkeyids = NULL;
+ struct openpgp_fingerprint *subkeyids = NULL;
uint32_t hashid;
int i = 0;
subkeyids = keysubkeys(publickey);
i = 0;
- while (subkeyids != NULL && subkeyids[i] != 0) {
- prove_path_to(subkeyids[i], "subkeys");
+ while (subkeyids != NULL && subkeyids[i].length != 0) {
+ keyid = fingerprint2keyid(&subkeyids[i]);
- subkeydir(wbuffer, sizeof(wbuffer), subkeyids[i]);
+ prove_path_to(keyid, "subkeys");
+
+ subkeydir(wbuffer, sizeof(wbuffer), keyid);
mkdir(wbuffer, 0777);
- subkeypath(wbuffer, sizeof(wbuffer), subkeyids[i]);
+ subkeypath(wbuffer, sizeof(wbuffer), keyid);
link(buffer, wbuffer);
i++;
struct openpgp_publickey *pk = NULL;
struct skshash hash;
struct ll *wordlist = NULL, *wl = NULL;
- uint64_t *subkeyids = NULL;
+ struct openpgp_fingerprint *subkeyids = NULL;
+ uint64_t subkeyid;
int i = 0;
if ((keyid >> 32) == 0)
subkeyids = keysubkeys(pk);
i = 0;
- while (subkeyids != NULL && subkeyids[i] != 0) {
- prove_path_to(subkeyids[i], "subkeys");
+ while (subkeyids != NULL && subkeyids[i].length != 0) {
+ subkeyid = fingerprint2keyid(&subkeyids[i]);
+ prove_path_to(subkeyid, "subkeys");
- subkeypath(buffer, sizeof(buffer), subkeyids[i]);
+ subkeypath(buffer, sizeof(buffer), subkeyid);
unlink(buffer);
i++;
#include "sha1.h"
#endif
+uint64_t fingerprint2keyid(struct openpgp_fingerprint *fingerprint)
+{
+ uint64_t keyid;
+ int i;
+
+ keyid = 0;
+ for (keyid = 0, i = 12; i < 20; i++) {
+ keyid <<= 8;
+ keyid += fingerprint->fp[i];
+ }
+
+ return keyid;
+}
+
/**
* get_keyid - Given a public key returns the keyid.
ripemd160_digest(&ripemd160_context,
RIPEMD160_DIGEST_SIZE,
fingerprint.fp);
+ fingerprint.length = RIPEMD160_DIGEST_SIZE;
- for (*keyid = 0, i = 12; i < 20; i++) {
- *keyid <<= 8;
- *keyid += fingerprint.fp[i];
- }
+ *keyid = fingerprint2keyid(&fingerprint);
return ONAK_E_OK;
}
break;
case 4:
get_fingerprint(packet, &fingerprint);
-
- for (*keyid = 0, i = 12; i < 20; i++) {
- *keyid <<= 8;
- *keyid += fingerprint.fp[i];
- }
+
+ *keyid = fingerprint2keyid(&fingerprint);
break;
default:
#include "keystructs.h"
#include "onak.h"
+/**
+ * fingerprint2keyid - convert a fingerprint to a keyid
+ * @fingerprint: The fingerprint structure to convert
+ * @returns: 64 bit keyid
+ *
+ * This function returns the key id for a given fingerprint. Currently
+ * only works for v4 fingerprints.
+ */
+uint64_t fingerprint2keyid(struct openpgp_fingerprint *fingerprint);
+
/**
* get_keyid - Given a public key returns the keyid.
* @publickey: The key to calculate the id for.