]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Fix more issues remaining
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 6 Feb 2016 14:31:22 +0000 (14:31 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 6 Feb 2016 14:31:22 +0000 (14:31 +0000)
src/libcryptobox/keypair.c
src/libserver/cfg_rcl.c
src/libutil/http.c

index e645ef3e07152d9c23868215a5ca1df51fc588fb..d8e160af1bc7d456271d398d8a58ba94eebfe888 100644 (file)
@@ -695,11 +695,13 @@ rspamd_keypair_from_ucl (const ucl_object_t *obj)
                /* TODO: handle errors */
        }
 
-       kp = rspamd_keypair_new (type, mode);
+       kp = rspamd_cryptobox_keypair_alloc (type, mode);
+       kp->type = type;
+       kp->alg = mode;
        g_assert (kp != NULL);
 
-       target = rspamd_cryptobox_keypair_pk (kp, &len);
-       str = ucl_object_tolstring (pubkey, &ucl_len);
+       target = rspamd_cryptobox_keypair_sk (kp, &len);
+       str = ucl_object_tolstring (privkey, &ucl_len);
 
        if (is_hex) {
                dec_len = rspamd_decode_hex_buf (str, ucl_len, target, len);
@@ -714,8 +716,8 @@ rspamd_keypair_from_ucl (const ucl_object_t *obj)
                return NULL;
        }
 
-       target = rspamd_cryptobox_keypair_sk (kp, &len);
-       str = ucl_object_tolstring (privkey, &ucl_len);
+       target = rspamd_cryptobox_keypair_pk (kp, &len);
+       str = ucl_object_tolstring (pubkey, &ucl_len);
 
        if (is_hex) {
                dec_len = rspamd_decode_hex_buf (str, ucl_len, target, len);
@@ -730,6 +732,10 @@ rspamd_keypair_from_ucl (const ucl_object_t *obj)
                return NULL;
        }
 
+       rspamd_cryptobox_hash (kp->id, target, len, NULL, 0);
+
+       REF_INIT_RETAIN (kp, rspamd_cryptobox_keypair_dtor);
+
        return kp;
 }
 
index 440ccd40d0be5820c768f921ebeab816e7f60a01..305b26eee8f003414abcf2d00ae87dde810f2e80 100644 (file)
@@ -2411,7 +2411,8 @@ rspamd_rcl_parse_struct_keypair (rspamd_mempool_t *pool,
        struct rspamd_cryptobox_keypair **target, *kp;
 
 
-       target = (gpointer *)(((gchar *)pd->user_struct) + pd->offset);
+       target = (struct rspamd_cryptobox_keypair **)(((gchar *)pd->user_struct) +
+                       pd->offset);
        if (obj->type == UCL_OBJECT) {
                kp = rspamd_keypair_from_ucl (obj);
 
index 4640fbffebc7b4515ef82d819c7d09cff09575d9..605439129c49f21b54798f02e8516bf18421e480 100644 (file)
@@ -84,7 +84,6 @@ static const rspamd_ftok_t date_header = {
                .len = 4
 };
 
-#define RSPAMD_HTTP_KEY_ID_LEN 5
 
 #define HTTP_ERROR http_error_quark ()
 GQuark
@@ -416,7 +415,7 @@ rspamd_http_parse_key (rspamd_ftok_t *data, struct rspamd_http_connection *conn,
                        decoded_id = rspamd_decode_base32 (data->begin, eq_pos - data->begin,
                                        &id_len);
 
-                       if (decoded_id != NULL && id_len >= RSPAMD_HTTP_KEY_ID_LEN) {
+                       if (decoded_id != NULL && id_len >= RSPAMD_KEYPAIR_SHORT_ID_LEN) {
                                pk = rspamd_pubkey_from_base32 (eq_pos + 1,
                                                data->begin + data->len - eq_pos - 1,
                                                RSPAMD_KEYPAIR_KEX,
@@ -424,7 +423,7 @@ rspamd_http_parse_key (rspamd_ftok_t *data, struct rspamd_http_connection *conn,
                                if (pk != NULL) {
                                        if (memcmp (rspamd_keypair_get_id (priv->local_key),
                                                        decoded_id,
-                                                       RSPAMD_HTTP_KEY_ID_LEN) == 0) {
+                                                       RSPAMD_KEYPAIR_SHORT_ID_LEN) == 0) {
                                                priv->msg->peer_key = pk;
 
                                                if (conn->cache && priv->msg->peer_key) {
@@ -1336,8 +1335,7 @@ rspamd_http_connection_write_message (struct rspamd_http_connection *conn,
        gsize bodylen, enclen = 0;
        rspamd_fstring_t *buf;
        gboolean encrypted = FALSE;
-       guchar nonce[rspamd_cryptobox_MAX_NONCEBYTES], mac[rspamd_cryptobox_MAX_MACBYTES],
-               id[rspamd_cryptobox_HASHBYTES];
+       guchar nonce[rspamd_cryptobox_MAX_NONCEBYTES], mac[rspamd_cryptobox_MAX_MACBYTES];
        guchar *np = NULL, *mp = NULL, *meth_pos = NULL;
        struct rspamd_cryptobox_pubkey *peer_key = NULL;
        enum rspamd_cryptobox_mode mode;
@@ -1623,15 +1621,14 @@ rspamd_http_connection_write_message (struct rspamd_http_connection *conn,
                if (encrypted) {
                        GString *b32_key, *b32_id;
 
-                       memcpy (id, rspamd_pubkey_get_id (peer_key), sizeof (id));
                        b32_key = rspamd_keypair_print (priv->local_key,
                                        RSPAMD_KEYPAIR_PUBKEY|RSPAMD_KEYPAIR_BASE32);
-                       b32_id = rspamd_keypair_print (priv->local_key,
+                       b32_id = rspamd_pubkey_print (peer_key,
                                        RSPAMD_KEYPAIR_ID_SHORT|RSPAMD_KEYPAIR_BASE32);
                        /* XXX: add some fuzz here */
-                       rspamd_printf_fstring (&buf, "Key: %s=%s\r\n", b32_id, b32_key);
-                       g_free (b32_key);
-                       g_free (b32_id);
+                       rspamd_printf_fstring (&buf, "Key: %v=%v\r\n", b32_id, b32_key);
+                       g_string_free (b32_key, TRUE);
+                       g_string_free (b32_id, TRUE);
                }
        }