line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Raps2::Password; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
949
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
73
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
50
|
|
5
|
2
|
|
|
2
|
|
110
|
use 5.010; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
224
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
12
|
use Carp 'confess'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
312
|
|
8
|
2
|
|
|
2
|
|
2577
|
use Crypt::CBC; |
|
2
|
|
|
|
|
26780
|
|
|
2
|
|
|
|
|
97
|
|
9
|
2
|
|
|
2
|
|
11122
|
use Crypt::Eksblowfish; |
|
2
|
|
|
|
|
12886
|
|
|
2
|
|
|
|
|
157
|
|
10
|
2
|
|
|
2
|
|
2449
|
use Crypt::Eksblowfish::Bcrypt qw(bcrypt_hash en_base64 de_base64); |
|
2
|
|
|
|
|
8655
|
|
|
2
|
|
|
|
|
1842
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.53'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
8
|
|
|
8
|
1
|
5943
|
my ( $obj, %conf ) = @_; |
16
|
|
|
|
|
|
|
|
17
|
8
|
|
100
|
|
|
44
|
$conf{cost} //= 12; |
18
|
|
|
|
|
|
|
|
19
|
8
|
100
|
|
|
|
23
|
if ( not defined $conf{salt} ) { |
20
|
2
|
|
|
|
|
10
|
$conf{salt} = create_salt(); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
8
|
100
|
|
|
|
204
|
if ( length( $conf{salt} ) != 16 ) { |
24
|
2
|
|
|
|
|
1195
|
confess('incorrect salt length'); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
6
|
100
|
100
|
|
|
36
|
if ( not( defined $conf{passphrase} and length $conf{passphrase} ) ) { |
28
|
2
|
|
|
|
|
1135
|
confess('no passphrase given'); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
4
|
|
|
|
|
8
|
my $ref = \%conf; |
32
|
|
|
|
|
|
|
|
33
|
4
|
|
|
|
|
21
|
return bless( $ref, $obj ); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub create_salt { |
37
|
4
|
|
|
4
|
1
|
10
|
my ($self) = @_; |
38
|
4
|
|
|
|
|
8
|
my $salt = q{}; |
39
|
|
|
|
|
|
|
|
40
|
4
|
|
|
|
|
13
|
for ( 1 .. 16 ) { |
41
|
64
|
|
|
|
|
223
|
$salt .= chr( 0x21 + int( rand(90) ) ); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
4
|
|
|
|
|
19
|
return $salt; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub salt { |
48
|
6
|
|
|
6
|
1
|
4202
|
my ( $self, $salt ) = @_; |
49
|
|
|
|
|
|
|
|
50
|
6
|
100
|
|
|
|
25
|
if ( defined $salt ) { |
51
|
4
|
100
|
|
|
|
15
|
if ( length($salt) != 16 ) { |
52
|
3
|
|
|
|
|
496
|
confess('incorrect salt length'); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
1
|
|
|
|
|
4
|
$self->{salt} = $salt; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
3
|
|
|
|
|
17
|
return $self->{salt}; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub encrypt { |
62
|
4
|
|
|
4
|
1
|
1103
|
my ( $self, %opt ) = @_; |
63
|
|
|
|
|
|
|
|
64
|
4
|
|
66
|
|
|
26
|
$opt{salt} //= $self->{salt}; |
65
|
4
|
|
66
|
|
|
21
|
$opt{cost} //= $self->{cost}; |
66
|
|
|
|
|
|
|
|
67
|
4
|
|
|
|
|
1559857
|
my $eksblowfish |
68
|
|
|
|
|
|
|
= Crypt::Eksblowfish->new( $opt{cost}, $opt{salt}, $self->{passphrase}, ); |
69
|
4
|
|
|
|
|
93
|
my $cbc = Crypt::CBC->new( -cipher => $eksblowfish ); |
70
|
|
|
|
|
|
|
|
71
|
4
|
|
|
|
|
721
|
return $cbc->encrypt_hex( $opt{data} ); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub decrypt { |
75
|
7
|
|
|
7
|
1
|
2072
|
my ( $self, %opt ) = @_; |
76
|
|
|
|
|
|
|
|
77
|
7
|
|
66
|
|
|
43
|
$opt{cost} //= $self->{cost}; |
78
|
7
|
|
66
|
|
|
77
|
$opt{salt} //= $self->{salt}; |
79
|
|
|
|
|
|
|
|
80
|
7
|
|
|
|
|
2810676
|
my $eksblowfish |
81
|
|
|
|
|
|
|
= Crypt::Eksblowfish->new( $opt{cost}, $opt{salt}, $self->{passphrase}, ); |
82
|
7
|
|
|
|
|
155
|
my $cbc = Crypt::CBC->new( -cipher => $eksblowfish ); |
83
|
|
|
|
|
|
|
|
84
|
7
|
|
|
|
|
1255
|
return $cbc->decrypt_hex( $opt{data} ); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub bcrypt { |
88
|
6
|
|
|
6
|
1
|
1279
|
my ($self) = @_; |
89
|
|
|
|
|
|
|
|
90
|
6
|
|
|
|
|
192
|
return en_base64( |
91
|
|
|
|
|
|
|
bcrypt_hash( |
92
|
|
|
|
|
|
|
{ |
93
|
|
|
|
|
|
|
key_nul => 1, |
94
|
|
|
|
|
|
|
cost => $self->{cost}, |
95
|
|
|
|
|
|
|
salt => $self->{salt}, |
96
|
|
|
|
|
|
|
}, |
97
|
|
|
|
|
|
|
$self->{passphrase}, |
98
|
|
|
|
|
|
|
) |
99
|
|
|
|
|
|
|
); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub verify { |
103
|
4
|
|
|
4
|
1
|
38898
|
my ( $self, $testhash ) = @_; |
104
|
|
|
|
|
|
|
|
105
|
4
|
|
|
|
|
19
|
my $myhash = $self->bcrypt(); |
106
|
|
|
|
|
|
|
|
107
|
4
|
100
|
|
|
|
582358
|
if ( $testhash eq $myhash ) { |
108
|
3
|
|
|
|
|
29
|
return 1; |
109
|
|
|
|
|
|
|
} |
110
|
1
|
|
|
|
|
240
|
confess('Passwords did not match'); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
__END__ |