Browse Source

[Feature] Allow base32 keys in maps

tags/1.2.0
Vsevolod Stakhov 8 years ago
parent
commit
81a563991f
2 changed files with 24 additions and 11 deletions
  1. 16
    4
      src/libutil/map.c
  2. 8
    7
      src/libutil/map_private.h

+ 16
- 4
src/libutil/map.c View 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 ++;
}

+ 8
- 7
src/libutil/map_private.h View 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;


Loading…
Cancel
Save