[GH-ISSUE #796] dkim body hash fails #481

Closed
opened 2026-02-25 21:35:08 +03:00 by kerem · 14 comments
Owner

Originally created by @apezio on GitHub (Oct 20, 2023).
Original GitHub issue: https://github.com/cypht-org/cypht/issues/796

Originally assigned to: @kambereBr on GitHub.

🐛 Bugreport

Using the latest code (only one I have tried) emails sent with cypht fail dkim verification. The error is "body hash did not verify"

I think cypht (or one of its libraries) is forgetting the end of the content-type boundary. In my example I am sending as text/plain but the same happens when sending as html or markdown.

Example body of email from cypht (quotes are mine):

"--EEbummS0cqZsZ4jVahUu7l5RWlOhhkRh8dQZC7PRP7RhHV2mfCWQgsiYKPLd
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable

dkim test 25"

and here it is at a destination:

"--EEbummS0cqZsZ4jVahUu7l5RWlOhhkRh8dQZC7PRP7RhHV2mfCWQgsiYKPLd
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable

dkim test 25

--EEbummS0cqZsZ4jVahUu7l5RWlOhhkRh8dQZC7PRP7RhHV2mfCWQgsiYKPLd--"

I am debugging the issue via opendkim's /etc/opendkim.conf options:

KeepTemporaryFiles yes
TemporaryDirectory /tmp/

This saves a copy of the body before and after it is sent.

My theory is that either opendkim or sendail is trying to 'fix' the missing boundary by adding the last "--EEbummS0cqZsZ4jVahUu7l5RWlOhhkRh8dQZC7PRP7RhHV2mfCWQgsiYKPLd--" which invalidates the dkim body hash.

I could be totally wrong and it could be something else. Something to do with CR/LF's, or an encoding / canonicalization issue.

Version & Environment

Rev: [10813]

OS: [cent os 7]

Steps to reproduce

  1. Have opendkim running and correctly configured to sign outgoing emails.
  2. Send any message to a gmail.com address.
  3. View the message on gmail and click 'show original' check the dkim status.
  4. Compare the message before it is mailed by cypht and the message at the destination.
Originally created by @apezio on GitHub (Oct 20, 2023). Original GitHub issue: https://github.com/cypht-org/cypht/issues/796 Originally assigned to: @kambereBr on GitHub. ## 🐛 Bugreport Using the latest code (only one I have tried) emails sent with cypht fail dkim verification. The error is "body hash did not verify" I think cypht (or one of its libraries) is forgetting the end of the content-type boundary. In my example I am sending as text/plain but the same happens when sending as html or markdown. Example body of email from cypht (quotes are mine): "--EEbummS0cqZsZ4jVahUu7l5RWlOhhkRh8dQZC7PRP7RhHV2mfCWQgsiYKPLd Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable dkim test 25" and here it is at a destination: "--EEbummS0cqZsZ4jVahUu7l5RWlOhhkRh8dQZC7PRP7RhHV2mfCWQgsiYKPLd Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable dkim test 25 --EEbummS0cqZsZ4jVahUu7l5RWlOhhkRh8dQZC7PRP7RhHV2mfCWQgsiYKPLd--" I am debugging the issue via opendkim's /etc/opendkim.conf options: KeepTemporaryFiles yes TemporaryDirectory /tmp/ This saves a copy of the body before and after it is sent. My theory is that either opendkim or sendail is trying to 'fix' the missing boundary by adding the last "--EEbummS0cqZsZ4jVahUu7l5RWlOhhkRh8dQZC7PRP7RhHV2mfCWQgsiYKPLd--" which invalidates the dkim body hash. I could be totally wrong and it could be something else. Something to do with CR/LF's, or an encoding / canonicalization issue. ### Version & Environment <!-- Paste Git-Commit ID or Tag-Name here --> Rev: [10813] <!-- Specify your OS and OS Version here if the issue is (most likely) platform dependent. --> OS: [cent os 7] ### Steps to reproduce 1. Have opendkim running and correctly configured to sign outgoing emails. 2. Send any message to a gmail.com address. 3. View the message on gmail and click 'show original' check the dkim status. 4. Compare the message before it is mailed by cypht and the message at the destination.
kerem closed this issue 2026-02-25 21:35:08 +03:00
Author
Owner

@apezio commented on GitHub (Oct 20, 2023):

An easier way to view the behavior is to compose a message and Save it as a draft. Open the draft and view it with the 'raw' button. Send it, then view it again in the Sent mailbox (or where ever it is). You should see it was missing the closed boundary but then later has one...

still trying to figure this out

<!-- gh-comment-id:1772054453 --> @apezio commented on GitHub (Oct 20, 2023): An easier way to view the behavior is to compose a message and Save it as a draft. Open the draft and view it with the 'raw' button. Send it, then view it again in the Sent mailbox (or where ever it is). You should see it was missing the closed boundary but then later has one... still trying to figure this out
Author
Owner

@apezio commented on GitHub (Oct 20, 2023):

Looks like changing line 234 of modules/smtp/hm-mime-message.php from:
$body = sprintf("--%s\r\nContent-Type: text/plain; charset=UTF-8; format=flowed\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n%s",

to:
$body = sprintf("--%s\r\nContent-Type: text/plain; charset=UTF-8; format=flowed\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n--".$this->boundary."--",

Adds the missing boundary, and dkim verify passes.

I never have understood the sprintf and %s thing but i think the error is in there and so on line 234 or 235.

<!-- gh-comment-id:1772063552 --> @apezio commented on GitHub (Oct 20, 2023): Looks like changing line 234 of modules/smtp/hm-mime-message.php from: ` $body = sprintf("--%s\r\nContent-Type: text/plain; charset=UTF-8; format=flowed\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n%s", ` to: ` $body = sprintf("--%s\r\nContent-Type: text/plain; charset=UTF-8; format=flowed\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n--".$this->boundary."--", ` Adds the missing boundary, and dkim verify passes. I never have understood the sprintf and %s thing but i think the error is in there and so on line 234 or 235.
Author
Owner

@apezio commented on GitHub (Oct 22, 2023):

FYI - Most likely there are many other places within modules/smtp/hm-mime-message.php with this problem. The above doesn't 'solve' the issue but merely is a placeholder for someone who is more familiar with hm-mime-message.php to realize there's an issue and create a fix.

<!-- gh-comment-id:1774151965 --> @apezio commented on GitHub (Oct 22, 2023): FYI - Most likely there are many other places within modules/smtp/hm-mime-message.php with this problem. The above doesn't 'solve' the issue but merely is a placeholder for someone who is more familiar with hm-mime-message.php to realize there's an issue and create a fix.
Author
Owner

@marclaporte commented on GitHub (Mar 9, 2024):

@apezio We are not currently equipped to set up a sandbox to test (We have Cypht sandboxes but not with DNS management for DKIM). Can you coordinate with @kambereBr for a screenshare session about this?

Thanks!

<!-- gh-comment-id:1987007250 --> @marclaporte commented on GitHub (Mar 9, 2024): @apezio We are not currently equipped to set up a sandbox to test (We have Cypht sandboxes but not with DNS management for DKIM). Can you coordinate with @kambereBr for a screenshare session about this? Thanks!
Author
Owner

@marclaporte commented on GitHub (May 6, 2024):

@apezio please

<!-- gh-comment-id:2096621332 --> @marclaporte commented on GitHub (May 6, 2024): @apezio please
Author
Owner

@apezio commented on GitHub (May 6, 2024):

I no longer have or use cypht so I dont think I can be of any more help here.

<!-- gh-comment-id:2096885873 --> @apezio commented on GitHub (May 6, 2024): I no longer have or use cypht so I dont think I can be of any more help here.
Author
Owner

@apezio commented on GitHub (May 6, 2024):

Sorry I accidently marked this as Closed and I don't know how to undo that.

<!-- gh-comment-id:2096888162 --> @apezio commented on GitHub (May 6, 2024): Sorry I accidently marked this as Closed and I don't know how to undo that.
Author
Owner

@marclaporte commented on GitHub (May 6, 2024):

I no longer have or use cypht

I hope you come back to Cypht.

We have done a lot of great work and released Cypht 2.0:
https://github.com/cypht-org/cypht/releases/tag/v2.0.0

The stats show the progress:
https://openhub.net/p/cypht

We can supply a server, and we can fix code issues in Cypht, but we need you help for the DKIM aspect.

Thanks!

<!-- gh-comment-id:2096971338 --> @marclaporte commented on GitHub (May 6, 2024): > I no longer have or use cypht I hope you come back to Cypht. We have done a lot of great work and released Cypht 2.0: https://github.com/cypht-org/cypht/releases/tag/v2.0.0 The stats show the progress: https://openhub.net/p/cypht We can supply a server, and we can fix code issues in Cypht, but we need you help for the DKIM aspect. Thanks!
Author
Owner

@marclaporte commented on GitHub (Sep 28, 2024):

The Cypht 2.x series is getting quite good. The latest is:
https://github.com/cypht-org/cypht/releases/tag/v2.4.0 is

<!-- gh-comment-id:2380399177 --> @marclaporte commented on GitHub (Sep 28, 2024): The Cypht 2.x series is getting quite good. The latest is: https://github.com/cypht-org/cypht/releases/tag/v2.4.0 is
Author
Owner

@marclaporte commented on GitHub (Aug 20, 2025):

@JohnXLivingston Do we have a server with DKIM that @kambereBr could use to test?

<!-- gh-comment-id:3206133190 --> @marclaporte commented on GitHub (Aug 20, 2025): @JohnXLivingston Do we have a server with DKIM that @kambereBr could use to test?
Author
Owner

@JohnXLivingston commented on GitHub (Aug 20, 2025):

@JohnXLivingston Do we have a server with DKIM that @kambereBr could use to test?

It should be possible to test using any email account from our usual mail provider. DKIM signature happens on the outgoing SMTP server.

<!-- gh-comment-id:3206195976 --> @JohnXLivingston commented on GitHub (Aug 20, 2025): > [@JohnXLivingston](https://github.com/JohnXLivingston) Do we have a server with DKIM that [@kambereBr](https://github.com/kambereBr) could use to test? It should be possible to test using any email account from our usual mail provider. DKIM signature happens on the outgoing SMTP server.
Author
Owner

@kambereBr commented on GitHub (Aug 20, 2025):

@JohnXLivingston Do we have a server with DKIM that @kambereBr could use to test?

It should be possible to test using any email account from our usual mail provider. DKIM signature happens on the outgoing SMTP server.

Thanks, @JohnXLivingston. I’ll give this another try and see if I can reproduce it.

<!-- gh-comment-id:3206208994 --> @kambereBr commented on GitHub (Aug 20, 2025): > > [@JohnXLivingston](https://github.com/JohnXLivingston) Do we have a server with DKIM that [@kambereBr](https://github.com/kambereBr) could use to test? > > It should be possible to test using any email account from our usual mail provider. DKIM signature happens on the outgoing SMTP server. Thanks, @JohnXLivingston. I’ll give this another try and see if I can reproduce it.
Author
Owner

@kambereBr commented on GitHub (Aug 24, 2025):

Issue reproduced and here is the PR: https://github.com/cypht-org/cypht/pull/1631

This issue has already been addressed in Cypht 2.x, so this PR backports the fix to the 1.4.x branch.

<!-- gh-comment-id:3218383795 --> @kambereBr commented on GitHub (Aug 24, 2025): Issue reproduced and here is the PR: https://github.com/cypht-org/cypht/pull/1631 This issue has already been addressed in Cypht 2.x, so this PR backports the fix to the 1.4.x branch.
Author
Owner

@kambereBr commented on GitHub (Aug 25, 2025):

The PR has been merged, so this issue is now resolved and will be closed.

<!-- gh-comment-id:3220672854 --> @kambereBr commented on GitHub (Aug 25, 2025): The PR has been merged, so this issue is now resolved and will be closed.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/cypht#481
No description provided.