1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
#!/usr/bin/env perl
use strict;
use warnings;
BEGIN {
unshift @INC, "../lib";
}
my $u2fhost = '/usr/local/bin/u2f-host';
my $appId = 'Example';
my $origin = 'http://127.0.0.1';
use Crypt::U2F::Server::Simple;
use MIME::Base64;
open(my $kifh, '<', 'keyHandle.dat') or die($!);
my $keyHandle = <$kifh>;
close $kifh;
open(my $pifh, '<', 'publicKey.dat') or die($!);
my $publicKey = <$pifh>;
$publicKey = decode_base64($publicKey);
close $pifh;
my $auth = Crypt::U2F::Server::Simple->new(appId=>$appId, origin=>$origin,
keyHandle=>$keyHandle, publicKey=>$publicKey);
if(!defined($auth)) {
die(Crypt::U2F::Server::Simple::lastError());
}
my $challenge = $auth->authenticationChallenge();
if(!defined($challenge) || !length($challenge)) {
die($auth->lastError());
}
open(my $cofh, '>', 'authChallenge.dat') or die($!);
print $cofh $challenge;
close $cofh;
my $regcmd = $u2fhost . ' -aauthenticate -o "' . $origin . '" < authChallenge.dat > authReply.dat';
print "Running $regcmd...\nPlease press the blinking button!\n";
`$regcmd`;
open(my $cifh, '<', 'authReply.dat') or die($!);
my $reply = <$cifh>;
close $cifh;
print "Got $reply\n";
my ($isValid) = $auth->authenticationVerify($reply);
if($isValid) {
print "Hurray! User has been verified as valid!\n";
} else {
print "Oh no, verification failed! The reason is: ", $auth->lastError(), "\n";
}
|