← Index
NYTProf Performance Profile   « line view »
For /usr/local/libexec/sympa/task_manager-debug.pl
  Run on Tue Jun 1 22:32:51 2021
Reported on Tue Jun 1 22:35:14 2021

Filename/usr/local/lib/perl5/site_perl/Mail/DKIM/Algorithm/Base.pm
StatementsExecuted 0 statements in 0s
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
0000s0sMail::DKIM::Algorithm::Base::::BEGIN@14Mail::DKIM::Algorithm::Base::BEGIN@14
0000s0sMail::DKIM::Algorithm::Base::::BEGIN@15Mail::DKIM::Algorithm::Base::BEGIN@15
0000s0sMail::DKIM::Algorithm::Base::::BEGIN@16Mail::DKIM::Algorithm::Base::BEGIN@16
0000s0sMail::DKIM::Algorithm::Base::::BEGIN@17Mail::DKIM::Algorithm::Base::BEGIN@17
0000s0sMail::DKIM::Algorithm::Base::::BEGIN@19Mail::DKIM::Algorithm::Base::BEGIN@19
0000s0sMail::DKIM::Algorithm::Base::::BEGIN@2Mail::DKIM::Algorithm::Base::BEGIN@2
0000s0sMail::DKIM::Algorithm::Base::::BEGIN@20Mail::DKIM::Algorithm::Base::BEGIN@20
0000s0sMail::DKIM::Algorithm::Base::::BEGIN@3Mail::DKIM::Algorithm::Base::BEGIN@3
0000s0sMail::DKIM::Algorithm::Base::::__ANON__Mail::DKIM::Algorithm::Base::__ANON__ (xsub)
0000s0sMail::DKIM::Algorithm::Base::::add_bodyMail::DKIM::Algorithm::Base::add_body
0000s0sMail::DKIM::Algorithm::Base::::add_headerMail::DKIM::Algorithm::Base::add_header
0000s0sMail::DKIM::Algorithm::Base::::check_body_hashMail::DKIM::Algorithm::Base::check_body_hash
0000s0sMail::DKIM::Algorithm::Base::::finish_bodyMail::DKIM::Algorithm::Base::finish_body
0000s0sMail::DKIM::Algorithm::Base::::finish_headerMail::DKIM::Algorithm::Base::finish_header
0000s0sMail::DKIM::Algorithm::Base::::finish_messageMail::DKIM::Algorithm::Base::finish_message
0000s0sMail::DKIM::Algorithm::Base::::get_canonicalization_classMail::DKIM::Algorithm::Base::get_canonicalization_class
0000s0sMail::DKIM::Algorithm::Base::::initMail::DKIM::Algorithm::Base::init
0000s0sMail::DKIM::Algorithm::Base::::init_digestsMail::DKIM::Algorithm::Base::init_digests
0000s0sMail::DKIM::Algorithm::Base::::newMail::DKIM::Algorithm::Base::new
0000s0sMail::DKIM::Algorithm::Base::::signMail::DKIM::Algorithm::Base::sign
0000s0sMail::DKIM::Algorithm::Base::::signatureMail::DKIM::Algorithm::Base::signature
0000s0sMail::DKIM::Algorithm::Base::::verifyMail::DKIM::Algorithm::Base::verify
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Mail::DKIM::Algorithm::Base;
2use strict;
3use warnings;
4our $VERSION = '1.20200907'; # VERSION
5# ABSTRACT: base class for DKIM "algorithms"
6
7# Copyright 2005-2007 Messiah College. All rights reserved.
8# Jason Long <jlong@messiah.edu>
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
14use Mail::DKIM::Canonicalization::nowsp;
15use Mail::DKIM::Canonicalization::relaxed;
16use Mail::DKIM::Canonicalization::simple;
17use Mail::DKIM::Canonicalization::seal;
18
19use Carp;
20use MIME::Base64;
21
22sub new {
23 my $class = shift;
24 my %args = @_;
25 my $self = bless \%args, $class;
26 $self->init;
27 return $self;
28}
29
30sub init {
31 my $self = shift;
32
33 croak 'no signature' unless $self->{Signature};
34
35 $self->{mode} = $self->{Signature}->signature ? 'verify' : 'sign';
36
37 # allows subclasses to set the header_digest and body_digest
38 # properties
39 $self->init_digests;
40
41 my ( $header_method, $body_method ) = $self->{Signature}->canonicalization;
42
43 my $header_class = $self->get_canonicalization_class($header_method);
44 my $body_class = $self->get_canonicalization_class($body_method);
45 $self->{canon} = $header_class->new(
46 output_digest => $self->{header_digest},
47 Signature => $self->{Signature},
48 Debug_Canonicalization => $self->{Debug_Canonicalization}
49 );
50 $self->{body_canon} = $body_class->new(
51 output_digest => $self->{body_digest},
52 Signature => $self->{Signature},
53 Debug_Canonicalization => $self->{Debug_Canonicalization}
54 );
55}
56
57# override this method, please...
58# this method should set the "header_digest" and "body_digest" properties
59sub init_digests {
60 die 'not implemented';
61}
62
63# private method - DKIM-specific
64sub get_canonicalization_class {
65 my $self = shift;
66 croak 'wrong number of arguments' unless ( @_ == 1 );
67 my ($method) = @_;
68
69 my $class =
70 $method eq 'nowsp' ? 'Mail::DKIM::Canonicalization::nowsp'
71 : $method eq 'relaxed' ? 'Mail::DKIM::Canonicalization::relaxed'
72 : $method eq 'simple' ? 'Mail::DKIM::Canonicalization::simple'
73 : $method eq 'seal' ? 'Mail::DKIM::Canonicalization::seal'
74 : die "unknown method $method\n";
75 return $class;
76}
77
78
79sub add_body {
80 my $self = shift;
81 my $canon = $self->{body_canon} || $self->{canon};
82 $canon->add_body(@_);
83}
84
85
86sub add_header {
87 my $self = shift;
88 $self->{canon}->add_header(@_);
89}
90
91
92sub finish_body {
93 my $self = shift;
94 my $body_canon = $self->{body_canon} || $self->{canon};
95 $body_canon->finish_body;
96 $self->finish_message;
97}
98
99
100sub finish_header {
101 my $self = shift;
102 $self->{canon}->finish_header(@_);
103}
104
105# checks the bh= tag of the signature to see if it has the same body
106# hash as computed by canonicalizing/digesting the actual message body.
107# If it doesn't match, a false value is returned, and the
108# verification_details property is set to "body has been altered"
109sub check_body_hash {
110 my $self = shift;
111
112 # The body_hash value is set in finish_message(), if we're operating
113 # from a version of the DKIM spec that uses the bh= tag. Otherwise,
114 # the signature shouldn't have a bh= tag to check.
115
116 my $sighash = $self->{Signature}->body_hash();
117 if ( $self->{body_hash} and $sighash ) {
118 my $body_hash = $self->{body_hash};
119 my $expected = decode_base64($sighash);
120 if ( $body_hash ne $expected ) {
121 $self->{verification_details} = 'body has been altered';
122
123 # print STDERR "I calculated "
124 # . encode_base64($body_hash, "") . "\n";
125 # print STDERR "signature has "
126 # . encode_base64($expected, "") . "\n";
127 return;
128 }
129 }
130 return 1;
131}
132
133sub finish_message {
134 my $self = shift;
135
136 # DKIM requires the signature itself to be committed into the digest.
137 # But first, we need to set the bh= tag on the signature, then
138 # "prettify" it.
139
140 $self->{body_hash} = $self->{body_digest}->digest;
141 if ( $self->{mode} eq 'sign' ) {
142 $self->{Signature}
143 ->body_hash( encode_base64( $self->{body_hash}, '' ) );
144 }
145
146 if ( $self->{mode} eq 'sign' ) {
147 $self->{Signature}->prettify;
148 }
149
150 my $sig_line = $self->{Signature}->as_string_without_data;
151 my $canonicalized = $self->{canon}->canonicalize_header($sig_line);
152
153 $self->{canon}->output($canonicalized);
154}
155
156
157# override this method, please...
158sub sign {
159 die 'Not implemented';
160}
161
162
163sub signature {
164 my $self = shift;
165 @_
166 and $self->{Signature} = shift;
167 return $self->{Signature};
168}
169
170
171# override this method, please...
172sub verify {
173 die 'Not implemented';
174}
175
1761;
177
178__END__