From: Vsevolod Stakhov Date: Thu, 26 Jan 2017 17:53:22 +0000 (+0000) Subject: [Feature] Simplify HTTPCrypt client support X-Git-Tag: 1.5.0~247 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7c8f499a6c9ff1e9b59dfd0787edade968add1eb;p=rspamd.git [Feature] Simplify HTTPCrypt client support --- diff --git a/src/libutil/http.c b/src/libutil/http.c index 9a33b1a90..1a8a4b953 100644 --- a/src/libutil/http.c +++ b/src/libutil/http.c @@ -1909,8 +1909,15 @@ rspamd_http_connection_write_message_common (struct rspamd_http_connection *conn priv->flags |= RSPAMD_HTTP_CONN_FLAG_ENCRYPTED; } - if (priv->local_key != NULL && msg->peer_key != NULL) { + if (msg->peer_key != NULL) { + if (priv->local_key == NULL) { + /* Automatically generate a temporary keypair */ + priv->local_key = rspamd_keypair_new (RSPAMD_KEYPAIR_KEX, + RSPAMD_CRYPTOBOX_MODE_25519); + } + encrypted = TRUE; + if (conn->cache) { rspamd_keypair_cache_process (conn->cache, priv->local_key, priv->msg->peer_key); @@ -2687,6 +2694,22 @@ rspamd_http_message_free (struct rspamd_http_message *msg) g_slice_free1 (sizeof (struct rspamd_http_message), msg); } +void +rspamd_http_message_set_peer_key (struct rspamd_http_message *msg, + struct rspamd_cryptobox_pubkey *pk) +{ + if (msg->peer_key != NULL) { + rspamd_pubkey_unref (msg->peer_key); + } + + if (pk) { + msg->peer_key = rspamd_pubkey_ref (pk); + } + else { + msg->peer_key = NULL; + } +} + void rspamd_http_message_add_header (struct rspamd_http_message *msg, const gchar *name, diff --git a/src/libutil/http.h b/src/libutil/http.h index 3f5288eca..9f3861865 100644 --- a/src/libutil/http.h +++ b/src/libutil/http.h @@ -296,6 +296,14 @@ struct rspamd_http_message * rspamd_http_message_ref (struct rspamd_http_message * @param msg */ void rspamd_http_message_unref (struct rspamd_http_message *msg); + +/** + * Sets a key for peer + * @param msg + * @param pk + */ +void rspamd_http_message_set_peer_key (struct rspamd_http_message *msg, + struct rspamd_cryptobox_pubkey *pk); /** * Create HTTP message from URL * @param url