|
2 | 2 |
|
3 | 3 | use strict; |
4 | 4 | use warnings; |
5 | | -use Test::Simple tests => 24; |
| 5 | +use Test::Simple tests => 32; |
6 | 6 |
|
7 | 7 | use Mail::DKIM::Signer; |
8 | 8 |
|
9 | | -my $keyfile = -f "t/test.key" ? "t/test.key" : "test.key"; |
| 9 | +my $tdir = -f "t/test.key" ? "t" : "."; |
| 10 | +my $keyfile = "$tdir/test.key"; |
| 11 | +my $keyfile_ed = "$tdir/test.ed.key"; |
10 | 12 | my $policy; |
11 | 13 | my $dkim; |
12 | 14 |
|
@@ -149,6 +151,89 @@ ok( $multiple[0]->as_string =~ /^DomainKey-Signature/, |
149 | 151 | "first is DomainKeys signature" ); |
150 | 152 | ok( $multiple[1]->as_string =~ /^DKIM-Signature/, "second is DKIM signature" ); |
151 | 153 |
|
| 154 | +# this policy should produce two DKIM signatures, one rsa and one ed25519 |
| 155 | +$policy = sub { |
| 156 | + my $signer = shift; |
| 157 | + $signer->add_signature( |
| 158 | + new Mail::DKIM::Signature( |
| 159 | + Algorithm => "rsa-sha256", |
| 160 | + Method => "relaxed", |
| 161 | + Headers => $signer->headers, |
| 162 | + Domain => "different-domain.example", |
| 163 | + Selector => "beta", |
| 164 | + Key => Mail::DKIM::PrivateKey->load( Type => 'rsa', |
| 165 | + File => $keyfile), |
| 166 | + ) |
| 167 | + ); |
| 168 | + $signer->add_signature( |
| 169 | + new Mail::DKIM::Signature( |
| 170 | + Algorithm => "ed25519-sha256", |
| 171 | + Method => "relaxed", |
| 172 | + Headers => $signer->headers, |
| 173 | + Domain => "different-domain.example", |
| 174 | + Selector => "gamma", |
| 175 | + Key => Mail::DKIM::PrivateKey->load( Type => 'ed25519', |
| 176 | + File => $keyfile_ed), |
| 177 | + ) |
| 178 | + ); |
| 179 | +}; |
| 180 | +$dkim = sign_sample_using_args( |
| 181 | + Policy => $policy, |
| 182 | +); |
| 183 | +ok( $dkim, "processed message" ); |
| 184 | + |
| 185 | +@multiple = $dkim->signatures; |
| 186 | +ok( @multiple == 2, "got 2 signatures" ); |
| 187 | + |
| 188 | +print "# signature=" . $multiple[0]->as_string . "\n"; |
| 189 | +ok( $multiple[0]->as_string =~ /a=rsa-sha256/, |
| 190 | + "got expected algorithm in first signature" ); |
| 191 | + |
| 192 | +print "# signature=" . $multiple[1]->as_string . "\n"; |
| 193 | +ok( $multiple[1]->as_string =~ /a=ed25519-sha256/, |
| 194 | + "got expected algorithm in second signature" ); |
| 195 | + |
| 196 | +# same test but this time with Signer loading the private keys |
| 197 | +$policy = sub { |
| 198 | + my $signer = shift; |
| 199 | + my $sig = |
| 200 | + new Mail::DKIM::Signature( |
| 201 | + Algorithm => "rsa-sha256", |
| 202 | + Method => "relaxed", |
| 203 | + Headers => $signer->headers, |
| 204 | + Domain => "different-domain.example", |
| 205 | + Selector => "beta", |
| 206 | + ); |
| 207 | + $sig->{KeyFile} = $keyfile; |
| 208 | + $signer->add_signature($sig); |
| 209 | + |
| 210 | + $sig = |
| 211 | + new Mail::DKIM::Signature( |
| 212 | + Algorithm => "ed25519-sha256", |
| 213 | + Method => "relaxed", |
| 214 | + Headers => $signer->headers, |
| 215 | + Domain => "different-domain.example", |
| 216 | + Selector => "gamma", |
| 217 | + ); |
| 218 | + $sig->{KeyFile} = $keyfile_ed; |
| 219 | + $signer->add_signature($sig); |
| 220 | +}; |
| 221 | +$dkim = sign_sample_using_args( |
| 222 | + Policy => $policy, |
| 223 | +); |
| 224 | +ok( $dkim, "processed message" ); |
| 225 | + |
| 226 | +@multiple = $dkim->signatures; |
| 227 | +ok( @multiple == 2, "got 2 signatures" ); |
| 228 | + |
| 229 | +print "# signature=" . $multiple[0]->as_string . "\n"; |
| 230 | +ok( $multiple[0]->as_string =~ /a=rsa-sha256/, |
| 231 | + "got expected algorithm in first signature" ); |
| 232 | + |
| 233 | +print "# signature=" . $multiple[1]->as_string . "\n"; |
| 234 | +ok( $multiple[1]->as_string =~ /a=ed25519-sha256/, |
| 235 | + "got expected algorithm in second signature" ); |
| 236 | + |
152 | 237 | sub sign_sample_using_args { |
153 | 238 | my %args = @_; |
154 | 239 |
|
|
0 commit comments