diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_client/Makefile b/IDE/Espressif/ESP-IDF/examples/wolfssl_client/Makefile index 7970240a11..225e88d6f2 100644 --- a/IDE/Espressif/ESP-IDF/examples/wolfssl_client/Makefile +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_client/Makefile @@ -1,29 +1,34 @@ # -# This is a project Makefile. It is assumed the directory this Makefile resides in is a -# project subdirectory. +# This is a project Makefile. +# It is assumed the directory this Makefile resides in is a +# project subdirectory containing an entire project. # PROJECT_NAME := wolfssl_client -#OS := $(shell uname -s) -#ifeq ($(OS),Linux) - #CFLAGS += -DOS_LINUX -#endif -#ifeq ($(OS),Darwin) - #CFLAGS += -DOS_MACOS -#endif -#ifneq (,$(findstring MINGW,$(OS))) - #CFLAGS += -DOS_WINDOWS_MINGW -#endif -#ifneq (,$(findstring CYGWIN,$(OS))) - #CFLAGS += -DOS_WINDOWS_CYGWIN -#endif -#CFLAGS += -DOS_WINDOWS +# Calling shell causes unintuiive error in Windows: +# OS := $(shell uname -s) +# But OS should already be defined: +ifeq ($(OS),Linux) + CFLAGS += -DOS_LINUX +endif +ifeq ($(OS),Windows_NT) + CFLAGS += -DWOLFSSL_MAKE_SYSTEM_NAME_WINDOWS +endif +ifeq ($(OS),Darwin) + CFLAGS += -DWOLFSSL_MAKE_SYSTEM_NAME_APPLE +endif +ifneq (,$(findstring MINGW,$(OS))) + CFLAGS += -DWOLFSSL_MAKE_SYSTEM_NAME_MINGW +endif +ifneq (,$(findstring CYGWIN,$(OS))) + CFLAGS += -DWOLFSSL_MAKE_SYSTEM_NAME_CYGWIN +endif +# It is essential that the build process sees the WOLFSSL_USER_SETTINGS CFLAGS += -DWOLFSSL_USER_SETTINGS + # if directory not available, please disable the line below. EXTRA_COMPONENT_DIRS = $(IDF_PATH)/examples/common_components/protocol_examples_common -# LDFLAGS += -T ./my.esp8266.project.ld - include $(IDF_PATH)/make/project.mk diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/client-tls.c b/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/client-tls.c index 395b086a48..6eacbbe83c 100644 --- a/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/client-tls.c +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/client-tls.c @@ -18,7 +18,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA */ - #include "client-tls.h" /* Espressif FreeRTOS */ @@ -28,6 +27,9 @@ #include #endif +/* Espressif */ +#include + /* socket includes */ #include #include @@ -62,7 +64,7 @@ * -h 192.168.1.128 -v 4 -l TLS13-SM4-CCM-SM3 -c ./certs/sm2/client-sm2.pem -k ./certs/sm2/client-sm2-priv.pem -A ./certs/sm2/root-sm2.pem -C * **/ -static const char* const TAG = "client-tls"; +#define TAG "client-tls" #if defined(DEBUG_WOLFSSL) int stack_start = -1; @@ -239,29 +241,29 @@ WOLFSSL_ESP_TASK tls_smp_client_task(void* args) * * reference code for SM Ciphers: * - #if defined(HAVE_AESGCM) && !defined(NO_DH) - #ifdef WOLFSSL_TLS13 - defaultCipherList = "TLS13-AES128-GCM-SHA256" - #ifndef WOLFSSL_NO_TLS12 - ":DHE-PSK-AES128-GCM-SHA256" - #endif - ; - #else - defaultCipherList = "DHE-PSK-AES128-GCM-SHA256"; + #if defined(HAVE_AESGCM) && !defined(NO_DH) + #ifdef WOLFSSL_TLS13 + defaultCipherList = "TLS13-AES128-GCM-SHA256" + #ifndef WOLFSSL_NO_TLS12 + ":DHE-PSK-AES128-GCM-SHA256" #endif - #elif defined(HAVE_AESGCM) && defined(WOLFSSL_TLS13) - defaultCipherList = "TLS13-AES128-GCM-SHA256:PSK-AES128-GCM-SHA256" - #ifndef WOLFSSL_NO_TLS12 - ":PSK-AES128-GCM-SHA256" - #endif - ; - #elif defined(HAVE_NULL_CIPHER) - defaultCipherList = "PSK-NULL-SHA256"; - #elif !defined(NO_AES_CBC) - defaultCipherList = "PSK-AES128-CBC-SHA256"; + ; #else - defaultCipherList = "PSK-AES128-GCM-SHA256"; + defaultCipherList = "DHE-PSK-AES128-GCM-SHA256"; #endif + #elif defined(HAVE_AESGCM) && defined(WOLFSSL_TLS13) + defaultCipherList = "TLS13-AES128-GCM-SHA256:PSK-AES128-GCM-SHA256" + #ifndef WOLFSSL_NO_TLS12 + ":PSK-AES128-GCM-SHA256" + #endif + ; + #elif defined(HAVE_NULL_CIPHER) + defaultCipherList = "PSK-NULL-SHA256"; + #elif !defined(NO_AES_CBC) + defaultCipherList = "PSK-AES128-CBC-SHA256"; + #else + defaultCipherList = "PSK-AES128-GCM-SHA256"; + #endif */ ret = wolfSSL_CTX_set_cipher_list(ctx, WOLFSSL_ESP32_CIPHER_SUITE); @@ -269,16 +271,16 @@ WOLFSSL_ESP_TASK tls_smp_client_task(void* args) ESP_LOGI(TAG, "Set cipher list: %s\n", WOLFSSL_ESP32_CIPHER_SUITE); } else { - ESP_LOGE(TAG, "ERROR: failed to set cipher list: %s\n", WOLFSSL_ESP32_CIPHER_SUITE); + ESP_LOGE(TAG, "ERROR: failed to set cipher list: %s\n", + WOLFSSL_ESP32_CIPHER_SUITE); } #endif #ifdef DEBUG_WOLFSSL ShowCiphers(NULL); - ESP_LOGI(TAG, - "Stack used: %d\n", - CONFIG_ESP_MAIN_TASK_STACK_SIZE - - uxTaskGetStackHighWaterMark(NULL)); + ESP_LOGI(TAG, "Stack used: %d\n", + CONFIG_ESP_MAIN_TASK_STACK_SIZE + - uxTaskGetStackHighWaterMark(NULL)); #endif /* see user_settings PROJECT_DH for HAVE_DH and HAVE_FFDHE_2048 */ @@ -303,7 +305,8 @@ WOLFSSL_ESP_TASK tls_smp_client_task(void* args) CTX_CLIENT_CERT_SIZE, CTX_CLIENT_CERT_TYPE); if (ret_i != SSL_SUCCESS) { - ESP_LOGE(TAG, "ERROR: failed to load chain %d, please check the file.\n", ret_i); + ESP_LOGE(TAG, "ERROR: failed to load chain %d, " + "please check the file.", ret_i); } /* Load client certificates into WOLFSSL_CTX */ @@ -440,7 +443,8 @@ WOLFSSL_ESP_TASK tls_smp_client_task(void* args) printf("%s\n", buff); } else { - ESP_LOGE(TAG, "ERROR: failed to connect to wolfSSL. Error: %d\n", ret_i); + ESP_LOGE(TAG, "ERROR: failed to connect to wolfSSL. " + "Error: %d\n", ret_i); } #ifdef DEBUG_WOLFSSL ShowCiphers(ssl); diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/component.mk b/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/component.mk index 6a0ac95522..0adf45649a 100644 --- a/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/component.mk +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/component.mk @@ -6,5 +6,3 @@ # in the build directory. This behaviour is entirely configurable, # please read the ESP-IDF documents if you need to do this. # - -COMPONENT_SRCDIRS += diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/include/client-tls.h b/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/include/client-tls.h index 283e16eecd..6a2fde47b7 100644 --- a/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/include/client-tls.h +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/include/client-tls.h @@ -41,14 +41,14 @@ #endif #define TLS_SMP_CLIENT_TASK_NAME "tls_client_example" -//#define TLS_SMP_CLIENT_TASK_BYTES (26 * 1024) -// #define TLS_SMP_CLIENT_TASK_BYTES (20 * 1024) /* leave handshake fail -125*/ +/* Reminder: Vanilla FreeRTOS is words, Espressif is bytes. */ #if defined(WOLFSSL_ESP8266) - #define TLS_SMP_CLIENT_TASK_BYTES (6 * 1024) + #define TLS_SMP_CLIENT_TASK_BYTES (6 * 1024) #else #define TLS_SMP_CLIENT_TASK_BYTES (8 * 1024) #endif + #define TLS_SMP_CLIENT_TASK_PRIORITY 8 #if defined(SINGLE_THREADED) diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/include/wifi_connect.h b/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/include/wifi_connect.h index fbca3bdfa8..c911147717 100644 --- a/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/include/wifi_connect.h +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/include/wifi_connect.h @@ -21,9 +21,6 @@ #ifndef _WIFI_CONNECT_H_ #define _WIFI_CONNECT_H_ -#include -#include - /* ESP lwip */ #define EXAMPLE_ESP_MAXIMUM_RETRY CONFIG_ESP_MAXIMUM_RETRY @@ -36,6 +33,10 @@ #include "protocol_examples_common.h" /* see project CMakeLists.txt */ #endif +#ifdef OS_WINDOWS + // #error "OS_WINDOWS" +#endif + /** ****************************************************************************** ****************************************************************************** @@ -48,15 +49,35 @@ * file my_private_config.h should be excluded from git updates */ #define USE_MY_PRIVATE_CONFIG +/* Note that IntelliSense may not work properly in the next section for the + * Espressif SDK 3.4 on the ESP8266. Macros should still be defined. + * See the project-level Makefile. Example found in: + * https://github.com/wolfSSL/wolfssl/tree/master/IDE/Espressif/ESP-IDF/examples/template + */ #ifdef USE_MY_PRIVATE_CONFIG #if defined(WOLFSSL_CMAKE_SYSTEM_NAME_WINDOWS) + #define WOLFSSL_CMAKE + #include "/workspace/my_private_config.h" + #elif defined(WOLFSSL_MAKE_SYSTEM_NAME_WINDOWS) + #define WOLFSSL_MAKE #include "/workspace/my_private_config.h" #elif defined(WOLFSSL_CMAKE_SYSTEM_NAME_WSL) + #define WOLFSSL_CMAKE + #include "/mnt/c/workspace/my_private_config.h" + #elif defined(WOLFSSL_MAKE_SYSTEM_NAME_WSL) + #define WOLFSSL_MAKE #include "/mnt/c/workspace/my_private_config.h" #elif defined(WOLFSSL_CMAKE_SYSTEM_NAME_LINUX) + #define WOLFSSL_CMAKE + #include "~/workspace/my_private_config.h" + #elif defined(WOLFSSL_MAKE_SYSTEM_NAME_LINUX) + #define WOLFSSL_MAKE #include "~/workspace/my_private_config.h" #elif defined(WOLFSSL_CMAKE_SYSTEM_NAME_APPLE) #include "~/Documents/my_private_config.h" + #elif defined(WOLFSSL_MAKE_SYSTEM_NAME_APPLE) + #define WOLFSSL_MAKE + #include "~/Documents/my_private_config.h" #elif defined(OS_WINDOWS) #include "/workspace/my_private_config.h" #else diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/main.c b/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/main.c index 73d888ac03..121bfdb761 100644 --- a/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/main.c +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/main.c @@ -264,7 +264,8 @@ void app_main(void) args[0].port = 11111; int this_heap = esp_get_free_heap_size(); - ESP_LOGI(TAG, "main tls_smp_client_init heap @ %p = %d", &this_heap, this_heap); + ESP_LOGI(TAG, "main tls_smp_client_init heap @ %p = %d", + &this_heap, this_heap); tls_smp_client_init(args); /* optional additional client threads tls_smp_client_init(args); diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/time_helper.c b/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/time_helper.c index e8a408ab6b..5eb06a140a 100644 --- a/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/time_helper.c +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/time_helper.c @@ -175,13 +175,13 @@ int probably_valid_time_string(const char* str) int set_time_from_string(const char* time_buffer) { /* expecting github default formatting: 'Thu Aug 31 12:41:45 2023 -0700' */ + char offset[28]; /* large arrays, just in case there's still bad data */ + char day_str[28]; + char month_str[28]; const char *format = "%3s %3s %d %d:%d:%d %d %s"; struct tm this_timeinfo; struct timeval now; time_t interim_time; - char offset[28]; /* large arrays, just in case there's still bad data */ - char day_str[28]; - char month_str[28]; int day, year, hour, minute, second; int quote_offset = 0; int ret = 0; @@ -224,8 +224,9 @@ int set_time_from_string(const char* time_buffer) ESP_LOGI(TAG, "Time updated to %s", time_buffer); } else { - ESP_LOGE(TAG, "Failed to convert \"%s\" to a tm date.", time_buffer); - ESP_LOGI(TAG, "Trying fixed date that was hard-coded."); + ESP_LOGE(TAG, "Failed to convert \"%s\" to a tm date.", + time_buffer); + ESP_LOGI(TAG, "Trying fixed date that was hard-coded...."); set_fixed_default_time(); ret = ESP_FAIL; } diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/wifi_connect.c b/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/wifi_connect.c index ab1acd00d5..c05e3867e0 100644 --- a/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/wifi_connect.c +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/wifi_connect.c @@ -18,13 +18,17 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA */ - #include "wifi_connect.h" +#include "wifi_connect.h" +/* FreeRTOS */ #include #include #include -#include + +/* Espressif */ #include +#include +#include /* wolfSSL */ #include