diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-01-29 19:27:08 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-01-29 19:27:08 +0000 |
commit | c4e10c1278a880f168257efb1d8fdf317d3c294c (patch) | |
tree | c10f7786710139b0d6119fbe4ce16b2687c34446 /src/libutil | |
parent | 17e047e1d0f5a84f2503f1550293213a4d4a6505 (diff) | |
download | rspamd-c4e10c1278a880f168257efb1d8fdf317d3c294c.tar.gz rspamd-c4e10c1278a880f168257efb1d8fdf317d3c294c.zip |
Add routine to parse remote pubkeys.
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/http.c | 27 | ||||
-rw-r--r-- | src/libutil/http.h | 2 |
2 files changed, 29 insertions, 0 deletions
diff --git a/src/libutil/http.c b/src/libutil/http.c index c562cffa1..8fd0e7448 100644 --- a/src/libutil/http.c +++ b/src/libutil/http.c @@ -1768,3 +1768,30 @@ rspamd_http_connection_key_destroy (gpointer key) g_assert (key != NULL); REF_RELEASE (kp); } + +GString * +rspamd_http_connection_make_peer_key (const gchar *key) +{ + guchar hashbuf[RSPAMD_HTTP_KEY_ID_LEN]; + gchar *b32_id; + guchar *pk_decoded; + GString *res = NULL; + gsize dec_len; + + pk_decoded = rspamd_decode_base32 (key, strlen (key), &dec_len); + + if (pk_decoded != NULL) { + if (dec_len == crypto_box_PUBLICKEYBYTES) { + res = g_string_new (NULL); + blake2b (hashbuf, pk_decoded, NULL, sizeof (hashbuf), dec_len, 0); + b32_id = rspamd_encode_base32 (hashbuf, sizeof (hashbuf)); + + g_string_printf (res, "%s%s", b32_id, key); + g_free (b32_id); + } + + g_free (pk_decoded); + } + + return res; +} diff --git a/src/libutil/http.h b/src/libutil/http.h index 7de3b2f68..b52671e10 100644 --- a/src/libutil/http.h +++ b/src/libutil/http.h @@ -195,6 +195,8 @@ GString *rspamd_http_connection_print_key (gpointer key, guint how); */ void rspamd_http_connection_key_destroy (gpointer key); +GString *rspamd_http_connection_make_peer_key (const gchar *key); + /** * Handle a request using socket fd and user data ud * @param conn connection structure |