}
static void
-rspamd_http_parse_key (GString *data, struct rspamd_http_connection_private *priv)
+rspamd_http_parse_key (GString *data, struct rspamd_http_connection *conn,
+ struct rspamd_http_connection_private *priv)
{
guchar *decoded_id, *decoded_key;
const gchar *eq_pos;
RSPAMD_HTTP_KEY_ID_LEN) == 0) {
priv->msg->peer_key =
rspamd_http_connection_make_peer_key (eq_pos + 1);
+
+ if (conn->cache && priv->msg->peer_key) {
+ rspamd_keypair_cache_process (conn->cache,
+ priv->msg->peer_key, priv->local_key);
+ }
}
}
}
}
static inline void
-rspamd_http_check_special_header (struct rspamd_http_connection_private *priv)
+rspamd_http_check_special_header (struct rspamd_http_connection *conn,
+ struct rspamd_http_connection_private *priv)
{
if (g_ascii_strcasecmp (priv->header->name->str, date_header) == 0) {
priv->msg->date = rspamd_http_parse_date (priv->header->value->str,
priv->header->value->len);
}
else if (g_ascii_strcasecmp (priv->header->name->str, key_header) == 0) {
- rspamd_http_parse_key (priv->header->value, priv);
+ rspamd_http_parse_key (priv->header->value, conn, priv);
}
}
}
else if (priv->new_header) {
DL_APPEND (priv->msg->headers, priv->header);
- rspamd_http_check_special_header (priv);
+ rspamd_http_check_special_header (conn, priv);
priv->header = g_slice_alloc (sizeof (struct rspamd_http_header));
priv->header->name = g_string_sized_new (32);
priv->header->value = g_string_sized_new (32);
if (priv->header != NULL) {
DL_APPEND (priv->msg->headers, priv->header);
- rspamd_http_check_special_header (priv);
+ rspamd_http_check_special_header (conn, priv);
priv->header = NULL;
}
rspamd_http_error_handler_t error_handler,
rspamd_http_finish_handler_t finish_handler,
unsigned opts,
- enum rspamd_http_connection_type type)
+ enum rspamd_http_connection_type type,
+ struct rspamd_keypair_cache *cache)
{
struct rspamd_http_connection *new;
struct rspamd_http_connection_private *priv;
new->fd = -1;
new->ref = 1;
new->finished = FALSE;
+ new->cache = cache;
/* Init priv */
priv = g_slice_alloc0 (sizeof (struct rspamd_http_connection_private));
priv->buf->data = g_string_sized_new (128);
buf = priv->buf->data;
- if (priv->peer_key) {
+ if (priv->peer_key && priv->local_key) {
priv->msg->peer_key = priv->peer_key;
priv->peer_key = NULL;
priv->encrypted = TRUE;
+
+ if (conn->cache && priv->msg->peer_key) {
+ rspamd_keypair_cache_process (conn->cache,
+ priv->msg->peer_key, priv->local_key);
+ }
}
if (msg->method < HTTP_SYMBOLS) {
}
new->default_fs_path = NULL;
+
if (default_fs_path != NULL) {
if (stat (default_fs_path, &st) == -1) {
msg_err ("cannot stat %s", default_fs_path);
}
}
+ /* XXX: stupid default value, should be configurable */
+ new->cache = rspamd_keypair_cache_new (256);
+
return new;
}
rspamd_http_router_error_handler,
rspamd_http_router_finish_handler,
0,
- RSPAMD_HTTP_SERVER);
+ RSPAMD_HTTP_SERVER, router->cache);
if (router->key) {
rspamd_http_connection_set_key (conn->conn, router->key);
REF_RELEASE (kp);
}
+ if (router->cache) {
+ rspamd_keypair_cache_destroy (router->cache);
+ }
+
if (router->default_fs_path != NULL) {
g_free (router->default_fs_path);
}
#include "config.h"
#include "http_parser.h"
+#include "keypairs_cache.h"
enum rspamd_http_connection_type {
RSPAMD_HTTP_SERVER,
rspamd_http_body_handler_t body_handler;
rspamd_http_error_handler_t error_handler;
rspamd_http_finish_handler_t finish_handler;
+ struct rspamd_keypair_cache *cache;
gpointer ud;
unsigned opts;
enum rspamd_http_connection_type type;
struct timeval tv;
struct timeval *ptv;
struct event_base *ev_base;
+ struct rspamd_keypair_cache *cache;
gchar *default_fs_path;
gpointer key;
rspamd_http_router_error_handler_t error_handler;
rspamd_http_error_handler_t error_handler,
rspamd_http_finish_handler_t finish_handler,
unsigned opts,
- enum rspamd_http_connection_type type);
+ enum rspamd_http_connection_type type,
+ struct rspamd_keypair_cache *cache);
/**
* Load the encryption keypair
#include "libserver/dns.h"
#include "libmime/message.h"
#include "main.h"
+#include "keypairs_cache.h"
#include "lua/lua_common.h"
struct event_base *ev_base;
/* Encryption key */
gpointer key;
+ /* Keys cache */
+ struct rspamd_keypair_cache *keys_cache;
};
/*
rspamd_worker_error_handler,
rspamd_worker_finish_handler,
0,
- RSPAMD_HTTP_SERVER);
+ RSPAMD_HTTP_SERVER,
+ ctx->keys_cache);
new_task->ev_base = ctx->ev_base;
ctx->tasks++;
rspamd_mempool_add_destructor (new_task->task_pool,
}
}
+ /* XXX: stupid default */
+ ctx->keys_cache = rspamd_keypair_cache_new (256);
+
event_base_loop (ctx->ev_base, 0);
g_mime_shutdown ();
rspamd_http_connection_key_unref (ctx->key);
}
+ rspamd_keypair_cache_destroy (ctx->keys_cache);
+
exit (EXIT_SUCCESS);
}