]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Add some public methods to DKIM API
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 11 Jun 2018 17:29:42 +0000 (18:29 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 11 Jun 2018 17:29:42 +0000 (18:29 +0100)
src/libserver/dkim.c
src/libserver/dkim.h

index e450f04c7787d39ace1e7326b165d1f37c31a7de..4dc16fd1ecfde77dc46c60213b11d24ac6ff1c8c 100644 (file)
@@ -58,23 +58,6 @@ enum rspamd_dkim_param_type {
        DKIM_PARAM_IGNORE
 };
 
-/* Signature methods */
-enum rspamd_sign_type {
-       DKIM_SIGN_UNKNOWN = -2,
-       DKIM_SIGN_RSASHA1 = 0,
-       DKIM_SIGN_RSASHA256,
-       DKIM_SIGN_RSASHA512,
-       DKIM_SIGN_ECDSASHA256,
-       DKIM_SIGN_ECDSASHA512,
-       DKIM_SIGN_EDDSASHA256,
-};
-
-enum rspamd_dkim_key_type {
-       RSPAMD_DKIM_KEY_RSA = 0,
-       RSPAMD_DKIM_KEY_ECDSA,
-       RSPAMD_DKIM_KEY_EDDSA
-};
-
 #define RSPAMD_DKIM_MAX_ARC_IDX 10
 
 #define msg_err_dkim(...) rspamd_default_log_function (G_LOG_LEVEL_CRITICAL, \
@@ -1222,8 +1205,8 @@ struct rspamd_dkim_key_cbdata {
        gpointer ud;
 };
 
-static rspamd_dkim_key_t *
-rspamd_dkim_make_key (rspamd_dkim_context_t *ctx, const gchar *keydata,
+rspamd_dkim_key_t *
+rspamd_dkim_make_key (const gchar *keydata,
                guint keylen, enum rspamd_dkim_key_type type, GError **err)
 {
        rspamd_dkim_key_t *key = NULL;
@@ -1372,9 +1355,8 @@ rspamd_dkim_sign_key_free (rspamd_dkim_sign_key_t *key)
        g_free (key);
 }
 
-static rspamd_dkim_key_t *
-rspamd_dkim_parse_key (rspamd_dkim_context_t *ctx, const gchar *txt,
-               gsize *keylen, GError **err)
+rspamd_dkim_key_t *
+rspamd_dkim_parse_key (const gchar *txt, gsize *keylen, GError **err)
 {
        const gchar *c, *p, *end, *key = NULL, *alg = "rsa";
        enum {
@@ -1468,20 +1450,16 @@ rspamd_dkim_parse_key (rspamd_dkim_context_t *ctx, const gchar *txt,
        }
 
        if (alglen == 8 && rspamd_lc_cmp (alg, "ecdsa256", alglen) == 0) {
-               return rspamd_dkim_make_key (ctx, c, klen,
+               return rspamd_dkim_make_key (c, klen,
                                RSPAMD_DKIM_KEY_ECDSA, err);
        }
        else if (alglen == 7 && rspamd_lc_cmp (alg, "ed25519", alglen) == 0) {
-               return rspamd_dkim_make_key (ctx, c, klen,
+               return rspamd_dkim_make_key (c, klen,
                                RSPAMD_DKIM_KEY_EDDSA, err);
        }
        else {
                /* We assume RSA default in all cases */
-               if (alglen != 3 || rspamd_lc_cmp (alg, "rsa", alglen) != 0) {
-                       msg_info_dkim ("invalid key algorithm: %*s", (gint)alglen, alg);
-               }
-
-               return rspamd_dkim_make_key (ctx, c, klen,
+               return rspamd_dkim_make_key (c, klen,
                                RSPAMD_DKIM_KEY_RSA, err);
        }
 
@@ -1525,7 +1503,7 @@ rspamd_dkim_dns_cb (struct rdns_reply *reply, gpointer arg)
                                        g_error_free (err);
                                        err = NULL;
                                }
-                               key = rspamd_dkim_parse_key (cbdata->ctx, elt->content.txt.data,
+                               key = rspamd_dkim_parse_key (elt->content.txt.data,
                                                &keylen,
                                                &err);
                                if (key) {
index 2a8b0e0b54896eecb900bde5c24ddab573cf4739..5081c0f52d1e0f248827dd48bb90d465ac568b2a 100644 (file)
@@ -120,6 +120,24 @@ enum rspamd_dkim_type {
        RSPAMD_DKIM_ARC_SEAL
 };
 
+/* Signature methods */
+enum rspamd_sign_type {
+       DKIM_SIGN_UNKNOWN = -2,
+       DKIM_SIGN_RSASHA1 = 0,
+       DKIM_SIGN_RSASHA256,
+       DKIM_SIGN_RSASHA512,
+       DKIM_SIGN_ECDSASHA256,
+       DKIM_SIGN_ECDSASHA512,
+       DKIM_SIGN_EDDSASHA256,
+};
+
+enum rspamd_dkim_key_type {
+       RSPAMD_DKIM_KEY_RSA = 0,
+       RSPAMD_DKIM_KEY_ECDSA,
+       RSPAMD_DKIM_KEY_EDDSA
+};
+
+
 /* Err MUST be freed if it is not NULL, key is allocated by slice allocator */
 typedef void (*dkim_key_handler_f)(rspamd_dkim_key_t *key, gsize keylen,
        rspamd_dkim_context_t *ctx, gpointer ud, GError *err);
@@ -207,6 +225,28 @@ const gchar* rspamd_dkim_get_domain (rspamd_dkim_context_t *ctx);
 const gchar* rspamd_dkim_get_dns_key (rspamd_dkim_context_t *ctx);
 guint rspamd_dkim_key_get_ttl (rspamd_dkim_key_t *k);
 
+/**
+ * Create DKIM public key from a raw data
+ * @param keydata
+ * @param keylen
+ * @param type
+ * @param err
+ * @return
+ */
+rspamd_dkim_key_t * rspamd_dkim_make_key (const gchar *keydata, guint keylen,
+                                                                                 enum rspamd_dkim_key_type type,
+                                                                                 GError **err);
+
+/**
+ * Parse DKIM public key from a TXT record
+ * @param txt
+ * @param keylen
+ * @param err
+ * @return
+ */
+rspamd_dkim_key_t * rspamd_dkim_parse_key (const gchar *txt, gsize *keylen,
+                                                                                  GError **err);
+
 /**
  * Canonocalise header using relaxed algorithm
  * @param hname