Skip to content

Commit

Permalink
fix state of current_cmd_src
Browse files Browse the repository at this point in the history
  • Loading branch information
z4yx committed Dec 12, 2024
1 parent 9834767 commit 74aef8d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
16 changes: 11 additions & 5 deletions applets/ctap/ctap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion include/ctap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion interfaces/USB/class/ctaphid/ctaphid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 74aef8d

Please sign in to comment.