Coverage Report

Created: 2020-09-01 07:05

/libfido2/src/extern.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2018 Yubico AB. All rights reserved.
3
 * Use of this source code is governed by a BSD-style
4
 * license that can be found in the LICENSE file.
5
 */
6
7
#ifndef _EXTERN_H
8
#define _EXTERN_H
9
10
#include <stdint.h>
11
12
#include "fido/types.h"
13
#include "blob.h"
14
15
#ifdef __cplusplus
16
extern "C" {
17
#endif /* __cplusplus */
18
19
/* aes256 */
20
int aes256_cbc_dec(const fido_blob_t *, const fido_blob_t *, fido_blob_t *);
21
int aes256_cbc_enc(const fido_blob_t *, const fido_blob_t *, fido_blob_t *);
22
23
/* cbor encoding functions */
24
cbor_item_t *cbor_flatten_vector(cbor_item_t **, size_t);
25
cbor_item_t *cbor_encode_assert_options(fido_opt_t, fido_opt_t);
26
cbor_item_t *cbor_encode_change_pin_auth(const fido_blob_t *,
27
    const fido_blob_t *, const fido_blob_t *);
28
cbor_item_t *cbor_encode_extensions(const fido_cred_ext_t *);
29
cbor_item_t *cbor_encode_hmac_secret_param(const fido_blob_t *,
30
    const es256_pk_t *, const fido_blob_t *);
31
cbor_item_t *cbor_encode_options(fido_opt_t, fido_opt_t);
32
cbor_item_t *cbor_encode_pin_auth(const fido_blob_t *, const fido_blob_t *);
33
cbor_item_t *cbor_encode_pin_enc(const fido_blob_t *, const fido_blob_t *);
34
cbor_item_t *cbor_encode_pin_hash_enc(const fido_blob_t *, const fido_blob_t *);
35
cbor_item_t *cbor_encode_pin_opt(void);
36
cbor_item_t *cbor_encode_pubkey(const fido_blob_t *);
37
cbor_item_t *cbor_encode_pubkey_list(const fido_blob_array_t *);
38
cbor_item_t *cbor_encode_pubkey_param(int);
39
cbor_item_t *cbor_encode_rp_entity(const fido_rp_t *);
40
cbor_item_t *cbor_encode_set_pin_auth(const fido_blob_t *, const fido_blob_t *);
41
cbor_item_t *cbor_encode_user_entity(const fido_user_t *);
42
cbor_item_t *es256_pk_encode(const es256_pk_t *, int);
43
44
/* cbor decoding functions */
45
int cbor_decode_attstmt(const cbor_item_t *, fido_attstmt_t *);
46
int cbor_decode_cred_authdata(const cbor_item_t *, int, fido_blob_t *,
47
    fido_authdata_t *, fido_attcred_t *, fido_cred_ext_t *);
48
int cbor_decode_assert_authdata(const cbor_item_t *, fido_blob_t *,
49
    fido_authdata_t *, int *, fido_blob_t *);
50
int cbor_decode_cred_id(const cbor_item_t *, fido_blob_t *);
51
int cbor_decode_fmt(const cbor_item_t *, char **);
52
int cbor_decode_pubkey(const cbor_item_t *, int *, void *);
53
int cbor_decode_rp_entity(const cbor_item_t *, fido_rp_t *);
54
int cbor_decode_uint64(const cbor_item_t *, uint64_t *);
55
int cbor_decode_user(const cbor_item_t *, fido_user_t *);
56
int es256_pk_decode(const cbor_item_t *, es256_pk_t *);
57
int rs256_pk_decode(const cbor_item_t *, rs256_pk_t *);
58
int eddsa_pk_decode(const cbor_item_t *, eddsa_pk_t *);
59
60
/* auxiliary cbor routines */
61
int cbor_add_bool(cbor_item_t *, const char *, fido_opt_t);
62
int cbor_add_bytestring(cbor_item_t *, const char *, const unsigned char *,
63
    size_t);
64
int cbor_add_string(cbor_item_t *, const char *, const char *);
65
int cbor_array_iter(const cbor_item_t *, void *, int(*)(const cbor_item_t *,
66
    void *));
67
int cbor_build_frame(uint8_t, cbor_item_t *[], size_t, fido_blob_t *);
68
int cbor_bytestring_copy(const cbor_item_t *, unsigned char **, size_t *);
69
int cbor_map_iter(const cbor_item_t *, void *, int(*)(const cbor_item_t *,
70
    const cbor_item_t *, void *));
71
int cbor_string_copy(const cbor_item_t *, char **);
72
int cbor_parse_reply(const unsigned char *, size_t, void *,
73
    int(*)(const cbor_item_t *, const cbor_item_t *, void *));
74
int cbor_add_pin_params(fido_dev_t *, const fido_blob_t *, const es256_pk_t *,
75
    const fido_blob_t *,const char *, cbor_item_t **, cbor_item_t **);
76
void cbor_vector_free(cbor_item_t **, size_t);
77
78
#ifndef nitems
79
26.3k
#define nitems(_a)      (sizeof((_a)) / sizeof((_a)[0]))
80
#endif
81
82
/* buf */
83
int fido_buf_read(const unsigned char **, size_t *, void *, size_t);
84
int fido_buf_write(unsigned char **, size_t *, const void *, size_t);
85
86
/* hid i/o */
87
void *fido_hid_open(const char *);
88
void  fido_hid_close(void *);
89
int fido_hid_read(void *, unsigned char *, size_t, int);
90
int fido_hid_write(void *, const unsigned char *, size_t);
91
size_t fido_hid_report_in_len(void *);
92
size_t fido_hid_report_out_len(void *);
93
94
/* generic i/o */
95
int fido_rx_cbor_status(fido_dev_t *, int);
96
int fido_rx(fido_dev_t *, uint8_t, void *, size_t, int);
97
int fido_tx(fido_dev_t *, uint8_t, const void *, size_t);
98
99
/* log */
100
#ifdef FIDO_NO_DIAGNOSTIC
101
#define fido_log_init(...)      do { /* nothing */ } while (0)
102
#define fido_log_debug(...)     do { /* nothing */ } while (0)
103
#define fido_log_xxd(...)       do { /* nothing */ } while (0)
104
#else
105
#ifdef __GNUC__
106
void fido_log_init(void);
107
void fido_log_debug(const char *, ...)
108
    __attribute__((__format__ (printf, 1, 2)));
109
void fido_log_xxd(const void *, size_t);
110
#else
111
void fido_log_init(void);
112
void fido_log_debug(const char *, ...);
113
void fido_log_xxd(const void *, size_t);
114
#endif /* __GNUC__ */
115
#endif /* FIDO_NO_DIAGNOSTIC */
116
117
/* u2f */
118
int u2f_register(fido_dev_t *, fido_cred_t *, int);
119
int u2f_authenticate(fido_dev_t *, fido_assert_t *, int);
120
int u2f_get_touch_begin(fido_dev_t *);
121
int u2f_get_touch_status(fido_dev_t *, int *, int);
122
123
/* unexposed fido ops */
124
int fido_dev_authkey(fido_dev_t *, es256_pk_t *);
125
int fido_dev_get_cbor_info_wait(fido_dev_t *, fido_cbor_info_t *, int);
126
int fido_dev_get_pin_token(fido_dev_t *, const char *, const fido_blob_t *,
127
    const es256_pk_t *, fido_blob_t *);
128
int fido_do_ecdh(fido_dev_t *, es256_pk_t **, fido_blob_t **);
129
130
/* misc */
131
void fido_assert_reset_rx(fido_assert_t *);
132
void fido_assert_reset_tx(fido_assert_t *);
133
void fido_cred_reset_rx(fido_cred_t *);
134
void fido_cred_reset_tx(fido_cred_t *);
135
int fido_check_rp_id(const char *, const unsigned char *);
136
int fido_check_flags(uint8_t, fido_opt_t, fido_opt_t);
137
138
/* crypto */
139
int fido_verify_sig_es256(const fido_blob_t *, const es256_pk_t *,
140
    const fido_blob_t *);
141
int fido_verify_sig_rs256(const fido_blob_t *, const rs256_pk_t *,
142
    const fido_blob_t *);
143
int fido_verify_sig_eddsa(const fido_blob_t *, const eddsa_pk_t *,
144
    const fido_blob_t *);
145
int fido_get_signed_hash(int, fido_blob_t *, const fido_blob_t *,
146
    const fido_blob_t *);
147
148
/* hid device manifest */
149
int fido_hid_manifest(fido_dev_info_t *, size_t, size_t *);
150
151
/* device manifest registration */
152
typedef int (*dev_manifest_func_t)(fido_dev_info_t *, size_t, size_t *);
153
int fido_dev_register_manifest_func(const dev_manifest_func_t);
154
void fido_dev_unregister_manifest_func(const dev_manifest_func_t);
155
156
/* fuzzing instrumentation */
157
#ifdef FIDO_FUZZ
158
uint32_t uniform_random(uint32_t);
159
#endif
160
161
/* internal device capability flags */
162
4.30k
#define FIDO_DEV_PIN_SET        0x01
163
4.23k
#define FIDO_DEV_PIN_UNSET      0x02
164
3.89k
#define FIDO_DEV_CRED_PROT      0x04
165
166
/* miscellanea */
167
2.78k
#define FIDO_DUMMY_CLIENTDATA   ""
168
1.45k
#define FIDO_DUMMY_RP_ID        "localhost"
169
103
#define FIDO_DUMMY_USER_NAME    "dummy"
170
1.44k
#define FIDO_DUMMY_USER_ID      1
171
172
#ifdef __cplusplus
173
} /* extern "C" */
174
#endif /* __cplusplus */
175
176
#endif /* !_EXTERN_H */