From 0ec563c8deb126669262164efdb70b221d0fef3e Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Tue, 27 Sep 2022 12:24:22 +0200 Subject: [PATCH] Adding authenticatorSelection 0x0B support. Signed-off-by: Pol Henarejos --- CMakeLists.txt | 1 + src/fido/cbor.c | 11 ++++++++++ src/fido/cbor_authenticator_selection.c | 28 +++++++++++++++++++++++++ src/fido/cbor_get_assertion.c | 2 ++ src/fido/ctap2_cbor.h | 6 ------ 5 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 src/fido/cbor_authenticator_selection.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f6bf1e..21c7fad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,7 @@ target_sources(pico_fido PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src/fido/cbor_client_pin.c ${CMAKE_CURRENT_LIST_DIR}/src/fido/credential.c ${CMAKE_CURRENT_LIST_DIR}/src/fido/cbor_get_assertion.c + ${CMAKE_CURRENT_LIST_DIR}/src/fido/cbor_authenticator_selection.c ) set(HSM_DRIVER "hid") include(pico-hsm-sdk/pico_hsm_sdk_import.cmake) diff --git a/src/fido/cbor.c b/src/fido/cbor.c index e187829..c3e564c 100644 --- a/src/fido/cbor.c +++ b/src/fido/cbor.c @@ -27,6 +27,15 @@ const bool _btrue = true, _bfalse = false; +extern int cbor_process(const uint8_t *data, size_t len); +int cbor_reset(); +int cbor_get_info(); +int cbor_make_credential(const uint8_t *data, size_t len); +int cbor_client_pin(const uint8_t *data, size_t len); +int cbor_get_assertion(const uint8_t *data, size_t len, bool next); +int cbor_get_next_assertion(const uint8_t *data, size_t len); +int cbor_authenticator_selection(); + const uint8_t aaguid[16] = {0x89, 0xFB, 0x94, 0xB7, 0x06, 0xC9, 0x36, 0x73, 0x9B, 0x7E, 0x30, 0x52, 0x6D, 0x96, 0x81, 0x45}; // First 16 bytes of SHA256("Pico FIDO2") const uint8_t *cbor_data = NULL; @@ -48,6 +57,8 @@ int cbor_parse(const uint8_t *data, size_t len) { return cbor_get_assertion(data + 1, len - 1, false); else if (data[0] == CTAP_GET_NEXT_ASSERTION) return cbor_get_next_assertion(data + 1, len - 1); + else if (data[0] == CTAP_AUTHENTICATOR_SEL) + return cbor_authenticator_selection(); return CTAP2_ERR_INVALID_CBOR; } diff --git a/src/fido/cbor_authenticator_selection.c b/src/fido/cbor_authenticator_selection.c new file mode 100644 index 0000000..5cc8964 --- /dev/null +++ b/src/fido/cbor_authenticator_selection.c @@ -0,0 +1,28 @@ + +/* + * This file is part of the Pico FIDO distribution (https://github.com/polhenarejos/pico-fido). + * Copyright (c) 2022 Pol Henarejos. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ctap2_cbor.h" +#include "fido.h" +#include "ctap.h" +#include "bsp/board.h" + +int cbor_authenticator_selection() { + if (wait_button_pressed() == true) + return CTAP2_ERR_USER_ACTION_TIMEOUT; + return CTAP2_OK; +} diff --git a/src/fido/cbor_get_assertion.c b/src/fido/cbor_get_assertion.c index 46436f7..ffb7375 100644 --- a/src/fido/cbor_get_assertion.c +++ b/src/fido/cbor_get_assertion.c @@ -29,6 +29,8 @@ #include "credential.h" #include +int cbor_get_assertion(const uint8_t *data, size_t len, bool next); + bool residentx = false; Credential credsx[MAX_CREDENTIAL_COUNT_IN_LIST] = {0}; uint8_t credentialCounter = 1; diff --git a/src/fido/ctap2_cbor.h b/src/fido/ctap2_cbor.h index 6fa4fb6..8b25fd3 100644 --- a/src/fido/ctap2_cbor.h +++ b/src/fido/ctap2_cbor.h @@ -26,12 +26,6 @@ extern uint8_t *driver_prepare_response(); extern void driver_exec_finished(size_t size_next); extern int cbor_process(const uint8_t *data, size_t len); -extern int cbor_reset(); -extern int cbor_get_info(); -extern int cbor_make_credential(const uint8_t *data, size_t len); -extern int cbor_client_pin(const uint8_t *data, size_t len); -extern int cbor_get_assertion(const uint8_t *data, size_t len, bool next); -extern int cbor_get_next_assertion(const uint8_t *data, size_t len); extern const uint8_t aaguid[16]; extern const bool _btrue, _bfalse;