lieser / dkim_verifier

DKIM Verifier Extension for Mozilla Thunderbird
MIT License
210 stars 35 forks source link

'DKIM DNS result is bogus' when reading AR headers @fastmail; OK @gmail #384

Closed pgnd closed 1 year ago

pgnd commented 1 year ago

i run

    Application Basics

    Name: Thunderbird
    Version: 115.1.0
    Build ID: 20230731171153
    Distribution ID:

    Update Channel: release
    User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0 Thunderbird/115.1.0
    OS: Linux 6.4.7-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jul 27 20:01:18 UTC 2023
    ...

        DKIM Verifier
        extension
        5.3.1
        true
        dkim_verifier@pl

on

    lsb_release -rd
        Description:    Fedora release 38 (Thirty Eight)
        Release:        38

in DKIM extension, i've enabled

    [X] Read Authentication-Results header
    [X] Reading the Authentication-Results header replaces the add-ons verification
    Resolver: libunbound
    Path: /usr/lib64/libunbound.so

where,

    ls -al /usr/lib64/libunbound.so*
        lrwxrwxrwx 1 root root   20 Jul 21 20:00 /usr/lib64/libunbound.so -> libunbound.so.8.1.21*
        lrwxrwxrwx 1 root root   20 Jul 21 20:00 /usr/lib64/libunbound.so.8 -> libunbound.so.8.1.21*
        -rwxr-xr-x 1 root root 1.4M Jul 21 20:00 /usr/lib64/libunbound.so.8.1.21*

    rpm -q --whatprovides /usr/lib64/libunbound.so.8.1.21
        unbound-libs-1.17.1-4.fc38.x86_64

sending a single test email from my local server to 2 external accounts, @fastmail & @gmail

    Message-ID: <975bad26-fe4a-26ee-915a-03e53f1b8c7e@example.com>
    Date: Tue, 8 Aug 2023 09:09:55 -0400
    MIME-Version: 1.0
    User-Agent: Mozilla Thunderbird
    From: Admin <admin@example.com>
    Subject: test
    Reply-To: admin@example.com
    To: user1fastmail.fm, user2gmail.com
    Content-Language: en-US
    Content-Type: text/plain; charset=UTF-8; format=flowed
    Content-Transfer-Encoding: 8bit

     Â test

outbound DKIM sigs are added

    ...
    2023-08-08T09:09:57.473515-04:00 mx dkimpy-milter[1088]: From: Admin <admin@example.com>
    2023-08-08T09:09:57.482007-04:00 mx dkimpy-milter[1088]: 3CKgkx152ga26: rsa-sha256 DKIM signature added (s=dkim-3xxx4-rsa d=example.com)
    2023-08-08T09:09:57.482399-04:00 mx dkimpy-milter[1088]: 3CKgkx152ga26: ed25519-sha256 DKIM signature added (s=dkim-3xxx4-ed25519 d=example.com)
    ...

@gmail, it's received with DKIM & DMARC pass,

    ...
    Authentication-Results: mx.google.com;
           dkim=neutral (no key) header.i=@example.com header.s=dkim-3xxx4-ed25519 header.b=FWYV3FIz;
           dkim=pass header.i=@example.com header.s=dkim-3xxx4-rsa header.b=qzVrCibU;
           spf=pass (google.com: domain of admin@example.com designates 192.0.2.15 as permitted sender) smtp.mailfrom=admin@example.com;
           dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=example.com
    ...
    DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed;
     d=example.com; i=@example.com; q=dns/txt;
     s=dkim-3xxx4-ed25519; t=1691500197; h=message-id : date :
     from : subject : reply-to : to : content-type :
     content-transfer-encoding : from;
     bh=W...
     b=F...
    DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
     d=example.com; i=@example.com; q=dns/txt;
     s=dkim-3xxx4-rsa; t=1691500197; h=message-id : date : from
     : subject : reply-to : to : content-type : content-transfer-encoding :
     from; bh=W...
     b=q...
    ...

and in TBird, DKIM extension header displays

    DKIM Valid (Signed by example.com) SPF: pass DMARC: pass

but @fastmail,

    ...
    Authentication-Results: mx5.messagingengine.com;
        dkim=pass (2048-bit rsa key sha256) header.d=example.com
          header.i=@example.com header.b=qzVrCibU header.a=rsa-sha256
          header.s=dkim-3xxx4-rsa x-bits=2048;
        dkim=pass (ed25519 key sha256) header.d=example.com
          header.i=@example.com header.b=FWYV3FIz header.a=ed25519-sha256
          header.s=dkim-3xxx4-ed25519;
        dmarc=pass policy.published-domain-policy=reject
          policy.applied-disposition=none policy.evaluated-disposition=none
          (p=reject,d=none,d.eval=none) policy.policy-from=p
          header.from=example.com;
        iprev=pass smtp.remote-ip=192.0.2.15 (mx.example.net);
        spf=pass smtp.mailfrom=admin@example.com
          smtp.helo=mx.example.net
    ...
    DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed;
     d=example.com; i=@example.com; q=dns/txt;
     s=dkim-3xxx4-ed25519; t=1691500197; h=message-id : date :
     from : subject : reply-to : to : content-type :
     content-transfer-encoding : from;
     bh=W...
     b=F...
    DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
     d=example.com; i=@example.com; q=dns/txt;
     s=dkim-3xxx4-rsa; t=1691500197; h=message-id : date : from
     : subject : reply-to : to : content-type : content-transfer-encoding :
     from; bh=W...
     b=q...
    ...

in TBird, DKIM extension header displays

    DKIM DNS result is bogus
lieser commented 1 year ago

Thanks for the detailed information.

Note that there are two different problems.

  1. Reading of the ARH falls.
  2. The domain is secured by DNSSEC, but verification of the DNS entry by libunbound falls.

The 2. is only visible because a failure to read the ARH is silently ignored.

So why does reading the ARH result from Fastmail falls? My guess is the x-bits=2048 part (I'm currently unable to do any test myself). Extra information has to be in the format <ptype>.<property>=<pvalue>.

Note that you should see more details about wait is going on if you enable debugging in the options, see also https://github.com/lieser/dkim_verifier/wiki/Debug#view-error-and-debug-messages.

pgnd commented 1 year ago

@lieser

here's the Console output for viewing/opening the 'failed' message, referenced above:

DKIM_Verifier.AuthVerifier  ERROR    Ignoring error in parsing of ARH Error: Parsing error
    match moz-extension://45b48b6c-b201-41df-af61-cc17974bd30d/modules/arhParser.mjs.js:305
    parseResInfo moz-extension://45b48b6c-b201-41df-af61-cc17974bd30d/modules/arhParser.mjs.js:188
    parse moz-extension://45b48b6c-b201-41df-af61-cc17974bd30d/modules/arhParser.mjs.js:156
    getARHResult moz-extension://45b48b6c-b201-41df-af61-cc17974bd30d/modules/authVerifier.mjs.js:241
    verify moz-extension://45b48b6c-b201-41df-af61-cc17974bd30d/modules/authVerifier.mjs.js:156
authVerifier.mjs.js:243:8
DKIM_Verifier.AuthVerifier  DEBUG    ARH result: 
Object { version: "3.0", dkim: [], spf: [], dmarc: [] }
authVerifier.mjs.js:320:6
DKIM_Verifier.Verifier  DEBUG    2 DKIM-Signatures found. verifier.mjs.js:1467:8
DKIM_Verifier.Verifier  DEBUG    Verifying DKIM-Signature 2 ... verifier.mjs.js:1482:9
DKIM_Verifier.Verifier  DEBUG    Parsed DKIM-Signature 2: 
Object { original_header: "DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r\n d=example.com; i=@example.com; q=dns/txt;\r\n s=dkim-3xxx4-rsa; t=1691500197; h=message-id : date : from\r\n : subject : reply-to : to : content-type : content-transfer-encoding :\r\n from; bh=W...=\r\n", v: "1", a_sig: "rsa", a_hash: "sha256", b: "qzV...==", b_folded: "qzV...==", bh: "W...=", c_header: "relaxed", c_body: "relaxed", d: "example.com", … }
verifier.mjs.js:1484:9
DKIM_Verifier.Verifier  DEBUG    computed body hash: WX...BI= verifier.mjs.js:1233:7
DKIM_Verifier.Verifier  FATAL    Error during DKIM verification: Error: An unexpected error occurred verifier.mjs.js:1447:8
DKIM_Verifier.Verifier  DEBUG    Exception on DKIM-Signature 2 verifier.mjs.js:1490:9
DKIM_Verifier.Verifier  DEBUG    Verifying DKIM-Signature 1 ... verifier.mjs.js:1482:9
DKIM_Verifier.Verifier  DEBUG    Parsed DKIM-Signature 1: 
Object { original_header: "DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed;\r\n d=example.com; i=@example.com; q=dns/txt;\r\n s=dkim-3xxx4-ed25519; t=1691500197; h=message-id : date :\r\n from : subject : reply-to : to : content-type :\r\n content-transfer-encoding : from;\r\n bh=W...0\r\n CmDvvtbd1dCn3y0BA==\r\n", v: "1", a_sig: "ed25519", a_hash: "sha256", b: "F...=", b_folded: "F...0\r\n C...=", bh: "W...=", c_header: "relaxed", c_body: "relaxed", d: "example.com", … }
verifier.mjs.js:1484:9
DKIM_Verifier.Verifier  DEBUG    computed body hash: WX...BI= verifier.mjs.js:1233:7
DKIM_Verifier.Verifier  FATAL    Error during DKIM verification: Error: An unexpected error occurred verifier.mjs.js:1447:8
DKIM_Verifier.Verifier  DEBUG    Exception on DKIM-Signature 1 verifier.mjs.js:1490:9
DKIM_Verifier.DMARC ERROR    Ignored error on getting the DMARC policy Error: An unexpected error occurred dmarc.mjs.js:61:8
DKIM_Verifier.SignRules DEBUG    shouldBeSigned:  
Object { shouldBeSigned: false, sdid: [], foundRule: false, hideFail: false }
signRules.mjs.js:457:7
DKIM_Verifier.DMARC ERROR    Ignored error on getting the DMARC policy Error: An unexpected error occurred dmarc.mjs.js:61:8
DKIM_Verifier.SignRules DEBUG    shouldBeSigned:  
Object { shouldBeSigned: false, sdid: [], foundRule: false, hideFail: false }
signRules.mjs.js:457:7
DKIM_Verifier.AuthVerifier  DEBUG    authResult:  
Object { version: "2.1", dkim: (2) […], spf: [], dmarc: [] } 
authVerifier.mjs.js:198:7

staring at it, i'm not sure what <ptype>.<property>=<pvalue> specifically to look for

I use fastmail authentication_milter (https://github.com/fastmail/authentication_milter/) on my server to analyze auth & generate AR headers; fastmail uses it on theirs as well.

It conditionally sets the 'x-bits' key --> https://github.com/search?q=repo%3Afastmail%2Fauthentication_milter%20x-bits&type=code

On my end, config sets extra_properties -> OFF

        "DKIM" : {
            "hide_none" : 0,
            "hide_domainkeys" : 1,
            "check_adsp" : 1,
            "show_default_adsp" : 0,
            "adsp_hide_none" : 0,
!!!         "extra_properties" : 0,
            "no_strict" : 0
        },

i'm not clear if "x-bits" is considered an invalid DKIM tag here, and, as you suggest, causes the parse fail

marcbradshaw commented 1 year ago

We (Fastmail) have made changes to remove the problematic tag from our Authentication-Results headers.

lieser commented 1 year ago

@marcbradshaw That is great to hear that you already removed the problematic tag. Did you only change


@pgnd

i'm not clear if "x-bits" is considered an invalid DKIM tag here, and, as you suggest, causes the parse fail

The <ptype>.<property>=<pvalue> I posted is a reference to the formal definition of the propspec part the the header, see https://www.rfc-editor.org/rfc/rfc8601#section-2.2. It is not something you will find in the logs of the addon.

Besides unstructured text in comments (e.g. (2048-bit rsa key sha256) in your example from mx5.messagingengine.com), propspec is the only allowed way to write arbitrary information in the header. But there the "key" part of the key-value pair must contain of two parts separated by a dot. So x-bits=2048 would have to be written as e.g. x.bits=1024.

In the log I noticed a lot of Error: An unexpected error occurred right at the places there a DNS query should happen. This kind of error normally means that something unexpected happens wrong in the internal parts Thunderbird. Maybe something is going wrong with the loading of the libunbound library?

pgnd commented 1 year ago

I can confirm that mail to my fastmail acct no longer lists the 'x-bits=' tag, and DKIM extension correctly reports:

DKIM  Valid (Signed by example.com) SPF: pass  DMARC:  pass

thx! o/