]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix HTTP headers signing case
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 18 Feb 2019 20:30:33 +0000 (20:30 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 18 Feb 2019 20:30:33 +0000 (20:30 +0000)
src/plugins/dkim_check.c
src/plugins/lua/dkim_signing.lua
test/functional/cases/131_dkim_signing/001_simple.robot

index bb66e5ccc118017b9af0c85992e74715a43576ab..8025e421a86aed04fe1b68a2040d5db14f63cd10 100644 (file)
@@ -669,13 +669,21 @@ dkim_module_load_key_format (struct rspamd_task *task,
         * This fails for paths that are also valid base64.
         * Maybe the caller should have specified a format.
         */
-       if (key_format == RSPAMD_DKIM_KEY_UNKNOWN &&
-               (key[0] == '.' || key[0] == '/')) {
-               if (!rspamd_cryptobox_base64_is_valid (key, keylen)) {
-                       key_format = RSPAMD_DKIM_KEY_FILE;
+       if (key_format == RSPAMD_DKIM_KEY_UNKNOWN) {
+               if (key[0] == '.' || key[0] == '/') {
+                       if (!rspamd_cryptobox_base64_is_valid (key, keylen)) {
+                               key_format = RSPAMD_DKIM_KEY_FILE;
+                       }
+               }
+               else if (rspamd_cryptobox_base64_is_valid (key, keylen)) {
+                       key_format = RSPAMD_DKIM_KEY_BASE64;
+               }
+               else {
+                       key_format = RSPAMD_DKIM_KEY_RAW;
                }
        }
 
+
        if (ret != NULL && key_format == RSPAMD_DKIM_KEY_FILE) {
                msg_debug_task("checking for stale file key");
 
@@ -770,7 +778,7 @@ lua_dkim_sign_handler (lua_State *L)
                dkim_key = dkim_module_load_key_format (task, dkim_module_ctx, key,
                                keylen, RSPAMD_DKIM_KEY_UNKNOWN);
        }
-       else if(rawkey) {
+       else if (rawkey) {
                dkim_key = dkim_module_load_key_format (task, dkim_module_ctx, rawkey,
                                rawlen, RSPAMD_DKIM_KEY_UNKNOWN);
        }
index 4bc002548aa16318f142074882857ab7fb6597b0..9b1bfef32b2563bb36e93ce4819ff1c1cc672540 100644 (file)
@@ -151,12 +151,15 @@ local function dkim_signing_cb(task)
     if #selectors > 0 then
       for _, k in ipairs(selectors) do
         -- templates
-        k.key = lua_util.template(k.key, {
-          domain = k.domain,
-          selector = k.selector
-        })
-        lua_util.debugm(N, task, 'using key "%s", use selector "%s" for domain "%s"',
-            k.key, k.selector, k.domain)
+        if k.key then
+          k.key = lua_util.template(k.key, {
+            domain = k.domain,
+            selector = k.selector
+          })
+          lua_util.debugm(N, task, 'using key "%s", use selector "%s" for domain "%s"',
+              k.key, k.selector, k.domain)
+        end
+
         do_sign(k)
       end
     else
index b28f8a6a20263e759f4b88aa701a5cdee1636602..2bcd53f3698c9a59183113c85b679f096aab2560 100644 (file)
@@ -20,7 +20,7 @@ TEST SIGNED
   Should Contain  ${result.stdout}  DKIM_SIGNED
 
 TEST SIGNED HTTP HEADERS
-  ${result} =  Scan Message With Rspamc  ${MESSAGE}  -u  bob@example.com  --header=PerformDkimSign:yes  --header=DkimDomain:example.com  --header=DkimSelector:test  --header=DkimPrivateKey:MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBANe3EETkiI1Exyrb+VzbMSt90K8MXJA0GcyNs6MFCs9JPaTh90Zu2l7ki7m5LTUx6350AR/3hcvwjSHCZjD6fvQ8/zfjN8kaLZ6DAaqtqSlpawIM+8glkuTEkIkpBED/OtDrba4Rd29iLFVuwQZXDtTjAAZKZPmtTZ5TXLrcCU6VAgMBAAECgYEA1BFvmBsIN8Gu/+6kNupya2xUNVM0yLu/xT5lpNV3LBO325oejAq8+d87kkl/LTW3a2jGFlQ0ICuLw+2mo24QUWRyv8if3oeBMlnLqHE+6wNjFVqo5sOjKzjO363xSXwXNUrBT7jDhnZcDN8w3/FecYKjifGTVtUs1SLsYwhlc8ECQQDuCRymLZQ/imPn5eFVIydwUzg8ptZlvoA7bfIxUL9BQRX33s59kLCilA0tTed8Dd+GnxsT93XOj1ApIfBwmTSlAkEA5/63PDsN7fH+WInqVD8nU07M9S8LcGDlPbVVBr2S2I78/iwrSDAYtbkU2vEbhFK/JuKNML2j8OkzV3v1QulfMQJBALDzhx+l/HHr3+8RPhx7QKNIyiKUaAdEwbDsP8IXY8YPq1QThu9jM1v4sX7/TdkzuvoppwiFykbe1NlvCH279p0CQCmTg4Ee0DtBcCSr6rvYaZLLf329RZ6JLuwlMCy6ErQOxBZFEiiovfTrS2qFZToMnkc4uLbwdY36LQJTq7unGTECQCCok8LzBeZtAw+TJofpOM3F2Rlm2qXiBVBeubhRedsiljG0hpvvLJBMppnQ6r27p5Jk39SmaTRkxEKrxPWWLNM=
+  ${result} =  Scan Message With Rspamc  ${MESSAGE}  -u  bob@cacophony.za.org  --header=PerformDkimSign:yes  --header=DkimDomain:cacophony.za.org  --header=DkimSelector:dkim  --header=DkimPrivateKey:MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBANe3EETkiI1Exyrb+VzbMSt90K8MXJA0GcyNs6MFCs9JPaTh90Zu2l7ki7m5LTUx6350AR/3hcvwjSHCZjD6fvQ8/zfjN8kaLZ6DAaqtqSlpawIM+8glkuTEkIkpBED/OtDrba4Rd29iLFVuwQZXDtTjAAZKZPmtTZ5TXLrcCU6VAgMBAAECgYEA1BFvmBsIN8Gu/+6kNupya2xUNVM0yLu/xT5lpNV3LBO325oejAq8+d87kkl/LTW3a2jGFlQ0ICuLw+2mo24QUWRyv8if3oeBMlnLqHE+6wNjFVqo5sOjKzjO363xSXwXNUrBT7jDhnZcDN8w3/FecYKjifGTVtUs1SLsYwhlc8ECQQDuCRymLZQ/imPn5eFVIydwUzg8ptZlvoA7bfIxUL9BQRX33s59kLCilA0tTed8Dd+GnxsT93XOj1ApIfBwmTSlAkEA5/63PDsN7fH+WInqVD8nU07M9S8LcGDlPbVVBr2S2I78/iwrSDAYtbkU2vEbhFK/JuKNML2j8OkzV3v1QulfMQJBALDzhx+l/HHr3+8RPhx7QKNIyiKUaAdEwbDsP8IXY8YPq1QThu9jM1v4sX7/TdkzuvoppwiFykbe1NlvCH279p0CQCmTg4Ee0DtBcCSr6rvYaZLLf329RZ6JLuwlMCy6ErQOxBZFEiiovfTrS2qFZToMnkc4uLbwdY36LQJTq7unGTECQCCok8LzBeZtAw+TJofpOM3F2Rlm2qXiBVBeubhRedsiljG0hpvvLJBMppnQ6r27p5Jk39SmaTRkxEKrxPWWLNM=
   Check Rspamc  ${result}  DKIM-Signature:
   Should Contain  ${result.stdout}  DKIM_SIGNED