diff --git a/applets/ctap/ctap.c b/applets/ctap/ctap.c index 7d1c3961..e7b4f66d 100644 --- a/applets/ctap/ctap.c +++ b/applets/ctap/ctap.c @@ -2159,11 +2159,8 @@ static uint8_t ctap_large_blobs(CborEncoder *encoder, const uint8_t *params, siz return 0; } -int ctap_process_cbor(uint8_t *req, size_t req_len, uint8_t *resp, size_t *resp_len) { +static int ctap_process_cbor(uint8_t *req, size_t req_len, uint8_t *resp, size_t *resp_len) { if (req_len-- == 0) return -1; - if (current_cmd_src != CTAP_SRC_NONE) return -1; - // Must set current_cmd_src to CTAP_SRC_NONE before return - current_cmd_src = CTAP_SRC_HID; cp_pin_uv_auth_token_usage_timer_observer(); @@ -2233,10 +2230,19 @@ int ctap_process_cbor(uint8_t *req, size_t req_len, uint8_t *resp, size_t *resp_ if (*resp != 0) { // do not allow GET_NEXT_ASSERTION if error occurs last_cmd = CTAP_INVALID_CMD; } - current_cmd_src = CTAP_SRC_NONE; return 0; } +int ctap_process_cbor_with_src(uint8_t *req, size_t req_len, uint8_t *resp, size_t *resp_len, ctap_src_t src) { + + if (current_cmd_src != CTAP_SRC_NONE) return -1; + // Must set current_cmd_src to CTAP_SRC_NONE before return + current_cmd_src = src; + int ret = ctap_process_cbor(req, req_len, resp, resp_len); + current_cmd_src = CTAP_SRC_NONE; + return ret; +} + int ctap_process_apdu_with_src(const CAPDU *capdu, RAPDU *rapdu, ctap_src_t src) { int ret = 0; if (current_cmd_src != CTAP_SRC_NONE) EXCEPT(SW_UNABLE_TO_PROCESS); diff --git a/include/ctap.h b/include/ctap.h index 71d3ed8a..43a9f251 100644 --- a/include/ctap.h +++ b/include/ctap.h @@ -16,7 +16,7 @@ int ctap_install_private_key(const CAPDU *capdu, RAPDU *rapdu); int ctap_install_cert(const CAPDU *capdu, RAPDU *rapdu); int ctap_read_sm2_config(const CAPDU *capdu, RAPDU *rapdu); int ctap_write_sm2_config(const CAPDU *capdu, RAPDU *rapdu); -int ctap_process_cbor(uint8_t *req, size_t req_len, uint8_t *resp, size_t *resp_len); +int ctap_process_cbor_with_src(uint8_t *req, size_t req_len, uint8_t *resp, size_t *resp_len, ctap_src_t src); int ctap_process_apdu_with_src(const CAPDU *capdu, RAPDU *rapdu, ctap_src_t src); static int ctap_process_apdu(const CAPDU *capdu, RAPDU *rapdu) { return ctap_process_apdu_with_src(capdu, rapdu, CTAP_SRC_CCID); diff --git a/interfaces/USB/class/ctaphid/ctaphid.c b/interfaces/USB/class/ctaphid/ctaphid.c index bb0f8507..71a2a2aa 100644 --- a/interfaces/USB/class/ctaphid/ctaphid.c +++ b/interfaces/USB/class/ctaphid/ctaphid.c @@ -115,7 +115,7 @@ static void CTAPHID_Execute_Cbor(void) { DBG_MSG("C: "); PRINT_HEX(channel.data, channel.bcnt_total); size_t len = sizeof(channel.data); - ctap_process_cbor(channel.data, channel.bcnt_total, channel.data, &len); + ctap_process_cbor_with_src(channel.data, channel.bcnt_total, channel.data, &len, CTAP_SRC_HID); DBG_MSG("R: "); PRINT_HEX(channel.data, len); CTAPHID_SendResponse(channel.cid, CTAPHID_CBOR, channel.data, len);