]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Feature] Allow base32 keys in maps
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 21 Mar 2016 09:18:36 +0000 (09:18 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 21 Mar 2016 09:18:36 +0000 (09:18 +0000)
src/libutil/map.c
src/libutil/map_private.h

index e960b32fd99948fbdc0f3d95cb14256687d46418..8de6e76c215b7ba2221f8601ea0b05ca24fd992e 100644 (file)
@@ -791,7 +791,7 @@ static const gchar *
 rspamd_map_check_proto (struct rspamd_config *cfg,
                const gchar *map_line, struct rspamd_map *map)
 {
-       const gchar *pos = map_line, *end;
+       const gchar *pos = map_line, *end, *end_key;
 
        g_assert (map != NULL);
        g_assert (pos != NULL);
@@ -805,8 +805,21 @@ rspamd_map_check_proto (struct rspamd_config *cfg,
 
        if (g_ascii_strncasecmp (pos, "key=", sizeof ("key=") - 1) == 0) {
                pos += sizeof ("key=") - 1;
+               end_key = memchr (pos, '+', end - pos);
 
-               if (end - pos > 64) {
+               if (end_key != NULL) {
+                       map->trusted_pubkey = rspamd_pubkey_from_base32 (pos, end_key - pos,
+                                       RSPAMD_KEYPAIR_SIGN, RSPAMD_CRYPTOBOX_MODE_25519);
+
+                       if (map->trusted_pubkey == NULL) {
+                               msg_err_config ("cannot read pubkey from map: %s",
+                                               map_line);
+                               return NULL;
+                       }
+                       pos = end_key + 1;
+               }
+               else if (end - pos > 64) {
+                       /* Try hex encoding */
                        map->trusted_pubkey = rspamd_pubkey_from_hex (pos, 64,
                                        RSPAMD_KEYPAIR_SIGN, RSPAMD_CRYPTOBOX_MODE_25519);
 
@@ -815,6 +828,7 @@ rspamd_map_check_proto (struct rspamd_config *cfg,
                                                map_line);
                                return NULL;
                        }
+                       pos += 64;
                }
                else {
                        msg_err_config ("cannot read pubkey from map: %s",
@@ -822,8 +836,6 @@ rspamd_map_check_proto (struct rspamd_config *cfg,
                        return NULL;
                }
 
-               pos += 64;
-
                if (*pos == '+' || *pos == ':') {
                        pos ++;
                }
index 4350283c7f2cc827ff5b397df35afddfc4e1479c..c26517574e9e108f0cab1a633416f9d7178acd0f 100644 (file)
@@ -72,6 +72,13 @@ struct http_map_data {
        gboolean request_sent;
 };
 
+enum rspamd_map_http_stage {
+       map_resolve_host2 = 0, /* 2 requests sent */
+       map_resolve_host1, /* 1 requests sent */
+       map_load_file,
+       map_load_pubkey,
+       map_load_signature
+};
 
 struct http_callback_data {
        struct event_base *ev_base;
@@ -84,13 +91,7 @@ struct http_callback_data {
        struct rspamd_cryptobox_pubkey *pk;
        gchar *tmpfile;
 
-       enum {
-               map_resolve_host2 = 0, /* 2 requests sent */
-               map_resolve_host1, /* 1 requests sent */
-               map_load_file,
-               map_load_pubkey,
-               map_load_signature
-       } stage;
+       enum rspamd_map_http_stage stage;
        gint out_fd;
        gint fd;