commit c91e415ab6e930d482aed37866c7816c365ae23a
parent c8b32f6b6c904e81acc469aaf1a07bb0c61f508c
Author: lash <dev@holbrook.no>
Date: Fri, 28 Mar 2025 13:34:16 +0000
Normalize crypto path on init
Diffstat:
3 files changed, 27 insertions(+), 21 deletions(-)
diff --git a/src/aux/README.txt b/src/aux/README.txt
@@ -0,0 +1,5 @@
+This folder contains third party code used in the libqaeda project
+
+
+hashmap.c https://github.com/tidwall/hashmap.c MIT License
+cwalk https://github.com/likle/cwalk MIT License
diff --git a/src/crypto/gcrypt.c b/src/crypto/gcrypt.c
@@ -67,13 +67,17 @@ static int gpg_passphrase_digest_len;
/**
* Verifies that installed gpg version is supported.
* Sets up crypto keys dir and sets passphrase digest length.
+ *
+ * \todo replace path massage with cwalk lib
*/
int lq_crypto_init(const char *base) {
#ifdef RERR
rerr_register(RERR_PFX_GPG, "crypto", _rerr);
#endif
int r;
- const char *v;
+ int l;
+ char *v;
+ char path[LQ_PATH_MAX];
if (gpg_version == NULL) {
v = gcry_check_version(GPG_MIN_VERSION);
@@ -86,19 +90,21 @@ int lq_crypto_init(const char *base) {
gpg_passphrase_digest_len = gcry_md_get_algo_dlen(GCRY_MD_SHA256);
gpg_cfg_idx_dir = lq_config_register(LQ_TYP_STR, "CRYPTODIR");
- r = lq_config_set(gpg_cfg_idx_dir, base);
+
+ v = path;
+ l = strlen(base);
+ lq_cpy(v, base, l);
+ v += l;
+ if (*v != '/') {
+ *v = '/';
+ *(v+1) = 0;
+ }
+
+ r = lq_config_set(gpg_cfg_idx_dir, path);
if (r) {
return ERR_FAIL;
}
-// strcpy(gpg->path, path);
-// c = strlen(gpg->path);
-// p = gpg->path+c;
-// if (*p != '/') {
-// *p = '/';
-// *(p+1) = 0;
-// }
-
return ERR_OK;
}
@@ -218,10 +224,13 @@ static LQPrivKey* privatekey_alloc(const char *seed, size_t seed_len, const char
return NULL;
}
- //
+ // populate the internal key structure
o->impl = (void*)gpg;
o->key_typ = GPG_KEY_TYP;
o->key_state = LQ_KEY_INIT;
+
+ debug_x(LLOG_INFO, "gpg", "created new private key", 1, MORGEL_TYP_BIN, LQ_FP_LEN, "fingerprint", gpg->fingerprint);
+
return o;
}
@@ -800,6 +809,7 @@ LQPubKey* lq_publickey_new(const char *full) {
pubk->impl = (void*)gpg;
pubk->key_typ = GPG_KEY_TYP;
pubk->pk = NULL;
+
return pubk;
}
diff --git a/src/test/test_crypto.c b/src/test/test_crypto.c
@@ -17,15 +17,6 @@ static const char privkeydata[32] = {
0xf9, 0x8a, 0x5e, 0x88, 0x62, 0x66, 0xe7, 0xae,
};
-// sha256sum "bar" fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9
-//static const char passphrase[32] = {
-// 0xfc, 0xde, 0x2b, 0x2e, 0xdb, 0xa5, 0x6b, 0xf4,
-// 0x08, 0x60, 0x1f, 0xb7, 0x21, 0xfe, 0x9b, 0x5c,
-// 0x33, 0x8d, 0x10, 0xee, 0x42, 0x9e, 0xa0, 0x4f,
-// 0xae, 0x55, 0x11, 0xb6, 0x8f, 0xbf, 0x8f, 0xb9,
-//};
-
-
// "1234"
static const size_t passphrase_len = 4;
static const char passphrase[4] = {
@@ -165,7 +156,7 @@ int main(void) {
return 1;
}
- r = lq_crypto_init("./testdata/");
+ r = lq_crypto_init("./testdata");
if (r) {
return 1;
}