ret = 1;
}
if (ret == 0) {
- bytes = read(fd, &keyid, sizeof(keyid));
- if (bytes != sizeof(keyid)) {
+ bytes = read(fd, &fingerprint,
+ sizeof(fingerprint));
+ if (bytes != sizeof(fingerprint)) {
ret = 1;
}
}
", result: %d",
keyid,
dbctx->delete_key(dbctx,
- keyid, false));
+ &fingerprint, false));
}
break;
case KEYD_CMD_GETFULLKEYID:
/**
* @brief Given a keyid delete the key from storage.
- * @param keyid The keyid to delete.
+ * @param fp The fingerprint of the key to delete.
* @param intrans If we're already in a transaction.
*
* This function deletes a public key from whatever storage mechanism we
* are using. Returns 0 if the key existed.
*/
- int (*delete_key)(struct onak_dbctx *, uint64_t keyid, bool intrans);
+ int (*delete_key)(struct onak_dbctx *, struct openpgp_fingerprint *fp,
+ bool intrans);
/**
* @brief Trys to find the keys that contain the supplied text.
/**
* delete_key - Given a keyid delete the key from storage.
- * @keyid: The keyid to delete.
+ * @fp: The fingerprint of the key to delete.
* @intrans: If we're already in a transaction.
*
* This function deletes a public key from whatever storage mechanism we
* are using. Returns 0 if the key existed.
*/
static int db4_delete_key(struct onak_dbctx *dbctx,
- uint64_t keyid, bool intrans)
+ struct openpgp_fingerprint *fp,
+ bool intrans)
{
struct onak_db4_dbctx *privctx = (struct onak_db4_dbctx *) dbctx->priv;
struct openpgp_publickey *publickey = NULL;
struct ll *curword = NULL;
bool deadlock = false;
struct skshash hash;
- struct openpgp_fingerprint fingerprint;
+ uint64_t keyid;
if (!intrans) {
db4_starttrans(dbctx);
}
- if (db4_fetch_key_id(dbctx, keyid, &publickey, true) == 0) {
+ if (db4_fetch_key_fp(dbctx, fp, &publickey, true) == 0) {
if (!intrans) {
db4_endtrans(dbctx);
}
return 1;
}
- get_fingerprint(publickey->publickey, &fingerprint);
+ if (get_keyid(publickey, &keyid) != ONAK_E_OK) {
+ return 1;
+ }
/*
* Walk through the uids removing the words from the worddb.
memset(&data, 0, sizeof(data));
key.data = curword->object;
key.size = strlen(key.data);
- data.data = fingerprint.fp;
- data.size = fingerprint.length;
+ data.data = fp->fp;
+ data.size = fp->length;
ret = cursor->c_get(cursor,
&key,
memset(&data, 0, sizeof(data));
key.data = &shortkeyid;
key.size = sizeof(shortkeyid);
- data.data = fingerprint.fp;
- data.size = fingerprint.length;
+ data.data = fp->fp;
+ data.size = fp->length;
ret = cursor->c_get(cursor,
&key,
memset(&data, 0, sizeof(data));
key.data = &keyid;
key.size = sizeof(keyid);
- data.data = fingerprint.fp;
- data.size = fingerprint.length;
+ data.data = fp->fp;
+ data.size = fp->length;
ret = cursor64->c_get(cursor64,
&key,
memset(&data, 0, sizeof(data));
key.data = &shortkeyid;
key.size = sizeof(shortkeyid);
- data.data = fingerprint.fp;
- data.size = fingerprint.length;
+ data.data = fp->fp;
+ data.size = fp->length;
ret = cursor->c_get(cursor,
&key,
memset(&data, 0, sizeof(data));
key.data = &subkeyid;
key.size = sizeof(subkeyid);
- data.data = fingerprint.fp;
- data.size = fingerprint.length;
+ data.data = fp->fp;
+ data.size = fp->length;
ret = cursor64->c_get(cursor64,
&key,
memset(&data, 0, sizeof(data));
key.data = hash.hash;
key.size = sizeof(hash.hash);
- data.data = fingerprint.fp;
- data.size = fingerprint.length;
+ data.data = fp->fp;
+ data.size = fp->length;
ret = cursor->c_get(cursor,
&key,
publickey = NULL;
if (!deadlock) {
- key.data = fingerprint.fp;
- key.size = fingerprint.length;
-
- keydb_fp(privctx, &fingerprint)->del(keydb_fp(privctx,
- &fingerprint),
- privctx->txn,
- &key,
- 0); /* flags */
-
- /* Delete old style 64 bit keyid */
- key.data = &keyid;
- key.size = sizeof(keyid);
+ key.data = fp->fp;
+ key.size = fp->length;
- keydb_id(privctx, keyid)->del(keydb_id(privctx, keyid),
+ keydb_fp(privctx, fp)->del(keydb_fp(privctx, fp),
privctx->txn,
&key,
0); /* flags */
* it definitely needs updated.
*/
if (update) {
- deadlock = (db4_delete_key(dbctx, keyid, true) == -1);
+ deadlock = (db4_delete_key(dbctx, &fingerprint, true) == -1);
}
/*
publickey, intrans, update);
}
-static int dynamic_delete_key(struct onak_dbctx *dbctx, uint64_t keyid,
+static int dynamic_delete_key(struct onak_dbctx *dbctx,
+ struct openpgp_fingerprint *fp,
bool intrans)
{
struct onak_dynamic_dbctx *privctx =
(struct onak_dynamic_dbctx *) dbctx->priv;
return privctx->loadeddbctx->delete_key(privctx->loadeddbctx,
- keyid, intrans);
+ fp, intrans);
}
static int dynamic_update_keys(struct onak_dbctx *dbctx,
/**
* delete_key - Given a keyid delete the key from storage.
- * @keyid: The keyid to delete.
+ * @fp: The fingerprint of the key to delete.
* @intrans: If we're already in a transaction.
*
* This function deletes a public key from whatever storage mechanism we
* are using. Returns 0 if the key existed.
*/
static int file_delete_key(struct onak_dbctx *dbctx,
- uint64_t keyid, bool intrans)
+ struct openpgp_fingerprint *fp, bool intrans)
{
char *db_dir = (char *) dbctx->priv;
char keyfile[1024];
snprintf(keyfile, 1023, "%s/0x%" PRIX64, db_dir,
- keyid & 0xFFFFFFFF);
+ fingerprint2keyid(fp) & 0xFFFFFFFF);
return unlink(keyfile);
}
/**
* delete_key - Given a keyid delete the key from storage.
- * @keyid: The keyid to delete.
+ * @fp: The fingerprint of the key to delete.
* @intrans: If we're already in a transaction.
*/
-static int fs_delete_key(struct onak_dbctx *dbctx, uint64_t keyid, bool intrans)
+static int fs_delete_key(struct onak_dbctx *dbctx,
+ struct openpgp_fingerprint *fp, bool intrans)
{
static char buffer[PATH_MAX];
int ret;
struct openpgp_fingerprint *subkeyids = NULL;
uint64_t subkeyid;
int i = 0;
+ uint64_t keyid;
- if ((keyid >> 32) == 0)
- keyid = fs_getfullkeyid(dbctx, keyid);
+ keyid = fingerprint2keyid(fp);
+ if (keyid == 0)
+ return 1;
if (!intrans)
fs_starttrans(dbctx);
/**
* delete_key - Given a keyid delete the key from storage.
- * @keyid: The keyid to delete.
+ * @fp: The fingerprint of the key to delete.
* @intrans: If we're already in a transaction.
*
* No op for HKP.
*/
static int hkp_delete_key(struct onak_dbctx *dbctx,
- uint64_t keyid, bool intrans)
+ struct openpgp_fingerprint *fp, bool intrans)
{
return -1;
}
/**
* delete_key - Given a keyid delete the key from storage.
-* @keyid: The keyid to delete.
+ * @fp: The fingerprint of the key to delete.
* @intrans: If we're already in a transaction.
*
* This function deletes a public key from whatever storage mechanism we
* are using. Returns 0 if the key existed.
*/
static int keyd_delete_key(struct onak_dbctx *dbctx,
- uint64_t keyid, bool intrans)
+ struct openpgp_fingerprint *fp, bool intrans)
{
int keyd_fd = (intptr_t) dbctx->priv;
if (keyd_send_cmd(keyd_fd, KEYD_CMD_DELETE)) {
- write(keyd_fd, &keyid, sizeof(keyid));
+ write(keyd_fd, fp, sizeof(*fp));
}
return 0;
/**
* delete_key - Given a keyid delete the key from storage.
- * @keyid: The keyid to delete.
+ * @fp: The fingerprint of the key to delete.
* @intrans: If we're already in a transaction.
*
* We don't support removing keys from a keyring file.
*/
static int keyring_delete_key(struct onak_dbctx *dbctx,
- uint64_t keyid, bool intrans)
+ struct openpgp_fingerprint *fp, bool intrans)
{
return 1;
}
* Walk the keyring file, noting the start of each public key and the
* total length of packets associated with it.
*/
- pos = start = totlen = 0;
+ len = pos = start = totlen = 0;
while (((privctx->length - pos) > 5) && (privctx->file[pos] & 0x80)) {
if (privctx->file[pos] & 0x40) {
tag = privctx->file[pos] & 0x3F;
/**
* delete_key - Given a keyid delete the key from storage.
- * @keyid: The keyid to delete.
+ * @fp: The fingerprint of the key to delete.
* @intrans: If we're already in a transaction.
*
* This function deletes a public key from whatever storage mechanism we
* are using. Returns 0 if the key existed.
*/
-static int pg_delete_key(struct onak_dbctx *dbctx, uint64_t keyid, bool intrans)
+static int pg_delete_key(struct onak_dbctx *dbctx,
+ struct openpgp_fingerprint *fp, bool intrans)
{
PGconn *dbconn = (PGconn *) dbctx->priv;
PGresult *result = NULL;
int found = 1;
int i;
Oid key_oid;
+ uint64_t keyid;
if (!intrans) {
result = PQexec(dbconn, "BEGIN");
PQclear(result);
}
+
+ keyid = fingerprint2keyid(fp);
snprintf(statement, 1023,
"SELECT keydata FROM onak_keys WHERE keyid = '%"
int i;
uint64_t keyid;
struct pg_fc_ctx fcctx;
+ struct openpgp_fingerprint fp;
if (!intrans) {
result = PQexec(dbconn, "BEGIN");
* it definitely needs updated.
*/
if (update) {
- pg_delete_key(dbctx, keyid, true);
+ get_fingerprint(publickey->publickey, &fp);
+ pg_delete_key(dbctx, &fp, true);
}
next = publickey->next;
publickey, intrans, update);
}
-static int stacked_delete_key(struct onak_dbctx *dbctx, uint64_t keyid,
+static int stacked_delete_key(struct onak_dbctx *dbctx,
+ struct openpgp_fingerprint *fp,
bool intrans)
{
struct onak_stacked_dbctx *privctx =
(struct onak_dbctx *) privctx->backends->object;
return backend->delete_key(backend,
- keyid, intrans);
+ fp, intrans);
}
static int stacked_update_keys(struct onak_dbctx *dbctx,
puts("Key not found");
}
} else if (!strcmp("delete", argv[optind])) {
- dbctx->delete_key(dbctx,
- dbctx->getfullkeyid(dbctx, keyid),
- false);
+ if (!isfp) {
+ if (dbctx->fetch_key_id(dbctx, keyid, &keys,
+ true)) {
+ get_fingerprint(keys->publickey,
+ &fingerprint);
+ dbctx->delete_key(dbctx, &fingerprint,
+ true);
+ }
+ } else
+ dbctx->delete_key(dbctx, &fingerprint, false);
} else if (!strcmp("get", argv[optind])) {
if (!(ishex || isfp)) {
puts("Can't get a key on uid text."
} else if (!strcmp("reindex", argv[optind])) {
dbctx->starttrans(dbctx);
if (dbctx->fetch_key_id(dbctx, keyid, &keys, true)) {
- dbctx->delete_key(dbctx, keyid, true);
+ get_fingerprint(keys->publickey, &fingerprint);
+ dbctx->delete_key(dbctx, &fingerprint, true);
cleankeys(&keys, config.clean_policies);
dbctx->store_key(dbctx, keys, true, false);
} else {