|
CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
|
Minimal CBOR reader/writer helpers used by CTAP2 implementation. More...
Go to the source code of this file.
Macros | |
| #define | CBOR_MAX_RECURSION_DEPTH 8 |
| Defensive limits for recursive container skipping. | |
| #define | CBOR_MAX_CONTAINER_SIZE 256 |
Functions | |
| void | cbor_writer_init (cbor_writer_t *w, uint8_t *buffer, size_t size) |
| CBOR writer implementation. | |
| size_t | cbor_writer_length (const cbor_writer_t *w) |
| Returns number of bytes written by CBOR writer. | |
| bool | cbor_writer_error (const cbor_writer_t *w) |
| Returns whether writer encountered an error. | |
| static void | write_byte (cbor_writer_t *w, uint8_t b) |
| Writes one byte to CBOR output buffer. | |
| static void | write_bytes (cbor_writer_t *w, const uint8_t *data, size_t len) |
| Writes byte span to CBOR output buffer. | |
| static void | write_type_value (cbor_writer_t *w, uint8_t type, uint64_t value) |
| Encodes CBOR major type and value header. | |
| void | cbor_encode_uint (cbor_writer_t *w, uint64_t value) |
| Encodes CBOR unsigned integer. | |
| void | cbor_encode_int (cbor_writer_t *w, int64_t value) |
| Encodes CBOR signed integer. | |
| void | cbor_encode_bytes (cbor_writer_t *w, const uint8_t *data, size_t len) |
| Encodes CBOR byte-string. | |
| void | cbor_encode_text (cbor_writer_t *w, const char *str) |
| Encodes CBOR text string. | |
| void | cbor_encode_text_len (cbor_writer_t *w, const char *str, size_t len) |
| Encodes CBOR text string with explicit length. | |
| void | cbor_encode_bool (cbor_writer_t *w, bool value) |
| Encodes CBOR boolean. | |
| void | cbor_encode_null (cbor_writer_t *w) |
| Encodes CBOR null. | |
| void | cbor_encode_array (cbor_writer_t *w, size_t count) |
| Encodes CBOR array header. | |
| void | cbor_encode_map (cbor_writer_t *w, size_t count) |
| Encodes CBOR map header. | |
| void | cbor_encode_cose_key_p256 (cbor_writer_t *w, const uint8_t *x, const uint8_t *y) |
| Encodes COSE P-256 public key map. | |
| void | cbor_encode_cose_key_ed25519 (cbor_writer_t *w, const uint8_t *pubkey) |
| Encodes COSE Ed25519 public key map. | |
| void | cbor_reader_init (cbor_reader_t *r, const uint8_t *data, size_t size) |
| CBOR reader implementation. | |
| bool | cbor_reader_error (const cbor_reader_t *r) |
| Returns whether reader is in error state. | |
| bool | cbor_reader_available (const cbor_reader_t *r) |
| Returns whether unread data remains. | |
| int | cbor_reader_peek_type (const cbor_reader_t *r) |
| Peeks major type of next CBOR item. | |
| static bool | read_byte (cbor_reader_t *r, uint8_t *b) |
| Reads one byte from CBOR reader. | |
| static bool | read_type_value (cbor_reader_t *r, uint8_t *type, uint64_t *value) |
| Reads CBOR item header and decoded value. | |
| bool | cbor_read_item (cbor_reader_t *r, cbor_item_t *item) |
| Reads next CBOR item metadata and optional inline payload pointer. | |
| bool | cbor_read_uint (cbor_reader_t *r, uint64_t *value) |
| Reads CBOR unsigned integer. | |
| bool | cbor_read_int (cbor_reader_t *r, int64_t *value) |
| Reads CBOR integer (positive or negative). | |
| bool | cbor_read_bytes (cbor_reader_t *r, uint8_t *out, size_t max_len, size_t *out_len) |
| Reads CBOR byte-string into optional output buffer. | |
| bool | cbor_read_text (cbor_reader_t *r, char *out, size_t max_len, size_t *out_len) |
| Reads CBOR text string into output buffer. | |
| bool | cbor_read_bool (cbor_reader_t *r, bool *value) |
| Reads CBOR boolean simple value. | |
| int | cbor_read_map (cbor_reader_t *r) |
| Reads CBOR map header and returns pair count. | |
| int | cbor_read_array (cbor_reader_t *r) |
| Reads CBOR array header and returns element count. | |
| static bool | cbor_skip_item_impl (cbor_reader_t *r, uint8_t depth) |
| bool | cbor_skip_item (cbor_reader_t *r) |
| Skips one complete CBOR item including nested container content. | |
| bool | cbor_parse_cose_key (cbor_reader_t *r, int *kty, int *alg, uint8_t *x, uint8_t *y) |
| Parses COSE key map and extracts key type, algorithm, and coordinates. | |
Variables | |
| static const char * | TAG = "CBOR" |
Minimal CBOR reader/writer helpers used by CTAP2 implementation.
Definition in file cbor_helpers.cpp.
| #define CBOR_MAX_CONTAINER_SIZE 256 |
Definition at line 561 of file cbor_helpers.cpp.
Referenced by cbor_skip_item_impl().
| #define CBOR_MAX_RECURSION_DEPTH 8 |
Defensive limits for recursive container skipping.
Definition at line 560 of file cbor_helpers.cpp.
Referenced by cbor_skip_item_impl().
| void cbor_encode_array | ( | cbor_writer_t * | w, |
| size_t | count ) |
Encodes CBOR array header.
| w | Writer context. |
| count | Element count. |
Definition at line 197 of file cbor_helpers.cpp.
References CBOR_ARRAY, and write_type_value().
Referenced by ctap2_build_make_credential_response_packed(), encode_info_algorithms(), encode_info_extensions(), encode_info_pin_uv_auth_protocols(), encode_info_transports(), and encode_info_versions().
| void cbor_encode_bool | ( | cbor_writer_t * | w, |
| bool | value ) |
Encodes CBOR boolean.
| w | Writer context. |
| value | Boolean value. |
Definition at line 180 of file cbor_helpers.cpp.
References CBOR_FALSE, CBOR_TRUE, and write_byte().
Referenced by ctap2_build_appid_extension(), and encode_info_options().
| void cbor_encode_bytes | ( | cbor_writer_t * | w, |
| const uint8_t * | data, | ||
| size_t | len ) |
Encodes CBOR byte-string.
| w | Writer context. |
| data | Byte payload. |
| len | Payload length. |
Definition at line 142 of file cbor_helpers.cpp.
References CBOR_BYTES, write_bytes(), and write_type_value().
Referenced by cbor_encode_cose_key_ed25519(), cbor_encode_cose_key_p256(), client_pin_get_key_agreement(), client_pin_get_pin_token(), client_pin_get_pin_uv_auth_token(), cred_mgmt_encode_credential(), cred_mgmt_encode_rp(), ctap2_build_make_credential_response_packed(), ctap2_get_next_assertion(), encode_info_aaguid(), and ga_build_response().
| void cbor_encode_cose_key_ed25519 | ( | cbor_writer_t * | w, |
| const uint8_t * | pubkey ) |
Encodes COSE Ed25519 public key map.
| w | Writer context. |
| pubkey | Public key bytes (32 bytes). |
Definition at line 248 of file cbor_helpers.cpp.
References cbor_encode_bytes(), cbor_encode_int(), cbor_encode_map(), and cbor_encode_uint().
Referenced by cred_mgmt_encode_credential(), and ctap2_build_attested_cred().
| void cbor_encode_cose_key_p256 | ( | cbor_writer_t * | w, |
| const uint8_t * | x, | ||
| const uint8_t * | y ) |
Encodes COSE P-256 public key map.
| w | Writer context. |
| x | X coordinate (32 bytes). |
| y | Y coordinate (32 bytes). |
Definition at line 216 of file cbor_helpers.cpp.
References cbor_encode_bytes(), cbor_encode_int(), cbor_encode_map(), and cbor_encode_uint().
Referenced by cred_mgmt_encode_credential(), and ctap2_build_attested_cred().
| void cbor_encode_int | ( | cbor_writer_t * | w, |
| int64_t | value ) |
Encodes CBOR signed integer.
| w | Writer context. |
| value | Signed value. |
Definition at line 128 of file cbor_helpers.cpp.
References CBOR_NEGATIVE, CBOR_UNSIGNED, and write_type_value().
Referenced by cbor_encode_cose_key_ed25519(), cbor_encode_cose_key_p256(), client_pin_get_key_agreement(), ctap2_build_make_credential_response_packed(), and encode_info_algorithms().
| void cbor_encode_map | ( | cbor_writer_t * | w, |
| size_t | count ) |
Encodes CBOR map header.
| w | Writer context. |
| count | Pair count. |
Definition at line 206 of file cbor_helpers.cpp.
References CBOR_MAP, and write_type_value().
Referenced by cbor_encode_cose_key_ed25519(), cbor_encode_cose_key_p256(), client_pin_get_key_agreement(), client_pin_get_pin_token(), client_pin_get_pin_uv_auth_token(), client_pin_get_retries(), cred_mgmt_encode_credential(), cred_mgmt_encode_rp(), ctap2_build_appid_extension(), ctap2_build_cred_protect_extension(), ctap2_build_make_credential_response_packed(), ctap2_cred_management(), ctap2_get_info(), ctap2_get_next_assertion(), encode_info_algorithms(), encode_info_options(), and ga_build_response().
| void cbor_encode_null | ( | cbor_writer_t * | w | ) |
Encodes CBOR null.
| w | Writer context. |
Definition at line 188 of file cbor_helpers.cpp.
References CBOR_NULL, and write_byte().
| void cbor_encode_text | ( | cbor_writer_t * | w, |
| const char * | str ) |
Encodes CBOR text string.
| w | Writer context. |
| str | Null-terminated string. |
Definition at line 154 of file cbor_helpers.cpp.
References CBOR_TEXT, write_bytes(), and write_type_value().
Referenced by cred_mgmt_encode_credential(), cred_mgmt_encode_rp(), ctap2_build_appid_extension(), ctap2_build_cred_protect_extension(), ctap2_build_make_credential_response_packed(), ctap2_get_next_assertion(), encode_info_algorithms(), encode_info_extensions(), encode_info_options(), encode_info_transports(), encode_info_versions(), and ga_build_response().
| void cbor_encode_text_len | ( | cbor_writer_t * | w, |
| const char * | str, | ||
| size_t | len ) |
Encodes CBOR text string with explicit length.
| w | Writer context. |
| str | Text pointer. |
| len | Text length. |
Definition at line 168 of file cbor_helpers.cpp.
References CBOR_TEXT, write_bytes(), and write_type_value().
| void cbor_encode_uint | ( | cbor_writer_t * | w, |
| uint64_t | value ) |
Encodes CBOR unsigned integer.
| w | Writer context. |
| value | Unsigned value. |
Definition at line 119 of file cbor_helpers.cpp.
References CBOR_UNSIGNED, and write_type_value().
Referenced by cbor_encode_cose_key_ed25519(), cbor_encode_cose_key_p256(), client_pin_get_key_agreement(), client_pin_get_pin_token(), client_pin_get_pin_uv_auth_token(), client_pin_get_retries(), cred_mgmt_encode_credential(), cred_mgmt_encode_rp(), ctap2_build_cred_protect_extension(), ctap2_build_make_credential_response_packed(), ctap2_cred_management(), ctap2_get_next_assertion(), encode_info_aaguid(), encode_info_algorithms(), encode_info_extensions(), encode_info_max_cred_count(), encode_info_max_cred_id_length(), encode_info_max_msg_size(), encode_info_options(), encode_info_pin_uv_auth_protocols(), encode_info_transports(), encode_info_versions(), and ga_build_response().
| bool cbor_parse_cose_key | ( | cbor_reader_t * | r, |
| int * | kty, | ||
| int * | alg, | ||
| uint8_t * | x, | ||
| uint8_t * | y ) |
Parses COSE key map and extracts key type, algorithm, and coordinates.
| r | Reader context positioned at COSE key map. |
| kty | Output key type. |
| alg | Output algorithm identifier. |
| x | Output x-coordinate/public key bytes. |
| y | Optional output y-coordinate bytes. |
Definition at line 613 of file cbor_helpers.cpp.
References cbor_read_bytes(), cbor_read_int(), cbor_read_map(), cbor_read_uint(), and cbor_skip_item().
| int cbor_read_array | ( | cbor_reader_t * | r | ) |
Reads CBOR array header and returns element count.
| r | Reader context. |
Definition at line 549 of file cbor_helpers.cpp.
References CBOR_ARRAY, and cbor_read_item().
Referenced by ga_parse_allow_list(), and cdc::mod_fido2::parse_pubkey_cred_params().
| bool cbor_read_bool | ( | cbor_reader_t * | r, |
| bool * | value ) |
Reads CBOR boolean simple value.
| r | Reader context. |
| value | Output boolean. |
Definition at line 513 of file cbor_helpers.cpp.
References CBOR_FALSE, CBOR_TRUE, and read_byte().
Referenced by ga_parse_options(), and cdc::mod_fido2::parse_options_map().
| bool cbor_read_bytes | ( | cbor_reader_t * | r, |
| uint8_t * | out, | ||
| size_t | max_len, | ||
| size_t * | out_len ) |
Reads CBOR byte-string into optional output buffer.
| r | Reader context. |
| out | Optional output data buffer. |
| max_len | Output capacity. |
| out_len | Optional output original item length. |
Definition at line 462 of file cbor_helpers.cpp.
References CBOR_BYTES, and cbor_read_item().
Referenced by cbor_parse_cose_key(), client_pin_get_pin_token(), client_pin_get_pin_uv_auth_token(), ctap2_cred_management(), ga_parse_allow_list_credential(), ga_parse_params(), cdc::mod_fido2::parse_make_credential_params(), and cdc::mod_fido2::parse_user_map().
| bool cbor_read_int | ( | cbor_reader_t * | r, |
| int64_t * | value ) |
Reads CBOR integer (positive or negative).
| r | Reader context. |
| value | Output value. |
Definition at line 439 of file cbor_helpers.cpp.
References CBOR_NEGATIVE, cbor_read_item(), and CBOR_UNSIGNED.
Referenced by cbor_parse_cose_key(), and cdc::mod_fido2::parse_pubkey_cred_params().
| bool cbor_read_item | ( | cbor_reader_t * | r, |
| cbor_item_t * | item ) |
Reads next CBOR item metadata and optional inline payload pointer.
| r | Reader context. |
| item | Output item descriptor. |
Definition at line 391 of file cbor_helpers.cpp.
References CBOR_BYTES, CBOR_TEXT, and read_type_value().
Referenced by cbor_read_array(), cbor_read_bytes(), cbor_read_int(), cbor_read_map(), cbor_read_text(), cbor_read_uint(), cbor_skip_item_impl(), client_pin_get_pin_token(), and client_pin_get_pin_uv_auth_token().
| int cbor_read_map | ( | cbor_reader_t * | r | ) |
Reads CBOR map header and returns pair count.
| r | Reader context. |
Definition at line 534 of file cbor_helpers.cpp.
References CBOR_MAP, and cbor_read_item().
Referenced by cbor_parse_cose_key(), client_pin_get_pin_token(), client_pin_get_pin_uv_auth_token(), ctap2_client_pin(), ctap2_cred_management(), ga_parse_allow_list_credential(), ga_parse_extensions(), ga_parse_options(), ga_parse_params(), cdc::mod_fido2::parse_extensions_map(), cdc::mod_fido2::parse_make_credential_params(), cdc::mod_fido2::parse_options_map(), cdc::mod_fido2::parse_pubkey_cred_params(), cdc::mod_fido2::parse_rp_map(), and cdc::mod_fido2::parse_user_map().
| bool cbor_read_text | ( | cbor_reader_t * | r, |
| char * | out, | ||
| size_t | max_len, | ||
| size_t * | out_len ) |
Reads CBOR text string into output buffer.
| r | Reader context. |
| out | Output text buffer. |
| max_len | Output capacity including terminator. |
| out_len | Optional output original text length. |
Definition at line 486 of file cbor_helpers.cpp.
References cbor_read_item(), and CBOR_TEXT.
Referenced by client_pin_get_pin_uv_auth_token(), ctap2_cred_management(), ga_parse_allow_list_credential(), ga_parse_extensions(), ga_parse_options(), ga_parse_params(), cdc::mod_fido2::parse_extensions_map(), cdc::mod_fido2::parse_options_map(), cdc::mod_fido2::parse_pubkey_cred_params(), cdc::mod_fido2::parse_rp_map(), and cdc::mod_fido2::parse_user_map().
| bool cbor_read_uint | ( | cbor_reader_t * | r, |
| uint64_t * | value ) |
Reads CBOR unsigned integer.
| r | Reader context. |
| value | Output value. |
Definition at line 422 of file cbor_helpers.cpp.
References cbor_read_item(), and CBOR_UNSIGNED.
Referenced by cbor_parse_cose_key(), client_pin_get_pin_token(), client_pin_get_pin_uv_auth_token(), ctap2_client_pin(), ctap2_cred_management(), ga_parse_params(), cdc::mod_fido2::parse_extensions_map(), and cdc::mod_fido2::parse_make_credential_params().
| bool cbor_reader_available | ( | const cbor_reader_t * | r | ) |
Returns whether unread data remains.
| r | Reader context. |
Definition at line 300 of file cbor_helpers.cpp.
| bool cbor_reader_error | ( | const cbor_reader_t * | r | ) |
Returns whether reader is in error state.
| r | Reader context. |
Definition at line 291 of file cbor_helpers.cpp.
| void cbor_reader_init | ( | cbor_reader_t * | r, |
| const uint8_t * | data, | ||
| size_t | size ) |
CBOR reader implementation.
Initializes CBOR reader state.
| r | Reader context. |
| data | Input buffer. |
| size | Input size. |
Definition at line 279 of file cbor_helpers.cpp.
Referenced by client_pin_get_pin_token(), client_pin_get_pin_uv_auth_token(), ctap2_client_pin(), ctap2_cred_management(), ga_parse_params(), and cdc::mod_fido2::parse_make_credential_params().
| int cbor_reader_peek_type | ( | const cbor_reader_t * | r | ) |
Peeks major type of next CBOR item.
| r | Reader context. |
Definition at line 309 of file cbor_helpers.cpp.
| bool cbor_skip_item | ( | cbor_reader_t * | r | ) |
Skips one complete CBOR item including nested container content.
| r | Reader context. |
Definition at line 600 of file cbor_helpers.cpp.
References cbor_skip_item_impl().
Referenced by cbor_parse_cose_key(), client_pin_get_pin_token(), client_pin_get_pin_uv_auth_token(), ctap2_client_pin(), ctap2_cred_management(), ga_parse_allow_list_credential(), ga_parse_extensions(), ga_parse_options(), ga_parse_params(), cdc::mod_fido2::parse_extensions_map(), cdc::mod_fido2::parse_make_credential_params(), cdc::mod_fido2::parse_options_map(), cdc::mod_fido2::parse_pubkey_cred_params(), cdc::mod_fido2::parse_rp_map(), and cdc::mod_fido2::parse_user_map().
|
static |
Definition at line 563 of file cbor_helpers.cpp.
References CBOR_ARRAY, CBOR_MAP, CBOR_MAX_CONTAINER_SIZE, CBOR_MAX_RECURSION_DEPTH, cbor_read_item(), cbor_skip_item_impl(), LOG_W, and TAG.
Referenced by cbor_skip_item(), and cbor_skip_item_impl().
| bool cbor_writer_error | ( | const cbor_writer_t * | w | ) |
Returns whether writer encountered an error.
| w | Writer context. |
Definition at line 41 of file cbor_helpers.cpp.
Referenced by ctap2_build_appid_extension(), ctap2_build_attested_cred(), ctap2_build_cred_protect_extension(), ctap2_build_make_credential_response_packed(), ctap2_cred_management(), ctap2_get_info(), and ga_build_response().
| void cbor_writer_init | ( | cbor_writer_t * | w, |
| uint8_t * | buffer, | ||
| size_t | size ) |
CBOR writer implementation.
Initializes CBOR writer state.
| w | Writer context. |
| buffer | Output buffer. |
| size | Output buffer size. |
Definition at line 20 of file cbor_helpers.cpp.
Referenced by client_pin_get_key_agreement(), client_pin_get_pin_token(), client_pin_get_pin_uv_auth_token(), client_pin_get_retries(), ctap2_build_appid_extension(), ctap2_build_attested_cred(), ctap2_build_cred_protect_extension(), ctap2_build_make_credential_response_packed(), ctap2_cred_management(), ctap2_get_info(), ctap2_get_next_assertion(), and ga_build_response().
| size_t cbor_writer_length | ( | const cbor_writer_t * | w | ) |
Returns number of bytes written by CBOR writer.
| w | Writer context. |
Definition at line 32 of file cbor_helpers.cpp.
Referenced by client_pin_get_key_agreement(), client_pin_get_pin_token(), client_pin_get_pin_uv_auth_token(), client_pin_get_retries(), ctap2_build_appid_extension(), ctap2_build_attested_cred(), ctap2_build_cred_protect_extension(), ctap2_build_make_credential_response_packed(), ctap2_cred_management(), ctap2_get_info(), ctap2_get_next_assertion(), and ga_build_response().
|
static |
Reads one byte from CBOR reader.
| r | Reader context. |
| b | Output byte. |
Definition at line 320 of file cbor_helpers.cpp.
Referenced by cbor_read_bool(), and read_type_value().
|
static |
Reads CBOR item header and decoded value.
| r | Reader context. |
| type | Output major type. |
| value | Output decoded additional value. |
Definition at line 338 of file cbor_helpers.cpp.
References LOG_E, read_byte(), and TAG.
Referenced by cbor_read_item().
|
static |
Writes one byte to CBOR output buffer.
| w | Writer context. |
| b | Byte value. |
Definition at line 50 of file cbor_helpers.cpp.
Referenced by cbor_encode_bool(), cbor_encode_null(), and write_type_value().
|
static |
Writes byte span to CBOR output buffer.
| w | Writer context. |
| data | Input byte span. |
| len | Number of bytes to write. |
Definition at line 66 of file cbor_helpers.cpp.
Referenced by cbor_encode_bytes(), cbor_encode_text(), and cbor_encode_text_len().
|
static |
Encodes CBOR major type and value header.
| w | Writer context. |
| type | CBOR major type. |
| value | Additional value. |
Definition at line 83 of file cbor_helpers.cpp.
References write_byte().
Referenced by cbor_encode_array(), cbor_encode_bytes(), cbor_encode_int(), cbor_encode_map(), cbor_encode_text(), cbor_encode_text_len(), and cbor_encode_uint().
|
static |
Definition at line 10 of file cbor_helpers.cpp.