« blib/lib/Lemonldap/NG/Portal/Lib/OIDCTokenExchange.pm
↑ Summary
blib/lib/Lemonldap/NG/Portal/Plugins/AdaptativeAuthenticationLevel.pm »
| 1 | # Self Password 2F registration | ||||||||||||||||||||||||||||
| 2 | package Lemonldap::NG::Portal::2F::Register::Password; | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Lemonldap::NG::Portal::Main::Constants ':all'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Mouse; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use JSON qw(from_json to_json); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Lemonldap::NG::Common::Crypto; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | our $VERSION = '2.23.0'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | extends 'Lemonldap::NG::Portal::2F::Register::Base'; | |||||||||||||||||||||||||||
| 13 | 1 | with 'Lemonldap::NG::Portal::Lib::2fDevices'; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | # INITIALIZATION | ||||||||||||||||||||||||||||
| 16 | 1 | has logo => ( is => 'rw', default => 'password.png' ); | |||||||||||||||||||||||||||
| 17 | 1 | has prefix => ( is => 'rw', default => 'password' ); | |||||||||||||||||||||||||||
| 18 | 1 | has template => ( is => 'ro', default => 'password2fregister' ); | |||||||||||||||||||||||||||
| 19 | 1 | has welcome => ( is => 'ro', default => 'PE71' ); | |||||||||||||||||||||||||||
| 20 | has ott => ( | ||||||||||||||||||||||||||||
| 21 | is => 'rw', | ||||||||||||||||||||||||||||
| 22 | lazy => 1, | ||||||||||||||||||||||||||||
| 23 | 0 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 24 | my $ott = | ||||||||||||||||||||||||||||
| 25 | 0 | $_[0]->{p}->loadModule('Lemonldap::NG::Portal::Lib::OneTimeToken'); | |||||||||||||||||||||||||||
| 26 | my $timeout = $_[0]->{conf}->{sfRegisterTimeout} | ||||||||||||||||||||||||||||
| 27 | 0 | ▶ | // $_[0]->{conf}->{formTimeout}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$_[0]{"conf"}{"sfRegisterTimeout"} // $_[0]{"conf"}{"formTimeout"}
MC/DC0%0/2
$_[0]{"conf"}{"sfRegisterTimeout"} // $_[0]{"conf"}{"formTimeout"}
$_[0]{"conf"}{"sfRegisterTimeout"}
$_[0]{"conf"}{"formTimeout"}
Truth table0%0/3
A // B
A= $_[0]{"conf"}{"sfRegisterTimeout"}B= $_[0]{"conf"}{"formTimeout"}
| |||||||||||||||||||||||||||||
| 28 | 0 | $ott->timeout($timeout); | |||||||||||||||||||||||||||
| 29 | 0 | return $ott; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | 1 | ); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | has key => ( | ||||||||||||||||||||||||||||
| 34 | is => 'ro', | ||||||||||||||||||||||||||||
| 35 | lazy => 1, | ||||||||||||||||||||||||||||
| 36 | 0 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 37 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 38 | 0 | ▶ | return $self->conf->{password2fKey} || $self->conf->{key}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->conf->{'password2fKey'} || $self->conf->{'key'}
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'}
| |||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | 1 | ); | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | has crypto => ( | ||||||||||||||||||||||||||||
| 43 | is => 'ro', | ||||||||||||||||||||||||||||
| 44 | lazy => 1, | ||||||||||||||||||||||||||||
| 45 | 0 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 46 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 47 | 0 | Lemonldap::NG::Common::Crypto->new( $self->key ); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | 1 | ); | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 1 | ▶ | use constant supportedActions => { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 52 | verify => "verify", | ||||||||||||||||||||||||||||
| 53 | modify => "modify", | ||||||||||||||||||||||||||||
| 54 | delete => "delete", | ||||||||||||||||||||||||||||
| 55 | 1 | }; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # Verification that user has a valid password | ||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub verify { | ||||||||||||||||||||||||||
|
Subroutine
verify: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 59 | 0 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||
| 60 | 0 | my $user = $req->userData->{ $self->conf->{whatToTrace} }; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | return $self->failResponse( $req, 'csrfError', 400 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | unless $self->checkCsrf($req); | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | # Check Password | ||||||||||||||||||||||||||||
| 66 | 0 | my $password = $req->param('password'); | |||||||||||||||||||||||||||
| 67 | 0 | my $passwordverify = $req->param('passwordverify'); | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | unless ( $password and $passwordverify ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$password and $passwordverify
MC/DC0%0/2
$password and $passwordverify
$password
$passwordverify
Truth table0%0/3
A and B
A= $passwordB= $passwordverify
| |||||||||||||||||||||||||||||
| 70 | 0 | return $self->failResponse( $req, 'missingPassword', 200 ); | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # Invalid try is returned with a 200 code. Javascript will read error | ||||||||||||||||||||||||||||
| 74 | # and propose to retry | ||||||||||||||||||||||||||||
| 75 | 0 | ▶ | if ( $password ne $passwordverify ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 0 | return $self->failResponse( $req, PE_PASSWORD_MISMATCH, 200 ); | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | 0 | $self->logger->debug( $self->prefix . '2f: code verified' ); | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | # Now password is verified, let's store it in persistent data | ||||||||||||||||||||||||||||
| 81 | 0 | my $secret = $self->crypto->encrypt($password); | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | # Reading existing 2F passwords | ||||||||||||||||||||||||||||
| 84 | 0 | my @password2f = | |||||||||||||||||||||||||||
| 85 | $self->find2fDevicesByType( $req, $req->userData, $self->type ); | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | # Delete previous password if any | ||||||||||||||||||||||||||||
| 88 | 0 | ▶ | if (@password2f) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if ( $self->del2fDevices( $req, $req->userData, \@password2f ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | $self->logger->debug( | |||||||||||||||||||||||||||
| 91 | $self->prefix . "2f: old password(s) deleted" ); | ||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | else { | ||||||||||||||||||||||||||||
| 94 | 0 | $self->logger->error( | |||||||||||||||||||||||||||
| 95 | $self->prefix . "2f: unable to delete old password(s)" ); | ||||||||||||||||||||||||||||
| 96 | 0 | return $self->failResponse( $req, 'serverError' ); | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | # Add a new one | ||||||||||||||||||||||||||||
| 101 | 0 | my $res = $self->registerDevice( | |||||||||||||||||||||||||||
| 102 | $req, | ||||||||||||||||||||||||||||
| 103 | $req->userData, | ||||||||||||||||||||||||||||
| 104 | { | ||||||||||||||||||||||||||||
| 105 | _secret => $secret, | ||||||||||||||||||||||||||||
| 106 | name => 'password', | ||||||||||||||||||||||||||||
| 107 | type => $self->type, | ||||||||||||||||||||||||||||
| 108 | epoch => time() | ||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | ); | ||||||||||||||||||||||||||||
| 111 | 0 | ▶ | if ( $res == PE_OK ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 0 | return $self->successResponse( $req, { result => 1 } ); | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | else { | ||||||||||||||||||||||||||||
| 115 | 0 | $self->logger->error( $self->prefix . "2f: unable to add password" ); | |||||||||||||||||||||||||||
| 116 | 0 | return $self->failResponse( $req, $res ); | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 1 | 1; | |||||||||||||||||||||||||||