| 1 | package Mail::DKIM::Algorithm::dk_rsa_sha1; | ||||||||||||||||||||||||||||
| 2 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 11 | our $VERSION = '1.20261116'; # VERSION | |||||||||||||||||||||||||||
| 5 | # ABSTRACT: Base algorithm class | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # Copyright 2005-2006 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 | |||||||||||||||||||||||||||||
| 14 | 11 | ▶ | use Mail::DKIM::Canonicalization::dk_simple; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 11 | ▶ | use Mail::DKIM::Canonicalization::dk_nofws; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 11 | ▶ | use base 'Mail::DKIM::Algorithm::Base'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 11 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 11 | ▶ | use MIME::Base64; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 11 | ▶ | use Digest::SHA; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 21 | ▶ | sub finish_header { | ||||||||||||||||||||||||||
|
Subroutine
finish_header: called CC=7 SCAR=20.7
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 21 | my $self = shift; | |||||||||||||||||||||||||||
| 24 | 21 | $self->SUPER::finish_header(@_); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 21 | ▶ | if ( ( my $s = $self->signature ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
my $s = $self->signature and $self->{"canon"}{"interesting_header"}
MC/DC0%0/2
my $s = $self->signature and $self->{"canon"}{"interesting_header"}
my $s = $self->signature
$self->{"canon"}{"interesting_header"}
Truth table33%1/3
A and B
A= my $s = $self->signatureB= $self->{"canon"}{"interesting_header"}
| |||||||||||||||||||||||||||||
| 27 | && $self->{canon}->{interesting_header} ) | ||||||||||||||||||||||||||||
| 28 | { | ||||||||||||||||||||||||||||
| 29 | 21 | my $sender = $self->{canon}->{interesting_header}->{sender}; | |||||||||||||||||||||||||||
| 30 | 21 | ▶ | $sender = defined($sender) && ( Mail::Address->parse($sender) )[0]; | ||||||||||||||||||||||||||
|
Condition66%2/3
defined $sender && ('Mail::Address'->parse($sender))[0]
MC/DC50%1/2
defined $sender && ('Mail::Address'->parse($sender))[0]
defined $sender
('Mail::Address'->parse($sender))[0]
Truth table66%2/3
A && B
A= defined $senderB= ('Mail::Address'->parse($sender))[0]
| |||||||||||||||||||||||||||||
| 31 | 21 | my $author = $self->{canon}->{interesting_header}->{from}; | |||||||||||||||||||||||||||
| 32 | 21 | ▶ | $author = defined($author) && ( Mail::Address->parse($author) )[0]; | ||||||||||||||||||||||||||
|
Condition33%1/3
defined $author && ('Mail::Address'->parse($author))[0]
MC/DC0%0/2
defined $author && ('Mail::Address'->parse($author))[0]
defined $author
('Mail::Address'->parse($author))[0]
Truth table33%1/3
A && B
A= defined $authorB= ('Mail::Address'->parse($author))[0]
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 21 | ▶ | if ($sender) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 35 | 4 | $s->init_identity( $sender->address, 'header.sender' ); | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | elsif ($author) { | ||||||||||||||||||||||||||||
| 38 | 17 | $s->init_identity( $author->address, 'header.from' ); | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | 21 | return; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 21 | ▶ | sub get_canonicalization_class { | ||||||||||||||||||||||||||
|
Subroutine
get_canonicalization_class: called CC=4 SCAR=14.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 45 | 21 | my $self = shift; | |||||||||||||||||||||||||||
| 46 | 21 | ▶ | croak 'wrong number of arguments' unless ( @_ == 1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 21 | my ($method) = @_; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 21 | ▶ | my $class = | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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 | return $class; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 21 | ▶ | sub init { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 57 | 21 | my $self = shift; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 21 | ▶ | die 'no signature' unless $self->{Signature}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 21 | ▶ | $self->{mode} = $self->{Signature}->signature ? 'verify' : 'sign'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | # allows subclasses to set the header_digest and body_digest | ||||||||||||||||||||||||||||
| 64 | # properties | ||||||||||||||||||||||||||||
| 65 | 21 | $self->init_digests; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 21 | my $method = $self->{Signature}->canonicalization; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 21 | 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 | ); | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 21 | ▶ | sub init_digests { | ||||||||||||||||||||||||||
|
Subroutine
init_digests: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 78 | 21 | my $self = shift; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | # initialize a SHA-1 Digest | ||||||||||||||||||||||||||||
| 81 | 21 | $self->{header_digest} = Digest::SHA->new(1); | |||||||||||||||||||||||||||
| 82 | 21 | $self->{body_digest} = $self->{header_digest}; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 6 | ▶ | sub sign { | ||||||||||||||||||||||||||
|
Subroutine
sign: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 86 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 87 | 6 | ▶ | croak 'wrong number of arguments' unless ( @_ == 1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 6 | my ($private_key) = @_; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 6 | my $digest = $self->{header_digest}->digest; | |||||||||||||||||||||||||||
| 91 | 6 | my $signature = $private_key->sign_digest( 'SHA-1', $digest ); | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 6 | return encode_base64( $signature, '' ); | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 13 | ▶ | sub verify { | ||||||||||||||||||||||||||
|
Subroutine
verify: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 97 | 13 | my $self = shift; | |||||||||||||||||||||||||||
| 98 | 13 | ▶ | croak 'wrong number of arguments' unless ( @_ == 0 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 13 | my $base64 = $self->signature->data; | |||||||||||||||||||||||||||
| 101 | 13 | my $public_key = $self->signature->get_public_key; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 13 | my $digest = $self->{header_digest}->digest; | |||||||||||||||||||||||||||
| 104 | 13 | my $sig = decode_base64($base64); | |||||||||||||||||||||||||||
| 105 | 13 | return $public_key->verify_digest( 'SHA-1', $digest, $sig ); | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 21 | ▶ | sub finish_message { | ||||||||||||||||||||||||||
|
Subroutine
finish_message: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 109 | 21 | 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 | ▶ | if ( $self->{mode} eq 'sign' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | 6 | $self->{Signature}->prettify; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 15 | ▶ | sub wants_pre_signature_headers { | ||||||||||||||||||||||||||
|
Subroutine
wants_pre_signature_headers: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 120 | 15 | return 0; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 11 | 1; | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | __END__ | ||||||||||||||||||||||||||||