From c4e10c1278a880f168257efb1d8fdf317d3c294c Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 29 Jan 2015 19:27:08 +0000 Subject: [PATCH] Add routine to parse remote pubkeys. --- src/libutil/http.c | 27 +++++++++++++++++++++++++++ src/libutil/http.h | 2 ++ 2 files changed, 29 insertions(+) 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 -- 2.39.5