mirror of
https://codeberg.org/scip/pcp.git
synced 2025-12-17 12:00:56 +01:00
moved all uthash related code into keyhash.c
This commit is contained in:
@@ -93,9 +93,7 @@ int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd) {
|
||||
unsigned char *check = ucmalloc(crypto_hash_BYTES);
|
||||
memcpy(hash, combined, crypto_hash_BYTES);
|
||||
|
||||
for(public=pcppubkey_hash;
|
||||
public != NULL;
|
||||
public=(pcp_pubkey_t*)(public->hh.next)) {
|
||||
pcphash_iteratepub(public) {
|
||||
crypto_hash(check, (unsigned char*)public->id, 16);
|
||||
if(memcmp(check, hash, crypto_hash_BYTES) == 0) {
|
||||
// found one
|
||||
@@ -105,7 +103,7 @@ int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd) {
|
||||
if(public == NULL) {
|
||||
// maybe self encryption, try secrets
|
||||
pcp_key_t *s = NULL;
|
||||
for(s=pcpkey_hash; s != NULL; s=(pcp_key_t*)(s->hh.next)) {
|
||||
pcphash_iterate(s) {
|
||||
crypto_hash(check, (unsigned char*)s->id, 16);
|
||||
if(memcmp(check, hash, crypto_hash_BYTES) == 0) {
|
||||
// matching secret
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "uthash.h"
|
||||
#include "z85.h"
|
||||
#include "keyprint.h"
|
||||
#include "keyhash.h"
|
||||
|
||||
int pcpdecrypt(char *id, int useid, char *infile, char *outfile, char *passwd);
|
||||
int pcpencrypt(char *id, char *infile, char *outfile, char *passwd, char *recipient);
|
||||
|
||||
@@ -131,12 +131,12 @@ void pcp_listkeys() {
|
||||
if(nkeys > 0) {
|
||||
printf("Key ID Type Creation Time Owner\n");
|
||||
|
||||
for(k=pcpkey_hash; k != NULL; k=(pcp_key_t*)(k->hh.next)) {
|
||||
pcphash_iterate(k) {
|
||||
pcpkey_printlineinfo(k);
|
||||
}
|
||||
|
||||
pcp_pubkey_t *p;
|
||||
for(p=pcppubkey_hash; p != NULL; p=(pcp_pubkey_t*)(p->hh.next)) {
|
||||
pcphash_iteratepub(p) {
|
||||
pcppubkey_printlineinfo(p);
|
||||
}
|
||||
}
|
||||
@@ -184,7 +184,7 @@ char *pcp_normalize_id(char *keyid) {
|
||||
pcp_key_t *pcp_find_primary_secret() {
|
||||
pcp_key_t *key = NULL;
|
||||
pcp_key_t *k;
|
||||
for(k=pcpkey_hash; k != NULL; k=(pcp_key_t*)(k->hh.next)) {
|
||||
pcphash_iterate(k) {
|
||||
if(k->type == PCP_KEY_TYPE_MAINSECRET) {
|
||||
key = ucmalloc(sizeof(pcp_key_t));
|
||||
memcpy(key, k, sizeof(pcp_key_t));
|
||||
@@ -195,7 +195,7 @@ pcp_key_t *pcp_find_primary_secret() {
|
||||
// no primary? whoops
|
||||
int nkeys = HASH_COUNT(pcpkey_hash);
|
||||
if(nkeys == 1) {
|
||||
for(k=pcpkey_hash; k != NULL; k=(pcp_key_t*)(k->hh.next)) {
|
||||
pcphash_iterate(k) {
|
||||
key = ucmalloc(sizeof(pcp_key_t));
|
||||
memcpy(key, k, sizeof(pcp_key_t));
|
||||
return key;
|
||||
@@ -474,7 +474,7 @@ int pcp_sanitycheck_pub(pcp_pubkey_t *key) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
pcp_pubkey_t *maybe = pcppubkey_exists(key->id);
|
||||
pcp_pubkey_t *maybe = pcphash_pubkeyexists(key->id);
|
||||
if(maybe != NULL) {
|
||||
fatal("Pubkey sanity check: there already exists a key with the id 0x%s\n", key->id);
|
||||
return 1;
|
||||
@@ -525,7 +525,7 @@ int pcp_sanitycheck_key(pcp_key_t *key) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
pcp_key_t *maybe = pcpkey_exists(key->id);
|
||||
pcp_key_t *maybe = pcphash_keyexists(key->id);
|
||||
if(maybe != NULL) {
|
||||
fatal("Secretkey sanity check: there already exists a key with the id 0x%s\n", key->id);
|
||||
return 1;
|
||||
@@ -535,7 +535,7 @@ int pcp_sanitycheck_key(pcp_key_t *key) {
|
||||
}
|
||||
|
||||
void pcpdelete_key(char *keyid) {
|
||||
pcp_pubkey_t *p = pcppubkey_exists(keyid);
|
||||
pcp_pubkey_t *p = pcphash_pubkeyexists(keyid);
|
||||
|
||||
if(p != NULL) {
|
||||
// delete public
|
||||
@@ -545,7 +545,7 @@ void pcpdelete_key(char *keyid) {
|
||||
fprintf(stderr, "Public key deleted.\n");
|
||||
}
|
||||
else {
|
||||
pcp_key_t *s = pcpkey_exists(keyid);
|
||||
pcp_key_t *s = pcphash_keyexists(keyid);
|
||||
if(s != NULL) {
|
||||
// delete secret
|
||||
HASH_DEL(pcpkey_hash, s);
|
||||
@@ -560,7 +560,7 @@ void pcpdelete_key(char *keyid) {
|
||||
}
|
||||
|
||||
void pcpedit_key(char *keyid) {
|
||||
pcp_key_t *key = pcpkey_exists(keyid);
|
||||
pcp_key_t *key = pcphash_keyexists(keyid);
|
||||
|
||||
if(key != NULL) {
|
||||
if(key->secret[0] == 0) {
|
||||
@@ -599,7 +599,7 @@ char *pcp_find_id_byrec(char *recipient) {
|
||||
pcp_pubkey_t *p;
|
||||
char *id = NULL;
|
||||
_lc(recipient);
|
||||
for(p=pcppubkey_hash; p != NULL; p=(pcp_pubkey_t*)(p->hh.next)) {
|
||||
pcphash_iteratepub(p) {
|
||||
if(strncmp(p->owner, recipient, 255) == 0) {
|
||||
id = ucmalloc(17);
|
||||
strncpy(id, p->id, 17);
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "defines.h"
|
||||
#include "readpass.h"
|
||||
#include "keyprint.h"
|
||||
#include "keyhash.h"
|
||||
|
||||
#define _WITH_GETLINE
|
||||
|
||||
|
||||
@@ -140,14 +140,14 @@ int pcptext_infile(char *infile) {
|
||||
|
||||
|
||||
void pcptext_key(char *keyid) {
|
||||
pcp_key_t *s = pcpkey_exists(keyid);
|
||||
pcp_key_t *s = pcphash_keyexists(keyid);
|
||||
if(s != NULL) {
|
||||
if(debug)
|
||||
pcp_dumpkey(s);
|
||||
pcpkey_print(s, stdout);
|
||||
}
|
||||
else {
|
||||
pcp_pubkey_t *p = pcppubkey_exists(keyid);
|
||||
pcp_pubkey_t *p = pcphash_pubkeyexists(keyid);
|
||||
if(p != NULL) {
|
||||
if(debug)
|
||||
pcp_dumppubkey(p);
|
||||
@@ -431,7 +431,7 @@ void pcpexport_yaml(char *outfile) {
|
||||
fprintf(out, "---\n");
|
||||
fprintf(out, "secret-keys:\n");
|
||||
|
||||
for(s=pcpkey_hash; s != NULL; s=(pcp_key_t*)(s->hh.next)) {
|
||||
pcphash_iterate(s) {
|
||||
fprintf(out, " -\n");
|
||||
fprintf(out, " id: %s\n", s->id);
|
||||
fprintf(out, " owner: %s\n", s->owner);
|
||||
@@ -456,7 +456,7 @@ void pcpexport_yaml(char *outfile) {
|
||||
}
|
||||
|
||||
fprintf(out, "public-keys:\n");
|
||||
for(p=pcppubkey_hash; p != NULL; p=(pcp_pubkey_t*)(p->hh.next)) {
|
||||
pcphash_iteratepub(p) {
|
||||
fprintf(out, " -\n");
|
||||
fprintf(out, " id: %s\n", p->id);
|
||||
fprintf(out, " owner: %s\n", p->owner);
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "vault.h"
|
||||
#include "pcp.h"
|
||||
#include "keymgmt.h"
|
||||
#include "keyhash.h"
|
||||
|
||||
void pcp_dumpkey(pcp_key_t *k);
|
||||
void pcp_dumppubkey(pcp_pubkey_t *k);
|
||||
|
||||
@@ -229,7 +229,7 @@ int main (int argc, char **argv) {
|
||||
}
|
||||
|
||||
if(usevault == 1) {
|
||||
pcp_inithashes();
|
||||
pcphash_init();
|
||||
vault = pcpvault_init(vaultfile);
|
||||
if(vault != NULL) {
|
||||
switch (mode) {
|
||||
@@ -396,7 +396,7 @@ int main (int argc, char **argv) {
|
||||
}
|
||||
}
|
||||
pcpvault_close(vault);
|
||||
pcp_cleanhashes();
|
||||
pcphash_clean();
|
||||
ucfree(vaultfile);
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user