File: u2fsimple_authenticate_replyonly.pl

package info (click to toggle)
libcrypt-u2f-server-perl 0.47-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 356 kB
  • sloc: perl: 415; ansic: 157; makefile: 8
file content (50 lines) | stat: -rw-r--r-- 1,139 bytes parent folder | download | duplicates (4)
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
#!/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';

my $challengeID = 'HelloWorldSECRETKEY';

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 $rc = $auth->setChallenge($challengeID);
if(!$rc) {
    die($auth->lastError());
}

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";
}