Skip to content

Commit

Permalink
polish Espressif wolfssl client for PR
Browse files Browse the repository at this point in the history
  • Loading branch information
gojimmypi committed Feb 14, 2024
1 parent 54a0070 commit e9b0b22
Show file tree
Hide file tree
Showing 12 changed files with 198 additions and 50 deletions.
126 changes: 113 additions & 13 deletions IDE/Espressif/ESP-IDF/examples/wolfssl_client/Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,127 @@
# ESP8266 Project Makefile for wolfssl_client
#
# Copyright (C) 2006-2024 wolfSSL Inc.
#
# This file is part of wolfSSL.
#
# wolfSSL is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# wolfSSL is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
#

#
# This is a project Makefile.
# It is assumed the directory this Makefile resides in is a
# project subdirectory containing an entire project.
#

# Optional private config headers. Define environment variables
# to include various default header files that are typically
# not in a git path, and thus excluded from being checked in.
#
# Environment Variable Name | Header file name included
# ---------------------------------- | ---------------------------------------
# MY_PRIVATE_CONFIG (files detected / selected in header)
# USE_MY_PRIVATE_WSL_CONFIG /mnt/c/workspace/my_private_config.h
# USE_MY_PRIVATE_MAC_CONFIG ~/Documents/my_private_config.h
# USE_MY_PRIVATE_LINUX_CONFIG ~/workspace/my_private_config.h
# USE_MY_PRIVATE_WINDOWS_CONFIG /workspace/my_private_config.h
#
#
PROJECT_NAME := wolfssl_client

# Calling shell causes unintuiive error in Windows:
MY_PRIVATE_CONFIG ?= n
USE_MY_PRIVATE_WSL_CONFIG ?= n
USE_MY_PRIVATE_MAC_CONFIG ?= n
USE_MY_PRIVATE_LINUX_CONFIG ?= n
USE_MY_PRIVATE_WINDOWS_CONFIG ?= n

# Calling shell causes unintuitive error in Windows:
# OS := $(shell uname -s)
# But OS should already be defined:
ifeq ($(OS),Linux)
CFLAGS += -DOS_LINUX
#
# But OS, or MY_PRIVATE_CONFIG should already be defined:
$(info ************* wolfssl_client *************)

ifeq ($(MY_PRIVATE_CONFIG),y)
CFLAGS += -DMY_PRIVATE_CONFIG
$(info Enabled MY_PRIVATE_CONFIG")
endif

# Check for Windows environment variable: USE_MY_PRIVATE_WINDOWS_CONFIG
ifeq ($(USE_MY_PRIVATE_WINDOWS_CONFIG),y)
# This hard coded MY_CONFIG_FILE value must match that in the header file.
MY_CONFIG_FILE := /workspace/my_private_config.h
ifeq ($(wildcard $(MY_CONFIG_FILE)),)
$(info File does not exist: $(MY_CONFIG_FILE))
else
CFLAGS += -DUSE_MY_PRIVATE_WINDOWS_CONFIG
$(info Using private config file for: Windows)
endif
endif
ifeq ($(OS),Windows_NT)
CFLAGS += -DWOLFSSL_MAKE_SYSTEM_NAME_WINDOWS

# Check for WSL environment variable: USE_MY_PRIVATE_WSL_CONFIG
ifeq ($(USE_MY_PRIVATE_WSL_CONFIG),y)
# This hard coded MY_CONFIG_FILE value must match that in the header file.
MY_CONFIG_FILE := /mnt/c/workspace/my_private_config.h
ifeq ($(wildcard $(MY_CONFIG_FILE)),)
$(info File does not exist: $(MY_CONFIG_FILE))
else
CFLAGS += -DUSE_MY_PRIVATE_WSL_CONFIG
$(info Using private config file for: WSL)
endif
endif
ifeq ($(OS),Darwin)
CFLAGS += -DWOLFSSL_MAKE_SYSTEM_NAME_APPLE

# Check for Linux environment variable: USE_MY_PRIVATE_LINUX_CONFIG
ifeq ($(USE_MY_PRIVATE_LINUX_CONFIG),y)
# This hard coded MY_CONFIG_FILE value must match that in the header file.
MY_CONFIG_FILE := ~/workspace/my_private_config.h
ifeq ($(wildcard $(MY_CONFIG_FILE)),)
$(info File does not exist: $(MY_CONFIG_FILE))
else
CFLAGS += -DUSE_MY_PRIVATE_LINUX_CONFIG
$(info Using private config file for: Linux)
endif
endif
ifneq (,$(findstring MINGW,$(OS)))
CFLAGS += -DWOLFSSL_MAKE_SYSTEM_NAME_MINGW

# Check for Mac environment variable: USE_MY_PRIVATE_MAC_CONFIG
ifeq ($(USE_MY_PRIVATE_MAC_CONFIG),y)
# This hard coded MY_CONFIG_FILE value must match that in the header file.
MY_CONFIG_FILE := ~/Documents/my_private_config.h
ifeq ($(wildcard $(MY_CONFIG_FILE)),)
$(info File does not exist: $(MY_CONFIG_FILE))
else
CFLAGS += -DUSE_MY_PRIVATE_MAC_CONFIG
$(info Using private config file for: Mac)
endif
endif
ifneq (,$(findstring CYGWIN,$(OS)))
CFLAGS += -DWOLFSSL_MAKE_SYSTEM_NAME_CYGWIN

ifneq ($(OS),MY_PRIVATE_CONFIG)
CFLAGS += -DMY_PRIVATE_CONFIG="$(MY_PRIVATE_CONFIG)"
else
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
endif

# It is essential that the build process sees the WOLFSSL_USER_SETTINGS
Expand All @@ -31,4 +130,5 @@ CFLAGS += -DWOLFSSL_USER_SETTINGS
# if directory not available, please disable the line below.
EXTRA_COMPONENT_DIRS = $(IDF_PATH)/examples/common_components/protocol_examples_common

# The Standard Espressif IDF include:
include $(IDF_PATH)/make/project.mk
44 changes: 31 additions & 13 deletions IDE/Espressif/ESP-IDF/examples/wolfssl_client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,22 @@ The latest examples use makefiles that do not require local file copy installati

Build and flash the software to see the example in action.

## Quick Start with VisualGDB

There are optional [VisualGDB](https://visualgdb.com/tutorials/esp8266/) project files in the
[VisualGDB](./VisualGDB) project subdirectory, and an ESP8266 project file in the project directory,
called `wolfssl_client_ESP8266.vgdbproj`.

Open the VisualGDB Visual Studio Project file in the VisualGDB directory and click the "Start" button.
No wolfSSL setup is needed. You may need to adjust your specific COM port. The default is `COM19`.

## Troubleshooting

Weird results, odd messages, unexpected compiler errors? Manually delete the build directory and
any locally generated files (`sdkconfig`, `sdkconfig-debug`, etc.) and start over.

The `build` directory is typically located in the root of the project directory: `[project]/build`.

For Windows Arduino users, there is the set of hash-named directories located here:

```text
C:\Users\%USERNAME%\AppData\Local\Temp\arduino\sketches
```

Difficulty flashing:

Expand All @@ -47,11 +51,6 @@ Difficulty flashing:
* Review board specifications: some require manual boot mode via on-board buttons.
* See [Espressif ESP Frequently Asked Questions](https://docs.espressif.com/projects/esp-faq/en/latest/esp-faq-en-master.pdf)

## VisualGDB

Open the VisualGDB Visual Studio Project file in the VisualGDB directory and click the "Start" button.
No wolfSSL setup is needed. You may need to adjust your specific COM port. The default is `COM20`.

## ESP-IDF Commandline v5.x


Expand Down Expand Up @@ -84,27 +83,46 @@ Reminder that we build with `make` and not `cmake` in VisualGDB.

Build files will be created in `[project directory]\build`

## ESP-IDF make Commandline (version 3.5 or earlier for the ESP8266)

```
export IDF_PATH=~/esp/ESP8266_RTOS_SDK
```


## ESP-IDF CMake Commandline (version 3.5 or earlier for the ESP8266)

Build files will be created in `[project directory]\build\debug`

```
# Set your path to RTOS SDK, shown here for default from WSL vis VisualGDB
# Set your path to RTOS SDK, shown here for default from WSL with VisualGDB
WRK_IDF_PATH=/mnt/c/SysGCC/esp8266/rtos-sdk/v3.4
# or
WRK_IDF_PATH=~/esp/ESP8266_RTOS_SDK
# Setup the environment
. $WRK_IDF_PATH/export.sh
# install as needed / prompted
/mnt/c/SysGCC/esp8266/rtos-sdk/v3.4/install.sh
cd IDE/Espressif/ESP-IDF/examples/wolfssl_client
# Fetch wolfssl from GitHub if needed:
cd /workspace
git clone https://github.com/wolfSSL/wolfssl.git
# change directory to wolfssl client example.
cd wolfssl/IDE/Espressif/ESP-IDF/examples/wolfssl_client
# or for example, WSL with C:\workspace as home for git clones:
# cd /mnt/c/workspace/wolfssl-$USER/IDE/Espressif/ESP-IDF/examples/wolfssl_client
# adjust settings as desired
idf.py menuconfig
idf.py build flash -p /dev/ttyS55 -b 115200
idf.py build flash -p /dev/ttyS70 -b 115200
idf.py monitor -p /dev/ttyS70 -b 74880
```

## SM Ciphers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* user_settings.h
*
* Copyright (C) 2006-2023 wolfSSL Inc.
* Copyright (C) 2006-2024 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
Expand All @@ -19,6 +19,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/

/* Standardized wolfSSL Espressif ESP32 + ESP8266 user_settings.h V5.6.6-01 */

/* This user_settings.h is for Espressif ESP-IDF */
#include <sdkconfig.h>
#define DEBUG_WOLFSSL
Expand Down Expand Up @@ -214,10 +216,6 @@
* Uncomment lines to force SW instead of HW acceleration */
#if defined(CONFIG_IDF_TARGET_ESP32)
#define WOLFSSL_ESP32
// #define NO_ESP32_CRYPT
#define NO_WOLFSSL_ESP32_CRYPT_HASH
// #define NO_WOLFSSL_ESP32_CRYPT_AES
// #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI
/* wolfSSL HW Acceleration supported on ESP32. Uncomment to disable: */
/* #define NO_ESP32_CRYPT */
/* #define NO_WOLFSSL_ESP32_CRYPT_HASH */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* client-tls.c
*
* Copyright (C) 2006-2023 wolfSSL Inc.
* Copyright (C) 2006-2024 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
Expand Down Expand Up @@ -334,7 +334,7 @@ WOLFSSL_ESP_TASK tls_smp_client_task(void* args)

/* Fill in the server address */
servAddr.sin_family = AF_INET; /* using IPv4 */
servAddr.sin_port = htons(11111); /* on DEFAULT_PORT */
servAddr.sin_port = htons(TLS_SMP_DEFAULT_PORT); /* on DEFAULT_PORT */

if (*ch >= '1' && *ch <= '9') {
/* Get the server IPv4 address from the command line call */
Expand All @@ -353,7 +353,7 @@ WOLFSSL_ESP_TASK tls_smp_client_task(void* args)
sprintf(buff,
"Connecting to server....%s(port:%d)",
TLS_SMP_TARGET_HOST,
11111);
TLS_SMP_DEFAULT_PORT);
WOLFSSL_MSG(buff);
printf("%s\n", buff);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
#
# This Makefile can be left empty. By default, it will take the sources in the
# src/ directory, compile them and link them into lib(subdirectory_name).a
# in the build directory. This behaviour is entirely configurable,
# in the build directory. This behavior is entirely configurable,
# please read the ESP-IDF documents if you need to do this.
#
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* client-tls.h
*
* Copyright (C) 2006-2023 wolfSSL Inc.
* Copyright (C) 2006-2024 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
Expand All @@ -18,8 +18,8 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
#ifndef _SERVER_TLS_
#define _SERVER_TLS_
#ifndef _CLIENT_TLS_H_
#define _CLIENT_TLS_H_

/* Local project, auto-generated configuration */
#include "sdkconfig.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* template main.h
/* wolfssl_client main.h
*
* Copyright (C) 2006-2023 wolfSSL Inc.
* Copyright (C) 2006-2024 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
#include "protocol_examples_common.h" /* see project CMakeLists.txt */
#endif

#ifdef OS_WINDOWS
// #error "OS_WINDOWS"
#endif

/**
******************************************************************************
******************************************************************************
Expand All @@ -53,8 +49,20 @@
* 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
*
* The USE_MY_PRIVATE_[OS]_CONFIG is typically an environment variable that
* triggers the make (not cmake) to add compiler defines.
*/
#ifdef USE_MY_PRIVATE_CONFIG
#if defined(USE_MY_PRIVATE_WINDOWS_CONFIG)
#include "/workspace/my_private_config.h"
#elif defined(USE_MY_PRIVATE_WSL_CONFIG)
#include "/mnt/c/workspace/my_private_config.h"
#elif defined(USE_MY_PRIVATE_LINUX_CONFIG)
#include "~/workspace/my_private_config.h"
#elif defined(USE_MY_PRIVATE_MAC_CONFIG)
#include "~/Documents/my_private_config.h"
#elif defined(USE_MY_PRIVATE_CONFIG)
/* This section works best with cmake & non-environment variable setting */
#if defined(WOLFSSL_CMAKE_SYSTEM_NAME_WINDOWS)
#define WOLFSSL_CMAKE
#include "/workspace/my_private_config.h"
Expand All @@ -81,7 +89,7 @@
#elif defined(OS_WINDOWS)
#include "/workspace/my_private_config.h"
#else
// #warning "did not detect environment. using ~/my_private_config.h"
#warning "default private config using /workspace/my_private_config.h"
#include "/workspace/my_private_config.h"
#endif
#else
Expand Down
2 changes: 1 addition & 1 deletion IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* main.c
*
* Copyright (C) 2006-2023 wolfSSL Inc.
* Copyright (C) 2006-2024 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
Expand Down
Loading

0 comments on commit e9b0b22

Please sign in to comment.