]> git.proxmox.com Git - libpve-u2f-server-perl.git/blame - PVE/U2F.pm
bump version to 1.2.0
[libpve-u2f-server-perl.git] / PVE / U2F.pm
CommitLineData
b8adb2d5
WB
1package PVE::U2F;
2
3use 5.024000;
4use strict;
5use warnings;
6
7require Exporter;
8
9our @ISA = qw(Exporter);
10
11# Items to export into callers namespace by default. Note: do not export
12# names by default without a very good reason. Use EXPORT_OK instead.
13# Do not simply export all your public functions/methods/constants.
14
15# This allows declaration use PVE::U2F::XS ':all';
16# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
17# will save memory.
18our %EXPORT_TAGS = ( 'all' => [] );
19
20our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
21our @EXPORT = ();
22our $VERSION = '1.0';
23
24require XSLoader;
25XSLoader::load('PVE::U2F', $VERSION);
26
27#### Context creation
28
29my $global_init = 0;
30sub new($) {
31 my ($class) = @_;
32 if (!$global_init) {
33 $global_init = 1;
34 do_global_init();
35 }
36 if (my $lib = new_impl()) {
37 return bless { ctx => $lib }, $class;
38 }
39 return undef;
40}
41
42sub DESTROY {
43 my ($self) = @_;
44 done_impl($self->{ctx});
45}
46
47#### Error handling
48
49my @errcodes = (
50qw(memory json base64 crypto origin challenge signature format)
51);
52sub checkrc($) {
53 my ($rc) = @_;
54 return if $rc == 0;
55 die "u2fs: $errcodes[-$rc-1] error\n" if $rc < 0 && $rc >= -8;
56 die "u2fs: unknown error\n";
57}
58
59#### Context initialization
60
61sub origin($) { return $_[0]->{origin}; }
62sub set_origin($$) {
63 my ($self, $origin) = @_;
64 checkrc(set_origin_impl($self->{ctx}, $origin));
65 return $self->{origin} = $origin;
66}
67
68sub appid($) { return $_[0]->{appid}; }
69sub set_appid($$) {
70 my ($self, $appid) = @_;
71 checkrc(set_appid_impl($self->{ctx}, $appid));
72 return $self->{appid} = $appid;
73}
74
75sub challenge($) { return $_[0]->{challenge}; }
76sub set_challenge($$) {
77 my ($self, $challenge) = @_;
78 checkrc(set_challenge_impl($self->{ctx}, $challenge));
79 return $self->{challenge} = $challenge;
80}
81
82sub keyHandle($) { return $_[0]->{keyHandle}; }
83sub set_keyHandle($$) {
84 my ($self, $keyHandle) = @_;
85 checkrc(set_keyHandle_impl($self->{ctx}, $keyHandle));
86 return $self->{keyHandle} = $keyHandle;
87}
88
89sub publicKey($) { return $_[0]->{publicKey}; }
90sub set_publicKey($$) {
91 my ($self, $publicKey) = @_;
92 checkrc(set_publicKey_impl($self->{ctx}, $publicKey));
93 return $self->{publicKey} = $publicKey;
94}
95
96#### Registration
97
98sub registration_challenge($) {
99 my ($self) = @_;
100 checkrc(registration_challenge_impl($self->{ctx}, my $challenge));
101 return $challenge;
102}
103
104sub registration_verify($$) {
105 my ($self, $response) = @_;
106 checkrc(registration_verify_impl($self->{ctx}, $response, my $kh, my $pk));
107 return ($kh, $pk);
108}
109
110#### Authentication
111
112sub auth_challenge($) {
113 my ($self) = @_;
114 checkrc(auth_challenge_impl($self->{ctx}, my $challenge));
115 return $challenge;
116}
117
118sub auth_verify($$) {
119 my ($self, $response) = @_;
120 checkrc(auth_verify_impl($self->{ctx}, $response,
121 my $verified,
122 my $counter,
123 my $presence));
124 checkrc($verified);
125 return wantarray ? ($counter, $presence) : 1;
126}
127
1281;
129__END__
130
131=head1 NAME
132
133PVE::U2F - Perl bindings for libu2f-server
134
135=head1 SYNOPSIS
136
137 use PVE::U2F;
138
139=head1 DESCRIPTION
140
141Perl bindings for libu2f-server
142
143=head2 EXPORT
144
145None by default.
146
147=head1 SEE ALSO
148
149TODO
150
151=head1 AUTHOR
152
153Proxmox Server Solutions GmbH <support@proxmox.com>
154
155=cut