File: sign.pl

package info (click to toggle)
libauthen-u2f-perl 0.003-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid
  • size: 196 kB
  • sloc: javascript: 334; perl: 209; makefile: 8
file content (44 lines) | stat: -rw-r--r-- 879 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env perl

use warnings;
use strict;

use Authen::U2F;
use JSON;

use constant APPID   => 'https://example.com';
use constant VERSION => 'U2F_V2';

my ($handle, $key) = @ARGV;
unless ($handle && $key) {
  die "usage: $0 <handle> <key>\n";
}

print "CHALLENGE:\n";

my $challenge = Authen::U2F->challenge;
print encode_json({
  challenge => $challenge,
  keyHandle => $handle,
  appId     => APPID,
  version   => VERSION,
}) . "\n";

print "\n";
print "ENTER RESPONSE:\n";
chomp (my $in = <STDIN>);

my $sign_response = decode_json($in);

Authen::U2F->signature_verify(
  challenge      => $challenge,
  app_id         => APPID,
  origin         => APPID,
  key_handle     => $sign_response->{keyHandle},
  key            => $key,
  signature_data => $sign_response->{signatureData},
  client_data    => $sign_response->{clientData},
);

print "\n";
print "SUCCESS\n";