]> source.dussan.org Git - rspamd.git/commitdiff
Implement keys manipulation in client.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 29 Jan 2015 19:27:20 +0000 (19:27 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 29 Jan 2015 19:27:20 +0000 (19:27 +0000)
src/client/rspamc.c
src/client/rspamdclient.c
src/client/rspamdclient.h

index 5432aeae7d676f14d7f6c742cf16c4cbb58166f6..4d137be81b35620b6cc90101f91d30787825f168 100644 (file)
@@ -57,6 +57,7 @@ static gboolean json = FALSE;
 static gboolean headers = FALSE;
 static gboolean raw = FALSE;
 static gboolean extended_urls = FALSE;
+static gchar *key = NULL;
 
 static GOptionEntry entries[] =
 {
@@ -106,6 +107,8 @@ static GOptionEntry entries[] =
          "Maximum count of parallel requests to rspamd", NULL },
        { "extended-urls", 0, 0, G_OPTION_ARG_NONE, &extended_urls,
           "Output urls in extended format", NULL },
+       { "key", 0, 0, G_OPTION_ARG_STRING, &key,
+          "Use specified pubkey to encrypt request", NULL },
        { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
 };
 
@@ -823,7 +826,7 @@ rspamc_process_input (struct event_base *ev_base, struct rspamc_command *cmd,
                port = 0;
        }
 
-       conn = rspamd_client_init (ev_base, connectv[0], port, timeout);
+       conn = rspamd_client_init (ev_base, connectv[0], port, timeout, key);
        g_strfreev (connectv);
 
        if (conn != NULL) {
index b66d67f2d76af3048ef5950234359d5d3ce9780e..c95f982cf6999d29de256bb4a148b6ca71e2ab85 100644 (file)
@@ -39,6 +39,8 @@ struct rspamd_client_request;
 struct rspamd_client_connection {
        gint fd;
        GString *server_name;
+       GString *key;
+       gpointer keypair;
        struct event_base *ev_base;
        struct timeval timeout;
        struct rspamd_http_connection *http_conn;
@@ -132,7 +134,7 @@ rspamd_client_finish_handler (struct rspamd_http_connection *conn,
 
 struct rspamd_client_connection *
 rspamd_client_init (struct event_base *ev_base, const gchar *name,
-       guint16 port, gdouble timeout)
+       guint16 port, gdouble timeout, const gchar *key)
 {
        struct rspamd_client_connection *conn;
        gint fd;
@@ -142,7 +144,7 @@ rspamd_client_init (struct event_base *ev_base, const gchar *name,
                return NULL;
        }
 
-       conn = g_slice_alloc (sizeof (struct rspamd_client_connection));
+       conn = g_slice_alloc0 (sizeof (struct rspamd_client_connection));
        conn->ev_base = ev_base;
        conn->fd = fd;
        conn->req_sent = FALSE;
@@ -151,6 +153,14 @@ rspamd_client_init (struct event_base *ev_base, const gchar *name,
                        rspamd_client_finish_handler,
                        0,
                        RSPAMD_HTTP_CLIENT);
+
+       if (key) {
+               conn->key = rspamd_http_connection_make_peer_key (key);
+               if (conn->key) {
+                       conn->keypair = rspamd_http_connection_gen_key ();
+                       rspamd_http_connection_set_key (conn->http_conn, conn->key);
+               }
+       }
        conn->server_name = g_string_new (name);
        if (port != 0) {
                rspamd_printf_gstring (conn->server_name, ":%d", (int)port);
@@ -178,6 +188,10 @@ rspamd_client_command (struct rspamd_client_connection *conn,
        req->ud = ud;
 
        req->msg = rspamd_http_new_message (HTTP_REQUEST);
+       if (conn->key) {
+               req->msg->peer_key = g_string_new (conn->key->str);
+       }
+
        if (in != NULL) {
                /* Read input stream */
                req->msg->body = g_string_sized_new (BUFSIZ);
@@ -233,6 +247,12 @@ rspamd_client_destroy (struct rspamd_client_connection *conn)
                        g_slice_free1 (sizeof (struct rspamd_client_request), conn->req);
                }
                close (conn->fd);
+               if (conn->key) {
+                       g_string_free (conn->key, TRUE);
+               }
+               if (conn->keypair) {
+                       rspamd_http_connection_key_destroy (conn->keypair);
+               }
                g_string_free (conn->server_name, TRUE);
                g_slice_free1 (sizeof (struct rspamd_client_connection), conn);
        }
index 6a41c35c156ed8f95406e65acf42a3240cdfc1c3..badfaafb2c8bbfa3ee7affd4277d888d4b5d4bad 100644 (file)
@@ -58,7 +58,8 @@ struct rspamd_client_connection * rspamd_client_init (
        struct event_base *ev_base,
        const gchar *name,
        guint16 port,
-       gdouble timeout);
+       gdouble timeout,
+       const gchar *key);
 
 /**
  *