Verify if max 2F devices is not reached (#1386)

This commit is contained in:
Christophe Maudoux 2018-04-04 23:50:33 +02:00
parent ff9ef7aab3
commit a3ba56aa12
3 changed files with 53 additions and 6 deletions

View File

@ -29,6 +29,8 @@ has ott => (
);
sub init {
my ($self) = @_;
$self->conf->{max2FDevices} ||= 10;
return 1;
}
@ -106,6 +108,22 @@ sub run {
$self->logger->debug("No 2F Device found");
$_2FDevices = [];
}
# Check if user can register one more device
my $size = @$_2FDevices;
$self->logger->debug(
"Nbr 2FDevices = $size / $self->conf->{max2FDevices}");
if ( $size > $self->conf->{max2FDevices} ) {
$self->userLogger->error("Max number of 2F devices is reached !!!");
return $self->p->sendHtml(
$req, 'error',
params => {
RAW_ERROR => 'MaxNumberof2FDevicesReached',
AUTH_ERROR_TYPE => 'warning',
}
);
}
push @{$_2FDevices},
{
type => 'TOTP',

View File

@ -19,6 +19,7 @@ has logo => ( is => 'rw', default => 'u2f.png' );
sub init {
my ($self) = @_;
$self->conf->{max2FDevices} ||= 10;
return 0 unless $self->SUPER::init;
return 1;
}
@ -76,6 +77,23 @@ sub run {
# Set default value
$_2FDevices = [];
}
# Check if user can register one more device
my $size = @$_2FDevices;
$self->logger->debug(
"Nbr 2FDevices = $size / $self->conf->{max2FDevices}");
if ( $size > $self->conf->{max2FDevices} ) {
$self->userLogger->error(
"Max number of 2F devices is reached !!!");
return $self->p->sendHtml(
$req, 'error',
params => {
RAW_ERROR => 'MaxNumberof2FDevicesReached',
AUTH_ERROR_TYPE => 'warning',
}
);
}
my $keyName = $req->param('keyName');
my $epoch = time();

View File

@ -24,6 +24,7 @@ has logo => ( is => 'rw', default => 'yubikey.png' );
sub init {
my ($self) = @_;
$self->conf->{yubikey2fPublicIDSize} ||= 12;
$self->conf->{max2FDevices} ||= 10;
return 1;
}
@ -57,12 +58,6 @@ sub run {
$_2FDevices = [];
}
# Select U2F Devices only
#my @listU2FKeys = map {
#( $_->{type} eq "U2F" ) ? return $_ : return ();
#} @{$_2FDevices};
#$self->logger->debug("Select U2F Devices only ...");
# Search if Yubikey has been already registered
my $SameUBKFound = 0;
foreach (@$_2FDevices) {
@ -85,6 +80,22 @@ sub run {
);
}
# Check if user can register one more device
my $size = @$_2FDevices;
$self->logger->debug(
"Nbr 2FDevices = $size / $self->conf->{max2FDevices}");
if ( $size > $self->conf->{max2FDevices} ) {
$self->userLogger->error(
"Max number of 2F devices is reached !!!");
return $self->p->sendHtml(
$req, 'error',
params => {
RAW_ERROR => 'MaxNumberof2FDevicesReached',
AUTH_ERROR_TYPE => 'warning',
}
);
}
push @{$_2FDevices},
{
type => 'UBK',