As part of moving towards a libonak start pulling things that are related
to the onak keyserver out of the core PGP related source files. Start
with logthing, our logging framework, instead moving towards an onak_status_t
enum to allow up to bubble up errors to the caller.
21 files changed:
#include "armor.h"
#include "keystructs.h"
#include "armor.h"
#include "keystructs.h"
#include "onak-conf.h"
#include "parsekey.h"
#include "version.h"
#include "onak-conf.h"
#include "parsekey.h"
#include "version.h"
} else if (c == 63) {
c = '/';
} else {
} else if (c == 63) {
c = '/';
} else {
- log_assert(ctx != NULL);
state = (struct armor_context *) ctx;
switch (state->curoctet++) {
state = (struct armor_context *) ctx;
switch (state->curoctet++) {
for (i = 0; i < count; i++) {
armor_putchar_int(ctx, ((char *) c)[i]);
for (i = 0; i < count; i++) {
armor_putchar_int(ctx, ((char *) c)[i]);
unsigned char tmpc;
int i;
unsigned char tmpc;
int i;
- log_assert(ctx != NULL);
state = (struct dearmor_context *) ctx;
*c = 0;
state = (struct dearmor_context *) ctx;
*c = 0;
struct openpgp_signedpacket_list *cursubkey = NULL;
uint64_t *subkeys = NULL;
int count = 0;
struct openpgp_signedpacket_list *cursubkey = NULL;
uint64_t *subkeys = NULL;
int count = 0;
if (key != NULL && key->subkeys != NULL) {
subkeys = malloc((spsize(key->subkeys) + 1) *
sizeof (uint64_t));
cursubkey = key->subkeys;
while (cursubkey != NULL) {
if (key != NULL && key->subkeys != NULL) {
subkeys = malloc((spsize(key->subkeys) + 1) *
sizeof (uint64_t));
cursubkey = key->subkeys;
while (cursubkey != NULL) {
- subkeys[count++] = get_packetid(cursubkey->packet);
+ get_packetid(cursubkey->packet, &subkeys[count++]);
cursubkey = cursubkey -> next;
}
subkeys[count] = 0;
cursubkey = cursubkey -> next;
}
subkeys[count] = 0;
struct buffer_ctx storebuf;
int ret = 0;
int *fd = (int *) ctx;
struct buffer_ctx storebuf;
int ret = 0;
int *fd = (int *) ctx;
if (key != NULL) {
storebuf.offset = 0;
storebuf.size = 8192;
storebuf.buffer = malloc(8192);
if (key != NULL) {
storebuf.offset = 0;
storebuf.size = 8192;
storebuf.buffer = malloc(8192);
+ get_keyid(key, &keyid);
logthing(LOGTHING_TRACE,
"Iterating over 0x%016" PRIX64 ".",
logthing(LOGTHING_TRACE,
"Iterating over 0x%016" PRIX64 ".",
flatten_publickey(key,
&packets,
flatten_publickey(key,
&packets,
if (keyid < 0x100000000LL) {
config.dbbackend->fetch_key(keyid, &publickey, false);
if (publickey != NULL) {
if (keyid < 0x100000000LL) {
config.dbbackend->fetch_key(keyid, &publickey, false);
if (publickey != NULL) {
- keyid = get_keyid(publickey);
+ get_keyid(publickey, &keyid);
free_publickey(publickey);
publickey = NULL;
} else {
free_publickey(publickey);
publickey = NULL;
} else {
struct openpgp_publickey *prev = NULL;
int newkeys = 0;
bool intrans;
struct openpgp_publickey *prev = NULL;
int newkeys = 0;
bool intrans;
for (curkey = *keys; curkey != NULL; curkey = curkey->next) {
intrans = config.dbbackend->starttrans();
for (curkey = *keys; curkey != NULL; curkey = curkey->next) {
intrans = config.dbbackend->starttrans();
+ get_keyid(curkey, &keyid);
logthing(LOGTHING_INFO,
"Fetching key 0x%" PRIX64 ", result: %d",
logthing(LOGTHING_INFO,
"Fetching key 0x%" PRIX64 ", result: %d",
- get_keyid(curkey),
- config.dbbackend->fetch_key(get_keyid(curkey), &oldkey,
+ keyid,
+ config.dbbackend->fetch_key(keyid, &oldkey,
bool deadlock = false;
struct skshash hash;
bool deadlock = false;
struct skshash hash;
- keyid = get_keyid(publickey);
+ get_keyid(publickey, &keyid);
if (!intrans) {
db4_starttrans();
if (!intrans) {
db4_starttrans();
if (keyid < 0x100000000LL) {
dynamic_fetch_key(keyid, &publickey, false);
if (publickey != NULL) {
if (keyid < 0x100000000LL) {
dynamic_fetch_key(keyid, &publickey, false);
if (publickey != NULL) {
- keyid = get_keyid(publickey);
+ get_keyid(publickey, &keyid);
free_publickey(publickey);
publickey = NULL;
} else {
free_publickey(publickey);
publickey = NULL;
} else {
struct openpgp_publickey *prev = NULL;
int newkeys = 0;
bool intrans;
struct openpgp_publickey *prev = NULL;
int newkeys = 0;
bool intrans;
if (loaded_backend == NULL) {
load_backend();
if (loaded_backend == NULL) {
load_backend();
for (curkey = *keys; curkey != NULL; curkey = curkey->next) {
intrans = dynamic_starttrans();
for (curkey = *keys; curkey != NULL; curkey = curkey->next) {
intrans = dynamic_starttrans();
+ get_keyid(curkey, &keyid);
logthing(LOGTHING_INFO,
"Fetching key 0x%" PRIX64 ", result: %d",
logthing(LOGTHING_INFO,
"Fetching key 0x%" PRIX64 ", result: %d",
- get_keyid(curkey),
- dynamic_fetch_key(get_keyid(curkey), &oldkey, intrans));
+ keyid,
+ dynamic_fetch_key(keyid, &oldkey, intrans));
/*
* If we already have the key stored in the DB then merge it
/*
* If we already have the key stored in the DB then merge it
struct openpgp_publickey *next = NULL;
char keyfile[1024];
int fd = -1;
struct openpgp_publickey *next = NULL;
char keyfile[1024];
int fd = -1;
+ get_keyid(publickey, &keyid);
snprintf(keyfile, 1023, "%s/0x%" PRIX64, config.db_dir,
snprintf(keyfile, 1023, "%s/0x%" PRIX64, config.db_dir,
- get_keyid(publickey) & 0xFFFFFFFF);
fd = open(keyfile, O_WRONLY | O_CREAT, 0664); // | O_EXLOCK);
if (fd > -1) {
fd = open(keyfile, O_WRONLY | O_CREAT, 0664); // | O_EXLOCK);
if (fd > -1) {
struct openpgp_packet_list *packets = NULL;
struct openpgp_packet_list *list_end = NULL;
struct openpgp_publickey *next = NULL;
struct openpgp_packet_list *packets = NULL;
struct openpgp_packet_list *list_end = NULL;
struct openpgp_publickey *next = NULL;
- uint64_t keyid = get_keyid(publickey);
struct ll *wordlist = NULL, *wl = NULL;
struct skshash hash;
uint64_t *subkeyids = NULL;
uint32_t hashid;
int i = 0;
struct ll *wordlist = NULL, *wl = NULL;
struct skshash hash;
uint64_t *subkeyids = NULL;
uint32_t hashid;
int i = 0;
+ get_keyid(publickey, &keyid);
if (!intrans)
fs_starttrans();
if (!intrans)
fs_starttrans();
uint32_t cmd = KEYD_CMD_STORE;
uint64_t keyid;
uint32_t cmd = KEYD_CMD_STORE;
uint64_t keyid;
- keyid = get_keyid(publickey);
+ get_keyid(publickey, &keyid);
if (update) {
keyd_delete_key(keyid, false);
if (update) {
keyd_delete_key(keyid, false);
#include "config.h"
#include "keyid.h"
#include "keystructs.h"
#include "config.h"
#include "keyid.h"
#include "keystructs.h"
#include "parsekey.h"
#include "mem.h"
#include "merge.h"
#include "parsekey.h"
#include "mem.h"
#include "merge.h"
* get_keyid - Given a public key returns the keyid.
* @publickey: The key to calculate the id for.
*/
* get_keyid - Given a public key returns the keyid.
* @publickey: The key to calculate the id for.
*/
-uint64_t get_keyid(struct openpgp_publickey *publickey)
+onak_status_t get_keyid(struct openpgp_publickey *publickey, uint64_t *keyid)
- return (get_packetid(publickey->publickey));
+ return (get_packetid(publickey->publickey, keyid));
}
/**
* get_fingerprint - Given a public key returns the fingerprint.
* @publickey: The key to calculate the id for.
}
/**
* get_fingerprint - Given a public key returns the fingerprint.
* @publickey: The key to calculate the id for.
- * @fingerprint: The fingerprint (must be at least 20 bytes of space).
+ * @fingerprint: The fingerprint (must be at least 20 bytes of space).
* @len: The length of the returned fingerprint.
*
* This function returns the fingerprint for a given public key. As Type 3
* fingerprints are 16 bytes and Type 4 are 20 the len field indicates
* which we've returned.
*/
* @len: The length of the returned fingerprint.
*
* This function returns the fingerprint for a given public key. As Type 3
* fingerprints are 16 bytes and Type 4 are 20 the len field indicates
* which we've returned.
*/
-unsigned char *get_fingerprint(struct openpgp_packet *packet,
+onak_status_t get_fingerprint(struct openpgp_packet *packet,
unsigned char *fingerprint,
size_t *len)
{
unsigned char *fingerprint,
size_t *len)
{
unsigned char c;
size_t modlen, explen;
unsigned char c;
size_t modlen, explen;
- log_assert(fingerprint != NULL);
- log_assert(len != NULL);
+ if (fingerprint == NULL)
+ return ONAK_E_INVALID_PARAM;
+ if (len == NULL)
+ return ONAK_E_INVALID_PARAM;
- logthing(LOGTHING_ERROR, "Unknown key type: %d",
- packet->data[0]);
+ return ONAK_E_UNKNOWN_VER;
* get_packetid - Given a PGP packet returns the keyid.
* @packet: The packet to calculate the id for.
*/
* get_packetid - Given a PGP packet returns the keyid.
* @packet: The packet to calculate the id for.
*/
-uint64_t get_packetid(struct openpgp_packet *packet)
+onak_status_t get_packetid(struct openpgp_packet *packet, uint64_t *keyid)
int offset = 0;
int i = 0;
size_t length = 0;
unsigned char buff[20];
int offset = 0;
int i = 0;
size_t length = 0;
unsigned char buff[20];
- log_assert(packet != NULL);
+ if (packet == NULL)
+ return ONAK_E_INVALID_PARAM;
switch (packet->data[0]) {
case 2:
switch (packet->data[0]) {
case 2:
packet->data[9];
offset = ((offset + 7) / 8) + 2;
packet->data[9];
offset = ((offset + 7) / 8) + 2;
- for (keyid = 0, i = 0; i < 8; i++) {
- keyid <<= 8;
- keyid += packet->data[offset++];
+ for (*keyid = 0, i = 0; i < 8; i++) {
+ *keyid <<= 8;
+ *keyid += packet->data[offset++];
- * Check for an RSA key; if not then log but accept anyway.
+ * Check for an RSA key; if not return an error.
* 1 == RSA
* 2 == RSA Encrypt-Only
* 3 == RSA Sign-Only
*/
if (packet->data[7] < 1 || packet->data[7] > 3) {
* 1 == RSA
* 2 == RSA Encrypt-Only
* 3 == RSA Sign-Only
*/
if (packet->data[7] < 1 || packet->data[7] > 3) {
- logthing(LOGTHING_NOTICE,
- "Type 2 or 3 key, but not RSA: %llx (type %d)",
- keyid,
- packet->data[7]);
+ return ONAK_E_INVALID_PKT;
}
break;
case 4:
get_fingerprint(packet, buff, &length);
}
break;
case 4:
get_fingerprint(packet, buff, &length);
- for (keyid = 0, i = 12; i < 20; i++) {
- keyid <<= 8;
- keyid += buff[i];
+ for (*keyid = 0, i = 12; i < 20; i++) {
+ *keyid <<= 8;
+ *keyid += buff[i];
- logthing(LOGTHING_ERROR, "Unknown key type: %d",
- packet->data[0]);
+ return ONAK_E_UNKNOWN_VER;
}
static struct openpgp_packet_list *sortpackets(struct openpgp_packet_list
}
static struct openpgp_packet_list *sortpackets(struct openpgp_packet_list
-void get_skshash(struct openpgp_publickey *key, struct skshash *hash)
+onak_status_t get_skshash(struct openpgp_publickey *key, struct skshash *hash)
{
struct openpgp_packet_list *packets = NULL, *list_end = NULL;
struct openpgp_packet_list *curpacket;
{
struct openpgp_packet_list *packets = NULL, *list_end = NULL;
struct openpgp_packet_list *curpacket;
md5_digest(&md5_context, 16, (uint8_t *) &hash->hash);
free_packet_list(packets);
md5_digest(&md5_context, 16, (uint8_t *) &hash->hash);
free_packet_list(packets);
}
uint8_t hexdigit(char c)
}
uint8_t hexdigit(char c)
#include <inttypes.h>
#include "keystructs.h"
#include <inttypes.h>
#include "keystructs.h"
/**
* get_keyid - Given a public key returns the keyid.
* @publickey: The key to calculate the id for.
/**
* get_keyid - Given a public key returns the keyid.
* @publickey: The key to calculate the id for.
+ * @keeyid: The returned keyid
*
* This function returns the key id for a given public key.
*/
*
* This function returns the key id for a given public key.
*/
-uint64_t get_keyid(struct openpgp_publickey *publickey);
+onak_status_t get_keyid(struct openpgp_publickey *publickey, uint64_t *keyid);
/**
* get_fingerprint - Given a public key returns the fingerprint.
* @publickey: The key to calculate the id for.
/**
* get_fingerprint - Given a public key returns the fingerprint.
* @publickey: The key to calculate the id for.
- * @fingerprint: The fingerprint (must be at least 20 bytes of space).
+ * @fingerprint: The fingerprint (must be at least 20 bytes of space).
* @len: The length of the returned fingerprint.
*
* This function returns the fingerprint for a given public key. As Type 3
* fingerprints are 16 bytes and Type 4 are 20 the len field indicates
* which we've returned.
*/
* @len: The length of the returned fingerprint.
*
* This function returns the fingerprint for a given public key. As Type 3
* fingerprints are 16 bytes and Type 4 are 20 the len field indicates
* which we've returned.
*/
-unsigned char *get_fingerprint(struct openpgp_packet *packet,
+onak_status_t get_fingerprint(struct openpgp_packet *packet,
unsigned char *fingerprint,
size_t *len);
/**
* get_packetid - Given a PGP packet returns the keyid.
* @packet: The packet to calculate the id for.
unsigned char *fingerprint,
size_t *len);
/**
* get_packetid - Given a PGP packet returns the keyid.
* @packet: The packet to calculate the id for.
+ * @keyid: The returned keyid
*
* This function returns the key id for a given PGP packet.
*/
*
* This function returns the key id for a given PGP packet.
*/
-uint64_t get_packetid(struct openpgp_packet *packet);
+onak_status_t get_packetid(struct openpgp_packet *packet, uint64_t *keyid);
/**
* get_skshash - Given a public key returns the SKS hash for it.
/**
* get_skshash - Given a public key returns the SKS hash for it.
* make up the key. The caller should allocate the memory for the
* hash.
*/
* make up the key. The caller should allocate the memory for the
* hash.
*/
-void get_skshash(struct openpgp_publickey *publickey, struct skshash *hash);
+onak_status_t get_skshash(struct openpgp_publickey *publickey,
+ struct skshash *hash);
/**
* parse_skshash - Parse a string into an SKS hash structure.
/**
* parse_skshash - Parse a string into an SKS hash structure.
#include "keyindex.h"
#include "keystructs.h"
#include "log.h"
#include "keyindex.h"
#include "keystructs.h"
#include "log.h"
#include "onak-conf.h"
#include "openpgp.h"
#include "onak-conf.h"
#include "openpgp.h"
time_t created_time = 0;
int type = 0;
int length = 0;
time_t created_time = 0;
int type = 0;
int length = 0;
while (subkeys != NULL) {
if (subkeys->packet->tag == OPENPGP_PACKET_PUBLICSUBKEY) {
while (subkeys != NULL) {
if (subkeys->packet->tag == OPENPGP_PACKET_PUBLICSUBKEY) {
"Unknown key type: %d",
subkeys->packet->data[0]);
}
"Unknown key type: %d",
subkeys->packet->data[0]);
}
+
+ if (get_packetid(subkeys->packet,
+ &keyid) != ONAK_E_OK) {
+ logthing(LOGTHING_ERROR, "Couldn't get keyid.");
+ }
printf("sub %5d%c/%08X %04d/%02d/%02d\n",
length,
(type == OPENPGP_PKALGO_RSA) ? 'R' :
((type == OPENPGP_PKALGO_ELGAMAL_ENC) ? 'g' :
((type == OPENPGP_PKALGO_DSA) ? 'D' : '?')),
printf("sub %5d%c/%08X %04d/%02d/%02d\n",
length,
(type == OPENPGP_PKALGO_RSA) ? 'R' :
((type == OPENPGP_PKALGO_ELGAMAL_ENC) ? 'g' :
((type == OPENPGP_PKALGO_DSA) ? 'D' : '?')),
- (uint32_t) (get_packetid(subkeys->packet) &
- 0xFFFFFFFF),
+ (uint32_t) (keyid & 0xFFFFFFFF),
created->tm_year + 1900,
created->tm_mon + 1,
created->tm_mday);
created->tm_year + 1900,
created->tm_mon + 1,
created->tm_mday);
keys->publickey->data[0]);
}
keys->publickey->data[0]);
}
- keyid = get_keyid(keys);
+ if (get_keyid(keys, &keyid) != ONAK_E_OK) {
+ logthing(LOGTHING_ERROR, "Couldn't get keyid.");
+ }
switch (type) {
case OPENPGP_PKALGO_RSA:
switch (type) {
case OPENPGP_PKALGO_RSA:
size_t fplength = 0;
unsigned char fp[20];
int c;
size_t fplength = 0;
unsigned char fp[20];
int c;
while (keys != NULL) {
created_time = (keys->publickey->data[1] << 24) +
while (keys != NULL) {
created_time = (keys->publickey->data[1] << 24) +
switch (keys->publickey->data[0]) {
case 2:
case 3:
switch (keys->publickey->data[0]) {
case 2:
case 3:
- printf("%016" PRIX64, get_keyid(keys));
+ if (get_keyid(keys, &keyid) != ONAK_E_OK) {
+ logthing(LOGTHING_ERROR, "Couldn't get keyid");
+ }
+ printf("%016" PRIX64, keyid);
type = keys->publickey->data[7];
length = (keys->publickey->data[8] << 8) +
keys->publickey->data[9];
type = keys->publickey->data[7];
length = (keys->publickey->data[8] << 8) +
keys->publickey->data[9];
size_t length = 0;
if (getphoto(publickey, indx, &photo,
size_t length = 0;
if (getphoto(publickey, indx, &photo,
+ &length) == ONAK_E_OK) {
#include "keystructs.h"
#include "ll.h"
#include "keystructs.h"
#include "ll.h"
{
struct openpgp_packet *newpacket = NULL;
{
struct openpgp_packet *newpacket = NULL;
- log_assert(packet != NULL);
+ if (packet == NULL)
+ return NULL;
newpacket = malloc(sizeof (struct openpgp_packet));
if (newpacket != NULL) {
newpacket = malloc(sizeof (struct openpgp_packet));
if (newpacket != NULL) {
struct openpgp_packet_list **list_end,
struct openpgp_packet_list *packet_list)
{
struct openpgp_packet_list **list_end,
struct openpgp_packet_list *packet_list)
{
- log_assert(list != NULL);
- log_assert(list_end != NULL);
-
for (; packet_list != NULL; packet_list = packet_list->next) {
ADD_PACKET_TO_LIST((*list_end),
packet_dup(packet_list->packet));
for (; packet_list != NULL; packet_list = packet_list->next) {
ADD_PACKET_TO_LIST((*list_end),
packet_dup(packet_list->packet));
* including the data part.
*/
void free_packet(struct openpgp_packet *packet) {
* including the data part.
*/
void free_packet(struct openpgp_packet *packet) {
- log_assert(packet != NULL);
-
if (packet->data != NULL) {
free(packet->data);
packet->data = NULL;
if (packet->data != NULL) {
free(packet->data);
packet->data = NULL;
struct openpgp_packet_list *curpacket = NULL;
struct openpgp_packet_list *lastpacket = NULL;
struct openpgp_packet_list *nextpacket = NULL;
struct openpgp_packet_list *curpacket = NULL;
struct openpgp_packet_list *lastpacket = NULL;
struct openpgp_packet_list *nextpacket = NULL;
if (a == NULL || b == NULL) {
/*
* Do nothing.
*/
if (a == NULL || b == NULL) {
/*
* Do nothing.
*/
- rc = 1;
- } else if (get_keyid(a) != get_keyid(b)) {
+ return 1;
+ }
+
+ if (get_keyid(a, &keya) != ONAK_E_OK) {
+ return 1;
+ } else if (get_keyid(b, &keyb) != ONAK_E_OK) {
+ return 1;
+ } else if (keya != keyb) {
/*
* Key IDs are different.
*/
/*
* Key IDs are different.
*/
unsigned char *photo = NULL;
size_t length = 0;
unsigned char *photo = NULL;
size_t length = 0;
- if (getphoto(keys, 0, &photo, &length)) {
+ if (getphoto(keys, 0, &photo,
+ &length) == ONAK_E_OK) {
#include "keyid.h"
#include "keystructs.h"
#include "ll.h"
#include "keyid.h"
#include "keystructs.h"
#include "ll.h"
#include "openpgp.h"
#include "parsekey.h"
#include "openpgp.h"
#include "parsekey.h"
* It's a signature packet. Add it to either the public
* key, to the current UID or the current subkey.
*/
* It's a signature packet. Add it to either the public
* key, to the current UID or the current subkey.
*/
- log_assert(curkey != NULL);
+ if (curkey == NULL)
+ return ONAK_E_INVALID_PARAM;
if (curkey->subkeys != NULL) {
ADD_PACKET_TO_LIST_END(curkey->last_subkey,
sig,
if (curkey->subkeys != NULL) {
ADD_PACKET_TO_LIST_END(curkey->last_subkey,
sig,
/*
* It's a UID packet (or a photo id, which is similar).
*/
/*
* It's a UID packet (or a photo id, which is similar).
*/
- log_assert(curkey != NULL);
- log_assert(curkey->subkeys == NULL);
+ if (curkey == NULL)
+ return ONAK_E_INVALID_PARAM;
+ if (curkey->subkeys != NULL)
+ return ONAK_E_INVALID_PARAM;
ADD_PACKET_TO_LIST_END(curkey,
uid,
packet_dup(packets->packet));
ADD_PACKET_TO_LIST_END(curkey,
uid,
packet_dup(packets->packet));
/*
* It's a subkey packet.
*/
/*
* It's a subkey packet.
*/
- log_assert(curkey != NULL);
+ if (curkey == NULL)
+ return ONAK_E_INVALID_PARAM;
ADD_PACKET_TO_LIST_END(curkey,
subkey,
packet_dup(packets->packet));
ADD_PACKET_TO_LIST_END(curkey,
subkey,
packet_dup(packets->packet));
- logthing(LOGTHING_ERROR,
- "Unsupported packet type: %d",
- packets->packet->tag);
+ /* Unsupported packet. Do what? Ignore for now. */
+ break;
}
packets = packets->next;
}
}
packets = packets->next;
}
* packet stream and reads the packets into a linked list of packets
* ready for parsing as a public key or whatever.
*/
* packet stream and reads the packets into a linked list of packets
* ready for parsing as a public key or whatever.
*/
-int read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
+onak_status_t read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
void *c),
void *ctx,
struct openpgp_packet_list **packets,
void *c),
void *ctx,
struct openpgp_packet_list **packets,
{
unsigned char curchar = 0;
struct openpgp_packet_list *curpacket = NULL;
{
unsigned char curchar = 0;
struct openpgp_packet_list *curpacket = NULL;
+ onak_status_t rc = ONAK_E_OK;
int keys = 0;
bool inpacket = false;
int keys = 0;
bool inpacket = false;
- log_assert(packets != NULL);
+ if (packets == NULL)
+ return ONAK_E_INVALID_PARAM;
+
curpacket = *packets;
if (curpacket != NULL) {
while (curpacket->next != NULL) {
curpacket = *packets;
if (curpacket != NULL) {
while (curpacket->next != NULL) {
curpacket->packet->length += 192;
} else if (curpacket->packet->length > 223 &&
curpacket->packet->length < 255) {
curpacket->packet->length += 192;
} else if (curpacket->packet->length > 223 &&
curpacket->packet->length < 255) {
- logthing(LOGTHING_NOTICE,
- "Partial length;"
- " not supported.");
+ return ONAK_E_UNSUPPORTED_FEATURE;
} else if (curpacket->packet->length == 255) {
/*
* 5 byte length; ie 255 followed by 3
} else if (curpacket->packet->length == 255) {
/*
* 5 byte length; ie 255 followed by 3
curpacket->packet->length += curchar;
break;
case 3:
curpacket->packet->length += curchar;
break;
case 3:
- logthing(LOGTHING_ERROR,
- "Unsupported length type 3.");
+ rc = ONAK_E_UNSUPPORTED_FEATURE;
curpacket->packet->length = 0;
curpacket->packet->data = NULL;
curpacket->packet->length = 0;
curpacket->packet->data = NULL;
malloc(curpacket->packet->length *
sizeof(unsigned char));
if (curpacket->packet->data == NULL) {
malloc(curpacket->packet->length *
sizeof(unsigned char));
if (curpacket->packet->data == NULL) {
- logthing(LOGTHING_ERROR,
- "Can't allocate memory for "
- "packet!");
- rc = -1;
} else {
rc = getchar_func(ctx,
curpacket->packet->length,
} else {
rc = getchar_func(ctx,
curpacket->packet->length,
}
inpacket = false;
} else {
}
inpacket = false;
} else {
- logthing(LOGTHING_ERROR, "Unexpected character: 0x%X",
- curchar);
- rc = 1;
+ rc = ONAK_E_INVALID_PKT;
* This function uses putchar_func to write characters to an OpenPGP
* packet stream from a linked list of packets.
*/
* This function uses putchar_func to write characters to an OpenPGP
* packet stream from a linked list of packets.
*/
-int write_openpgp_stream(int (*putchar_func)(void *ctx, size_t count,
+onak_status_t write_openpgp_stream(int (*putchar_func)(void *ctx, size_t count,
void *c),
void *ctx,
struct openpgp_packet_list *packets)
void *c),
void *ctx,
struct openpgp_packet_list *packets)
putchar_func(ctx, 1, &curchar);
} else if (packets->packet->length > 8382 &&
packets->packet->length < 0xFFFFFFFF) {
putchar_func(ctx, 1, &curchar);
} else if (packets->packet->length > 8382 &&
packets->packet->length < 0xFFFFFFFF) {
- logthing(LOGTHING_DEBUG,
- "Writing 5 byte length");
curchar = 255;
putchar_func(ctx, 1, &curchar);
curchar = 255;
putchar_func(ctx, 1, &curchar);
curchar &= 0xFF;
putchar_func(ctx, 1, &curchar);
} else {
curchar &= 0xFF;
putchar_func(ctx, 1, &curchar);
} else {
- logthing(LOGTHING_ERROR,
- "Unsupported new format length.");
+ return ONAK_E_UNSUPPORTED_FEATURE;
}
} else {
curchar |= (packets->packet->tag << 2);
}
} else {
curchar |= (packets->packet->tag << 2);
packets->packet->data);
packets = packets->next;
}
packets->packet->data);
packets = packets->next;
}
#define __PARSEKEY_H__
#include "keystructs.h"
#define __PARSEKEY_H__
#include "keystructs.h"
/**
* parse_keys - Process a stream of packets for public keys + sigs.
/**
* parse_keys - Process a stream of packets for public keys + sigs.
* then only the public key component of the last key will be returned,
* none of the other packets of the key will be read.
*/
* then only the public key component of the last key will be returned,
* none of the other packets of the key will be read.
*/
-int read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
+onak_status_t read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
void *c),
void *ctx,
struct openpgp_packet_list **packets,
void *c),
void *ctx,
struct openpgp_packet_list **packets,
* This function uses putchar_func to write characters to an OpenPGP
* packet stream from a linked list of packets.
*/
* This function uses putchar_func to write characters to an OpenPGP
* packet stream from a linked list of packets.
*/
-int write_openpgp_stream(int (*putchar_func)(void *ctx, size_t count,
+onak_status_t write_openpgp_stream(int (*putchar_func)(void *ctx, size_t count,
void *c),
void *ctx,
struct openpgp_packet_list *packets);
void *c),
void *ctx,
struct openpgp_packet_list *packets);
#include "keyid.h"
#include "keyindex.h"
#include "keystructs.h"
#include "keyid.h"
#include "keyindex.h"
#include "keystructs.h"
* photo id NULL is returned. The returned data pointer refers to the key
* data supplied rather than a copy of it.
*/
* photo id NULL is returned. The returned data pointer refers to the key
* data supplied rather than a copy of it.
*/
-int getphoto(struct openpgp_publickey *key, int index, unsigned char **photo,
- size_t *length)
+onak_status_t getphoto(struct openpgp_publickey *key, int index,
+ unsigned char **photo, size_t *length)
{
struct openpgp_signedpacket_list *curuid = NULL;
int i = 0;
int j = 0;
{
struct openpgp_signedpacket_list *curuid = NULL;
int i = 0;
int j = 0;
- log_assert(key != NULL);
- log_assert(photo != NULL);
- log_assert(length != NULL);
+ if (key == NULL || photo == NULL || length == NULL)
+ return ONAK_E_INVALID_PARAM;
*length <<= 8;
*length += curuid->packet->data[j++];
}
*length <<= 8;
*length += curuid->packet->data[j++];
}
- logthing(LOGTHING_DEBUG, "Got photo, size %d",
- *length);
j++;
*length -= 17;
*photo = &(curuid->packet->data[j+16]);
j++;
*length -= 17;
*photo = &(curuid->packet->data[j+16]);
- return (*photo != NULL);
+ return *photo == NULL ? ONAK_E_NOT_FOUND : ONAK_E_OK;
* photo id NULL is returned. The returned data pointer refers to the key
* data supplied rather than a copy of it.
*/
* photo id NULL is returned. The returned data pointer refers to the key
* data supplied rather than a copy of it.
*/
-int getphoto(struct openpgp_publickey *key, int index, unsigned char **photo,
- size_t *length);
+onak_status_t getphoto(struct openpgp_publickey *key, int index,
+ unsigned char **photo, size_t *length);
#endif /* __PHOTOID_H__ */
#endif /* __PHOTOID_H__ */
cleankeys( keys );
/* Iterate over the keys... */
for( key = keys; key; key = key->next ) {
cleankeys( keys );
/* Iterate over the keys... */
for( key = keys; key; key = key->next ) {
- uint64_t keyid = get_keyid( key );
+ uint64_t keyid;
+ get_keyid( key, &keyid );
for( uid = key->uids; uid; uid = uid->next ) {
REPEATTHISUID:
for( sig = uid->sigs, prevsig = NULL;
for( uid = key->uids; uid; uid = uid->next ) {
REPEATTHISUID:
for( sig = uid->sigs, prevsig = NULL;