]> source.dussan.org Git - rspamd.git/commitdiff
Add routine to parse remote pubkeys.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 29 Jan 2015 19:27:08 +0000 (19:27 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 29 Jan 2015 19:27:08 +0000 (19:27 +0000)
src/libutil/http.c
src/libutil/http.h

index c562cffa173441fa73a91997bc8898e5b67a89f9..8fd0e7448150b65a7878c0e1f90e56a17e033ecf 100644 (file)
@@ -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;
+}
index 7de3b2f6860a16f75c36edd9825d8257ca243538..b52671e102379be3c8095bb35cc1187a2511b12a 100644 (file)
@@ -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