From 81a563991ffb0c37c9a30c660a5f20f413fb3b92 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 21 Mar 2016 09:18:36 +0000 Subject: [PATCH] [Feature] Allow base32 keys in maps --- src/libutil/map.c | 20 ++++++++++++++++---- src/libutil/map_private.h | 15 ++++++++------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/libutil/map.c b/src/libutil/map.c index e960b32fd..8de6e76c2 100644 --- a/src/libutil/map.c +++ b/src/libutil/map.c @@ -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 ++; } diff --git a/src/libutil/map_private.h b/src/libutil/map_private.h index 4350283c7..c26517574 100644 --- a/src/libutil/map_private.h +++ b/src/libutil/map_private.h @@ -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; -- 2.39.5