[Mimedefang] DKIM body hash won't verify.

Matthew Schumacher matt.s at aptalaska.net
Fri Feb 22 13:57:28 EST 2019


I just put DKIM on my mail system, but gmail rejects with "body hash did 
not verify", so something is wrong with how I'm hashing.  Does this code 
look reasonable?

  sub dkim_sign {
         my $dkim = Mail::DKIM::Signer->new(
                 Algorithm => "rsa-sha1",
                 Method => "relaxed",
                 Domain => "domain.net",
                 Selector => "beta",
                 KeyFile => "/etc/mail/dkim.key");
         if (open(TOSIGN, "<SIGNME")) {
                 while(<TOSIGN>) {
                         # remove local line terminators

                         # use SMTP line terminators
                 my $signature = $dkim->signature()->as_string();
                 $signature =~ s/^DKIM-Signature:\s+//i;
                 action_add_header('DKIM-Signature', $signature);

sub filter_wrapup {
   my($entity) = @_;

   open(my $fh, '>', "./SIGNME") or die "Could not open file 'SIGNME' $!";
   print $fh $entity->stringify();
   close $fh;



I got the key from https://dkimcore.org/tools/ to make sure I got 
something workable, perhaps that is the issue.

More information about the MIMEDefang mailing list