| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::OATH::Crypt::CBC; |
|
2
|
|
|
|
|
|
|
our $VERSION = '1.20150914'; |
|
3
|
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
22
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
22
|
|
|
6
|
1
|
|
|
1
|
|
4
|
use Convert::Base32; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
41
|
|
|
7
|
1
|
|
|
1
|
|
795
|
use Crypt::CBC; |
|
|
1
|
|
|
|
|
4019
|
|
|
|
1
|
|
|
|
|
27
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use Digest::MD5; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
38
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use String::Random qw{ random_string }; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
399
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
|
12
|
18
|
|
|
18
|
1
|
23
|
my ( $class, $args ) = @_; |
|
13
|
|
|
|
|
|
|
my $self = { |
|
14
|
|
|
|
|
|
|
'password' => $args->{'password'}, |
|
15
|
18
|
|
|
|
|
51
|
'type' => $args->{'type'}, |
|
16
|
|
|
|
|
|
|
'check' => 'oath', |
|
17
|
|
|
|
|
|
|
}; |
|
18
|
18
|
|
|
|
|
30
|
bless $self, $class; |
|
19
|
18
|
|
|
|
|
85
|
return $self; |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _get_crypt_object { |
|
23
|
21
|
|
|
21
|
|
25
|
my ( $self ) = @_; |
|
24
|
21
|
|
|
|
|
32
|
my $password = $self->{'password'}; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $crypt = Crypt::CBC->new({ |
|
27
|
|
|
|
|
|
|
'key' => $password, |
|
28
|
21
|
|
|
|
|
125
|
'cipher' => $self->{'type'}, |
|
29
|
|
|
|
|
|
|
'salt' => 1, |
|
30
|
|
|
|
|
|
|
}); |
|
31
|
21
|
|
|
|
|
3611
|
return $crypt; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub encrypt { |
|
35
|
8
|
|
|
8
|
1
|
9
|
my ( $self, $data ) = @_; |
|
36
|
8
|
|
|
|
|
20
|
my $worker = $self->_get_crypt_object(); |
|
37
|
8
|
|
|
|
|
25
|
my $u = random_string( '..........' ) . ' ' . $self->{'check'} . ' ' . $data; |
|
38
|
|
|
|
|
|
|
|
|
39
|
8
|
|
|
|
|
770
|
my $e = $worker->encrypt( $u ); |
|
40
|
8
|
|
|
|
|
9541
|
$e = encode_base32( $e ); |
|
41
|
8
|
|
|
|
|
17677
|
return $e; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub decrypt { |
|
45
|
13
|
|
|
13
|
1
|
21
|
my ( $self, $data ) = @_; |
|
46
|
13
|
|
|
|
|
23
|
my $worker = $self->_get_crypt_object(); |
|
47
|
13
|
|
|
|
|
33
|
my $e = decode_base32( $data ); |
|
48
|
11
|
|
|
|
|
406
|
my $u = $worker->decrypt($e); |
|
49
|
11
|
|
|
|
|
1744
|
my ( $salt, $check, $payload ) = split( ' ', $u ); |
|
50
|
11
|
50
|
|
|
|
25
|
$check = q{} if ! $check; |
|
51
|
11
|
100
|
|
|
|
26
|
if ( $check ne $self->{'check'} ) { |
|
52
|
3
|
|
|
|
|
21
|
return; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
8
|
|
|
|
|
54
|
return $payload; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__END__ |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 NAME |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
App::OATH::Crypt::CBC - Crypto modules for Simple OATH authenticator |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Crypto modules for CBC methods, this includes Rijndael and Blowfish |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Handles encryption and decryption for CBC Rijndael and Blowfish ciphers |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 METHODS |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=over |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=item I<new()> |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Instantiate a new object |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=item I<encrypt($data)> |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Encrypt the given data |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item I<decrypt($data)> |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Decrypt the given data |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=back |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Convert::Base32 |
|
94
|
|
|
|
|
|
|
Crypt::Blowfish |
|
95
|
|
|
|
|
|
|
Crypt::CBC |
|
96
|
|
|
|
|
|
|
Crypt::Rijndael |
|
97
|
|
|
|
|
|
|
Digest::MD5 |
|
98
|
|
|
|
|
|
|
String::Random |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 AUTHORS |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Marc Bradshaw E<lt>marc@marcbradshaw.netE<gt> |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Copyright 2015 |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
This library is free software; you may redistribute it and/or |
|
109
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|