10afa8e06SEd Maste /* 20afa8e06SEd Maste * Copyright (c) 2018 Yubico AB. All rights reserved. 30afa8e06SEd Maste * Use of this source code is governed by a BSD-style 40afa8e06SEd Maste * license that can be found in the LICENSE file. 50afa8e06SEd Maste */ 60afa8e06SEd Maste 70afa8e06SEd Maste #ifndef _FIDO_H 80afa8e06SEd Maste #define _FIDO_H 90afa8e06SEd Maste 100afa8e06SEd Maste #include <openssl/ec.h> 110afa8e06SEd Maste #include <openssl/evp.h> 120afa8e06SEd Maste 130afa8e06SEd Maste #include <stdbool.h> 140afa8e06SEd Maste #include <stdint.h> 150afa8e06SEd Maste #include <stdlib.h> 160afa8e06SEd Maste 170afa8e06SEd Maste #ifdef _FIDO_INTERNAL 180afa8e06SEd Maste #include <sys/types.h> 190afa8e06SEd Maste 200afa8e06SEd Maste #include <cbor.h> 210afa8e06SEd Maste #include <limits.h> 220afa8e06SEd Maste 230afa8e06SEd Maste #include "../openbsd-compat/openbsd-compat.h" 240afa8e06SEd Maste #include "blob.h" 250afa8e06SEd Maste #include "iso7816.h" 260afa8e06SEd Maste #include "extern.h" 270afa8e06SEd Maste #endif 280afa8e06SEd Maste 290afa8e06SEd Maste #include "fido/err.h" 300afa8e06SEd Maste #include "fido/param.h" 310afa8e06SEd Maste #include "fido/types.h" 320afa8e06SEd Maste 330afa8e06SEd Maste #ifdef __cplusplus 340afa8e06SEd Maste extern "C" { 350afa8e06SEd Maste #endif /* __cplusplus */ 360afa8e06SEd Maste 370afa8e06SEd Maste fido_assert_t *fido_assert_new(void); 380afa8e06SEd Maste fido_cred_t *fido_cred_new(void); 390afa8e06SEd Maste fido_dev_t *fido_dev_new(void); 400afa8e06SEd Maste fido_dev_t *fido_dev_new_with_info(const fido_dev_info_t *); 410afa8e06SEd Maste fido_dev_info_t *fido_dev_info_new(size_t); 420afa8e06SEd Maste fido_cbor_info_t *fido_cbor_info_new(void); 43*3e696dfbSEd Maste void *fido_dev_io_handle(const fido_dev_t *); 440afa8e06SEd Maste 450afa8e06SEd Maste void fido_assert_free(fido_assert_t **); 460afa8e06SEd Maste void fido_cbor_info_free(fido_cbor_info_t **); 470afa8e06SEd Maste void fido_cred_free(fido_cred_t **); 480afa8e06SEd Maste void fido_dev_force_fido2(fido_dev_t *); 490afa8e06SEd Maste void fido_dev_force_u2f(fido_dev_t *); 500afa8e06SEd Maste void fido_dev_free(fido_dev_t **); 510afa8e06SEd Maste void fido_dev_info_free(fido_dev_info_t **, size_t); 520afa8e06SEd Maste 530afa8e06SEd Maste /* fido_init() flags. */ 540afa8e06SEd Maste #define FIDO_DEBUG 0x01 550afa8e06SEd Maste #define FIDO_DISABLE_U2F_FALLBACK 0x02 560afa8e06SEd Maste 570afa8e06SEd Maste void fido_init(int); 580afa8e06SEd Maste void fido_set_log_handler(fido_log_handler_t *); 590afa8e06SEd Maste 600afa8e06SEd Maste const unsigned char *fido_assert_authdata_ptr(const fido_assert_t *, size_t); 610afa8e06SEd Maste const unsigned char *fido_assert_clientdata_hash_ptr(const fido_assert_t *); 620afa8e06SEd Maste const unsigned char *fido_assert_hmac_secret_ptr(const fido_assert_t *, size_t); 630afa8e06SEd Maste const unsigned char *fido_assert_id_ptr(const fido_assert_t *, size_t); 640afa8e06SEd Maste const unsigned char *fido_assert_largeblob_key_ptr(const fido_assert_t *, size_t); 650afa8e06SEd Maste const unsigned char *fido_assert_sig_ptr(const fido_assert_t *, size_t); 660afa8e06SEd Maste const unsigned char *fido_assert_user_id_ptr(const fido_assert_t *, size_t); 670afa8e06SEd Maste const unsigned char *fido_assert_blob_ptr(const fido_assert_t *, size_t); 680afa8e06SEd Maste 690afa8e06SEd Maste char **fido_cbor_info_extensions_ptr(const fido_cbor_info_t *); 700afa8e06SEd Maste char **fido_cbor_info_options_name_ptr(const fido_cbor_info_t *); 710afa8e06SEd Maste char **fido_cbor_info_transports_ptr(const fido_cbor_info_t *); 720afa8e06SEd Maste char **fido_cbor_info_versions_ptr(const fido_cbor_info_t *); 730afa8e06SEd Maste const bool *fido_cbor_info_options_value_ptr(const fido_cbor_info_t *); 740afa8e06SEd Maste const char *fido_assert_rp_id(const fido_assert_t *); 750afa8e06SEd Maste const char *fido_assert_user_display_name(const fido_assert_t *, size_t); 760afa8e06SEd Maste const char *fido_assert_user_icon(const fido_assert_t *, size_t); 770afa8e06SEd Maste const char *fido_assert_user_name(const fido_assert_t *, size_t); 780afa8e06SEd Maste const char *fido_cbor_info_algorithm_type(const fido_cbor_info_t *, size_t); 790afa8e06SEd Maste const char *fido_cred_display_name(const fido_cred_t *); 800afa8e06SEd Maste const char *fido_cred_fmt(const fido_cred_t *); 810afa8e06SEd Maste const char *fido_cred_rp_id(const fido_cred_t *); 820afa8e06SEd Maste const char *fido_cred_rp_name(const fido_cred_t *); 830afa8e06SEd Maste const char *fido_cred_user_name(const fido_cred_t *); 840afa8e06SEd Maste const char *fido_dev_info_manufacturer_string(const fido_dev_info_t *); 850afa8e06SEd Maste const char *fido_dev_info_path(const fido_dev_info_t *); 860afa8e06SEd Maste const char *fido_dev_info_product_string(const fido_dev_info_t *); 870afa8e06SEd Maste const fido_dev_info_t *fido_dev_info_ptr(const fido_dev_info_t *, size_t); 880afa8e06SEd Maste const uint8_t *fido_cbor_info_protocols_ptr(const fido_cbor_info_t *); 890afa8e06SEd Maste const unsigned char *fido_cbor_info_aaguid_ptr(const fido_cbor_info_t *); 90f540a430SEd Maste const unsigned char *fido_cred_aaguid_ptr(const fido_cred_t *); 91f540a430SEd Maste const unsigned char *fido_cred_attstmt_ptr(const fido_cred_t *); 920afa8e06SEd Maste const unsigned char *fido_cred_authdata_ptr(const fido_cred_t *); 930afa8e06SEd Maste const unsigned char *fido_cred_authdata_raw_ptr(const fido_cred_t *); 940afa8e06SEd Maste const unsigned char *fido_cred_clientdata_hash_ptr(const fido_cred_t *); 950afa8e06SEd Maste const unsigned char *fido_cred_id_ptr(const fido_cred_t *); 96f540a430SEd Maste const unsigned char *fido_cred_largeblob_key_ptr(const fido_cred_t *); 970afa8e06SEd Maste const unsigned char *fido_cred_pubkey_ptr(const fido_cred_t *); 980afa8e06SEd Maste const unsigned char *fido_cred_sig_ptr(const fido_cred_t *); 99f540a430SEd Maste const unsigned char *fido_cred_user_id_ptr(const fido_cred_t *); 1000afa8e06SEd Maste const unsigned char *fido_cred_x5c_ptr(const fido_cred_t *); 1010afa8e06SEd Maste 1020afa8e06SEd Maste int fido_assert_allow_cred(fido_assert_t *, const unsigned char *, size_t); 1030afa8e06SEd Maste int fido_assert_set_authdata(fido_assert_t *, size_t, const unsigned char *, 1040afa8e06SEd Maste size_t); 1050afa8e06SEd Maste int fido_assert_set_authdata_raw(fido_assert_t *, size_t, const unsigned char *, 1060afa8e06SEd Maste size_t); 1070afa8e06SEd Maste int fido_assert_set_clientdata(fido_assert_t *, const unsigned char *, size_t); 1080afa8e06SEd Maste int fido_assert_set_clientdata_hash(fido_assert_t *, const unsigned char *, 1090afa8e06SEd Maste size_t); 1100afa8e06SEd Maste int fido_assert_set_count(fido_assert_t *, size_t); 1110afa8e06SEd Maste int fido_assert_set_extensions(fido_assert_t *, int); 1120afa8e06SEd Maste int fido_assert_set_hmac_salt(fido_assert_t *, const unsigned char *, size_t); 1130afa8e06SEd Maste int fido_assert_set_hmac_secret(fido_assert_t *, size_t, const unsigned char *, 1140afa8e06SEd Maste size_t); 1150afa8e06SEd Maste int fido_assert_set_options(fido_assert_t *, bool, bool); 1160afa8e06SEd Maste int fido_assert_set_rp(fido_assert_t *, const char *); 1170afa8e06SEd Maste int fido_assert_set_up(fido_assert_t *, fido_opt_t); 1180afa8e06SEd Maste int fido_assert_set_uv(fido_assert_t *, fido_opt_t); 1190afa8e06SEd Maste int fido_assert_set_sig(fido_assert_t *, size_t, const unsigned char *, size_t); 1200afa8e06SEd Maste int fido_assert_verify(const fido_assert_t *, size_t, int, const void *); 1210afa8e06SEd Maste int fido_cbor_info_algorithm_cose(const fido_cbor_info_t *, size_t); 1220afa8e06SEd Maste int fido_cred_exclude(fido_cred_t *, const unsigned char *, size_t); 1230afa8e06SEd Maste int fido_cred_prot(const fido_cred_t *); 124f540a430SEd Maste int fido_cred_set_attstmt(fido_cred_t *, const unsigned char *, size_t); 1250afa8e06SEd Maste int fido_cred_set_authdata(fido_cred_t *, const unsigned char *, size_t); 1260afa8e06SEd Maste int fido_cred_set_authdata_raw(fido_cred_t *, const unsigned char *, size_t); 1270afa8e06SEd Maste int fido_cred_set_blob(fido_cred_t *, const unsigned char *, size_t); 1280afa8e06SEd Maste int fido_cred_set_clientdata(fido_cred_t *, const unsigned char *, size_t); 1290afa8e06SEd Maste int fido_cred_set_clientdata_hash(fido_cred_t *, const unsigned char *, size_t); 1300afa8e06SEd Maste int fido_cred_set_extensions(fido_cred_t *, int); 1310afa8e06SEd Maste int fido_cred_set_fmt(fido_cred_t *, const char *); 1320afa8e06SEd Maste int fido_cred_set_id(fido_cred_t *, const unsigned char *, size_t); 1330afa8e06SEd Maste int fido_cred_set_options(fido_cred_t *, bool, bool); 134f540a430SEd Maste int fido_cred_set_pin_minlen(fido_cred_t *, size_t); 1350afa8e06SEd Maste int fido_cred_set_prot(fido_cred_t *, int); 1360afa8e06SEd Maste int fido_cred_set_rk(fido_cred_t *, fido_opt_t); 1370afa8e06SEd Maste int fido_cred_set_rp(fido_cred_t *, const char *, const char *); 1380afa8e06SEd Maste int fido_cred_set_sig(fido_cred_t *, const unsigned char *, size_t); 1390afa8e06SEd Maste int fido_cred_set_type(fido_cred_t *, int); 1400afa8e06SEd Maste int fido_cred_set_uv(fido_cred_t *, fido_opt_t); 1410afa8e06SEd Maste int fido_cred_type(const fido_cred_t *); 1420afa8e06SEd Maste int fido_cred_set_user(fido_cred_t *, const unsigned char *, size_t, 1430afa8e06SEd Maste const char *, const char *, const char *); 1440afa8e06SEd Maste int fido_cred_set_x509(fido_cred_t *, const unsigned char *, size_t); 1450afa8e06SEd Maste int fido_cred_verify(const fido_cred_t *); 1460afa8e06SEd Maste int fido_cred_verify_self(const fido_cred_t *); 1470afa8e06SEd Maste int fido_dev_set_sigmask(fido_dev_t *, const fido_sigset_t *); 1480afa8e06SEd Maste int fido_dev_cancel(fido_dev_t *); 1490afa8e06SEd Maste int fido_dev_close(fido_dev_t *); 1500afa8e06SEd Maste int fido_dev_get_assert(fido_dev_t *, fido_assert_t *, const char *); 1510afa8e06SEd Maste int fido_dev_get_cbor_info(fido_dev_t *, fido_cbor_info_t *); 1520afa8e06SEd Maste int fido_dev_get_retry_count(fido_dev_t *, int *); 1530afa8e06SEd Maste int fido_dev_get_uv_retry_count(fido_dev_t *, int *); 1540afa8e06SEd Maste int fido_dev_get_touch_begin(fido_dev_t *); 1550afa8e06SEd Maste int fido_dev_get_touch_status(fido_dev_t *, int *, int); 1560afa8e06SEd Maste int fido_dev_info_manifest(fido_dev_info_t *, size_t, size_t *); 157*3e696dfbSEd Maste int fido_dev_info_set(fido_dev_info_t *, size_t, const char *, const char *, 158*3e696dfbSEd Maste const char *, const fido_dev_io_t *, const fido_dev_transport_t *); 1590afa8e06SEd Maste int fido_dev_make_cred(fido_dev_t *, fido_cred_t *, const char *); 1600afa8e06SEd Maste int fido_dev_open_with_info(fido_dev_t *); 1610afa8e06SEd Maste int fido_dev_open(fido_dev_t *, const char *); 1620afa8e06SEd Maste int fido_dev_reset(fido_dev_t *); 1630afa8e06SEd Maste int fido_dev_set_io_functions(fido_dev_t *, const fido_dev_io_t *); 1640afa8e06SEd Maste int fido_dev_set_pin(fido_dev_t *, const char *, const char *); 1650afa8e06SEd Maste int fido_dev_set_transport_functions(fido_dev_t *, const fido_dev_transport_t *); 166f540a430SEd Maste int fido_dev_set_timeout(fido_dev_t *, int); 1670afa8e06SEd Maste 1680afa8e06SEd Maste size_t fido_assert_authdata_len(const fido_assert_t *, size_t); 1690afa8e06SEd Maste size_t fido_assert_clientdata_hash_len(const fido_assert_t *); 1700afa8e06SEd Maste size_t fido_assert_count(const fido_assert_t *); 1710afa8e06SEd Maste size_t fido_assert_hmac_secret_len(const fido_assert_t *, size_t); 1720afa8e06SEd Maste size_t fido_assert_id_len(const fido_assert_t *, size_t); 1730afa8e06SEd Maste size_t fido_assert_largeblob_key_len(const fido_assert_t *, size_t); 1740afa8e06SEd Maste size_t fido_assert_sig_len(const fido_assert_t *, size_t); 1750afa8e06SEd Maste size_t fido_assert_user_id_len(const fido_assert_t *, size_t); 1760afa8e06SEd Maste size_t fido_assert_blob_len(const fido_assert_t *, size_t); 1770afa8e06SEd Maste size_t fido_cbor_info_aaguid_len(const fido_cbor_info_t *); 1780afa8e06SEd Maste size_t fido_cbor_info_algorithm_count(const fido_cbor_info_t *); 1790afa8e06SEd Maste size_t fido_cbor_info_extensions_len(const fido_cbor_info_t *); 1800afa8e06SEd Maste size_t fido_cbor_info_options_len(const fido_cbor_info_t *); 1810afa8e06SEd Maste size_t fido_cbor_info_protocols_len(const fido_cbor_info_t *); 1820afa8e06SEd Maste size_t fido_cbor_info_transports_len(const fido_cbor_info_t *); 1830afa8e06SEd Maste size_t fido_cbor_info_versions_len(const fido_cbor_info_t *); 184f540a430SEd Maste size_t fido_cred_aaguid_len(const fido_cred_t *); 185f540a430SEd Maste size_t fido_cred_attstmt_len(const fido_cred_t *); 1860afa8e06SEd Maste size_t fido_cred_authdata_len(const fido_cred_t *); 1870afa8e06SEd Maste size_t fido_cred_authdata_raw_len(const fido_cred_t *); 1880afa8e06SEd Maste size_t fido_cred_clientdata_hash_len(const fido_cred_t *); 1890afa8e06SEd Maste size_t fido_cred_id_len(const fido_cred_t *); 190f540a430SEd Maste size_t fido_cred_largeblob_key_len(const fido_cred_t *); 191f540a430SEd Maste size_t fido_cred_pin_minlen(const fido_cred_t *); 1920afa8e06SEd Maste size_t fido_cred_pubkey_len(const fido_cred_t *); 1930afa8e06SEd Maste size_t fido_cred_sig_len(const fido_cred_t *); 194f540a430SEd Maste size_t fido_cred_user_id_len(const fido_cred_t *); 1950afa8e06SEd Maste size_t fido_cred_x5c_len(const fido_cred_t *); 1960afa8e06SEd Maste 1970afa8e06SEd Maste uint8_t fido_assert_flags(const fido_assert_t *, size_t); 1980afa8e06SEd Maste uint32_t fido_assert_sigcount(const fido_assert_t *, size_t); 1990afa8e06SEd Maste uint8_t fido_cred_flags(const fido_cred_t *); 2000afa8e06SEd Maste uint32_t fido_cred_sigcount(const fido_cred_t *); 2010afa8e06SEd Maste uint8_t fido_dev_protocol(const fido_dev_t *); 2020afa8e06SEd Maste uint8_t fido_dev_major(const fido_dev_t *); 2030afa8e06SEd Maste uint8_t fido_dev_minor(const fido_dev_t *); 2040afa8e06SEd Maste uint8_t fido_dev_build(const fido_dev_t *); 2050afa8e06SEd Maste uint8_t fido_dev_flags(const fido_dev_t *); 2060afa8e06SEd Maste int16_t fido_dev_info_vendor(const fido_dev_info_t *); 2070afa8e06SEd Maste int16_t fido_dev_info_product(const fido_dev_info_t *); 2080afa8e06SEd Maste uint64_t fido_cbor_info_maxmsgsiz(const fido_cbor_info_t *); 2090afa8e06SEd Maste uint64_t fido_cbor_info_maxcredbloblen(const fido_cbor_info_t *); 2100afa8e06SEd Maste uint64_t fido_cbor_info_maxcredcntlst(const fido_cbor_info_t *); 2110afa8e06SEd Maste uint64_t fido_cbor_info_maxcredidlen(const fido_cbor_info_t *); 2120afa8e06SEd Maste uint64_t fido_cbor_info_fwversion(const fido_cbor_info_t *); 2130afa8e06SEd Maste 2140afa8e06SEd Maste bool fido_dev_has_pin(const fido_dev_t *); 2150afa8e06SEd Maste bool fido_dev_has_uv(const fido_dev_t *); 2160afa8e06SEd Maste bool fido_dev_is_fido2(const fido_dev_t *); 2170afa8e06SEd Maste bool fido_dev_is_winhello(const fido_dev_t *); 2180afa8e06SEd Maste bool fido_dev_supports_credman(const fido_dev_t *); 219*3e696dfbSEd Maste bool fido_dev_supports_cred_prot(const fido_dev_t *); 220*3e696dfbSEd Maste bool fido_dev_supports_permissions(const fido_dev_t *); 221*3e696dfbSEd Maste bool fido_dev_supports_pin(const fido_dev_t *); 2220afa8e06SEd Maste bool fido_dev_supports_uv(const fido_dev_t *); 2230afa8e06SEd Maste 2240afa8e06SEd Maste int fido_dev_largeblob_get(fido_dev_t *, const unsigned char *, size_t, 2250afa8e06SEd Maste unsigned char **, size_t *); 2260afa8e06SEd Maste int fido_dev_largeblob_set(fido_dev_t *, const unsigned char *, size_t, 2270afa8e06SEd Maste const unsigned char *, size_t, const char *); 2280afa8e06SEd Maste int fido_dev_largeblob_remove(fido_dev_t *, const unsigned char *, size_t, 2290afa8e06SEd Maste const char *); 2300afa8e06SEd Maste int fido_dev_largeblob_get_array(fido_dev_t *, unsigned char **, size_t *); 2310afa8e06SEd Maste int fido_dev_largeblob_set_array(fido_dev_t *, const unsigned char *, size_t, 2320afa8e06SEd Maste const char *); 2330afa8e06SEd Maste 2340afa8e06SEd Maste #ifdef __cplusplus 2350afa8e06SEd Maste } /* extern "C" */ 2360afa8e06SEd Maste #endif /* __cplusplus */ 2370afa8e06SEd Maste 2380afa8e06SEd Maste #endif /* !_FIDO_H */ 239