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