]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Simplify HTTPCrypt client support
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 26 Jan 2017 17:53:22 +0000 (17:53 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 26 Jan 2017 17:53:22 +0000 (17:53 +0000)
src/libutil/http.c
src/libutil/http.h

index 9a33b1a90b5c6ad938a2196c4db0b5219ac6cc74..1a8a4b95346a74c0a4de3daf1b929ece65b5d35a 100644 (file)
@@ -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,
index 3f5288eca6ad952f07a809c83fdf1ab1aa8a44d3..9f3861865e2985ca2368d816ecfe37d3d0b3830c 100644 (file)
@@ -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