2017-02-04 08:55:47 +01:00
|
|
|
# Self U2F registration
|
2017-02-02 22:48:32 +01:00
|
|
|
package Lemonldap::NG::Portal::Register::U2F;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Mouse;
|
2017-02-04 08:55:47 +01:00
|
|
|
use MIME::Base64;
|
2017-02-02 22:48:32 +01:00
|
|
|
|
|
|
|
our $VERSION = '2.0.0';
|
|
|
|
|
2017-02-04 08:55:47 +01:00
|
|
|
extends 'Lemonldap::NG::Portal::Lib::U2F';
|
2017-02-02 22:48:32 +01:00
|
|
|
|
2017-02-04 08:55:47 +01:00
|
|
|
# INITIALIZATION
|
2017-02-03 18:14:13 +01:00
|
|
|
|
2017-02-02 22:48:32 +01:00
|
|
|
sub init {
|
|
|
|
my ($self) = @_;
|
2017-02-04 08:55:47 +01:00
|
|
|
return 0 unless $self->SUPER::init;
|
2017-02-03 07:23:39 +01:00
|
|
|
$self->addAuthRoute( u2fregister => 'run', [ 'GET', 'POST' ] );
|
2017-02-02 22:48:32 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-02-04 08:55:47 +01:00
|
|
|
# RUNNING METHODS
|
|
|
|
|
|
|
|
# Main method
|
2017-02-02 22:48:32 +01:00
|
|
|
sub run {
|
|
|
|
my ( $self, $req ) = @_;
|
|
|
|
|
|
|
|
# Check for registration response
|
2017-02-03 18:14:13 +01:00
|
|
|
if ( my $response = $req->param('registration') ) {
|
|
|
|
$self->lmLog( "Get registration data $response", 'debug' );
|
|
|
|
my ( $keyHandle, $userKey ) =
|
|
|
|
$self->crypter->registrationVerify($response);
|
2017-02-03 07:23:39 +01:00
|
|
|
if ( $keyHandle and $userKey ) {
|
2017-02-04 08:55:47 +01:00
|
|
|
$self->p->updatePersistentSession(
|
|
|
|
$req,
|
|
|
|
{
|
|
|
|
_u2fHandle => encode_base64( $keyHandle, '' ),
|
|
|
|
_u2fKey => encode_base64( $userKey, '' )
|
|
|
|
}
|
|
|
|
);
|
2017-02-03 07:23:39 +01:00
|
|
|
return $self->p->sendHtml( $req, 'u2fregister',
|
|
|
|
params => { SUCCESS => 1 } );
|
|
|
|
}
|
2017-02-03 18:14:13 +01:00
|
|
|
$self->p->userError( 'U2F Registration failed: '
|
|
|
|
. Crypt::U2F::Server::Simple::lastError() );
|
|
|
|
return $self->p->sendHtml( $req, 'u2fregister',
|
|
|
|
params => { FAILED => 1 } );
|
2017-02-02 22:48:32 +01:00
|
|
|
}
|
2017-02-03 07:23:39 +01:00
|
|
|
my $challenge = $self->crypter->registrationChallenge;
|
|
|
|
return $self->p->sendHtml( $req, 'u2fregister',
|
2017-02-03 18:14:13 +01:00
|
|
|
params => { CHALLENGE => $challenge, APPID => $self->origin } );
|
2017-02-02 22:48:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|