line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- mode: cperl; tab-width: 8; indent-tabs-mode: nil; basic-offset: 2 -*- |
2
|
|
|
|
|
|
|
# vim:ts=8:sw=2:et:sta:sts=2 |
3
|
|
|
|
|
|
|
######### |
4
|
|
|
|
|
|
|
# Author: rmp |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package ClearPress::authenticator::session; |
7
|
1
|
|
|
1
|
|
949
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
40
|
|
8
|
1
|
|
|
1
|
|
8
|
use warnings; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
37
|
|
9
|
1
|
|
|
1
|
|
498
|
use Crypt::CBC; |
|
1
|
|
|
|
|
6069
|
|
|
1
|
|
|
|
|
47
|
|
10
|
1
|
|
|
1
|
|
11
|
use base qw(ClearPress::authenticator); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
546
|
|
11
|
1
|
|
|
1
|
|
423
|
use Readonly; |
|
1
|
|
|
|
|
4832
|
|
|
1
|
|
|
|
|
71
|
|
12
|
1
|
|
|
1
|
|
10
|
use Carp; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
78
|
|
13
|
1
|
|
|
1
|
|
9
|
use MIME::Base64 qw(encode_base64 decode_base64); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
76
|
|
14
|
1
|
|
|
1
|
|
547
|
use YAML::Tiny qw(Load Dump); |
|
1
|
|
|
|
|
7103
|
|
|
1
|
|
|
|
|
553
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = q[477.1.4]; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Readonly::Scalar our $KEY => q[topsecretkey]; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub authen_token { |
21
|
3
|
|
|
3
|
1
|
5971
|
my ($self, $token) = @_; |
22
|
|
|
|
|
|
|
|
23
|
3
|
|
|
|
|
14
|
return $self->decode_token($token); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub encode_token { |
27
|
1
|
|
|
1
|
1
|
13
|
my ($self, $user_hash) = @_; |
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
|
|
9
|
my $user_yaml = Dump($user_hash); |
30
|
1
|
|
|
|
|
291
|
my $encrypted = $self->cipher->encrypt($user_yaml); |
31
|
1
|
|
|
|
|
1479
|
my $encoded = encode_base64($encrypted); |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
5
|
return $encoded; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub decode_token { |
37
|
4
|
|
|
4
|
1
|
22
|
my ($self, $token) = @_; |
38
|
|
|
|
|
|
|
|
39
|
4
|
|
|
|
|
13
|
my $decoded = q[]; |
40
|
|
|
|
|
|
|
eval { |
41
|
4
|
|
|
|
|
31
|
$decoded = decode_base64($token); |
42
|
4
|
50
|
|
|
|
11
|
} or do { |
43
|
0
|
|
|
|
|
0
|
carp q[Failed to decode token]; |
44
|
0
|
|
|
|
|
0
|
return; |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
|
47
|
4
|
|
|
|
|
14
|
my $decrypted = q[]; |
48
|
|
|
|
|
|
|
eval { |
49
|
4
|
|
|
|
|
15
|
$decrypted = $self->cipher->decrypt($decoded); |
50
|
4
|
100
|
|
|
|
9
|
} or do { |
51
|
1
|
|
|
|
|
485
|
carp q[Failed to decrypt token]; |
52
|
1
|
|
|
|
|
136
|
return; |
53
|
|
|
|
|
|
|
}; |
54
|
|
|
|
|
|
|
|
55
|
3
|
|
|
|
|
1246
|
my $deyamled; |
56
|
|
|
|
|
|
|
eval { |
57
|
3
|
|
|
|
|
18
|
$deyamled = Load($decrypted); |
58
|
|
|
|
|
|
|
|
59
|
3
|
100
|
|
|
|
9
|
} or do { |
60
|
1
|
|
|
|
|
511
|
carp q[Failed to de-YAML token]; |
61
|
1
|
|
|
|
|
124
|
return; |
62
|
|
|
|
|
|
|
}; |
63
|
|
|
|
|
|
|
|
64
|
2
|
|
|
|
|
813
|
return $deyamled; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub key { |
68
|
8
|
|
|
8
|
1
|
38
|
my ($self, $key) = @_; |
69
|
|
|
|
|
|
|
|
70
|
8
|
100
|
|
|
|
27
|
if($key) { |
71
|
1
|
|
|
|
|
4
|
$self->{key} = $key; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
8
|
100
|
|
|
|
28
|
if($self->{key}) { |
75
|
3
|
|
|
|
|
15
|
return $self->{key}; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
5
|
|
|
|
|
38
|
return $KEY; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub cipher { |
82
|
8
|
|
|
8
|
1
|
669
|
my $self = shift; |
83
|
|
|
|
|
|
|
|
84
|
8
|
100
|
|
|
|
41
|
if(!$self->{cipher}) { |
85
|
4
|
|
|
|
|
14
|
$self->{cipher} = Crypt::CBC->new( |
86
|
|
|
|
|
|
|
-cipher => 'Blowfish', |
87
|
|
|
|
|
|
|
-key => $self->key, |
88
|
|
|
|
|
|
|
); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
8
|
|
|
|
|
2504
|
return $self->{cipher}; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
__END__ |