line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::DKIM::Key; |
2
|
14
|
|
|
14
|
|
121
|
use strict; |
|
14
|
|
|
|
|
29
|
|
|
14
|
|
|
|
|
409
|
|
3
|
14
|
|
|
14
|
|
67
|
use warnings; |
|
14
|
|
|
|
|
37
|
|
|
14
|
|
|
|
|
6182
|
|
4
|
|
|
|
|
|
|
# ABSTRACT: Represents a DKIM Key |
5
|
|
|
|
|
|
|
our $VERSION = '1.20230911'; # VERSION |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# Copyright 2006 Jason Long. All rights reserved. |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# Copyright (c) 2004 Anthony D. Urso. All rights reserved. |
10
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or |
11
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub cork { |
14
|
1499
|
|
|
1499
|
0
|
2340
|
my $self = shift; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
(@_) |
17
|
1499
|
100
|
|
|
|
3159
|
and $self->{'CORK'} = shift; |
18
|
|
|
|
|
|
|
|
19
|
1499
|
100
|
|
|
|
3875
|
$self->{'CORK'} |
20
|
|
|
|
|
|
|
or $self->convert; |
21
|
|
|
|
|
|
|
|
22
|
1498
|
|
|
|
|
3541
|
$self->{'CORK'}; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub data { |
26
|
1040
|
|
|
1040
|
0
|
1295
|
my $self = shift; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
(@_) |
29
|
1040
|
50
|
|
|
|
1719
|
and $self->{'DATA'} = shift; |
30
|
|
|
|
|
|
|
|
31
|
1040
|
|
|
|
|
2304
|
$self->{'DATA'}; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub errorstr { |
35
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
(@_) |
38
|
0
|
0
|
|
|
|
0
|
and $self->{'ESTR'} = shift; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
0
|
$self->{'ESTR'}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub size { |
44
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
0
|
return $self->cork->size * 8; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub type { |
50
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
(@_) |
53
|
0
|
0
|
|
|
|
0
|
and $self->{'TYPE'} = shift; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
0
|
$self->{'TYPE'}; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub calculate_EM { |
59
|
390
|
|
|
390
|
0
|
761
|
my ( $digest_algorithm, $digest, $emLen ) = @_; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# this function performs DER encoding of the algorithm ID for the |
62
|
|
|
|
|
|
|
# hash function and the hash value itself |
63
|
|
|
|
|
|
|
# It has this syntax: |
64
|
|
|
|
|
|
|
# DigestInfo ::= SEQUENCE { |
65
|
|
|
|
|
|
|
# digestAlgorithm AlgorithmIdentifier, |
66
|
|
|
|
|
|
|
# digest OCTET STRING |
67
|
|
|
|
|
|
|
# } |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# RFC 3447, page 42, provides the following octet values: |
70
|
390
|
|
|
|
|
1379
|
my %digest_encoding = ( |
71
|
|
|
|
|
|
|
'SHA-1' => pack( 'H*', '3021300906052B0E03021A05000414' ), |
72
|
|
|
|
|
|
|
'SHA-256' => pack( 'H*', '3031300d060960864801650304020105000420' ), |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
|
75
|
390
|
50
|
|
|
|
1007
|
defined $digest_encoding{$digest_algorithm} |
76
|
|
|
|
|
|
|
or die "Unsupported digest algorithm '$digest_algorithm'"; |
77
|
|
|
|
|
|
|
|
78
|
390
|
|
|
|
|
917
|
my $T = $digest_encoding{$digest_algorithm} . $digest; |
79
|
390
|
|
|
|
|
658
|
my $tLen = length($T); |
80
|
|
|
|
|
|
|
|
81
|
390
|
50
|
|
|
|
924
|
if ( $emLen < $tLen + 11 ) { |
82
|
0
|
|
|
|
|
0
|
die 'Intended encoded message length too short.'; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
390
|
|
|
|
|
990
|
my $PS = chr(0xff) x ( $emLen - $tLen - 3 ); |
86
|
390
|
|
|
|
|
766
|
my $EM = chr(0) . chr(1) . $PS . chr(0) . $T; |
87
|
390
|
|
|
|
|
1275
|
return $EM; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__END__ |