Loading...
Searching...
No Matches
ctap.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021 Freie Universität Berlin
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
25#ifndef FIDO2_CTAP_CTAP_H
26#define FIDO2_CTAP_CTAP_H
27
28#include <stdint.h>
29
30#include "mutex.h"
31#include "cbor.h"
32#include "assert.h"
33#include "crypto/modes/ccm.h"
34#include "timex.h"
35#include "board.h"
36
37#include "fido2/ctap.h"
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
51#define CTAP_PIN_AUTH_SZ 16
52
58#define CTAP_MAKE_CREDENTIAL 0x01
59#define CTAP_GET_ASSERTION 0x02
60#define CTAP_GET_INFO 0x04
61#define CTAP_CLIENT_PIN 0x06
62#define CTAP_RESET 0x07
63#define CTAP_GET_NEXT_ASSERTION 0x08
71#define CTAP_AUTH_DATA_FLAG_UP (1 << 0)
72#define CTAP_AUTH_DATA_FLAG_UV (1 << 2)
73#define CTAP_AUTH_DATA_FLAG_AT (1 << 6)
74#define CTAP_AUTH_DATA_FLAG_ED (1 << 7)
82#define CTAP_VERSION_FLAG_FIDO_PRE 0x01
83#define CTAP_VERSION_FLAG_FIDO 0x02
84#define CTAP_VERSION_FLAG_U2F_V2 0x04
94#define CTAP_GET_INFO_RESP_OPTIONS_ID_PLAT "plat"
95#define CTAP_GET_INFO_RESP_OPTIONS_ID_RK "rk"
96#define CTAP_GET_INFO_RESP_OPTIONS_ID_CLIENT_PIN "clientPin"
97#define CTAP_GET_INFO_RESP_OPTIONS_ID_UP "up"
98#define CTAP_GET_INFO_RESP_OPTIONS_ID_UV "uv"
106#define CTAP_INFO_OPTIONS_FLAG_PLAT (1 << 0)
107#define CTAP_INFO_OPTIONS_FLAG_RK (1 << 1)
108#define CTAP_INFO_OPTIONS_FLAG_CLIENT_PIN (1 << 2)
109#define CTAP_INFO_OPTIONS_FLAG_UP (1 << 3)
110#define CTAP_INFO_OPTIONS_FLAG_UV (1 << 4)
118#define CTAP_CP_REQ_SUB_COMMAND_GET_RETRIES 0x01
119#define CTAP_CP_REQ_SUB_COMMAND_GET_KEY_AGREEMENT 0x02
120#define CTAP_CP_REQ_SUB_COMMAND_SET_PIN 0x03
121#define CTAP_CP_REQ_SUB_COMMAND_CHANGE_PIN 0x04
122#define CTAP_CP_REQ_SUB_COMMAND_GET_PIN_TOKEN 0x05
128#ifdef CONFIG_FIDO2_CTAP_STACK_SIZE
129#define CTAP_STACKSIZE CONFIG_FIDO2_CTAP_STACK_SIZE
130#else
131#define CTAP_STACKSIZE 15000
132#endif
133
137#if defined(CONFIG_FIDO2_CTAP_UP_BUTTON_PORT) && defined(CONFIG_FIDO2_CTAP_UP_BUTTON_PIN) && \
138 (CONFIG_FIDO2_CTAP_UP_BUTTON_PORT >= 0) && (CONFIG_FIDO2_CTAP_UP_BUTTON_PIN >= 0)
139#define CTAP_UP_BUTTON GPIO_PIN(CONFIG_FIDO2_CTAP_UP_BUTTON_PORT, CONFIG_FIDO2_CTAP_UP_BUTTON_PIN)
140#else
141/* set default button if no button is configured */
142#ifdef BTN0_PIN
143#define CTAP_UP_BUTTON BTN0_PIN
144#else
145#define CTAP_UP_BUTTON 0
149#define CONFIG_FIDO2_CTAP_DISABLE_UP 1
150#endif /* BTN0_PIN */
151#endif
152
156#if IS_ACTIVE(CONFIG_FIDO2_CTAP_UP_BUTTON_MODE_IN_PU)
157#define CTAP_UP_BUTTON_MODE GPIO_IN_PU
158#elif IS_ACTIVE(CONFIG_FIDO2_CTAP_UP_BUTTON_MODE_IN_PD)
159#define CTAP_UP_BUTTON_MODE GPIO_IN_PD
160#elif IS_ACTIVE(CONFIG_FIDO2_CTAP_UP_BUTTON_MODE_IN)
161#define CTAP_UP_BUTTON_MODE GPIO_IN
162#else
163#define CTAP_UP_BUTTON_MODE GPIO_IN_PU
164#endif
165
169#if IS_ACTIVE(CONFIG_FIDO2_CTAP_UP_BUTTON_FLANK_FALLING)
170#define CTAP_UP_BUTTON_FLANK GPIO_FALLING
171#elif IS_ACTIVE(CONFIG_FIDO2_CTAP_UP_BUTTON_FLANK_RISING)
172#define CTAP_UP_BUTTON_FLANK GPIO_RISING
173#elif IS_ACTIVE(CONFIG_FIDO2_CTAP_UP_BUTTON_FLANK_BOTH)
174#define CTAP_UP_BUTTON_FLANK GPIO_BOTH
175#else
176#define CTAP_UP_BUTTON_FLANK GPIO_FALLING
177#endif
178
182#ifndef CONFIG_FIDO2_CTAP_DISABLE_UP
183#define CONFIG_FIDO2_CTAP_DISABLE_UP 0
184#endif
185
189#ifndef CONFIG_FIDO2_CTAP_DISABLE_LED
190#define CONFIG_FIDO2_CTAP_DISABLE_LED 0
191#endif
192
196#define CTAP_RP_MAX_NAME_SIZE 32
197
201#define CTAP_USER_MAX_NAME_SIZE 64 + 1
202
206#define CTAP_USER_ID_MAX_SIZE 64
207
211#define CTAP_DOMAIN_NAME_MAX_SIZE 253 + 1
212
216#define CTAP_ICON_MAX_SIZE 128 + 1
217
221#define CTAP_PIN_MIN_SIZE 4
222
229#define CTAP_PIN_ENC_MIN_SIZE 64
230
235#define CTAP_PIN_ENC_MAX_SIZE 256
236
240#define CTAP_PIN_MAX_SIZE 64
241
245#define CTAP_PIN_MAX_ATTS 8
246
250#define CTAP_PIN_MAX_ATTS_BOOT 3
251
255#define CTAP_PIN_PROT_VER 1
256
260#define CTAP_AMT_SUP_PIN_VER 1
261
267#define CTAP_PIN_TOKEN_SZ 16
268
276#define CTAP_CRED_KEY_LEN 16
277
285#define CTAP_AES_CCM_L 2
286
290#define CTAP_AES_CCM_NONCE_SIZE (15 - CTAP_AES_CCM_L)
291
297#define CTAP_CREDENTIAL_ID_ENC_SIZE (sizeof(struct ctap_resident_key) - \
298 sizeof(((struct ctap_resident_key *)0)-> \
299 cred_desc.cred_id) - \
300 sizeof(((struct ctap_resident_key *)0)-> \
301 cred_desc.has_nonce))
302
306#ifdef CONFIG_FIDO2_CTAP_UP_TIMEOUT
307#define CTAP_UP_TIMEOUT (CONFIG_FIDO2_CTAP_UP_TIMEOUT * MS_PER_SEC)
308#else
309#define CTAP_UP_TIMEOUT (15 * MS_PER_SEC)
310#endif
311
316#define CTAP_GET_NEXT_ASSERTION_TIMEOUT (30 * MS_PER_SEC)
317
321#ifdef CONFIG_FIDO2_CTAP_DEVICE_AAGUID
322#define CTAP_AAGUID CONFIG_FIDO2_CTAP_DEVICE_AAGUID
323#else
324/* randomly generated fallback value */
325#define CTAP_AAGUID "9c295865fa2c36b705a42320af9c8f16"
326#endif
327
333#define CTAP_PUB_KEY_CRED_PUB_KEY 0x01
334#define CTAP_PUB_KEY_CRED_UNKNOWN 0x02
342#define CTAP_COSE_KEY_LABEL_KTY 1
343#define CTAP_COSE_KEY_LABEL_ALG 3
344#define CTAP_COSE_KEY_LABEL_CRV -1
345#define CTAP_COSE_KEY_LABEL_X -2
346#define CTAP_COSE_KEY_LABEL_Y -3
347#define CTAP_COSE_KEY_KTY_EC2 2
348#define CTAP_COSE_KEY_CRV_P256 1
354#define CTAP_AAGUID_SIZE 16
355
359#define CTAP_COSE_ALG_ES256 -7
360
364#define CTAP_COSE_ALG_ECDH_ES_HKDF_256 -25
365
370#define CTAP_CREDENTIAL_ID_SIZE 16U
371
378#define CTAP_INITIALIZED_MARKER 0x4e
379
383#define CTAP_MAX_EXCLUDE_LIST_SIZE 0x14
384
389
394
399
403typedef struct {
404 uint8_t aaguid[CTAP_AAGUID_SIZE];
405 uint8_t options;
407
425
429typedef struct {
430 int rk;
431 int uv;
432 int up;
434
438typedef struct {
440 uint8_t id_len;
442 uint8_t display_name[CTAP_USER_MAX_NAME_SIZE];
445
450typedef struct {
452 uint8_t id_len;
454 uint8_t name[CTAP_RP_MAX_NAME_SIZE + 1];
456 uint8_t icon[CTAP_DOMAIN_NAME_MAX_SIZE + 1];
459
472
482 uint8_t cred_type;
483 union {
486 };
489};
490
497struct __attribute__((packed)) ctap_resident_key {
498 uint8_t rp_id_hash[SHA256_DIGEST_LENGTH];
499 uint8_t user_id[CTAP_USER_ID_MAX_SIZE];
500 uint8_t user_id_len;
501 uint8_t priv_key[CTAP_CRYPTO_KEY_SIZE];
502 uint16_t id;
503 uint32_t sign_count;
508};
509
516typedef struct __attribute__((packed)) {
518 uint8_t mac[CCM_MAC_MAX_LEN];
519 uint8_t nonce[CTAP_AES_CCM_NONCE_SIZE];
521
531
549
565
581
587typedef struct __attribute__((packed)){
588 uint8_t aaguid[CTAP_AAGUID_SIZE];
589 uint8_t cred_len_h;
590 uint8_t cred_len_l;
593
601
607typedef struct __attribute__((packed)){
608 uint8_t rp_id_hash[SHA256_DIGEST_LENGTH];
609 uint8_t flags;
610 uint32_t sign_count;
612
620
624typedef struct {
625 uint16_t max_msg_size;
626 uint8_t aaguid[CTAP_AAGUID_SIZE];
627 uint8_t versions;
628 uint8_t options;
629 uint8_t pin_protocol;
632
647int fido2_ctap_get_sig(const uint8_t *auth_data, size_t auth_data_len,
648 const uint8_t *client_data_hash,
649 const ctap_resident_key_t *rk,
650 uint8_t *sig, size_t *sig_len);
651
661bool fido2_ctap_cred_params_supported(uint8_t cred_type, int32_t alg_type);
662
674 size_t nonce_len, ctap_cred_id_t *id);
675
683
690
691#ifdef __cplusplus
692}
693#endif
694#endif /* FIDO2_CTAP_CTAP_H */
POSIX.1-2008 compliant version of the assert macro.
Functionality for encoding SenML values as CBOR.
Counter with CBC-MAC mode of operation for block ciphers.
#define CCM_MAC_MAX_LEN
Maximum length for the appended MAC.
Definition ccm.h:48
Public FIDO2 CTAP defines, structures and function declarations.
FIDO2 CTAP crypto helper defines, structures and function declarations.
#define CTAP_CRYPTO_KEY_SIZE
Size in bytes of cryptographic keys used.
Definition ctap_crypto.h:37
bool fido2_ctap_cred_params_supported(uint8_t cred_type, int32_t alg_type)
Check if requested algorithm is supported.
#define CTAP_CREDENTIAL_ID_SIZE
CTAP size of credential id.
Definition ctap.h:370
int fido2_ctap_encrypt_rk(ctap_resident_key_t *rk, uint8_t *nonce, size_t nonce_len, ctap_cred_id_t *id)
Encrypt resident key with AES CCM.
int fido2_ctap_get_sig(const uint8_t *auth_data, size_t auth_data_len, const uint8_t *client_data_hash, const ctap_resident_key_t *rk, uint8_t *sig, size_t *sig_len)
Create signature from authenticator data.
#define CTAP_CREDENTIAL_ID_ENC_SIZE
Total size of AES CCM credential id.
Definition ctap.h:297
#define CTAP_PIN_AUTH_SZ
Size of pin auth.
Definition ctap.h:51
#define CTAP_RP_MAX_NAME_SIZE
Max size of relying party name.
Definition ctap.h:196
#define CTAP_PIN_ENC_MAX_SIZE
Encrypted newPin max size.
Definition ctap.h:235
#define CTAP_AAGUID_SIZE
CTAP size of authenticator AAGUID in bytes.
Definition ctap.h:354
ctap_state_t * fido2_ctap_get_state(void)
Get a pointer to the authenticator state.
#define CTAP_DOMAIN_NAME_MAX_SIZE
Max size of a domain name including null character.
Definition ctap.h:211
#define CTAP_MAX_EXCLUDE_LIST_SIZE
Max size of allow list.
Definition ctap.h:383
#define CTAP_USER_ID_MAX_SIZE
Max size of user id.
Definition ctap.h:206
bool fido2_ctap_pin_is_set(void)
Check if PIN has been set on authenticator.
#define CTAP_AES_CCM_NONCE_SIZE
AES CCM nonce size.
Definition ctap.h:290
#define CTAP_USER_MAX_NAME_SIZE
Max size of username including null character.
Definition ctap.h:201
#define CTAP_CRED_KEY_LEN
Size of key used to encrypt credential.
Definition ctap.h:276
#define SHA256_DIGEST_LENGTH
Length of SHA256 digests in bytes.
Definition sha256.h:62
Mutex for thread synchronization.
CTAP attested credential data header struct.
Definition ctap.h:587
ctap_cred_id_t cred_id
credential id
Definition ctap.h:591
uint8_t cred_len_l
lower byte of credential length
Definition ctap.h:590
uint8_t cred_len_h
higher byte of credential length
Definition ctap.h:589
CTAP attested credential data struct.
Definition ctap.h:597
ctap_public_key_cose_t key
cose key
Definition ctap.h:599
ctap_attested_cred_data_header_t header
attested credential data header
Definition ctap.h:598
CTAP authenticator data header struct.
Definition ctap.h:607
uint8_t flags
flags indicating result of user verification
Definition ctap.h:609
uint32_t sign_count
sign count of credential
Definition ctap.h:610
CTAP authenticator data struct.
Definition ctap.h:616
ctap_attested_cred_data_t attested_cred_data
attested credential data
Definition ctap.h:618
ctap_auth_data_header_t header
auth data header
Definition ctap.h:617
CTAP client pin request struct.
Definition ctap.h:569
bool key_agreement_present
indicate if key_agreement present
Definition ctap.h:579
uint16_t new_pin_enc_size
size of encrypted new pin
Definition ctap.h:571
ctap_public_key_cose_t key_agreement
public key of platform_key_agreement_key
Definition ctap.h:570
uint8_t sub_command
authenticator Client PIN sub command
Definition ctap.h:575
bool pin_auth_present
indicate if pin_auth present
Definition ctap.h:578
uint8_t pin_protocol
PIN protocol version chosen by the client.
Definition ctap.h:576
bool pin_hash_enc_present
indicate pin_hash_enc is present
Definition ctap.h:577
CTAP authenticator config struct.
Definition ctap.h:403
uint8_t options
options
Definition ctap.h:405
CTAP credential description alternative struct.
Definition ctap.h:527
uint8_t cred_type
type of credential
Definition ctap.h:528
ctap_cred_id_t cred_id
credential id
Definition ctap.h:529
CTAP credential description struct.
Definition ctap.h:481
uint8_t cred_id[CTAP_CREDENTIAL_ID_SIZE]
credential identifier
Definition ctap.h:484
uint8_t nonce[CTAP_AES_CCM_NONCE_SIZE]
CTAP AES CCM nonce.
Definition ctap.h:485
uint8_t cred_type
type of credential
Definition ctap.h:482
bool has_nonce
Indicate if nonce or cred_id
Definition ctap.h:487
CTAP credential ID.
Definition ctap.h:516
Elliptic curve public key.
Definition ctap_crypto.h:47
CTAP get assertion request struct.
Definition ctap.h:553
uint8_t pin_protocol
PIN protocol version.
Definition ctap.h:562
bool pin_auth_present
indicate if pin_auth present
Definition ctap.h:563
size_t pin_auth_len
pin_auth length
Definition ctap.h:561
uint8_t rp_id_len
Actual Length of Relying Party Identifier.
Definition ctap.h:558
uint8_t allow_list_len
length of CBOR allow list array
Definition ctap.h:559
ctap_options_t options
parameters to influence authenticator operation
Definition ctap.h:554
CTAP info struct.
Definition ctap.h:624
bool pin_is_set
PIN is set or not.
Definition ctap.h:630
uint8_t options
supported options
Definition ctap.h:628
uint8_t pin_protocol
supported PIN protocol versions
Definition ctap.h:629
uint8_t versions
supported versions of FIDO
Definition ctap.h:627
uint16_t max_msg_size
max message size
Definition ctap.h:625
CTAP make credential request struct.
Definition ctap.h:535
ctap_user_ent_t user
user
Definition ctap.h:539
bool pin_auth_present
pin_auth present
Definition ctap.h:545
int32_t alg_type
cryptographic algorithm identifier
Definition ctap.h:544
size_t exclude_list_len
length of CBOR exclude list array
Definition ctap.h:537
ctap_rp_ent_t rp
relying party
Definition ctap.h:538
size_t pin_auth_len
pin_auth len
Definition ctap.h:543
uint8_t cred_type
type of credential
Definition ctap.h:547
ctap_options_t options
parameters to influence authenticator operation
Definition ctap.h:540
uint8_t pin_protocol
PIN protocol version.
Definition ctap.h:546
CTAP options struct.
Definition ctap.h:429
int up
user presence
Definition ctap.h:432
int uv
user verification
Definition ctap.h:431
int rk
resident key
Definition ctap.h:430
CTAP cose key struct.
Definition ctap.h:465
int crv
EC identifier.
Definition ctap.h:468
int32_t alg_type
COSEAlgorithmIdentifier.
Definition ctap.h:469
int kty
identification of key type
Definition ctap.h:467
ctap_crypto_pub_key_t pubkey
public key
Definition ctap.h:466
uint8_t cred_type
type of credential
Definition ctap.h:470
CTAP resident key struct.
Definition ctap.h:497
ctap_cred_desc_t cred_desc
credential descriptor
Definition ctap.h:507
uint32_t sign_count
signature counter.
Definition ctap.h:503
uint8_t user_id_len
length of the user id
Definition ctap.h:500
uint16_t id
internal id of key
Definition ctap.h:502
CTAP relying party entity struct.
Definition ctap.h:450
uint8_t id_len
actual length of relying party identifier
Definition ctap.h:452
CTAP state struct.
Definition ctap.h:413
uint16_t rk_amount_stored
total number of resident keys stored on device
Definition ctap.h:417
int rem_pin_att
remaining PIN tries
Definition ctap.h:416
bool pin_is_set
PIN is set or not.
Definition ctap.h:422
ctap_config_t config
configuration of authenticator
Definition ctap.h:414
bool cred_key_is_initialized
AES CCM key initialized flag.
Definition ctap.h:421
uint8_t initialized_marker
CTAP initialized marker.
Definition ctap.h:418
ctap_crypto_key_agreement_key_t ag_key
Platform key agreement key.
Definition ctap.h:415
uint32_t id_cnt
id counter for credential id
Definition ctap.h:423
CTAP user entity struct.
Definition ctap.h:438
uint8_t id_len
actual length of user id
Definition ctap.h:440
Utility library for comparing and computing timestamps.