line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::Passphrase::System; |
2
|
|
|
|
|
|
|
$Crypt::Passphrase::System::VERSION = '0.015'; |
3
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use Crypt::Passphrase -encoder; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
15
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
7
|
use Carp 'croak'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
52
|
|
9
|
1
|
|
|
1
|
|
450
|
use MIME::Base64 qw/encode_base64/; |
|
1
|
|
|
|
|
594
|
|
|
1
|
|
|
|
|
782
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my @possibilities = ( |
12
|
|
|
|
|
|
|
[1 , '$1$' , 6, '$1$aaaaaa$FuYJ957Lgsw.eVsENqOok1' ], |
13
|
|
|
|
|
|
|
[5 , '$5$rounds=535000$', 12, '$5$aaaaaa$9hHgJfCniK4.dU43ykArHVETrhKDDElbS.cioeCajw.' ], |
14
|
|
|
|
|
|
|
[6 , '$6$rounds=656000$', 12, '$6$aaaaaa$RgJSheuY/DBadaBm/5gQ.s3M9a/2n8gubwCE41kMiz1P4KcxORD6LxY2NUCuOQNZawfiD8tWWfRKg9v0CQjbH0'], |
15
|
|
|
|
|
|
|
['2x', '$2x$12$' , 16, '$2x$08$......................qrjEXaz4RUVmquy3IT5eLKXLB28ahI2' ], |
16
|
|
|
|
|
|
|
['2a', '$2a$12$' , 16, '$2a$08$......................qrjEXaz4RUVmquy3IT5eLKXLB28ahI2' ], |
17
|
|
|
|
|
|
|
['2y', '$2y$12$' , 16, '$2y$08$......................qrjEXaz4RUVmquy3IT5eLKXLB28ahI2' ], |
18
|
|
|
|
|
|
|
['2b', '$2b$12$' , 16, '$2b$08$......................qrjEXaz4RUVmquy3IT5eLKXLB28ahI2' ], |
19
|
|
|
|
|
|
|
[7 , '$7$DU..../....' , 16, '$7$AU..../....2Q9obwLhin8qvQl6sisAO/$E1HizYWxBmnIH4sdPkd1UOML9t62Gf.wvNTnt5XFzs8' ], |
20
|
|
|
|
|
|
|
['gy', '$gy$j8T$' , 18, '$gy$j9T$......................$5.2XCu2DhNfGzpifM7X8goEG2Wkio9cWIMtyWnX4tp2' ], |
21
|
|
|
|
|
|
|
['y' , '$y$j8T$' , 18, '$y$j9T$F5Jx5fExrKuPp53xLKQ..1$tnSYvahCwPBHKZUspmcxMfb0.WiB9W.zEaKlOBL35rC' ], |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my (%algorithm, %salt_for, $default); |
25
|
|
|
|
|
|
|
for my $row (@possibilities) { |
26
|
|
|
|
|
|
|
my ($name, $setting, $salt_size, $value) = @{$row}; |
27
|
|
|
|
|
|
|
my $hash = eval { crypt('password', $value) }; |
28
|
|
|
|
|
|
|
if (defined $hash and $hash eq $value) { |
29
|
|
|
|
|
|
|
$algorithm{$name} = { settings => $setting, salt_size => $salt_size }; |
30
|
|
|
|
|
|
|
$default = $name; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _get_parameters { |
35
|
1
|
|
|
1
|
|
3
|
my %args = @_; |
36
|
|
|
|
|
|
|
|
37
|
1
|
50
|
33
|
|
|
8
|
if (defined(my $settings = $args{settings})) { |
|
|
50
|
|
|
|
|
|
38
|
0
|
0
|
|
|
|
0
|
return ('', 2) if $settings eq ''; |
39
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
0
|
my ($type) = $settings =~ /\A \$ ([^\$]+) \$ /x or croak "Invalid settings string '$settings'"; |
41
|
0
|
0
|
|
|
|
0
|
croak "Unsupported algorithm $type" if not $algorithm{$type}; |
42
|
0
|
|
0
|
|
|
0
|
return ($settings, $args{salt_size} // $algorithm{$type}{salt_size}); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
elsif (my $type = $args{type} // $default) { |
45
|
1
|
|
33
|
|
|
4
|
$settings = $algorithm{$type}{settings} // croak "No such crypt type $type known"; |
46
|
1
|
|
33
|
|
|
8
|
return ($settings, $args{salt_size} // $algorithm{$type}{salt_size}); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
else { |
49
|
0
|
|
|
|
|
0
|
return ('', 2); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub new { |
54
|
1
|
|
|
1
|
1
|
6
|
my ($class, %args) = @_; |
55
|
|
|
|
|
|
|
|
56
|
1
|
|
|
|
|
5
|
my ($settings, $salt_size) = _get_parameters(%args); |
57
|
1
|
|
|
|
|
7
|
return bless { |
58
|
|
|
|
|
|
|
settings => $settings, |
59
|
|
|
|
|
|
|
salt_size => $salt_size, |
60
|
|
|
|
|
|
|
}, $class; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub hash_password { |
64
|
1
|
|
|
1
|
1
|
3
|
my ($self, $password) = @_; |
65
|
1
|
|
|
|
|
11
|
my $salt = $self->random_bytes($self->{salt_size}); |
66
|
1
|
|
|
|
|
10615
|
my $encoded_salt = encode_base64($salt, "") =~ tr{A-Za-z0-9+/=}{./0-9A-Za-z}dr; |
67
|
1
|
|
|
|
|
655050
|
return crypt($password, "$self->{settings}$encoded_salt\$"); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my $descrypt = qr{ \A [./0-9A-Za-z]{13} \z }x; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub accepts_hash { |
73
|
3
|
|
|
3
|
1
|
9
|
my ($self, $hash) = @_; |
74
|
3
|
|
66
|
|
|
84
|
return $hash =~ $descrypt || $self->SUPER::accepts_hash($hash); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub crypt_subtypes { |
78
|
2
|
|
|
2
|
1
|
36
|
return sort keys %algorithm; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub needs_rehash { |
82
|
1
|
|
|
1
|
1
|
3
|
my ($self, $hash) = @_; |
83
|
1
|
50
|
|
|
|
12
|
return length $self->{settings} ? substr($hash, 0, length $self->{settings}) ne $self->{settings} : $hash !~ $descrypt; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub verify_password { |
87
|
3
|
|
|
3
|
1
|
9
|
my ($class, $password, $hash) = @_; |
88
|
3
|
|
|
|
|
755246
|
my $new_hash = crypt($password, $hash); |
89
|
3
|
|
|
|
|
73
|
return $class->secure_compare($hash, $new_hash); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
#ABSTRACT: An system crypt() encoder for Crypt::Passphrase |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |