diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml new file mode 100644 index 0000000..61a9640 --- /dev/null +++ b/.github/workflows/nightly.yml @@ -0,0 +1,35 @@ +name: "Nightly deploy" + +on: + schedule: + - cron: '0 2 * * *' + workflow_dispatch: + +jobs: + nightly: + name: Deploy nightly + strategy: + fail-fast: false + matrix: + refs: [main] + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + ref: ${{ matrix.refs }} + submodules: 'recursive' + - name : Build + env: + PICO_SDK_PATH: ../pico-sdk + run: | + ./workflows/autobuild.sh pico + ./build_pico_openpgp.sh + ./workflows/autobuild.sh esp32 + - name: Update nightly release + uses: pyTooling/Actions/releaser@main + with: + tag: nightly-${{ matrix.refs }} + rm: true + token: ${{ secrets.GITHUB_TOKEN }} + files: release/*.* diff --git a/CMakeLists.txt b/CMakeLists.txt index 1207dbd..e7ff723 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,79 +18,83 @@ cmake_minimum_required(VERSION 3.13) if(ESP_PLATFORM) - set(EXTRA_COMPONENT_DIRS src pico-keys-sdk/src) - include($ENV{IDF_PATH}/tools/cmake/project.cmake) + set(EXTRA_COMPONENT_DIRS src pico-keys-sdk/src) + include($ENV{IDF_PATH}/tools/cmake/project.cmake) else() - if(ENABLE_EMULATION) - else() - include(pico_sdk_import.cmake) - endif() - project(pico_openpgp C CXX ASM) - set(CMAKE_C_STANDARD 11) - set(CMAKE_CXX_STANDARD 17) + if(ENABLE_EMULATION) + else() + include(pico_sdk_import.cmake) + endif() - if(ENABLE_EMULATION) - else() - pico_sdk_init() - endif() + project(pico_openpgp C CXX ASM) - add_executable(pico_openpgp) + set(CMAKE_C_STANDARD 11) + set(CMAKE_CXX_STANDARD 17) + + if(ENABLE_EMULATION) + else() + pico_sdk_init() + endif() + + add_executable(pico_openpgp) endif() set(SOURCES ${SOURCES} - ${CMAKE_CURRENT_LIST_DIR}/src/openpgp/openpgp.c - ${CMAKE_CURRENT_LIST_DIR}/src/openpgp/files.c - ${CMAKE_CURRENT_LIST_DIR}/src/openpgp/piv.c - ${CMAKE_CURRENT_LIST_DIR}/src/openpgp/management.c + ${CMAKE_CURRENT_LIST_DIR}/src/openpgp/openpgp.c + ${CMAKE_CURRENT_LIST_DIR}/src/openpgp/files.c + ${CMAKE_CURRENT_LIST_DIR}/src/openpgp/piv.c + ${CMAKE_CURRENT_LIST_DIR}/src/openpgp/management.c ) set(USB_ITF_CCID 1) set(USB_ITF_WCID 1) include(pico-keys-sdk/pico_keys_sdk_import.cmake) if(ESP_PLATFORM) - project(pico_openpgp) + project(pico_openpgp) endif() set(INCLUDES ${INCLUDES} - ${CMAKE_CURRENT_LIST_DIR}/src/openpgp + ${CMAKE_CURRENT_LIST_DIR}/src/openpgp ) if(NOT ESP_PLATFORM) - target_sources(pico_openpgp PUBLIC ${SOURCES}) - target_include_directories(pico_openpgp PUBLIC ${INCLUDES}) + target_sources(pico_openpgp PUBLIC ${SOURCES}) + target_include_directories(pico_openpgp PUBLIC ${INCLUDES}) - target_compile_options(pico_openpgp PUBLIC - -Wall - ) - if(NOT MSVC) target_compile_options(pico_openpgp PUBLIC - -Werror + -Wall ) - endif() - - if(ENABLE_EMULATION) if(NOT MSVC) - target_compile_options(pico_openpgp PUBLIC - -fdata-sections - -ffunction-sections - ) + target_compile_options(pico_openpgp PUBLIC + -Werror + ) endif() - if(APPLE) - target_link_options(pico_openpgp PUBLIC - -Wl,-dead_strip - ) - elseif(MSVC) - target_compile_options(pico_openpgp PUBLIC - -WX - ) - target_link_libraries(pico_openpgp PUBLIC wsock32 ws2_32 Bcrypt) + if(ENABLE_EMULATION) + if(NOT MSVC) + target_compile_options(pico_openpgp PUBLIC + -fdata-sections + -ffunction-sections + ) + endif() + if(APPLE) + target_link_options(pico_openpgp PUBLIC + -Wl,-dead_strip + ) + elseif(MSVC) + target_compile_options(pico_openpgp PUBLIC + -WX + ) + + target_link_libraries(pico_openpgp PUBLIC wsock32 ws2_32 Bcrypt) + else() + target_link_options(pico_openpgp PUBLIC + -Wl,--gc-sections + ) + endif(APPLE) + target_link_libraries(pico_openpgp PRIVATE pthread m) else() - target_link_options(pico_openpgp PUBLIC - -Wl,--gc-sections - ) - endif(APPLE) - target_link_libraries(pico_openpgp PRIVATE pthread m) - endif() + pico_add_extra_outputs(${CMAKE_PROJECT_NAME}) + endif() endif() diff --git a/pico-keys-sdk b/pico-keys-sdk index 1d86efa..83e6d0c 160000 --- a/pico-keys-sdk +++ b/pico-keys-sdk @@ -1 +1 @@ -Subproject commit 1d86efa33bf1b3c118947eac14280f9953a49bc9 +Subproject commit 83e6d0c89fae443b4ab7f596b5f06db49f234f78 diff --git a/sdkconfig.defaults b/sdkconfig.defaults index d917312..d5613aa 100644 --- a/sdkconfig.defaults +++ b/sdkconfig.defaults @@ -4,6 +4,7 @@ IGNORE_UNKNOWN_FILES_FOR_MANAGED_COMPONENTS=1 CONFIG_TINYUSB=y +CONFIG_TINYUSB_TASK_STACK_SIZE=16384 CONFIG_PARTITION_TABLE_CUSTOM=y CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="pico-keys-sdk/config/esp32/partitions.csv" diff --git a/src/openpgp/openpgp.c b/src/openpgp/openpgp.c index 41e1482..84bdaf0 100644 --- a/src/openpgp/openpgp.c +++ b/src/openpgp/openpgp.c @@ -108,7 +108,7 @@ static int cmd_select() { uint16_t fid = 0x0; if (apdu.nc >= 2) { - fid = get_uint16_t(apdu.data, 0); + fid = get_uint16_t_be(apdu.data); } if (!pe) { @@ -1338,14 +1338,14 @@ void make_rsa_response(mbedtls_rsa_context *rsa) { res_APDU_size = 5; res_APDU[res_APDU_size++] = 0x81; res_APDU[res_APDU_size++] = 0x82; - put_uint16_t(mbedtls_mpi_size(&rsa->N), res_APDU + res_APDU_size); res_APDU_size += 2; + put_uint16_t_be(mbedtls_mpi_size(&rsa->N), res_APDU + res_APDU_size); res_APDU_size += 2; mbedtls_mpi_write_binary(&rsa->N, res_APDU + res_APDU_size, mbedtls_mpi_size(&rsa->N)); res_APDU_size += mbedtls_mpi_size(&rsa->N); res_APDU[res_APDU_size++] = 0x82; res_APDU[res_APDU_size++] = mbedtls_mpi_size(&rsa->E) & 0xff; mbedtls_mpi_write_binary(&rsa->E, res_APDU + res_APDU_size, mbedtls_mpi_size(&rsa->E)); res_APDU_size += mbedtls_mpi_size(&rsa->E); - put_uint16_t(res_APDU_size - 5, res_APDU + 3); + put_uint16_t_be(res_APDU_size - 5, res_APDU + 3); } void make_ecdsa_response(mbedtls_ecp_keypair *ecdsa) { diff --git a/src/openpgp/piv.c b/src/openpgp/piv.c index 6b37772..dc72d99 100644 --- a/src/openpgp/piv.c +++ b/src/openpgp/piv.c @@ -475,7 +475,7 @@ static int cmd_get_metadata() { } res_APDU[res_APDU_size++] = 0x81; res_APDU[res_APDU_size++] = 0x82; - put_uint16_t(mbedtls_mpi_size(&ctx.N), res_APDU + res_APDU_size); res_APDU_size += 2; + put_uint16_t_be(mbedtls_mpi_size(&ctx.N), res_APDU + res_APDU_size); res_APDU_size += 2; mbedtls_mpi_write_binary(&ctx.N, res_APDU + res_APDU_size, mbedtls_mpi_size(&ctx.N)); res_APDU_size += mbedtls_mpi_size(&ctx.N); res_APDU[res_APDU_size++] = 0x82; diff --git a/workflows/autobuild.sh b/workflows/autobuild.sh index 8f830c3..16c9600 100755 --- a/workflows/autobuild.sh +++ b/workflows/autobuild.sh @@ -22,6 +22,7 @@ mkdir build_pico cd build_pico cmake -DPICO_SDK_PATH=../pico-sdk .. make +cd .. elif [[ $1 == "esp32" ]]; then sudo apt install -y git wget flex bison gperf python3 python3-pip python3-venv cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0 git clone --recursive https://github.com/espressif/esp-idf.git @@ -31,6 +32,10 @@ cd esp-idf cd .. idf.py set-target esp32s3 idf.py all +mkdir -p release +cd build +esptool.py --chip ESP32-S3 merge_bin -o ../release/pico_openpgp_esp32-s3.bin @flash_args +cd .. else mkdir build cd build