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.js error on send of email #2668

Closed
zereraz opened this issue Jul 11, 2019 · 12 comments · Fixed by #2649 or #2697
Closed

dkim_sign.js error on send of email #2668

zereraz opened this issue Jul 11, 2019 · 12 comments · Fixed by #2649 or #2697

Comments

@zereraz
Copy link
Contributor

zereraz commented Jul 11, 2019

system info

Haraka Haraka.js — Version: 2.8.24
Node v11.15.0
OS Linux ignismail 4.4.0-154-generic #181-Ubuntu SMP Tue Jun 25 05:29:03 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
openssl OpenSSL 1.0.2g 1 Mar 2016

Expected behavior

Dkim signs email

Observed behavior

[CRIT] [-] [core] at /usr/lib/node_modules/Haraka/node_modules/async/dist/async.js:2797:21
[CRIT] [-] [core] at /usr/lib/node_modules/Haraka/node_modules/async/dist/async.js:969:16
[CRIT] [-] [core] at iterateeCallback (/usr/lib/node_modules/Haraka/node_modules/async/dist/async.js:992:24)
[CRIT] [-] [core] at /usr/lib/node_modules/Haraka/node_modules/async/dist/async.js:473:16
[CRIT] [-] [core] at /usr/lib/node_modules/Haraka/node_modules/async/dist/async.js:2806:17
[CRIT] [-] [core] at async.detectSeries (/usr/lib/node_modules/Haraka/plugins/dkim_sign.js:260:9)
[CRIT] [-] [core] at plugin.get_key_dir (/usr/lib/node_modules/Haraka/plugins/dkim_sign.js:230:28)
[CRIT] [-] [core] at MessageStream.pipe (/usr/lib/node_modules/Haraka/messagestream.js:326:31)
[CRIT] [-] [core] at MessageStream.Stream.pipe (internal/streams/legacy.js:85:8)
[CRIT] [-] [core] at DKIMSignStream.EventEmitter.emit (domain.js:503:10)
[CRIT] [-] [core] TypeError: domain.enter is not a function

Steps to reproduce

I think it would be due to my dkim_sign.ini
I tried various forms

dkim.private.key=private
[main]
  selector=jul2019
  domain=ignismail.com
selector=jul2019
domain=ignismail.com
dkim.private.key=private
[main]
  selector=jul2019
  domain=ignismail.com
  dkim.private.key=private
[main]
  selector=jul2019
  domain=ignismail.com
  dkim.private.key=./dkim/ignismail.com/private

there is a file called private in config folder
then send email after enabling dkim_sign plugin, with the plugin disabled email works.

Also I'm finding the dkim_sign plugin docs a bit confusing, thanks in advance.

@msimerson
Copy link
Member

To just sign mails for a single domain (ignismail.com), you just need to create the DKIM config for that domain:

cd config/dkim/ && ./dkim_key_gen.sh ignismail.com

Publish the DKIM public key in DNS and then you're off and running. The only contents of dkim_sign.ini that matter will be making sure [main]disabled = false.

To sign all emails with a single selector/domain/key, you follow the Single Domain Configuration section in the docs.

The dkim_sign docs currently suggest that you can assign a value to dkim.private.key. That's not how the code is written. You must instead store your dkim private key in the file config/dkim.private.key.

msimerson added a commit to msimerson/Haraka that referenced this issue Aug 29, 2019
@msimerson msimerson mentioned this issue Aug 29, 2019
3 tasks
msimerson added a commit to msimerson/Haraka that referenced this issue Aug 31, 2019
@zereraz
Copy link
Contributor Author

zereraz commented Aug 31, 2019

Thanks for fixing that,
I followed the steps and still getting the same error, I logged values and it is getting all the correct values from the config. The dig command also confirms that dns is setup correctly.
It seems to me the issue coming in DKIMSignStream(if I remove dkim_sign plugin error does not come in outbound)

[CRIT] [-] [core] TypeError: domain.enter is not a function
[CRIT] [-] [core]     at DKIMSignStream.EventEmitter.emit (domain.js:503:10)
[CRIT] [-] [core]     at MessageStream.Stream.pipe (internal/streams/legacy.js:85:8)
[CRIT] [-] [core]     at MessageStream.pipe (/usr/lib/node_modules/Haraka/messagestream.js:326:31)
[CRIT] [-] [core]     at /usr/lib/node_modules/Haraka/plugins/dkim_sign.js:230:28
[CRIT] [-] [core]     at /usr/lib/node_modules/Haraka/plugins/dkim_sign.js:260:9
[CRIT] [-] [core]     at /usr/lib/node_modules/Haraka/node_modules/async/dist/async.js:2806:17
[CRIT] [-] [core]     at /usr/lib/node_modules/Haraka/node_modules/async/dist/async.js:473:16
[CRIT] [-] [core]     at iterateeCallback (/usr/lib/node_modules/Haraka/node_modules/async/dist/async.js:992:24)
[CRIT] [-] [core]     at /usr/lib/node_modules/Haraka/node_modules/async/dist/async.js:969:16
[CRIT] [-] [core]     at /usr/lib/node_modules/Haraka/node_modules/async/dist/async.js:2797:21
[NOTICE] [-] [core] Shutting down

dkim_sign.ini

disabled = false
selector = jul2019
domain = ignismail.com
headers_to_sign = From, Sender, Reply-To, Subject, Date, Message-ID, To, Cc, MIME-Version

dkim

@noogen
Copy link
Contributor

noogen commented Sep 9, 2019

Hi, I'm also getting this error TypeError: domain.enter is not a function running Node 10 and above. Node 8 works just fine.

This happen with both v2.8.24 and also when running directly from this repo master branch.

@msimerson
Copy link
Member

I was getting that error before #2695, and I thought I had introduced it in #2694. But if you're getting it with 2.8.4, then I must have just ran into it on a fresh deployment with node 10. I need to look into that again.

@zereraz
Copy link
Contributor Author

zereraz commented Sep 10, 2019

So what I found for my case is, I was running hook_data plugin(I had written for attachments), when I removed that my dkim_sign error domain.enter went away. When I wrote at start of hook_data plugin

if(connection.relaying) {
        return next();
  }

just calling the next caused the error again.

@noogen
Copy link
Contributor

noogen commented Sep 10, 2019

It seem to be an internal node error and I've been poking around on github https://github.com/search?q=TypeError%3A+domain.enter+is+not+a+function&type=Issues which causes more confusion.

I'm suspecting this has to do with the DKIMSignStream, which inherit from Stream which derived from EventEmitter https://nodejs.org/api/domain.html#domain_implicit_binding

And when EventEmitter see that there is a domain property: https://github.com/haraka/Haraka/blob/master/plugins/dkim_sign.js#L18, it assumes that this is a Domain object and calls enter? Doing a fork and renaming this property to test this out.

@noogen
Copy link
Contributor

noogen commented Sep 10, 2019

The theory above worked out, here is my commit - https://github.com/noogen/Haraka/commit/92c0b4426ed13445065fabcda0308163e6671a0f - Well, at least it worked out for me. I no longer have the error when tested on node v12.10.0

@msimerson I did a quick test and so my variable name is not very compliance. I don't know how you want to handle this so I'll leave it up to you.

If anyone else can reproduce the error (@raunaqrox ?) and want to test, simply replace you local dkim_sign.js file:

curl -sL https://raw.githubusercontent.com/noogen/Haraka/master/plugins/dkim_sign.js -o dkim_sign.js

FYI, this was my error running inside of Docker so you can see how I came to the solution:

9/9/2019 11:17:05 PM[CRIT] [-] [core] TypeError: domain.enter is not a function
9/9/2019 11:17:05 PM[CRIT] [-] [core]     at DKIMSignStream.EventEmitter.emit (domain.js:498:10)
9/9/2019 11:17:05 PM[CRIT] [-] [core]     at MessageStream.Stream.pipe (internal/streams/legacy.js:87:8)
9/9/2019 11:17:05 PM[CRIT] [-] [core]     at MessageStream.pipe (/usr/local/lib/node_modules/Haraka/messagestream.js:327:31)
9/9/2019 11:17:05 PM[CRIT] [-] [core]     at /usr/local/lib/node_modules/Haraka/plugins/dkim_sign.js:196:28
9/9/2019 11:17:05 PM[CRIT] [-] [core]     at /usr/local/lib/node_modules/Haraka/plugins/dkim_sign.js:246:24
9/9/2019 11:17:05 PM[CRIT] [-] [core]     at /usr/local/lib/node_modules/Haraka/plugins/dkim_sign.js:291:9
9/9/2019 11:17:05 PM[CRIT] [-] [core]     at /usr/local/lib/node_modules/Haraka/node_modules/async/dist/async.js:1934:17
9/9/2019 11:17:05 PM[CRIT] [-] [core]     at wrapper (/usr/local/lib/node_modules/Haraka/node_modules/async/dist/async.js:272:20)
9/9/2019 11:17:05 PM[CRIT] [-] [core]     at iterateeCallback (/usr/local/lib/node_modules/Haraka/node_modules/async/dist/async.js:425:28)
9/9/2019 11:17:05 PM[CRIT] [-] [core]     at /usr/local/lib/node_modules/Haraka/node_modules/async/dist/async.js:325:20
9/9/2019 11:17:05 PM[NOTICE] [-] [core] Shutting down
9/9/2019 11:17:05 PM[NOTICE] [-] [core] worker 2 exited with error code: 1
9/9/2019 11:17:05 PM[NOTICE] [-] [core] worker started worker=3 pid=95
9/9/2019 11:17:05 PMloaded TLD files: 1=1528 2=8564 3=2448
9/9/2019 11:17:05 PMloaded 8787 Public Suffixes
9/9/2019 11:17:06 PMloglevel: INFO
9/9/2019 11:17:06 PMlog format: DEFAULT

And this is my Docker build installing directing from github master: https://github.com/niiknow/dockers/blob/master/haraka/Dockerfile

@msimerson
Copy link
Member

@noogen, do you mind applying my suggestion and then creating a PR?

@zereraz
Copy link
Contributor Author

zereraz commented Sep 10, 2019

Yes I tried it and it's fixed it for me!
No more the domain.enter error.
And was able to successfully send dkim signed email with attachments.

@noogen
Copy link
Contributor

noogen commented Sep 10, 2019

@msimerson sure, what would you like the property name to be?

@msimerson
Copy link
Member

We have a lot of underscore names in the code base so domain_name is the most consistent choice.

@msimerson
Copy link
Member

Leaving a comment referencing that domain is a keyword with a reference to this Issue # wouldn't be a bad idea.

msimerson pushed a commit that referenced this issue Sep 10, 2019
…2697)

* dkim_sign: fix issue #2668 renaming reserved kw/property of 'domain' to 'domain_name'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants