| 1 | package Crypt::Passphrase::System; | ||||||||||||||||||||||||||||
| 2 | 2 | $Crypt::Passphrase::System::VERSION = '0.024'; | |||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use parent 'Crypt::Passphrase::Encoder'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Crypt::Passphrase::Util::Crypt64 'encode_crypt64'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Carp 'croak'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | my @possibilities = ( | |||||||||||||||||||||||||||
| 13 | ['3' , '$3$' , 0, '$3$$8846f7eaee8fb117ad06bdd830b7586c'], | ||||||||||||||||||||||||||||
| 14 | ['', '' , 2, 'abJnggxhB/yWI' , '%s%s'], | ||||||||||||||||||||||||||||
| 15 | ['_', '_EQ0.' , 3, '_EQ0.jzhSVeUyoSqLupI', '%s%s'], | ||||||||||||||||||||||||||||
| 16 | ['1' , '$1$' , 6, '$1$aaaaaa$FuYJ957Lgsw.eVsENqOok1' ], | ||||||||||||||||||||||||||||
| 17 | ['md5', '$md5,rounds=5000$', 6, '$md5,rounds=5000$GUBv0xjJ$$PI9W.MLvhYh0hQMCkz1CH/', '%s%s$'], | ||||||||||||||||||||||||||||
| 18 | ['sha1', '$sha1$40000$' , 6, '$sha1$40000$jtNX3nZ2$hBNaIXkt4wBI2o5rsi8KejSjNqIq'], | ||||||||||||||||||||||||||||
| 19 | ['5' , '$5$rounds=535000$', 12, '$5$aaaaaa$9hHgJfCniK4.dU43ykArHVETrhKDDElbS.cioeCajw.' ], | ||||||||||||||||||||||||||||
| 20 | ['6' , '$6$rounds=656000$', 12, '$6$aaaaaa$RgJSheuY/DBadaBm/5gQ.s3M9a/2n8gubwCE41kMiz1P4KcxORD6LxY2NUCuOQNZawfiD8tWWfRKg9v0CQjbH0'], | ||||||||||||||||||||||||||||
| 21 | ['2x', '$2x$12$' , 16, '$2x$08$......................qrjEXaz4RUVmquy3IT5eLKXLB28ahI2' ], | ||||||||||||||||||||||||||||
| 22 | ['2a', '$2a$12$' , 16, '$2a$08$......................qrjEXaz4RUVmquy3IT5eLKXLB28ahI2' ], | ||||||||||||||||||||||||||||
| 23 | ['2y', '$2y$12$' , 16, '$2y$08$......................qrjEXaz4RUVmquy3IT5eLKXLB28ahI2' ], | ||||||||||||||||||||||||||||
| 24 | ['2b', '$2b$12$' , 16, '$2b$08$......................qrjEXaz4RUVmquy3IT5eLKXLB28ahI2' ], | ||||||||||||||||||||||||||||
| 25 | ['7' , '$7$DU..../....' , 16, '$7$AU..../....2Q9obwLhin8qvQl6sisAO/$E1HizYWxBmnIH4sdPkd1UOML9t62Gf.wvNTnt5XFzs8' ], | ||||||||||||||||||||||||||||
| 26 | ['gy', '$gy$j8T$' , 16, '$gy$j9T$......................$5.2XCu2DhNfGzpifM7X8goEG2Wkio9cWIMtyWnX4tp2' ], | ||||||||||||||||||||||||||||
| 27 | ['y' , '$y$j8T$' , 16, '$y$j9T$F5Jx5fExrKuPp53xLKQ..1$tnSYvahCwPBHKZUspmcxMfb0.WiB9W.zEaKlOBL35rC' ], | ||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 2 | my (%algorithm, $default); | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 2 | for my $row (@possibilities) { | |||||||||||||||||||||||||||
| 33 | 30 | my ($name, $setting, $salt_size, $value, $format) = @{$row}; | |||||||||||||||||||||||||||
| 34 | 30 | my $hash = eval { crypt 'password', $value }; | |||||||||||||||||||||||||||
| 35 | 30 | ▶ | if (defined $hash and $hash eq $value) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $hash and $hash eq $value
MC/DC0%0/2
defined $hash and $hash eq $value
defined $hash
$hash eq $value
Truth table33%1/3
A and B
A= defined $hashB= $hash eq $value
| |||||||||||||||||||||||||||||
| 36 | 30 | $algorithm{$name} = { settings => $setting, salt_size => $salt_size, format => $format }; | |||||||||||||||||||||||||||
| 37 | 30 | $default = $name; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 16 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=15 SCAR=42.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 42 | 16 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 16 | my ($settings, $salt_size, $format); | |||||||||||||||||||||||||||
| 45 | 16 | ▶ | if (defined($settings = $args{settings})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | if ($settings eq '') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 47 | 0 | ($salt_size, $format) = (2, '%s%s'); | |||||||||||||||||||||||||||
| 48 | } elsif ($settings eq '_') { | ||||||||||||||||||||||||||||
| 49 | 0 | ($salt_size, $format) = (3, '%s%s'); | |||||||||||||||||||||||||||
| 50 | } else { | ||||||||||||||||||||||||||||
| 51 | 0 | ▶ | my $type = $settings =~ /\A \$ ([^\$]+) \$ /x or croak "Invalid settings string '$settings'"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | $salt_size = $args{salt_size} // $algorithm{$type}{salt_size} // 16; | ||||||||||||||||||||||||||
|
Condition0%0/5
($args{"salt_size"} // $algorithm{$type}{"salt_size"}) // 16
$args{"salt_size"} // $algorithm{$type}{"salt_size"}
MC/DC0%0/2
($args{"salt_size"} // $algorithm{$type}{"salt_size"}) // 16
$args{"salt_size"}
$algorithm{$type}{"salt_size"}
Truth table0%0/3
A // B
A= $args{"salt_size"}B= $algorithm{$type}{"salt_size"}
| |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | $format = $args{format} // $algorithm{$type}{format} // '%s%s$'; | ||||||||||||||||||||||||||
|
Condition0%0/5
($args{"format"} // $algorithm{$type}{"format"}) // "%s%s\$"
$args{"format"} // $algorithm{$type}{"format"}
MC/DC0%0/2
($args{"format"} // $algorithm{$type}{"format"}) // "%s%s\$"
$args{"format"}
$algorithm{$type}{"format"}
Truth table0%0/3
A // B
A= $args{"format"}B= $algorithm{$type}{"format"}
| |||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | else { | ||||||||||||||||||||||||||||
| 57 | 16 | ▶ | my $type = $args{type} // $default // croak 'No known crypt type found'; | ||||||||||||||||||||||||||
|
Condition60%3/5
($args{"type"} // $default) // croak("No known crypt type found")
$args{"type"} // $default
MC/DC0%0/2
($args{"type"} // $default) // croak("No known crypt type found")
$args{"type"}
$default
Truth table66%2/3
A // B
A= $args{"type"}B= $default
| |||||||||||||||||||||||||||||
| 58 | 16 | ▶ | $settings = $algorithm{$type}{settings} // croak "No such crypt type '$type' known"; | ||||||||||||||||||||||||||
|
Condition50%1/2
$algorithm{$type}{"settings"} // croak("No such crypt type '${type}' known")
MC/DC0%0/1
$algorithm{$type}{"settings"} // croak("No such crypt type '${type}' known")
$algorithm{$type}{"settings"}
Truth table50%1/2
A
A= $algorithm{$type}{"settings"}
| |||||||||||||||||||||||||||||
| 59 | 16 | ▶ | $salt_size = $args{salt_size} // $algorithm{$type}{salt_size}; | ||||||||||||||||||||||||||
|
Condition33%1/3
$args{"salt_size"} // $algorithm{$type}{"salt_size"}
MC/DC0%0/2
$args{"salt_size"} // $algorithm{$type}{"salt_size"}
$args{"salt_size"}
$algorithm{$type}{"salt_size"}
Truth table33%1/3
A // B
A= $args{"salt_size"}B= $algorithm{$type}{"salt_size"}
| |||||||||||||||||||||||||||||
| 60 | 16 | ▶ | $format = $args{format} // $algorithm{$type}{format} // '%s%s$'; | ||||||||||||||||||||||||||
|
Condition80%4/5
($args{"format"} // $algorithm{$type}{"format"}) // "%s%s\$"
$args{"format"} // $algorithm{$type}{"format"}
MC/DC50%1/2
($args{"format"} // $algorithm{$type}{"format"}) // "%s%s\$"
$args{"format"}
$algorithm{$type}{"format"}
Truth table66%2/3
A // B
A= $args{"format"}B= $algorithm{$type}{"format"}
| |||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 16 | return bless { | |||||||||||||||||||||||||||
| 64 | settings => $settings, | ||||||||||||||||||||||||||||
| 65 | salt_size => $salt_size, | ||||||||||||||||||||||||||||
| 66 | format => $format, | ||||||||||||||||||||||||||||
| 67 | }, $class; | ||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 16 | ▶ | sub hash_password { | ||||||||||||||||||||||||||
|
Subroutine
hash_password: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 71 | 16 | my ($self, $password) = @_; | |||||||||||||||||||||||||||
| 72 | 16 | my $salt = $self->random_bytes($self->{salt_size}); | |||||||||||||||||||||||||||
| 73 | 16 | my $encoded_salt = encode_crypt64($salt); | |||||||||||||||||||||||||||
| 74 | 16 | ▶ | substr $encoded_salt, 2, 1, '' if $self->{salt_size} == 2; # descrypt | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 16 | my $settings = sprintf $self->{format}, $self->{settings}, $encoded_salt; | |||||||||||||||||||||||||||
| 77 | 16 | return crypt $password, $settings; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 2 | my $descrypt = qr{ \A [./0-9A-Za-z]{13} \z }x; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 2 | my @formats; | |||||||||||||||||||||||||||
| 83 | 2 | ▶ | push @formats, $descrypt if $algorithm{''}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 2 | ▶ | push @formats, qr{ \A _[./0-9A-Za-z]{19} \z }x if $algorithm{'_'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 20 | ▶ | sub accepts_hash { | ||||||||||||||||||||||||||
|
Subroutine
accepts_hash: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | 20 | my ($self, $hash) = @_; | |||||||||||||||||||||||||||
| 88 | 20 | ▶ | return 1 if $self->SUPER::accepts_hash($hash); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 3 | for my $format (@formats) { | |||||||||||||||||||||||||||
| 90 | 4 | ▶ | return 1 if $hash =~ $format; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | 0 | return 0; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 18 | ▶ | sub crypt_subtypes { | ||||||||||||||||||||||||||
|
Subroutine
crypt_subtypes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 96 | 18 | return sort keys %algorithm; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 16 | ▶ | sub needs_rehash { | ||||||||||||||||||||||||||
|
Subroutine
needs_rehash: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 100 | 16 | my ($self, $hash) = @_; | |||||||||||||||||||||||||||
| 101 | 16 | ▶ | return length $self->{settings} ? substr($hash, 0, length $self->{settings}) ne $self->{settings} : $hash !~ $descrypt; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 20 | ▶ | sub verify_password { | ||||||||||||||||||||||||||
|
Subroutine
verify_password: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 105 | 20 | my ($class, $password, $hash) = @_; | |||||||||||||||||||||||||||
| 106 | 20 | my $new_hash = crypt $password, $hash; | |||||||||||||||||||||||||||
| 107 | 20 | return $class->secure_compare($hash, $new_hash); | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | #ABSTRACT: An system crypt() encoder for Crypt::Passphrase | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 2 | 1; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | __END__ | ||||||||||||||||||||||||||||