From abd52c34ba94a1f3be34ff9dfe71d7be38118a3a Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Thu, 8 Sep 2022 20:37:21 +0200 Subject: [PATCH] Added CBOR processing. Signed-off-by: Pol Henarejos --- src/usb/hid/ctap_hid.h | 9 +++++++++ src/usb/hid/hid.c | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/usb/hid/ctap_hid.h b/src/usb/hid/ctap_hid.h index 1aa2d96..3a2caf9 100644 --- a/src/usb/hid/ctap_hid.h +++ b/src/usb/hid/ctap_hid.h @@ -93,6 +93,15 @@ typedef struct { #define CTAPHID_VENDOR_FIRST (TYPE_INIT | 0x40) // First vendor defined command #define CTAPHID_VENDOR_LAST (TYPE_INIT | 0x7F) // Last vendor defined command +// CTAP CBOR commands + +#define CTAP_MAKE_CREDENTIAL 0x01 +#define CTAP_GET_ASSERTION 0x02 +#define CTAP_GET_INFO 0x04 +#define CTAP_CLIENT_PIN 0x06 +#define CTAP_RESET 0x07 +#define CTAP_GET_NEXT_ASSERTION 0x08 + // CTAP_KEEPALIVE command defines #define KEEPALIVE_STATUS_PROCESSING 0x1 diff --git a/src/usb/hid/hid.c b/src/usb/hid/hid.c index 0dfc7c7..4dbc84e 100644 --- a/src/usb/hid/hid.c +++ b/src/usb/hid/hid.c @@ -142,6 +142,18 @@ uint8_t last_seq = 0; CTAPHID_FRAME last_req = { 0 }; uint32_t lock = 0; +int cbor_make_credential(const uint8_t *data, size_t len) { + return 0; +} + +int cbor_process(const uint8_t *data, size_t len) { + if (len == 0) + return -ERR_INVALID_LEN; + if (data[0] == CTAP_MAKE_CREDENTIAL) + return cbor_make_credential(data + 1, len - 1); + return 0; +} + int driver_process_usb_packet(uint16_t read) { int apdu_sent = 0; if (read >= 5) @@ -239,6 +251,15 @@ int driver_process_usb_packet(uint16_t read) { DEBUG_PAYLOAD(apdu.data, (int)apdu.nc); msg_packet.len = msg_packet.current_len = 0; //Reset the transaction } + else if ((ctap_req->init.cmd == CTAPHID_CBOR && msg_packet.len == 0) || (msg_packet.len == msg_packet.current_len && msg_packet.len > 0)) { + if (msg_packet.current_len == msg_packet.len && msg_packet.len > 0) + apdu_sent = cbor_process(msg_packet.data, msg_packet.len); + else + apdu_sent = cbor_process(ctap_req->init.data, MSG_LEN(ctap_req)); + msg_packet.len = msg_packet.current_len = 0; //Reset the transaction + if (apdu_sent < 0) + return ctap_error(-apdu_sent); + } else { if (msg_packet.len == 0) return ctap_error(ERR_INVALID_CMD);