ARC: add independent-source testcase. Fix signatures by not line-terminating
[exim.git] / test / aux-fixed / dkim / sign_arc.pl
1 use Mail::DKIM::ARC::Signer;
2 use Mail::DKIM::TextWrap;  #recommended
3 use Getopt::Long;
4
5 # default option values
6 my $method = "simple/simple";
7 my $selector = "sel";
8 my $keyfile = "aux-fixed/dkim/dkim.private";
9 my $algorithm = "rsa-sha256";
10
11 GetOptions(
12         "method=s" => \$method,
13         "selector=s" => \$selector,
14         "keyfile=s" => \$keyfile,
15         "algorithm=s" => \$algorithm,
16 );
17
18 # create a signer object
19 my $signer = Mail::DKIM::ARC::Signer->new(
20                   Algorithm => $algorithm,
21                   Chain => 'none',    # or pass|fail|ar
22                   Domain => 'test.ex',
23                   SrvId => 'test.ex',
24                   Selector => $selector,
25                   KeyFile => $keyfile,
26                   Headers => 'x-header:x-header2',
27              );
28
29
30   # NOTE: any email being ARC signed must have an Authentication-Results
31   # header so that the ARC seal can cover those results copied into
32   # an ARC-Authentication-Results header.
33
34 # read an email and pass it into the signer, one line at a time
35 while (<STDIN>)
36 {
37       # remove local line terminators
38       chomp;
39       s/\015$//;
40
41       # use SMTP line terminators
42       $signer->PRINT("$_\015\012");
43 }
44 $signer->CLOSE;
45
46 die 'Failed' . $signer->result_details() unless $signer->result() eq 'sealed';
47
48 # Get all the signature headers to prepend to the message
49 # ARC-Seal, ARC-Message-Signature and ARC-Authentication-Results
50 # in that order.
51 print $signer->as_string;