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
|
|
527
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
8
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
9
|
1
|
|
|
1
|
|
329
|
use Crypt::CBC; |
|
1
|
|
|
|
|
3338
|
|
|
1
|
|
|
|
|
27
|
|
10
|
1
|
|
|
1
|
|
7
|
use base qw(ClearPress::authenticator); |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
313
|
|
11
|
1
|
|
|
1
|
|
296
|
use Readonly; |
|
1
|
|
|
|
|
3170
|
|
|
1
|
|
|
|
|
43
|
|
12
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
13
|
1
|
|
|
1
|
|
5
|
use MIME::Base64 qw(encode_base64 decode_base64); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
14
|
1
|
|
|
1
|
|
343
|
use YAML::Tiny qw(Load Dump); |
|
1
|
|
|
|
|
3974
|
|
|
1
|
|
|
|
|
310
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = q[476.4.2]; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Readonly::Scalar our $KEY => q[topsecretkey]; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub authen_token { |
21
|
3
|
|
|
3
|
1
|
5138
|
my ($self, $token) = @_; |
22
|
|
|
|
|
|
|
|
23
|
3
|
|
|
|
|
17
|
return $self->decode_token($token); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub encode_token { |
27
|
1
|
|
|
1
|
1
|
8
|
my ($self, $user_hash) = @_; |
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
|
|
4
|
my $user_yaml = Dump($user_hash); |
30
|
1
|
|
|
|
|
138
|
my $encrypted = $self->cipher->encrypt($user_yaml); |
31
|
1
|
|
|
|
|
825
|
my $encoded = encode_base64($encrypted); |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
3
|
return $encoded; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub decode_token { |
37
|
4
|
|
|
4
|
1
|
12
|
my ($self, $token) = @_; |
38
|
|
|
|
|
|
|
|
39
|
4
|
|
|
|
|
8
|
my $decoded = q[]; |
40
|
|
|
|
|
|
|
eval { |
41
|
4
|
|
|
|
|
23
|
$decoded = decode_base64($token); |
42
|
4
|
50
|
|
|
|
8
|
} or do { |
43
|
0
|
|
|
|
|
0
|
carp q[Failed to decode token]; |
44
|
0
|
|
|
|
|
0
|
return; |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
|
47
|
4
|
|
|
|
|
9
|
my $decrypted = q[]; |
48
|
|
|
|
|
|
|
eval { |
49
|
4
|
|
|
|
|
10
|
$decrypted = $self->cipher->decrypt($decoded); |
50
|
4
|
100
|
|
|
|
7
|
} or do { |
51
|
1
|
|
|
|
|
437
|
carp q[Failed to decrypt token]; |
52
|
1
|
|
|
|
|
131
|
return; |
53
|
|
|
|
|
|
|
}; |
54
|
|
|
|
|
|
|
|
55
|
3
|
|
|
|
|
856
|
my $deyamled; |
56
|
|
|
|
|
|
|
eval { |
57
|
3
|
|
|
|
|
9
|
$deyamled = Load($decrypted); |
58
|
|
|
|
|
|
|
|
59
|
3
|
100
|
|
|
|
7
|
} or do { |
60
|
1
|
|
|
|
|
283
|
carp q[Failed to de-YAML token]; |
61
|
1
|
|
|
|
|
107
|
return; |
62
|
|
|
|
|
|
|
}; |
63
|
|
|
|
|
|
|
|
64
|
2
|
|
|
|
|
519
|
return $deyamled; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub key { |
68
|
8
|
|
|
8
|
1
|
25
|
my ($self, $key) = @_; |
69
|
|
|
|
|
|
|
|
70
|
8
|
100
|
|
|
|
18
|
if($key) { |
71
|
1
|
|
|
|
|
2
|
$self->{key} = $key; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
8
|
100
|
|
|
|
19
|
if($self->{key}) { |
75
|
3
|
|
|
|
|
8
|
return $self->{key}; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
5
|
|
|
|
|
28
|
return $KEY; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub cipher { |
82
|
8
|
|
|
8
|
1
|
323
|
my $self = shift; |
83
|
|
|
|
|
|
|
|
84
|
8
|
100
|
|
|
|
28
|
if(!$self->{cipher}) { |
85
|
4
|
|
|
|
|
13
|
$self->{cipher} = Crypt::CBC->new( |
86
|
|
|
|
|
|
|
-cipher => 'Blowfish', |
87
|
|
|
|
|
|
|
-key => $self->key, |
88
|
|
|
|
|
|
|
); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
8
|
|
|
|
|
1496
|
return $self->{cipher}; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
__END__ |