aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-01-26 17:53:22 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-01-26 17:53:22 +0000
commit7c8f499a6c9ff1e9b59dfd0787edade968add1eb (patch)
tree05f595aec81c29fe8f9d3f1842f91fc3bf8e34ae /src/libutil
parent625aec042ca53fc3d98200809c5fe9b3cf4b3117 (diff)
downloadrspamd-7c8f499a6c9ff1e9b59dfd0787edade968add1eb.tar.gz
rspamd-7c8f499a6c9ff1e9b59dfd0787edade968add1eb.zip
[Feature] Simplify HTTPCrypt client support
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/http.c25
-rw-r--r--src/libutil/http.h8
2 files changed, 32 insertions, 1 deletions
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);
@@ -2688,6 +2695,22 @@ rspamd_http_message_free (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,
const gchar *value)
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