File: Server.pm

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 (204 lines) | stat: -rw-r--r-- 6,352 bytes parent folder | download
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package Crypt::U2F::Server;

use 5.018001;
use strict;
use warnings;
use Carp;

require Exporter;
use AutoLoader;

our @ISA     = qw(Exporter);
our $VERSION = '0.47';

# Items to export into callers namespace by default. Note: do not export
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.

# This allows declaration	use Crypt::U2F ':all';
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
# will save memory.
our %EXPORT_TAGS = (
    'all' => [
        qw(
          u2fclib_calcAuthenticationChallenge
          u2fclib_calcRegistrationChallenge
          u2fclib_deInit
          u2fclib_free_context
          u2fclib_getError
          u2fclib_get_context
          u2fclib_init
          u2fclib_setAppID
          u2fclib_setChallenge
          u2fclib_setKeyHandle
          u2fclib_setOrigin
          u2fclib_setPublicKey
          u2fclib_verifyAuthentication
          u2fclib_verifyRegistration
          )
    ]
);

our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );

our @EXPORT = qw(

);

sub AUTOLOAD {

    # This AUTOLOAD is used to 'autoload' constants from the constant()
    # XS function.

    my $constname;
    our $AUTOLOAD;
    ( $constname = $AUTOLOAD ) =~ s/.*:://;
    croak "&Crypt::U2F::Server::constant not defined"
      if $constname eq 'constant';
    my ( $error, $val ) = constant($constname);
    if ($error) { croak $error; }
    {
        no strict 'refs';
        *$AUTOLOAD = sub { $val };
    }
    goto &$AUTOLOAD;
}

require XSLoader;
XSLoader::load( 'Crypt::U2F::Server', $VERSION );

# Preloaded methods go here.

# Autoload methods go after =cut, and are processed by the autosplit program.

1;
__END__

# Below is stub documentation for your module. You'd better edit it!

=head1 NAME

Crypt::U2F::Server - Low level wrapper around the U2F two factor authentication C library (server side)

=head1 SYNOPSIS

  use Crypt::U2F::Server;

=head1 DESCRIPTION

This is a very low level wrapper around the original C library. You probably B<shouldn't> use it,
but use L<Crypt::U2F::Server::Simple> instead!

This API is subject to change, depending on the underlying library, the weather and the whims of
the developer.

If you decide to use it anyway, it would probably be a good idea to specify the exact version number
of L<Crypt::U2F::Server> to use.

=head1 INSTALLATION

This module requires the Yubico u2f-server shared library installed, please see the official
project page at L<https://developers.yubico.com/libu2f-server/> on how to do that.

=head1 NO MULTITHREADING / MULTI INSTANCES

The way this is currently implemented, i doubt very much that multithreading or even use in
more than one instance in your program will work. Multi-Forking should be OK, though, if you
only call u2fclib_init() after forking, but this isn't tested as of yet.

The problem is how u2fclib_init() and u2fclib_deInit() are implemented. While the underlying
library has a context-handle (not used here), u2fclib_deInit() will tear down everything as far
as i can tell.

L<Crypt::U2F::Server::Simple> works around this problem by reference counting and always requiring all
values to call the relevant u2fclib_set* functions.

=head2 EXPORT

None by default.

=head2 Exportable functions


  char* u2fclib_calcRegistrationChallenge(void* ctx)
  int u2fclib_deInit(void)
  int u2fclib_free_context(void* ctx)
  char* u2fclib_getError(void)
  void* u2fclib_get_context(void)
  int u2fclib_init(bool debug)
  int u2fclib_setAppID(void* ctx, char* appid)
  int u2fclib_setChallenge(void* ctx, char* challenge)
  int u2fclib_setKeyHandle(void* ctx, char* buf)
  int u2fclib_setOrigin(void* ctx, char* origin)
  int u2fclib_setPublicKey(void* ctx, char* buf)
  int u2fclib_verifyAuthentication(void* ctx, char* buf)
  registrationData_t* u2fclib_verifyRegistration(void* ctx, char* buf)



=head1 SEE ALSO

See L<Crypt::U2F::Server::Simple> for the module you should actually be using.

=head1 BUGS

Yes, there should be some in there. First of all, this is crypto stuff, so
it's broken by default (it only depends on the time it takes to happen).

Also, at the moment, this module has seen only very limited testing.

=head1 AUTHOR

=over

=item Rene Schickbauer, E<lt>rene.schickbauer@magnapowertrain.comE<gt>

=item Xavier Guimard, E<lt>x.guimard@free.frE<gt>

=back

=head1 COPYRIGHT AND LICENSE

Adapted as a Perl library by Rene 'cavac' Schickbauer

This roughly based on u2f-server.c from Yubico's
C library, see L<https://developers.yubico.com/libu2f-server/>

In order for this to work, you need to install that
library.

This adaption is (C) 2014-2018 Rene 'cavac' Schickbauer and 2018 Xavier
Guimard, but as it is based on Yubico's code, the licence below applies!

I<We, the community, would hereby thank Yubico for open sourcing their code!>

    /*
    * Copyright (c) 2014 Yubico AB
    * All rights reserved.
    *
    * Redistribution and use in source and binary forms, with or without
    * modification, are permitted provided that the following conditions are
    * met:
    *
    * * Redistributions of source code must retain the above copyright
    * notice, this list of conditions and the following disclaimer.
    *
    * * Redistributions in binary form must reproduce the above
    * copyright notice, this list of conditions and the following
    * disclaimer in the documentation and/or other materials provided
    * with the distribution.
    *
    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    */

=cut