aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-01-28 17:52:59 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-01-28 17:52:59 +0000
commitddc00caeab38019d9d34fed60168dc33de754b1f (patch)
tree3456eae45be89ddb3ae82c13eab1c51331b8f8f1 /src
parenta5fdfa3a5a6642bf350260cc72a4c87c27abdab3 (diff)
downloadrspamd-ddc00caeab38019d9d34fed60168dc33de754b1f.tar.gz
rspamd-ddc00caeab38019d9d34fed60168dc33de754b1f.zip
Rework key API to allow reusing of keypairs.
Diffstat (limited to 'src')
-rw-r--r--src/libutil/http.c33
-rw-r--r--src/libutil/http.h16
2 files changed, 32 insertions, 17 deletions
diff --git a/src/libutil/http.c b/src/libutil/http.c
index 91cf43084..84e4b2655 100644
--- a/src/libutil/http.c
+++ b/src/libutil/http.c
@@ -1540,31 +1540,40 @@ rspamd_http_router_free (struct rspamd_http_connection_router *router)
}
}
-gboolean
-rspamd_http_connection_set_key (struct rspamd_http_connection *conn,
- gchar *key, gsize keylen)
+gpointer
+rspamd_http_connection_make_key (gchar *key, gsize keylen)
{
guchar *decoded;
gsize decoded_len;
- struct rspamd_http_connection_private *priv = conn->priv;
+ struct rspamd_http_keypair *kp;
decoded = rspamd_decode_base32 (key, keylen, &decoded_len);
if (decoded != NULL) {
if (decoded_len == crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES) {
- priv->local_key = g_slice_alloc (sizeof (*priv->local_key));
- memcpy (priv->local_key->sk, decoded, crypto_box_SECRETKEYBYTES);
- memcpy (priv->local_key->pk, decoded + crypto_box_SECRETKEYBYTES,
+ kp = g_slice_alloc (sizeof (*kp));
+ memcpy (kp->sk, decoded, crypto_box_SECRETKEYBYTES);
+ memcpy (kp->pk, decoded + crypto_box_SECRETKEYBYTES,
crypto_box_PUBLICKEYBYTES);
- crypto_box_beforenm (priv->local_key->beforenm, priv->local_key->pk,
- priv->local_key->sk);
- blake2b (priv->local_key->id, priv->local_key->pk, NULL,
- sizeof (priv->local_key->id), sizeof (priv->local_key->pk), 0);
+ crypto_box_beforenm (kp->beforenm, kp->pk,
+ kp->sk);
+ blake2b (kp->id, kp->pk, NULL, sizeof (kp->id), sizeof (kp->pk), 0);
- return TRUE;
+ return (gpointer)kp;
}
g_free (decoded);
}
return FALSE;
}
+
+void
+rspamd_http_connection_set_key (struct rspamd_http_connection *conn,
+ gpointer key)
+{
+ struct rspamd_http_connection_private *priv = conn->priv;
+ struct rspamd_http_keypair *kp = (struct rspamd_http_keypair *)key;
+
+ g_assert (key != NULL);
+ priv->local_key = kp;
+}
diff --git a/src/libutil/http.h b/src/libutil/http.h
index 10634e2c7..5234fe46b 100644
--- a/src/libutil/http.h
+++ b/src/libutil/http.h
@@ -148,14 +148,20 @@ struct rspamd_http_connection * rspamd_http_connection_new (
enum rspamd_http_connection_type type);
/**
- * Load the encryption keypair for this connection
- * @param conn connection structure
+ * Load the encryption keypair
* @param key base32 encoded privkey and pubkey (in that order)
* @param keylen length of base32 string
- * @return TRUE if a key has been loaded successfully
+ * @return opaque pointer pr NULL in case of error
+ */
+gpointer rspamd_http_connection_make_key (gchar *key, gsize keylen);
+
+/**
+ * Set key pointed by an opaque pointer
+ * @param conn connection structure
+ * @param key opaque key structure
*/
-gboolean rspamd_http_connection_set_key (struct rspamd_http_connection *conn,
- gchar *key, gsize keylen);
+void rspamd_http_connection_set_key (struct rspamd_http_connection *conn,
+ gpointer key);
/**
* Handle a request using socket fd and user data ud