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 56 57 58 59 60
|
#!/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;
my $auth = Crypt::U2F::Server::Simple->new(appId=>$appId, origin=>$origin);
if(!defined($auth)) {
die(Crypt::U2F::Server::Simple::lastError());
}
my $challenge = $auth->registrationChallenge();
if(!defined($challenge) || !length($challenge)) {
die($auth->lastError());
}
open(my $cofh, '>', 'regChallenge.dat') or die($!);
print $cofh $challenge;
close $cofh;
my $regcmd = $u2fhost . ' -aregister -o "' . $origin . '" < regChallenge.dat > regReply.dat';
print "Running $regcmd...\nPlease press the blinking button!\n";
`$regcmd`;
open(my $cifh, '<', 'regReply.dat') or die($!);
my $reply = <$cifh>;
close $cifh;
print "Got $reply\n";
my ($keyHandle, $publicKey) = $auth->registrationVerify($reply);
if(!defined($keyHandle)) {
print "failed to get keyHandle!\n";
}
if(!defined($publicKey)) {
print "failed to get publicKey!\n";
}
if(!defined($keyHandle) || !defined($publicKey)) {
die($auth->lastError());
}
open(my $kofh, '>', 'keyHandle.dat') or die($!);
print $kofh $keyHandle;
close $kofh;
open(my $pofh, '>', 'publicKey.dat') or die($!);
print $pofh encode_base64($publicKey, '');
close $pofh;
|