From 5bd5920b0fd775937d20863563d44146361cb2ff Mon Sep 17 00:00:00 2001 From: Christophe Maudoux Date: Thu, 5 Apr 2018 19:43:06 +0200 Subject: [PATCH] Truncate 2F device name (#1386) --- .../lib/Lemonldap/NG/Portal/2F/Register/TOTP.pm | 5 ++++- .../lib/Lemonldap/NG/Portal/2F/Register/U2F.pm | 4 +++- .../lib/Lemonldap/NG/Portal/2F/Register/Yubikey.pm | 8 ++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/2F/Register/TOTP.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/2F/Register/TOTP.pm index d9cd34838..dfd413c40 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/2F/Register/TOTP.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/2F/Register/TOTP.pm @@ -67,8 +67,11 @@ sub run { my $TOTPName = $req->param('TOTPName'); my $epoch = time(); - # Set default name if empty + # Set default name if empty and troncate name if too long $TOTPName ||= $epoch; + $TOTPName = + substr( $TOTPName, 0, $self->conf->{max2FDevicesNameLength} ); + $self->logger->debug("TOTP name : $TOTPName"); unless ($code) { $self->logger->userInfo('TOTP registration: empty validation form'); diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/2F/Register/U2F.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/2F/Register/U2F.pm index 4820b7a91..2e7f51cd3 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/2F/Register/U2F.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/2F/Register/U2F.pm @@ -104,8 +104,10 @@ sub run { my $keyName = $req->param('keyName'); my $epoch = time(); - # Set default name if empty + # Set default name if empty and troncate name if too long $keyName ||= $epoch; + $keyName = + substr( $keyName, 0, $self->conf->{max2FDevicesNameLength} ); $self->logger->debug("Key name : $keyName"); push @{$_2FDevices}, diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/2F/Register/Yubikey.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/2F/Register/Yubikey.pm index fada59279..dccd9153d 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/2F/Register/Yubikey.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/2F/Register/Yubikey.pm @@ -23,7 +23,8 @@ has logo => ( is => 'rw', default => 'yubikey.png' ); sub init { my ($self) = @_; - $self->conf->{yubikey2fPublicIDSize} ||= 12; + + #$self->conf->{yubikey2fPublicIDSize} ||= 12; return 1; } @@ -37,8 +38,11 @@ sub run { my $UBKName = $req->param('UBKName'); my $epoch = time(); - # Set default name if empty + # Set default name if empty and troncate name if too long $UBKName ||= $epoch; + $UBKName = substr( $UBKName, 0, $self->conf->{max2FDevicesNameLength} ); + $self->logger->debug("Yubikey name : $UBKName"); + if ( $otp and length($otp) > $self->conf->{yubikey2fPublicIDSize} ) {