LIBS = -L/usr/local/lib -ldb3
PROGS = add lookup gpgwww onak
-CORE_OBJS = armor.o charfuncs.o getcgi.o hash.o keydb_$(DBTYPE).o keyid.o \
- keyindex.o ll.o mem.o onak-conf.o parsekey.o sha.o
+CORE_OBJS = armor.o charfuncs.o decodekey.o getcgi.o hash.o keydb_$(DBTYPE).o \
+ keyid.o keyindex.o ll.o mem.o onak-conf.o parsekey.o sha.o
OBJS = merge.o md5.o stats.o sendsync.o $(CORE_OBJS)
SRCS = armor.c parsekey.c merge.c keyid.c md5.c sha.c main.c getcgi.c stats.c \
keyindex.c mem.c lookup.c add.c keydb_$(DBTYPE).c ll.c hash.c \
--- /dev/null
+/*
+ * decodekey.c - Routines to further decode an OpenPGP key.
+ *
+ * Jonathan McDowell <noodles@earth.li>
+ *
+ * Copyright 2002 Project Purple
+ */
+
+#include <assert.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#include "decodekey.h"
+#include "hash.h"
+#include "keyid.h"
+#include "keystructs.h"
+#include "ll.h"
+
+/*
+ * parse_subpackets - Parse the subpackets of a Type 4 signature.
+ * @data: The subpacket data.
+ * @keyid: A pointer to where we should return the keyid.
+ *
+ * This function parses the subkey data of a Type 4 signature and fills
+ * in the supplied variables. It also returns the length of the data
+ * processed.
+ */
+int parse_subpackets(unsigned char *data, uint64_t *keyid)
+{
+ int offset = 0;
+ int length = 0;
+ int packetlen = 0;
+
+ assert(data != NULL);
+
+ length = (data[0] << 8) + data[1] + 2;
+
+ offset = 2;
+ while (offset < length) {
+ packetlen = data[offset++];
+ if (packetlen > 191 && packetlen < 255) {
+ packetlen = ((packetlen - 192) << 8) +
+ data[offset++] + 192;
+ } else if (packetlen == 255) {
+ packetlen = data[offset++];
+ packetlen <<= 8;
+ packetlen = data[offset++];
+ packetlen <<= 8;
+ packetlen = data[offset++];
+ packetlen <<= 8;
+ packetlen = data[offset++];
+ }
+ switch (data[offset]) {
+ case 2:
+ /*
+ * Signature creation time. Might want to output this?
+ */
+ break;
+ case 0x83:
+ /*
+ * Signature expiration time. Might want to output this?
+ */
+ break;
+ case 16:
+ *keyid = data[offset+packetlen - 8];
+ *keyid <<= 8;
+ *keyid += data[offset+packetlen - 7];
+ *keyid <<= 8;
+ *keyid += data[offset+packetlen - 6];
+ *keyid <<= 8;
+ *keyid += data[offset+packetlen - 5];
+ *keyid <<= 8;
+ *keyid += data[offset+packetlen - 4];
+ *keyid <<= 8;
+ *keyid += data[offset+packetlen - 3];
+ *keyid <<= 8;
+ *keyid += data[offset+packetlen - 2];
+ *keyid <<= 8;
+ *keyid += data[offset+packetlen - 1];
+ break;
+ case 23:
+ /*
+ * Key server preferences. Including no-modify.
+ */
+ break;
+ case 25:
+ /*
+ * Primary UID.
+ */
+ break;
+ default:
+ /*
+ * We don't care about unrecognized packets unless bit
+ * 7 is set in which case we prefer an error than
+ * ignoring it.
+ */
+ assert(!(data[offset] & 0x80));
+ }
+ offset += packetlen;
+ }
+
+ return length;
+}
+
+/**
+ * keysigs - Return the sigs on a given OpenPGP signature list.
+ * @curll: The current linked list. Can be NULL to create a new list.
+ * @sigs: The signature list we want the sigs on.
+ *
+ * Returns a linked list of stats_key elements containing the sigs on the
+ * supplied OpenPGP packet list.
+ */
+struct ll *keysigs(struct ll *curll,
+ struct openpgp_packet_list *sigs)
+{
+ uint64_t keyid = 0;
+
+ while (sigs != NULL) {
+ keyid = sig_keyid(sigs->packet);
+ sigs = sigs->next;
+ curll = lladd(curll, createandaddtohash(keyid));
+ }
+
+ return curll;
+}
+
+/**
+ * sig_keyid - Return the keyid for a given OpenPGP signature packet.
+ * @packet: The signature packet.
+ *
+ * Returns the keyid for the supplied signature packet.
+ */
+uint64_t sig_keyid(struct openpgp_packet *packet)
+{
+ int length = 0;
+ uint64_t keyid = 0;
+
+ if (packet != NULL) {
+ keyid = 0;
+ switch (packet->data[0]) {
+ case 2:
+ case 3:
+ keyid = packet->data[7];
+ keyid <<= 8;
+ keyid += packet->data[8];
+ keyid <<= 8;
+ keyid += packet->data[9];
+ keyid <<= 8;
+ keyid += packet->data[10];
+ keyid <<= 8;
+ keyid += packet->data[11];
+ keyid <<= 8;
+ keyid += packet->data[12];
+ keyid <<= 8;
+ keyid += packet->data[13];
+ keyid <<= 8;
+ keyid += packet->data[14];
+ break;
+ case 4:
+ length = parse_subpackets(&packet->data[4],
+ &keyid);
+ parse_subpackets(&packet->data[length + 4],
+ &keyid);
+ /*
+ * Don't bother to look at the unsigned packets.
+ */
+ break;
+ default:
+ break;
+ }
+ }
+
+ return keyid;
+}
+
+/*
+ * TODO: Abstract out; all our linked lists should be generic and then we can
+ * llsize them.
+ */
+int spsize(struct openpgp_signedpacket_list *list)
+{
+ int size = 0;
+ struct openpgp_signedpacket_list *cur;
+
+ for (cur = list; cur != NULL; cur = cur->next, size++) ;
+
+ return size;
+}
+
+/**
+ * keyuids - Takes a key and returns an array of its UIDs
+ * @key: The key to get the uids of.
+ * @primary: A pointer to store the primary UID in.
+ *
+ * keyuids takes a public key structure and builds an array of the UIDs
+ * on the key. It also attempts to work out the primary UID and returns a
+ * separate pointer to that particular element of the array.
+ */
+char **keyuids(struct openpgp_publickey *key, char **primary)
+{
+ struct openpgp_signedpacket_list *curuid = NULL;
+ char buf[1024];
+ char **uids = NULL;
+ int count = 0;
+
+ if (key != NULL && key->uids != NULL) {
+ uids = malloc((spsize(key->uids) + 1) * sizeof (char *));
+
+ curuid = key->uids;
+ while (curuid != NULL) {
+ buf[0] = 0;
+ if (curuid->packet->tag == 13) {
+ snprintf(buf, 1023, "%.*s",
+ (int) curuid->packet->length,
+ curuid->packet->data);
+ uids[count++] = strdup(buf);
+ }
+ curuid = curuid -> next;
+ }
+ uids[count] = NULL;
+ }
+ /*
+ * TODO: Parse subpackets for real primary ID (v4 keys)
+ */
+ if (primary != NULL) {
+ *primary = uids[0];
+ }
+
+ return uids;
+}
--- /dev/null
+/*
+ * keyindex.h - Routines to list an OpenPGP key.
+ *
+ * Jonathan McDowell <noodles@earth.li>
+ *
+ * Copyright 2002 Project Purple
+ */
+
+#ifndef __DECODEKEY_H__
+#define __DECODEKEY_H__
+
+#include "keystructs.h"
+#include "ll.h"
+
+/**
+ * keysigs - Return the sigs on a given OpenPGP signature packet list.
+ * @curll: The current linked list. Can be NULL to create a new list.
+ * @sigs: The signature list we want the sigs on.
+ *
+ * Returns a linked list of stats_key elements containing the sigs for the
+ * supplied OpenPGP signature packet list.
+ */
+struct ll *keysigs(struct ll *curll,
+ struct openpgp_packet_list *sigs);
+
+/**
+ * sig_keyid - Return the keyid for a given OpenPGP signature packet.
+ * @packet: The signature packet.
+ *
+ * Returns the keyid for the supplied signature packet.
+ */
+uint64_t sig_keyid(struct openpgp_packet *packet);
+
+/**
+ * keyuids - Takes a key and returns an array of its UIDs
+ * @key: The key to get the uids of.
+ * @primary: A pointer to store the primary UID in.
+ *
+ * keyuids takes a public key structure and builds an array of the UIDs
+ * on the key. It also attempts to work out the primary UID and returns a
+ * separate pointer to that particular element of the array.
+ */
+char **keyuids(struct openpgp_publickey *key, char **primary);
+
+#endif
#include <stdlib.h>
#include "hash.h"
-#include "keydb.h"
-#include "keyid.h"
+#include "keystructs.h"
#include "ll.h"
#include "mem.h"
-#include "stats.h"
/**
* hashtable - the hash table array.
{
return hashtable[entry];
}
-
-/**
- * hash_getkeysigs - Gets the signatures on a key.
- * @keyid: The key we want the signatures for.
- *
- * This function gets the signatures on a key. It's the same as the
- * getkeysigs function from the keydb module except we also cache the data
- * so that if we need it again we already have it available.
- */
-struct ll *hash_getkeysigs(uint64_t keyid)
-{
- struct stats_key *key = NULL;
-
- if (keyid == 0) {
- return NULL;
- }
-
- key = findinhash(keyid);
- if (key == NULL) {
- key = malloc(sizeof(*key));
- if (key != NULL) {
- key->keyid = keyid;
- key->colour = 0;
- key->parent = 0;
- key->sigs = NULL;
- key->gotsigs = false;
- addtohash(key);
- } else {
- perror("hash_getkeysigs()");
- return NULL;
- }
- }
- if (key->gotsigs == false) {
- key->sigs = getkeysigs(key->keyid);
- key->gotsigs = true;
- }
-
- return key->sigs;
-}
#ifndef __HASH_H__
#define __HASH_H__
+#include "keystructs.h"
#include "ll.h"
-#include "stats.h"
#define HASHSIZE 1024
#define HASHMASK 0x3FF
*/
struct ll *gethashtableentry(int entry);
-/**
- * hash_getkeysigs - Gets the signatures on a key.
- * @keyid: The key we want the signatures for.
- *
- * This function gets the signatures on a key. It's the same as the
- * getkeysigs function from the keydb module except we also cache the data
- * so that if we need it again we already have it available.
- */
-struct ll *hash_getkeysigs(uint64_t keyid);
-
#endif /* __HASH_H__ */
#include <stdio.h>
+#include "decodekey.h"
+#include "hash.h"
#include "keydb.h"
#include "keyid.h"
-#include "keyindex.h"
#include "keystructs.h"
#include "mem.h"
#include "parsekey.h"
}
#endif
+/**
+ * cached_getkeysigs - Gets the signatures on a key.
+ * @keyid: The key we want the signatures for.
+ *
+ * This function gets the signatures on a key. It's the same as the
+ * getkeysigs function above except we use the hash module to cache the
+ * data so if we need it again it's already loaded.
+ */
+struct ll *cached_getkeysigs(uint64_t keyid)
+{
+ struct stats_key *key = NULL;
+
+ if (keyid == 0) {
+ return NULL;
+ }
+
+ key = findinhash(keyid);
+ if (key == NULL) {
+ key = malloc(sizeof(*key));
+ if (key != NULL) {
+ key->keyid = keyid;
+ key->colour = 0;
+ key->parent = 0;
+ key->sigs = NULL;
+ key->gotsigs = false;
+ addtohash(key);
+ } else {
+ perror("cached_getkeysigs()");
+ return NULL;
+ }
+ }
+ if (key->gotsigs == false) {
+ key->sigs = getkeysigs(key->keyid);
+ key->gotsigs = true;
+ }
+
+ return key->sigs;
+}
+
#ifdef NEED_GETFULLKEYID
/**
* getfullkeyid - Maps a 32bit key id to a 64bit one.
*/
struct ll *getkeysigs(uint64_t keyid);
+/**
+ * cached_getkeysigs - Gets the signatures on a key.
+ * @keyid: The key we want the signatures for.
+ *
+ * This function gets the signatures on a key. It's the same as the
+ * getkeysigs function above except we use the hash module to cache the
+ */
+struct ll *cached_getkeysigs(uint64_t keyid);
+
/**
* getfullkeyid - Maps a 32bit key id to a 64bit one.
* @keyid: The 32bit keyid.
*/
#include <assert.h>
+#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
-#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
+#include "decodekey.h"
#include "getcgi.h"
#include "hash.h"
#include "keydb.h"
#include "keyid.h"
#include "keyindex.h"
#include "keystructs.h"
-#include "ll.h"
-#include "stats.h"
int list_sigs(struct openpgp_packet_list *sigs, bool html)
{
return 0;
}
-
/**
* key_index - List a set of OpenPGP keys.
* @keys: The keys to display.
return 0;
}
-
-/*
- * parse_subpackets - Parse the subpackets of a Type 4 signature.
- * @data: The subpacket data.
- * @keyid: A pointer to where we should return the keyid.
- *
- * This function parses the subkey data of a Type 4 signature and fills
- * in the supplied variables. It also returns the length of the data
- * processed.
- */
-int parse_subpackets(unsigned char *data, uint64_t *keyid)
-{
- int offset = 0;
- int length = 0;
- int packetlen = 0;
-
- assert(data != NULL);
-
- length = (data[0] << 8) + data[1] + 2;
-
- offset = 2;
- while (offset < length) {
- packetlen = data[offset++];
- if (packetlen > 191 && packetlen < 255) {
- packetlen = ((packetlen - 192) << 8) +
- data[offset++] + 192;
- } else if (packetlen == 255) {
- packetlen = data[offset++];
- packetlen <<= 8;
- packetlen = data[offset++];
- packetlen <<= 8;
- packetlen = data[offset++];
- packetlen <<= 8;
- packetlen = data[offset++];
- }
- switch (data[offset]) {
- case 2:
- /*
- * Signature creation time. Might want to output this?
- */
- break;
- case 0x83:
- /*
- * Signature expiration time. Might want to output this?
- */
- break;
- case 16:
- *keyid = data[offset+packetlen - 8];
- *keyid <<= 8;
- *keyid += data[offset+packetlen - 7];
- *keyid <<= 8;
- *keyid += data[offset+packetlen - 6];
- *keyid <<= 8;
- *keyid += data[offset+packetlen - 5];
- *keyid <<= 8;
- *keyid += data[offset+packetlen - 4];
- *keyid <<= 8;
- *keyid += data[offset+packetlen - 3];
- *keyid <<= 8;
- *keyid += data[offset+packetlen - 2];
- *keyid <<= 8;
- *keyid += data[offset+packetlen - 1];
- break;
- case 23:
- /*
- * Key server preferences. Including no-modify.
- */
- break;
- case 25:
- /*
- * Primary UID.
- */
- break;
- default:
- /*
- * We don't care about unrecognized packets unless bit
- * 7 is set in which case we prefer an error than
- * ignoring it.
- */
- assert(!(data[offset] & 0x80));
- }
- offset += packetlen;
- }
-
- return length;
-}
-
-/**
- * keysigs - Return the sigs on a given OpenPGP signature list.
- * @curll: The current linked list. Can be NULL to create a new list.
- * @sigs: The signature list we want the sigs on.
- *
- * Returns a linked list of stats_key elements containing the sigs on the
- * supplied OpenPGP packet list.
- */
-struct ll *keysigs(struct ll *curll,
- struct openpgp_packet_list *sigs)
-{
- uint64_t keyid = 0;
-
- while (sigs != NULL) {
- keyid = sig_keyid(sigs->packet);
- sigs = sigs->next;
- curll = lladd(curll, createandaddtohash(keyid));
- }
-
- return curll;
-}
-
-/**
- * sig_keyid - Return the keyid for a given OpenPGP signature packet.
- * @packet: The signature packet.
- *
- * Returns the keyid for the supplied signature packet.
- */
-uint64_t sig_keyid(struct openpgp_packet *packet)
-{
- int length = 0;
- uint64_t keyid = 0;
-
- if (packet != NULL) {
- keyid = 0;
- switch (packet->data[0]) {
- case 2:
- case 3:
- keyid = packet->data[7];
- keyid <<= 8;
- keyid += packet->data[8];
- keyid <<= 8;
- keyid += packet->data[9];
- keyid <<= 8;
- keyid += packet->data[10];
- keyid <<= 8;
- keyid += packet->data[11];
- keyid <<= 8;
- keyid += packet->data[12];
- keyid <<= 8;
- keyid += packet->data[13];
- keyid <<= 8;
- keyid += packet->data[14];
- break;
- case 4:
- length = parse_subpackets(&packet->data[4],
- &keyid);
- parse_subpackets(&packet->data[length + 4],
- &keyid);
- /*
- * Don't bother to look at the unsigned packets.
- */
- break;
- default:
- break;
- }
- }
-
- return keyid;
-}
-
-/*
- * TODO: Abstract out; all our linked lists should be generic and then we can
- * llsize them.
- */
-int spsize(struct openpgp_signedpacket_list *list)
-{
- int size = 0;
- struct openpgp_signedpacket_list *cur;
-
- for (cur = list; cur != NULL; cur = cur->next, size++) ;
-
- return size;
-}
-
-/**
- * keyuids - Takes a key and returns an array of its UIDs
- * @key: The key to get the uids of.
- * @primary: A pointer to store the primary UID in.
- *
- * keyuids takes a public key structure and builds an array of the UIDs
- * on the key. It also attempts to work out the primary UID and returns a
- * separate pointer to that particular element of the array.
- */
-char **keyuids(struct openpgp_publickey *key, char **primary)
-{
- struct openpgp_signedpacket_list *curuid = NULL;
- char buf[1024];
- char **uids = NULL;
- int count = 0;
-
- if (key != NULL && key->uids != NULL) {
- uids = malloc((spsize(key->uids) + 1) * sizeof (char *));
-
- curuid = key->uids;
- while (curuid != NULL) {
- buf[0] = 0;
- if (curuid->packet->tag == 13) {
- snprintf(buf, 1023, "%.*s",
- (int) curuid->packet->length,
- curuid->packet->data);
- uids[count++] = strdup(buf);
- }
- curuid = curuid -> next;
- }
- uids[count] = NULL;
- }
- /*
- * TODO: Parse subpackets for real primary ID (v4 keys)
- */
- if (primary != NULL) {
- *primary = uids[0];
- }
-
- return uids;
-}
int key_index(struct openpgp_publickey *keys, bool verbose,
bool fingerprint, bool html);
-/**
- * keysigs - Return the sigs on a given OpenPGP signature packet list.
- * @curll: The current linked list. Can be NULL to create a new list.
- * @sigs: The signature list we want the sigs on.
- *
- * Returns a linked list of stats_key elements containing the sigs for the
- * supplied OpenPGP signature packet list.
- */
-struct ll *keysigs(struct ll *curll,
- struct openpgp_packet_list *sigs);
-
-/**
- * sig_keyid - Return the keyid for a given OpenPGP signature packet.
- * @packet: The signature packet.
- *
- * Returns the keyid for the supplied signature packet.
- */
-uint64_t sig_keyid(struct openpgp_packet *packet);
-
-/**
- * keyuids - Takes a key and returns an array of its UIDs
- * @key: The key to get the uids of.
- * @primary: A pointer to store the primary UID in.
- *
- * keyuids takes a public key structure and builds an array of the UIDs
- * on the key. It also attempts to work out the primary UID and returns a
- * separate pointer to that particular element of the array.
- */
-char **keyuids(struct openpgp_publickey *key, char **primary);
-
#endif
#ifndef __KEYSTRUCTS_H__
#define __KEYSTRUCTS_H__
+#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
+#include "ll.h"
+
/**
* struct openpgp_packet - Stores an OpenPGP packet.
* @tag: The packet tag (ie type).
struct openpgp_publickey *next;
};
+/**
+ * struct stats_key - holds key details suitable for doing stats on.
+ * @keyid: The keyid.
+ * @colour: Used for marking during DFS/BFS.
+ * @parent: The key that lead us to this one for DFS/BFS.
+ * @sigs: A linked list of the signatures on this key.
+ * @gotsigs: A bool indicating if we've initialized the sigs element yet.
+ */
+struct stats_key {
+ uint64_t keyid;
+ int colour;
+ uint64_t parent;
+ struct ll *sigs;
+ bool gotsigs;
+};
+
#endif /* __KEYSTRUCTS_H__ */
distance = 0;
from = to = tmp = NULL;
- hash_getkeysigs(0xF1BD4BE45B430367);
+ cached_getkeysigs(0xF1BD4BE45B430367);
for (loop = 0; (loop < HASHSIZE) && (distance < max); loop++) {
curkey = gethashtableentry(loop);
while (curkey != NULL && distance < max) {
- hash_getkeysigs(((struct stats_key *)
+ cached_getkeysigs(((struct stats_key *)
curkey->object)->keyid);
initcolour(false);
tmp = furthestkey((struct stats_key *)
#include "keystructs.h"
#include "ll.h"
#include "mem.h"
-#include "stats.h"
/**
* packet_dup - duplicate an OpenPGP packet.
#define __MEM_H_
#include "keystructs.h"
-#include "stats.h"
/**
* packet_dup - duplicate an OpenPGP packet.
#include <stdio.h>
#include <stdlib.h>
+#include "decodekey.h"
#include "keydb.h"
#include "keyid.h"
-#include "keyindex.h"
#include "keystructs.h"
#include "ll.h"
#include "mem.h"
oldkeys = keys;
while (keys != NULL && have->colour == 0) {
- sigs = hash_getkeysigs(((struct stats_key *)
+ sigs = cached_getkeysigs(((struct stats_key *)
keys->object)->keyid);
while (sigs != NULL && have->colour == 0) {
/*
/*
* Make sure the keys we have and want are in the cache.
*/
- hash_getkeysigs(fullhave);
- hash_getkeysigs(fullwant);
+ cached_getkeysigs(fullhave);
+ cached_getkeysigs(fullwant);
if ((keyinfoa = findinhash(fullhave)) == NULL) {
printf("Couldn't find key 0x%llX.\n", have);
curll = lladd(NULL, have);
while (curll != NULL) {
- sigs = hash_getkeysigs(((struct stats_key *)
+ sigs = cached_getkeysigs(((struct stats_key *)
curll->object)->keyid);
while (sigs != NULL) {
if (((struct stats_key *) sigs->object)->colour == 0) {
#ifndef __STATS_H__
#define __STATS_H__
-#include <stdbool.h>
-// #include <stdint.h>
#include <inttypes.h>
+#include <stdbool.h>
+#include "keystructs.h"
#include "ll.h"
-/**
- * struct stats_key - holds key details suitable for doing stats on.
- * @keyid: The keyid.
- * @colour: Used for marking during DFS/BFS.
- * @parent: The key that lead us to this one for DFS/BFS.
- * @sigs: A linked list of the signatures on this key.
- * @gotsigs: A bool indicating if we've initialized the sigs element yet.
- */
-struct stats_key {
- uint64_t keyid;
- int colour;
- uint64_t parent;
- struct ll *sigs;
- bool gotsigs;
-};
-
/**
* initcolour - Clear the key graph ready for use.
* @parent: Do we want to clear the parent pointers too?