line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::OATH::Crypt::Rijndael; |
2
|
|
|
|
|
|
|
our $VERSION = '1.20150914'; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
6
|
1
|
|
|
1
|
|
4
|
use Convert::Base32; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
55
|
|
7
|
1
|
|
|
1
|
|
616
|
use Crypt::Rijndael; |
|
1
|
|
|
|
|
408
|
|
|
1
|
|
|
|
|
28
|
|
8
|
1
|
|
|
1
|
|
5
|
use Digest::MD5; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
9
|
1
|
|
|
1
|
|
748
|
use String::Random qw{ random_string }; |
|
1
|
|
|
|
|
2914
|
|
|
1
|
|
|
|
|
370
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
9
|
|
|
9
|
1
|
16
|
my ( $class, $args ) = @_; |
13
|
|
|
|
|
|
|
my $self = { |
14
|
9
|
|
|
|
|
29
|
'password' => $args->{'password'}, |
15
|
|
|
|
|
|
|
'check' => 'oath', |
16
|
|
|
|
|
|
|
}; |
17
|
9
|
|
|
|
|
15
|
bless $self, $class; |
18
|
9
|
|
|
|
|
66
|
return $self; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub _get_crypt_object { |
22
|
6
|
|
|
6
|
|
8
|
my ( $self ) = @_; |
23
|
6
|
|
|
|
|
14
|
my $password = $self->{'password'}; |
24
|
|
|
|
|
|
|
|
25
|
6
|
|
|
|
|
24
|
my $md5 = Digest::MD5->new(); |
26
|
6
|
|
|
|
|
17
|
$md5->add( $password ); |
27
|
6
|
|
|
|
|
19
|
my $crypt_key = $md5->digest(); |
28
|
|
|
|
|
|
|
|
29
|
6
|
|
|
|
|
50
|
my $crypt = Crypt::Rijndael->new( $crypt_key, Crypt::Rijndael::MODE_CBC() ); |
30
|
6
|
|
|
|
|
24
|
return $crypt; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub encrypt { |
34
|
2
|
|
|
2
|
1
|
3
|
my ( $self, $data ) = @_; |
35
|
2
|
|
|
|
|
8
|
my $worker = $self->_get_crypt_object(); |
36
|
2
|
|
|
|
|
6
|
my $u = random_string( '..........' ) . ' ' . $self->{'check'} . ' ' . $data; |
37
|
2
|
|
|
|
|
205
|
my $pad = random_string( '.' x ( 16 - ( length( $u ) % 16 ) ) ); |
38
|
|
|
|
|
|
|
|
39
|
2
|
|
|
|
|
122
|
my $e = $worker->encrypt( $pad . $u ); |
40
|
2
|
|
|
|
|
7
|
$e = encode_base32( $e ); |
41
|
2
|
|
|
|
|
111
|
return $e; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub decrypt { |
45
|
4
|
|
|
4
|
1
|
6
|
my ( $self, $data ) = @_; |
46
|
4
|
|
|
|
|
10
|
my $worker = $self->_get_crypt_object(); |
47
|
4
|
|
|
|
|
13
|
my $e = decode_base32( $data ); |
48
|
3
|
|
|
|
|
98
|
my $u = $worker->decrypt($e); |
49
|
3
|
|
|
|
|
9
|
my ( $salt, $check, $payload ) = split( ' ', $u ); |
50
|
3
|
50
|
|
|
|
9
|
$check = q{} if ! $check; |
51
|
3
|
100
|
|
|
|
8
|
if ( $check ne $self->{'check'} ) { |
52
|
1
|
|
|
|
|
4
|
return; |
53
|
|
|
|
|
|
|
} |
54
|
2
|
|
|
|
|
10
|
return $payload; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__END__ |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 NAME |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
App::OATH::Crypt::Rijndael - Crypto modules for Simple OATH authenticator |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 DESCRIPTION |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Crypto modules for basic Rijndael |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 SYNOPSIS |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Handles encryption and decryption for the basic Rijndael (not CBC) 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::Rijndael |
95
|
|
|
|
|
|
|
Digest::MD5 |
96
|
|
|
|
|
|
|
String::Random |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 AUTHORS |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Marc Bradshaw E<lt>marc@marcbradshaw.netE<gt> |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 COPYRIGHT |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Copyright 2015 |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
This library is free software; you may redistribute it and/or |
107
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|