| 1 | package Authen::DigestMD5; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | package Authen::DigestMD5::Packet; | ||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | my %quote=map{$_=>1} qw(username realm nonce cnonce digest-uri qop cipher); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 0 | ▶ | sub _quote($$) { | ||||||||||||||||||||||||||
|
Subroutine
_quote: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 14 | 0 | shift; | |||||||||||||||||||||||||||
| 15 | 0 | my ($k, $v)=@_; | |||||||||||||||||||||||||||
| 16 | 0 | ▶ | return () unless defined $v; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 17 | 0 | ▶ | if ($quote{$k}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | 0 | $v =~ s/([\\"])/\\$1/g; | |||||||||||||||||||||||||||
| 19 | 0 | return qq|$k="$v"|; | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | 0 | "$k=$v"; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 0 | ▶ | sub _split { | ||||||||||||||||||||||||||
|
Subroutine
_split: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 25 | 0 | shift; | |||||||||||||||||||||||||||
| 26 | 0 | my $str=shift; | |||||||||||||||||||||||||||
| 27 | 0 | my %pair; | |||||||||||||||||||||||||||
| 28 | 0 | ▶ | while ($str=~/\G\s*([\w\-]+)\s*=\s*("([^\\"]+|\\.)*"|[^,]+)\s*(?:,|$)/g) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 0 | $pair{$1}=$2; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | 0 | my ($k, $v); | |||||||||||||||||||||||||||
| 32 | 0 | ▶ | while(($k, $v)=each %pair) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | if ($v=~/^"(.*)"$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 0 | $v=$1; | |||||||||||||||||||||||||||
| 35 | 0 | $v=~s/\\(.)/$1/g; | |||||||||||||||||||||||||||
| 36 | 0 | $pair{$k}=$v; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | %pair | ||||||||||||||||||||||||||||
| 40 | 0 | } | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub _join { | ||||||||||||||||||||||||||
|
Subroutine
_join: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 43 | 0 | my $this=shift; | |||||||||||||||||||||||||||
| 44 | 0 | my %pair=@_; | |||||||||||||||||||||||||||
| 45 | 0 | delete $pair{password}; | |||||||||||||||||||||||||||
| 46 | 0 | join(',', map { $this->_quote($_, $pair{$_}) } sort keys %pair) | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 50 | 0 | my $class=shift; | |||||||||||||||||||||||||||
| 51 | 0 | ▶ | my $input=shift if @_ & 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | my $this={ @_ }; | |||||||||||||||||||||||||||
| 53 | 0 | bless $this, $class; | |||||||||||||||||||||||||||
| 54 | 0 | ▶ | $this->input($input) if defined $input; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | return $this; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub clone { | ||||||||||||||||||||||||||
|
Subroutine
clone: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 59 | 0 | my $this=shift; | |||||||||||||||||||||||||||
| 60 | 0 | my $clone={ %$this }; | |||||||||||||||||||||||||||
| 61 | 0 | bless $clone, ref($this); | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub _public { | ||||||||||||||||||||||||||
|
Subroutine
_public: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 65 | 0 | my $this=shift; | |||||||||||||||||||||||||||
| 66 | 0 | return grep /^[a-z]/i, keys(%$this); | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub input { | ||||||||||||||||||||||||||
|
Subroutine
input: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 70 | 0 | my ($this, $str)=@_; | |||||||||||||||||||||||||||
| 71 | 0 | ▶ | return unless defined $str; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 0 | $this->set($this->_split($str)); | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub output { | ||||||||||||||||||||||||||
|
Subroutine
output: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 76 | 0 | my $this=shift; | |||||||||||||||||||||||||||
| 77 | 0 | return $this->_join(map { $_, $this->{$_} } $this->_public); | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | sub set { | ||||||||||||||||||||||||||
|
Subroutine
set: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 81 | 0 | my $this=shift; | |||||||||||||||||||||||||||
| 82 | 0 | ▶ | while (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 0 | my $k=shift; | |||||||||||||||||||||||||||
| 84 | 0 | my $v=shift; | |||||||||||||||||||||||||||
| 85 | 0 | $this->{$k}=$v; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | sub get { | ||||||||||||||||||||||||||
|
Subroutine
get: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 90 | 0 | my $this=shift; | |||||||||||||||||||||||||||
| 91 | return wantarray | ||||||||||||||||||||||||||||
| 92 | 0 | ? (map { $this->{$_} } @_) | |||||||||||||||||||||||||||
| 93 | 0 | ▶ | : $this->{$_[0]}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub reset { | ||||||||||||||||||||||||||
|
Subroutine
reset: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 97 | 0 | my $this=shift; | |||||||||||||||||||||||||||
| 98 | 0 | for my $k ($this->_public) { | |||||||||||||||||||||||||||
| 99 | 0 | delete $this->{$k} | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | package Authen::DigestMD5::Request; | ||||||||||||||||||||||||||||
| 104 | 1 | our @ISA=qw(Authen::DigestMD5::Packet); | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 107 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | ▶ | sub auth_ok { | ||||||||||||||||||||||||||
|
Subroutine
auth_ok: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 110 | 0 | my $this=shift; | |||||||||||||||||||||||||||
| 111 | 0 | return defined $this->{rspauth}; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | package Authen::DigestMD5::Response; | ||||||||||||||||||||||||||||
| 115 | 1 | our @ISA=qw(Authen::DigestMD5::Packet); | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 118 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 1 | ▶ | use Digest::MD5 qw(md5_hex md5); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 121 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 124 | 0 | my $this=shift->SUPER::new(@_); | |||||||||||||||||||||||||||
| 125 | 0 | $this->{_nc}={}; | |||||||||||||||||||||||||||
| 126 | 0 | return $this; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 0 | ▶ | sub _public { | ||||||||||||||||||||||||||
|
Subroutine
_public: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 130 | 0 | my $this=shift; | |||||||||||||||||||||||||||
| 131 | 0 | ▶ | return grep { $_=~/^[a-z]/i and | ||||||||||||||||||||||||||
|
Condition0%0/3
$_ =~ /^[a-z]/i && $_ ne 'password'
MC/DC0%0/2
$_ =~ /^[a-z]/i && $_ ne 'password'
$_ =~ /^[a-z]/i
$_ ne 'password'
Truth table0%0/3
A && B
A= $_ =~ /^[a-z]/iB= $_ ne 'password'
| |||||||||||||||||||||||||||||
| 132 | $_ ne 'password' } keys(%$this); | ||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | ▶ | sub got_request { | ||||||||||||||||||||||||||
|
Subroutine
got_request: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 136 | 0 | my $this=shift; | |||||||||||||||||||||||||||
| 137 | 0 | my $req=shift; | |||||||||||||||||||||||||||
| 138 | # $this->{_r}=$req; | ||||||||||||||||||||||||||||
| 139 | 0 | for my $k (qw(nonce realm charset)) { | |||||||||||||||||||||||||||
| 140 | 0 | ▶ | $this->{$k}=$req->{$k} if exists $req->{$k}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | #$this->{nc}=sprintf("%08d", ++$this->{_nc}{$req->{nonce}}) | ||||||||||||||||||||||||||||
| 143 | # if exists $req->{nonce}; | ||||||||||||||||||||||||||||
| 144 | 0 | ▶ | if (exists $req->{qop}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 0 | my @qop=split(/\s*,\s*/, $req->{qop}); | |||||||||||||||||||||||||||
| 146 | 0 | ▶ | if (grep {$_ eq 'auth-int'} @qop) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 147 | 0 | $this->{qop}='auth-int' | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | 0 | elsif (grep {$_ eq 'auth'} @qop) { | |||||||||||||||||||||||||||
| 150 | 0 | $this->{qop}='auth' | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | 0 | else { croak "not supported qop found ($req->{qop})" } | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 0 | ▶ | sub add_digest { | ||||||||||||||||||||||||||
|
Subroutine
add_digest: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 157 | 0 | my $this=shift; | |||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 0 | $this->{cnonce}=md5_hex(join(':', time, rand, $$)); | |||||||||||||||||||||||||||
| 160 | # unless defined $this->{cnonce}; | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | $this->{nc}=sprintf("%08d", ++$this->{_nc}{$this->{nonce}}) | ||||||||||||||||||||||||||||
| 163 | 0 | ▶ | if exists $this->{nonce}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 0 | my %pair=((map { $_, $this->{$_} } $this->_public), @_); | |||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | my $A1=join (":", | ||||||||||||||||||||||||||||
| 168 | md5(join (":", @pair{qw(username realm password)}, )), | ||||||||||||||||||||||||||||
| 169 | 0 | @pair{qw(nonce cnonce)} ); | |||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 0 | my $A2 = "AUTHENTICATE:" . $pair{'digest-uri'}; | |||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | $A2 .= ":00000000000000000000000000000000" | ||||||||||||||||||||||||||||
| 174 | if (defined $pair{'qop'} and | ||||||||||||||||||||||||||||
| 175 | 0 | ▶ | $pair{'qop'} =~ /^auth-(conf|int)$/); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $pair{"qop"} and $pair{"qop"} =~ /^auth-(conf|int)$/
MC/DC0%0/2
defined $pair{"qop"} and $pair{"qop"} =~ /^auth-(conf|int)$/
defined $pair{"qop"}
$pair{"qop"} =~ /^auth-(conf|int)$/
Truth table0%0/3
A and B
A= defined $pair{"qop"}B= $pair{"qop"} =~ /^auth-(conf|int)$/
| |||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | $this->{response} = | ||||||||||||||||||||||||||||
| 178 | md5_hex(join (":", md5_hex($A1), | ||||||||||||||||||||||||||||
| 179 | 0 | @pair{qw(nonce nc cnonce qop)}, | |||||||||||||||||||||||||||
| 180 | md5_hex($A2)) ); | ||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 1 | 1; | |||||||||||||||||||||||||||
| 185 | __END__ | ||||||||||||||||||||||||||||