line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Radius::Util; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
118724
|
use v5.10; |
|
7
|
|
|
|
|
34
|
|
4
|
7
|
|
|
7
|
|
32
|
use strict; |
|
7
|
|
|
|
|
29
|
|
|
7
|
|
|
|
|
220
|
|
5
|
7
|
|
|
7
|
|
37
|
use warnings; |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
175
|
|
6
|
7
|
|
|
7
|
|
28
|
use Digest::MD5 (); |
|
7
|
|
|
|
|
11
|
|
|
7
|
|
|
|
|
107
|
|
7
|
|
|
|
|
|
|
|
8
|
7
|
|
|
7
|
|
28
|
use Exporter qw(import); |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
2199
|
|
9
|
|
|
|
|
|
|
our @EXPORT_OK = qw(encrypt_pwd decrypt_pwd is_enum_type); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my %ENUM_TYPES = map { $_ => 1 } (qw(integer byte short signed)); |
12
|
|
|
|
|
|
|
|
13
|
40
|
100
|
|
40
|
0
|
4620
|
sub is_enum_type { $ENUM_TYPES{ $_[0] } ? 1 : 0 } |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $md5; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# encode User-Password attribute |
18
|
|
|
|
|
|
|
sub encrypt_pwd { |
19
|
5
|
|
|
5
|
0
|
589
|
my ($value, $secret, $authenticator) = @_; |
20
|
|
|
|
|
|
|
|
21
|
5
|
|
66
|
|
|
56
|
$md5 //= Digest::MD5->new; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# padding |
24
|
5
|
|
|
|
|
10
|
my $len = length($value); |
25
|
5
|
|
|
|
|
11
|
my $pad16 = $len % 16; |
26
|
5
|
50
|
|
|
|
68
|
$value .= "\x0" x (16 - $pad16) if($pad16); |
27
|
5
|
|
|
|
|
40
|
my @v = unpack('a16' x ( (16 + $len - $pad16) / 16), $value); |
28
|
|
|
|
|
|
|
|
29
|
5
|
|
|
|
|
9
|
my $ep = $authenticator; |
30
|
5
|
|
|
|
|
9
|
my @list = (); |
31
|
5
|
|
|
|
|
11
|
foreach my $p (@v) { |
32
|
5
|
|
|
|
|
23
|
$md5->add($secret, $ep); |
33
|
5
|
|
|
|
|
26
|
$ep = $p ^ $md5->digest(); |
34
|
5
|
|
|
|
|
12
|
push @list, $ep; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
5
|
|
|
|
|
22
|
return join('', @list); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# decrypt value of User-Password attribute |
41
|
|
|
|
|
|
|
sub decrypt_pwd { |
42
|
3
|
|
|
3
|
0
|
709
|
my ($value, $secret, $authenticator) = @_; |
43
|
|
|
|
|
|
|
|
44
|
3
|
|
33
|
|
|
10
|
$md5 //= Digest::MD5->new; |
45
|
|
|
|
|
|
|
|
46
|
3
|
|
|
|
|
28
|
my $p = $authenticator; |
47
|
3
|
|
|
|
|
14
|
my $result; |
48
|
3
|
|
|
|
|
16
|
for (my $i = 0; $i < length($value); $i += 16) { |
49
|
3
|
|
|
|
|
15
|
$md5->add($secret, $p); |
50
|
3
|
|
|
|
|
8
|
$p = substr($value, $i, 16); |
51
|
3
|
|
|
|
|
22
|
$result .= $p ^ $md5->digest(); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# clear padding |
55
|
3
|
|
|
|
|
22
|
$result =~ s/\000*$//; |
56
|
3
|
|
|
|
|
10
|
return $result; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |