]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/libfido2-util.h
libfido2: tweak credential to read fido2 PIN from
[thirdparty/systemd.git] / src / shared / libfido2-util.h
CommitLineData
69cb2896
LP
1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2#pragma once
3
4#include "macro.h"
5
cde2f860
LB
6typedef enum Fido2EnrollFlags {
7 FIDO2ENROLL_PIN = 1 << 0,
06f08719 8 FIDO2ENROLL_UP = 1 << 1, /* User presence (ie: touching token) */
896cc0da 9 FIDO2ENROLL_UV = 1 << 2, /* User verification (ie: fingerprint) */
3cc00ba6
LP
10 FIDO2ENROLL_PIN_IF_NEEDED = 1 << 3, /* If auth doesn't work without PIN ask for one, as in systemd 248 */
11 FIDO2ENROLL_UP_IF_NEEDED = 1 << 4, /* If auth doesn't work without UP, enable it, as in systemd 248 */
12 FIDO2ENROLL_UV_OMIT = 1 << 5, /* Leave "uv" untouched, as in systemd 248 */
cde2f860
LB
13 _FIDO2ENROLL_TYPE_MAX,
14 _FIDO2ENROLL_TYPE_INVALID = -EINVAL,
15} Fido2EnrollFlags;
16
69cb2896
LP
17#if HAVE_LIBFIDO2
18#include <fido.h>
19
20extern int (*sym_fido_assert_allow_cred)(fido_assert_t *, const unsigned char *, size_t);
21extern void (*sym_fido_assert_free)(fido_assert_t **);
22extern size_t (*sym_fido_assert_hmac_secret_len)(const fido_assert_t *, size_t);
23extern const unsigned char* (*sym_fido_assert_hmac_secret_ptr)(const fido_assert_t *, size_t);
24extern fido_assert_t* (*sym_fido_assert_new)(void);
25extern int (*sym_fido_assert_set_clientdata_hash)(fido_assert_t *, const unsigned char *, size_t);
26extern int (*sym_fido_assert_set_extensions)(fido_assert_t *, int);
27extern int (*sym_fido_assert_set_hmac_salt)(fido_assert_t *, const unsigned char *, size_t);
28extern int (*sym_fido_assert_set_rp)(fido_assert_t *, const char *);
29extern int (*sym_fido_assert_set_up)(fido_assert_t *, fido_opt_t);
896cc0da 30extern int (*sym_fido_assert_set_uv)(fido_assert_t *, fido_opt_t);
69cb2896
LP
31extern size_t (*sym_fido_cbor_info_extensions_len)(const fido_cbor_info_t *);
32extern char **(*sym_fido_cbor_info_extensions_ptr)(const fido_cbor_info_t *);
33extern void (*sym_fido_cbor_info_free)(fido_cbor_info_t **);
34extern fido_cbor_info_t* (*sym_fido_cbor_info_new)(void);
e3fb662b
LP
35extern size_t (*sym_fido_cbor_info_options_len)(const fido_cbor_info_t *);
36extern char** (*sym_fido_cbor_info_options_name_ptr)(const fido_cbor_info_t *);
37extern const bool* (*sym_fido_cbor_info_options_value_ptr)(const fido_cbor_info_t *);
69cb2896
LP
38extern void (*sym_fido_cred_free)(fido_cred_t **);
39extern size_t (*sym_fido_cred_id_len)(const fido_cred_t *);
40extern const unsigned char* (*sym_fido_cred_id_ptr)(const fido_cred_t *);
41extern fido_cred_t* (*sym_fido_cred_new)(void);
42extern int (*sym_fido_cred_set_clientdata_hash)(fido_cred_t *, const unsigned char *, size_t);
43extern int (*sym_fido_cred_set_extensions)(fido_cred_t *, int);
44extern int (*sym_fido_cred_set_rk)(fido_cred_t *, fido_opt_t);
45extern int (*sym_fido_cred_set_rp)(fido_cred_t *, const char *, const char *);
46extern int (*sym_fido_cred_set_type)(fido_cred_t *, int);
47extern int (*sym_fido_cred_set_user)(fido_cred_t *, const unsigned char *, size_t, const char *, const char *, const char *);
48extern int (*sym_fido_cred_set_uv)(fido_cred_t *, fido_opt_t);
49extern void (*sym_fido_dev_free)(fido_dev_t **);
50extern int (*sym_fido_dev_get_assert)(fido_dev_t *, fido_assert_t *, const char *);
51extern int (*sym_fido_dev_get_cbor_info)(fido_dev_t *, fido_cbor_info_t *);
52extern void (*sym_fido_dev_info_free)(fido_dev_info_t **, size_t);
53extern int (*sym_fido_dev_info_manifest)(fido_dev_info_t *, size_t, size_t *);
54extern const char* (*sym_fido_dev_info_manufacturer_string)(const fido_dev_info_t *);
55extern const char* (*sym_fido_dev_info_product_string)(const fido_dev_info_t *);
56extern fido_dev_info_t* (*sym_fido_dev_info_new)(size_t);
57extern const char* (*sym_fido_dev_info_path)(const fido_dev_info_t *);
58extern const fido_dev_info_t* (*sym_fido_dev_info_ptr)(const fido_dev_info_t *, size_t);
59extern bool (*sym_fido_dev_is_fido2)(const fido_dev_t *);
60extern int (*sym_fido_dev_make_cred)(fido_dev_t *, fido_cred_t *, const char *);
61extern fido_dev_t* (*sym_fido_dev_new)(void);
62extern int (*sym_fido_dev_open)(fido_dev_t *, const char *);
b6aa89b0 63extern int (*sym_fido_dev_close)(fido_dev_t *);
5a96b32d
LP
64extern void (*sym_fido_init)(int);
65extern void (*sym_fido_set_log_handler)(fido_log_handler_t *);
69cb2896
LP
66extern const char* (*sym_fido_strerr)(int);
67
68int dlopen_libfido2(void);
69
70static inline void fido_cbor_info_free_wrapper(fido_cbor_info_t **p) {
71 if (*p)
72 sym_fido_cbor_info_free(p);
73}
74
75static inline void fido_assert_free_wrapper(fido_assert_t **p) {
76 if (*p)
77 sym_fido_assert_free(p);
78}
79
80static inline void fido_dev_free_wrapper(fido_dev_t **p) {
b6aa89b0 81 if (*p) {
82 sym_fido_dev_close(*p);
69cb2896 83 sym_fido_dev_free(p);
b6aa89b0 84 }
69cb2896
LP
85}
86
87static inline void fido_cred_free_wrapper(fido_cred_t **p) {
88 if (*p)
89 sym_fido_cred_free(p);
90}
91
ebcb3f38
LP
92int fido2_use_hmac_hash(
93 const char *device,
94 const char *rp_id,
95 const void *salt,
96 size_t salt_size,
97 const void *cid,
98 size_t cid_size,
99 char **pins,
cde2f860 100 Fido2EnrollFlags required,
ebcb3f38
LP
101 void **ret_hmac,
102 size_t *ret_hmac_size);
103
17599e12
LP
104int fido2_generate_hmac_hash(
105 const char *device,
106 const char *rp_id,
107 const char *rp_name,
108 const void *user_id, size_t user_id_len,
109 const char *user_name,
110 const char *user_display_name,
111 const char *user_icon,
251c71b6
LP
112 const char *askpw_icon,
113 const char *askpw_credential,
cde2f860 114 Fido2EnrollFlags lock_with,
70e723c0 115 int cred_alg,
17599e12
LP
116 void **ret_cid, size_t *ret_cid_size,
117 void **ret_salt, size_t *ret_salt_size,
118 void **ret_secret, size_t *ret_secret_size,
0735ed95
LP
119 char **ret_usedpin,
120 Fido2EnrollFlags *ret_locked_with);
17599e12 121
70e723c0
M
122int parse_fido2_algorithm(const char *s, int *ret);
123#else
124static inline int parse_fido2_algorithm(const char *s, int *ret) {
125 return -EOPNOTSUPP;
126}
69cb2896 127#endif
fb2d839c
LP
128
129int fido2_list_devices(void);
130int fido2_find_device_auto(char **ret);
4f0cfa77
LP
131
132int fido2_have_device(const char *device);