]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Allow different dump types for the keypairs
authorVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 4 Jan 2023 12:46:56 +0000 (12:46 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 4 Jan 2023 12:46:56 +0000 (12:46 +0000)
src/fuzzy_storage.c
src/libcryptobox/keypair.c
src/libcryptobox/keypair.h
src/lua/lua_cryptobox.c

index 76072ddcdab39120b764ad17f69ba95ea074809f..bea32134f7650a7c4c80b63d7da3e2795980a4ad 100644 (file)
@@ -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);
                }
index 98e2322d322fafbd81d136b03d4c8637940b2e5a..b97cd699e6c8a18e24f81e1c2889d7784324742d 100644 (file)
@@ -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);
index ecb7fc81cd94e58a70671ae90a229672152bf91c..ed247e8ca5bebe0919bfd3a6190fefb9d93e4b49 100644 (file)
@@ -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);
 
 
 /**
index e18658d883832d1818dbfd643267cf2e1a13c418..e342610ce49e4788605140bb6d311173db19e21b 100644 (file)
@@ -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);