From: Vsevolod Stakhov Date: Wed, 4 Jan 2023 12:46:56 +0000 (+0000) Subject: [Minor] Allow different dump types for the keypairs X-Git-Tag: 3.5~109 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=27d878daa1f97dd40afc69d5bcb1ae23eb6c3b29;p=rspamd.git [Minor] Allow different dump types for the keypairs --- diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c index 76072ddcd..bea32134f 100644 --- a/src/fuzzy_storage.c +++ b/src/fuzzy_storage.c @@ -1882,7 +1882,7 @@ rspamd_fuzzy_stat_to_ucl (struct rspamd_fuzzy_storage_ctx *ctx, gboolean ip_stat ucl_object_insert_key (elt, ip_elt, "ips", 0, false); } - ucl_object_insert_key (elt, rspamd_keypair_to_ucl (fuzzy_key->key, FALSE), + ucl_object_insert_key (elt, rspamd_keypair_to_ucl (fuzzy_key->key, RSPAMD_KEYPAIR_DUMP_NO_SECRET), "keypair", 0, false); ucl_object_insert_key (keys_obj, elt, keyname, 0, true); } diff --git a/src/libcryptobox/keypair.c b/src/libcryptobox/keypair.c index 98e2322d3..b97cd699e 100644 --- a/src/libcryptobox/keypair.c +++ b/src/libcryptobox/keypair.c @@ -787,7 +787,7 @@ rspamd_keypair_from_ucl (const ucl_object_t *obj) ucl_object_t * rspamd_keypair_to_ucl (struct rspamd_cryptobox_keypair *kp, - gboolean is_hex) + enum rspamd_keypair_dump_flags flags) { ucl_object_t *ucl_out, *elt; gint how = 0; @@ -796,7 +796,7 @@ rspamd_keypair_to_ucl (struct rspamd_cryptobox_keypair *kp, g_assert (kp != NULL); - if (is_hex) { + if (flags & RSPAMD_KEYPAIR_DUMP_HEX) { how |= RSPAMD_KEYPAIR_HEX; encoding = "hex"; } @@ -817,13 +817,15 @@ rspamd_keypair_to_ucl (struct rspamd_cryptobox_keypair *kp, "pubkey", 0, false); g_string_free (keypair_out, TRUE); - /* privkey part */ - keypair_out = rspamd_keypair_print (kp, - RSPAMD_KEYPAIR_PRIVKEY|how); - ucl_object_insert_key (elt, - ucl_object_fromlstring (keypair_out->str, keypair_out->len), + if (!(flags & RSPAMD_KEYPAIR_DUMP_NO_SECRET)) { + /* privkey part */ + keypair_out = rspamd_keypair_print(kp, + RSPAMD_KEYPAIR_PRIVKEY | how); + ucl_object_insert_key(elt, + ucl_object_fromlstring(keypair_out->str, keypair_out->len), "privkey", 0, false); - g_string_free (keypair_out, TRUE); + g_string_free(keypair_out, TRUE); + } keypair_out = rspamd_keypair_print (kp, RSPAMD_KEYPAIR_ID|how); diff --git a/src/libcryptobox/keypair.h b/src/libcryptobox/keypair.h index ecb7fc81c..ed247e8ca 100644 --- a/src/libcryptobox/keypair.h +++ b/src/libcryptobox/keypair.h @@ -244,13 +244,20 @@ const guchar *rspamd_keypair_component (struct rspamd_cryptobox_keypair *kp, */ struct rspamd_cryptobox_keypair *rspamd_keypair_from_ucl (const ucl_object_t *obj); + +enum rspamd_keypair_dump_flags { + RSPAMD_KEYPAIR_DUMP_DEFAULT = 0, + RSPAMD_KEYPAIR_DUMP_HEX = 1u << 0u, + RSPAMD_KEYPAIR_DUMP_NO_SECRET = 1u << 1u, +}; + /** * Converts keypair to ucl object * @param kp * @return */ ucl_object_t *rspamd_keypair_to_ucl (struct rspamd_cryptobox_keypair *kp, - gboolean is_hex); + enum rspamd_keypair_dump_flags flags); /** diff --git a/src/lua/lua_cryptobox.c b/src/lua/lua_cryptobox.c index e18658d88..e342610ce 100644 --- a/src/lua/lua_cryptobox.c +++ b/src/lua/lua_cryptobox.c @@ -567,7 +567,7 @@ lua_cryptobox_keypair_totable (lua_State *L) hex = lua_toboolean (L, 2); } - obj = rspamd_keypair_to_ucl (kp, hex); + obj = rspamd_keypair_to_ucl (kp, hex ? RSPAMD_KEYPAIR_DUMP_HEX : RSPAMD_KEYPAIR_DUMP_DEFAULT); ret = ucl_object_push_lua (L, obj, true); ucl_object_unref (obj);