Skip to content

Commit

Permalink
improve Authres signature
Browse files Browse the repository at this point in the history
  • Loading branch information
bigio committed May 26, 2022
1 parent 12522d8 commit 24a3bc1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
1 change: 1 addition & 0 deletions MANIFEST
Expand Up @@ -149,6 +149,7 @@ t/actions.t
t/arc.t
t/authres.t
t/data/arc1.eml
t/data/arc2.eml
t/data/dkim1.eml
t/data/dkim2.eml
t/data/dkim.pem
Expand Down
8 changes: 4 additions & 4 deletions modules/lib/Mail/MIMEDefang/Authres.pm
Expand Up @@ -81,19 +81,19 @@ sub md_authres {
my $dkimb = substr($dkimpk, 0, 8);
$authres = "$serverdomain (MIMEDefang);";
if($ksize > 0) {
$authres .= "\r\ndkim=$dkimres ($ksize-bit key) header.d=$dkimdom";
$authres .= "\r\n\tdkim=$dkimres ($ksize-bit key) header.d=$dkimdom";
if(defined($dkimb)) {
$authres .= " header.b=$dkimb";
}
$authres .= ";";
}
if(defined $spfres) {
if($spfres->code eq 'fail') {
$authres .= "\r\nspf=" . $spfres->code . " ($serverdomain: domain of $spfmail does not designate $relayip as permitted sender) smtp.mailfrom=$spfmail;";
$authres .= "\r\n\tspf=" . $spfres->code . " (domain of $spfmail does not designate $relayip as permitted sender) smtp.mailfrom=$spfmail;";
} elsif($spfres->code eq 'pass') {
$authres .= "\r\nspf=" . $spfres->code . " ($serverdomain: domain of $spfmail designates $relayip as permitted sender) smtp.mailfrom=$spfmail;";
$authres .= "\r\n\tspf=" . $spfres->code . " (domain of $spfmail designates $relayip as permitted sender) smtp.mailfrom=$spfmail;";
} elsif($spfres->code eq 'none') {
$authres .= "\r\nspf=" . $spfres->code . " ($serverdomain: domain of $spfmail doesn't specify if $relayip is a permitted sender) smtp.mailfrom=$spfmail;";
$authres .= "\r\n\tspf=" . $spfres->code . " (domain of $spfmail doesn't specify if $relayip is a permitted sender) smtp.mailfrom=$spfmail;";
}
}
$authres =~ s/\r//gs;
Expand Down
13 changes: 11 additions & 2 deletions t/arc.t
Expand Up @@ -10,7 +10,7 @@ use Mail::MIMEDefang::DKIM::ARC;

use File::Copy;

sub arc_sign : Test(3)
sub arc_sign : Test(6)
{
copy('t/data/arc1.eml', './INPUTMSG');

Expand All @@ -20,6 +20,15 @@ sub arc_sign : Test(3)
like($headers{"ARC-Authentication-Results"}, qr/i=1; testing\.dkim\.org; header\.From=mickey\@dkim\.org; dkim=pass/);

unlink('./INPUTMSG');
}
undef %headers;

copy('t/data/arc2.eml', './INPUTMSG');

%headers = md_arc_sign('t/data/dkim.pem', 'rsa-sha256', 'none', 'sa-test.spamassassin.org', undef, 't0768');
like($headers{"ARC-Seal"}, qr/i=1; a=rsa\-sha256; cv=none; d=sa-test\.spamassassin\.org; s=/);
like($headers{"ARC-Message-Signature"}, qr/i=1; a=rsa\-sha256; c=relaxed\/relaxed; d=/);
like($headers{"ARC-Authentication-Results"}, qr/i=1; sa-test.spamassassin.org;/);

unlink('./INPUTMSG');
}
__PACKAGE__->runtests();
2 changes: 1 addition & 1 deletion t/authres.t
Expand Up @@ -15,7 +15,7 @@ sub t_md_authres : Test(1)
copy('t/data/dkim1.eml', './INPUTMSG');

my $header = md_authres('test@sa-test.spamassassin.org', '1.2.3.4', 'sa-test.spamassassin.org');
like($header, qr{sa\-test\.spamassassin\.org \(MIMEDefang\);(?:.*)\s+dkim=pass \(768\-bit key\) header\.d=sa-test\.spamassassin\.org header\.b=oRxHoP0Y;(?:.*)\s+spf=none \(sa\-test\.spamassassin\.org: domain of test\@sa\-test\.spamassassin\.org doesn't specify if 1\.2\.3\.4 is a permitted sender\) smtp\.mailfrom=test\@sa\-test\.spamassassin\.org;});
like($header, qr{sa\-test\.spamassassin\.org \(MIMEDefang\);(?:.*)\s+dkim=pass \(768\-bit key\) header\.d=sa-test\.spamassassin\.org header\.b=oRxHoP0Y;(?:.*)\s+spf=none \(domain of test\@sa\-test\.spamassassin\.org doesn't specify if 1\.2\.3\.4 is a permitted sender\) smtp\.mailfrom=test\@sa\-test\.spamassassin\.org;});

unlink('./INPUTMSG');
}
Expand Down
17 changes: 17 additions & 0 deletions t/data/arc2.eml
@@ -0,0 +1,17 @@
Authentication-Results: sa-test.spamassassin.org (MIMEDefang);
dkim=pass (768-bit key) header.d=sa-test.spamassassin.org header.b=oRxHoP0Y;
spf=none (domain of test@sa-test.spamassassin.org doesn't specify if 1.2.3.4 is a permitted sender) smtp.mailfrom=test@sa-test.spamassassin.org;
DKIM-Signature: v=1; a=rsa-sha1; d=sa-test.spamassassin.org; h=from:to
:subject:message-id:date:mime-version:content-type; s=t0768; bh=
vxHXq7bMZ9+UHGuKBsbQKsDHmmk=; b=oRxHoP0YN5LfqwKiqM0iFIeG6J0odmtG
bttw9VPWjmTouQl15+EEPNfmWNyKqbXYSs0BbmfkWZuYHSf56lj1F89xqbf62w2h
cnelgVK2HSbyD8kzbAAGR/yPWamnRhne
From: SpamAssassin Test <test@sa-test.spamassassin.org>
To: undisclosed-recipients:;
Subject: test message 1
Message-ID: <4A294538.10002@spamassassin.org>
Date: Mon, 08 Jun 2009 12:00:00 +0000
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii

testing

0 comments on commit 24a3bc1

Please sign in to comment.