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

Fix DKIM-Signature header flowing, it is not valid to arbitrarily sli… #27

Closed
wants to merge 2 commits into from

Conversation

jensbjorgensen
Copy link

Hello, another user reported that the package sometimes create invalid DKIM-Signature headers due to how it is flowing lines. As you noted in reply, the way flowing is done presently in the code is not correct--in particular the header value cannot be split arbitrarily at any point, because when the header is processed at the receiver, the linebreaks remain whitespace and inserting whitespace into a value can only be done in base64 values without corrupting the data. I've written a robust and generalized solution that fixes this and I would humbly present it to you for you acceptance.

…ce into the header to wrap the lines, flowing must respect whitespace/token boundaries except in base64
@jensbjorgensen
Copy link
Author

Hmm ok tests failed, sorry let me run those on my end. Also I added another commit, there was another small problem.

@emersion
Copy link
Owner

emersion commented May 7, 2020

Thanks for the PR! I'm sorry about this, but I'm not sure we'll want to maintain that much code though.

What about using https://godoc.org/github.com/emersion/go-message/textproto#WriteHeader instead?

@emersion
Copy link
Owner

emersion commented May 7, 2020

I take it this PR fixes #18 right?

@jensbjorgensen
Copy link
Author

jensbjorgensen commented May 7, 2020 via email

@foxcpp
Copy link
Contributor

foxcpp commented May 8, 2020

RFC seems to allow interesting arbitrary whitespace in base64 data. Is it possible to make textproto.WriteHeader folding algorithm produce valid output by inserting e.g. spaces in base64 as a hint?

@foxcpp
Copy link
Contributor

foxcpp commented May 8, 2020

That would require go-message to expose folding algorithm independently in API. I think that's formatHeaderField function in textproto.go. @jensbjorgensen, mind taking a look if you can reuse it?

@foxcpp
Copy link
Contributor

foxcpp commented May 8, 2020

If possible, we can try to improve it. Because you know, maintaining one implementation is enough fun already, let alone two.

@jensbjorgensen
Copy link
Author

jensbjorgensen commented May 8, 2020 via email

@jensbjorgensen
Copy link
Author

jensbjorgensen commented May 8, 2020 via email

@emersion
Copy link
Owner

emersion commented May 8, 2020

If go-message doesn't help, there's still no need to have all of this complexity. We could just keep the params map we had, and put each parameter on a single line, inserting "\r\n " in the value if necessary.

@ludusrusso
Copy link
Contributor

I notice the same issue! It's a problem when you send email to "@hotmail.xx" or any MS receiver that did not pass dkim verification due to this issue!

@jensbjorgensen
Copy link
Author

jensbjorgensen commented May 21, 2020 via email

@emersion
Copy link
Owner

@jensbjorgensen Do you have any plans to update this PR to address the feedback you've received?

@jensbjorgensen
Copy link
Author

jensbjorgensen commented May 22, 2020 via email

@ludusrusso
Copy link
Contributor

I can work on it if it's ok for you!

@jensbjorgensen
Copy link
Author

jensbjorgensen commented May 22, 2020 via email

@jensbjorgensen
Copy link
Author

jensbjorgensen commented May 22, 2020 via email

@ludusrusso
Copy link
Contributor

In dkim/sign.go there's a function formatSignature which in turn calls foldHeaderField, that function is arbitrarily wrapping at 75-char boundaries. If you changed it to instead fold right after ';' where the rest of the line was longer than 78 chars that would do the trick.
On 5/22/20 7:08 PM, Ludovico Russo wrote: I can work on it if it's ok for you! — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#27 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABNVZ3EP4FSF4PG6DTFWPELRSZMK5ANCNFSM4M3I7PZA.
-- Jens B. Jorgensen jbj1@ultraemail.net

Uhm, that would not solve completely the issue if the headers string is longer then 75 chars. What about to completelly rewrite the formatHeaderParams in order to generate directly a well folded header? It should be simpler and also this should avoid folding issues like #23

@jensbjorgensen
Copy link
Author

jensbjorgensen commented May 23, 2020 via email

@foxcpp
Copy link
Contributor

foxcpp commented May 24, 2020

Is there a test case that reproduces issue with folding?

@foxcpp
Copy link
Contributor

foxcpp commented May 24, 2020

unless you had some massive list of headers you were hashing over

This can be the case, take a look at the list of headers signed by maddy by default.
https://github.com/foxcpp/maddy/blob/b54c705e2d3f415daa853a2e146322f4f29a8dca/internal/modify/dkim/dkim.go#L29

P.S. All field names from the first list are included twice in DKIM-Signature ("oversign").

@jensbjorgensen
Copy link
Author

jensbjorgensen commented May 25, 2020 via email

@emersion
Copy link
Owner

Regarding h=:

Folding whitespace (FWS) MAY be included on either side of the colon separator

@jensbjorgensen
Copy link
Author

jensbjorgensen commented May 25, 2020 via email

@emersion
Copy link
Owner

Superseded by #29

@emersion emersion closed this May 28, 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 this pull request may close these issues.

None yet

4 participants