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);
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,
* @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