#include <sys/un.h>
#include <unistd.h>
+#include "build-config.h"
#include "charfuncs.h"
#include "keyd.h"
#include "keydb.h"
* operations on the database to help speed it all up, or if we want
* something to only succeed if all relevant operations are successful.
*/
-static bool keyd_starttrans(struct onak_dbctx *dbctx)
+static bool keyd_starttrans(__unused struct onak_dbctx *dbctx)
{
return true;
}
*
* Ends a transaction.
*/
-static void keyd_endtrans(struct onak_dbctx *dbctx)
+static void keyd_endtrans(__unused struct onak_dbctx *dbctx)
{
return;
}
*
* This function returns a public key from whatever storage mechanism we
* are using.
- *
- * TODO: What about keyid collisions? Should we use fingerprint instead?
*/
-static int keyd_fetch_key_id(struct onak_dbctx *dbctx,
- uint64_t keyid,
+static int keyd_fetch_key(struct onak_dbctx *dbctx,
+ struct openpgp_fingerprint *fingerprint,
struct openpgp_publickey **publickey,
- bool intrans)
+ __unused bool intrans)
{
int keyd_fd = (intptr_t) dbctx->priv;
struct buffer_ctx keybuf;
struct openpgp_packet_list *packets = NULL;
ssize_t bytes = 0;
ssize_t count = 0;
+ uint8_t size;
- if (keyd_send_cmd(keyd_fd, KEYD_CMD_GET_ID)) {
- write(keyd_fd, &keyid, sizeof(keyid));
+ if (fingerprint->length > MAX_FINGERPRINT_LEN) {
+ return 0;
+ }
+
+ if (keyd_send_cmd(keyd_fd, KEYD_CMD_GET)) {
+ size = fingerprint->length;
+ write(keyd_fd, &size, sizeof(size));
+ write(keyd_fd, fingerprint->fp, size);
keybuf.offset = 0;
read(keyd_fd, &keybuf.size, sizeof(keybuf.size));
if (keybuf.size > 0) {
static int keyd_fetch_key_fp(struct onak_dbctx *dbctx,
struct openpgp_fingerprint *fingerprint,
struct openpgp_publickey **publickey,
- bool intrans)
+ __unused bool intrans)
{
int keyd_fd = (intptr_t) dbctx->priv;
struct buffer_ctx keybuf;
return (count > 0) ? 1 : 0;
}
+static int keyd_fetch_key_id(struct onak_dbctx *dbctx,
+ uint64_t keyid,
+ struct openpgp_publickey **publickey,
+ __unused bool intrans)
+{
+ int keyd_fd = (intptr_t) dbctx->priv;
+ struct buffer_ctx keybuf;
+ struct openpgp_packet_list *packets = NULL;
+ ssize_t bytes = 0;
+ ssize_t count = 0;
+
+ if (keyd_send_cmd(keyd_fd, KEYD_CMD_GET_ID)) {
+ write(keyd_fd, &keyid, sizeof(keyid));
+ keybuf.offset = 0;
+ read(keyd_fd, &keybuf.size, sizeof(keybuf.size));
+ if (keybuf.size > 0) {
+ keybuf.buffer = malloc(keybuf.size);
+ bytes = count = 0;
+ logthing(LOGTHING_TRACE,
+ "Getting %d bytes of key data.",
+ keybuf.size);
+ while (bytes >= 0 && count < keybuf.size) {
+ bytes = read(keyd_fd, &keybuf.buffer[count],
+ keybuf.size - count);
+ logthing(LOGTHING_TRACE,
+ "Read %d bytes.", bytes);
+ count += bytes;
+ }
+ read_openpgp_stream(buffer_fetchchar, &keybuf,
+ &packets, 0);
+ parse_keys(packets, publickey);
+ free_packet_list(packets);
+ packets = NULL;
+ free(keybuf.buffer);
+ keybuf.buffer = NULL;
+ keybuf.size = 0;
+ }
+ }
+
+ return (count > 0) ? 1 : 0;
+}
+
/**
* delete_key - Given a keyid delete the key from storage.
* @fp: The fingerprint of the key to delete.
* are using. Returns 0 if the key existed.
*/
static int keyd_delete_key(struct onak_dbctx *dbctx,
- struct openpgp_fingerprint *fp, bool intrans)
+ struct openpgp_fingerprint *fp,
+ __unused bool intrans)
{
int keyd_fd = (intptr_t) dbctx->priv;
* it?
*/
static int keyd_store_key(struct onak_dbctx *dbctx,
- struct openpgp_publickey *publickey, bool intrans,
+ struct openpgp_publickey *publickey,
+ __unused bool intrans,
bool update)
{
int keyd_fd = (intptr_t) dbctx->priv;
* this file are called in order to allow the DB to be initialized ready
* for access.
*/
-struct onak_dbctx *keydb_keyd_init(struct onak_db_config *dbcfg, bool readonly)
+struct onak_dbctx *keydb_keyd_init(struct onak_db_config *dbcfg,
+ __unused bool readonly)
{
struct sockaddr_un sock;
uint32_t cmd = KEYD_CMD_UNKNOWN;
dbctx->cleanupdb = keyd_cleanupdb;
dbctx->starttrans = keyd_starttrans;
dbctx->endtrans = keyd_endtrans;
- dbctx->fetch_key_id = keyd_fetch_key_id;
+ dbctx->fetch_key = keyd_fetch_key;
dbctx->fetch_key_fp = keyd_fetch_key_fp;
+ dbctx->fetch_key_id = keyd_fetch_key_id;
dbctx->fetch_key_text = keyd_fetch_key_text;
dbctx->fetch_key_skshash = keyd_fetch_key_skshash;
dbctx->store_key = keyd_store_key;