Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/device #64

Merged
merged 3 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,16 @@ 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 Expand Up @@ -468,7 +478,7 @@ jobs:
PIVGenKeyCert $s "/CN=CertAtSlot$s/" RSA2048
yubico-piv-tool -r "$RDID" -a import-certificate -s $s -i test-via-pcsc/long-cert.pem
done

- name: Prepare the Test Coverage Report
run: |
go test test-via-pcsc/admin_test.go -v -run TestFSUsage
Expand Down
1 change: 1 addition & 0 deletions include/apdu.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ enum {
BUFFER_OWNER_NONE = 1,
BUFFER_OWNER_CCID,
BUFFER_OWNER_WEBUSB,
BUFFER_OWNER_USBD, // store the configuration descriptor during a control transfer
};

void init_apdu_buffer(void); // implement in ccid.c for reusing the ccid buffer
Expand Down
2 changes: 1 addition & 1 deletion interfaces/USB/device/usb_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ EP_SIZE_TABLE_t EP_SIZE_TABLE;

void usb_device_init(void) {
usb_resources_alloc();
USBD_DescriptorInit();
// USBD_DescriptorInit();
USBD_Init(&usb_device, &usbdDescriptors, 0);
USBD_RegisterClass(&usb_device, &USBD_CANOKEY);
USBD_Start(&usb_device);
Expand Down
59 changes: 31 additions & 28 deletions interfaces/USB/device/usbd_desc.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <usbd_ctaphid.h>
#include <usbd_desc.h>
#include <usbd_kbdhid.h>
#include <apdu.h>

#define USBD_LANGID_STRING 0x0409
#define USBD_MANUFACTURER_STRING "canokeys.org"
Expand Down Expand Up @@ -213,11 +214,7 @@ static const uint8_t USBD_FS_IfDesc_CCID[] = {
0x00, /* bInterval: Polling Interval */
};

static uint8_t USBD_FS_CfgDesc[USB_LEN_CFG_DESC +
sizeof(USBD_FS_IfDesc_CCID) +
sizeof(USBD_FS_IfDesc_WEBUSB) +
sizeof(USBD_FS_IfDesc_KBDHID) +
sizeof(USBD_FS_IfDesc_CTAPHID)] = {
static const uint8_t USBD_FS_CfgDescHeader[USB_LEN_CFG_DESC] = {
USB_LEN_CFG_DESC, /* bLength: Configuration Descriptor size */
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
0x00, 0x00, /* wTotalLength: To be filled by program */
Expand Down Expand Up @@ -343,9 +340,13 @@ static void patch_interface_descriptor(uint8_t *desc, uint8_t *desc_end, uint8_t
}

void USBD_DescriptorInit(void) {
uint8_t *desc = USBD_FS_CfgDesc + USB_LEN_CFG_DESC;
uint8_t *USBD_FS_CfgDesc = global_buffer;
uint8_t *desc = USBD_FS_CfgDesc;
uint8_t nIface = 3;

memcpy(desc, USBD_FS_CfgDescHeader, USB_LEN_CFG_DESC);
desc += USB_LEN_CFG_DESC;

memcpy(desc, USBD_FS_IfDesc_CTAPHID, sizeof(USBD_FS_IfDesc_CTAPHID));
patch_interface_descriptor(desc, desc + sizeof(USBD_FS_IfDesc_CTAPHID), USBD_CANOKEY_CTAPHID_IF, EP_IN(ctap_hid),
EP_OUT(ctap_hid), EP_SIZE(ctap_hid));
Expand Down Expand Up @@ -373,17 +374,19 @@ void USBD_DescriptorInit(void) {
USBD_FS_CfgDesc[3] = totalLen >> 8;
}

/* Internal string descriptor. */
uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ];

const uint8_t *USBD_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
*length = sizeof(USBD_FS_DeviceDesc);
return USBD_FS_DeviceDesc;
}

const uint8_t *USBD_ConfigurationDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
*length = sizeof(USBD_FS_CfgDesc);
return USBD_FS_CfgDesc;
USBD_DescriptorInit();
*length = USB_LEN_CFG_DESC +
sizeof(USBD_FS_IfDesc_CCID) +
sizeof(USBD_FS_IfDesc_WEBUSB) +
sizeof(USBD_FS_IfDesc_KBDHID) +
sizeof(USBD_FS_IfDesc_CTAPHID);
return global_buffer;
}

const uint8_t *USBD_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
Expand All @@ -392,29 +395,29 @@ const uint8_t *USBD_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *lengt
}

const uint8_t *USBD_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
USBD_GetString((uint8_t *)USBD_PRODUCT_STRING, USBD_StrDesc, length);
return USBD_StrDesc;
USBD_GetString((uint8_t *)USBD_PRODUCT_STRING, global_buffer, length);
return global_buffer;
}

const uint8_t *USBD_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
return USBD_StrDesc;
USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, global_buffer, length);
return global_buffer;
}

const uint8_t *USBD_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
uint8_t sn[4];
char sn_str[9];
fill_sn(sn);
sprintf(sn_str, "%02X%02X%02X%02X", sn[0], sn[1], sn[2], sn[3]);
USBD_GetString((uint8_t *)sn_str, USBD_StrDesc, length);
return USBD_StrDesc;
USBD_GetString((uint8_t *)sn_str, global_buffer, length);
return global_buffer;
}

const uint8_t *USBD_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
*length = sizeof(USBD_FS_BOSDesc);
memcpy(USBD_StrDesc, USBD_FS_BOSDesc, sizeof(USBD_FS_BOSDesc)); // use USBD_StrDesc to store this descriptor
USBD_StrDesc[28] = cfg_is_webusb_landing_enable();
return USBD_StrDesc;
memcpy(global_buffer, USBD_FS_BOSDesc, sizeof(USBD_FS_BOSDesc)); // use global_buffer to store this descriptor
global_buffer[28] = cfg_is_webusb_landing_enable();
return global_buffer;
}

const uint8_t *USBD_MSOS20Descriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
Expand All @@ -425,17 +428,17 @@ const uint8_t *USBD_MSOS20Descriptor(USBD_SpeedTypeDef speed, uint16_t *length)
const uint8_t *USBD_UsrStrDescriptor(USBD_SpeedTypeDef speed, uint8_t index, uint16_t *length) {
switch (index) {
case USBD_CTAPHID_INTERFACE_IDX:
USBD_GetString((uint8_t *)USBD_CTAPHID_INTERFACE_STRING, USBD_StrDesc, length);
return USBD_StrDesc;
USBD_GetString((uint8_t *)USBD_CTAPHID_INTERFACE_STRING, global_buffer, length);
return global_buffer;
case USBD_CCID_INTERFACE_IDX:
USBD_GetString((uint8_t *)USBD_CCID_INTERFACE_STRING, USBD_StrDesc, length);
return USBD_StrDesc;
USBD_GetString((uint8_t *)USBD_CCID_INTERFACE_STRING, global_buffer, length);
return global_buffer;
case USBD_WEBUSB_INTERFACE_IDX:
USBD_GetString((uint8_t *)USBD_WEBUSB_INTERFACE_STRING, USBD_StrDesc, length);
return USBD_StrDesc;
USBD_GetString((uint8_t *)USBD_WEBUSB_INTERFACE_STRING, global_buffer, length);
return global_buffer;
case USBD_KBDHID_INTERFACE_IDX:
USBD_GetString((uint8_t *)USBD_KBDHID_INTERFACE_STRING, USBD_StrDesc, length);
return USBD_StrDesc;
USBD_GetString((uint8_t *)USBD_KBDHID_INTERFACE_STRING, global_buffer, length);
return global_buffer;
}
*length = 0;
return NULL;
Expand Down
Loading