line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::DKIM::Algorithm::dk_rsa_sha1; |
2
|
7
|
|
|
7
|
|
116
|
use strict; |
|
7
|
|
|
|
|
22
|
|
|
7
|
|
|
|
|
193
|
|
3
|
7
|
|
|
7
|
|
36
|
use warnings; |
|
7
|
|
|
|
|
19
|
|
|
7
|
|
|
|
|
320
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.20230212'; # VERSION |
5
|
|
|
|
|
|
|
# ABSTRACT: Base algorithm class |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# Copyright 2005-2006 Messiah College. All rights reserved. |
8
|
|
|
|
|
|
|
# Jason Long |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# Copyright (c) 2004 Anthony D. Urso. All rights reserved. |
11
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or |
12
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
13
|
|
|
|
|
|
|
|
14
|
7
|
|
|
7
|
|
2964
|
use Mail::DKIM::Canonicalization::dk_simple; |
|
7
|
|
|
|
|
21
|
|
|
7
|
|
|
|
|
226
|
|
15
|
7
|
|
|
7
|
|
2896
|
use Mail::DKIM::Canonicalization::dk_nofws; |
|
7
|
|
|
|
|
65
|
|
|
7
|
|
|
|
|
228
|
|
16
|
|
|
|
|
|
|
|
17
|
7
|
|
|
7
|
|
43
|
use base 'Mail::DKIM::Algorithm::Base'; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
667
|
|
18
|
7
|
|
|
7
|
|
49
|
use Carp; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
325
|
|
19
|
7
|
|
|
7
|
|
61
|
use MIME::Base64; |
|
7
|
|
|
|
|
18
|
|
|
7
|
|
|
|
|
310
|
|
20
|
7
|
|
|
7
|
|
62
|
use Digest::SHA; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
4741
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub finish_header { |
23
|
21
|
|
|
21
|
1
|
37
|
my $self = shift; |
24
|
21
|
|
|
|
|
78
|
$self->SUPER::finish_header(@_); |
25
|
|
|
|
|
|
|
|
26
|
21
|
50
|
33
|
|
|
74
|
if ( ( my $s = $self->signature ) |
27
|
|
|
|
|
|
|
&& $self->{canon}->{interesting_header} ) |
28
|
|
|
|
|
|
|
{ |
29
|
21
|
|
|
|
|
46
|
my $sender = $self->{canon}->{interesting_header}->{sender}; |
30
|
21
|
|
66
|
|
|
79
|
$sender = defined($sender) && ( Mail::Address->parse($sender) )[0]; |
31
|
21
|
|
|
|
|
854
|
my $author = $self->{canon}->{interesting_header}->{from}; |
32
|
21
|
|
33
|
|
|
132
|
$author = defined($author) && ( Mail::Address->parse($author) )[0]; |
33
|
|
|
|
|
|
|
|
34
|
21
|
100
|
|
|
|
4369
|
if ($sender) { |
|
|
50
|
|
|
|
|
|
35
|
4
|
|
|
|
|
14
|
$s->init_identity( $sender->address, 'header.sender' ); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
elsif ($author) { |
38
|
17
|
|
|
|
|
66
|
$s->init_identity( $author->address, 'header.from' ); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
21
|
|
|
|
|
71
|
return; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub get_canonicalization_class { |
45
|
21
|
|
|
21
|
0
|
46
|
my $self = shift; |
46
|
21
|
50
|
|
|
|
50
|
croak 'wrong number of arguments' unless ( @_ == 1 ); |
47
|
21
|
|
|
|
|
52
|
my ($method) = @_; |
48
|
|
|
|
|
|
|
|
49
|
21
|
50
|
|
|
|
66
|
my $class = |
|
|
100
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$method eq 'nofws' ? 'Mail::DKIM::Canonicalization::dk_nofws' |
51
|
|
|
|
|
|
|
: $method eq 'simple' ? 'Mail::DKIM::Canonicalization::dk_simple' |
52
|
|
|
|
|
|
|
: die "unknown method $method\n"; |
53
|
21
|
|
|
|
|
42
|
return $class; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub init { |
57
|
21
|
|
|
21
|
0
|
42
|
my $self = shift; |
58
|
|
|
|
|
|
|
|
59
|
21
|
50
|
|
|
|
73
|
die 'no signature' unless $self->{Signature}; |
60
|
|
|
|
|
|
|
|
61
|
21
|
100
|
|
|
|
67
|
$self->{mode} = $self->{Signature}->signature ? 'verify' : 'sign'; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# allows subclasses to set the header_digest and body_digest |
64
|
|
|
|
|
|
|
# properties |
65
|
21
|
|
|
|
|
99
|
$self->init_digests; |
66
|
|
|
|
|
|
|
|
67
|
21
|
|
|
|
|
59
|
my $method = $self->{Signature}->canonicalization; |
68
|
|
|
|
|
|
|
|
69
|
21
|
|
|
|
|
67
|
my $canon_class = $self->get_canonicalization_class($method); |
70
|
|
|
|
|
|
|
$self->{canon} = $canon_class->new( |
71
|
|
|
|
|
|
|
output_digest => $self->{header_digest}, |
72
|
|
|
|
|
|
|
Signature => $self->{Signature}, |
73
|
|
|
|
|
|
|
Debug_Canonicalization => $self->{Debug_Canonicalization} |
74
|
21
|
|
|
|
|
177
|
); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub init_digests { |
78
|
21
|
|
|
21
|
0
|
38
|
my $self = shift; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# initialize a SHA-1 Digest |
81
|
21
|
|
|
|
|
100
|
$self->{header_digest} = Digest::SHA->new(1); |
82
|
21
|
|
|
|
|
304
|
$self->{body_digest} = $self->{header_digest}; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub sign { |
86
|
6
|
|
|
6
|
1
|
21
|
my $self = shift; |
87
|
6
|
50
|
|
|
|
18
|
croak 'wrong number of arguments' unless ( @_ == 1 ); |
88
|
6
|
|
|
|
|
19
|
my ($private_key) = @_; |
89
|
|
|
|
|
|
|
|
90
|
6
|
|
|
|
|
41
|
my $digest = $self->{header_digest}->digest; |
91
|
6
|
|
|
|
|
28
|
my $signature = $private_key->sign_digest( 'SHA-1', $digest ); |
92
|
|
|
|
|
|
|
|
93
|
6
|
|
|
|
|
47
|
return encode_base64( $signature, '' ); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub verify { |
97
|
13
|
|
|
13
|
1
|
24
|
my $self = shift; |
98
|
13
|
50
|
|
|
|
37
|
croak 'wrong number of arguments' unless ( @_ == 0 ); |
99
|
|
|
|
|
|
|
|
100
|
13
|
|
|
|
|
39
|
my $base64 = $self->signature->data; |
101
|
13
|
|
|
|
|
36
|
my $public_key = $self->signature->get_public_key; |
102
|
|
|
|
|
|
|
|
103
|
13
|
|
|
|
|
82
|
my $digest = $self->{header_digest}->digest; |
104
|
13
|
|
|
|
|
53
|
my $sig = decode_base64($base64); |
105
|
13
|
|
|
|
|
42
|
return $public_key->verify_digest( 'SHA-1', $digest, $sig ); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub finish_message { |
109
|
21
|
|
|
21
|
0
|
38
|
my $self = shift; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# DomainKeys doesn't include the signature in the digest, |
112
|
|
|
|
|
|
|
# but we still want it to look "pretty" :). |
113
|
|
|
|
|
|
|
|
114
|
21
|
100
|
|
|
|
68
|
if ( $self->{mode} eq 'sign' ) { |
115
|
6
|
|
|
|
|
22
|
$self->{Signature}->prettify; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub wants_pre_signature_headers { |
120
|
15
|
|
|
15
|
0
|
38
|
return 0; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
1; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
__END__ |