]> source.dussan.org Git - rspamd.git/commitdiff
Add support of encryption to the worker.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 29 Jan 2015 18:39:42 +0000 (18:39 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 29 Jan 2015 18:39:42 +0000 (18:39 +0000)
src/libserver/cfg_rcl.c
src/libutil/util.c
src/worker.c

index b16c24846b9f0da735e94b653703c9e7f116a520..959d22cd362325d87caafe33abe6bc1abb4d2004 100644 (file)
@@ -1793,22 +1793,37 @@ rspamd_rcl_parse_struct_keypair (struct rspamd_config *cfg,
                                *target = key;
                                return TRUE;
                        }
-
+                       g_set_error (err,
+                                       CFG_RCL_ERROR,
+                                       EINVAL,
+                                       "invalid string with keypair content");
                        return FALSE;
                }
        }
        else if (obj->type == UCL_OBJECT) {
                elt = ucl_object_find_key (obj, "pubkey");
                if (elt == NULL || !ucl_object_tostring_safe (elt, &pk)) {
+                       g_set_error (err,
+                                       CFG_RCL_ERROR,
+                                       EINVAL,
+                                       "no sane pubkey found in the keypair");
                        return FALSE;
                }
                elt = ucl_object_find_key (obj, "privkey");
                if (elt == NULL || !ucl_object_tostring_safe (elt, &sk)) {
+                       g_set_error (err,
+                                       CFG_RCL_ERROR,
+                                       EINVAL,
+                                       "no sane privkey found in the keypair");
                        return FALSE;
                }
        }
 
        if (sk == NULL || pk == NULL) {
+               g_set_error (err,
+                               CFG_RCL_ERROR,
+                               EINVAL,
+                               "no sane pubkey or privkey found in the keypair");
                return FALSE;
        }
 
@@ -1819,13 +1834,17 @@ rspamd_rcl_parse_struct_keypair (struct rspamd_config *cfg,
                rspamd_snprintf (keybuf, sizeof (keybuf), "%*s%s", sem - sk, sk, pk);
        }
 
-       key = rspamd_http_connection_make_key (keybuf, strlen (val));
+       key = rspamd_http_connection_make_key (keybuf, strlen (keybuf));
        if (key != NULL) {
                /* XXX: clean buffer after usage */
                *target = key;
                return TRUE;
        }
 
+       g_set_error (err,
+                       CFG_RCL_ERROR,
+                       EINVAL,
+                       "cannot load the keypair specified");
        return FALSE;
 }
 
index ada373eb1a857e16f659c8b484caff91b0338187..e690812d6083c62a209081b6ba045f994b20481d 100644 (file)
@@ -2186,7 +2186,7 @@ rspamd_decode_base32 (gchar *in, gsize inlen, gsize *outlen)
                res[olen++] = (acc & 0xFF);
        }
 
-       *outlen = olen;
+       *outlen = olen > 0 ? olen - 1 : 0;
 
        return res;
 }
index 62a1292353c9e2bbb0c7665c678cd114656eaeec..0a6ce4a5ec9bdba4bf4173c94d20a61b4a22d073 100644 (file)
@@ -86,6 +86,8 @@ struct rspamd_worker_ctx {
        GThreadPool *classify_pool;
        /* Events base */
        struct event_base *ev_base;
+       /* Encryption key */
+       gpointer key;
 };
 
 /*
@@ -243,6 +245,10 @@ accept_socket (gint fd, short what, void *arg)
 
        new_task->classify_pool = ctx->classify_pool;
 
+       if (ctx->key) {
+               rspamd_http_connection_set_key (new_task->http_conn, ctx->key);
+       }
+
        rspamd_http_connection_read_message (new_task->http_conn,
                new_task,
                nfd,
@@ -295,6 +301,12 @@ init_worker (struct rspamd_config *cfg)
                G_STRUCT_OFFSET (struct rspamd_worker_ctx,
                classify_threads), RSPAMD_CL_FLAG_INT_32);
 
+
+       rspamd_rcl_register_worker_option (cfg, type, "keypair",
+               rspamd_rcl_parse_struct_keypair, ctx,
+               G_STRUCT_OFFSET (struct rspamd_worker_ctx,
+               key), 0);
+
        return ctx;
 }
 
@@ -340,6 +352,11 @@ start_worker (struct rspamd_worker *worker)
 
        g_mime_shutdown ();
        rspamd_log_close (rspamd_main->logger);
+
+       if (ctx->key) {
+               rspamd_http_connection_key_destroy (ctx->key);
+       }
+
        exit (EXIT_SUCCESS);
 }