SRS/Guarded.pm

filter: Statementstmt 95.1% 39 / 41 Branchbran 85.7% 12 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 88.5% 62 / 70 CC 9 SCAR 14.5
CC
9
Cov
90%
parse
7.6
compile
3.0
BEGIN
1.0
CRAP 4.3
« SRS.pm ↑ Summary SRS/Shortcut.pm »
1 package Mail::SRS::Guarded;
2  
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use Mail::SRS qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use Mail::SRS::Shortcut;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 7 @ISA = qw(Mail::SRS::Shortcut);
11  
12 =head1 NAME
13  
14 Mail::SRS::Guarded - A guarded Sender Rewriting Scheme (recommended)
15  
16 =head1 SYNOPSIS
17  
18 use Mail::SRS::Guarded;
19 my $srs = new Mail::SRS::Guarded(...);
20  
21 =head1 DESCRIPTION
22  
23 This is the default subclass of Mail::SRS. An instance of this subclass
24 is actually constructed when "new Mail::SRS" is called.
25  
26 Note that allowing variable separators after the SRS\d token means that
27 we must preserve this separator in the address for a possible reversal.
28 SRS1 does not need to understand the SRS0 address, just preserve it,
29 on the assumption that it is valid and that the host doing the final
30 reversal will perform cryptographic tests. It may therefore strip just
31 the string SRS0 and not the separator. This explains the appearance
32 of a double separator in SRS1<sep><hostname>=<sep>.
33  
34 See Mail::SRS for details of the standard SRS subclass interface.
35 This module provides the methods compile() and parse(). It operates
36 without store, and guards against gaming the shortcut system.
37  
38 =head1 SEE ALSO
39  
40 L<Mail::SRS>
41  
42 =cut
43  
44 75 ▶sub compile {
Subroutine compile: called CC=3 SCAR=11.0
Pod documented
45 75 my ($self, $sendhost, $senduser) = @_;
46  
47 75 ▶ if ($senduser =~ s/$SRS1RE//io) {
Branch: 2 branches
BranchTrueFalseTotal
if ($senduser =~ s/$Mail::SRS::Guarded::SRS1RE//io) { } 5 70 75
elsif ($senduser =~ s/$Mail::SRS::Guarded::SRS0RE/$1/io) { } 37 33 70
48  
49 # We could do a sanity check. After all, it might NOT be
50 # an SRS address, unlikely though that is. We are in the
51 # presence of malicious agents. However, since we don't need
52 # to interpret it, it doesn't matter if it isn't an SRS
53 # address. Our malicious SRS0 party gets back the garbage
54 # he spat out.
55  
56 # Actually, it turns out that we can simplify this
57 # function considerably, although it should be borne in mind
58 # that this address is not opaque to us, even though we didn't
59 # actually process or generate it.
60  
61 # hash, srshost, srsuser
62 5 my (undef, $srshost, $srsuser) =
63 split(qr/\Q$SRSSEP\E/, $senduser, 3);
64  
65 5 my $hash = $self->hash_create($srshost, $srsuser);
66  
67 5 return $SRS1TAG . $self->separator .
68 join($SRSSEP, $hash, $srshost, $srsuser);
69 }
70 elsif ($senduser =~ s/$SRS0RE/$1/io) {
71 37 my $hash = $self->hash_create($sendhost, $senduser);
72 37 return $SRS1TAG . $self->separator .
73 join($SRSSEP, $hash, $sendhost, $senduser);
74 }
75  
76 33 return $self->SUPER::compile($sendhost, $senduser);
77 }
78  
79 77 ▶sub parse {
Subroutine parse: called CC=7 SCAR=20.3
Pod documented
80 77 my ($self, $user) = @_;
81  
82 77 ▶ if ($user =~ s/$SRS1RE//oi) {
Branch: 1 branch
BranchTrueFalseTotal
if ($user =~ s/$Mail::SRS::Guarded::SRS1RE//io) 40 37 77
83 40 my ($hash, $srshost, $srsuser) =
84 split(qr/\Q$SRSSEP\E/, $user, 3);
85  
86 40 ▶ if ($hash =~ /\Q.\E/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hash =~ /\./) { } 2 38 40
87 die "Hashless SRS1 address received when " .
88 "AllowUnsafeSrs is not set"
89 2 ▶ unless $self->{AllowUnsafeSrs};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"AllowUnsafeSrs"} 1 1 2
90 # Reconstruct the parameters as they were in the old format.
91 1 $srsuser = $srshost . $SRSSEP . $srsuser;
92 1 $srshost = $hash;
93 }
94 else {
95 38 ▶ unless ($self->hash_verify($hash, $srshost, $srsuser)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->hash_verify($hash, $srshost, $srsuser)) 0 38 38
96 0 die "Invalid hash";
97 }
98 }
99  
100 39 ▶ unless (defined $srshost and defined $srsuser) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $srshost and defined $srsuser) 0 39 39
Condition33%1/3
defined $srshost and defined $srsuser
!ll&&!rl&&r
0039
MC/DC0%0/2
defined $srshost and defined $srsuser
defined $srshost defined $srsuser
Truth table33%1/3
A and B
A= defined $srshostB= defined $srsuser
ABresult
0X0
100
111
101 0 die "Invalid SRS1 address";
102 }
103 39 return ($srshost, $SRS0TAG . $srsuser);
104 }
105  
106 37 return $self->SUPER::parse($user);
107 }
108  
109 7 1;
« SRS.pm ↑ Summary SRS/Shortcut.pm »