Modify $list2FDevices to $_2FDevices conf. entry (#1386)

This commit is contained in:
Christophe Maudoux 2018-04-04 23:05:27 +02:00
parent 7f2d50536f
commit 3db93c49fe
4 changed files with 47 additions and 65 deletions

View File

@ -263,47 +263,24 @@ sub _displayRegister {
[] ];
}
my $list2FDevices = eval {
from_json( $req->userData->{list2FDevices},
my $_2FDevices = eval {
from_json( $req->userData->{_2FDevices},
{ allow_nonref => 1 } );
};
unless ($list2FDevices) {
unless ($_2FDevices) {
$self->logger->debug("No 2F Device found");
$list2FDevices = [];
$_2FDevices = [];
};
#my @listClefsU2F = map {
#if ( $_->{type} eq "U2F" ) {
#return $_;
#}
#else {
#return ();
#}
#} @$req->userData->{list2FDevices};
return $self->p->sendHtml(
$req,
'2fregisters',
params => {
SKIN => $self->conf->{portalSkin},
MODULES => \@am,
SFDEVICES => $list2FDevices,
#SFDEVICES => @$list2FDevices,
SFDEVICES => $_2FDevices,
}
);
}

View File

@ -98,15 +98,15 @@ sub run {
$self->p->updatePersistentSession( $req,
{ _totp2fSecret => $token->{_totp2fSecret} } );
my $list2FDevices = eval {
my $_2FDevices = eval {
$self->logger->debug("Looking for 2F Devices ...");
from_json( $req->userData->{list2FDevices}, { allow_nonref => 1 } );
from_json( $req->userData->{_2FDevices}, { allow_nonref => 1 } );
};
unless ($list2FDevices) {
unless ($_2FDevices) {
$self->logger->debug("No 2F Device found");
$list2FDevices = [];
$_2FDevices = [];
}
push @{$list2FDevices},
push @{$_2FDevices},
{
type => 'TOTP',
name => $TOTPName,
@ -117,7 +117,7 @@ sub run {
$self->logger->debug(
"Append 2F Device : { type => 'totp', name => $TOTPName }");
$self->p->updatePersistentSession( $req,
{ list2FDevices => to_json($list2FDevices) } );
{ _2FDevices => to_json($_2FDevices) } );
$self->userLogger->notice('TOTP registration succeed');
return [ 200, [ 'Content-Type' => 'application/json' ],
@ -187,16 +187,16 @@ sub run {
}
elsif ( $action eq 'delete' ) {
my $epoch = $req->param('epoch');
my $list2FDevices = eval {
my $_2FDevices = eval {
$self->logger->debug("Loading 2F Devices ...");
# Read existing 2FDevices
from_json( $req->userData->{list2FDevices}, { allow_nonref => 1 } );
from_json( $req->userData->{_2FDevices}, { allow_nonref => 1 } );
};
my @keep = ();
while (@$list2FDevices) {
my $element = shift @$list2FDevices;
while (@$_2FDevices) {
my $element = shift @$_2FDevices;
$self->logger->debug("Looking for 2F device to delete ...");
push @keep, $element unless ( $element->{epoch} eq $epoch );
}
@ -204,7 +204,7 @@ sub run {
$self->logger->debug(
"Delete 2F Device : { type => 'TOTP', epoch => $epoch }");
$self->p->updatePersistentSession( $req,
{ list2FDevices => to_json( \@keep ) } );
{ _2FDevices => to_json( \@keep ) } );
$self->userLogger->notice('TOTP deletion succeed');
return [ 200, [ 'Content-Type' => 'application/json' ],
['{"result":1}'] ];

View File

@ -63,18 +63,18 @@ sub run {
my ( $keyHandle, $userKey ) = $c->registrationVerify($resp);
if ( $keyHandle and $userKey ) {
my $list2FDevices = eval {
my $_2FDevices = eval {
$self->logger->debug("Looking for 2F Devices ...");
# Read existing 2FDevices
from_json( $req->userData->{list2FDevices},
from_json( $req->userData->{_2FDevices},
{ allow_nonref => 1 } );
};
unless ($list2FDevices) {
unless ($_2FDevices) {
$self->logger->debug("No 2F Device found");
# Set default value
$list2FDevices = [];
$_2FDevices = [];
}
my $keyName = $req->param('keyName');
my $epoch = time();
@ -83,7 +83,7 @@ sub run {
$keyName ||= $epoch;
$self->logger->debug("Key name : $keyName");
push @{$list2FDevices},
push @{$_2FDevices},
{
type => 'U2F',
name => $keyName,
@ -94,7 +94,7 @@ sub run {
$self->logger->debug(
"Append 2F Device : { type => 'U2F', name => $keyName }");
$self->p->updatePersistentSession( $req,
{ list2FDevices => to_json($list2FDevices) } );
{ _2FDevices => to_json($_2FDevices) } );
$self->p->updatePersistentSession(
$req,
@ -201,16 +201,16 @@ sub run {
}
elsif ( $action eq 'delete' ) {
my $epoch = $req->param('epoch');
my $list2FDevices = eval {
my $_2FDevices = eval {
$self->logger->debug("Loading 2F Devices ...");
# Read existing 2FDevices
from_json( $req->userData->{list2FDevices}, { allow_nonref => 1 } );
from_json( $req->userData->{_2FDevices}, { allow_nonref => 1 } );
};
my @keep = ();
while (@$list2FDevices) {
my $element = shift @$list2FDevices;
while (@$_2FDevices) {
my $element = shift @$_2FDevices;
$self->logger->debug("Looking for 2F device to delete ...");
push @keep, $element unless ( $element->{epoch} eq $epoch );
}
@ -218,7 +218,7 @@ sub run {
$self->logger->debug(
"Delete 2F Device : { type => 'U2F', epoch => $epoch }");
$self->p->updatePersistentSession( $req,
{ list2FDevices => to_json( \@keep ) } );
{ _2FDevices => to_json( \@keep ) } );
$self->p->updatePersistentSession(
$req,

View File

@ -47,25 +47,25 @@ sub run {
. substr( $otp, 0, $self->conf->{yubikey2fPublicIDSize} );
my $key = substr( $otp, 0, $self->conf->{yubikey2fPublicIDSize} );
my $list2FDevices = eval {
my $_2FDevices = eval {
$self->logger->debug("Looking for 2F Devices ...");
from_json( $req->userData->{list2FDevices},
from_json( $req->userData->{_2FDevices},
{ allow_nonref => 1 } );
};
unless ($list2FDevices) {
unless ($_2FDevices) {
$self->logger->debug("No 2F Device found");
$list2FDevices = [];
$_2FDevices = [];
}
# Select U2F Devices only
#my @listU2FKeys = map {
#( $_->{type} eq "U2F" ) ? return $_ : return ();
#} @{$list2FDevices};
#} @{$_2FDevices};
#$self->logger->debug("Select U2F Devices only ...");
# Search if Yubikey has been already registered
my $SameUBKFound = 0;
foreach (@$list2FDevices) {
foreach (@$_2FDevices) {
$self->logger->debug("Reading Yubikeys ...");
if ( $_->{_yubikey} eq $key ) {
$SameUBKFound = 1;
@ -76,11 +76,16 @@ sub run {
$self->logger->debug("Same 2F Device found ? $SameUBKFound");
if ($SameUBKFound) {
$self->userLogger->error("Yubikey already registered !");
return $self->p->sendError( $req, 'Yubikey already registered',
200 );
return $self->p->sendHtml(
$req, 'error',
params => {
RAW_ERROR => 'yourKeyIsAlreadyRegistered',
AUTH_ERROR_TYPE => 'warning',
}
);
}
push @{$list2FDevices},
push @{$_2FDevices},
{
type => 'UBK',
name => $UBKName,
@ -91,7 +96,7 @@ sub run {
$self->logger->debug(
"Append 2F Device : { type => 'UBK', name => $UBKName }");
$self->p->updatePersistentSession( $req,
{ list2FDevices => to_json($list2FDevices) } );
{ _2FDevices => to_json($_2FDevices) } );
$self->p->updatePersistentSession( $req, { _yubikeys => $keys } );
return $self->p->sendHtml(
@ -121,16 +126,16 @@ sub run {
if ( $action eq 'delete' ) {
my $epoch = $req->param('epoch');
my $list2FDevices = eval {
my $_2FDevices = eval {
$self->logger->debug("Loading 2F Devices ...");
# Read existing 2FDevices
from_json( $req->userData->{list2FDevices}, { allow_nonref => 1 } );
from_json( $req->userData->{_2FDevices}, { allow_nonref => 1 } );
};
my @keep = ();
while (@$list2FDevices) {
my $element = shift @$list2FDevices;
while (@$_2FDevices) {
my $element = shift @$_2FDevices;
$self->logger->debug("Looking for 2F device to delete ...");
push @keep, $element unless ( $element->{epoch} eq $epoch );
}
@ -138,7 +143,7 @@ sub run {
$self->logger->debug(
"Delete 2F Device : { type => 'UBK', epoch => $epoch }");
$self->p->updatePersistentSession( $req,
{ list2FDevices => to_json( \@keep ) } );
{ _2FDevices => to_json( \@keep ) } );
$self->userLogger->notice('Yubikey deletion succeed');
return [