Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DKIM_sign tries to sign using the envelop from #2774

Closed
X-Ryl669 opened this issue Mar 19, 2020 · 4 comments · Fixed by #2776
Closed

DKIM_sign tries to sign using the envelop from #2774

X-Ryl669 opened this issue Mar 19, 2020 · 4 comments · Fixed by #2776

Comments

@X-Ryl669
Copy link
Contributor

system info

system info

Haraka Haraka.js — Version: 2.8.23
Node v10.15.0
OS Linux cyril 4.9.185-xxxx-std-ipv6-64 #799710 SMP Wed Jul 10 08:31:28 UTC 2019 x86_64 GNU/Linux
openssl OpenSSL 1.1.0l 10 Sep 2019

$ grep -v "^#" /var/lib/haraka/config/plugins
syslog
dnsbl
helo.checks
tls
rcpt_to.alias_forward2
data.headers
dkim_sign
queue/discard
limit

$ cat dkim_sign.ini
[main]
disabled = false
selector = mars2020
domain = mydomain.com
headers_to_sign = To, From, Subject, Content-Type, Message-ID, Date
dkim.private.key = /var/lib/haraka/config/dkim/mydomain.com/private

Expected behavior

When using the dkim_sign plugin with an alias/forward plugin, the dkim_sign should use the current server's domain and not the envelope's from (or if missing the From header).

Observed behavior

In bold, see the dkim_sign error

Extract of logs:

[INFO] [0A24668F-A8FE-4A00-AE4D-3C6DE6EB114C.1] [core]  hook=rcpt plugin=rcpt_to.alias_forward2 function=alias_forward params=<fwd.me@mydomain.com> retval=OK msg=""
[DEBUG] [0A24668F-A8FE-4A00-AE4D-3C6DE6EB114C.1] [core] running rcpt_ok hooks
[NOTICE] [0A24668F-A8FE-4A00-AE4D-3C6DE6EB114C.1] [core] recipient <fwd.me@mydomain.com> code=OK msg="" sender=me@gmail
[PROTOCOL] [0A24668F-A8FE-4A00-AE4D-3C6DE6EB114C.1] [core] S: 250 recipient <fwd.me@mydomain.com> OK
[PROTOCOL] [0A24668F-A8FE-4A00-AE4D-3C6DE6EB114C.1] [core] C: DATA state=1
[DEBUG] [0A24668F-A8FE-4A00-AE4D-3C6DE6EB114C.1] [core] running data hooks
[PROTOCOL] [0A24668F-A8FE-4A00-AE4D-3C6DE6EB114C.1] [core] S: 354 go ahead, make my day
**[DEBUG] [-] [dkim_sign] undefined
[NOTICE] [-] [dkim_sign] skipped: no private key for todomain.com**
[DEBUG] [-] [core]  hook=pre_send_trans_email plugin=dkim_sign function=hook_pre_send_trans_email params="" retval=CONT msg=""
[INFO] [-] [core] [outbound] Processing delivery for domain: todomain.com
[DATA] [0A24668F-A8FE-4A00-AE4D-3C6DE6EB114C.1] [core] C: Received: from MacBook-Pro-de-me.local (unknown [myip])\r
[DATA] [0A24668F-A8FE-4A00-AE4D-3C6DE6EB114C.1] [core] C: 	(Authenticated sender: me)\r
[DATA] [0A24668F-A8FE-4A00-AE4D-3C6DE6EB114C.1] [core] C: 	by smtp3-g21.todomain.com (Postfix) with ESMTPSA id B47B213F8AE\r
[DATA] [0A24668F-A8FE-4A00-AE4D-3C6DE6EB114C.1] [core] C: 	for <fwd.me@mydomain.com>; Thu, 19 Mar 2020 19:03:18 +0100 (CET)\r
[DATA] [0A24668F-A8FE-4A00-AE4D-3C6DE6EB114C.1] [core] C: To: fwd.me@mydomain.com\r
[DATA] [0A24668F-A8FE-4A00-AE4D-3C6DE6EB114C.1] [core] C: From: Me <me@todomain.com>\r
[DATA] [0A24668F-A8FE-4A00-AE4D-3C6DE6EB114C.1] [core] C: Subject: Test\r
[DATA] [0A24668F-A8FE-4A00-AE4D-3C6DE6EB114C.1] [core] C: Message-ID: <554b28ee-a5f9-633c-953c-d5593457b732@free.fr>\r
[DATA] [0A24668F-A8FE-4A00-AE4D-3C6DE6EB114C.1] [core] C: Date: Thu, 19 Mar 2020 19:03:17 +0100\r
[DATA] [0A24668F-A8FE-4A00-AE4D-3C6DE6EB114C.1] [core] C: User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:68.0)\r
[DATA] [0A24668F-A8FE-4A00-AE4D-3C6DE6EB114C.1] [core] C:  Gecko/20100101 Thunderbird/68.6.0\r
[DATA] [0A24668F-A8FE-4A00-AE4D-3C6DE6EB114C.1] [core] C: MIME-Version: 1.0\r
[DATA] [0A24668F-A8FE-4A00-AE4D-3C6DE6EB114C.1] [core] C: Content-Type: text/plain; charset=utf-8; format=flowed\r
[DATA] [0A24668F-A8FE-4A00-AE4D-3C6DE6EB114C.1] [core] C: Content-Transfer-Encoding: 7bit\r
[DATA] [0A24668F-A8FE-4A00-AE4D-3C6DE6EB114C.1] [core] C: Content-Language: fr\r
[DATA] [0A24668F-A8FE-4A00-AE4D-3C6DE6EB114C.1] [core] C: \r
[DATA] [0A24668F-A8FE-4A00-AE4D-3C6DE6EB114C.1] [core] C: Test\r
[DATA] [0A24668F-A8FE-4A00-AE4D-3C6DE6EB114C.1] [core] C: \r
[DATA] [0A24668F-A8FE-4A00-AE4D-3C6DE6EB114C.1] [core] C: .\r

Steps to reproduce

Enable a forwarding plugin like alias_forward or alias_forword and set up DKIM.

@msimerson
Copy link
Member

the current server's domain

This might work for a server serving only one domain.

Per the DMARC specification, the DKIM signature should align with the From header. Therefore, the dkim_sign plugin will prefer to sign the message with the domain in the From header if present, and that's exactly what happened:

C: From: Me <me@todomain.com>\r
[dkim_sign] skipped: no private key for todomain.com

When the From header is missing, we attempt to extract the domain name from the envelope from.

@X-Ryl669
Copy link
Contributor Author

X-Ryl669 commented Mar 20, 2020

Yes, that's what I've understood. But when forwarding emails, there is no way to have a domain name signature (since it's from the source we don't master). From what I've seen in some email:

Received: (Haraka outbound); Thu, 19 Mar 2020 14:24:02 +0100
Delivered-To: me@todomain.com
Message-Id: <10E785D7-39E7-47BE-9657-CCD3B362ED30.1@cyril>
Date: Thu, 19 Mar 2020 14:24:02 +0100
Received: from a3-14.smtp-out.eu-west-1.amazonses.com (a3-14.smtp-out.eu-west-1.amazonses.com [54.240.3.14])
	by cyril (Haraka/2.8.23) with ESMTPS id 10E785D7-39E7-47BE-9657-CCD3B362ED30.1
	envelope-from <01020170f2f70c28-589c4219-923f-4393-8bcf-a88e5f93736b-000000@sesmailer.luno.com>
	(version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-SHA256 verify=FAIL);
	Thu, 19 Mar 2020 14:24:02 +0100
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple;
	s=2q4tpfgng4do2qfskkknw2a7okjbe5ot; d=luno.com; t=1584624241;
	h=To:From:Subject:Content-Type:Message-ID:Date;
	bh=0oFKKcJJvv4y5SXHMndR/1iHN3NHIUsv16zkt1bJmGE=;
	b=Rg1pOdf2agw186WmvhXLBBDk+wCQOpirLOo0Rb4rMMiHvgOGPNZ1TL0i4vR7D8rj
	YTPTzaEEMJG5XzGrfDmuscFkZIMuCx3YgiOFJ9Bb3WTwI6aN1rc+aiocQNos1TRjlmO
	zhYH8P8LfbBPQHFA8NwHC0s2VOdUx2eqpHvU2CUc=
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple;
	s=shh3fegwg5fppqsuzphvschd53n6ihuv; d=amazonses.com; t=1584624241;
	h=To:From:Subject:Content-Type:Message-ID:Date:Feedback-ID;
	bh=0oFKKcJJvv4y5SXHMndR/1iHN3NHIUsv16zkt1bJmGE=;
	b=Urfi9z/8TC6lFKA+yxLHyagMyNNWdZU5YcFHCGeOAAc9GorSOxuGnFOqkZnBycj8
	he9XRJzTyuBUmQuVjbY0gobCtNgNcWwqhbNAuvbLeZCgH6Pr6uNhYL++GaN9gdtlILX
	9aP3ww7iGZkVn3Vw7x9IY+4r5/W0zSTJxtgoOuNU=
To: "Cyril" <me@mydomain.com>
From: "Luno" <no-reply@luno.com>

You can have multiple layer of DKIM signature, one for each hop.
I wonder if, in case of forwarding, Haraka shouldn't add its own layer (based on the intermediate domain) ? Maybe by adding an envelope from ?

In the standard, I'm reading:

RFC 4871 (DKIM Signatures), section 4.1 "Example Scenarios" states:

    There are many reasons why a message might have multiple signatures. [...]

    [An] example of multiple signers might be forwarding services, such as those commonly associated with academic alumni sites.

RFC 4871, section 4.2 states:

   When evaluating a message with multiple signatures, a verifier SHOULD evaluate signatures independently and on their own merits.

@X-Ryl669
Copy link
Contributor Author

From what I've found, it seems SRS is required in order to rewrite the envelope without breaking the initial message. Does Haraka supports SRS ?

@X-Ryl669
Copy link
Contributor Author

Ok, I've hacked something that works a bit like this:

  1. My alias plugin is adding SRS to the envelope from address. It's also adding a transaction.notes.aliased = true so later plugin can behave differently depending if we are forwarding or not.
  2. I've modified the DKIM_sign plugin to extract the domain from the envelope only, if transaction.notes.aliased is true. Else, it'll use From header and fallback to envelope from if none found (like before). DKIM_sign adds its own signature and since no modifications are done on the mail headers, the previous signature are still valid.
  3. That way, SPF and DKIM should still pass (SPF pass because of the presence of SRS), so DMARC should pass too (at least, it does on the many failing emails that before the change).

It seems to work now better for forwarding as it's following the RFC I've read (see above).

Would you like me to send a PR for the DKIM change ?

X-Ryl669 pushed a commit to X-Ryl669/Haraka that referenced this issue Mar 23, 2020
X-Ryl669 added a commit to X-Ryl669/Haraka that referenced this issue Mar 23, 2020
X-Ryl669 added a commit to X-Ryl669/Haraka that referenced this issue Mar 25, 2020
X-Ryl669 added a commit to X-Ryl669/Haraka that referenced this issue Mar 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants