-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathslauth.h
307 lines (167 loc) · 7.73 KB
/
slauth.h
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#define OTP_DEFAULT_DIGITS_VALUE 6
#define HOTP_DEFAULT_COUNTER_VALUE 0
#define HOTP_DEFAULT_RESYNC_VALUE 2
#define TOTP_DEFAULT_PERIOD_VALUE 30
#define TOTP_DEFAULT_BACK_RESYNC_VALUE 1
#define TOTP_DEFAULT_FORWARD_RESYNC_VALUE 1
#define MAX_RESPONSE_LEN_SHORT 256
#define MAX_RESPONSE_LEN_EXTENDED 65536
#define ASN1_SEQ_TYPE 48
#define ASN1_DEFINITE_SHORT_MASK 128
#define ASN1_DEFINITE_LONG_FOLLOWING_MASK 127
#define ASN1_MAX_FOLLOWING_LEN_BYTES 126
#define U2F_EC_KEY_SIZE 32
#define U2F_EC_POINT_SIZE ((U2F_EC_KEY_SIZE * 2) + 1)
#define U2F_MAX_KH_SIZE 128
#define U2F_MAX_ATT_CERT_SIZE 2048
#define U2F_MAX_EC_SIG_SIZE 72
#define U2F_CTR_SIZE 4
#define U2F_APPID_SIZE 32
#define U2F_CHAL_SIZE 32
#define U2F_REGISTER_MAX_DATA_TBS_SIZE ((((1 + U2F_APPID_SIZE) + U2F_CHAL_SIZE) + U2F_MAX_KH_SIZE) + U2F_EC_POINT_SIZE)
#define U2F_AUTH_MAX_DATA_TBS_SIZE ((((1 + U2F_APPID_SIZE) + U2F_CHAL_SIZE) + 1) + 4)
#define U2F_POINT_UNCOMPRESSED 4
#define U2F_REGISTER 1
#define U2F_AUTHENTICATE 2
#define U2F_VERSION 3
#define U2F_VENDOR_FIRST 64
#define U2F_VENDOR_LAST 191
#define U2F_REGISTER_ID 5
#define U2F_REGISTER_HASH_ID 0
#define U2F_AUTH_DONT_ENFORCE 8
#define U2F_AUTH_ENFORCE 3
#define U2F_AUTH_CHECK_ONLY 7
#define U2F_AUTH_FLAG_TUP 1
#define U2F_AUTH_FLAG_TDOWN 0
#define U2F_SW_NO_ERROR 36864
#define U2F_SW_WRONG_DATA 27264
#define U2F_SW_CONDITIONS_NOT_SATISFIED 27013
#define U2F_SW_COMMAND_NOT_ALLOWED 27014
#define U2F_SW_WRONG_LENGTH 26368
#define U2F_SW_CLA_NOT_SUPPORTED 28160
#define U2F_SW_INS_NOT_SUPPORTED 27904
#define HID_RPT_SIZE 64
#define CID_BROADCAST 4294967295
#define TYPE_MASK 128
#define TYPE_INIT 128
#define TYPE_CONT 0
#define FIDO_USAGE_PAGE 61904
#define FIDO_USAGE_U2FHID 1
#define FIDO_USAGE_DATA_IN 32
#define FIDO_USAGE_DATA_OUT 33
#define U2FHID_IF_VERSION 2
#define U2FHID_TRANS_TIMEOUT 3000
#define U2FHID_PING (TYPE_INIT | 1)
#define U2FHID_MSG (TYPE_INIT | 3)
#define U2FHID_LOCK (TYPE_INIT | 4)
#define U2FHID_INIT (TYPE_INIT | 6)
#define U2FHID_WINK (TYPE_INIT | 8)
#define U2FHID_SYNC (TYPE_INIT | 60)
#define U2FHID_ERROR (TYPE_INIT | 63)
#define U2FHID_VENDOR_FIRST (TYPE_INIT | 64)
#define U2FHID_VENDOR_LAST (TYPE_INIT | 127)
#define INIT_NONCE_SIZE 8
#define CAPFLAG_WINK 1
#define ERR_NONE 0
#define ERR_INVALID_CMD 1
#define ERR_INVALID_PAR 2
#define ERR_INVALID_LEN 3
#define ERR_INVALID_SEQ 4
#define ERR_MSG_TIMEOUT 5
#define ERR_CHANNEL_BUSY 6
#define ERR_LOCK_REQUIRED 10
#define ERR_SYNC_FAIL 11
#define ERR_OTHER 127
#define WEBAUTHN_CHALLENGE_LENGTH 32
#define WEBAUTHN_CREDENTIAL_ID_LENGTH 16
#define WEBAUTHN_USER_PRESENT_FLAG 1
#define WEBAUTHN_USER_VERIFIED_FLAG 4
#define WEBAUTHN_ATTESTED_CREDENTIAL_DATA_FLAG 64
#define WEBAUTHN_EXTENSION_DATA_FLAG 128
#define WEBAUTH_PUBLIC_KEY_TYPE_OKP 1
#define WEBAUTH_PUBLIC_KEY_TYPE_EC2 2
#define WEBAUTH_PUBLIC_KEY_TYPE_RSA 3
#define ECDSA_Y_PREFIX_POSITIVE 2
#define ECDSA_Y_PREFIX_NEGATIVE 3
#define ECDSA_Y_PREFIX_UNCOMPRESSED 4
#define ECDSA_CURVE_P256 1
#define ECDSA_CURVE_P384 2
#define ECDSA_CURVE_P521 3
#define ECDAA_CURVE_ED25519 6
#define TPM_GENERATED_VALUE 4283712327
typedef struct AuthenticatorCreationResponse AuthenticatorCreationResponse;
typedef struct AuthenticatorRequestResponse AuthenticatorRequestResponse;
typedef struct ClientWebResponse ClientWebResponse;
typedef struct HOTPContext HOTPContext;
typedef struct HashesAlgorithm HashesAlgorithm;
typedef struct SigningKey SigningKey;
typedef struct TOTPContext TOTPContext;
/**
*
*/
typedef struct U2fRequest U2fRequest;
typedef struct U2fRequest WebRequest;
typedef struct Buffer {
uint8_t *data;
uintptr_t len;
} Buffer;
struct HOTPContext *hotp_from_uri(const char *uri);
void hotp_free(struct HOTPContext *hotp);
char *hotp_to_uri(struct HOTPContext *hotp, const char *label, const char *issuer);
char *hotp_gen(struct HOTPContext *hotp);
void hotp_inc(struct HOTPContext *hotp);
bool hotp_verify(struct HOTPContext *hotp, const char *code);
bool hotp_validate_current(struct HOTPContext *hotp, const char *code);
struct TOTPContext *totp_from_uri(const char *uri);
void totp_free(struct TOTPContext *totp);
char *totp_to_uri(struct TOTPContext *totp, const char *label, const char *issuer);
char *totp_gen(struct TOTPContext *totp);
char *totp_gen_with(struct TOTPContext *totp, unsigned long elapsed);
bool totp_verify(struct TOTPContext *totp, const char *code);
bool totp_validate_current(struct TOTPContext *totp, const char *code);
WebRequest *web_request_from_json(const char *req);
void web_request_free(WebRequest *req);
bool web_request_is_register(WebRequest *req);
bool web_request_is_sign(WebRequest *req);
char *web_request_origin(WebRequest *req);
unsigned long long web_request_timeout(WebRequest *req);
char *web_request_key_handle(WebRequest *req, const char *origin);
struct ClientWebResponse *web_request_sign(WebRequest *req,
struct SigningKey *signing_key,
const char *origin,
unsigned long counter,
bool user_presence);
struct ClientWebResponse *web_request_register(WebRequest *req,
const char *origin,
const unsigned char *attestation_cert,
unsigned long long attestation_cert_len,
const unsigned char *attestation_key,
unsigned long long attestation_key_len);
void client_web_response_free(struct ClientWebResponse *rsp);
char *client_web_response_to_json(struct ClientWebResponse *rsp);
struct SigningKey *client_web_response_signing_key(struct ClientWebResponse *rsp);
void signing_key_free(struct SigningKey *s);
char *signing_key_to_string(struct SigningKey *s);
char *signing_key_get_key_handle(struct SigningKey *s);
struct SigningKey *signing_key_from_string(const char *s);
char *get_private_key_from_response(struct AuthenticatorCreationResponse *res);
struct Buffer get_attestation_object_from_response(struct AuthenticatorCreationResponse *res);
void response_free(struct AuthenticatorCreationResponse *res);
struct AuthenticatorCreationResponse *generate_credential_creation_response(const char *aaguid,
const unsigned char *credential_id,
uintptr_t credential_id_length,
const char *rp_id,
uint8_t attestation_flags,
const int *cose_algorithm_identifiers,
uintptr_t cose_algorithm_identifiers_length);
struct AuthenticatorRequestResponse *generate_credential_request_response(const char *rp_id,
const char *private_key,
uint8_t attestation_flags,
const unsigned char *client_data_hash,
uintptr_t client_data_hash_length);
struct Buffer get_auth_data_from_response(struct AuthenticatorRequestResponse *res);
struct Buffer get_signature_from_response(struct AuthenticatorRequestResponse *res);