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

U2F implementation #56

Draft
wants to merge 28 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1e6ca27
Vendor in the highly customised tinyusb, rather than patching esp-iot…
MatthewWilkes May 28, 2022
f50f336
Reduce patching of micropython to support USB
MatthewWilkes May 28, 2022
98d660d
Merge remote-tracking branch 'emf/main' into feature/u2f-mode
MatthewWilkes May 28, 2022
e4b1cd2
Progress on internal U2F protocol
MatthewWilkes May 29, 2022
ae3e5f7
Update U2F implementation to be ready for crypto drop-in
MatthewWilkes May 29, 2022
02ff0f7
Add cryptoauthlib and partial SoftI2C HAL
marksteward Jun 12, 2022
260af72
Add get serial number for ecc108
MatthewWilkes Jul 30, 2022
ed6dc1d
Update ECC108A interface
MatthewWilkes Jul 30, 2022
6995c47
Attempts to configure keys
MatthewWilkes Aug 21, 2022
6cec889
Include calib updatextra
MatthewWilkes Aug 21, 2022
7b0596a
Provision ATECC108A and offer some initial helper functions
MatthewWilkes Aug 29, 2022
42c115c
Merge branch 'ecc108a-wip' into feature/u2f-mode
MatthewWilkes Oct 30, 2022
51ee313
U2F Implementation includes crypto functions
MatthewWilkes Nov 27, 2022
91e249c
Use DER format for signature return
MatthewWilkes Nov 27, 2022
e26308f
Send pubkey in uncompressed format
MatthewWilkes Nov 27, 2022
2a66ea5
Fix alignment of continuation packets and simplify signature scheme.
MatthewWilkes Nov 28, 2022
64564fd
Helper functions for debugging. Return data as bytes rather than a nu…
MatthewWilkes Feb 10, 2024
237bf9b
Improve verify helper to fix mp API problem. Now returns ATCA error.@
MatthewWilkes Apr 3, 2024
eaba9ee
Update github build script with user components
MatthewWilkes Apr 3, 2024
99487ac
Fix signature size, allowing authentication to work (!)
MatthewWilkes Apr 4, 2024
44df071
Basic GUI for authenticator support
MatthewWilkes Apr 15, 2024
3a347cc
Allow user driven switching of U2F and HID modes
MatthewWilkes Apr 15, 2024
fb4a4f2
Set the target env variable at workflow module scope
MatthewWilkes Apr 15, 2024
020440b
Force idf target in the tinyusb component
MatthewWilkes Apr 15, 2024
818d729
Another attempt to sort target for github builds
MatthewWilkes Apr 15, 2024
b440c3c
Use IDF 4.4.1 in github
MatthewWilkes Apr 15, 2024
7e94e9d
Move cryptographic operation calls into MicroPython to improve reliab…
MatthewWilkes Apr 21, 2024
be695b2
Improvements to u2f
MatthewWilkes Jul 7, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ jobs:
source esp-idf/export.sh
ln -sfn $GITHUB_WORKSPACE/tildamk6 micropython/ports/esp32/boards/tildamk6
cd micropython/ports/esp32
make submodules BOARD=tildamk6 USER_C_MODULES=$GITHUB_WORKSPACE/drivers/micropython.cmake IOT_SOLUTION_PATH=$GITHUB_WORKSPACE/esp-iot-solution TARGET=esp32s3
make BOARD=tildamk6 USER_C_MODULES=$GITHUB_WORKSPACE/drivers/micropython.cmake $@ IOT_SOLUTION_PATH=$GITHUB_WORKSPACE/esp-iot-solution TARGET=esp32s3
make submodules BOARD=tildamk6 USER_C_MODULES=$GITHUB_WORKSPACE/drivers/micropython.cmake USER_COMPONENTS=$GITHUB_WORKSPACE/components/tinyusb IOT_SOLUTION_PATH=$GITHUB_WORKSPACE/esp-iot-solution TARGET=esp32s3
make BOARD=tildamk6 USER_C_MODULES=$GITHUB_WORKSPACE/drivers/micropython.cmake USER_COMPONENTS=$GITHUB_WORKSPACE/components/tinyusb $@ IOT_SOLUTION_PATH=$GITHUB_WORKSPACE/esp-iot-solution TARGET=esp32s3
cd ../../..
echo "{\"build\":\"$(git describe --tags --always)\", \"name\":\"$(git describe --tags --always)\"}" > micropython/ports/esp32/build-tildamk6/tidal.txt
- name: Archive firmware
Expand Down
106 changes: 106 additions & 0 deletions components/tinyusb/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
idf_build_get_property(target IDF_TARGET)

set(srcs)
set(includes_public)
set(includes_private)
set(compile_options)


if(CONFIG_TINYUSB)
set(tusb_mcu "OPT_MCU_ESP32S3")
set(tusb_family "esp32sx")

list(APPEND compile_options
"-DCFG_TUSB_MCU=${tusb_mcu}"
"-DCFG_TUSB_DEBUG=${CONFIG_TINYUSB_DEBUG_LEVEL}"
)

idf_component_get_property(freertos_component_dir freertos COMPONENT_DIR)

list(APPEND includes_private
"${IDF_PATH}/components/tinyusb/tinyusb/hw/bsp/"
"${IDF_PATH}/components/tinyusb/tinyusb/src/"
"${IDF_PATH}/components/tinyusb/tinyusb/src/device"
"${IDF_PATH}/components/tinyusb/tinyusb/src/class/bth"
#"additions/include_private"
)

list(APPEND includes_public
"${IDF_PATH}/components/tinyusb/tinyusb/src/"
"additions/include"
"additions/include_private"
"additions/tusb/src/lib/networking"
"additions/tusb/src/class/dfu"
# The FreeRTOS API include convention in tinyusb is different from esp-idf
"${freertos_component_dir}/include/freertos"
)

list(APPEND srcs
"${IDF_PATH}/components/tinyusb/tinyusb/src/portable/espressif/${tusb_family}/dcd_${tusb_family}.c"
"${IDF_PATH}/components/tinyusb/tinyusb/src/class/cdc/cdc_device.c"
"${IDF_PATH}/components/tinyusb/tinyusb/src/class/hid/hid_device.c"
"${IDF_PATH}/components/tinyusb/tinyusb/src/class/midi/midi_device.c"
"${IDF_PATH}/components/tinyusb/tinyusb/src/class/msc/msc_device.c"
"${IDF_PATH}/components/tinyusb/tinyusb/src/class/vendor/vendor_device.c"
"${IDF_PATH}/components/tinyusb/tinyusb/src/common/tusb_fifo.c"
"${IDF_PATH}/components/tinyusb/tinyusb/src/device/usbd_control.c"
"${IDF_PATH}/components/tinyusb/tinyusb/src/tusb.c"
"additions/src/usbd.c"
"additions/src/descriptors_control.c"
"additions/src/tinyusb.c"
"additions/src/tusb_tasks.c"
"additions/src/usb_descriptors.c"
)

# when no builtin class driver is enabled, an uint8_t data compared with `BUILTIN_DRIVER_COUNT` will always be false
set_source_files_properties("tinyusb/src/device/usbd.c" PROPERTIES COMPILE_FLAGS "-Wno-type-limits")

if(CONFIG_TINYUSB_CDC_ENABLED)
list(APPEND srcs
"additions/src/cdc.c"
"additions/src/tusb_cdc_acm.c"
"additions/src/tusb_console.c"
"additions/src/vfs_tinyusb.c"
)
endif() # CONFIG_TINYUSB_CDC_ENABLED

if(CONFIG_TINYUSB_HID_ENABLED)
list(APPEND srcs
"additions/src/tusb_hid.c")
endif()

if(CONFIG_TINYUSB_MSC_ENABLED)
list(APPEND srcs
"additions/src/tusb_msc.c")
endif()

if(CONFIG_TINYUSB_NET_ENABLED)
list(APPEND srcs
"additions/src/tusb_net.c"
"additions/tusb/src/class/net/net_device.c"
"additions/tusb/src/lib/networking/rndis_reports.c")
endif()

if(CONFIG_TINYUSB_BTH_ENABLED)
list(APPEND srcs
"additions/src/tusb_bth.c"
"${IDF_PATH}/components/tinyusb/tinyusb/src/class/bth/bth_device.c")
endif()

if(CONFIG_TINYUSB_DFU_ENABLED)
list(APPEND srcs
"additions/src/tusb_dfu.c"
"additions/tusb/src/class/dfu/dfu_device.c")
endif()

endif() # CONFIG_TINYUSB

idf_component_register(SRCS ${srcs}
INCLUDE_DIRS ${includes_public}
PRIV_INCLUDE_DIRS ${includes_private}
PRIV_REQUIRES "vfs" "fatfs" "bt" "app_update"
)

if(CONFIG_TINYUSB)
target_compile_options(${COMPONENT_LIB} PRIVATE ${compile_options})
endif()
267 changes: 267 additions & 0 deletions components/tinyusb/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
menu "TinyUSB Stack"
visible if USB_OTG_SUPPORTED

config TINYUSB
bool "Use TinyUSB Stack"
depends on USB_OTG_SUPPORTED
default n
help
Enable TinyUSB stack support.
Note that, esp-idf only uses the device stack provided by TinyUSB.

if TINYUSB
config TINYUSB_DEBUG_LEVEL
int "TinyUSB log level (0-3)"
default 0
range 0 3
help
Specify verbosity of TinyUSB log output.

menu "TinyUSB task configuration"
config TINYUSB_NO_DEFAULT_TASK
bool "Do not create a TinyUSB task"
default n
help
This option allows to not create the FreeRTOS task during the driver initialization.
User will have to handle TinyUSB events manually.

config TINYUSB_TASK_PRIORITY
int "TinyUSB task priority"
default 5
depends on !TINYUSB_NO_DEFAULT_TASK
help
Set the priority of the default TinyUSB main task.

config TINYUSB_TASK_STACK_SIZE
int "TinyUSB task stack size (bytes)"
default 4096
depends on !TINYUSB_NO_DEFAULT_TASK
help
Set the stack size of the default TinyUSB main task.
endmenu

menu "Descriptor configuration"
config TINYUSB_DESC_USE_ESPRESSIF_VID
bool "VID: Use Espressif's vendor ID"
default y
help
Enable this option, USB device will use Espressif's vendor ID as its VID.
This is helpful at product develop stage.

config TINYUSB_DESC_CUSTOM_VID
hex "VID: Custom vendor ID"
default 0x1234
depends on !TINYUSB_DESC_USE_ESPRESSIF_VID
help
Custom Vendor ID.

config TINYUSB_DESC_USE_DEFAULT_PID
bool "PID: Use a default PID assigned to TinyUSB"
default y
help
Default TinyUSB PID assigning uses values 0x4000...0x4007.

config TINYUSB_DESC_CUSTOM_PID
hex "PID: Custom product ID"
default 0x5678
depends on !TINYUSB_DESC_USE_DEFAULT_PID
help
Custom Product ID.

config TINYUSB_DESC_BCD_DEVICE
hex "bcdDevice"
default 0x0100
help
Version of the firmware of the USB device.

config TINYUSB_DESC_MANUFACTURER_STRING
string "Manufacturer name"
default "Espressif Systems"
help
Name of the manufacturer of the USB device.

config TINYUSB_DESC_PRODUCT_STRING
string "Product name"
default "Espressif Device"
help
Name of the USB device.

config TINYUSB_DESC_SERIAL_STRING
string "Serial string"
default "123456"
help
Serial number of the USB device.

config TINYUSB_DESC_CDC_STRING
depends on TINYUSB_CDC_ENABLED
string "CDC Device String"
default "Espressif CDC Device"
help
Name of the CDC device.

config TINYUSB_DESC_MSC_STRING
depends on TINYUSB_MSC_ENABLED
string "MSC Device String"
default "Espressif MSC Device"
help
Name of the MSC device.

config TINYUSB_DESC_HID_STRING
depends on TINYUSB_HID_ENABLED
string "HID Device String"
default "Espressif HID Device"
help
Name of the HID device
config TINYUSB_DESC_NET_STRING
depends on TINYUSB_NET_ENABLED
string "NET Device String"
default "Espressif NET Device"
help
Name of the NET device.
config TINYUSB_DESC_BTH_STRING
depends on TINYUSB_BTH_ENABLED
string "BTH String"
default "Espressif BTH Device"
help
Name of the BTH device.
endmenu # "Descriptor configuration"

menu "Massive Storage Class (MSC)"
config TINYUSB_MSC_ENABLED
bool "Enable TinyUSB MSC feature"
default n
help
Enable TinyUSB MSC feature.

config TINYUSB_MSC_BUFSIZE
depends on TINYUSB_MSC_ENABLED
int "MSC FIFO size"
default 512
help
MSC FIFO size, in bytes.
endmenu # "Massive Storage Class"

menu "Communication Device Class (CDC)"
config TINYUSB_CDC_ENABLED
bool "Enable TinyUSB CDC feature"
default n
help
Enable TinyUSB CDC feature.
config TINYUSB_CDC_PORT_NUM
depends on TINYUSB_CDC_ENABLED
int "Number of Serial (CDC) Port"
default 1
range 1 2
help
Number of Serial (CDC) Port.
config TINYUSB_CDC_RX_BUFSIZE
depends on TINYUSB_CDC_ENABLED
int "CDC FIFO size of RX channel"
default 64
help
CDC FIFO size of RX channel.

config TINYUSB_CDC_TX_BUFSIZE
depends on TINYUSB_CDC_ENABLED
int "CDC FIFO size of TX channel"
default 64
help
CDC FIFO size of TX channel.
endmenu # "Communication Device Class"

menu "Human Interface Device Class (HID)"
config TINYUSB_HID_ENABLED
bool "Enable TinyUSB HID feature"
default n
help
Enable TinyUSB HID feature.

config TINYUSB_U2FHID_ENABLED
bool "Enable TinyUSB U2FHID tunneling"
default n
help
Enable TinyUSB U2FHID feature.

config TINYUSB_HIDKEYBOARD_ENABLED
bool "Enable TinyUSB HID Keyboard"
default n
help
Enable TinyUSB HID Keyboard.

config TINYUSB_HID_BUFSIZE
int "HID FIFO size"
default 64
depends on TINYUSB_HID_ENABLED
help
HID FIFO size
endmenu # "Human Interface Device Class"

menu "USB Network Class (RNDIS, ECM)"

config TINYUSB_NET_ENABLED
bool "Enable TinyUSB NET driver"
default n
help
Enable USB NET TinyUSB driver.

config TINYUSB_RNDIS_VENDOR
string "USB Vendor"
default "Espressif Incorporated"
depends on TINYUSB_NET_ENABLED
help
Vendor description.

choice TINYUSB_NET
prompt "Choose a network communication standard"
default TINYUSB_NET_RNDIS
depends on TINYUSB_NET_ENABLED
help
RNDIS and CDC-ECM
- Windows only works with RNDIS
- MacOS only works with CDC-ECM
- Linux will work on both

config TINYUSB_NET_RNDIS
bool "RNDIS"
help
RNDIS.
config TINYUSB_NET_ECM
bool "CDC-ECM"
help
CDC-ECM.
endchoice
endmenu # "usb network"

menu "Bluetooth Host Class (BTH)"
config TINYUSB_BTH_ENABLED
bool "Enable TinyUSB BTH feature"
default n
help
Enable TinyUSB BTH feature.

config TINYUSB_BTH_ISO_ALT_COUNT
depends on TINYUSB_BTH_ENABLED
int "BTH ISO ALT COUNT"
default 0
help
BTH ISO ALT COUNT.
endmenu # "Bluetooth Host Device Class"

menu "Firmware Upgrade Class (DFU)"
config TINYUSB_DFU_ENABLED
bool "Enable TinyUSB DFU feature"
default n
help
Enable TinyUSB DFU feature.

config TINYUSB_DFU_BUFSIZE
depends on TINYUSB_DFU_ENABLED
int "DFU XFER BUFFSIZE"
default 512
help
DFU XFER BUFFSIZE.
endmenu # "Firmware Upgrade Class"

endif # TINYUSB

endmenu # "TinyUSB Stack"
Loading
Loading