blib/lib/Lemonldap/NG/Portal/2F/Password.pm

filter: Statementstmt 49.1% 29 / 59 Branchbran 20.0% 2 / 10 Conditioncond 33.3% 2 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 63.6% 7 / 11 Podpod 33.3% 1 / 3 totaltotal 45.1% 42 / 93 CC 8 SCAR 23.1
CC
8
Cov
44%
verify
30.0
__ANON__
6.0
init
3.0
CRAP 10.1
« blib/lib/Lemonldap/NG/Portal/Plugins/PublicNotifications.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Lib/Remote.pm »
1 # Password 2F second factor authentication
2 #
3 # This plugin handle authentications to ask the password for users that
4 # have registered their password
5 package Lemonldap::NG::Portal::2F::Password;
6  
7 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use JSON qw(from_json to_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Lemonldap::NG::Common::Crypto;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Lemonldap::NG::Common::Util qw/display2F/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Lemonldap::NG::Portal::Main::Constants qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
13 PE_OK
14 PE_ERROR
15 PE_FORMEMPTY
16 PE_SENDRESPONSE
17 PE_BADCREDENTIALS
18 2 );
19  
20 2 our $VERSION = '2.23.0';
21  
22 2 extends 'Lemonldap::NG::Portal::Main::SecondFactor';
23 2 with 'Lemonldap::NG::Portal::Lib::2fDevices';
24  
25 # INITIALIZATION
26  
27 2 has prefix => ( is => 'ro', default => 'password' );
28 2 has logo => ( is => 'rw', default => 'password.png' );
29  
30 has key => (
31 is => 'ro',
32 lazy => 1,
33 0 ▶ default => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
34 0 my ($self) = @_;
35 0 ▶ return $self->conf->{password2fKey} || $self->conf->{key};
Condition0%0/3
$self->conf->{'password2fKey'} || $self->conf->{'key'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->conf->{'password2fKey'} || $self->conf->{'key'}
$self->conf->{'password2fKey'} $self->conf->{'key'}
Truth table0%0/3
A || B
A= $self->conf->{'password2fKey'}B= $self->conf->{'key'}
ABresult
1X1
011
000
36 }
37 2 );
38  
39 has crypto => (
40 is => 'ro',
41 lazy => 1,
42 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
43 0 my ($self) = @_;
44 0 Lemonldap::NG::Common::Crypto->new( $self->key );
45 }
46 2 );
47  
48 2 ▶sub init {
Subroutine init: called CC=3 SCAR=11.0
Pod undocumented
49 2 my ($self) = @_;
50  
51 # If self registration is enabled and "activation" is just set to
52 # "enabled", replace the rule to detect if user has registered its key
53 $self->conf->{password2fActivation} = 'has2f("Password")'
54 if ( $self->conf->{password2fSelfRegistration}
55 2 ▶ and $self->conf->{password2fActivation} eq '1' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->conf->{"password2fSelfRegistration"} and $self->conf->{"password2fActivation"} eq 1 1 1 2
Condition66%2/3
$self->conf->{"password2fSelfRegistration"} and $self->conf->{"password2fActivation"} eq 1
!ll&&!rl&&r
101
MC/DC50%1/2
$self->conf->{"password2fSelfRegistration"} and $self->conf->{"password2fActivation"} eq 1
$self->conf->{"password2fSelfRegistration"} $self->conf->{"password2fActivation"} eq 1
Truth table66%2/3
A and B
A= $self->conf->{"password2fSelfRegistration"}B= $self->conf->{"password2fActivation"} eq 1
ABresult
0X0
100
111
56  
57 2 return $self->SUPER::init();
58 }
59  
60 # RUNNING METHODS
61  
62 0 ▶sub run {
Subroutine run: not called CC=1 SCAR=6.9
Pod documented
63 0 my ( $self, $req, $token ) = @_;
64 0 $self->logger->debug( $self->prefix . '2f: generate form' );
65  
66 # Prepare form
67 0 my $tmp = $self->p->sendHtml(
68 $req,
69 'password2fcheck',
70 params => {
71 TARGET => $self->p->relativeUrl( $req, 'password2fcheck' ),
72 TOKEN => $token,
73 $self->get2fTplParams($req),
74 }
75 );
76 0 $self->logger->debug( $self->prefix . '2f: prepare verification' );
77  
78 0 $req->response($tmp);
79 0 return PE_SENDRESPONSE;
80 }
81  
82 0 ▶sub verify {
Subroutine verify: not called CC=5 SCAR=34.0
Pod undocumented
83 0 my ( $self, $req, $session ) = @_;
84 0 my ( $password, $password_device, $secret );
85 0 my $uid = $session->{ $self->conf->{whatToTrace} };
86  
87 0 $self->logger->debug( $self->prefix . '2f: verification' );
88  
89 0 ▶ unless ( $password = $req->param('password') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($password = $req->param("password")) 0 0 0
90 0 $self->userLogger->error( $self->prefix . '2f: no value provided' );
91 0 return PE_FORMEMPTY;
92 }
93  
94 0 my @password_devices =
95 $self->find2fDevicesByType( $req, $session, $self->type );
96 0 ▶ unless ( $password_device = shift @password_devices ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($password_device = shift @password_devices) 0 0 0
97 0 $self->logger->debug( $self->prefix . '2f: no password found' );
98 0 return PE_ERROR;
99 }
100  
101 0 ▶ unless ( $secret = $password_device->{_secret} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($secret = $password_device->{"_secret"}) 0 0 0
102 0 $self->logger->debug( $self->prefix . '2f: no password secret found' );
103 0 return PE_ERROR;
104 }
105  
106 0 ▶ if ( $password eq $self->crypto->decrypt($secret) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($password eq $self->crypto->decrypt($secret)) { } 0 0 0
107  
108 0 $req->data->{_2fDevice} = $password_device;
109 0 $self->userLogger->info( "User $uid authenticated with 2F device: "
110 . display2F($password_device) );
111 0 return PE_OK;
112 }
113 else {
114 0 $self->userLogger->notice( $self->prefix . '2f: invalid for ' . $uid );
115 0 return PE_BADCREDENTIALS;
116 }
117 }
118  
119 2 1;
« blib/lib/Lemonldap/NG/Portal/Plugins/PublicNotifications.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Lib/Remote.pm »