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

wolfSSL updates #3

Merged
merged 13 commits into from
May 5, 2024
Merged

wolfSSL updates #3

merged 13 commits into from
May 5, 2024

Conversation

gojimmypi
Copy link
Collaborator

@gojimmypi gojimmypi commented May 4, 2024

This PR addresses wolfSSL SRP issues for the ESP32-C2 as noted in wolfssl issue #7210.

TL;DR: working on 6 different ESP32 devices!

  • ESP32
  • ESP32-S2
  • ESP32-S3
  • ESP32-C2
  • ESP32-C3
  • ESP32-C6

image

image

The changes in wolfssl PR #7505 are required and can be found in gojimmypi/wolfssl/tree/PR-Apple-Homekit-SRP-fix.

Note that I removed the local, static, stale copy of wolfSSL. See details on fetching into a GitHub directory, either directly from wolfSSL or from my fork, or a fork of your own. This allows easy contributions upstream as well as easily updating wolfSSL.

Here are instructions to test from the gojimmypi forks:

# set TEST_DIR to fully qualified path:
# export TEST_DIR=~/yourdir
export TEST_DIR=/mnt/c/test-homekit

cd $TEST_DIR

mkdir test-homekit
cd    test-homekit

# get a copy of the gojimmypi fork of wolfSSL (see PR)
git clone https://github.com/gojimmypi/wolfssl.git wolfssl-gojimmypi
cd wolfssl-gojimmypi
git checkout PR-Apple-Homekit-SRP-fix
cd ..

# if wolfSSL was fetched to `wolfssl` or 'wolfssl-$USER` or `wolfssl-master`
# then cmake would find it if in parent directory of example
# since it is not, we set the WOLFSSL_ROOT source code directory an environment variable:

export WOLFSSL_ROOT=$TEST_DIR/wolfssl-gojimmypi

# get a copy of the gojimmypi esp32-homekit-demo fork (see PR)
git clone --recursive https://github.com/gojimmypi/esp32-homekit-demo.git esp32-homekit-demo-gojimmypi
cd  ./esp32-homekit-demo-gojimmypi
git remote add upstream https://github.com/AchimPieters/esp32-homekit-demo.git
git checkout PR-wolfssl

# Windows users may need:
git config core.fileMode false

cd ./examples/led

# Set path for your ESP-IDF, shown here for v5.2 in WSL for VisualGDB
WRK_IDF_PATH=/mnt/c/SysGCC/esp32/esp-idf/v5.2

. ${WRK_IDF_PATH}/export.sh

idf.py set-target esp32c2
idf.py menuconfig
idf.py build

A variety of issues are noted:

Watchdog

The ESP32-C2 is relatively slow; the watchdog timer needed to be increased.

Currently the setting is 60 seconds, but can be adjusted as desired or turned off.

Suggestion to remove non-components

I see these warnings during build:

-- Component directory /mnt/c/workspace/esp32-homekit-demo-gojimmypi/components/esp-idf does not contain a CMakeLists.txt file. No component will be added
-- Component directory /mnt/c/workspace/esp32-homekit-demo-gojimmypi/components/esp32-library does not contain a CMakeLists.txt file. No component will be added

Homekit ESP32 Device Bug

Occasionally after deleting a device, when I'd reflash and try to re-add, I'd get this message at startup:

>>> HomeKit: Found admin pairing with CD52A808-E26A-45C1-AE40-296B389AD1D9, disabling pair setup

With that message, the ESP32 was not listed as a device to add. I needed to idf.py erase-flash -p /dev/ttyS79 -b 115200 to fix.

Homekit App Bug

It seems to be a Homekit app bug on the iPhone. I'm also not able to delete a device that's not online.

New testAll script

Edit the sdkconfig.defaults to ensure all the targets have the appropriate WiFi SSID and password. (probably don't want to check in to GitHub). See pattern for including parent my_private_config.h.

#
# StudioPieters
#
CONFIG_ESP_WIFI_SSID="your SSID"
CONFIG_ESP_WIFI_PASSWORD="your password"
CONFIG_ESP_LED_GPIO=2
CONFIG_ESP_SETUP_CODE="338-77-883"
CONFIG_ESP_SETUP_ID="1QJ8"

Need to fix wolfSSL setting and user settings files.

Find all instances of #include <user_settings.h> and remove them.

Find all instances of #include <wolfssl/wolfcrypt/settings.h> and ensure they appear before any other wolfSSL includes.

Find all instances of a wolfSSL include, and ensure there's a #include <wolfssl/wolfcrypt/settings.h> in each file or header.

See

  • components/homekit/src/crypto.h
  • components/homekit/src/crypto.c
  • components/homekit/src/server.c.c

Consider replacing the settings.h include with this block:

/* wolfSSL */
/* Always include wolfcrypt/settings.h before any other wolfSSL file.    */
/* Reminder: settings.h pulls in user_settings.h; don't include it here. */
#ifdef WOLFSSL_USER_SETTINGS
    #include <wolfssl/wolfcrypt/settings.h>
    #ifndef WOLFSSL_ESPIDF
        #warning "Problem with wolfSSL user_settings."
        #warning "Check components/wolfssl/include"
    #endif
    #include <wolfssl/wolfcrypt/port/Espressif/esp32-crypt.h>
#else
    /* Define WOLFSSL_USER_SETTINGS project wide for settings.h to include   */
    /* wolfSSL user settings in ./components/wolfssl/include/user_settings.h */
    #error "Missing WOLFSSL_USER_SETTINGS in CMakeLists or Makefile:\
    CFLAGS +=-DWOLFSSL_USER_SETTINGS"
#endif

ESP8266 Makefiles (via VisualGDB)

There are some makefiles included for building ESP8266, but there are missing files for the rest of the project.

See No rule to make target 'component-homekit-build', needed by 'component-main-build'. Stop. in log, below.

I didn't chase them down.

Run "C:\SysGCC\esp8266\usr\bin\bash.exe --login -c "export IDF_PATH=/rtos-sdk/v3.4 && export BATCH_BUILD=1 && export PATH=/mingw32/bin:/usr/bin:/opt/xtensa-lx106-elf/bin:$PATH && export -n PYTHONHOME && export LANG=en_US && cd /C/workspace/esp32-homekit-demo-gojimmypi/examples/led && make -j20 BUILD_DIR_BASE='/C/workspace/esp32-homekit-demo-gojimmypi/examples/led/build/Debug' SDKCONFIG='/C/workspace/esp32-homekit-demo-gojimmypi/examples/led/sdkconfig-debug' V=0"" in directory "" on local computer
C:\SysGCC\esp8266\usr\bin\bash.exe --login -c "export IDF_PATH=/rtos-sdk/v3.4 && export BATCH_BUILD=1 && export PATH=/mingw32/bin:/usr/bin:/opt/xtensa-lx106-elf/bin:$PATH && export -n PYTHONHOME && export LANG=en_US && cd /C/workspace/esp32-homekit-demo-gojimmypi/examples/led && make -j20 BUILD_DIR_BASE='/C/workspace/esp32-homekit-demo-gojimmypi/examples/led/build/Debug' SDKCONFIG='/C/workspace/esp32-homekit-demo-gojimmypi/examples/led/sdkconfig-debug' V=0"
Python requirements from C:/SysGCC/esp8266/rtos-sdk/v3.4/requirements.txt are satisfied.
GENCONFIG
App "homekit-demo" version: 18d6239-dirty
make: *** No rule to make target 'component-homekit-build', needed by 'component-main-build'.  Stop.
make: *** Waiting for unfinished jobs....
Building partitions from /rtos-sdk/v3.4/components/partition_table/partitions_singleapp.csv...
CC build/Debug/bootloader/main/bootloader_start.o
CC build/Debug/bootloader/bootloader_support/src/bootloader_random.o
CC build/Debug/bootloader/log/log.o
CC build/Debug/bootloader/bootloader_support/src/flash_encrypt.o
CC build/Debug/bootloader/bootloader_support/src/bootloader_sha.o
CC build/Debug/bootloader/spi_flash/src/spi_flash.o
CC build/Debug/bootloader/esp8266/source/ets_printf.o
CC build/Debug/bootloader/spi_flash/src/spi_flash_raw.o
CC build/Debug/bootloader/esp8266/source/crc.o
CC build/Debug/bootloader/spi_flash/port/port.o
CC build/Debug/bootloader/esp8266/source/esp_fast_boot.o
CC build/Debug/bootloader/bootloader_support/src/esp_image_format.o
CC build/Debug/bootloader/bootloader_support/src/flash_partitions.o
CC build/Debug/bootloader/bootloader_support/src/secure_boot_signatures.o
CC build/Debug/bootloader/bootloader_support/src/bootloader_clock.o
AR build/Debug/bootloader/main/libmain.a
AR build/Debug/bootloader/log/liblog.a
CC build/Debug/bootloader/bootloader_support/src/secure_boot.o
CC build/Debug/bootloader/bootloader_support/src/bootloader_common.o
AR build/Debug/bootloader/esp8266/libesp8266.a
AR build/Debug/bootloader/spi_flash/libspi_flash.a
CC build/Debug/bootloader/bootloader_support/src/bootloader_utility.o
CC build/Debug/bootloader/bootloader_support/src/bootloader_init.o
CC build/Debug/bootloader/bootloader_support/src/efuse.o
CC build/Debug/bootloader/bootloader_support/src/flash_qio_mode.o
CC build/Debug/bootloader/bootloader_support/src/bootloader_flash.o
AR build/Debug/bootloader/bootloader_support/libbootloader_support.a
LD build/Debug/bootloader/bootloader.elf
esptool.py v2.4.0
-------------------------------------------------------------
Command exited with code 2
Executable: C:\SysGCC\esp8266\usr\bin\bash.exe
Arguments: --login -c "export IDF_PATH=/rtos-sdk/v3.4 && export BATCH_BUILD=1 && export PATH=/mingw32/bin:/usr/bin:/opt/xtensa-lx106-elf/bin:$PATH && export -n PYTHONHOME && export LANG=en_US && cd /C/workspace/esp32-homekit-demo-gojimmypi/examples/led && make -j20 BUILD_DIR_BASE='/C/workspace/esp32-homekit-demo-gojimmypi/examples/led/build/Debug' SDKCONFIG='/C/workspace/esp32-homekit-demo-gojimmypi/examples/led/sdkconfig-debug' V=0"
Directory: 
Command-line action failed

========== Project Build Summary ==========
    wolfssl_ESP8266  built in 00:19
========== Build: 0 Succeeded, 1 Failed, 0 Skipped ==========

ESP8266 cmake

I'm not sure the ESP8266 is an option at this time.

cd /mnt/c/workspace/esp32-homekit-demo-gojimmypi/examples/led

WRK_IDF_PATH=/mnt/c/SysGCC/esp8266/rtos-sdk/v3.4

# Clear ESP-IDF environment variables to ensure clean start
unset ESP_IDF_VERSION
unset ESP_ROM_ELF_DIR
unset IDF_DEACTIVATE_FILE_PATH
unset IDF_PATH
unset IDF_PYTHON_ENV_PATH
unset IDF_TOOLS_EXPORT_CMD
unset IDF_TOOLS_INSTALL_CMD
unset OPENOCD_SCRIPTS

. "$WRK_IDF_PATH"/export.sh
idf.py build

There are a variety of missing dependencies in the homekit, including bt, openthread, esp_partition.
I didn't chase them down.

CMake Error at /mnt/c/SysGCC/esp8266/rtos-sdk/v3.4/tools/cmake/build.cmake:185 (message):
  Failed to resolve component 'openthread'.
Call Stack (most recent call first):
  /mnt/c/SysGCC/esp8266/rtos-sdk/v3.4/tools/cmake/build.cmake:211 (__build_resolve_and_add_req)
  /mnt/c/SysGCC/esp8266/rtos-sdk/v3.4/tools/cmake/build.cmake:407 (__build_expand_requirements)
  /mnt/c/SysGCC/esp8266/rtos-sdk/v3.4/tools/cmake/project.cmake:341 (idf_build_process)
  CMakeLists.txt:42 (project)

There's also an optional wolfSSL feature for esp_timer and driver that's not available on the ESP8266:

PRIV_REQUIRES esp_timer driver # this will typically only be needed for wolfSSL benchmark

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants