]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Feature] Allow to parse pubkeys from the rcl config
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 23 May 2016 08:24:21 +0000 (09:24 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 23 May 2016 08:24:21 +0000 (09:24 +0100)
src/libserver/cfg_rcl.c
src/libserver/cfg_rcl.h

index f774ac126c43c8c16bba4bc9211b71c492cf3dea..ebbc29d611811ece9d3b99beb3041a987bc86b9c 100644 (file)
@@ -2668,7 +2668,6 @@ rspamd_rcl_parse_struct_keypair (rspamd_mempool_t *pool,
        struct rspamd_rcl_struct_parser *pd = ud;
        struct rspamd_cryptobox_keypair **target, *kp;
 
-
        target = (struct rspamd_cryptobox_keypair **)(((gchar *)pd->user_struct) +
                        pd->offset);
        if (obj->type == UCL_OBJECT) {
@@ -2698,6 +2697,49 @@ rspamd_rcl_parse_struct_keypair (rspamd_mempool_t *pool,
        return TRUE;
 }
 
+gboolean
+rspamd_rcl_parse_struct_pubkey (rspamd_mempool_t *pool,
+       const ucl_object_t *obj,
+       gpointer ud,
+       struct rspamd_rcl_section *section,
+       GError **err)
+{
+       struct rspamd_rcl_struct_parser *pd = ud;
+       struct rspamd_cryptobox_pubkey **target, *pk;
+       gsize len;
+       const gchar *str;
+
+       target = (struct rspamd_cryptobox_pubkey **)(((gchar *)pd->user_struct) +
+                       pd->offset);
+       if (obj->type == UCL_STRING) {
+               str = ucl_object_tolstring (obj, &len);
+               pk = rspamd_pubkey_from_base32 (str, len, RSPAMD_KEYPAIR_KEX,
+                               RSPAMD_CRYPTOBOX_MODE_25519);
+
+               if (pk != NULL) {
+                       *target = pk;
+               }
+               else {
+                       g_set_error (err,
+                                       CFG_RCL_ERROR,
+                                       EINVAL,
+                                       "cannot load the pubkey specified: %s",
+                                       ucl_object_key (obj));
+                       return FALSE;
+               }
+       }
+       else {
+               g_set_error (err,
+                               CFG_RCL_ERROR,
+                               EINVAL,
+                               "no sane pubkey found in the element: %s",
+                               ucl_object_key (obj));
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
 static void
 rspamd_rcl_insert_string_list_item (gpointer *target, rspamd_mempool_t *pool,
                const gchar *src, gboolean is_hash)
index ee0a1b5260dd35017523fcc5933cb8102a2ff058..1a27b056f8bddeb46ba5553795efe839bf7055d9 100644 (file)
@@ -277,6 +277,21 @@ gboolean rspamd_rcl_parse_struct_keypair (rspamd_mempool_t *pool,
        struct rspamd_rcl_section *section,
        GError **err);
 
+/**
+ * Parse a pubkey field of a structure
+ * @param cfg config pointer
+ * @param obj object to parse
+ * @param ud struct_parser structure (flags mean the exact structure used)
+ * @param section the current section
+ * @param err error pointer
+ * @return TRUE if a value has been successfully parsed
+ */
+gboolean rspamd_rcl_parse_struct_pubkey (rspamd_mempool_t *pool,
+       const ucl_object_t *obj,
+       gpointer ud,
+       struct rspamd_rcl_section *section,
+       GError **err);
+
 /**
  * Parse a inet addr field of a structure
  * @param cfg config pointer