| 1 | package Apache2::Authen::Passphrase; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use 5.014000; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use parent qw/Exporter/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use subs qw/OK HTTP_UNAUTHORIZED/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 1 | our $VERSION = 0.002002; | |||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 1 | ▶ | use constant USER_REGEX => qr/^\w{2,20}$/pas; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 1 | ▶ | use constant PASSPHRASE_VERSION => 1; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 1 | ▶ | use constant INVALID_USER => "invalid-user\n"; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 1 | ▶ | use constant BAD_PASSWORD => "bad-password\n"; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 1 | ▶ | use if $ENV{MOD_PERL}, 'Apache2::RequestRec'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | 1 | ▶ | use if $ENV{MOD_PERL}, 'Apache2::RequestUtil'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 18 | 1 | ▶ | use if $ENV{MOD_PERL}, 'Apache2::Access'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | 1 | ▶ | use if $ENV{MOD_PERL}, 'Apache2::Const' => qw/OK HTTP_UNAUTHORIZED/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | 1 | ▶ | use Authen::Passphrase; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 21 | 1 | ▶ | use Authen::Passphrase::BlowfishCrypt; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 22 | 1 | ▶ | use YAML::Any qw/LoadFile DumpFile/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 1 | our @EXPORT_OK = qw/pwset pwcheck pwhash USER_REGEX PASSPHRASE_VERSION INVALID_USER BAD_PASSWORD/; | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | ################################################## | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 1 | our $rootdir; | |||||||||||||||||||
| 29 | 1 | ▶ | $rootdir //= $ENV{AAP_ROOTDIR}; | ||||||||||||||||||
|
Condition33%1/3
$rootdir //= $ENV{"AAP_ROOTDIR"}
MC/DC0%0/2
$rootdir //= $ENV{"AAP_ROOTDIR"}
$rootdir
$ENV{"AAP_ROOTDIR"}
Truth table33%1/3
A //= B
A= $rootdirB= $ENV{"AAP_ROOTDIR"}
| |||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 2 | ▶ | sub pwhash{ | ||||||||||||||||||
|
Subroutine
pwhash: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 32 | 2 | my ($pass)=@_; | |||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 2 | my $ppr=Authen::Passphrase::BlowfishCrypt->new( | |||||||||||||||||||
| 35 | cost => 10, | ||||||||||||||||||||
| 36 | passphrase => $pass, | ||||||||||||||||||||
| 37 | salt_random => 1, | ||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 2 | $ppr->as_rfc2307 | |||||||||||||||||||
| 41 | } | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 2 | ▶ | sub pwset{ | ||||||||||||||||||
|
Subroutine
pwset: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 44 | 2 | my ($user, $pass)=@_; | |||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 2 | my $file = "$rootdir/$user.yml"; | |||||||||||||||||||
| 47 | 2 | ▶ | my $conf = eval { LoadFile $file } // undef; | ||||||||||||||||||
|
Condition100%2/2
eval {
do {
LoadFile($file)
}
} // undef
MC/DC100%1/1
eval {
do {
LoadFile($file)
}
} // undef
eval {
do {
LoadFile($file)
}
}
Truth table100%2/2
A
A= eval {
do {
LoadFile($file)
}
}
| |||||||||||||||||||||
| 48 | 2 | $conf->{passphrase}=pwhash $pass; | |||||||||||||||||||
| 49 | 2 | $conf->{passphrase_version}=PASSPHRASE_VERSION; | |||||||||||||||||||
| 50 | 2 | DumpFile $file, $conf; | |||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 2 | chmod 0660, $file; | |||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 6 | ▶ | sub pwcheck{ | ||||||||||||||||||
|
Subroutine
pwcheck: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||
| 56 | 6 | my ($user, $pass)=@_; | |||||||||||||||||||
| 57 | 6 | ▶ | die INVALID_USER unless $user =~ USER_REGEX; ## no critic (RequireCarping) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 58 | 3 | $user=${^MATCH}; # Make taint shut up | |||||||||||||||||||
| 59 | 3 | my $conf=LoadFile "$rootdir/$user.yml"; | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | ## no critic (RequireCarping) | ||||||||||||||||||||
| 62 | 3 | ▶ | die BAD_PASSWORD unless keys %$conf; # Empty hash means no such user | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 63 | 3 | ▶ | die BAD_PASSWORD unless Authen::Passphrase->from_rfc2307($conf->{passphrase})->match($pass); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 64 | ## use critic | ||||||||||||||||||||
| 65 | 2 | ▶ | pwset $user, $pass if $conf->{passphrase_version} < PASSPHRASE_VERSION | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 0 | ▶ | sub handler{ | ||||||||||||||||||
|
Subroutine
handler: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 69 | 0 | my $r=shift; | |||||||||||||||||||
| 70 | 0 | local $rootdir = $r->dir_config('AuthenPassphraseRootdir'); | |||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 0 | my ($rc, $pass) = $r->get_basic_auth_pw; | |||||||||||||||||||
| 73 | 0 | ▶ | return $rc unless $rc == OK; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 0 | my $user=$r->user; | |||||||||||||||||||
| 76 | 0 | ▶ | unless (eval { pwcheck $user, $pass; 1 }) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 77 | 0 | $r->note_basic_auth_failure; | |||||||||||||||||||
| 78 | 0 | return HTTP_UNAUTHORIZED | |||||||||||||||||||
| 79 | } | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | OK | ||||||||||||||||||||
| 82 | 0 | } | |||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 1 | 1; | |||||||||||||||||||
| 85 | __END__ | ||||||||||||||||||||