"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "scripts/dkimsign.pl" between
Mail-DKIM-1.20220408.tar.gz and Mail-DKIM-1.20220520.tar.gz

About: Mail-DKIM Perl module for implementing the DKIM (DomainKeys Identified Mail) message-signing and verifying standard for Internet mail.

dkimsign.pl  (Mail-DKIM-1.20220408):dkimsign.pl  (Mail-DKIM-1.20220520)
skipping to change at line 14 skipping to change at line 14
# You can redistribute it and/or modify it under the terms of the # You can redistribute it and/or modify it under the terms of the
# GNU Public License as found at http://www.fsf.org/copyleft/gpl.html. # GNU Public License as found at http://www.fsf.org/copyleft/gpl.html.
# #
# Written by Jason Long, jlong@messiah.edu. # Written by Jason Long, jlong@messiah.edu.
use strict; use strict;
use warnings; use warnings;
use Mail::DKIM::Signer; use Mail::DKIM::Signer;
use Mail::DKIM::TextWrap; use Mail::DKIM::TextWrap;
use Getopt::Long; use Getopt::Long::Descriptive;
use Pod::Usage; use Pod::Usage;
my $type = "dkim"; my ($opt, $usage) = describe_options(
my $selector = "selector1"; "%c %o < original_email.txt",
my $algorithm = "rsa-sha1"; [ "type=s" => "Determine the desired signature type 'dkim' or 'domainkeys'", {
my $method = "simple"; default=>'dkim'} ],
my $domain; # undef => auto-select domain [ "algorithm=s" => "Algorithm to sign with", {default=>"rsa-sha256"} ],
my $expiration; [ "method=s" => "Specify the desired canonicalization method, Possible values
my $identity; are simple, simple/simple, simple/relaxed, relaxed, relaxed/relaxed, relaxed/sim
my $key_file = "private.key"; ple", {default=>"simple"} ],
my $key_protocol; [ "selector=s" => "Signing selector", {default=>'selector1'} ],
my @extra_tag; [ "domain=s" => "Signing domain" ],
my $debug_canonicalization; [ "expiration=s" => "Optional signature expiration, as delta from current time
my $binary; stamp" ],
my $help; [ "identity=s" => "Optional identity to use for signing" ],
GetOptions( [ "key=s" => "File containing private key, without BEGIN or END lines.", {defa
"type=s" => \$type, ult=>"private.key"} ],
"algorithm=s" => \$algorithm, [ "key-protocol=s" => "Optional key protocol to use" ],
"method=s" => \$method, [ "debug-canonicalization=s" => "Outputs the canonicalized message to the spec
"selector=s" => \$selector, ified file, in addition to computing the DKIM signature. This is helpful for deb
"domain=s" => \$domain, ugging canonicalization methods." ],
"expiration=i" => \$expiration, [ "extra-tag=s@" => "Extra tags to use in signing" ],
"identity=s" => \$identity, [ "timestamp=i" => "Timestamp to sign with, defaults to now", {default=>time}
"key=s" => \$key_file, ],
"key-protocol=s" => \$key_protocol, [ "binary" => "Read input in binary mode" ],
"debug-canonicalization=s" => \$debug_canonicalization, [ "help|?" => "Show help" ],
"extra-tag=s" => \@extra_tag, {show_defaults=>1},
"binary" => \$binary, );
"help|?" => \$help,
) if ($opt->help) {
or pod2usage(2); print $usage->text;
pod2usage(1) if $help; exit 1;
pod2usage("Error: unrecognized argument(s)") }
unless (@ARGV == 0);
my $debugfh; my $debugfh;
if (defined $debug_canonicalization) if (defined $opt->debug_canonicalization)
{ {
open $debugfh, ">", $debug_canonicalization open $debugfh, ">", $opt->debug_canonicalization
or die "Error: cannot write $debug_canonicalization: $!\n"; or die "Error: cannot write ".$opt->debug_canonicalization.": $!\
n";
} }
if ($binary) if ($opt->binary)
{ {
binmode STDIN; binmode STDIN;
} }
my $dkim = new Mail::DKIM::Signer( my $dkim = new Mail::DKIM::Signer(
Policy => \&signer_policy, Policy => \&signer_policy,
Algorithm => $algorithm, Algorithm => $opt->algorithm,
Method => $method, Method => $opt->method,
Selector => $selector, Selector => $opt->selector,
KeyFile => $key_file, KeyFile => $opt->key,
Debug_Canonicalization => $debugfh, Debug_Canonicalization => $debugfh,
); );
while (<STDIN>) while (<STDIN>)
{ {
unless ($binary) unless ($opt->binary)
{ {
chomp $_; chomp $_;
s/\015?$/\015\012/s; s/\015?$/\015\012/s;
} }
$dkim->PRINT($_); $dkim->PRINT($_);
} }
$dkim->CLOSE; $dkim->CLOSE;
if ($debugfh) if ($debugfh)
{ {
close $debugfh; close $debugfh;
print STDERR "wrote canonicalized message to $debug_canonicalization\n"; print STDERR "wrote canonicalized message to ".$opt->debug_canonicalizati on."\n";
} }
print $dkim->signature->as_string . "\n"; print $dkim->signature->as_string . "\n";
sub signer_policy sub signer_policy
{ {
my $dkim = shift; my $dkim = shift;
use Mail::DKIM::DkSignature; use Mail::DKIM::DkSignature;
$dkim->domain($domain || $dkim->message_sender->host); $dkim->domain($opt->domain || $dkim->message_sender->host);
my $class = $type eq "domainkeys" ? "Mail::DKIM::DkSignature" : my $class = $opt->type eq "domainkeys" ? "Mail::DKIM::DkSignature" :
$type eq "dkim" ? "Mail::DKIM::Signature" : $opt->type eq "dkim" ? "Mail::DKIM::Signature" :
die "unknown signature type '$type'\n"; die "unknown signature type '".$opt->type."'\n";
my $timestamp = $opt->timestamp ? $opt->timestamp : time();
my $sig = $class->new( my $sig = $class->new(
Algorithm => $dkim->algorithm, Algorithm => $dkim->algorithm,
Method => $dkim->method, Method => $dkim->method,
Headers => $dkim->headers, Headers => $dkim->headers,
Domain => $dkim->domain, Domain => $dkim->domain,
Selector => $dkim->selector, Selector => $dkim->selector,
defined($expiration) ? (Expiration => time() + $expiratio defined($opt->timestamp) ? (Timestamp => $opt->expiration
n) : (), ) : (),
defined($identity) ? (Identity => $identity) : (), defined($opt->expiration) ? (Expiration => $timestamp + $
opt->expiration) : (),
defined($opt->identity) ? (Identity => $opt->identity) :
(),
); );
$sig->protocol($key_protocol) if defined $key_protocol; $sig->protocol($opt->key_protocol) if defined $opt->key_protocol;
foreach my $extra (@extra_tag) if ($opt->extra_tag) {
{ foreach my $extra ($opt->extra_tag->@*)
my ($n, $v) = split /=/, $extra, 2; {
$sig->set_tag($n, $v); my ($n, $v) = split /=/, $extra, 2;
$sig->set_tag($n, $v);
}
} }
$dkim->add_signature($sig); $dkim->add_signature($sig);
return; return;
} }
__END__ __END__
=head1 NAME =head1 NAME
dkimsign.pl - computes a DKIM signature for an email message dkimsign.pl - computes a DKIM signature for an email message
skipping to change at line 138 skipping to change at line 133
options: options:
--type=TYPE --type=TYPE
--method=METHOD --method=METHOD
--selector=SELECTOR --selector=SELECTOR
--expiration=INTEGER --expiration=INTEGER
--debug-canonicalization=FILE --debug-canonicalization=FILE
dkimsign.pl --help dkimsign.pl --help
to see a full description of the various options to see a full description of the various options
=head1 OPTIONS
=over
=item B<--expiration>
Optional. Specify the desired signature expiration, as a delta
from the signature timestamp.
=item B<--type>
Determines the desired signature. Use dkim for a DKIM-Signature, or
domainkeys for a DomainKey-Signature.
=item B<--method>
Determines the desired canonicalization method. Possible values are
simple, simple/simple, simple/relaxed, relaxed, relaxed/relaxed,
relaxed/simple.
=item B<--debug-canonicalization>
Outputs the canonicalized message to the specified file, in addition
to computing the DKIM signature. This is helpful for debugging
canonicalization methods.
=back
=head1 AUTHOR =head1 AUTHOR
Jason Long, E<lt>jlong@messiah.eduE<gt> Jason Long, E<lt>jlong@messiah.eduE<gt>
Marc Bradshaw, E<lt>marc@marcbradshaw.netE<gt>
=head1 COPYRIGHT AND LICENSE =head1 COPYRIGHT AND LICENSE
Copyright (C) 2006-2007 by Messiah College Copyright (C) 2006-2007 by Messiah College
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.6 or, it under the same terms as Perl itself, either Perl version 5.8.6 or,
at your option, any later version of Perl 5 you may have available. at your option, any later version of Perl 5 you may have available.
=cut =cut
 End of changes. 14 change blocks. 
83 lines changed or deleted 63 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)