-
Notifications
You must be signed in to change notification settings - Fork 0
/
cffi_defs.h
527 lines (413 loc) · 16.3 KB
/
cffi_defs.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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
// ctanker/async.h
typedef struct tanker_future tanker_future_t;
typedef struct tanker_future tanker_expected_t;
typedef struct tanker_promise tanker_promise_t;
typedef struct tanker_error tanker_error_t;
typedef void* (*tanker_future_then_t)(tanker_future_t* fut, void* arg);
tanker_promise_t* tanker_promise_create(void);
void tanker_promise_destroy(tanker_promise_t* promise);
tanker_future_t* tanker_promise_get_future(tanker_promise_t* promise);
void tanker_promise_set_value(tanker_promise_t* promise, void* value);
void* tanker_future_get_voidptr(tanker_future_t* future);
bool tanker_future_is_ready(tanker_future_t* future);
void tanker_future_wait(tanker_future_t* future);
tanker_future_t* tanker_future_then(tanker_future_t* future,
tanker_future_then_t cb,
void* arg);
tanker_error_t* tanker_future_get_error(tanker_future_t* future);
unsigned char tanker_future_has_error(tanker_future_t* future);
void tanker_future_destroy(tanker_future_t* future);
// ctanker/error.h
enum tanker_error_code
{
TANKER_ERROR_INVALID_ARGUMENT = 1,
TANKER_ERROR_INTERNAL_ERROR,
TANKER_ERROR_NETWORK_ERROR,
TANKER_ERROR_PRECONDITION_FAILED,
TANKER_ERROR_OPERATION_CANCELED,
TANKER_ERROR_DECRYPTION_FAILED,
TANKER_ERROR_GROUP_TOO_BIG,
TANKER_ERROR_INVALID_VERIFICATION,
TANKER_ERROR_TOO_MANY_ATTEMPTS,
TANKER_ERROR_EXPIRED_VERIFICATION,
TANKER_ERROR_IO_ERROR,
TANKER_ERROR_LAST,
};
typedef uint32_t tanker_error_code_t;
struct tanker_error
{
tanker_error_code_t code;
char const* message;
};
// ctanker/http.h There is no HTTP revese bindings for python
// foward declarations to satisfy FFI
typedef struct tanker_http_request tanker_http_request_t;
typedef void tanker_http_request_handle_t;
typedef tanker_http_request_handle_t* (*tanker_http_send_request_t)(
tanker_http_request_t* request, void* data);
typedef void (*tanker_http_cancel_request_t)(
tanker_http_request_t* request,
tanker_http_request_handle_t* request_handle,
void* data);
struct tanker_http_options
{
tanker_http_send_request_t send_request;
tanker_http_cancel_request_t cancel_request;
void* data;
};
typedef struct tanker_http_options tanker_http_options_t;
// ctanker/datastore.h
enum tanker_datastore_error_code
{
TANKER_DATASTORE_ERROR_INVALID_DATABASE_VERSION = 1,
TANKER_DATASTORE_ERROR_RECORD_NOT_FOUND,
TANKER_DATASTORE_ERROR_DATABASE_ERROR,
TANKER_DATASTORE_ERROR_DATABASE_LOCKED,
TANKER_DATASTORE_ERROR_DATABASE_CORRUPT,
TANKER_DATASTORE_ERROR_DATABASE_TOO_RECENT,
TANKER_DATASTORE_ERROR_CONSTRAINT_FAILED,
TANKER_DATASTORE_ERROR_LAST,
};
enum tanker_datastore_onconflict
{
TANKER_DATASTORE_ONCONFLICT_FAIL,
TANKER_DATASTORE_ONCONFLICT_IGNORE,
TANKER_DATASTORE_ONCONFLICT_REPLACE,
TANKER_DATASTORE_ONCONFLICT_LAST,
};
typedef void tanker_datastore_t;
typedef void tanker_datastore_error_handle_t;
typedef void tanker_datastore_device_get_result_handle_t;
typedef void tanker_datastore_cache_get_result_handle_t;
typedef void (*tanker_datastore_open_t)(tanker_datastore_error_handle_t* h,
tanker_datastore_t** db,
char const* data_path,
char const* cache_path);
typedef void (*tanker_datastore_close_t)(tanker_datastore_t* db);
typedef void (*tanker_datastore_device_nuke_t)(
tanker_datastore_t* datastore, tanker_datastore_error_handle_t* h);
typedef void (*tanker_datastore_put_serialized_device_t)(
tanker_datastore_t* datastore,
tanker_datastore_error_handle_t* h,
uint8_t const* device,
uint32_t device_size);
typedef void (*tanker_datastore_find_serialized_device_t)(
tanker_datastore_t* datastore,
tanker_datastore_device_get_result_handle_t* h);
typedef void (*tanker_datastore_put_cache_values_t)(
tanker_datastore_t* datastore,
tanker_datastore_error_handle_t* h,
uint8_t const* const* keys,
uint32_t const* key_sizes,
uint8_t const* const* values,
uint32_t const* value_sizes,
uint32_t elem_count,
uint8_t onconflict);
typedef void (*tanker_datastore_find_cache_values_t)(
tanker_datastore_t* datastore,
tanker_datastore_device_get_result_handle_t* h,
uint8_t const* const* keys,
uint32_t const* key_sizes,
uint32_t elem_count);
struct tanker_datastore_options
{
tanker_datastore_open_t open;
tanker_datastore_close_t close;
tanker_datastore_device_nuke_t nuke;
tanker_datastore_put_serialized_device_t put_serialized_device;
tanker_datastore_find_serialized_device_t find_serialized_device;
tanker_datastore_put_cache_values_t put_cache_values;
tanker_datastore_find_cache_values_t find_cache_values;
};
typedef struct tanker_datastore_options tanker_datastore_options_t;
uint8_t* tanker_datastore_allocate_device_buffer(
tanker_datastore_device_get_result_handle_t* result_handle, uint32_t size);
void tanker_datastore_allocate_cache_buffer(
tanker_datastore_cache_get_result_handle_t* result_handle,
uint8_t** out_ptrs,
uint32_t* sizes);
void tanker_datastore_report_error(tanker_datastore_error_handle_t* handle,
uint8_t error_code,
char const* message);
// ctanker/ctanker.h
enum tanker_status
{
TANKER_STATUS_STOPPED,
TANKER_STATUS_READY,
TANKER_STATUS_IDENTITY_REGISTRATION_NEEDED,
TANKER_STATUS_IDENTITY_VERIFICATION_NEEDED,
TANKER_STATUS_LAST
};
enum tanker_verification_method_type
{
TANKER_VERIFICATION_METHOD_EMAIL = 0x1,
TANKER_VERIFICATION_METHOD_PASSPHRASE,
TANKER_VERIFICATION_METHOD_VERIFICATION_KEY,
TANKER_VERIFICATION_METHOD_OIDC_ID_TOKEN,
TANKER_VERIFICATION_METHOD_PHONE_NUMBER,
TANKER_VERIFICATION_METHOD_PREVERIFIED_EMAIL,
TANKER_VERIFICATION_METHOD_PREVERIFIED_PHONE_NUMBER,
TANKER_VERIFICATION_METHOD_E2E_PASSPHRASE,
TANKER_VERIFICATION_METHOD_PREVERIFIED_OIDC,
TANKER_VERIFICATION_METHOD_OIDC_AUTHORIZATION_CODE,
TANKER_VERIFICATION_METHOD_PREHASHED_AND_ENCRYPTED_PASSPHRASE,
TANKER_VERIFICATION_METHOD_LAST
};
enum tanker_log_level
{
TANKER_LOG_DEBUG = 1,
TANKER_LOG_INFO,
TANKER_LOG_WARNING,
TANKER_LOG_ERROR,
};
typedef struct tanker tanker_t;
typedef struct tanker_options tanker_options_t;
typedef struct tanker_email_verification tanker_email_verification_t;
typedef struct tanker_phone_number_verification tanker_phone_number_verification_t;
typedef struct tanker_preverified_oidc_verification tanker_preverified_oidc_verification_t;
typedef struct tanker_oidc_authorization_code_verification tanker_oidc_authorization_code_verification_t;
typedef struct tanker_verification tanker_verification_t;
typedef struct tanker_verification_list tanker_verification_list_t;
typedef struct tanker_verification_method tanker_verification_method_t;
typedef struct tanker_verification_options tanker_verification_options_t;
typedef struct tanker_encrypt_options tanker_encrypt_options_t;
typedef struct tanker_sharing_options tanker_sharing_options_t;
typedef struct tanker_log_record tanker_log_record_t;
typedef struct tanker_verification_method_list tanker_verification_method_list_t;
typedef struct tanker_attach_result tanker_attach_result_t;
struct tanker_verification_method_list
{
tanker_verification_method_t* methods;
uint32_t count;
};
struct tanker_verification_list
{
uint8_t version;
tanker_verification_t* verifications;
uint32_t count;
};
struct tanker_log_record
{
char const* category;
uint32_t level;
char const* file;
uint32_t line;
char const* message;
};
typedef void (*tanker_log_handler_t)(tanker_log_record_t const* record);
struct tanker_options
{
uint8_t version;
char const* app_id; /*!< Must not be NULL. */
char const* url; /*!< Must not be NULL. */
char const* persistent_path; /*!< Must not be NULL. */
char const* cache_path; /*!< Must not be NULL. */
char const* sdk_type; /*!< Must not be NULL. */
char const* sdk_version; /*!< Must not be NULL. */
tanker_http_options_t http_options;
tanker_datastore_options_t datastore_options;
// We have a `version` field to handle ABI compatibility ourselves, tell cffi
// to ignore extra fields.
...;
};
struct tanker_email_verification
{
uint8_t version;
char const* email;
char const* verification_code;
};
struct tanker_phone_number_verification
{
uint8_t version;
char const* phone_number;
char const* verification_code;
};
struct tanker_preverified_oidc_verification
{
uint8_t version;
char const* subject;
char const* provider_id;
};
struct tanker_oidc_authorization_code_verification
{
uint8_t version;
char const* provider_id;
char const* authorization_code;
char const* state;
};
struct tanker_verification
{
uint8_t version;
// enum cannot be bound to java as they do not have a fixed size.
// It takes a value from tanker_verification_method_type:
uint8_t verification_method_type;
char const* verification_key;
tanker_email_verification_t email_verification;
char const* passphrase;
char const* e2e_passphrase;
char const* oidc_id_token;
tanker_phone_number_verification_t phone_number_verification;
char const* preverified_email;
char const* preverified_phone_number;
tanker_preverified_oidc_verification_t preverified_oidc_verification;
tanker_oidc_authorization_code_verification_t oidc_authorization_code_verification;
char const* prehashed_and_encrypted_passphrase;
};
struct tanker_verification_method
{
uint8_t version;
// enum cannot be bound to java as they do not have a fixed size.
// It takes a value from tanker_verification_method_type:
uint8_t verification_method_type;
char const* value1;
char const* value2;
};
struct tanker_verification_options
{
uint8_t version;
bool with_session_token;
bool allow_e2e_method_switch;
};
struct tanker_encrypt_options
{
uint8_t version;
char const* const* share_with_users;
uint32_t nb_users;
char const* const* share_with_groups;
uint32_t nb_groups;
bool share_with_self;
uint32_t padding_step;
};
struct tanker_sharing_options
{
uint8_t version;
char const* const* share_with_users;
uint32_t nb_users;
char const* const* share_with_groups;
uint32_t nb_groups;
};
struct tanker_attach_result
{
uint8_t version;
// enum cannot be bound to java as they do not have a fixed size.
// It takes a value from the enum tanker_status:
uint8_t status;
tanker_verification_method_t* method;
};
char const* tanker_version_string(void);
void tanker_set_log_handler(tanker_log_handler_t handler);
void tanker_init(void);
tanker_future_t* tanker_create(tanker_options_t const* options);
tanker_future_t* tanker_destroy(tanker_t* tanker);
tanker_future_t* tanker_start(tanker_t* tanker, char const* identity);
tanker_expected_t* tanker_enroll_user(tanker_t* tanker,
char const* identity,
tanker_verification_list_t const* verifications);
tanker_future_t* tanker_register_identity(
tanker_t* tanker,
tanker_verification_t const* verification,
tanker_verification_options_t const* cverif_opts);
tanker_future_t* tanker_verify_identity(
tanker_t* tanker,
tanker_verification_t const* verification,
tanker_verification_options_t const* cverif_opts);
tanker_future_t* tanker_stop(tanker_t* tanker);
tanker_future_t* tanker_create_oidc_nonce(tanker_t* tanker);
tanker_future_t* tanker_set_oidc_test_nonce(tanker_t* tanker, char const* nonce);
enum tanker_status tanker_status(tanker_t* tanker);
tanker_future_t* tanker_generate_verification_key(tanker_t* session);
tanker_future_t* tanker_set_verification_method(
tanker_t* session,
tanker_verification_t const* verification,
tanker_verification_options_t const* cverif_opts);
tanker_future_t* tanker_get_verification_methods(tanker_t* session);
uint64_t tanker_encrypted_size(uint64_t clear_size, uint32_t padding_step);
tanker_expected_t* tanker_decrypted_size(uint8_t const* encrypted_data,
uint64_t encrypted_size);
tanker_expected_t* tanker_get_resource_id(uint8_t const* encrypted_data,
uint64_t encrypted_size);
tanker_future_t* tanker_encrypt(tanker_t* tanker,
uint8_t* encrypted_data,
uint8_t const* data,
uint64_t data_size,
tanker_encrypt_options_t const* options);
tanker_future_t* tanker_decrypt(tanker_t* session,
uint8_t* decrypted_data,
uint8_t const* data,
uint64_t data_size);
tanker_future_t* tanker_share(tanker_t* session,
char const* const* resource_ids,
uint64_t nb_resource_ids,
tanker_sharing_options_t* options);
tanker_future_t* tanker_attach_provisional_identity(
tanker_t* session, char const* provisional_identity);
tanker_future_t* tanker_verify_provisional_identity(
tanker_t* ctanker, tanker_verification_t const* verification);
tanker_expected_t* tanker_authenticate_with_idp(tanker_t* session, char const* provider_id, char const* cookie);
void tanker_free_authenticate_with_idp_result(tanker_oidc_authorization_code_verification_t* result);
void tanker_free_buffer(void const* buffer);
void tanker_free_verification_method_list(
tanker_verification_method_list_t* list);
tanker_expected_t* tanker_prehash_password(char const* password);
tanker_expected_t* tanker_prehash_and_encrypt_password(char const* password, char const* public_key);
void tanker_free_attach_result(tanker_attach_result_t* result);
// ctanker/groups.h
tanker_future_t* tanker_create_group(
tanker_t* session,
char const* const* public_identities_to_add,
uint64_t nb_public_identities_to_add);
tanker_future_t* tanker_update_group_members(
tanker_t* session,
char const* group_id,
char const* const* public_identities_to_add,
uint64_t nb_public_identities_to_add,
char const* const* public_identities_to_remove,
uint64_t nb_public_identities_to_remove);
// ctanker/stream.h
typedef struct tanker_stream tanker_stream_t;
typedef struct tanker_stream_read_operation tanker_stream_read_operation_t;
typedef void (*tanker_stream_input_source_t)(
uint8_t* buffer,
int64_t buffer_size,
tanker_stream_read_operation_t* operation,
void* additional_data);
tanker_future_t* tanker_stream_encrypt(tanker_t* tanker,
tanker_stream_input_source_t cb,
void* additional_data,
tanker_encrypt_options_t const* options);
tanker_future_t* tanker_stream_decrypt(tanker_t* tanker,
tanker_stream_input_source_t cb,
void* additional_data);
void tanker_stream_read_operation_finish(tanker_stream_read_operation_t* op,
int64_t nb_read);
tanker_future_t* tanker_stream_read(tanker_stream_t* stream,
uint8_t* buffer,
int64_t buffer_size);
tanker_expected_t* tanker_stream_get_resource_id(tanker_stream_t* stream);
tanker_future_t* tanker_stream_close(tanker_stream_t* stream);
// ctanker/encryptionsession.h
typedef struct tanker_encryption_session tanker_encryption_session_t;
tanker_future_t* tanker_encryption_session_open(
tanker_t* tanker, tanker_encrypt_options_t const* options);
tanker_future_t* tanker_encryption_session_close(
tanker_encryption_session_t* session);
uint64_t tanker_encryption_session_encrypted_size(
tanker_encryption_session_t* session, uint64_t clear_size);
tanker_expected_t* tanker_encryption_session_get_resource_id(
tanker_encryption_session_t* session);
tanker_future_t* tanker_encryption_session_encrypt(
tanker_encryption_session_t* session,
uint8_t* encrypted_data,
uint8_t const* data,
uint64_t data_size);
tanker_future_t* tanker_encryption_session_stream_encrypt(
tanker_encryption_session_t* session,
tanker_stream_input_source_t cb,
void* additional_data);
// cffi specific
extern "Python" void log_handler(tanker_log_record_t*);
extern "Python" void stream_input_source_callback(
uint8_t* buffer,
int64_t buffer_size,
tanker_stream_read_operation_t* operation,
void* additional_data);