YMSG/CRAM.pm

filter: Statementstmt 91.7% 100 / 109 Branchbran 70.5% 24 / 34 Conditioncond 33.3% 3 / 9 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 100% 13 / 13 Podpod 0.0% 0 / 5 totaltotal 80.1% 141 / 176 CC 21 SCAR 22.7
CC
21
Cov
84%
get_response_strings
20.3
_md5_crypt
10.0
_to_yahoo_base64
2.0
CRAP 9.7
« YMSG/ChatRoomReceive.pm ↑ Summary YMSG/ChatRoomLogoff.pm »
1 package Net::YMSG::CRAM;
2  
3 2 ▶use Digest::MD5 qw(md5);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 $VERSION = '0.02';
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use constant MD5_CRYPT_MAGIC_STRING => '$1$';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use constant I_TO_A64 => './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12 sub new
13 1 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
14 1 my $class = shift;
15 1 bless {
16 challenge_string => '',
17 id => '',
18 password => '',
19 }, $class;
20 }
21  
22  
23 sub set_challenge_string
24 2 ▶{
Subroutine set_challenge_string: called CC=1 SCAR=0.0
Pod undocumented
25 2 my $self = shift;
26 2 $self->{challenge_string} = shift;
27 }
28  
29  
30 sub set_id
31 2 ▶{
Subroutine set_id: called CC=1 SCAR=0.0
Pod undocumented
32 2 my $self = shift;
33 2 $self->{id} = shift;
34 }
35  
36  
37 sub set_password
38 2 ▶{
Subroutine set_password: called CC=1 SCAR=0.0
Pod undocumented
39 2 my $self = shift;
40 2 $self->{password} = shift;
41 }
42  
43  
44 sub get_response_strings
45 2 ▶{
Subroutine get_response_strings: called CC=10 SCAR=30.1
Pod undocumented
46 2 my $self = shift;
47 2 my $id = $self->{id};
48 2 my $password = $self->{password};
49 2 my @challenge_string = split //, $self->{challenge_string};
50  
51 2 ▶ return undef unless scalar @challenge_string;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @challenge_string 0 2 2
52  
53  
54 2 my $password_hash = _to_yahoo_base64(md5($password));
55 2 my $crypt_hash = _to_yahoo_base64(md5(_md5_crypt($password, '_2S43d5f')));
56  
57 2 my $hash_string_p;
58 my $hash_string_c;
59  
60 2 my $sv = ord($challenge_string[15]) % 8;
61 2 ▶ if ($sv == 1 || $sv == 6) {
Branch: 5 branches
BranchTrueFalseTotal
if ($sv == 1 or $sv == 6) { } 1 1 2
elsif ($sv == 2 or $sv == 7) { } 1 0 1
elsif ($sv == 3) { } 0 0 0
elsif ($sv == 4) { } 0 0 0
elsif ($sv == 0 or $sv == 5) { } 0 0 0
Condition66%2/3
$sv == 1 or $sv == 6
l!l&&r!l&&!r
011
MC/DC50%1/2
$sv == 1 or $sv == 6
$sv == 1 $sv == 6
Truth table66%2/3
A or B
A= $sv == 1B= $sv == 6
ABresult
1X1
011
000
62 1 my $checksum = $challenge_string[ord($challenge_string[9]) % 16];
63 1 $hash_string_p = sprintf '%s%s%s%s',
64 $checksum, $id, join('', @challenge_string), $password_hash;
65 1 $hash_string_c = sprintf '%s%s%s%s',
66 $checksum, $id, join('', @challenge_string), $crypt_hash;
67 }
68 ▶ elsif ($sv == 2 || $sv == 7) {
Condition33%1/3
$sv == 2 or $sv == 7
l!l&&r!l&&!r
010
MC/DC0%0/2
$sv == 2 or $sv == 7
$sv == 2 $sv == 7
Truth table33%1/3
A or B
A= $sv == 2B= $sv == 7
ABresult
1X1
011
000
69 1 my $checksum = $challenge_string[ord($challenge_string[15]) % 16];
70 1 $hash_string_p = sprintf '%s%s%s%s',
71 $checksum, join('', @challenge_string), $password_hash, $id;
72 1 $hash_string_c = sprintf '%s%s%s%s',
73 $checksum, join('', @challenge_string), $crypt_hash, $id;
74 }
75 elsif ($sv == 3) {
76 0 my $checksum = $challenge_string[ord($challenge_string[1]) % 16];
77 0 $hash_string_p = sprintf '%s%s%s%s',
78 $checksum, $id, $password_hash, join('', @challenge_string);
79 0 $hash_string_c = sprintf '%s%s%s%s',
80 $checksum, $id, $crypt_hash, join('', @challenge_string);
81 }
82 elsif ($sv == 4) {
83 0 my $checksum = $challenge_string[ord($challenge_string[3]) % 16];
84 0 $hash_string_p = sprintf '%s%s%s%s',
85 $checksum, $password_hash, join('', @challenge_string), $id;
86 0 $hash_string_c = sprintf '%s%s%s%s',
87 $checksum, $crypt_hash, join('', @challenge_string), $id;
88 }
89 ▶ elsif ($sv == 0 || $sv == 5) {
Condition0%0/3
$sv == 0 or $sv == 5
l!l&&r!l&&!r
000
MC/DC0%0/2
$sv == 0 or $sv == 5
$sv == 0 $sv == 5
Truth table0%0/3
A or B
A= $sv == 0B= $sv == 5
ABresult
1X1
011
000
90 0 my $checksum = $challenge_string[ord($challenge_string[7]) % 16];
91 0 $hash_string_p = sprintf '%s%s%s%s',
92 $checksum, $password_hash, $id, join('', @challenge_string);
93 0 $hash_string_c = sprintf '%s%s%s%s',
94 $checksum, $crypt_hash, $id, join('', @challenge_string);
95 }
96  
97 2 my $result6 = _to_yahoo_base64(md5($hash_string_p));
98 2 my $result96 = _to_yahoo_base64(md5($hash_string_c));
99 2 return ($result6, $result96);
100 }
101  
102  
103 sub _to_yahoo_base64
104 8 ▶{
Subroutine _to_yahoo_base64: called CC=2 SCAR=7.0
105 8 pos($_[0]) = 0;
106  
107 8 my $res = join '', map( pack('u',$_)=~ /^.(\S*)/, ($_[0]=~/(.{1,45})/gs));
108 8 $res =~ tr{` -_}{AA-Za-z0-9\._};
109  
110 8 my $padding = (3 - length($_[0]) % 3) % 3;
111 8 ▶ $res =~ s/.{$padding}$/'-' x $padding/e if $padding;
Branch: 1 branch
BranchTrueFalseTotal
if $padding 8 0 8
112 8 return $res;
113 }
114  
115  
116 sub _to64
117 12 ▶{
Subroutine _to64: called CC=2 SCAR=6.9
118 12 my ($v, $n) = @_;
119 12 my $ret = '';
120 12 ▶ while (--$n >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$n >= 0) 44 12 56
121 44 $ret .= substr(I_TO_A64, $v & 0x3f, 1);
122 44 $v >>= 6;
123 }
124 12 $ret;
125 }
126  
127  
128 sub _md5_crypt
129 2 ▶{
Subroutine _md5_crypt: called CC=10 SCAR=23.0
130 2 my $pw = shift;
131 2 my $salt = shift;
132  
133 2 my $Magic = MD5_CRYPT_MAGIC_STRING;
134 2 $salt =~ s/^\Q$Magic//;
135 2 $salt =~ s/^(.*)\$.*$/$1/;
136 2 $salt = substr $salt, 0, 8;
137  
138 2 my $ctx = new Digest::MD5;
139 2 $ctx->add($pw);
140 2 $ctx->add($Magic);
141 2 $ctx->add($salt);
142  
143 2 my $final = new Digest::MD5;
144 2 $final->add($pw);
145 2 $final->add($salt);
146 2 $final->add($pw);
147 2 $final = $final->digest;
148  
149 2 ▶ for (my $pl = length($pw); $pl > 0; $pl -= 16) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pl > 0) 2 2 4
150 2 ▶ $ctx->add(substr($final, 0, $pl > 16 ? 16 : $pl));
Branch: 1 branch
BranchTrueFalseTotal
$pl > 16 ? : 0 2 2
151 }
152  
153  
154 2 ▶ for (my $i = length($pw); $i; $i >>= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i) 7 2 9
155 7 ▶ if ($i & 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i & 1) { } 3 4 7
156 3 $ctx->add(pack("C", 0));
157 } else {
158 4 $ctx->add(substr($pw, 0, 1));
159 }
160 }
161  
162 2 $final = $ctx->digest;
163  
164 2 ▶ for (my $i = 0; $i < 1000; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 1000) 2000 2 2002
165 2000 my $ctx1 = new Digest::MD5;
166 2000 ▶ if ($i & 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i & 1) { } 1000 1000 2000
167 1000 $ctx1->add($pw);
168 } else {
169 1000 $ctx1->add(substr($final, 0, 16));
170 }
171 2000 ▶ if ($i % 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i % 3) 1332 668 2000
172 1332 $ctx1->add($salt);
173 }
174 2000 ▶ if ($i % 7) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i % 7) 1714 286 2000
175 1714 $ctx1->add($pw);
176 }
177 2000 ▶ if ($i & 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i & 1) { } 1000 1000 2000
178 1000 $ctx1->add(substr($final, 0, 16));
179 } else {
180 1000 $ctx1->add($pw);
181 }
182 2000 $final = $ctx1->digest;
183 }
184  
185 2 my $passwd = '';
186 2 $passwd .= _to64(int(unpack("C", (substr($final, 0, 1))) << 16)
187 | int(unpack("C", (substr($final, 6, 1))) << 8)
188 | int(unpack("C", (substr($final, 12, 1)))), 4);
189 2 $passwd .= _to64(int(unpack("C", (substr($final, 1, 1))) << 16)
190 | int(unpack("C", (substr($final, 7, 1))) << 8)
191 | int(unpack("C", (substr($final, 13, 1)))), 4);
192 2 $passwd .= _to64(int(unpack("C", (substr($final, 2, 1))) << 16)
193 | int(unpack("C", (substr($final, 8, 1))) << 8)
194 | int(unpack("C", (substr($final, 14, 1)))), 4);
195 2 $passwd .= _to64(int(unpack("C", (substr($final, 3, 1))) << 16)
196 | int(unpack("C", (substr($final, 9, 1))) << 8)
197 | int(unpack("C", (substr($final, 15, 1)))), 4);
198 2 $passwd .= _to64(int(unpack("C", (substr($final, 4, 1))) << 16)
199 | int(unpack("C", (substr($final, 10, 1))) << 8)
200 | int(unpack("C", (substr($final, 5, 1)))), 4);
201 2 $passwd .= _to64(int(unpack("C", substr($final, 11, 1))), 2);
202  
203 2 return $Magic. $salt. '$'. $passwd;
204 }
205  
206  
207 2 1;
208 __END__
« YMSG/ChatRoomReceive.pm ↑ Summary YMSG/ChatRoomLogoff.pm »