Skip to content

Commit

Permalink
Merge pull request #107 from canokeys/dev
Browse files Browse the repository at this point in the history
Fix state of current_cmd_src
  • Loading branch information
dangfan authored Dec 14, 2024
2 parents 5303543 + e1694fe commit 99eb28d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 24 deletions.
21 changes: 6 additions & 15 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ jobs:
run: |
sudo sed -i 's/^# deb-src/deb-src/' /etc/apt/sources.list
sudo apt-get update
sudo apt-get install -q -y curl git gcc g++ cmake swig psmisc procps debian-keyring devscripts libpcsclite-dev check gengetopt help2man openssl zlib1g-dev
sudo apt-get install -q -y libeac-dev curl git gcc g++ cmake swig psmisc procps debian-keyring devscripts libpcsclite-dev check gengetopt help2man openssl zlib1g-dev
sudo apt-get build-dep -q -y opensc
sudo rm -f /usr/bin/clang-tidy
- name: Build opensc package
if: steps.check_opensc.outputs.files_exists == 'false'
run: |
dget http://archive.ubuntu.com/ubuntu/pool/universe/o/opensc/opensc_0.23.0-0.1ubuntu1.dsc
cd opensc-0.23.0
curl https://github.com/OpenSC/OpenSC/commit/a0aef25c7f2ce0ec2c7e1014f959f0fe86ff0479.diff | patch -p1
dget -u http://archive.ubuntu.com/ubuntu/pool/universe/o/opensc/opensc_0.25.0~rc1-1build2.dsc
ls -l
cd 'opensc-0.25.0~rc1'
#curl https://github.com/OpenSC/OpenSC/commit/a0aef25c7f2ce0ec2c7e1014f959f0fe86ff0479.diff | patch -p1
dch --local ppa~jammy --distribution jammy "Apply a patch. Backports to Jammy."
DEB_BUILD_OPTIONS='parallel=2' debuild --no-sign -b
- name: Build yubico-piv-tool package
Expand Down Expand Up @@ -80,7 +81,7 @@ jobs:
run: |
sudo apt-add-repository ppa:yubico/stable
sudo apt-get update
sudo apt-get install -q -y git gcc g++ cmake swig psmisc procps pcscd pcsc-tools libhidapi-dev libassuan-dev libgcrypt20-dev libksba-dev libnpth0-dev libssl3 zlib1g libglib2.0-0 openssl openssh-server libpcsclite-dev libudev-dev libcmocka-dev python3-pip python3-setuptools python3-wheel lcov yubikey-manager libcbor-dev
sudo apt-get install -q -y libeac3 git gcc g++ cmake swig psmisc procps pcscd pcsc-tools libhidapi-dev libassuan-dev libgcrypt20-dev libksba-dev libnpth0-dev libssl3 zlib1g libglib2.0-0 openssl openssh-server libpcsclite-dev libudev-dev libcmocka-dev python3-pip python3-setuptools python3-wheel lcov yubikey-manager libcbor-dev
sudo dpkg -i opensc*.deb yubico-piv-tool*.deb
pip3 install --upgrade pip
Expand Down Expand Up @@ -198,16 +199,6 @@ jobs:
echo 0 | ./u2f-ref-code/u2f-tests/NFC/u2f_nfc_test -v | tee /tmp/u2f_nfc_test.log
test $(grep -c 'PASS(signCheckSignature(regReq, regRsp, authReq, authRsp, rapduLen))' /tmp/u2f_nfc_test.log) -eq 6
- name: Test the ckman Utility
run: |
pip3 install canokey-manager
ckman --log-level DEBUG info
ckman oath accounts add steam1 HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ -i Steam
ckman oath accounts code
ckman openpgp info
ckman piv info
#ckman fido credentials list --pin 123456
- name: Test the OATH
run: go test -v test-via-pcsc/oath_test.go

Expand Down
18 changes: 12 additions & 6 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,16 +2230,25 @@ 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;
LL = 0;
if (current_cmd_src != CTAP_SRC_NONE) EXCEPT(SW_UNABLE_TO_PROCESS);
// Must set current_cmd_src to CTAP_SRC_NONE before return
current_cmd_src = src;
LL = 0;
SW = SW_NO_ERROR;
if (CLA == 0x80) {
if (INS == CTAP_INS_MSG) {
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
2 changes: 1 addition & 1 deletion virt-card/device-sim.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ uint32_t device_get_tick(void) {
void device_disable_irq(void) {}
void device_enable_irq(void) {}
void device_set_timeout(void (*callback)(void), uint16_t timeout) {}
void fm_write_eeprom(uint16_t addr, const uint8_t *buf, uint8_t len) { return; }
fm_status_t fm_write_eeprom(uint16_t addr, const uint8_t *buf, uint8_t len) { return FM_STATUS_OK; }

int device_atomic_compare_and_swap(volatile uint32_t *var, uint32_t expect, uint32_t update) {
if (*var == expect) {
Expand Down

0 comments on commit 99eb28d

Please sign in to comment.