fix: DKIM sign formatting#483
Closed
AdityaAudi wants to merge 2 commits intoKumoCorp:mainfrom
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
During post-migration validation of a CIDR block of customer mail, AWS SES testing endpoint reported dkim=permerror on DKIM signatures generated by KumoMTA after migration. This indicated a signature formatting issue that could impact delivery for customers using strict DKIM validators. The issue only manifested when signing many headers (especially with List-Unsubscribe headers included), suggesting a formatting bug rather than a cryptographic problem. Interestingly, more lenient validators (like Outlook) accepted the same messages, confirming the issue was specific to header formatting rather than the signing algorithm.
Problem Statement
The DKIM-Signature header generation in KumoMTA had a critical bug in RFC 5322 header folding logic. When the h= parameter (list of signed headers) exceeded the 75-character line length limit and needed to wrap across multiple lines, the folding algorithm would split header field names mid-word instead of only at proper delimiters (colons).
Example of Corrupted Output (observed in AWS SES testing):
This malformed h= value would be inserted into the DKIM-Signature header, creating an unparseable signature that strict validators reject while lenient validators attempt to work around.
Root Cause
The serialize() function in header.rs (lines 97-170) performed two sequential wrapping operations:
The second wrap would re-wrap already-wrapped content, and since it only understood space-delimited words, it could break header names mid-word when they didn't fit on a single 75-character line. The h= value would be unwrapped and re-wrapped without understanding its colon-delimited structure.
Solution
Modified the serialize() function to intelligently handle wrapping:
This ensures that: