Merge pull request #399 from gojimmypi/ESP32-DTLS13
Initial ESP32 DTLS 1.3 client and server examplespull/400/head
commit
57e641e6a9
|
@ -0,0 +1,43 @@
|
|||
# The following lines of boilerplate have to be in your project's
|
||||
# CMakeLists in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
# set(WOLFSSL_ROOT "~/workspace/wolfssl-other-source")
|
||||
|
||||
# This tag is used to include this file in the ESP Component Registry:
|
||||
# __ESP_COMPONENT_SOURCE__
|
||||
|
||||
# Optional WOLFSSL_CMAKE_SYSTEM_NAME detection to find
|
||||
# USE_MY_PRIVATE_CONFIG path for my_private_config.h
|
||||
#
|
||||
if(WIN32)
|
||||
# Windows-specific configuration here
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_CMAKE_SYSTEM_NAME_WINDOWS")
|
||||
message("Detected Windows")
|
||||
endif()
|
||||
if(CMAKE_HOST_UNIX)
|
||||
message("Detected UNIX")
|
||||
endif()
|
||||
if(APPLE)
|
||||
message("Detected APPLE")
|
||||
endif()
|
||||
if(CMAKE_HOST_UNIX AND (NOT APPLE) AND EXISTS "/proc/sys/fs/binfmt_misc/WSLInterop")
|
||||
# Windows-specific configuration here
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_CMAKE_SYSTEM_NAME_WSL")
|
||||
message("Detected WSL")
|
||||
endif()
|
||||
if(CMAKE_HOST_UNIX AND (NOT APPLE) AND (NOT WIN32))
|
||||
# Windows-specific configuration here
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_CMAKE_SYSTEM_NAME_LINUX")
|
||||
message("Detected Linux")
|
||||
endif()
|
||||
if(APPLE)
|
||||
# Windows-specific configuration here
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_CMAKE_SYSTEM_NAME_APPLE")
|
||||
message("Detected Apple")
|
||||
endif()
|
||||
# End optional WOLFSSL_CMAKE_SYSTEM_NAME
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
|
||||
project(wolfssl_dtls13_client)
|
|
@ -0,0 +1,45 @@
|
|||
# The following lines of boilerplate have to be in your project's
|
||||
# CMakeLists in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
# set(WOLFSSL_ROOT "~/workspace/wolfssl-other-source")
|
||||
# This example uses an extra component for common functions such as Wi-Fi and Ethernet connection.
|
||||
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common)
|
||||
|
||||
# This tag is used to include this file in the ESP Component Registry:
|
||||
# __ESP_COMPONENT_SOURCE__
|
||||
|
||||
# Optional WOLFSSL_CMAKE_SYSTEM_NAME detection to find
|
||||
# USE_MY_PRIVATE_CONFIG path for my_private_config.h
|
||||
#
|
||||
if(WIN32)
|
||||
# Windows-specific configuration here
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_CMAKE_SYSTEM_NAME_WINDOWS")
|
||||
message("Detected Windows")
|
||||
endif()
|
||||
if(CMAKE_HOST_UNIX)
|
||||
message("Detected UNIX")
|
||||
endif()
|
||||
if(APPLE)
|
||||
message("Detected APPLE")
|
||||
endif()
|
||||
if(CMAKE_HOST_UNIX AND (NOT APPLE) AND EXISTS "/proc/sys/fs/binfmt_misc/WSLInterop")
|
||||
# Windows-specific configuration here
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_CMAKE_SYSTEM_NAME_WSL")
|
||||
message("Detected WSL")
|
||||
endif()
|
||||
if(CMAKE_HOST_UNIX AND (NOT APPLE) AND (NOT WIN32))
|
||||
# Windows-specific configuration here
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_CMAKE_SYSTEM_NAME_LINUX")
|
||||
message("Detected Linux")
|
||||
endif()
|
||||
if(APPLE)
|
||||
# Windows-specific configuration here
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_CMAKE_SYSTEM_NAME_APPLE")
|
||||
message("Detected Apple")
|
||||
endif()
|
||||
# End optional WOLFSSL_CMAKE_SYSTEM_NAME
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
|
||||
project(wolfssl_dtls13_server)
|
|
@ -0,0 +1,76 @@
|
|||
# wolfSSL DTLS1.3 Project
|
||||
|
||||
This is an example minimally viable wolfSSL template to get started with your own project.
|
||||
|
||||
### Prerequisites
|
||||
|
||||
It is assumed the [ESP-IDF environment](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/) has been installed.
|
||||
|
||||
```
|
||||
gcc -o client-dtls13 client-dtls13.c -L/mnt/c/workspace/wolfssl-gojimmypi/src/.libs -I/mnt/c/workspace/wolfssl-gojimmypi/ -I/mnt/c/workspace/wolfssl-gojimmypi/include -DWOLFSSL_TLS13 -DWOLFSSL_DTLS -DWOLFSSL_DTLS13 -DWOLFSSL_USER_SETTINGS -lwolfssl -ldl -lm
|
||||
```
|
||||
|
||||
### Files Included
|
||||
|
||||
- [main.c](./main/main.c) with a simple call to an Espressif library (`ESP_LOGI`) and a call to a wolfSSL library (`esp_ShowExtendedSystemInfo`) .
|
||||
|
||||
- See [components/wolfssl/include](./components/wolfssl/include/user_settings.h) directory to edit the wolfSSL `user_settings.h`.
|
||||
|
||||
- Edit [main/CMakeLists.txt](./main/CMakeLists.txt) to add/remove source files.
|
||||
|
||||
- The [components/wolfssl/CMakeLists.txt](./components/wolfssl/CMakeLists.txt) typically does not need to be changed.
|
||||
|
||||
- Optional [VisualGDB Project](./VisualGDB/wolfssl_template_IDF_v5.1_ESP32.vgdbproj) for Visual Studio using ESP32 and ESP-IDF v5.1.
|
||||
|
||||
- Edit the project [CMakeLists.txt](./CMakeLists.txt) to optionally point this project's wolfSSL component source code at a different directory:
|
||||
|
||||
```
|
||||
set(WOLFSSL_ROOT "~/workspace/wolfssl-other-source")
|
||||
```
|
||||
|
||||
|
||||
## Getting Started:
|
||||
|
||||
Here's an example using the command-line [idf.py](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-py.html).
|
||||
|
||||
Edit your `WRK_IDF_PATH`to point to your ESP-IDF install directory.
|
||||
|
||||
```
|
||||
cd /mnt/C/workspace/wolfssl-gojimmypi/IDE/Espressif/ESP-IDF5/examples/wolfssl_dtls13_server
|
||||
|
||||
WRK_IDF_PATH=/mnt/c/SysGCC/esp32/esp-idf/v5.1
|
||||
|
||||
echo "Run export.sh from ${WRK_IDF_PATH}"
|
||||
. ${WRK_IDF_PATH}/export.sh
|
||||
|
||||
# build the example:
|
||||
idf.py build
|
||||
|
||||
# flash the code onto the serial device at /dev/ttyS19
|
||||
idf.py flash -p /dev/ttyS19 -b 115200
|
||||
|
||||
# build, flash, and view UART output with one command:
|
||||
idf.py flash -p /dev/ttyS19 -b 115200 monitor
|
||||
|
||||
# erase
|
||||
idf.py erase-flash -p /dev/ttyS9 -b 115200
|
||||
|
||||
# save defaults
|
||||
idf.py save-defconfig
|
||||
```
|
||||
|
||||
Press `Ctrl+]` to exit `idf.py monitor`. See [additional monitor keyboard commands](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-monitor.html).
|
||||
|
||||
## Other Examples:
|
||||
|
||||
For examples, see:
|
||||
|
||||
- [TLS Client](../wolfssl_client/README.md)
|
||||
- [TLS Server](../wolfssl_server/README.md)
|
||||
- [Benchmark](../wolfssl_benchmark/README.md)
|
||||
- [Test](../wolfssl_test/README.md)
|
||||
- [wolfssl-examples](https://github.com/wolfSSL/wolfssl-examples/tree/master/ESP32)
|
||||
- [wolfssh-examples](https://github.com/wolfSSL/wolfssh-examples/tree/main/Espressif)
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,269 @@
|
|||
<?xml version="1.0"?>
|
||||
<VisualGDBProjectSettings2 xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<Project xsi:type="com.visualgdb.project.external.esp-idf">
|
||||
<CustomSourceDirectories>
|
||||
<Directories />
|
||||
<PathStyle>Unknown</PathStyle>
|
||||
</CustomSourceDirectories>
|
||||
<AutoProgramSPIFFSPartition>true</AutoProgramSPIFFSPartition>
|
||||
<ProjectModeSettings>
|
||||
<ProjectGUID>7bbd1486-d457-4e49-92ba-0cfc9d80849e</ProjectGUID>
|
||||
<GroupSourcesByTypes>true</GroupSourcesByTypes>
|
||||
<GroupSourcesByPaths>true</GroupSourcesByPaths>
|
||||
<HeaderScanMode>SourceDirs</HeaderScanMode>
|
||||
</ProjectModeSettings>
|
||||
</Project>
|
||||
<Build xsi:type="com.visualgdb.build.cmake">
|
||||
<BuildLogMode xsi:nil="true" />
|
||||
<ToolchainID>
|
||||
<ID>com.visualgdb.xtensa-esp32-elf</ID>
|
||||
<Version>
|
||||
<GCC>12.2.0</GCC>
|
||||
<GDB>12.1</GDB>
|
||||
<Revision>1</Revision>
|
||||
</Version>
|
||||
</ToolchainID>
|
||||
<RelativeSourceDirectory>..</RelativeSourceDirectory>
|
||||
<ConfigurationType>DEBUG</ConfigurationType>
|
||||
<BinaryDirectory>build/$(PlatformName)/$(ConfigurationName)</BinaryDirectory>
|
||||
<MakeCommandTemplate>
|
||||
<SkipWhenRunningCommandList>false</SkipWhenRunningCommandList>
|
||||
<Command>$(ToolchainNinja)</Command>
|
||||
<WorkingDirectory>$(BuildDir)</WorkingDirectory>
|
||||
<BackgroundMode xsi:nil="true" />
|
||||
</MakeCommandTemplate>
|
||||
<CMakeCommand>
|
||||
<SkipWhenRunningCommandList>false</SkipWhenRunningCommandList>
|
||||
<Command>$(SYSPROGS_CMAKE_PATH)</Command>
|
||||
<BackgroundMode xsi:nil="true" />
|
||||
</CMakeCommand>
|
||||
<UpdateSourcesInCMakeFile>true</UpdateSourcesInCMakeFile>
|
||||
<ExportCompileCommands>false</ExportCompileCommands>
|
||||
<DisableToolchainFile>false</DisableToolchainFile>
|
||||
<CMakeMakefileType>Ninja</CMakeMakefileType>
|
||||
<DeployAsRoot>false</DeployAsRoot>
|
||||
<CMakeCleanMode>RemoveBuildDirectory</CMakeCleanMode>
|
||||
<UseCCache>false</UseCCache>
|
||||
<ProjectModeSettings>
|
||||
<ProjectItemSettings>
|
||||
<GroupSourcesByTypes>true</GroupSourcesByTypes>
|
||||
<GroupSourcesByPaths>true</GroupSourcesByPaths>
|
||||
<GroupTargetsByPaths>true</GroupTargetsByPaths>
|
||||
<FollowCMakeSourceGroups>false</FollowCMakeSourceGroups>
|
||||
<AutoRefreshProject>true</AutoRefreshProject>
|
||||
<AlwaysConsiderOutdated>false</AlwaysConsiderOutdated>
|
||||
<SortTargetsByName>true</SortTargetsByName>
|
||||
<RedundantTargetMode>HideOuterProjectTargets</RedundantTargetMode>
|
||||
<SortSourcesByName>true</SortSourcesByName>
|
||||
<BuildAllTargetsInSubdir>false</BuildAllTargetsInSubdir>
|
||||
<FoldSingleItemPathLevels>true</FoldSingleItemPathLevels>
|
||||
</ProjectItemSettings>
|
||||
<TargetSpecificSettings />
|
||||
<SetLDLibraryPathFromDependentArtifacts>true</SetLDLibraryPathFromDependentArtifacts>
|
||||
<ProjectGUID>eadcc9ab-72b3-4b51-a838-593e5d80ddf7</ProjectGUID>
|
||||
<VirtualFolders />
|
||||
<ConfigurationNameCase>Upper</ConfigurationNameCase>
|
||||
<DefaultHeaderDiscoveryMode>HeaderDirectoryAndSubdirectories</DefaultHeaderDiscoveryMode>
|
||||
<EnableFastUpToDateCheck>true</EnableFastUpToDateCheck>
|
||||
<ESPIDFExtension>
|
||||
<IDFCheckout>
|
||||
<Version>release/v5.1</Version>
|
||||
<Subdirectory>esp-idf/v5.1</Subdirectory>
|
||||
<Type>ESPIDF</Type>
|
||||
</IDFCheckout>
|
||||
<COMPort>COM9</COMPort>
|
||||
<SuppressTestPrerequisiteChecks>false</SuppressTestPrerequisiteChecks>
|
||||
<UseCCache>false</UseCCache>
|
||||
<DeviceID>ESP32</DeviceID>
|
||||
</ESPIDFExtension>
|
||||
</ProjectModeSettings>
|
||||
</Build>
|
||||
<CustomBuild>
|
||||
<PreSyncActions />
|
||||
<PreBuildActions />
|
||||
<PostBuildActions />
|
||||
<PreCleanActions />
|
||||
<PostCleanActions />
|
||||
</CustomBuild>
|
||||
<CustomDebug>
|
||||
<PreDebugActions />
|
||||
<PostDebugActions />
|
||||
<DebugStopActions />
|
||||
<BreakMode>Default</BreakMode>
|
||||
</CustomDebug>
|
||||
<DeviceTerminalSettings>
|
||||
<Connection xsi:type="com.sysprogs.terminal.connection.serial">
|
||||
<ComPortName>COM9</ComPortName>
|
||||
<AdvancedSettings>
|
||||
<BaudRate>115200</BaudRate>
|
||||
<DataBits>8</DataBits>
|
||||
<Parity>None</Parity>
|
||||
<StopBits>One</StopBits>
|
||||
<FlowControl>None</FlowControl>
|
||||
</AdvancedSettings>
|
||||
</Connection>
|
||||
<LastConnectionTime>0</LastConnectionTime>
|
||||
<EchoTypedCharacters>false</EchoTypedCharacters>
|
||||
<ClearContentsWhenReconnecting>true</ClearContentsWhenReconnecting>
|
||||
<ReconnectAutomatically>false</ReconnectAutomatically>
|
||||
<DisplayMode>ASCII</DisplayMode>
|
||||
<Colors>
|
||||
<Background>
|
||||
<Alpha>255</Alpha>
|
||||
<Red>0</Red>
|
||||
<Green>0</Green>
|
||||
<Blue>0</Blue>
|
||||
</Background>
|
||||
<Disconnected>
|
||||
<Alpha>255</Alpha>
|
||||
<Red>169</Red>
|
||||
<Green>169</Green>
|
||||
<Blue>169</Blue>
|
||||
</Disconnected>
|
||||
<Text>
|
||||
<Alpha>255</Alpha>
|
||||
<Red>211</Red>
|
||||
<Green>211</Green>
|
||||
<Blue>211</Blue>
|
||||
</Text>
|
||||
<Echo>
|
||||
<Alpha>255</Alpha>
|
||||
<Red>144</Red>
|
||||
<Green>238</Green>
|
||||
<Blue>144</Blue>
|
||||
</Echo>
|
||||
<Inactive>
|
||||
<Alpha>255</Alpha>
|
||||
<Red>169</Red>
|
||||
<Green>169</Green>
|
||||
<Blue>169</Blue>
|
||||
</Inactive>
|
||||
</Colors>
|
||||
<HexSettings>
|
||||
<MaximumBytesPerLine>16</MaximumBytesPerLine>
|
||||
<ShowTextView>true</ShowTextView>
|
||||
<BreaksAroundEcho>true</BreaksAroundEcho>
|
||||
<AutoSend>true</AutoSend>
|
||||
<SendAsHex>true</SendAsHex>
|
||||
<TimeoutForAutoBreak>0</TimeoutForAutoBreak>
|
||||
</HexSettings>
|
||||
<LineEnding>LF</LineEnding>
|
||||
<TreatLFAsCRLF>false</TreatLFAsCRLF>
|
||||
<KeepOpenAfterExit>false</KeepOpenAfterExit>
|
||||
<ShowAfterProgramming>false</ShowAfterProgramming>
|
||||
</DeviceTerminalSettings>
|
||||
<CustomShortcuts>
|
||||
<Shortcuts />
|
||||
<ShowMessageAfterExecuting>true</ShowMessageAfterExecuting>
|
||||
</CustomShortcuts>
|
||||
<UserDefinedVariables />
|
||||
<ImportedPropertySheets />
|
||||
<CodeSense>
|
||||
<Enabled>Unknown</Enabled>
|
||||
<ExtraSettings>
|
||||
<HideErrorsInSystemHeaders>true</HideErrorsInSystemHeaders>
|
||||
<SupportLightweightReferenceAnalysis>true</SupportLightweightReferenceAnalysis>
|
||||
<CheckForClangFormatFiles>true</CheckForClangFormatFiles>
|
||||
<FormattingEngine xsi:nil="true" />
|
||||
</ExtraSettings>
|
||||
<CodeAnalyzerSettings>
|
||||
<Enabled>false</Enabled>
|
||||
</CodeAnalyzerSettings>
|
||||
</CodeSense>
|
||||
<Configurations>
|
||||
<VisualGDBConfiguration>
|
||||
<Name>Debug</Name>
|
||||
<BuildSettingsExtension xsi:type="com.visualgdb.build.external.esp-idf.cmake.extension" />
|
||||
</VisualGDBConfiguration>
|
||||
<VisualGDBConfiguration>
|
||||
<Name>Release</Name>
|
||||
<BuildSettingsExtension xsi:type="com.visualgdb.build.external.esp-idf.cmake.extension" />
|
||||
</VisualGDBConfiguration>
|
||||
</Configurations>
|
||||
<ProgramArgumentsSuggestions />
|
||||
<Debug xsi:type="com.visualgdb.debug.embedded">
|
||||
<AdditionalStartupCommands />
|
||||
<AdditionalGDBSettings>
|
||||
<Features>
|
||||
<DisableAutoDetection>false</DisableAutoDetection>
|
||||
<UseFrameParameter>false</UseFrameParameter>
|
||||
<SimpleValuesFlagSupported>false</SimpleValuesFlagSupported>
|
||||
<ListLocalsSupported>false</ListLocalsSupported>
|
||||
<ByteLevelMemoryCommandsAvailable>false</ByteLevelMemoryCommandsAvailable>
|
||||
<ThreadInfoSupported>false</ThreadInfoSupported>
|
||||
<PendingBreakpointsSupported>false</PendingBreakpointsSupported>
|
||||
<SupportTargetCommand>false</SupportTargetCommand>
|
||||
<ReliableBreakpointNotifications>false</ReliableBreakpointNotifications>
|
||||
</Features>
|
||||
<EnableSmartStepping>false</EnableSmartStepping>
|
||||
<FilterSpuriousStoppedNotifications>false</FilterSpuriousStoppedNotifications>
|
||||
<ForceSingleThreadedMode>false</ForceSingleThreadedMode>
|
||||
<UseAppleExtensions>false</UseAppleExtensions>
|
||||
<CanAcceptCommandsWhileRunning>false</CanAcceptCommandsWhileRunning>
|
||||
<MakeLogFile>false</MakeLogFile>
|
||||
<IgnoreModuleEventsWhileStepping>true</IgnoreModuleEventsWhileStepping>
|
||||
<UseRelativePathsOnly>false</UseRelativePathsOnly>
|
||||
<ExitAction>None</ExitAction>
|
||||
<DisableDisassembly>false</DisableDisassembly>
|
||||
<ExamineMemoryWithXCommand>false</ExamineMemoryWithXCommand>
|
||||
<StepIntoNewInstanceEntry>app_main</StepIntoNewInstanceEntry>
|
||||
<ExamineRegistersInRawFormat>true</ExamineRegistersInRawFormat>
|
||||
<DisableSignals>false</DisableSignals>
|
||||
<EnableAsyncExecutionMode>false</EnableAsyncExecutionMode>
|
||||
<AsyncModeSupportsBreakpoints>true</AsyncModeSupportsBreakpoints>
|
||||
<TemporaryBreakConsolidationTimeout>0</TemporaryBreakConsolidationTimeout>
|
||||
<EnableNonStopMode>false</EnableNonStopMode>
|
||||
<MaxBreakpointLimit>0</MaxBreakpointLimit>
|
||||
<EnableVerboseMode>true</EnableVerboseMode>
|
||||
<EnablePrettyPrinters>false</EnablePrettyPrinters>
|
||||
</AdditionalGDBSettings>
|
||||
<DebugMethod>
|
||||
<ID>openocd</ID>
|
||||
<Configuration xsi:type="com.visualgdb.edp.openocd.settings.esp32">
|
||||
<CommandLine>-f interface/ftdi/tigard.cfg -c "adapter_khz 15000" -f target/esp32.cfg</CommandLine>
|
||||
<ExtraParameters>
|
||||
<Frequency xsi:nil="true" />
|
||||
<BoostedFrequency xsi:nil="true" />
|
||||
<ConnectUnderReset>false</ConnectUnderReset>
|
||||
</ExtraParameters>
|
||||
<LoadProgressGUIThreshold>131072</LoadProgressGUIThreshold>
|
||||
<ProgramMode>Enabled</ProgramMode>
|
||||
<StartupCommands>
|
||||
<string>set remotetimeout 60</string>
|
||||
<string>target remote :$$SYS:GDB_PORT$$</string>
|
||||
<string>mon gdb_breakpoint_override hard</string>
|
||||
<string>mon reset halt</string>
|
||||
<string>load</string>
|
||||
</StartupCommands>
|
||||
<ProgramFLASHUsingExternalTool>false</ProgramFLASHUsingExternalTool>
|
||||
<PreferredGDBPort>0</PreferredGDBPort>
|
||||
<PreferredTelnetPort>0</PreferredTelnetPort>
|
||||
<AlwaysPassSerialNumber>false</AlwaysPassSerialNumber>
|
||||
<SelectedCoreIndex xsi:nil="true" />
|
||||
<LiveMemoryTimeout>5000</LiveMemoryTimeout>
|
||||
<SuggestionLogicRevision>1</SuggestionLogicRevision>
|
||||
<CheckFLASHSize>true</CheckFLASHSize>
|
||||
<FLASHSettings>
|
||||
<Size>size2MB</Size>
|
||||
<Frequency>freq40M</Frequency>
|
||||
<Mode>DIO</Mode>
|
||||
</FLASHSettings>
|
||||
<PatchBootloader>true</PatchBootloader>
|
||||
</Configuration>
|
||||
</DebugMethod>
|
||||
<AutoDetectRTOS>true</AutoDetectRTOS>
|
||||
<SemihostingSupport>Disabled</SemihostingSupport>
|
||||
<SemihostingPollingDelay>0</SemihostingPollingDelay>
|
||||
<StepIntoEntryPoint>false</StepIntoEntryPoint>
|
||||
<ReloadFirmwareOnReset>false</ReloadFirmwareOnReset>
|
||||
<ValidateEndOfStackAddress>true</ValidateEndOfStackAddress>
|
||||
<StopAtEntryPoint>false</StopAtEntryPoint>
|
||||
<EnableVirtualHalts>false</EnableVirtualHalts>
|
||||
<DynamicAnalysisSettings />
|
||||
<EndOfStackSymbol>_estack</EndOfStackSymbol>
|
||||
<TimestampProviderTicksPerSecond>0</TimestampProviderTicksPerSecond>
|
||||
<KeepConsoleAfterExit>false</KeepConsoleAfterExit>
|
||||
<UnusedStackFillPattern xsi:nil="true" />
|
||||
<CheckInterfaceDrivers>true</CheckInterfaceDrivers>
|
||||
</Debug>
|
||||
</VisualGDBProjectSettings2>
|
|
@ -0,0 +1,516 @@
|
|||
#
|
||||
# Copyright (C) 2006-2023 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
|
||||
#
|
||||
# cmake for wolfssl Espressif projects
|
||||
#
|
||||
# See https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/build-system.html
|
||||
#
|
||||
|
||||
# allows /include/user_settings.h (ignores it).
|
||||
# user_settings.h file to use must be in [project]/components/wolfssl/include
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_USER_SETTINGS")
|
||||
set(CMAKE_CURRENT_SOURCE_DIR ".")
|
||||
set(COMPONENT_REQUIRES lwip) # we typically don't need lwip directly in wolfssl component
|
||||
set(WOLFCRYPT_PATH "wolfssl/wolfcrypt") # breadcrumb path to detect if we've found wolfssl
|
||||
|
||||
# find the user name to search for possible "wolfssl-username"
|
||||
if( "$ENV{USER}" STREQUAL "" ) # the bash user
|
||||
if( "$ENV{USERNAME}" STREQUAL "" ) # the Windows user
|
||||
message(STATUS "Could not find USER or USERNAME.")
|
||||
else()
|
||||
# the bash user is not blank, so we'll use it.
|
||||
set(THIS_USER "$ENV{USERNAME}")
|
||||
endif()
|
||||
else()
|
||||
# the bash user is not blank, so we'll use it.
|
||||
set(THIS_USER "$ENV{USER}")
|
||||
endif()
|
||||
message(STATUS "THIS_USER = ${THIS_USER}")
|
||||
|
||||
# COMPONENT_NAME = wolfssl
|
||||
# The component name is the directory name. "No feature to change this".
|
||||
# See https://github.com/espressif/esp-idf/issues/8978#issuecomment-1129892685
|
||||
|
||||
# set the root of wolfSSL in top-level project CMakelists.txt:
|
||||
# set(WOLFSSL_ROOT "C:/some path/with/spaces")
|
||||
# set(WOLFSSL_ROOT "c:/workspace/wolfssl-[username]")
|
||||
# set(WOLFSSL_ROOT "/mnt/c/some path/with/spaces")
|
||||
# or use this logic to assign value from Environment Variable WOLFSSL_ROOT,
|
||||
# or assume this is an example 7 subdirectories below:
|
||||
|
||||
# We are typically in [root]/IDE/Espressif/ESP-IDF/examples/wolfssl_test/components/wolfssl
|
||||
# The root of wolfSSL is 7 directories up from here:
|
||||
|
||||
if(CMAKE_BUILD_EARLY_EXPANSION)
|
||||
message(STATUS "wolfssl component CMAKE_BUILD_EARLY_EXPANSION:")
|
||||
idf_component_register(
|
||||
REQUIRES "${COMPONENT_REQUIRES}"
|
||||
PRIV_REQUIRES esp_timer driver # this will typically only be needed for wolfSSL benchmark
|
||||
)
|
||||
|
||||
else()
|
||||
# not CMAKE_BUILD_EARLY_EXPANSION
|
||||
message(STATUS "************************************************************************************************")
|
||||
message(STATUS "wolfssl component config:")
|
||||
message(STATUS "************************************************************************************************")
|
||||
|
||||
# Check to see if we're already in wolfssl, and only if WOLFSSL_ROOT not specified
|
||||
if ("${WOLFSSL_ROOT}" STREQUAL "")
|
||||
# wolfssl examples are 7 directories deep from wolfssl repo root
|
||||
# 1 2 3 4 5 6 7
|
||||
set(THIS_RELATIVE_PATH "../../../../../../..")
|
||||
get_filename_component(THIS_SEARCH_PATH "${THIS_RELATIVE_PATH}" ABSOLUTE)
|
||||
message(STATUS "Searching in path = ${THIS_SEARCH_PATH}")
|
||||
|
||||
if (EXISTS "${THIS_SEARCH_PATH}/${WOLFCRYPT_PATH}")
|
||||
# we're already in wolfssl examples!
|
||||
get_filename_component(WOLFSSL_ROOT "${THIS_SEARCH_PATH}" ABSOLUTE)
|
||||
message(STATUS "Using wolfSSL example with root ${WOLFSSL_ROOT}")
|
||||
else()
|
||||
# We're in some other repo such as wolfssh, so we'll search for an
|
||||
# adjacent-level directory for wolfssl. (8 directories up, then down one)
|
||||
#
|
||||
# For example wolfSSL examples:
|
||||
# C:\workspace\wolfssl-gojimmypi\IDE\Espressif\ESP-IDF\examples\wolfssl_benchmark\components\wolfssl
|
||||
#
|
||||
# For example wolfSSH examples:
|
||||
# C:\workspace\wolfssh-gojimmypi\ide\Espressif\ESP-IDF\examples\wolfssh_benchmark\components\wolfssl
|
||||
#
|
||||
# 1 2 3 4 5 6 7 8
|
||||
set(THIS_RELATIVE_PATH "../../../../../../../..")
|
||||
get_filename_component(THIS_SEARCH_PATH "${THIS_RELATIVE_PATH}" ABSOLUTE)
|
||||
message(STATUS "Searching next in path = ${THIS_SEARCH_PATH}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# search other possible locations
|
||||
if ("${WOLFSSL_ROOT}" STREQUAL "")
|
||||
# there's not a hard-coded WOLFSSL_ROOT value above, so let's see if we can find it.
|
||||
if( "$ENV{WOLFSSL_ROOT}" STREQUAL "" )
|
||||
message(STATUS "Environment Variable WOLFSSL_ROOT not set. Will search common locations.")
|
||||
|
||||
message(STATUS "CMAKE_CURRENT_SOURCE_DIR = ${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
get_filename_component(THIS_DIR "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE)
|
||||
message(STATUS "THIS_DIR = ${THIS_DIR}")
|
||||
|
||||
# This same makefile is used for both the wolfssl component, and other
|
||||
# components that may depend on wolfssl, such as wolfssh. Therefore
|
||||
# we need to determine if this makefile is in the wolfssl repo, or
|
||||
# some other repo.
|
||||
|
||||
if( "{THIS_USER}" STREQUAL "" )
|
||||
# This is highly unusual to not find a user name.
|
||||
# In this case, we'll just search for a "wolfssl" directory:
|
||||
message(STATUS "No username found!")
|
||||
get_filename_component(WOLFSSL_ROOT "${THIS_RELATIVE_PATH}/wolfssl" ABSOLUTE)
|
||||
else()
|
||||
# We found an environment USER name!
|
||||
# The first place to look for wolfssl will be in a user-clone called "wolfssl-[username]"
|
||||
message(STATUS "Using [THIS_USER = ${THIS_USER}] to see if there's a [relative path]/wolfssl-${THIS_USER} directory.")
|
||||
get_filename_component(WOLFSSL_ROOT "${THIS_RELATIVE_PATH}/wolfssl-${THIS_USER}" ABSOLUTE)
|
||||
|
||||
if( EXISTS "${WOLFSSL_ROOT}/${WOLFCRYPT_PATH}" )
|
||||
message(STATUS "Found wolfssl in user-suffix ${WOLFSSL_ROOT}")
|
||||
else()
|
||||
# If there's not a user-clone called "wolfssl-[username]",
|
||||
# perhaps there's simply a git clone called "wolfssl"?
|
||||
message(STATUS "Did not find wolfssl in ${WOLFSSL_ROOT}; continuing search...")
|
||||
get_filename_component(WOLFSSL_ROOT "${THIS_RELATIVE_PATH}/wolfssl" ABSOLUTE)
|
||||
|
||||
if( EXISTS "${WOLFSSL_ROOT}" )
|
||||
message(STATUS "Found wolfssl in standard ${WOLFSSL_ROOT}")
|
||||
else()
|
||||
# Things are looking pretty bleak. We'll likely not be able to compile.
|
||||
message(STATUS "Did not find wolfssl in ${WOLFSSL_ROOT}")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
else()
|
||||
# there's an environment variable, so use it.
|
||||
set(WOLFSSL_ROOT "$ENV{WOLFSSL_ROOT}")
|
||||
|
||||
if( EXISTS "${WOLFSSL_ROOT}/${WOLFCRYPT_PATH}" )
|
||||
get_filename_component(WOLFSSL_ROOT "$ENV{WOLFSSL_ROOT}" ABSOLUTE)
|
||||
message(STATUS "Found WOLFSSL_ROOT via Environment Variable: ${WOLFSSL_ROOT}")
|
||||
else()
|
||||
# message(FATAL_ERROR "WOLFSSL_ROOT Environment Variable defined, but path not found:")
|
||||
message(STATUS "$ENV{WOLFSSL_ROOT} not found or does not contain ${WOLFCRYPT_PATH}")
|
||||
endif()
|
||||
endif()
|
||||
# end of search for wolfssl component root
|
||||
else()
|
||||
# There's already a value assigned; we won't search for anything else.
|
||||
message(STATUS "Found user-specified WOLFSSL_ROOT value.")
|
||||
endif() # WOLFSSL_ROOT user defined
|
||||
|
||||
# After all the logic above, does our WOLFSSL_ROOT actually exist?
|
||||
if( EXISTS "${WOLFSSL_ROOT}/${WOLFCRYPT_PATH}" )
|
||||
message(STATUS "WOLFSSL_ROOT = ${WOLFSSL_ROOT}")
|
||||
else()
|
||||
# Perhaps we are in wolfssl-examples, 4 directories down from parallel wolfssl?
|
||||
# First, we'll see if we can find wolfssl in the wolfssl-[username] repo
|
||||
# 1 2 3 4 |- parallel parent
|
||||
set(NEXT_RELATIVE_PATH "../../../../../wolfssl-${THIS_USER}")
|
||||
get_filename_component(THIS_SEARCH_PATH "${NEXT_RELATIVE_PATH}" ABSOLUTE)
|
||||
message(STATUS "Searching for wolfssl in path: ${THIS_SEARCH_PATH}")
|
||||
if(EXISTS "${THIS_SEARCH_PATH}/${WOLFCRYPT_PATH}" )
|
||||
set(WOLFSSL_ROOT "${THIS_SEARCH_PATH}")
|
||||
message(STATUS "Found wolfssl in user suffix directory: ${WOLFSSL_ROOT}")
|
||||
else()
|
||||
# next, let's see if there's jsut a simple clone of wolfssl in the same parent directory
|
||||
set(NEXT_RELATIVE_PATH "../../../../../wolfssl")
|
||||
get_filename_component(THIS_SEARCH_PATH "${NEXT_RELATIVE_PATH}" ABSOLUTE)
|
||||
message(STATUS "Searching wolfssl-examples for path = ${THIS_SEARCH_PATH}")
|
||||
if( EXISTS "${THIS_SEARCH_PATH}/${WOLFCRYPT_PATH}" )
|
||||
set(WOLFSSL_ROOT "${THIS_SEARCH_PATH}")
|
||||
message(STATUS "Found wolfssl in same parent directory: ${WOLFSSL_ROOT}")
|
||||
else()
|
||||
message(STATUS "unable to find wolfssl.")
|
||||
message(STATUS "---- Try setting the WOLFSSL_ROOT environment variable")
|
||||
message(STATUS "---- Or set WOLFSSL_ROOT in the CMakeFile.txt")
|
||||
set(WOLFSSL_ROOT "../wolfssl")
|
||||
# Abort. We need wolfssl _somewhere_.
|
||||
message(FATAL_ERROR "Could not find wolfssl in ${WOLFSSL_ROOT}. Try setting environment variable or git clone.")
|
||||
endif() # checking [workspace]/wolfssl
|
||||
endif() # chcking [workspace]/wolfssl-[username]
|
||||
endif() # alternate check if in wolfssl-examples
|
||||
|
||||
|
||||
set(INCLUDE_PATH ${WOLFSSL_ROOT})
|
||||
|
||||
set(COMPONENT_SRCDIRS "\"${WOLFSSL_ROOT}/src/\""
|
||||
"\"${WOLFSSL_ROOT}/wolfcrypt/src\""
|
||||
"\"${WOLFSSL_ROOT}/wolfcrypt/src/port/Espressif\""
|
||||
"\"${WOLFSSL_ROOT}/wolfcrypt/src/port/atmel\""
|
||||
# "\"${WOLFSSL_ROOT}/wolfcrypt/benchmark\"" # the benchmark application
|
||||
# "\"${WOLFSSL_ROOT}/wolfcrypt/test\"" # the test application
|
||||
) # COMPONENT_SRCDIRS
|
||||
message(STATUS "This COMPONENT_SRCDIRS = ${COMPONENT_SRCDIRS}")
|
||||
|
||||
set(WOLFSSL_PROJECT_DIR "${CMAKE_HOME_DIRECTORY}/components/wolfssl")
|
||||
|
||||
# Espressif may take several passes through this makefile. Check to see if we found IDF
|
||||
string(COMPARE EQUAL "${PROJECT_SOURCE_DIR}" "" WOLFSSL_FOUND_IDF)
|
||||
|
||||
# get a list of all wolfcrypt assembly files; we'll exclude them as they don't target Xtensa
|
||||
file(GLOB EXCLUDE_ASM *.S)
|
||||
file(GLOB_RECURSE EXCLUDE_ASM ${CMAKE_SOURCE_DIR} "${WOLFSSL_ROOT}/wolfcrypt/src/*.S")
|
||||
|
||||
message(STATUS "IDF_PATH = $ENV{IDF_PATH}")
|
||||
message(STATUS "PROJECT_SOURCE_DIR = ${PROJECT_SOURCE_DIR}")
|
||||
message(STATUS "EXCLUDE_ASM = ${EXCLUDE_ASM}")
|
||||
|
||||
#
|
||||
# Check to see if there's both a local copy and EDP-IDF copy of the wolfssl and/or wolfssh components.
|
||||
#
|
||||
if( EXISTS "${WOLFSSL_PROJECT_DIR}" AND EXISTS "$ENV{IDF_PATH}/components/wolfssl/" )
|
||||
#
|
||||
# wolfSSL found in both ESP-IDF and local project - needs to be resolved by user
|
||||
#
|
||||
message(STATUS "")
|
||||
message(STATUS "**************************************************************************************")
|
||||
message(STATUS "")
|
||||
message(STATUS "Error: Found components/wolfssl in both local project and IDF_PATH")
|
||||
message(STATUS "")
|
||||
message(STATUS "To proceed: ")
|
||||
message(STATUS "")
|
||||
message(STATUS "Remove either the local project component: ${WOLFSSL_PROJECT_DIR} ")
|
||||
message(STATUS "or the Espressif shared component installed at: $ENV{IDF_PATH}/components/wolfssl/ ")
|
||||
message(STATUS "")
|
||||
message(FATAL_ERROR "Please use wolfSSL in either local project or Espressif components, but not both.")
|
||||
message(STATUS "")
|
||||
message(STATUS "**************************************************************************************")
|
||||
message(STATUS "")
|
||||
|
||||
# Optional: if you change the above FATAL_ERROR to STATUS you can warn at runtime with this macro definition:
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_MULTI_INSTALL_WARNING")
|
||||
|
||||
else()
|
||||
if( EXISTS "$ENV{IDF_PATH}/components/wolfssl/" )
|
||||
#
|
||||
# wolfSSL found in ESP-IDF components and is assumed to be already configured in user_settings.h via setup.
|
||||
#
|
||||
message(STATUS "")
|
||||
message(STATUS "Using components/wolfssl in IDF_PATH = $ENV{IDF_PATH}")
|
||||
message(STATUS "")
|
||||
else()
|
||||
#
|
||||
# wolfSSL is not an ESP-IDF component.
|
||||
# We need to now determine if it is local and if so if it is part of the wolfSSL repo,
|
||||
# or if wolfSSL is simply installed as a local component.
|
||||
#
|
||||
|
||||
if( EXISTS "${WOLFSSL_PROJECT_DIR}" )
|
||||
#
|
||||
# wolfSSL found in local project.
|
||||
#
|
||||
if( EXISTS "${WOLFSSL_PROJECT_DIR}/wolfcrypt/" )
|
||||
message(STATUS "")
|
||||
message(STATUS "Using installed project ./components/wolfssl in CMAKE_HOME_DIRECTORY = ${CMAKE_HOME_DIRECTORY}")
|
||||
message(STATUS "")
|
||||
#
|
||||
# Note we already checked above and confirmed there's not another wolfSSL installed in the ESP-IDF components.
|
||||
#
|
||||
# We won't do anything else here, as it will be assumed the original install completed successfully.
|
||||
#
|
||||
else() # full wolfSSL not installed in local project
|
||||
#
|
||||
# This is the developer repo mode. wolfSSL will be assumed to be not installed to ESP-IDF nor local project
|
||||
# In this configuration, we are likely running a wolfSSL example found directly in the repo.
|
||||
#
|
||||
message(STATUS "")
|
||||
message(STATUS "Using developer repo ./components/wolfssl in CMAKE_HOME_DIRECTORY = ${CMAKE_HOME_DIRECTORY}")
|
||||
message(STATUS "")
|
||||
|
||||
message(STATUS "************************************************************************************************")
|
||||
# When in developer mode, we are typically running wolfSSL examples such as benchmark or test directories.
|
||||
# However, the as-cloned or distributed wolfSSL does not have the ./include/ directory, so we'll add it as needed.
|
||||
#
|
||||
# first check if there's a [root]/include/user_settings.h
|
||||
if( EXISTS "${WOLFSSL_ROOT}/include/user_settings.h" )
|
||||
message(STATUS "Found wolfSSL EXCLUDED user_settings.h in "
|
||||
"${WOLFSSL_ROOT}/include/user_settings.h "
|
||||
" (using ${WOLFSSL_PROJECT_DIR}/include/user_settings.h )")
|
||||
else()
|
||||
# we won't overwrite an existing user settings file, just note that we already have one:
|
||||
if( EXISTS "${WOLFSSL_PROJECT_DIR}/include/user_settings.h" )
|
||||
message(STATUS "Using existing wolfSSL user_settings.h in "
|
||||
"${WOLFSSL_PROJECT_DIR}/include/user_settings.h")
|
||||
else()
|
||||
message(STATUS "Installing wolfSSL user_settings.h to "
|
||||
"${WOLFSSL_PROJECT_DIR}/include/user_settings.h")
|
||||
file(COPY "${WOLFSSL_ROOT}/IDE/Espressif/ESP-IDF/user_settings.h"
|
||||
DESTINATION "${CMAKE_HOME_DIRECTORY}/wolfssl/include/")
|
||||
endif()
|
||||
endif() # user_settings.h
|
||||
|
||||
# next check if there's a [root]/include/config.h
|
||||
if( EXISTS "${WOLFSSL_ROOT}/include/config.h" )
|
||||
# message(FATAL_ERROR "Found stray wolfSSL config.h in ${WOLFSSL_ROOT}/include/config.h (please move it to ${WOLFSSL_PROJECT_DIR}/include/config.h")
|
||||
else()
|
||||
# we won't overwrite an existing user settings file, just note that we already have one:
|
||||
if( EXISTS "${WOLFSSL_PROJECT_DIR}/include/config.h" )
|
||||
message(STATUS "Using existing wolfSSL config.h ${WOLFSSL_PROJECT_DIR}/include/config.h")
|
||||
else()
|
||||
message(STATUS "Installing wolfSSL config.h to ${WOLFSSL_PROJECT_DIR}/include/config.h")
|
||||
file(COPY "${WOLFSSL_ROOT}/IDE/Espressif/ESP-IDF/dummy_config_h" DESTINATION "${WOLFSSL_PROJECT_DIR}/include/")
|
||||
file(RENAME "${WOLFSSL_PROJECT_DIR}/include/dummy_config_h" "${WOLFSSL_PROJECT_DIR}/include/config.h")
|
||||
endif() # Project config.h
|
||||
endif() # WOLFSSL_ROOT config.h
|
||||
message(STATUS "************************************************************************************************")
|
||||
message(STATUS "")
|
||||
endif()
|
||||
|
||||
else()
|
||||
# we did not find a ./components/wolfssl/include/ directory from this pass of cmake.
|
||||
if($WOLFSSL_FOUND_IDF)
|
||||
message(STATUS "")
|
||||
message(STATUS "WARNING: wolfSSL not found.")
|
||||
message(STATUS "")
|
||||
else()
|
||||
# probably needs to be re-parsed by Espressif
|
||||
message(STATUS "wolfSSL found IDF. Project Source:${PROJECT_SOURCE_DIR}")
|
||||
endif() # else we have not found ESP-IDF yet
|
||||
endif() # else not a local wolfSSL component
|
||||
|
||||
endif() #else not an ESP-IDF component
|
||||
endif() # else not local copy and EDP-IDF wolfSSL
|
||||
|
||||
|
||||
# RTOS_IDF_PATH is typically:
|
||||
# "/Users/{username}/Desktop/esp-idf/components/freertos/include/freertos"
|
||||
# depending on the environment, we may need to swap backslashes with forward slashes
|
||||
string(REPLACE "\\" "/" RTOS_IDF_PATH "$ENV{IDF_PATH}/components/freertos/FreeRTOS-Kernel/include/freertos")
|
||||
|
||||
string(REPLACE "\\" "/" WOLFSSL_ROOT ${WOLFSSL_ROOT})
|
||||
|
||||
if(IS_DIRECTORY "${RTOS_IDF_PATH}")
|
||||
message(STATUS "Found current RTOS path: ${RTOS_IDF_PATH}")
|
||||
else()
|
||||
# ESP-IDF prior version 4.4x has a different RTOS directory structure
|
||||
string(REPLACE "\\" "/" RTOS_IDF_PATH "$ENV{IDF_PATH}/components/freertos/include/freertos")
|
||||
if(IS_DIRECTORY "${RTOS_IDF_PATH}")
|
||||
message(STATUS "Found legacy RTOS path: ${RTOS_IDF_PATH}")
|
||||
else()
|
||||
message(STATUS "Could not find RTOS path")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
set(COMPONENT_ADD_INCLUDEDIRS
|
||||
"./include" # this is the location of wolfssl user_settings.h
|
||||
"\"${WOLFSSL_ROOT}/\""
|
||||
"\"${WOLFSSL_ROOT}/wolfssl/\""
|
||||
"\"${WOLFSSL_ROOT}/wolfssl/wolfcrypt/\""
|
||||
"\"${RTOS_IDF_PATH}/\""
|
||||
)
|
||||
|
||||
|
||||
if(IS_DIRECTORY ${IDF_PATH}/components/cryptoauthlib)
|
||||
list(APPEND COMPONENT_ADD_INCLUDEDIRS "../cryptoauthlib/lib")
|
||||
endif()
|
||||
|
||||
list(APPEND COMPONENT_ADD_INCLUDEDIRS "\"${WOLFSSL_ROOT}/wolfssl/\"")
|
||||
list(APPEND COMPONENT_ADD_INCLUDEDIRS "\"${WOLFSSL_ROOT}/wolfssl/wolfcrypt/\"")
|
||||
|
||||
|
||||
|
||||
set(COMPONENT_SRCEXCLUDE
|
||||
"\"${WOLFSSL_ROOT}/include/user_settings.h\"" # use local file only
|
||||
"\"${WOLFSSL_ROOT}/src/bio.c\""
|
||||
"\"${WOLFSSL_ROOT}/src/conf.c\""
|
||||
"\"${WOLFSSL_ROOT}/src/misc.c\""
|
||||
"\"${WOLFSSL_ROOT}/src/pk.c\""
|
||||
"\"${WOLFSSL_ROOT}/src/ssl_asn1.c\"" # included by ssl.c
|
||||
"\"${WOLFSSL_ROOT}/src/ssl_certman.c\"" # included by ssl.c
|
||||
"\"${WOLFSSL_ROOT}/src/ssl_bn.c\"" # included by ssl.c
|
||||
"\"${WOLFSSL_ROOT}/src/ssl_misc.c\"" # included by ssl.c
|
||||
"\"${WOLFSSL_ROOT}/src/x509.c\""
|
||||
"\"${WOLFSSL_ROOT}/src/x509_str.c\""
|
||||
"\"${WOLFSSL_ROOT}/wolfcrypt/src/evp.c\""
|
||||
"\"${WOLFSSL_ROOT}/wolfcrypt/src/misc.c\""
|
||||
"\"${EXCLUDE_ASM}\""
|
||||
)
|
||||
|
||||
spaces2list(COMPONENT_REQUIRES)
|
||||
|
||||
separate_arguments(COMPONENT_SRCDIRS NATIVE_COMMAND "${COMPONENT_SRCDIRS}")
|
||||
separate_arguments(COMPONENT_SRCEXCLUDE NATIVE_COMMAND "${COMPONENT_SRCEXCLUDE}")
|
||||
separate_arguments(COMPONENT_ADD_INCLUDEDIRS NATIVE_COMMAND "${COMPONENT_ADD_INCLUDEDIRS}")
|
||||
|
||||
#
|
||||
# See https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/build-system.html#example-component-requirements
|
||||
#
|
||||
message(STATUS "COMPONENT_SRCDIRS = ${COMPONENT_SRCDIRS}")
|
||||
message(STATUS "COMPONENT_ADD_INCLUDEDIRS = ${COMPONENT_ADD_INCLUDEDIRS}")
|
||||
message(STATUS "COMPONENT_REQUIRES = ${COMPONENT_REQUIRES}")
|
||||
message(STATUS "COMPONENT_SRCEXCLUDE = ${COMPONENT_SRCEXCLUDE}")
|
||||
|
||||
#
|
||||
# see https://docs.espressif.com/projects/esp-idf/en/stable/esp32/migration-guides/release-5.x/build-system.html?highlight=space%20path
|
||||
#
|
||||
set(EXTRA_COMPONENT_DIRS "${COMPONENT_SRCDIRS}")
|
||||
idf_component_register(
|
||||
SRC_DIRS "${COMPONENT_SRCDIRS}"
|
||||
INCLUDE_DIRS "${COMPONENT_ADD_INCLUDEDIRS}"
|
||||
REQUIRES "${COMPONENT_REQUIRES}"
|
||||
EXCLUDE_SRCS "${COMPONENT_SRCEXCLUDE}"
|
||||
PRIV_REQUIRES esp_timer driver # this will typically only be needed for wolfSSL benchmark
|
||||
)
|
||||
# some optional diagnostics
|
||||
if (1)
|
||||
get_cmake_property(_variableNames VARIABLES)
|
||||
list (SORT _variableNames)
|
||||
message(STATUS "")
|
||||
message(STATUS "ALL VARIABLES BEGIN")
|
||||
message(STATUS "")
|
||||
foreach (_variableName ${_variableNames})
|
||||
message(STATUS "${_variableName}=${${_variableName}}")
|
||||
endforeach()
|
||||
message(STATUS "")
|
||||
message(STATUS "ALL VARIABLES END")
|
||||
message(STATUS "")
|
||||
endif()
|
||||
|
||||
# target_sources(wolfssl PRIVATE "\"${WOLFSSL_ROOT}/wolfssl/\"" "\"${WOLFSSL_ROOT}/wolfssl/wolfcrypt\"")
|
||||
endif() # CMAKE_BUILD_EARLY_EXPANSION
|
||||
|
||||
|
||||
|
||||
# check to see if there's both a local copy and EDP-IDF copy of the wolfssl components
|
||||
if( EXISTS "${WOLFSSL_PROJECT_DIR}" AND EXISTS "$ENV{IDF_PATH}/components/wolfssl/" )
|
||||
message(STATUS "")
|
||||
message(STATUS "")
|
||||
message(STATUS "********************************************************************")
|
||||
message(STATUS "WARNING: Found components/wolfssl in both local project and IDF_PATH")
|
||||
message(STATUS "********************************************************************")
|
||||
message(STATUS "")
|
||||
endif()
|
||||
# end multiple component check
|
||||
|
||||
|
||||
#
|
||||
# LIBWOLFSSL_SAVE_INFO(VAR_OUPUT THIS_VAR VAR_RESULT)
|
||||
#
|
||||
# Save the THIS_VAR as a string in a macro called VAR_OUPUT
|
||||
#
|
||||
# VAR_OUPUT: the name of the macro to define
|
||||
# THIS_VAR: the OUTPUT_VARIABLE result from a execute_process()
|
||||
# VAR_RESULT: the RESULT_VARIABLE from a execute_process(); "0" if successful.
|
||||
#
|
||||
function ( LIBWOLFSSL_SAVE_INFO VAR_OUPUT THIS_VAR VAR_RESULT )
|
||||
# is the RESULT_VARIABLE output value 0? If so, IS_VALID_VALUE is true.
|
||||
string(COMPARE EQUAL "${VAR_RESULT}" "0" IS_VALID_VALUE)
|
||||
|
||||
# if we had a successful operation, save the THIS_VAR in VAR_OUPUT
|
||||
if(${IS_VALID_VALUE})
|
||||
# strip newline chars in THIS_VAR parameter and save in VAR_VALUE
|
||||
string(REPLACE "\n" "" VAR_VALUE ${THIS_VAR})
|
||||
|
||||
# we'll could percolate the value to the parent for possible later use
|
||||
# set(${VAR_OUPUT} ${VAR_VALUE} PARENT_SCOPE)
|
||||
|
||||
# but we're only using it here in this function
|
||||
set(${VAR_OUPUT} ${VAR_VALUE})
|
||||
|
||||
# we'll print what we found to the console
|
||||
message(STATUS "Found ${VAR_OUPUT}=${VAR_VALUE}")
|
||||
|
||||
# the interesting part is defining the VAR_OUPUT name a value to use in the app
|
||||
add_definitions(-D${VAR_OUPUT}=\"${VAR_VALUE}\")
|
||||
else()
|
||||
# if we get here, check the execute_process command and parameters.
|
||||
message(STATUS "LIBWOLFSSL_SAVE_INFO encountered a non-zero VAR_RESULT")
|
||||
set(${VAR_OUPUT} "Unknown")
|
||||
endif()
|
||||
endfunction() # LIBWOLFSSL_SAVE_INFO
|
||||
|
||||
# create some programmatic #define values that will be used by ShowExtendedSystemInfo().
|
||||
# see wolfcrypt\src\port\Espressif\esp32_utl.c
|
||||
if(NOT CMAKE_BUILD_EARLY_EXPANSION)
|
||||
set (git_cmd "git")
|
||||
message(STATUS "Adding macro definitions:")
|
||||
|
||||
# LIBWOLFSSL_VERSION_GIT_ORIGIN: git config --get remote.origin.url
|
||||
execute_process(WORKING_DIRECTORY ${WOLFSSL_ROOT} COMMAND ${git_cmd} "config" "--get" "remote.origin.url" OUTPUT_VARIABLE TMP_OUT RESULT_VARIABLE TMP_RES ERROR_QUIET )
|
||||
LIBWOLFSSL_SAVE_INFO(LIBWOLFSSL_VERSION_GIT_ORIGIN "${TMP_OUT}" "${TMP_RES}")
|
||||
|
||||
# LIBWOLFSSL_VERSION_GIT_BRANCH: git rev-parse --abbrev-ref HEAD
|
||||
execute_process(WORKING_DIRECTORY ${WOLFSSL_ROOT} COMMAND ${git_cmd} "rev-parse" "--abbrev-ref" "HEAD" OUTPUT_VARIABLE TMP_OUT RESULT_VARIABLE TMP_RES ERROR_QUIET )
|
||||
LIBWOLFSSL_SAVE_INFO(LIBWOLFSSL_VERSION_GIT_BRANCH "${TMP_OUT}" "${TMP_RES}")
|
||||
|
||||
# LIBWOLFSSL_VERSION_GIT_HASH: git rev-parse HEAD
|
||||
execute_process(WORKING_DIRECTORY ${WOLFSSL_ROOT} COMMAND ${git_cmd} "rev-parse" "HEAD" OUTPUT_VARIABLE TMP_OUT RESULT_VARIABLE TMP_RES ERROR_QUIET )
|
||||
LIBWOLFSSL_SAVE_INFO(LIBWOLFSSL_VERSION_GIT_HASH "${TMP_OUT}" "${TMP_RES}")
|
||||
|
||||
# LIBWOLFSSL_VERSION_GIT_SHORT_HASH: git rev-parse --short HEAD
|
||||
execute_process(WORKING_DIRECTORY ${WOLFSSL_ROOT} COMMAND ${git_cmd} "rev-parse" "--short" "HEAD" OUTPUT_VARIABLE TMP_OUT RESULT_VARIABLE TMP_RES ERROR_QUIET )
|
||||
LIBWOLFSSL_SAVE_INFO(LIBWOLFSSL_VERSION_GIT_SHORT_HASH "${TMP_OUT}" "${TMP_RES}")
|
||||
|
||||
# LIBWOLFSSL_VERSION_GIT_HASH_DATE git show --no-patch --no-notes --pretty=\'\%cd\'
|
||||
execute_process(WORKING_DIRECTORY ${WOLFSSL_ROOT} COMMAND ${git_cmd} "show" "--no-patch" "--no-notes" "--pretty=\'\%cd\'" OUTPUT_VARIABLE TMP_OUT RESULT_VARIABLE TMP_RES )
|
||||
LIBWOLFSSL_SAVE_INFO(LIBWOLFSSL_VERSION_GIT_HASH_DATE "${TMP_OUT}" "${TMP_RES}")
|
||||
|
||||
message(STATUS "************************************************************************************************")
|
||||
message(STATUS "wolfssl component config complete!")
|
||||
message(STATUS "************************************************************************************************")
|
||||
endif()
|
|
@ -0,0 +1,33 @@
|
|||
#
|
||||
# Copyright (C) 2006-2022 wolfSSL Inc. All rights reserved.
|
||||
#
|
||||
# This file is part of wolfSSL.
|
||||
#
|
||||
# Contact licensing@wolfssl.com with any questions or comments.
|
||||
#
|
||||
# https://www.wolfssl.com
|
||||
#/
|
||||
#
|
||||
# Kconfig for wolfssl
|
||||
#
|
||||
menu "wolfSSL"
|
||||
|
||||
config TLS_STACK_WOLFSSL
|
||||
bool "Include wolfSSL in ESP-TLS"
|
||||
default y
|
||||
select FREERTOS_ENABLE_BACKWARD_COMPATIBILITY
|
||||
help
|
||||
Includes wolfSSL in ESP-TLS so that it can be compiled with wolfSSL as its SSL/TLS library.
|
||||
|
||||
config WOLFSSL_HAVE_ALPN
|
||||
bool "Enable ALPN (Application Layer Protocol Negotiation) in wolfSSL"
|
||||
default n
|
||||
|
||||
config WOLFSSL_ALLOW_TLS12
|
||||
bool "Allow TLS 1.2"
|
||||
default n
|
||||
help
|
||||
Allow TLS to fallback to TLS1.2. Memory footprint will likely be larger for TLS1.2.
|
||||
When disabled HTTPS and MQTT over TLS connections will fail if TLS1.3 not accepted.
|
||||
|
||||
endmenu # wolfSSL
|
|
@ -0,0 +1,33 @@
|
|||
#
|
||||
# Copyright (C) 2006-2022 wolfSSL Inc. All rights reserved.
|
||||
#
|
||||
# This file is part of wolfSSL.
|
||||
#
|
||||
# Contact licensing@wolfssl.com with any questions or comments.
|
||||
#
|
||||
# https://www.wolfssl.com
|
||||
#/
|
||||
#
|
||||
# Kconfig for wolfssl
|
||||
#
|
||||
menu "wolfSSL"
|
||||
|
||||
config TLS_STACK_WOLFSSL
|
||||
bool "Include wolfSSL in ESP-TLS"
|
||||
default y
|
||||
select FREERTOS_ENABLE_BACKWARD_COMPATIBILITY
|
||||
help
|
||||
Includes wolfSSL in ESP-TLS so that it can be compiled with wolfSSL as its SSL/TLS library.
|
||||
|
||||
config WOLFSSL_HAVE_ALPN
|
||||
bool "Enable ALPN (Application Layer Protocol Negotiation) in wolfSSL"
|
||||
default n
|
||||
|
||||
config WOLFSSL_ALLOW_TLS12
|
||||
bool "Allow TLS 1.2"
|
||||
default n
|
||||
help
|
||||
Allow TLS to fallback to TLS1.2. Memory footprint will likely be larger for TLS1.2.
|
||||
When disabled HTTPS and MQTT over TLS connections will fail if TLS1.3 not accepted.
|
||||
|
||||
endmenu # wolfSSL
|
|
@ -0,0 +1,38 @@
|
|||
#
|
||||
# Copyright (C) 2006-2023 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
|
||||
#
|
||||
|
||||
#
|
||||
# See https://docs.espressif.com/projects/esp-idf/en/v4.2-beta1/esp32/api-guides/build-system.html#kconfig-projbuild
|
||||
#
|
||||
# " This is an equivalent to project_include.cmake for Component Configuration
|
||||
# KConfig files. If you want to include configuration options at the top-level
|
||||
# of menuconfig, rather than inside the “Component Configuration” sub-menu,
|
||||
# then these can be defined in the KConfig.projbuild file alongside the
|
||||
# CMakeLists.txt file. "
|
||||
|
||||
menu "Example wolfSSL Configuration"
|
||||
|
||||
config EXAMPLE_CONNECT_WIFI
|
||||
bool "connect wolfssl using WiFi interface"
|
||||
depends on !IDF_TARGET_LINUX
|
||||
default y
|
||||
help
|
||||
Protocol examples can use Wi-Fi and/or Ethernet to connect to the network.
|
||||
Choose this option to connect with WiFi
|
|
@ -0,0 +1,24 @@
|
|||
/* config.h - dummy
|
||||
*
|
||||
* Copyright (C) 2006-2023 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
|
||||
*/
|
||||
|
||||
#ifndef _CONFIG_H_
|
||||
#define _CONFIG_H_
|
||||
#endif
|
|
@ -0,0 +1,24 @@
|
|||
/* config.h - dummy
|
||||
*
|
||||
* Copyright (C) 2006-2023 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
|
||||
*/
|
||||
|
||||
#ifndef _CONFIG_H_
|
||||
#define _CONFIG_H_
|
||||
#endif
|
|
@ -0,0 +1,306 @@
|
|||
/* user_settings.h
|
||||
*
|
||||
* Copyright (C) 2006-2023 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
|
||||
*/
|
||||
|
||||
#include <sdkconfig.h> /* essential to chip set detection */
|
||||
|
||||
#undef WOLFSSL_ESPIDF
|
||||
#undef WOLFSSL_ESP32
|
||||
#undef WOLFSSL_ESPWROOM32SE
|
||||
#undef WOLFSSL_ESP32
|
||||
#undef WOLFSSL_ESP8266
|
||||
|
||||
/* The Espressif sdkconfig will have chipset info.
|
||||
**
|
||||
** Possible values:
|
||||
**
|
||||
** CONFIG_IDF_TARGET_ESP32
|
||||
** CONFIG_IDF_TARGET_ESP32S2
|
||||
** CONFIG_IDF_TARGET_ESP32S3
|
||||
** CONFIG_IDF_TARGET_ESP32C3
|
||||
** CONFIG_IDF_TARGET_ESP32C6
|
||||
*/
|
||||
|
||||
#define WOLFSSL_ESPIDF
|
||||
|
||||
/*
|
||||
* choose ONE of these Espressif chips to define:
|
||||
*
|
||||
* WOLFSSL_ESP32
|
||||
* WOLFSSL_ESPWROOM32SE
|
||||
* WOLFSSL_ESP8266
|
||||
*/
|
||||
|
||||
#define WOLFSSL_ESP32
|
||||
|
||||
/* optionally turn off SHA512/224 SHA512/256 */
|
||||
/* #define WOLFSSL_NOSHA512_224 */
|
||||
/* #define WOLFSSL_NOSHA512_256 */
|
||||
|
||||
#define BENCH_EMBEDDED
|
||||
#define USE_CERT_BUFFERS_2048
|
||||
|
||||
/* TLS 1.3 */
|
||||
#define WOLFSSL_TLS13
|
||||
#define HAVE_TLS_EXTENSIONS
|
||||
#define WC_RSA_PSS
|
||||
#define HAVE_HKDF
|
||||
#define HAVE_AEAD
|
||||
#define HAVE_SUPPORTED_CURVES
|
||||
|
||||
#define WOLFSSL_BENCHMARK_FIXED_UNITS_KB
|
||||
|
||||
/* when you want to use SINGLE THREAD */
|
||||
/* #define SINGLE_THREADED */
|
||||
|
||||
#define NO_FILESYSTEM
|
||||
|
||||
#define HAVE_AESGCM
|
||||
|
||||
/* #define WOLFSSL_RIPEMD */
|
||||
/* when you want to use SHA224 */
|
||||
/* #define WOLFSSL_SHA224 */
|
||||
#define NO_OLD_TLS
|
||||
/* when you want to use SHA384 */
|
||||
/* #define WOLFSSL_SHA3 */
|
||||
|
||||
/* #define WOLFSSL_SHA384*/
|
||||
/* #define NO_SHA256*/
|
||||
/* #define WOLFSSL_SHA384*/
|
||||
#define WOLFSSL_SHA512
|
||||
#define HAVE_ECC
|
||||
|
||||
/* #define HAVE_CURVE25519 */
|
||||
/* #define CURVE25519_SMALL */
|
||||
/* #define HAVE_ED25519 */
|
||||
|
||||
/* when you want to use pkcs7 */
|
||||
/* #define HAVE_PKCS7 */
|
||||
|
||||
#if defined(HAVE_PKCS7)
|
||||
#define HAVE_AES_KEYWRAP
|
||||
#define HAVE_X963_KDF
|
||||
#define WOLFSSL_AES_DIRECT
|
||||
#endif
|
||||
|
||||
/* when you want to use aes counter mode */
|
||||
/* #define WOLFSSL_AES_DIRECT */
|
||||
/* #define WOLFSSL_AES_COUNTER */
|
||||
|
||||
/* esp32-wroom-32se specific definition */
|
||||
#if defined(WOLFSSL_ESPWROOM32SE)
|
||||
#define WOLFSSL_ATECC508A
|
||||
#define HAVE_PK_CALLBACKS
|
||||
/* when you want to use a custom slot allocation for ATECC608A */
|
||||
/* unless your configuration is unusual, you can use default */
|
||||
/* implementation. */
|
||||
/* #define CUSTOM_SLOT_ALLOCATION */
|
||||
#endif
|
||||
|
||||
/* rsa primitive specific definition */
|
||||
#if defined(WOLFSSL_ESP32) || defined(WOLFSSL_ESPWROOM32SE)
|
||||
/* Define USE_FAST_MATH and SMALL_STACK */
|
||||
#define ESP32_USE_RSA_PRIMITIVE
|
||||
/* threshold for performance adjustment for HW primitive use */
|
||||
/* X bits of G^X mod P greater than */
|
||||
#define EPS_RSA_EXPT_XBTIS 32 /* NOTE HW unreliable for small values! */
|
||||
/* X and Y of X * Y mod P greater than */
|
||||
#define ESP_RSA_MULM_BITS 9
|
||||
#endif
|
||||
|
||||
/* #define RSA_LOW_MEM */
|
||||
|
||||
/* debug options */
|
||||
/* #define DEBUG_WOLFSSL */
|
||||
/* #define WOLFSSL_ESP32_CRYPT_DEBUG */
|
||||
/* #define WOLFSSL_ATECC508A_DEBUG */
|
||||
|
||||
/* date/time */
|
||||
/* if it cannot adjust time in the device, */
|
||||
/* enable macro below */
|
||||
/* #define NO_ASN_TIME */
|
||||
/* #define XTIME time */
|
||||
|
||||
/* adjust wait-timeout count if you see timeout in RSA HW acceleration */
|
||||
#define ESP_RSA_TIMEOUT_CNT 0x249F00
|
||||
|
||||
#define HASH_SIZE_LIMIT /* for test.c */
|
||||
|
||||
/* only FAST_MATH has HW acceleration at this time */
|
||||
#define USE_FAST_MATH
|
||||
/* #define WOLFSSL_SP_MATH_ALL */
|
||||
/* #define WOLFSSL_SP_RISCV32 */ /* only valid on RISC-V chips */
|
||||
|
||||
/* optionally use SP_MATH */
|
||||
/* #define SP_MATH */
|
||||
|
||||
#define WOLFSSL_SMALL_STACK
|
||||
|
||||
#define HAVE_VERSION_EXTENDED_INFO
|
||||
#define HAVE_WC_INTROSPECTION
|
||||
|
||||
/* allows for all version info, even that suppressed with intospection */
|
||||
#define ALLOW_BINARY_MISMATCH_INTROSPECTION
|
||||
|
||||
/* Default is HW enabled unless turned off.
|
||||
** Uncomment these lines for SW: */
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32)
|
||||
/* #define NO_ESP32_CRYPT */
|
||||
/* #define NO_WOLFSSL_ESP32_CRYPT_HASH */
|
||||
/* #define NO_WOLFSSL_ESP32_CRYPT_AES */
|
||||
/* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI */
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32S2)
|
||||
#define NO_ESP32_CRYPT
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_HASH
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_AES
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32S3)
|
||||
/* #define NO_ESP32_CRYPT */
|
||||
/* #define NO_WOLFSSL_ESP32_CRYPT_HASH */
|
||||
/* #define NO_WOLFSSL_ESP32_CRYPT_AES */
|
||||
/* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI */
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32C2)
|
||||
#define NO_ESP32_CRYPT
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_HASH
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_AES
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32C3)
|
||||
#define NO_ESP32_CRYPT
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_HASH
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_AES
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32C6)
|
||||
#define NO_ESP32_CRYPT
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_HASH
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_AES
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32H2)
|
||||
#define NO_ESP32_CRYPT
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_HASH
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_AES
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI
|
||||
#else
|
||||
#define NO_ESP32_CRYPT
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_HASH
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_AES
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI
|
||||
#endif
|
||||
|
||||
/* optional SM4 Ciphers. See https://github.com/wolfSSL/wolfsm
|
||||
#define WOLFSSL_SM2
|
||||
#define WOLFSSL_SM3
|
||||
#define WOLFSSL_SM4
|
||||
*/
|
||||
|
||||
/* debug options */
|
||||
/* #define ESP_VERIFY_MEMBLOCK */
|
||||
#define WOLFSSL_HW_METRICS
|
||||
/* #define DEBUG_WOLFSSL_VERBOSE */
|
||||
/* #define DEBUG_WOLFSSL */
|
||||
/* #define WOLFSSL_ESP32_CRYPT_DEBUG */
|
||||
#define NO_RECOVER_SOFTWARE_CALC
|
||||
|
||||
/* optionally turn off individual math HW acceleration features */
|
||||
|
||||
/* Turn off Large Number Multiplication:
|
||||
** [Z = X * Y] in esp_mp_mul() */
|
||||
/* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MP_MUL */
|
||||
|
||||
/* Turn off Large Number Modular Exponentiation:
|
||||
** [Z = X^Y mod M] in esp_mp_exptmod() */
|
||||
/* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_EXPTMOD */
|
||||
|
||||
/* Turn off Large Number Modular Multiplication
|
||||
** [Z = X × Y mod M] in esp_mp_mulmod() */
|
||||
/* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MULMOD */
|
||||
|
||||
|
||||
/* this is known to fail in TFM: */
|
||||
/* #define HONOR_MATH_USED_LENGTH */
|
||||
|
||||
/* this is known to fail in TFM */
|
||||
/* #define CHECK_MP_READ_UNSIGNED_BIN */
|
||||
|
||||
#define WOLFSSL_PUBLIC_MP /* used by benchmark */
|
||||
#if defined(WOLFSSL_SM2) || defined(WOLFSSL_SM3) || defined(WOLFSSL_SM4)
|
||||
#include <wolfssl/certs_test_sm.h>
|
||||
#define CTX_CA_CERT root_sm2
|
||||
#define CTX_CA_CERT_SIZE sizeof_root_sm2
|
||||
#define CTX_CA_CERT_TYPE WOLFSSL_FILETYPE_PEM
|
||||
#define CTX_SERVER_CERT server_sm2
|
||||
#define CTX_SERVER_CERT_SIZE sizeof_server_sm2
|
||||
#define CTX_SERVER_CERT_TYPE WOLFSSL_FILETYPE_PEM
|
||||
#define CTX_SERVER_KEY server_sm2_priv
|
||||
#define CTX_SERVER_KEY_SIZE sizeof_server_sm2_priv
|
||||
#define CTX_SERVER_KEY_TYPE WOLFSSL_FILETYPE_PEM
|
||||
#else
|
||||
#define USE_CERT_BUFFERS_2048
|
||||
#define USE_CERT_BUFFERS_256
|
||||
#define CTX_CA_CERT ca_cert_der_2048
|
||||
#define CTX_CA_CERT_SIZE sizeof_ca_cert_der_2048
|
||||
#define CTX_CA_CERT_TYPE WOLFSSL_FILETYPE_ASN1
|
||||
#define CTX_SERVER_CERT server_cert_der_2048
|
||||
#define CTX_SERVER_CERT_SIZE sizeof_server_cert_der_2048
|
||||
#define CTX_SERVER_CERT_TYPE WOLFSSL_FILETYPE_ASN1
|
||||
#define CTX_SERVER_KEY server_key_der_2048
|
||||
#define CTX_SERVER_KEY_SIZE sizeof_server_key_der_2048
|
||||
#define CTX_SERVER_KEY_TYPE WOLFSSL_FILETYPE_ASN1
|
||||
#endif
|
||||
|
||||
/* Optionally include alternate HW test library: alt_hw_test.h */
|
||||
/* When enabling, the ./components/wolfssl/CMakeLists.txt file
|
||||
* will need the name of the library in the idf_component_register
|
||||
* for the PRIV_REQUIRES list. */
|
||||
/* #define INCLUDE_ALT_HW_TEST */
|
||||
|
||||
/* #define NO_HW_MATH_TEST */
|
||||
|
||||
|
||||
/* when turning on ECC508 / ECC608 support
|
||||
#define WOLFSSL_ESPWROOM32SE
|
||||
#define HAVE_PK_CALLBACKS
|
||||
#define WOLFSSL_ATECC508A
|
||||
#define ATCA_WOLFSSL
|
||||
*/
|
||||
|
||||
/* USE_FAST_MATH is default */
|
||||
|
||||
/* use SP_MATH */
|
||||
/*
|
||||
#undef USE_FAST_MATH
|
||||
#define WOLFSSL_SP_MATH_ALL
|
||||
*/
|
||||
|
||||
/* use integer heap math */
|
||||
/*
|
||||
#undef USE_FAST_MATH
|
||||
#define USE_INTEGER_HEAP_MATH
|
||||
*/
|
||||
|
||||
/* optionally use DPORT_ACCESS_READ_BUFFER */
|
||||
/*
|
||||
#define USE_ESP_DPORT_ACCESS_READ_BUFFER
|
||||
*/
|
||||
|
||||
#define WOLFSSL_DTLS 1
|
||||
#define WOLFSSL_DTLS13
|
||||
#define WOLFSSL_SEND_HRR_COOKIE
|
||||
#define WOLFSSL_ENCRYPTED_KEYS
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
# This tag is used to include this file in the ESP Component Registry:
|
||||
# __ESP_COMPONENT_SOURCE__
|
||||
|
||||
#
|
||||
# wolfssl dtls 1.3 demo
|
||||
#
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_USER_SETTINGS")
|
||||
|
||||
set (git_cmd "git")
|
||||
|
||||
if( EXISTS "${CMAKE_HOME_DIRECTORY}/components/wolfssl/" AND EXISTS "$ENV{IDF_PATH}/components/wolfssl/" )
|
||||
#
|
||||
# wolfSSL found in both ESP-IDF and local project - needs to be resolved by user
|
||||
#
|
||||
message(STATUS "")
|
||||
message(STATUS "WARNING: Found components/wolfssl in both local project and IDF_PATH")
|
||||
message(STATUS "")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_MULTI_INSTALL_WARNING")
|
||||
endif()
|
||||
|
||||
## register_component()
|
||||
idf_component_register(
|
||||
SRCS main.c client-dtls13.c time_helper.c wifi_connect.c
|
||||
INCLUDE_DIRS "." "./include")
|
||||
#
|
||||
|
||||
#
|
||||
# LIBWOLFSSL_SAVE_INFO(VAR_OUPUT THIS_VAR VAR_RESULT)
|
||||
#
|
||||
# Save the THIS_VAR as a string in a macro called VAR_OUPUT
|
||||
#
|
||||
# VAR_OUPUT: the name of the macro to define
|
||||
# THIS_VAR: the OUTPUT_VARIABLE result from a execute_process()
|
||||
# VAR_RESULT: the RESULT_VARIABLE from a execute_process(); "0" if successful.
|
||||
#
|
||||
function ( LIBWOLFSSL_SAVE_INFO VAR_OUPUT THIS_VAR VAR_RESULT )
|
||||
# is the RESULT_VARIABLE output value 0? If so, IS_VALID_VALUE is true.
|
||||
string(COMPARE EQUAL "${VAR_RESULT}" "0" IS_VALID_VALUE)
|
||||
|
||||
# if we had a successful operation, save the THIS_VAR in VAR_OUPUT
|
||||
if(${IS_VALID_VALUE})
|
||||
# strip newline chars in THIS_VAR parameter and save in VAR_VALUE
|
||||
string(REPLACE "\n" "" VAR_VALUE ${THIS_VAR})
|
||||
|
||||
# we'll could percolate the value to the parent for possible later use
|
||||
# set(${VAR_OUPUT} ${VAR_VALUE} PARENT_SCOPE)
|
||||
|
||||
# but we're only using it here in this function
|
||||
set(${VAR_OUPUT} ${VAR_VALUE})
|
||||
|
||||
# we'll print what we found to the console
|
||||
message(STATUS "Found ${VAR_OUPUT}=${VAR_VALUE}")
|
||||
|
||||
# the interesting part is defining the VAR_OUPUT name a value to use in the app
|
||||
add_definitions(-D${VAR_OUPUT}=\"${VAR_VALUE}\")
|
||||
else()
|
||||
# if we get here, check the execute_process command and parameters.
|
||||
message(STATUS "LIBWOLFSSL_SAVE_INFO encountered a non-zero VAR_RESULT")
|
||||
set(${VAR_OUPUT} "Unknown")
|
||||
endif()
|
||||
endfunction() # LIBWOLFSSL_SAVE_INFO
|
||||
|
||||
if(NOT CMAKE_BUILD_EARLY_EXPANSION)
|
||||
# LIBWOLFSSL_VERSION_GIT_HASH
|
||||
execute_process(COMMAND ${git_cmd} "rev-parse" "HEAD" OUTPUT_VARIABLE TMP_OUT RESULT_VARIABLE TMP_RES ERROR_QUIET )
|
||||
LIBWOLFSSL_SAVE_INFO(LIBWOLFSSL_VERSION_GIT_HASH "${TMP_OUT}" "${TMP_RES}")
|
||||
|
||||
# LIBWOLFSSL_VERSION_GIT_SHORT_HASH
|
||||
execute_process(COMMAND ${git_cmd} "rev-parse" "--short" "HEAD" OUTPUT_VARIABLE TMP_OUT RESULT_VARIABLE TMP_RES ERROR_QUIET )
|
||||
LIBWOLFSSL_SAVE_INFO(LIBWOLFSSL_VERSION_GIT_SHORT_HASH "${TMP_OUT}" "${TMP_RES}")
|
||||
|
||||
# LIBWOLFSSL_VERSION_GIT_HASH_DATE
|
||||
execute_process(COMMAND ${git_cmd} "show" "--no-patch" "--no-notes" "--pretty=\'\%cd\'" OUTPUT_VARIABLE TMP_OUT RESULT_VARIABLE TMP_RES )
|
||||
LIBWOLFSSL_SAVE_INFO(LIBWOLFSSL_VERSION_GIT_HASH_DATE "${TMP_OUT}" "${TMP_RES}")
|
||||
endif()
|
||||
|
||||
message(STATUS "")
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
# This tag is used to include this file in the ESP Component Registry:
|
||||
# __ESP_COMPONENT_SOURCE__
|
||||
|
||||
#
|
||||
# wolfssl client test
|
||||
#
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_USER_SETTINGS")
|
||||
|
||||
set (git_cmd "git")
|
||||
|
||||
if( EXISTS "${CMAKE_HOME_DIRECTORY}/components/wolfssl/" AND EXISTS "$ENV{IDF_PATH}/components/wolfssl/" )
|
||||
#
|
||||
# wolfSSL found in both ESP-IDF and local project - needs to be resolved by user
|
||||
#
|
||||
message(STATUS "")
|
||||
message(STATUS "WARNING: Found components/wolfssl in both local project and IDF_PATH")
|
||||
message(STATUS "")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_MULTI_INSTALL_WARNING")
|
||||
endif()
|
||||
|
||||
## register_component()
|
||||
idf_component_register(
|
||||
SRCS main.c time_helper.c wifi_connect.c
|
||||
INCLUDE_DIRS "." "./include")
|
||||
#
|
||||
|
||||
#
|
||||
# LIBWOLFSSL_SAVE_INFO(VAR_OUPUT THIS_VAR VAR_RESULT)
|
||||
#
|
||||
# Save the THIS_VAR as a string in a macro called VAR_OUPUT
|
||||
#
|
||||
# VAR_OUPUT: the name of the macro to define
|
||||
# THIS_VAR: the OUTPUT_VARIABLE result from a execute_process()
|
||||
# VAR_RESULT: the RESULT_VARIABLE from a execute_process(); "0" if successful.
|
||||
#
|
||||
function ( LIBWOLFSSL_SAVE_INFO VAR_OUPUT THIS_VAR VAR_RESULT )
|
||||
# is the RESULT_VARIABLE output value 0? If so, IS_VALID_VALUE is true.
|
||||
string(COMPARE EQUAL "${VAR_RESULT}" "0" IS_VALID_VALUE)
|
||||
|
||||
# if we had a successful operation, save the THIS_VAR in VAR_OUPUT
|
||||
if(${IS_VALID_VALUE})
|
||||
# strip newline chars in THIS_VAR parameter and save in VAR_VALUE
|
||||
string(REPLACE "\n" "" VAR_VALUE ${THIS_VAR})
|
||||
|
||||
# we'll could percolate the value to the parent for possible later use
|
||||
# set(${VAR_OUPUT} ${VAR_VALUE} PARENT_SCOPE)
|
||||
|
||||
# but we're only using it here in this function
|
||||
set(${VAR_OUPUT} ${VAR_VALUE})
|
||||
|
||||
# we'll print what we found to the console
|
||||
message(STATUS "Found ${VAR_OUPUT}=${VAR_VALUE}")
|
||||
|
||||
# the interesting part is defining the VAR_OUPUT name a value to use in the app
|
||||
add_definitions(-D${VAR_OUPUT}=\"${VAR_VALUE}\")
|
||||
else()
|
||||
# if we get here, check the execute_process command and parameters.
|
||||
message(STATUS "LIBWOLFSSL_SAVE_INFO encountered a non-zero VAR_RESULT")
|
||||
set(${VAR_OUPUT} "Unknown")
|
||||
endif()
|
||||
endfunction() # LIBWOLFSSL_SAVE_INFO
|
||||
|
||||
if(NOT CMAKE_BUILD_EARLY_EXPANSION)
|
||||
# LIBWOLFSSL_VERSION_GIT_HASH
|
||||
execute_process(COMMAND ${git_cmd} "rev-parse" "HEAD" OUTPUT_VARIABLE TMP_OUT RESULT_VARIABLE TMP_RES ERROR_QUIET )
|
||||
LIBWOLFSSL_SAVE_INFO(LIBWOLFSSL_VERSION_GIT_HASH "${TMP_OUT}" "${TMP_RES}")
|
||||
|
||||
# LIBWOLFSSL_VERSION_GIT_SHORT_HASH
|
||||
execute_process(COMMAND ${git_cmd} "rev-parse" "--short" "HEAD" OUTPUT_VARIABLE TMP_OUT RESULT_VARIABLE TMP_RES ERROR_QUIET )
|
||||
LIBWOLFSSL_SAVE_INFO(LIBWOLFSSL_VERSION_GIT_SHORT_HASH "${TMP_OUT}" "${TMP_RES}")
|
||||
|
||||
# LIBWOLFSSL_VERSION_GIT_HASH_DATE
|
||||
execute_process(COMMAND ${git_cmd} "show" "--no-patch" "--no-notes" "--pretty=\'\%cd\'" OUTPUT_VARIABLE TMP_OUT RESULT_VARIABLE TMP_RES )
|
||||
LIBWOLFSSL_SAVE_INFO(LIBWOLFSSL_VERSION_GIT_HASH_DATE "${TMP_OUT}" "${TMP_RES}")
|
||||
endif()
|
||||
|
||||
message(STATUS "")
|
||||
|
|
@ -0,0 +1,310 @@
|
|||
/* client-dtls13.c
|
||||
*
|
||||
* Copyright (C) 2006-2022 wolfSSL Inc.
|
||||
*
|
||||
* This file is part of wolfSSL. (formerly known as CyaSSL)
|
||||
*
|
||||
* 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-1301, USA
|
||||
*
|
||||
*=============================================================================
|
||||
*
|
||||
* Bare-bones example of a DTLS 1.3 server for instructional/learning purposes.
|
||||
* This example can only accept one connection at a time.
|
||||
*
|
||||
* Define USE_DTLS12 to use DTLS 1.2 instead of DTLS 1.3
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code was adapted from the wolfSSL/wolfssl-examples/dtls located at:
|
||||
*
|
||||
* https://github.com/wolfSSL/wolfssl-examples/blob/master/dtls/client-dtls13.c
|
||||
*/
|
||||
#include "client-dtls13.h"
|
||||
|
||||
#if defined(SINGLE_THREADED)
|
||||
#define WOLFSSL_ESP_TASK int
|
||||
#else
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include <freertos/event_groups.h>
|
||||
#define WOLFSSL_ESP_TASK void
|
||||
#endif
|
||||
|
||||
/* Espressif socket */
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* #include <signal.h> not fully implemented in ESP-IDF */
|
||||
#include <lwip/netdb.h>
|
||||
#include <lwip/sockets.h>
|
||||
|
||||
/* wolfSSL */
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
#include "user_settings.h" /* always before other wolfssl files */
|
||||
|
||||
#include <wolfssl/ssl.h>
|
||||
#include <errno.h>
|
||||
#include <wolfssl/certs_test.h>
|
||||
|
||||
/* this app */
|
||||
#include "dtls-common.h"
|
||||
|
||||
/* convert macros values to string */
|
||||
#define STRINGIFY(x) #x
|
||||
|
||||
static const char* const TAG = "server-dtls13";
|
||||
|
||||
WOLFSSL_CTX* ctx = NULL;
|
||||
WOLFSSL* ssl = NULL;
|
||||
int listenfd = INVALID_SOCKET; /* Initialize our socket */
|
||||
|
||||
/* Note: not implemented at this time:
|
||||
* static void sig_handler(const int sig); */
|
||||
|
||||
/* show stack space for this task */
|
||||
static int ShowStackInfo(char* msg)
|
||||
{
|
||||
int ret;
|
||||
ret = TLS_SMP_CLIENT_TASK_WORDS - (uxTaskGetStackHighWaterMark(NULL));
|
||||
ESP_LOGI(TAG, "%s: %d words", msg, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if 0
|
||||
int main(int argc, char** argv)
|
||||
#else
|
||||
WOLFSSL_ESP_TASK dtls13_smp_client_task(void *pvParameters)
|
||||
#endif
|
||||
{
|
||||
/* Loc short for "location" */
|
||||
#if defined(SINGLE_THREADED)
|
||||
#define TLS_SMP_CLIENT_TASK_RET exitVal
|
||||
#else
|
||||
#define TLS_SMP_CLIENT_TASK_RET
|
||||
#endif
|
||||
|
||||
/* standard variables used in a dtls client*/
|
||||
int n = 0;
|
||||
int sockfd = INVALID_SOCKET;
|
||||
int err;
|
||||
int ret;
|
||||
struct sockaddr_in servAddr;
|
||||
WOLFSSL* ssl = NULL;
|
||||
WOLFSSL_CTX* ctx = NULL;
|
||||
char sendLine[MAXLINE];
|
||||
char recvLine[MAXLINE - 1];
|
||||
|
||||
ShowStackInfo("dtls13_smp_client_task startup");
|
||||
/* Initialize wolfSSL before assigning ctx */
|
||||
if (wolfSSL_Init() != WOLFSSL_SUCCESS) {
|
||||
ESP_LOGE(TAG, "wolfSSL_CTX_new error.\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* No-op when debugging is not compiled in */
|
||||
wolfSSL_Debugging_ON();
|
||||
|
||||
if ( (ctx = wolfSSL_CTX_new(
|
||||
#ifndef USE_DTLS12
|
||||
wolfDTLSv1_3_client_method()
|
||||
#else
|
||||
wolfDTLSv1_2_client_method()
|
||||
#endif
|
||||
)) == NULL) {
|
||||
ESP_LOGE(TAG, "wolfSSL_CTX_new error.\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* Load certificates into ctx variable */
|
||||
#ifdef NO_FILESYSTEM
|
||||
if (wolfSSL_CTX_load_verify_buffer(ctx,
|
||||
CTX_CA_CERT, CTX_CA_CERT_SIZE,
|
||||
CTX_CA_CERT_TYPE) != SSL_SUCCESS) {
|
||||
ESP_LOGE(TAG, "Error loading CTX_CA_CERT, please check the file.\n");
|
||||
goto cleanup;
|
||||
}
|
||||
#else
|
||||
if (wolfSSL_CTX_load_verify_locations(ctx, caCertLoc, 0)
|
||||
!= SSL_SUCCESS) {
|
||||
ESP_LOGE(TAG, "Error loading %s, please check the file.\n", caCertLoc);
|
||||
goto cleanup;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Assign ssl variable */
|
||||
ssl = wolfSSL_new(ctx);
|
||||
if (ssl == NULL) {
|
||||
ESP_LOGE(TAG, "unable to get ssl object\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* servAddr setup */
|
||||
ESP_LOGI(TAG, "See ./include/client-dtls13.h to update settings.");
|
||||
ESP_LOGI(TAG, "Setting server address to %s, port %d.",
|
||||
TLS_SMP_SERVER_ADDRESS, SERV_PORT);
|
||||
memset(&servAddr, 0, sizeof(servAddr));
|
||||
servAddr.sin_family = AF_INET;
|
||||
servAddr.sin_port = htons(SERV_PORT);
|
||||
if (inet_pton(AF_INET, TLS_SMP_SERVER_ADDRESS, &servAddr.sin_addr) < 1) {
|
||||
ESP_LOGE(TAG, "inet_pton()");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (wolfSSL_dtls_set_peer(ssl, &servAddr, sizeof(servAddr))
|
||||
!= WOLFSSL_SUCCESS) {
|
||||
ESP_LOGE(TAG, "wolfSSL_dtls_set_peer failed\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ( (sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
|
||||
ESP_LOGE(TAG, "socket()");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* Set the file descriptor for ssl */
|
||||
if (wolfSSL_set_fd(ssl, sockfd) != WOLFSSL_SUCCESS) {
|
||||
ESP_LOGE(TAG, "cannot set socket file descriptor\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* Perform SSL connection */
|
||||
ESP_LOGI(TAG, "Connecting to DTLS 1.3 server...");
|
||||
if (wolfSSL_connect(ssl) != SSL_SUCCESS) {
|
||||
err = wolfSSL_get_error(ssl, 0);
|
||||
ESP_LOGE(TAG, "err = %d, %s\n",
|
||||
err, wolfSSL_ERR_reason_error_string(err));
|
||||
ESP_LOGE(TAG, "wolfSSL_connect failed\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
showConnInfo(ssl);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code for sending datagram to server */
|
||||
while (1) {
|
||||
|
||||
ESP_LOGI(TAG, "Sending message");
|
||||
|
||||
strcpy(sendLine, "Hello World.");
|
||||
|
||||
/* Send sendLine to the server */
|
||||
if (wolfSSL_write(ssl, sendLine, strlen(sendLine)) != strlen(sendLine)) {
|
||||
err = wolfSSL_get_error(ssl, 0);
|
||||
ESP_LOGE(TAG, "err = %d, %s\n",
|
||||
err, wolfSSL_ERR_reason_error_string(err));
|
||||
ESP_LOGE(TAG, "wolfSSL_write failed\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Reading reply");
|
||||
/* n is the # of bytes received */
|
||||
n = wolfSSL_read(ssl, recvLine, sizeof(recvLine)-1);
|
||||
|
||||
if (n > 0) {
|
||||
/* Add a terminating character to the generic server message */
|
||||
recvLine[n] = '\0';
|
||||
ESP_LOGI(TAG, "%s\n", recvLine);
|
||||
}
|
||||
else {
|
||||
err = wolfSSL_get_error(ssl, 0);
|
||||
ESP_LOGE(TAG, "err = %d, %s\n",
|
||||
err, wolfSSL_ERR_reason_error_string(err));
|
||||
ESP_LOGE(TAG, "wolfSSL_read failed\n");
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
/* End code for sending datagram to server */
|
||||
/*****************************************************************************/
|
||||
|
||||
cleanup:
|
||||
if (ssl != NULL) {
|
||||
/* Attempt a full shutdown */
|
||||
ret = wolfSSL_shutdown(ssl);
|
||||
if (ret == WOLFSSL_SHUTDOWN_NOT_DONE)
|
||||
ret = wolfSSL_shutdown(ssl);
|
||||
if (ret != WOLFSSL_SUCCESS) {
|
||||
err = wolfSSL_get_error(ssl, 0);
|
||||
ESP_LOGE(TAG, "err = %d, %s\n",
|
||||
err, wolfSSL_ERR_reason_error_string(err));
|
||||
ESP_LOGE(TAG, "wolfSSL_shutdown failed\n");
|
||||
}
|
||||
wolfSSL_free(ssl);
|
||||
}
|
||||
if (sockfd != INVALID_SOCKET)
|
||||
close(sockfd);
|
||||
if (ctx != NULL)
|
||||
wolfSSL_CTX_free(ctx);
|
||||
wolfSSL_Cleanup();
|
||||
|
||||
vTaskDelete(NULL);
|
||||
|
||||
return TLS_SMP_CLIENT_TASK_RET;
|
||||
}
|
||||
|
||||
|
||||
#ifndef WOLFSSL_ESPIDF
|
||||
static void sig_handler(const int sig)
|
||||
{
|
||||
(void)sig;
|
||||
free_resources();
|
||||
wolfSSL_Cleanup();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if defined(SINGLE_THREADED)
|
||||
/* we don't initialize a thread */
|
||||
#else
|
||||
/* create task */
|
||||
int dtls13_smp_client_init(int port)
|
||||
{
|
||||
int ret = 0;
|
||||
int thisPort;
|
||||
thisPort = port;
|
||||
if (thisPort == 0) {
|
||||
thisPort = DEFAULT_PORT;
|
||||
}
|
||||
|
||||
|
||||
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||
TaskHandle_t _handle;
|
||||
#else
|
||||
xTaskHandle _handle;
|
||||
#endif
|
||||
|
||||
/* http://esp32.info/docs/esp_idf/html/dd/d3c/group__xTaskCreate.html */
|
||||
ESP_LOGI(TAG, "Creating dtls13_smp_client_task with stack size = %d words",
|
||||
TLS_SMP_CLIENT_TASK_WORDS);
|
||||
ret = xTaskCreate(dtls13_smp_client_task,
|
||||
TLS_SMP_CLIENT_TASK_NAME,
|
||||
TLS_SMP_CLIENT_TASK_WORDS, /* not bytes! */
|
||||
(void*)&thisPort,
|
||||
TLS_SMP_CLIENT_TASK_PRIORITY,
|
||||
&_handle);
|
||||
|
||||
if (ret == pdPASS) {
|
||||
ESP_LOGI(TAG, "Success: create thread %s", TLS_SMP_CLIENT_TASK_NAME);
|
||||
}
|
||||
else {
|
||||
ESP_LOGE(TAG, "create thread %s failed", TLS_SMP_CLIENT_TASK_NAME);
|
||||
}
|
||||
|
||||
/* vTaskStartScheduler(); // called automatically in ESP-IDF */
|
||||
return ret;
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,58 @@
|
|||
/* server-dtls13.h
|
||||
*
|
||||
* Copyright (C) 2006-2023 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
|
||||
*/
|
||||
#ifndef CLIENT_TLS
|
||||
#define CLIENT_TLS
|
||||
|
||||
#define DEFAULT_PORT 11111
|
||||
|
||||
#define TLS_SMP_CLIENT_TASK_NAME "dtls13"
|
||||
#define TLS_SMP_CLIENT_TASK_WORDS 20240
|
||||
#define TLS_SMP_CLIENT_TASK_PRIORITY 5
|
||||
|
||||
#define TLS_SMP_SERVER_ADDRESS "192.168.1.125"
|
||||
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
#include "user_settings.h"
|
||||
|
||||
#include <wolfssl/ssl.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Function to show the ciphers available / in use. */
|
||||
int ShowCiphers(WOLFSSL* ssl);
|
||||
|
||||
/* This is the TLS Server function, possibly in an RTOS thread. */
|
||||
//WOLFSSL_ESP_TASK udp_server_task(void *pvParameters);
|
||||
|
||||
/* init will create an RTOS task, otherwise server is simply function call. */
|
||||
#if defined(SINGLE_THREADED)
|
||||
/* no init neded */
|
||||
#else
|
||||
int dtls13_smp_client_init(int port);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* CLIENT_TLS */
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* dtls-common.h
|
||||
*
|
||||
* Copyright (C) 2006-2022 wolfSSL Inc.
|
||||
*
|
||||
* This file is part of wolfSSL. (formerly known as CyaSSL)
|
||||
*
|
||||
* 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-1301, USA
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Define USE_DTLS12 to use DTLS 1.2 instead of DTLS 1.3
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef DTLS_COMMON_H
|
||||
#define DTLS_COMMON_H
|
||||
|
||||
#include <esp_log.h>
|
||||
|
||||
#define INVALID_SOCKET -1
|
||||
#define MAXLINE 4096
|
||||
#define SERV_PORT 11111
|
||||
#define LOOP_LIMIT 5
|
||||
#define SFD_TIMEOUT 1
|
||||
|
||||
/* Loc short for "location" */
|
||||
#ifndef NO_FILESYSTEM
|
||||
const char caCertLoc[] = "../certs/ca-cert.pem";
|
||||
const char servCertLoc[] = "../certs/server-cert.pem";
|
||||
const char servKeyLoc[] = "../certs/server-key.pem";
|
||||
#else
|
||||
/* see user_settings.h for CTX_ array macros */
|
||||
#endif
|
||||
|
||||
static inline void showConnInfo(WOLFSSL* ssl) {
|
||||
ESP_LOGI("DTLS", "New connection established using %s %s\n",
|
||||
wolfSSL_get_version(ssl), wolfSSL_get_cipher(ssl));
|
||||
}
|
||||
|
||||
#endif /* DTLS_COMMON_H */
|
|
@ -0,0 +1,30 @@
|
|||
/* template main.h
|
||||
*
|
||||
* Copyright (C) 2006-2023 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 tag is used to include this file in the ESP Component Registry:
|
||||
# __ESP_COMPONENT_SOURCE__
|
||||
*/
|
||||
|
||||
#ifndef MAIN_H
|
||||
#define MAIN_H
|
||||
|
||||
#endif
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (C) 2006-2023 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 tag is used to include this file in the ESP Component Registry:
|
||||
# __ESP_COMPONENT_SOURCE__
|
||||
*/
|
||||
|
||||
#ifndef _TIME_HELPER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* worst case, if GitHub time not available, used fixed time */
|
||||
int set_fixed_default_time();
|
||||
|
||||
/* set time from string (e.g. GitHub commit time) */
|
||||
int set_time_from_string(char* time_buffer);
|
||||
|
||||
/* set time from NTP servers,
|
||||
* also intitially calls set_fixed_default_time or set_time_from_string */
|
||||
int set_time(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* #ifndef _TIME_HELPER_H */
|
|
@ -0,0 +1,74 @@
|
|||
/* wifi_connect.h
|
||||
*
|
||||
* Copyright (C) 2006-2023 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
|
||||
*/
|
||||
#ifndef WIFI_CONNECT_H
|
||||
#define WIFI_CONNECT_H
|
||||
|
||||
#include <esp_idf_version.h>
|
||||
#include <esp_log.h>
|
||||
|
||||
/* ESP lwip */
|
||||
#define EXAMPLE_ESP_MAXIMUM_RETRY CONFIG_ESP_MAXIMUM_RETRY
|
||||
|
||||
#define TLS_SMP_WIFI_SSID CONFIG_WIFI_SSID
|
||||
#define TLS_SMP_WIFI_PASS CONFIG_WIFI_PASSWORD
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
******************************************************************************
|
||||
** USER APPLICATION SETTINGS BEGIN
|
||||
******************************************************************************
|
||||
******************************************************************************
|
||||
**/
|
||||
|
||||
/* when using a private config with plain text passwords, not my_private_config.h should be excluded from git updates */
|
||||
#define USE_MY_PRIVATE_CONFIG
|
||||
|
||||
#ifdef USE_MY_PRIVATE_CONFIG
|
||||
#if defined(WOLFSSL_CMAKE_SYSTEM_NAME_WINDOWS)
|
||||
#include "/workspace/my_private_config.h"
|
||||
#elif defined(WOLFSSL_CMAKE_SYSTEM_NAME_WSL)
|
||||
#include "/mnt/c/workspace/my_private_config.h"
|
||||
#elif defined(WOLFSSL_CMAKE_SYSTEM_NAME_LINUX)
|
||||
#include "~/workspace/my_private_config.h"
|
||||
#elif defined(WOLFSSL_CMAKE_SYSTEM_NAME_APPLE)
|
||||
#include "~/Documents/my_private_config.h"
|
||||
#else
|
||||
#warning "did not detect environment. using ~/my_private_config.h"
|
||||
#include "~/my_private_config.h"
|
||||
#endif
|
||||
#else
|
||||
|
||||
/*
|
||||
** The examples use WiFi configuration that you can set via project
|
||||
** configuration menu
|
||||
**
|
||||
** If you'd rather not, just change the below entries to strings with
|
||||
** the config you want - ie #define EXAMPLE_WIFI_SSID "mywifissid"
|
||||
*/
|
||||
#define EXAMPLE_ESP_WIFI_SSID CONFIG_ESP_WIFI_SSID
|
||||
#define EXAMPLE_ESP_WIFI_PASS CONFIG_ESP_WIFI_PASSWORD
|
||||
#endif
|
||||
|
||||
int wifi_init_sta(void);
|
||||
|
||||
int wifi_show_ip(void);
|
||||
|
||||
#endif /* _WIFI_CONNECT_H_ */
|
|
@ -0,0 +1,85 @@
|
|||
/* wifi_connect.h
|
||||
*
|
||||
* Copyright (C) 2006-2023 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
|
||||
*/
|
||||
#ifndef _WIFI_CONNECT_H_
|
||||
#define _WIFI_CONNECT_H_
|
||||
|
||||
#include <esp_idf_version.h>
|
||||
#include <esp_log.h>
|
||||
|
||||
|
||||
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||
//#include "esp_wifi.h"
|
||||
//#include "esp_event.h"
|
||||
#else
|
||||
#include "esp_event_loop.h"
|
||||
#endif
|
||||
|
||||
/* ESP lwip */
|
||||
#define EXAMPLE_ESP_MAXIMUM_RETRY CONFIG_ESP_MAXIMUM_RETRY
|
||||
#define TLS_SMP_WIFI_SSID CONFIG_WIFI_SSID
|
||||
#define TLS_SMP_WIFI_PASS CONFIG_WIFI_PASSWORD
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
******************************************************************************
|
||||
** USER APPLICATION SETTINGS BEGIN
|
||||
******************************************************************************
|
||||
******************************************************************************
|
||||
**/
|
||||
|
||||
/* when using a private config with plain text passwords, not my_private_config.h should be excluded from git updates */
|
||||
#define USE_MY_PRIVATE_CONFIG
|
||||
|
||||
#ifdef USE_MY_PRIVATE_CONFIG
|
||||
#if defined(WOLFSSL_CMAKE_SYSTEM_NAME_WINDOWS)
|
||||
#include "/workspace/my_private_config.h"
|
||||
#elif defined(WOLFSSL_CMAKE_SYSTEM_NAME_WSL)
|
||||
#include "/mnt/c/workspace/my_private_config.h"
|
||||
#elif defined(WOLFSSL_CMAKE_SYSTEM_NAME_LINUX)
|
||||
#include "~/workspace/my_private_config.h"
|
||||
#elif defined(WOLFSSL_CMAKE_SYSTEM_NAME_APPLE)
|
||||
#include "~/Documents/my_private_config.h"
|
||||
#else
|
||||
#warning "did not detect environment. using ~/my_private_config.h"
|
||||
#include "~/my_private_config.h"
|
||||
#warning "did not detect environment"
|
||||
#endif
|
||||
#else
|
||||
|
||||
/*
|
||||
** The examples use WiFi configuration that you can set via project
|
||||
** configuration menu
|
||||
**
|
||||
** If you'd rather not, just change the below entries to strings with
|
||||
** the config you want - ie #define EXAMPLE_WIFI_SSID "mywifissid"
|
||||
*/
|
||||
#define EXAMPLE_ESP_WIFI_SSID CONFIG_ESP_WIFI_SSID
|
||||
#define EXAMPLE_ESP_WIFI_PASS CONFIG_ESP_WIFI_PASSWORD
|
||||
#endif
|
||||
|
||||
/* ESP lwip */
|
||||
#define EXAMPLE_ESP_MAXIMUM_RETRY CONFIG_ESP_MAXIMUM_RETRY
|
||||
|
||||
int wifi_init_sta(void);
|
||||
|
||||
int wifi_show_ip(void);
|
||||
|
||||
#endif /* _WIFI_CONNECT_H_ */
|
|
@ -0,0 +1,115 @@
|
|||
/* main.c
|
||||
*
|
||||
* Copyright (C) 2006-2023 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
|
||||
*/
|
||||
|
||||
/* ESP specific */
|
||||
#include <nvs_flash.h>
|
||||
#include <esp_log.h>
|
||||
|
||||
/* wolfSSL */
|
||||
#include <wolfssl/wolfcrypt/port/Espressif/esp32-crypt.h>
|
||||
#include <wolfssl/certs_test.h>
|
||||
|
||||
/* project */
|
||||
#include "main.h"
|
||||
#include "wifi_connect.h"
|
||||
#include "time_helper.h"
|
||||
#include "client-dtls13.h"
|
||||
static const char* const TAG = "main task";
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "-------------- wolfSSL DTLS 1.3 Client Example ---------");
|
||||
ESP_LOGI(TAG, "--------------------------------------------------------");
|
||||
ESP_LOGI(TAG, "--------------------------------------------------------");
|
||||
ESP_LOGI(TAG, "---------------------- BEGIN MAIN ----------------------");
|
||||
ESP_LOGI(TAG, "--------------------------------------------------------");
|
||||
ESP_LOGI(TAG, "--------------------------------------------------------");
|
||||
#ifdef HAVE_VERSION_EXTENDED_INFO
|
||||
esp_ShowExtendedSystemInfo();
|
||||
#endif
|
||||
|
||||
/* Initialize NVS */
|
||||
esp_err_t ret = nvs_flash_init();
|
||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES ||
|
||||
ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
ret = nvs_flash_init();
|
||||
}
|
||||
ESP_ERROR_CHECK(ret);
|
||||
|
||||
/* Initialize WiFi */
|
||||
ESP_LOGI(TAG, "ESP_WIFI_MODE_STA");
|
||||
ret = wifi_init_sta();
|
||||
while (ret != 0) {
|
||||
ESP_LOGI(TAG, "Waiting...");
|
||||
vTaskDelay(60000 / portTICK_PERIOD_MS);
|
||||
ESP_LOGI(TAG, "Trying WiFi again...");
|
||||
ret = wifi_init_sta();
|
||||
}
|
||||
|
||||
/* set time for cert validation */
|
||||
ret = set_time();
|
||||
if (ret < -1) {
|
||||
/* a value of -1 means there was no NTP server, so no need to wait */
|
||||
ESP_LOGI(TAG, "Waiting 10 seconds for NTP to complete." );
|
||||
vTaskDelay(10000 / portTICK_PERIOD_MS); /* brute-force solution */
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "CONFIG_ESP_MAIN_TASK_STACK_SIZE = %d bytes (%d words)",
|
||||
CONFIG_ESP_MAIN_TASK_STACK_SIZE,
|
||||
(int)(CONFIG_ESP_MAIN_TASK_STACK_SIZE / sizeof(void*)));
|
||||
|
||||
/* HWM is maximum amount of stack space that has been unused, in words. */
|
||||
ESP_LOGI(TAG, "Initial Stack Used (before wolfSSL Server): %d bytes",
|
||||
CONFIG_ESP_MAIN_TASK_STACK_SIZE
|
||||
- (uxTaskGetStackHighWaterMark(NULL) / 4)
|
||||
);
|
||||
ESP_LOGI(TAG, "Starting DTLS 1.3 Client...\n");
|
||||
|
||||
#if defined(SINGLE_THREADED)
|
||||
/* just call the task */
|
||||
dtls13_smp_client_task((void*)NULL);
|
||||
#else
|
||||
/* start a thread with the task */
|
||||
dtls13_smp_client_init((int)NULL); /* NULL will use the DEFAULT_PORT value */
|
||||
#endif
|
||||
|
||||
ESP_LOGV(TAG, "\n\nvTaskDelete...\n\n");
|
||||
vTaskDelete(NULL);
|
||||
/* done */
|
||||
while (1) {
|
||||
ESP_LOGV(TAG, "\n\nLoop...\n\n");
|
||||
#ifdef INCLUDE_uxTaskGetStackHighWaterMark
|
||||
ESP_LOGI(TAG, "Stack HWM: %d", uxTaskGetStackHighWaterMark(NULL));
|
||||
|
||||
ESP_LOGI(TAG, "Stack used: %d", CONFIG_ESP_MAIN_TASK_STACK_SIZE
|
||||
- (uxTaskGetStackHighWaterMark(NULL) / 4));
|
||||
#endif
|
||||
|
||||
#if defined(SINGLE_THREADED)
|
||||
ESP_LOGV(TAG, "\n\nDone!\n\n");
|
||||
while (1);
|
||||
#else
|
||||
vTaskDelay(60000);
|
||||
#endif
|
||||
} /* done whle */
|
||||
|
||||
} /* app_main */
|
|
@ -0,0 +1,466 @@
|
|||
/* server-dtls13.c
|
||||
*
|
||||
* Copyright (C) 2006-2022 wolfSSL Inc.
|
||||
*
|
||||
* This file is part of wolfSSL. (formerly known as CyaSSL)
|
||||
*
|
||||
* 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-1301, USA
|
||||
*
|
||||
*=============================================================================
|
||||
*
|
||||
* Bare-bones example of a DTLS 1.3 server for instructional/learning purposes.
|
||||
* This example can gonly accept one connection at a time.
|
||||
*
|
||||
* Define USE_DTLS12 to use DTLS 1.2 instead of DTLS 1.3
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code was adapted from the wolfSSL/wolfssl-examples/dtls located at:
|
||||
*
|
||||
* https://github.com/wolfSSL/wolfssl-examples/blob/master/dtls/client-dtls13.c
|
||||
*/
|
||||
#include "server-dtls13.h"
|
||||
|
||||
#if defined(SINGLE_THREADED)
|
||||
#define WOLFSSL_ESP_TASK int
|
||||
#else
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include <freertos/event_groups.h>
|
||||
#define WOLFSSL_ESP_TASK void
|
||||
#endif
|
||||
|
||||
/* Espressif socket */
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* #include <signal.h> not fully implemented in ESP-IDF */
|
||||
#include <lwip/netdb.h>
|
||||
#include <lwip/sockets.h>
|
||||
#include <stdio.h> /* standard in/out procedures */
|
||||
#include <stdlib.h> /* defines system calls */
|
||||
#include <string.h> /* necessary for memset */
|
||||
|
||||
/* wolfSSL */
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
#include "user_settings.h"
|
||||
|
||||
#include <wolfssl/ssl.h>
|
||||
#include <errno.h>
|
||||
#include <wolfssl/certs_test.h>
|
||||
|
||||
/* this app */
|
||||
#include "dtls-common.h"
|
||||
|
||||
/* convert macros values to string */
|
||||
#define STRINGIFY(x) #x
|
||||
|
||||
static const char* const TAG = "server-dtls13";
|
||||
|
||||
WOLFSSL_CTX* ctx = NULL;
|
||||
WOLFSSL* ssl = NULL;
|
||||
int listenfd = INVALID_SOCKET; /* Initialize our socket */
|
||||
|
||||
/* Note: not implemented at this time:
|
||||
* static void sig_handler(const int sig); */
|
||||
|
||||
static void free_resources(void);
|
||||
|
||||
/* show stack space for this task */
|
||||
static int ShowStackInfo(char* msg)
|
||||
{
|
||||
int ret;
|
||||
ret = TLS_SMP_SERVER_TASK_WORDS - (uxTaskGetStackHighWaterMark(NULL));
|
||||
ESP_LOGI(TAG, "%s: %d words", msg, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if 0
|
||||
int main(int argc, char** argv)
|
||||
#else
|
||||
WOLFSSL_ESP_TASK dtls13_smp_server_task(void *pvParameters)
|
||||
#endif
|
||||
{
|
||||
/* Loc short for "location" */
|
||||
#if defined(SINGLE_THREADED)
|
||||
#define TLS_SMP_SERVER_TASK_RET exitVal
|
||||
#else
|
||||
#define TLS_SMP_SERVER_TASK_RET
|
||||
#endif
|
||||
char buff[MAXLINE]; /* the incoming message */
|
||||
char ack[] = "I hear you fashizzle!\n";
|
||||
struct sockaddr_in servAddr = { 0 }; /* our server's address */
|
||||
struct sockaddr_in cliaddr = { 0 }; /* the client's address */
|
||||
socklen_t cliLen;
|
||||
int ret;
|
||||
int err;
|
||||
int recvLen = 0; /* length of message */
|
||||
int exitVal = 0;
|
||||
int ip_protocol = 0;
|
||||
exitVal = 1;
|
||||
|
||||
ESP_LOGI(TAG, "Init Stack: %d words", TLS_SMP_SERVER_TASK_WORDS);
|
||||
ShowStackInfo("Begin Stack used");
|
||||
|
||||
/* Initialize wolfSSL before assigning ctx */
|
||||
ret = wolfSSL_Init();
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
ESP_LOGI(TAG, "wolfSSL_Init success.");
|
||||
}
|
||||
else {
|
||||
ESP_LOGE(TAG, "wolfSSL_Init error %d.\n", ret);
|
||||
return TLS_SMP_SERVER_TASK_RET;
|
||||
}
|
||||
|
||||
/* Create new conext ctx & show some diagnostics */
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
ShowStackInfo("Init Stack used");
|
||||
|
||||
/* No-op when debugging is not compiled in */
|
||||
wolfSSL_Debugging_ON();
|
||||
|
||||
/* Set ctx to DTLS 1.3 unless DTLS1.2 explicitly enabled */
|
||||
#ifndef USE_DTLS12
|
||||
ESP_LOGI(TAG, "wolfSSL_CTX_new(wolfDTLSv1_3_server_method())");
|
||||
ctx = wolfSSL_CTX_new(wolfDTLSv1_3_server_method());
|
||||
#else
|
||||
ESP_LOGI(TAG, "wolfSSL_CTX_new(wolfDTLSv1_2_server_method())");
|
||||
ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method());
|
||||
#endif
|
||||
if(ctx == NULL) {
|
||||
ESP_LOGE(TAG, "wolfSSL_CTX_new error.\n");
|
||||
ret = WOLFSSL_FATAL_ERROR;
|
||||
}
|
||||
|
||||
(void)ctx;
|
||||
ShowStackInfo("Init ctx Stack used");
|
||||
} /* new ctx */
|
||||
|
||||
#ifdef NO_FILESYSTEM
|
||||
/* Load CA certificates */
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
/* caCertLoc[] = "../certs/ca-cert.pem"; */
|
||||
ret = wolfSSL_CTX_load_verify_buffer(ctx,
|
||||
CTX_CA_CERT,
|
||||
CTX_CA_CERT_SIZE,
|
||||
CTX_SERVER_CERT_TYPE);
|
||||
}
|
||||
|
||||
/* if successful, Load server certificates */
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
ESP_LOGI(TAG, "Success: wolfSSL_CTX_load_verify_buffer loaded %s",
|
||||
STRINGIFY(CTX_CA_CERT));
|
||||
|
||||
/* servCertLoc[] = "../certs/server-cert.pem"; */
|
||||
ret = wolfSSL_CTX_use_certificate_buffer(ctx,
|
||||
CTX_SERVER_CERT,
|
||||
CTX_SERVER_CERT_SIZE,
|
||||
CTX_SERVER_CERT_TYPE);
|
||||
}
|
||||
else {
|
||||
ESP_LOGE(TAG, "Failed CA wolfSSL_CTX_load_verify_buffer "
|
||||
"loading CA %s", STRINGIFY(CTX_SERVER_CERT));
|
||||
}
|
||||
|
||||
/* if successful Load server Keys */
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
ESP_LOGI(TAG, "Success: "
|
||||
"wolfSSL_CTX_use_certificate_chain_buffer_format "
|
||||
"loaded cert chain %s", STRINGIFY(CTX_SERVER_CERT));
|
||||
/* servKeyLoc[] = "../certs/server-key.pem"; */
|
||||
ret = wolfSSL_CTX_use_PrivateKey_buffer(ctx,
|
||||
CTX_SERVER_KEY,
|
||||
CTX_SERVER_KEY_SIZE,
|
||||
CTX_SERVER_KEY_TYPE);
|
||||
}
|
||||
else {
|
||||
ESP_LOGE(TAG, "Failed wolfSSL_CTX_use_certificate_chain_buffer_format "
|
||||
"loading private key %s", STRINGIFY(CTX_SERVER_KEY));
|
||||
}
|
||||
|
||||
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
ESP_LOGI(TAG, "Success: "
|
||||
"wolfSSL_CTX_use_PrivateKey_buffer "
|
||||
"loaded private key %s", STRINGIFY(CTX_SERVER_KEY));
|
||||
}
|
||||
else {
|
||||
ESP_LOGE(TAG, "Failed to load private key: %s",
|
||||
STRINGIFY(CTX_SERVER_KEY));
|
||||
}
|
||||
#else
|
||||
/* Load CA certificates */
|
||||
if (wolfSSL_CTX_load_verify_locations(ctx,caCertLoc,0) !=
|
||||
SSL_SUCCESS) {
|
||||
ESP_LOGE(TAG, "Error loading %s, please check the file.\n", caCertLoc);
|
||||
goto cleanup;
|
||||
}
|
||||
/* Load server certificates */
|
||||
if (wolfSSL_CTX_use_certificate_file(ctx, servCertLoc, SSL_FILETYPE_PEM) !=
|
||||
SSL_SUCCESS) {
|
||||
ESP_LOGE(TAG, "Error loading %s, please check the file.\n", servCertLoc);
|
||||
goto cleanup;
|
||||
}
|
||||
/* Load server Keys */
|
||||
if (wolfSSL_CTX_use_PrivateKey_file(ctx, servKeyLoc,
|
||||
SSL_FILETYPE_PEM) != SSL_SUCCESS) {
|
||||
ESP_LOGE(TAG, "Error loading %s, please check the file.\n", servKeyLoc);
|
||||
goto cleanup;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* initialize network vars */
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
memset((char *)&servAddr, 0, sizeof(servAddr));
|
||||
/* host-to-network-long conversion (htonl) */
|
||||
/* host-to-network-short conversion (htons) */
|
||||
servAddr.sin_family = AF_INET;
|
||||
servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
servAddr.sin_port = htons(SERV_PORT);
|
||||
ip_protocol = IPPROTO_IP;
|
||||
|
||||
/* Create a UDP/IP socket */
|
||||
listenfd = socket(AF_INET, SOCK_DGRAM, ip_protocol);
|
||||
if (listenfd < 0) {
|
||||
ESP_LOGE(TAG, "socket() failed: %d", listenfd);
|
||||
ret = WOLFSSL_FATAL_ERROR;
|
||||
}
|
||||
else {
|
||||
ESP_LOGI(TAG, "Socket allocated.");
|
||||
}
|
||||
} /* init network vars */
|
||||
|
||||
#if defined(CONFIG_LWIP_NETBUF_RECVINFO) && !defined(CONFIG_EXAMPLE_IPV6)
|
||||
int enable = 1;
|
||||
lwip_setsockopt(sock, IPPROTO_IP, IP_PKTINFO, &enable, sizeof(enable));
|
||||
#endif
|
||||
|
||||
/* init socket options */
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
struct timeval timeout;
|
||||
timeout.tv_sec = 1000; // 10 seconds
|
||||
timeout.tv_usec = 0;
|
||||
|
||||
if (setsockopt(listenfd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) == -1) {
|
||||
ESP_LOGE(TAG, "setsockopt for receive timeout");
|
||||
ret = WOLFSSL_FATAL_ERROR;
|
||||
}
|
||||
if (setsockopt(listenfd, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout)) == -1) {
|
||||
ESP_LOGE(TAG, "setsockopt for send timeout");
|
||||
ret = WOLFSSL_FATAL_ERROR;
|
||||
}
|
||||
} /* soctet options */
|
||||
|
||||
/* Bind Socket */
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
if (bind(listenfd, (struct sockaddr*)&servAddr, sizeof(servAddr)) < 0) {
|
||||
ESP_LOGE(TAG, "bind()");
|
||||
ret = WOLFSSL_FATAL_ERROR;
|
||||
}
|
||||
} /* bind socket */
|
||||
|
||||
#ifndef WOLFSSL_ESPIDF
|
||||
/* Signals and signal handling are not implemented in esp-idf.
|
||||
* Calling raise() will abort the program.
|
||||
* see https://esp32.com/viewtopic.php?t=29988&p=103871 */
|
||||
signal(SIGINT, sig_handler);
|
||||
#endif
|
||||
|
||||
ESP_LOGI(TAG, "While Stack used: %d words", TLS_SMP_SERVER_TASK_WORDS
|
||||
- (uxTaskGetStackHighWaterMark(NULL)));
|
||||
while (1) {
|
||||
printf("Awaiting client connection on port %d\n", SERV_PORT);
|
||||
|
||||
cliLen = sizeof(cliaddr);
|
||||
ret = (int)recvfrom(listenfd, (char *)&buff, sizeof(buff), MSG_PEEK,
|
||||
(struct sockaddr*)&cliaddr, &cliLen);
|
||||
|
||||
if (ret < 0) {
|
||||
ESP_LOGE(TAG, "recvfrom() < 0");
|
||||
ret = WOLFSSL_FATAL_ERROR;
|
||||
goto cleanup;
|
||||
}
|
||||
else if (ret == 0) {
|
||||
ESP_LOGE(TAG, "recvfrom zero return\n");
|
||||
ret = WOLFSSL_FATAL_ERROR;
|
||||
goto cleanup;
|
||||
}
|
||||
else {
|
||||
ret = WOLFSSL_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
ESP_LOGI(TAG, "Data!");
|
||||
/* Create the WOLFSSL Object */
|
||||
if ((ssl = wolfSSL_new(ctx)) == NULL) {
|
||||
ESP_LOGE(TAG, "wolfSSL_new error.\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (wolfSSL_dtls_set_peer(ssl, &cliaddr, cliLen) != WOLFSSL_SUCCESS) {
|
||||
ESP_LOGE(TAG, "wolfSSL_dtls_set_peer error.\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (wolfSSL_set_fd(ssl, listenfd) != WOLFSSL_SUCCESS) {
|
||||
ESP_LOGE(TAG, "wolfSSL_set_fd error.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if (wolfSSL_accept(ssl) != SSL_SUCCESS) {
|
||||
err = wolfSSL_get_error(ssl, 0);
|
||||
ESP_LOGE(TAG, "error = %d, %s\n",
|
||||
err, wolfSSL_ERR_reason_error_string(err));
|
||||
ESP_LOGE(TAG, "SSL_accept failed.\n");
|
||||
goto cleanup;
|
||||
}
|
||||
showConnInfo(ssl);
|
||||
while (1) {
|
||||
if ((recvLen = wolfSSL_read(ssl, buff, sizeof(buff)-1)) > 0) {
|
||||
ESP_LOGI(TAG, "heard %d bytes\n", recvLen);
|
||||
|
||||
buff[recvLen] = '\0';
|
||||
ESP_LOGI(TAG, "I heard this: \"%s\"\n", buff);
|
||||
}
|
||||
else if (recvLen <= 0) {
|
||||
err = wolfSSL_get_error(ssl, 0);
|
||||
if (err == WOLFSSL_ERROR_ZERO_RETURN) /* Received shutdown */
|
||||
break;
|
||||
ESP_LOGE(TAG, "error = %d, %s\n",
|
||||
err, wolfSSL_ERR_reason_error_string(err));
|
||||
ESP_LOGE(TAG, "SSL_read failed.\n");
|
||||
goto cleanup;
|
||||
}
|
||||
ESP_LOGI(TAG, "Sending reply.\n");
|
||||
if (wolfSSL_write(ssl, ack, sizeof(ack)) < 0) {
|
||||
err = wolfSSL_get_error(ssl, 0);
|
||||
ESP_LOGE(TAG, "error = %d, %s\n",
|
||||
err, wolfSSL_ERR_reason_error_string(err));
|
||||
ESP_LOGE(TAG, "wolfSSL_write failed.\n");
|
||||
goto cleanup;
|
||||
}
|
||||
ESP_LOGI(TAG, "reply sent \"%s\"\n", ack);
|
||||
} /* while */
|
||||
} /* got data */
|
||||
|
||||
printf("reply sent \"%s\"\n", ack);
|
||||
|
||||
/* Attempt a full shutdown */
|
||||
ret = wolfSSL_shutdown(ssl);
|
||||
if (ret == WOLFSSL_SHUTDOWN_NOT_DONE)
|
||||
ret = wolfSSL_shutdown(ssl);
|
||||
if (ret != WOLFSSL_SUCCESS) {
|
||||
err = wolfSSL_get_error(ssl, 0);
|
||||
ESP_LOGE(TAG, "err = %d, %s\n",
|
||||
err, wolfSSL_ERR_reason_error_string(err));
|
||||
ESP_LOGE(TAG, "wolfSSL_shutdown failed\n");
|
||||
}
|
||||
wolfSSL_free(ssl);
|
||||
ssl = NULL;
|
||||
|
||||
ESP_LOGI(TAG, "Awaiting new connection\n");
|
||||
//cleanup:
|
||||
// if (listenfd != -1) {
|
||||
// ESP_LOGE(TAG, "Shutting down socket and restarting...");
|
||||
// shutdown(listenfd, 0);
|
||||
// close(listenfd);
|
||||
// }
|
||||
// else {
|
||||
// ESP_LOGI(TAG, "restarting...");
|
||||
//
|
||||
// }
|
||||
}
|
||||
ESP_LOGI(TAG, "Exit %d", exitVal);
|
||||
exitVal = 0;
|
||||
cleanup:
|
||||
free_resources();
|
||||
wolfSSL_Cleanup();
|
||||
|
||||
vTaskDelete(NULL);
|
||||
|
||||
return TLS_SMP_SERVER_TASK_RET;
|
||||
}
|
||||
|
||||
|
||||
#ifndef WOLFSSL_ESPIDF
|
||||
static void sig_handler(const int sig)
|
||||
{
|
||||
(void)sig;
|
||||
free_resources();
|
||||
wolfSSL_Cleanup();
|
||||
}
|
||||
#endif
|
||||
|
||||
static void free_resources(void)
|
||||
{
|
||||
if (ssl != NULL) {
|
||||
wolfSSL_shutdown(ssl);
|
||||
wolfSSL_free(ssl);
|
||||
ssl = NULL;
|
||||
}
|
||||
if (ctx != NULL) {
|
||||
wolfSSL_CTX_free(ctx);
|
||||
ctx = NULL;
|
||||
}
|
||||
if (listenfd != INVALID_SOCKET) {
|
||||
close(listenfd);
|
||||
listenfd = INVALID_SOCKET;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(SINGLE_THREADED)
|
||||
/* we don't initialize a thread */
|
||||
#else
|
||||
/* create task */
|
||||
int dtls13_smp_server_init(int port)
|
||||
{
|
||||
int ret = 0;
|
||||
int thisPort;
|
||||
thisPort = port;
|
||||
if (thisPort == 0) {
|
||||
thisPort = DEFAULT_PORT;
|
||||
}
|
||||
|
||||
|
||||
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||
TaskHandle_t _handle;
|
||||
#else
|
||||
xTaskHandle _handle;
|
||||
#endif
|
||||
|
||||
/* http://esp32.info/docs/esp_idf/html/dd/d3c/group__xTaskCreate.html */
|
||||
ESP_LOGI(TAG, "Creating dtls13_smp_server_task with stack size = %d words",
|
||||
TLS_SMP_SERVER_TASK_WORDS);
|
||||
ret = xTaskCreate(dtls13_smp_server_task,
|
||||
TLS_SMP_SERVER_TASK_NAME,
|
||||
TLS_SMP_SERVER_TASK_WORDS, /* not bytes! */
|
||||
(void*)&thisPort,
|
||||
TLS_SMP_SERVER_TASK_PRIORITY,
|
||||
&_handle);
|
||||
|
||||
if (ret == pdPASS) {
|
||||
ESP_LOGI(TAG, "Success: create thread %s", TLS_SMP_SERVER_TASK_NAME);
|
||||
}
|
||||
else {
|
||||
ESP_LOGE(TAG, "create thread %s failed", TLS_SMP_SERVER_TASK_NAME);
|
||||
}
|
||||
|
||||
/* vTaskStartScheduler(); // called automatically in ESP-IDF */
|
||||
return ret;
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,212 @@
|
|||
/* time_helper.c
|
||||
*
|
||||
* Copyright (C) 2006-2023 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 tag is used to include this file in the ESP Component Registry:
|
||||
# __ESP_COMPONENT_SOURCE__
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <lwip/apps/sntp.h>
|
||||
#include <esp_netif_sntp.h>
|
||||
#include "sdkconfig.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
#include "time_helper.h"
|
||||
|
||||
const static char* TAG = "time_helper";
|
||||
|
||||
#define TIME_ZONE "PST-8"
|
||||
/* NELEMS(x) number of elements
|
||||
* To determine the number of elements in the array, we can divide the total size of
|
||||
* the array by the size of the array element
|
||||
* See https://stackoverflow.com/questions/37538/how-do-i-determine-the-size-of-my-array-in-c
|
||||
**/
|
||||
#define NELEMS(x) ( (int)(sizeof(x) / sizeof((x)[0])) )
|
||||
#define NTP_SERVER_LIST ( (char*[]) { \
|
||||
"pool.ntp.org", \
|
||||
"time.nist.gov", \
|
||||
"utcnist.colorado.edu" \
|
||||
} \
|
||||
)
|
||||
/* #define NTP_SERVER_COUNT using NELEMS:
|
||||
*
|
||||
* (int)(sizeof(NTP_SERVER_LIST) / sizeof(NTP_SERVER_LIST[0]))
|
||||
*/
|
||||
#define USE_NTP
|
||||
#define NTP_SERVER_COUNT NELEMS(NTP_SERVER_LIST)
|
||||
char* ntpServerList[NTP_SERVER_COUNT] = NTP_SERVER_LIST;
|
||||
|
||||
/* our NTP server list is global info */
|
||||
extern char* ntpServerList[NTP_SERVER_COUNT];
|
||||
|
||||
/* the worst-case scenario is a hard-coded date/time */
|
||||
int set_fixed_default_time()
|
||||
{
|
||||
time_t interim_time;
|
||||
|
||||
/* ideally, we'd like to set time from network,
|
||||
* but let's set a default time, just in case */
|
||||
struct tm timeinfo = {
|
||||
.tm_year = 2023 - 1900,
|
||||
.tm_mon = 7,
|
||||
.tm_mday = 18,
|
||||
.tm_hour = 9,
|
||||
.tm_min = 49,
|
||||
.tm_sec = 0
|
||||
};
|
||||
struct timeval now;
|
||||
/* set interim static time */
|
||||
interim_time = mktime(&timeinfo);
|
||||
now = (struct timeval){ .tv_sec = interim_time };
|
||||
settimeofday(&now, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* set_time_from_string
|
||||
*
|
||||
* returns 0 = success if able to set the time from the provided string
|
||||
* error for any other value, typically -1 */
|
||||
int set_time_from_string(char* time_buffer)
|
||||
{
|
||||
/* expecting github default formatting: 'Thu Aug 31 12:41:45 2023 -0700' */
|
||||
const char *format = "%3s %3s %d %d:%d:%d %d %s";
|
||||
struct tm this_timeinfo;
|
||||
struct timeval now;
|
||||
time_t interim_time;
|
||||
char day_str[4];
|
||||
char month_str[4];
|
||||
char offset[6]; /* expecting trailing single quote, not used */
|
||||
int day, year, hour, minute, second;
|
||||
int quote_offset = 0;
|
||||
int ret = 0;
|
||||
|
||||
/* we are expecting the string to be encapsulated in single quotes */
|
||||
if (*time_buffer == 0x27) {
|
||||
quote_offset = 1;
|
||||
}
|
||||
|
||||
ret = sscanf(time_buffer + quote_offset,
|
||||
format,
|
||||
day_str, month_str,
|
||||
&day, &hour, &minute, &second, &year, &offset);
|
||||
|
||||
if (ret == 8) {
|
||||
/* we found a match for all componets */
|
||||
|
||||
const char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
|
||||
|
||||
for (int i = 0; i < 12; i++) {
|
||||
if (strcmp(month_str, months[i]) == 0) {
|
||||
this_timeinfo.tm_mon = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this_timeinfo.tm_mday = day;
|
||||
this_timeinfo.tm_hour = hour;
|
||||
this_timeinfo.tm_min = minute;
|
||||
this_timeinfo.tm_sec = second;
|
||||
this_timeinfo.tm_year = year - 1900; /* Number of years since 1900 */
|
||||
|
||||
interim_time = mktime(&this_timeinfo);
|
||||
now = (struct timeval){ .tv_sec = interim_time };
|
||||
settimeofday(&now, NULL);
|
||||
ESP_LOGI(TAG, "Time updated to %s", time_buffer);
|
||||
ret = 0; /* success */
|
||||
}
|
||||
else {
|
||||
ret = -1;
|
||||
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();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* set time; returns 0 if succecssfully confirmed NTP update */
|
||||
int set_time(void)
|
||||
{
|
||||
/* we'll also return a result code of zero */
|
||||
int res = 0;
|
||||
int i = 0; /* counter for time servers */
|
||||
|
||||
#ifdef LIBWOLFSSL_VERSION_GIT_HASH_DATE
|
||||
/* initialy set a default approximate time from recent git commit */
|
||||
ESP_LOGI(TAG, "Found git hash date, attempting to set system date.");
|
||||
set_time_from_string(LIBWOLFSSL_VERSION_GIT_HASH_DATE);
|
||||
|
||||
// return 0;
|
||||
|
||||
res = -4;
|
||||
#else
|
||||
/* otherwise set a fixed time that was hard coded */
|
||||
set_fixed_default_time();
|
||||
restrict = -3;
|
||||
#endif
|
||||
|
||||
#ifndef NTP_SERVER_COUNT
|
||||
ESP_LOGW(TAG, "WArning: no sntp server names defined. Setting to empty list");
|
||||
#define NTP_SERVER_COUNT 0
|
||||
char* ntpServerList[NTP_SERVER_COUNT];
|
||||
#endif /* not defined: NTP_SERVER_COUNT */
|
||||
|
||||
#ifndef TIME_ZONE
|
||||
#define TIME_ZONE "PST-8"
|
||||
#endif /* not defined: TIME_ZONE */
|
||||
|
||||
/* set timezone */
|
||||
setenv("TZ", TIME_ZONE, 1);
|
||||
tzset();
|
||||
|
||||
if (NTP_SERVER_COUNT) {
|
||||
/* next, let's setup NTP time servers
|
||||
*
|
||||
* see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/system_time.html#sntp-time-synchronization
|
||||
*/
|
||||
sntp_setoperatingmode(SNTP_OPMODE_POLL);
|
||||
|
||||
ESP_LOGI(TAG, "sntp_setservername:");
|
||||
for (i = 0; i < NTP_SERVER_COUNT; i++) {
|
||||
const char* thisServer = ntpServerList[i];
|
||||
if (strncmp(thisServer, "\x00", 1) == 0) {
|
||||
/* just in case we run out of NTP servers */
|
||||
break;
|
||||
}
|
||||
ESP_LOGI(TAG, "%s", thisServer);
|
||||
sntp_setservername(i, thisServer);
|
||||
}
|
||||
sntp_init();
|
||||
if (esp_netif_sntp_sync_wait(pdMS_TO_TICKS(200000)) != ESP_OK) {
|
||||
ESP_LOGW(TAG, "Failed to update system time within 10s timeout using NTP.");
|
||||
res = -2;
|
||||
}
|
||||
ESP_LOGI(TAG, "sntp_init done.");
|
||||
}
|
||||
else {
|
||||
ESP_LOGW(TAG, "No sntp time servers found.");
|
||||
res = -1;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
@ -0,0 +1,234 @@
|
|||
/* wifi_connect.c
|
||||
*
|
||||
* Copyright (C) 2006-2023 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
|
||||
*/
|
||||
#include "wifi_connect.h"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include <esp_wifi.h>
|
||||
#include <esp_log.h>
|
||||
|
||||
/* wolfSSL */
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
#include <user_settings.h>
|
||||
#include <wolfssl/version.h>
|
||||
#ifndef WOLFSSL_ESPIDF
|
||||
#warning "problem with wolfSSL user_settings. Check components/wolfssl/include"
|
||||
#endif
|
||||
|
||||
#if ESP_IDF_VERSION_MAJOR >= 5
|
||||
#elif ESP_IDF_VERSION_MAJOR >= 4
|
||||
#include "protocol_examples_common.h"
|
||||
#else
|
||||
const static int CONNECTED_BIT = BIT0;
|
||||
static EventGroupHandle_t wifi_event_group;
|
||||
#endif
|
||||
|
||||
/* breadcrumb prefix for logging */
|
||||
const static char *TAG = "dtls_server";
|
||||
|
||||
#if ESP_IDF_VERSION_MAJOR < 4
|
||||
/* event handler for wifi events */
|
||||
static esp_err_t wifi_event_handler(void *ctx, system_event_t *event)
|
||||
{
|
||||
switch (event->event_id)
|
||||
{
|
||||
case SYSTEM_EVENT_STA_START:
|
||||
esp_wifi_connect();
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_GOT_IP:
|
||||
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||
ESP_LOGI(TAG, "got ip:" IPSTR "\n",
|
||||
IP2STR(&event->event_info.got_ip.ip_info.ip));
|
||||
#else
|
||||
ESP_LOGI(TAG, "got ip:%s",
|
||||
ip4addr_ntoa(&event->event_info.got_ip.ip_info.ip));
|
||||
#endif
|
||||
/* see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/freertos_idf.html */
|
||||
xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_DISCONNECTED:
|
||||
esp_wifi_connect();
|
||||
xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
#else
|
||||
#define EXAMPLE_ESP_WIFI_SSID CONFIG_ESP_WIFI_SSID
|
||||
#define EXAMPLE_ESP_WIFI_PASS CONFIG_ESP_WIFI_PASSWORD
|
||||
|
||||
#ifdef CONFIG_ESP_MAXIMUM_RETRY
|
||||
#define EXAMPLE_ESP_MAXIMUM_RETRY CONFIG_ESP_MAXIMUM_RETRY
|
||||
#else
|
||||
#define CONFIG_ESP_MAXIMUM_RETRY 5
|
||||
#endif
|
||||
|
||||
|
||||
#if CONFIG_ESP_WIFI_AUTH_OPEN
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_OPEN
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WEP
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WEP
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WPA_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA_PSK
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WPA2_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_PSK
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WPA_WPA2_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA_WPA2_PSK
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WPA3_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA3_PSK
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WPA2_WPA3_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_WPA3_PSK
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WAPI_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WAPI_PSK
|
||||
#endif
|
||||
|
||||
#ifndef ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD
|
||||
#define CONFIG_ESP_WIFI_AUTH_WPA2_PSK 1
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD CONFIG_ESP_WIFI_AUTH_WPA2_PSK
|
||||
#endif
|
||||
|
||||
/* FreeRTOS event group to signal when we are connected*/
|
||||
static EventGroupHandle_t s_wifi_event_group;
|
||||
|
||||
/* The event group allows multiple bits for each event, but we only care about two events:
|
||||
* - we are connected to the AP with an IP
|
||||
* - we failed to connect after the maximum amount of retries */
|
||||
#define WIFI_CONNECTED_BIT BIT0
|
||||
#define WIFI_FAIL_BIT BIT1
|
||||
|
||||
|
||||
static int s_retry_num = 0;
|
||||
ip_event_got_ip_t* event;
|
||||
|
||||
|
||||
static void event_handler(void* arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void* event_data)
|
||||
{
|
||||
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
|
||||
esp_wifi_connect();
|
||||
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
|
||||
if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY) {
|
||||
esp_wifi_connect();
|
||||
s_retry_num++;
|
||||
ESP_LOGI(TAG, "retry to connect to the AP");
|
||||
} else {
|
||||
xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT);
|
||||
}
|
||||
ESP_LOGI(TAG,"connect to the AP fail");
|
||||
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
|
||||
event = (ip_event_got_ip_t*) event_data;
|
||||
wifi_show_ip();
|
||||
s_retry_num = 0;
|
||||
xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
|
||||
}
|
||||
}
|
||||
|
||||
int wifi_init_sta(void)
|
||||
{
|
||||
int ret = 0;
|
||||
s_wifi_event_group = xEventGroupCreate();
|
||||
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
esp_netif_create_default_wifi_sta();
|
||||
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
|
||||
esp_event_handler_instance_t instance_any_id;
|
||||
esp_event_handler_instance_t instance_got_ip;
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
|
||||
ESP_EVENT_ANY_ID,
|
||||
&event_handler,
|
||||
NULL,
|
||||
&instance_any_id));
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT,
|
||||
IP_EVENT_STA_GOT_IP,
|
||||
&event_handler,
|
||||
NULL,
|
||||
&instance_got_ip));
|
||||
|
||||
wifi_config_t wifi_config = {
|
||||
.sta = {
|
||||
.ssid = EXAMPLE_ESP_WIFI_SSID,
|
||||
.password = EXAMPLE_ESP_WIFI_PASS,
|
||||
/* Authmode threshold resets to WPA2 as default if password matches
|
||||
* WPA2 standards (pasword len => 8). If you want to connect the
|
||||
* device to deprecated WEP/WPA networks, Please set the threshold
|
||||
* value WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK and set the password with
|
||||
* length and format matching to WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK
|
||||
* standards. */
|
||||
.threshold.authmode = ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD,
|
||||
.sae_pwe_h2e = WPA3_SAE_PWE_BOTH,
|
||||
},
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA) );
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config) );
|
||||
ESP_ERROR_CHECK(esp_wifi_start() );
|
||||
|
||||
ESP_LOGI(TAG, "wifi_init_sta finished.");
|
||||
|
||||
/* Waiting until either the connection is established (WIFI_CONNECTED_BIT)
|
||||
* or connection failed for the maximum number of re-tries (WIFI_FAIL_BIT).
|
||||
* The bits are set by event_handler() (see above) */
|
||||
EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group,
|
||||
WIFI_CONNECTED_BIT | WIFI_FAIL_BIT,
|
||||
pdFALSE,
|
||||
pdFALSE,
|
||||
portMAX_DELAY);
|
||||
|
||||
/* xEventGroupWaitBits() returns the bits before the call returned,
|
||||
* hence we can test which event actually happened. */
|
||||
#if defined(SHOW_SSID_AND_PASSWORD)
|
||||
ESP_LOGW(TAG, "Undefine SHOW_SSID_AND_PASSWORD to not show SSID/password");
|
||||
if (bits & WIFI_CONNECTED_BIT) {
|
||||
ESP_LOGI(TAG, "connected to ap SSID:%s password:%s",
|
||||
EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS);
|
||||
} else if (bits & WIFI_FAIL_BIT) {
|
||||
ESP_LOGI(TAG, "Failed to connect to SSID:%s, password:%s",
|
||||
EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "UNEXPECTED EVENT");
|
||||
}
|
||||
#else
|
||||
if (bits & WIFI_CONNECTED_BIT) {
|
||||
ESP_LOGI(TAG, "Connected to AP");
|
||||
} else if (bits & WIFI_FAIL_BIT) {
|
||||
ESP_LOGI(TAG, "Failed to connect to AP");
|
||||
ret = -1;
|
||||
} else {
|
||||
ESP_LOGE(TAG, "AP UNEXPECTED EVENT");
|
||||
ret = -2;
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wifi_show_ip(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip));
|
||||
return 0;
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,235 @@
|
|||
/* wifi_connect.c
|
||||
*
|
||||
* Copyright (C) 2006-2023 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
|
||||
*/
|
||||
/*ESP specific */
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "wifi_connect.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/netdb.h"
|
||||
#include "lwip/apps/sntp.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
/* wolfSSL */
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
#include <user_settings.h>
|
||||
#include <wolfssl/version.h>
|
||||
#ifndef WOLFSSL_ESPIDF
|
||||
#warning "problem with wolfSSL user_settings. Check components/wolfssl/include"
|
||||
#endif
|
||||
|
||||
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||
// #include "protocol_examples_common.h"
|
||||
#else
|
||||
const static int CONNECTED_BIT = BIT0;
|
||||
static EventGroupHandle_t wifi_event_group;
|
||||
#endif
|
||||
|
||||
/* breadcrumb prefix for logging */
|
||||
const static char *TAG = "tls_client";
|
||||
|
||||
#if ESP_IDF_VERSION_MAJOR < 4
|
||||
/* event handler for wifi events */
|
||||
static esp_err_t wifi_event_handler(void *ctx, system_event_t *event)
|
||||
{
|
||||
switch (event->event_id)
|
||||
{
|
||||
case SYSTEM_EVENT_STA_START:
|
||||
esp_wifi_connect();
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_GOT_IP:
|
||||
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||
ESP_LOGI(TAG, "got ip:" IPSTR "\n",
|
||||
IP2STR(&event->event_info.got_ip.ip_info.ip));
|
||||
#else
|
||||
ESP_LOGI(TAG, "got ip:%s",
|
||||
ip4addr_ntoa(&event->event_info.got_ip.ip_info.ip));
|
||||
#endif
|
||||
/* see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/freertos_idf.html */
|
||||
xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_DISCONNECTED:
|
||||
esp_wifi_connect();
|
||||
xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
#else
|
||||
#define EXAMPLE_ESP_WIFI_SSID CONFIG_ESP_WIFI_SSID
|
||||
#define EXAMPLE_ESP_WIFI_PASS CONFIG_ESP_WIFI_PASSWORD
|
||||
|
||||
#ifdef CONFIG_ESP_MAXIMUM_RETRY
|
||||
#define EXAMPLE_ESP_MAXIMUM_RETRY CONFIG_ESP_MAXIMUM_RETRY
|
||||
#else
|
||||
#define CONFIG_ESP_MAXIMUM_RETRY 5
|
||||
#endif
|
||||
|
||||
|
||||
#if CONFIG_ESP_WIFI_AUTH_OPEN
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_OPEN
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WEP
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WEP
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WPA_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA_PSK
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WPA2_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_PSK
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WPA_WPA2_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA_WPA2_PSK
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WPA3_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA3_PSK
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WPA2_WPA3_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_WPA3_PSK
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WAPI_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WAPI_PSK
|
||||
#endif
|
||||
|
||||
#ifndef ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD
|
||||
#define CONFIG_ESP_WIFI_AUTH_WPA2_PSK 1
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD CONFIG_ESP_WIFI_AUTH_WPA2_PSK
|
||||
#endif
|
||||
|
||||
/* FreeRTOS event group to signal when we are connected*/
|
||||
static EventGroupHandle_t s_wifi_event_group;
|
||||
|
||||
/* The event group allows multiple bits for each event, but we only care about two events:
|
||||
* - we are connected to the AP with an IP
|
||||
* - we failed to connect after the maximum amount of retries */
|
||||
#define WIFI_CONNECTED_BIT BIT0
|
||||
#define WIFI_FAIL_BIT BIT1
|
||||
|
||||
|
||||
static int s_retry_num = 0;
|
||||
ip_event_got_ip_t* event;
|
||||
|
||||
|
||||
static void event_handler(void* arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void* event_data)
|
||||
{
|
||||
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
|
||||
esp_wifi_connect();
|
||||
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
|
||||
if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY) {
|
||||
esp_wifi_connect();
|
||||
s_retry_num++;
|
||||
ESP_LOGI(TAG, "retry to connect to the AP");
|
||||
} else {
|
||||
xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT);
|
||||
}
|
||||
ESP_LOGI(TAG,"connect to the AP fail");
|
||||
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
|
||||
event = (ip_event_got_ip_t*) event_data;
|
||||
wifi_show_ip();
|
||||
s_retry_num = 0;
|
||||
xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
|
||||
}
|
||||
}
|
||||
|
||||
int wifi_init_sta(void)
|
||||
{
|
||||
int ret = 0;
|
||||
s_wifi_event_group = xEventGroupCreate();
|
||||
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
esp_netif_create_default_wifi_sta();
|
||||
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
|
||||
esp_event_handler_instance_t instance_any_id;
|
||||
esp_event_handler_instance_t instance_got_ip;
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
|
||||
ESP_EVENT_ANY_ID,
|
||||
&event_handler,
|
||||
NULL,
|
||||
&instance_any_id));
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT,
|
||||
IP_EVENT_STA_GOT_IP,
|
||||
&event_handler,
|
||||
NULL,
|
||||
&instance_got_ip));
|
||||
|
||||
wifi_config_t wifi_config = {
|
||||
.sta = {
|
||||
.ssid = EXAMPLE_ESP_WIFI_SSID,
|
||||
.password = EXAMPLE_ESP_WIFI_PASS,
|
||||
/* Authmode threshold resets to WPA2 as default if password matches
|
||||
* WPA2 standards (pasword len => 8). If you want to connect the
|
||||
* device to deprecated WEP/WPA networks, Please set the threshold
|
||||
* value WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK and set the password with
|
||||
* length and format matching to WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK
|
||||
* standards. */
|
||||
.threshold.authmode = ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD,
|
||||
.sae_pwe_h2e = WPA3_SAE_PWE_BOTH,
|
||||
},
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA) );
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config) );
|
||||
ESP_ERROR_CHECK(esp_wifi_start() );
|
||||
|
||||
ESP_LOGI(TAG, "wifi_init_sta finished.");
|
||||
|
||||
/* Waiting until either the connection is established (WIFI_CONNECTED_BIT)
|
||||
* or connection failed for the maximum number of re-tries (WIFI_FAIL_BIT).
|
||||
* The bits are set by event_handler() (see above) */
|
||||
EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group,
|
||||
WIFI_CONNECTED_BIT | WIFI_FAIL_BIT,
|
||||
pdFALSE,
|
||||
pdFALSE,
|
||||
portMAX_DELAY);
|
||||
|
||||
/* xEventGroupWaitBits() returns the bits before the call returned,
|
||||
* hence we can test which event actually happened. */
|
||||
#if defined(SHOW_SSID_AND_PASSWORD)
|
||||
ESP_LOGW(TAG, "Undefine SHOW_SSID_AND_PASSWORD to not show SSID/password");
|
||||
if (bits & WIFI_CONNECTED_BIT) {
|
||||
ESP_LOGI(TAG, "connected to ap SSID:%s password:%s",
|
||||
EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS);
|
||||
} else if (bits & WIFI_FAIL_BIT) {
|
||||
ESP_LOGI(TAG, "Failed to connect to SSID:%s, password:%s",
|
||||
EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "UNEXPECTED EVENT");
|
||||
}
|
||||
#else
|
||||
if (bits & WIFI_CONNECTED_BIT) {
|
||||
ESP_LOGI(TAG, "Connected to AP");
|
||||
} else if (bits & WIFI_FAIL_BIT) {
|
||||
ESP_LOGI(TAG, "Failed to connect to AP");
|
||||
ret = -1;
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Connect to AP UNEXPECTED EVENT");
|
||||
ret = -2;
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wifi_show_ip(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip));
|
||||
return 0;
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,31 @@
|
|||
# to view: idf.py partition-table
|
||||
#
|
||||
# ESP-IDF Partition Table
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
nvs, data, nvs, 0x9000, 24K,
|
||||
phy_init,data, phy, 0xf000, 4K,
|
||||
factory, app, factory, 0x10000, 1500K,
|
||||
|
||||
|
||||
# For other settings, see:
|
||||
# https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html#creating-custom-tables
|
||||
#
|
||||
# Here is the summary printed for the “Single factory app, no OTA” configuration:
|
||||
#
|
||||
# # ESP-IDF Partition Table
|
||||
# # Name, Type, SubType, Offset, Size, Flags
|
||||
# nvs, data, nvs, 0x9000, 0x6000,
|
||||
# phy_init, data, phy, 0xf000, 0x1000,
|
||||
# factory, app, factory, 0x10000, 1M,
|
||||
#
|
||||
#
|
||||
# Here is the summary printed for the “Factory app, two OTA definitions” configuration:
|
||||
#
|
||||
# # ESP-IDF Partition Table
|
||||
# # Name, Type, SubType, Offset, Size, Flags
|
||||
# nvs, data, nvs, 0x9000, 0x4000,
|
||||
# otadata, data, ota, 0xd000, 0x2000,
|
||||
# phy_init, data, phy, 0xf000, 0x1000,
|
||||
# factory, app, factory, 0x10000, 1M,
|
||||
# ota_0, app, ota_0, 0x110000, 1M,
|
||||
# ota_1, app, ota_1, 0x210000, 1M,
|
|
|
@ -0,0 +1,34 @@
|
|||
# This tag is used to include this file in the ESP Component Registry:
|
||||
# __ESP_COMPONENT_SOURCE__
|
||||
|
||||
# to view: idf.py partition-table
|
||||
#
|
||||
# ESP-IDF Partition Table
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
nvs, data, nvs, 0x9000, 24K,
|
||||
phy_init,data, phy, 0xf000, 4K,
|
||||
factory, app, factory, 0x10000, 1500K,
|
||||
|
||||
|
||||
# For other settings, see:
|
||||
# https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html#creating-custom-tables
|
||||
#
|
||||
# Here is the summary printed for the “Single factory app, no OTA” configuration:
|
||||
#
|
||||
# # ESP-IDF Partition Table
|
||||
# # Name, Type, SubType, Offset, Size, Flags
|
||||
# nvs, data, nvs, 0x9000, 0x6000,
|
||||
# phy_init, data, phy, 0xf000, 0x1000,
|
||||
# factory, app, factory, 0x10000, 1M,
|
||||
#
|
||||
#
|
||||
# Here is the summary printed for the “Factory app, two OTA definitions” configuration:
|
||||
#
|
||||
# # ESP-IDF Partition Table
|
||||
# # Name, Type, SubType, Offset, Size, Flags
|
||||
# nvs, data, nvs, 0x9000, 0x4000,
|
||||
# otadata, data, ota, 0xd000, 0x2000,
|
||||
# phy_init, data, phy, 0xf000, 0x1000,
|
||||
# factory, app, factory, 0x10000, 1M,
|
||||
# ota_0, app, ota_0, 0x110000, 1M,
|
||||
# ota_1, app, ota_1, 0x210000, 1M,
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,4 @@
|
|||
# This file was generated using idf.py save-defconfig. It can be edited manually.
|
||||
# Espressif IoT Development Framework (ESP-IDF) Project Minimal Configuration
|
||||
#
|
||||
CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE=y
|
|
@ -0,0 +1,50 @@
|
|||
# This file was generated using idf.py save-defconfig. It can be edited manually.
|
||||
# Espressif IoT Development Framework (ESP-IDF) Project Minimal Configuration
|
||||
#
|
||||
CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE=y
|
||||
CONFIG_COMPILER_STACK_CHECK_MODE_ALL=y
|
||||
CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=n
|
||||
CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1=n
|
||||
CONFIG_LWIP_IPV6=n
|
||||
|
||||
CONFIG_FREERTOS_HZ=1000
|
||||
CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y
|
||||
|
||||
#
|
||||
# Default main stack size
|
||||
#
|
||||
# This is typically way bigger than needed for stack size. See user_settings.h
|
||||
#
|
||||
CONFIG_ESP_MAIN_TASK_STACK_SIZE=55500
|
||||
# Legacy stack size for older ESP-IDF versions
|
||||
CONFIG_MAIN_TASK_STACK_SIZE=55500
|
||||
|
||||
#
|
||||
# Compiler options
|
||||
#
|
||||
CONFIG_COMPILER_OPTIMIZATION_DEFAULT=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTION_LEVEL=2
|
||||
CONFIG_COMPILER_HIDE_PATHS_MACROS=y
|
||||
CONFIG_COMPILER_STACK_CHECK_MODE_NORM=y
|
||||
CONFIG_COMPILER_STACK_CHECK=y
|
||||
|
||||
#
|
||||
# Partition Table
|
||||
#
|
||||
# CONFIG_PARTITION_TABLE_SINGLE_APP is not set
|
||||
CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE=y
|
||||
# CONFIG_PARTITION_TABLE_TWO_OTA is not set
|
||||
# CONFIG_PARTITION_TABLE_CUSTOM is not set
|
||||
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
|
||||
CONFIG_PARTITION_TABLE_FILENAME="partitions_singleapp_large.csv"
|
||||
CONFIG_PARTITION_TABLE_OFFSET=0x8000
|
||||
CONFIG_PARTITION_TABLE_MD5=y
|
||||
# end of Partition Table
|
||||
|
||||
|
||||
CONFIG_FREERTOS_HZ=100
|
||||
CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=1
|
||||
CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1=1
|
||||
CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0=CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0
|
||||
CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1=CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1
|
|
@ -0,0 +1,54 @@
|
|||
# The following lines of boilerplate have to be in your project's
|
||||
# CMakeLists in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
# set(WOLFSSL_ROOT "~/workspace/wolfssl-other-source")
|
||||
|
||||
# This tag is used to include this file in the ESP Component Registry:
|
||||
# __ESP_COMPONENT_SOURCE__
|
||||
|
||||
# Optional WOLFSSL_CMAKE_SYSTEM_NAME detection to find
|
||||
# USE_MY_PRIVATE_CONFIG path for my_private_config.h
|
||||
#
|
||||
if(WIN32)
|
||||
# Windows-specific configuration here
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_CMAKE_SYSTEM_NAME_WINDOWS")
|
||||
message("Detected Windows")
|
||||
endif()
|
||||
if(CMAKE_HOST_UNIX)
|
||||
message("Detected UNIX")
|
||||
endif()
|
||||
if(APPLE)
|
||||
message("Detected APPLE")
|
||||
endif()
|
||||
if(CMAKE_HOST_UNIX AND (NOT APPLE) AND EXISTS "/proc/sys/fs/binfmt_misc/WSLInterop")
|
||||
# Windows-specific configuration here
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_CMAKE_SYSTEM_NAME_WSL")
|
||||
message("Detected WSL")
|
||||
endif()
|
||||
if(CMAKE_HOST_UNIX AND (NOT APPLE) AND (NOT WIN32))
|
||||
# Windows-specific configuration here
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_CMAKE_SYSTEM_NAME_LINUX")
|
||||
message("Detected Linux")
|
||||
endif()
|
||||
if(APPLE)
|
||||
# Windows-specific configuration here
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_CMAKE_SYSTEM_NAME_APPLE")
|
||||
message("Detected Apple")
|
||||
endif()
|
||||
# End optional WOLFSSL_CMAKE_SYSTEM_NAME
|
||||
|
||||
# This example uses an extra component for common functions such as Wi-Fi and Ethernet connection.
|
||||
set (PROTOCOL_EXAMPLES_DIR $ENV{IDF_PATH}/examples/common_components/protocol_examples_common)
|
||||
|
||||
if (EXISTS "${PROTOCOL_EXAMPLES_DIR}")
|
||||
message("Found PROTOCOL_EXAMPLES_DIR=${PROTOCOL_EXAMPLES_DIR}")
|
||||
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFOUND_PROTOCOL_EXAMPLES_DIR")
|
||||
else()
|
||||
message("NOT FOUND: PROTOCOL_EXAMPLES_DIR=${PROTOCOL_EXAMPLES_DIR}")
|
||||
endif()
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
|
||||
project(wolfssl_dtls13_server)
|
|
@ -0,0 +1,45 @@
|
|||
# The following lines of boilerplate have to be in your project's
|
||||
# CMakeLists in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
# set(WOLFSSL_ROOT "~/workspace/wolfssl-other-source")
|
||||
# This example uses an extra component for common functions such as Wi-Fi and Ethernet connection.
|
||||
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common)
|
||||
|
||||
# This tag is used to include this file in the ESP Component Registry:
|
||||
# __ESP_COMPONENT_SOURCE__
|
||||
|
||||
# Optional WOLFSSL_CMAKE_SYSTEM_NAME detection to find
|
||||
# USE_MY_PRIVATE_CONFIG path for my_private_config.h
|
||||
#
|
||||
if(WIN32)
|
||||
# Windows-specific configuration here
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_CMAKE_SYSTEM_NAME_WINDOWS")
|
||||
message("Detected Windows")
|
||||
endif()
|
||||
if(CMAKE_HOST_UNIX)
|
||||
message("Detected UNIX")
|
||||
endif()
|
||||
if(APPLE)
|
||||
message("Detected APPLE")
|
||||
endif()
|
||||
if(CMAKE_HOST_UNIX AND (NOT APPLE) AND EXISTS "/proc/sys/fs/binfmt_misc/WSLInterop")
|
||||
# Windows-specific configuration here
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_CMAKE_SYSTEM_NAME_WSL")
|
||||
message("Detected WSL")
|
||||
endif()
|
||||
if(CMAKE_HOST_UNIX AND (NOT APPLE) AND (NOT WIN32))
|
||||
# Windows-specific configuration here
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_CMAKE_SYSTEM_NAME_LINUX")
|
||||
message("Detected Linux")
|
||||
endif()
|
||||
if(APPLE)
|
||||
# Windows-specific configuration here
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_CMAKE_SYSTEM_NAME_APPLE")
|
||||
message("Detected Apple")
|
||||
endif()
|
||||
# End optional WOLFSSL_CMAKE_SYSTEM_NAME
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
|
||||
project(wolfssl_dtls13_server)
|
|
@ -0,0 +1,105 @@
|
|||
# wolfSSL DTLS1.3 Project
|
||||
|
||||
This is an example minimally viable wolfSSL template to get started with your own project.
|
||||
|
||||
### Prerequisites
|
||||
|
||||
It is assumed the [ESP-IDF environment](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/) has been installed.
|
||||
|
||||
```
|
||||
gcc -o client-dtls13 client-dtls13.c -L/mnt/c/workspace/wolfssl-gojimmypi/src/.libs -I/mnt/c/workspace/wolfssl-gojimmypi/ -I/mnt/c/workspace/wolfssl-gojimmypi/include -DWOLFSSL_TLS13 -DWOLFSSL_DTLS -DWOLFSSL_DTLS13 -DWOLFSSL_USER_SETTINGS -lwolfssl -ldl -lm
|
||||
```
|
||||
|
||||
Connect with Linux command line example:
|
||||
|
||||
```bash
|
||||
# assuming wolfssl is in /workspace/wolfssl-$USER
|
||||
cd /mnt/c/workspace/wolfssl-$USER
|
||||
./autogen.sh
|
||||
./configure --enable-dtls --enable-dtls13 --enable-tls13
|
||||
make
|
||||
./examples/dtls13client/client 192.168.1.37
|
||||
```
|
||||
|
||||
```
|
||||
./configure --enable-dtls --enable-dtls13 --enable-tls13 --enable-sm3 --enable-sm4-gcm --enable-sm2
|
||||
make
|
||||
./examples/dtls13client/client 192.168.1.37
|
||||
```
|
||||
|
||||
Testing TLS 1.3 SM:
|
||||
|
||||
```
|
||||
./examples/server/server -v 4 -l TLS13-SM4-GCM-SM3 \
|
||||
-c ./certs/sm2/server-sm2.pem -k ./certs/sm2/server-sm2-priv.pem \
|
||||
-A ./certs/sm2/client-sm2.pem -V &
|
||||
./examples/client/client -v 4 -l TLS13-SM4-GCM-SM3 \
|
||||
-c ./certs/sm2/client-sm2.pem -k ./certs/sm2/client-sm2-priv.pem \
|
||||
-A ./certs/sm2/root-sm2.pem -C
|
||||
```
|
||||
|
||||
|
||||
### Files Included
|
||||
|
||||
- [main.c](./main/main.c) with a simple call to an Espressif library (`ESP_LOGI`) and a call to a wolfSSL library (`esp_ShowExtendedSystemInfo`) .
|
||||
|
||||
- See [components/wolfssl/include](./components/wolfssl/include/user_settings.h) directory to edit the wolfSSL `user_settings.h`.
|
||||
|
||||
- Edit [main/CMakeLists.txt](./main/CMakeLists.txt) to add/remove source files.
|
||||
|
||||
- The [components/wolfssl/CMakeLists.txt](./components/wolfssl/CMakeLists.txt) typically does not need to be changed.
|
||||
|
||||
- Optional [VisualGDB Project](./VisualGDB/wolfssl_template_IDF_v5.1_ESP32.vgdbproj) for Visual Studio using ESP32 and ESP-IDF v5.1.
|
||||
|
||||
- Edit the project [CMakeLists.txt](./CMakeLists.txt) to optionally point this project's wolfSSL component source code at a different directory:
|
||||
|
||||
```
|
||||
set(WOLFSSL_ROOT "~/workspace/wolfssl-other-source")
|
||||
```
|
||||
|
||||
|
||||
## Getting Started:
|
||||
|
||||
Here's an example using the command-line [idf.py](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-py.html).
|
||||
|
||||
Edit your `WRK_IDF_PATH`to point to your ESP-IDF install directory.
|
||||
|
||||
```
|
||||
cd /mnt/C/workspace/wolfssl-gojimmypi/IDE/Espressif/ESP-IDF5/examples/wolfssl_dtls13_server
|
||||
|
||||
WRK_IDF_PATH=/mnt/c/SysGCC/esp32/esp-idf/v5.1
|
||||
|
||||
echo "Run export.sh from ${WRK_IDF_PATH}"
|
||||
. ${WRK_IDF_PATH}/export.sh
|
||||
|
||||
# build the example:
|
||||
idf.py build
|
||||
|
||||
# flash the code onto the serial device at /dev/ttyS19
|
||||
idf.py flash -p /dev/ttyS19 -b 115200
|
||||
|
||||
# build, flash, and view UART output with one command:
|
||||
idf.py flash -p /dev/ttyS19 -b 115200 monitor
|
||||
|
||||
# erase
|
||||
idf.py erase-flash -p /dev/ttyS9 -b 115200
|
||||
|
||||
# save defaults
|
||||
idf.py save-defconfig
|
||||
```
|
||||
|
||||
Press `Ctrl+]` to exit `idf.py monitor`. See [additional monitor keyboard commands](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-monitor.html).
|
||||
|
||||
## Other Examples:
|
||||
|
||||
For examples, see:
|
||||
|
||||
- [TLS Client](../wolfssl_client/README.md)
|
||||
- [TLS Server](../wolfssl_server/README.md)
|
||||
- [Benchmark](../wolfssl_benchmark/README.md)
|
||||
- [Test](../wolfssl_test/README.md)
|
||||
- [wolfssl-examples](https://github.com/wolfSSL/wolfssl-examples/tree/master/ESP32)
|
||||
- [wolfssh-examples](https://github.com/wolfSSL/wolfssh-examples/tree/main/Espressif)
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,269 @@
|
|||
<?xml version="1.0"?>
|
||||
<VisualGDBProjectSettings2 xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<Project xsi:type="com.visualgdb.project.external.esp-idf">
|
||||
<CustomSourceDirectories>
|
||||
<Directories />
|
||||
<PathStyle>Unknown</PathStyle>
|
||||
</CustomSourceDirectories>
|
||||
<AutoProgramSPIFFSPartition>true</AutoProgramSPIFFSPartition>
|
||||
<ProjectModeSettings>
|
||||
<ProjectGUID>7bbd1486-d457-4e49-92ba-0cfc9d80849e</ProjectGUID>
|
||||
<GroupSourcesByTypes>true</GroupSourcesByTypes>
|
||||
<GroupSourcesByPaths>true</GroupSourcesByPaths>
|
||||
<HeaderScanMode>SourceDirs</HeaderScanMode>
|
||||
</ProjectModeSettings>
|
||||
</Project>
|
||||
<Build xsi:type="com.visualgdb.build.cmake">
|
||||
<BuildLogMode xsi:nil="true" />
|
||||
<ToolchainID>
|
||||
<ID>com.visualgdb.xtensa-esp32-elf</ID>
|
||||
<Version>
|
||||
<GCC>12.2.0</GCC>
|
||||
<GDB>12.1</GDB>
|
||||
<Revision>1</Revision>
|
||||
</Version>
|
||||
</ToolchainID>
|
||||
<RelativeSourceDirectory>..</RelativeSourceDirectory>
|
||||
<ConfigurationType>DEBUG</ConfigurationType>
|
||||
<BinaryDirectory>build/$(PlatformName)/$(ConfigurationName)</BinaryDirectory>
|
||||
<MakeCommandTemplate>
|
||||
<SkipWhenRunningCommandList>false</SkipWhenRunningCommandList>
|
||||
<Command>$(ToolchainNinja)</Command>
|
||||
<WorkingDirectory>$(BuildDir)</WorkingDirectory>
|
||||
<BackgroundMode xsi:nil="true" />
|
||||
</MakeCommandTemplate>
|
||||
<CMakeCommand>
|
||||
<SkipWhenRunningCommandList>false</SkipWhenRunningCommandList>
|
||||
<Command>$(SYSPROGS_CMAKE_PATH)</Command>
|
||||
<BackgroundMode xsi:nil="true" />
|
||||
</CMakeCommand>
|
||||
<UpdateSourcesInCMakeFile>true</UpdateSourcesInCMakeFile>
|
||||
<ExportCompileCommands>false</ExportCompileCommands>
|
||||
<DisableToolchainFile>false</DisableToolchainFile>
|
||||
<CMakeMakefileType>Ninja</CMakeMakefileType>
|
||||
<DeployAsRoot>false</DeployAsRoot>
|
||||
<CMakeCleanMode>RemoveBuildDirectory</CMakeCleanMode>
|
||||
<UseCCache>false</UseCCache>
|
||||
<ProjectModeSettings>
|
||||
<ProjectItemSettings>
|
||||
<GroupSourcesByTypes>true</GroupSourcesByTypes>
|
||||
<GroupSourcesByPaths>true</GroupSourcesByPaths>
|
||||
<GroupTargetsByPaths>true</GroupTargetsByPaths>
|
||||
<FollowCMakeSourceGroups>false</FollowCMakeSourceGroups>
|
||||
<AutoRefreshProject>true</AutoRefreshProject>
|
||||
<AlwaysConsiderOutdated>false</AlwaysConsiderOutdated>
|
||||
<SortTargetsByName>true</SortTargetsByName>
|
||||
<RedundantTargetMode>HideOuterProjectTargets</RedundantTargetMode>
|
||||
<SortSourcesByName>true</SortSourcesByName>
|
||||
<BuildAllTargetsInSubdir>false</BuildAllTargetsInSubdir>
|
||||
<FoldSingleItemPathLevels>true</FoldSingleItemPathLevels>
|
||||
</ProjectItemSettings>
|
||||
<TargetSpecificSettings />
|
||||
<SetLDLibraryPathFromDependentArtifacts>true</SetLDLibraryPathFromDependentArtifacts>
|
||||
<ProjectGUID>eadcc9ab-72b3-4b51-a838-593e5d80ddf7</ProjectGUID>
|
||||
<VirtualFolders />
|
||||
<ConfigurationNameCase>Upper</ConfigurationNameCase>
|
||||
<DefaultHeaderDiscoveryMode>HeaderDirectoryAndSubdirectories</DefaultHeaderDiscoveryMode>
|
||||
<EnableFastUpToDateCheck>true</EnableFastUpToDateCheck>
|
||||
<ESPIDFExtension>
|
||||
<IDFCheckout>
|
||||
<Version>release/v5.1</Version>
|
||||
<Subdirectory>esp-idf/v5.1</Subdirectory>
|
||||
<Type>ESPIDF</Type>
|
||||
</IDFCheckout>
|
||||
<COMPort>COM9</COMPort>
|
||||
<SuppressTestPrerequisiteChecks>false</SuppressTestPrerequisiteChecks>
|
||||
<UseCCache>false</UseCCache>
|
||||
<DeviceID>ESP32</DeviceID>
|
||||
</ESPIDFExtension>
|
||||
</ProjectModeSettings>
|
||||
</Build>
|
||||
<CustomBuild>
|
||||
<PreSyncActions />
|
||||
<PreBuildActions />
|
||||
<PostBuildActions />
|
||||
<PreCleanActions />
|
||||
<PostCleanActions />
|
||||
</CustomBuild>
|
||||
<CustomDebug>
|
||||
<PreDebugActions />
|
||||
<PostDebugActions />
|
||||
<DebugStopActions />
|
||||
<BreakMode>Default</BreakMode>
|
||||
</CustomDebug>
|
||||
<DeviceTerminalSettings>
|
||||
<Connection xsi:type="com.sysprogs.terminal.connection.serial">
|
||||
<ComPortName>COM9</ComPortName>
|
||||
<AdvancedSettings>
|
||||
<BaudRate>115200</BaudRate>
|
||||
<DataBits>8</DataBits>
|
||||
<Parity>None</Parity>
|
||||
<StopBits>One</StopBits>
|
||||
<FlowControl>None</FlowControl>
|
||||
</AdvancedSettings>
|
||||
</Connection>
|
||||
<LastConnectionTime>0</LastConnectionTime>
|
||||
<EchoTypedCharacters>false</EchoTypedCharacters>
|
||||
<ClearContentsWhenReconnecting>true</ClearContentsWhenReconnecting>
|
||||
<ReconnectAutomatically>false</ReconnectAutomatically>
|
||||
<DisplayMode>ASCII</DisplayMode>
|
||||
<Colors>
|
||||
<Background>
|
||||
<Alpha>255</Alpha>
|
||||
<Red>0</Red>
|
||||
<Green>0</Green>
|
||||
<Blue>0</Blue>
|
||||
</Background>
|
||||
<Disconnected>
|
||||
<Alpha>255</Alpha>
|
||||
<Red>169</Red>
|
||||
<Green>169</Green>
|
||||
<Blue>169</Blue>
|
||||
</Disconnected>
|
||||
<Text>
|
||||
<Alpha>255</Alpha>
|
||||
<Red>211</Red>
|
||||
<Green>211</Green>
|
||||
<Blue>211</Blue>
|
||||
</Text>
|
||||
<Echo>
|
||||
<Alpha>255</Alpha>
|
||||
<Red>144</Red>
|
||||
<Green>238</Green>
|
||||
<Blue>144</Blue>
|
||||
</Echo>
|
||||
<Inactive>
|
||||
<Alpha>255</Alpha>
|
||||
<Red>169</Red>
|
||||
<Green>169</Green>
|
||||
<Blue>169</Blue>
|
||||
</Inactive>
|
||||
</Colors>
|
||||
<HexSettings>
|
||||
<MaximumBytesPerLine>16</MaximumBytesPerLine>
|
||||
<ShowTextView>true</ShowTextView>
|
||||
<BreaksAroundEcho>true</BreaksAroundEcho>
|
||||
<AutoSend>true</AutoSend>
|
||||
<SendAsHex>true</SendAsHex>
|
||||
<TimeoutForAutoBreak>0</TimeoutForAutoBreak>
|
||||
</HexSettings>
|
||||
<LineEnding>LF</LineEnding>
|
||||
<TreatLFAsCRLF>false</TreatLFAsCRLF>
|
||||
<KeepOpenAfterExit>false</KeepOpenAfterExit>
|
||||
<ShowAfterProgramming>false</ShowAfterProgramming>
|
||||
</DeviceTerminalSettings>
|
||||
<CustomShortcuts>
|
||||
<Shortcuts />
|
||||
<ShowMessageAfterExecuting>true</ShowMessageAfterExecuting>
|
||||
</CustomShortcuts>
|
||||
<UserDefinedVariables />
|
||||
<ImportedPropertySheets />
|
||||
<CodeSense>
|
||||
<Enabled>Unknown</Enabled>
|
||||
<ExtraSettings>
|
||||
<HideErrorsInSystemHeaders>true</HideErrorsInSystemHeaders>
|
||||
<SupportLightweightReferenceAnalysis>true</SupportLightweightReferenceAnalysis>
|
||||
<CheckForClangFormatFiles>true</CheckForClangFormatFiles>
|
||||
<FormattingEngine xsi:nil="true" />
|
||||
</ExtraSettings>
|
||||
<CodeAnalyzerSettings>
|
||||
<Enabled>false</Enabled>
|
||||
</CodeAnalyzerSettings>
|
||||
</CodeSense>
|
||||
<Configurations>
|
||||
<VisualGDBConfiguration>
|
||||
<Name>Debug</Name>
|
||||
<BuildSettingsExtension xsi:type="com.visualgdb.build.external.esp-idf.cmake.extension" />
|
||||
</VisualGDBConfiguration>
|
||||
<VisualGDBConfiguration>
|
||||
<Name>Release</Name>
|
||||
<BuildSettingsExtension xsi:type="com.visualgdb.build.external.esp-idf.cmake.extension" />
|
||||
</VisualGDBConfiguration>
|
||||
</Configurations>
|
||||
<ProgramArgumentsSuggestions />
|
||||
<Debug xsi:type="com.visualgdb.debug.embedded">
|
||||
<AdditionalStartupCommands />
|
||||
<AdditionalGDBSettings>
|
||||
<Features>
|
||||
<DisableAutoDetection>false</DisableAutoDetection>
|
||||
<UseFrameParameter>false</UseFrameParameter>
|
||||
<SimpleValuesFlagSupported>false</SimpleValuesFlagSupported>
|
||||
<ListLocalsSupported>false</ListLocalsSupported>
|
||||
<ByteLevelMemoryCommandsAvailable>false</ByteLevelMemoryCommandsAvailable>
|
||||
<ThreadInfoSupported>false</ThreadInfoSupported>
|
||||
<PendingBreakpointsSupported>false</PendingBreakpointsSupported>
|
||||
<SupportTargetCommand>false</SupportTargetCommand>
|
||||
<ReliableBreakpointNotifications>false</ReliableBreakpointNotifications>
|
||||
</Features>
|
||||
<EnableSmartStepping>false</EnableSmartStepping>
|
||||
<FilterSpuriousStoppedNotifications>false</FilterSpuriousStoppedNotifications>
|
||||
<ForceSingleThreadedMode>false</ForceSingleThreadedMode>
|
||||
<UseAppleExtensions>false</UseAppleExtensions>
|
||||
<CanAcceptCommandsWhileRunning>false</CanAcceptCommandsWhileRunning>
|
||||
<MakeLogFile>false</MakeLogFile>
|
||||
<IgnoreModuleEventsWhileStepping>true</IgnoreModuleEventsWhileStepping>
|
||||
<UseRelativePathsOnly>false</UseRelativePathsOnly>
|
||||
<ExitAction>None</ExitAction>
|
||||
<DisableDisassembly>false</DisableDisassembly>
|
||||
<ExamineMemoryWithXCommand>false</ExamineMemoryWithXCommand>
|
||||
<StepIntoNewInstanceEntry>app_main</StepIntoNewInstanceEntry>
|
||||
<ExamineRegistersInRawFormat>true</ExamineRegistersInRawFormat>
|
||||
<DisableSignals>false</DisableSignals>
|
||||
<EnableAsyncExecutionMode>false</EnableAsyncExecutionMode>
|
||||
<AsyncModeSupportsBreakpoints>true</AsyncModeSupportsBreakpoints>
|
||||
<TemporaryBreakConsolidationTimeout>0</TemporaryBreakConsolidationTimeout>
|
||||
<EnableNonStopMode>false</EnableNonStopMode>
|
||||
<MaxBreakpointLimit>0</MaxBreakpointLimit>
|
||||
<EnableVerboseMode>true</EnableVerboseMode>
|
||||
<EnablePrettyPrinters>false</EnablePrettyPrinters>
|
||||
</AdditionalGDBSettings>
|
||||
<DebugMethod>
|
||||
<ID>openocd</ID>
|
||||
<Configuration xsi:type="com.visualgdb.edp.openocd.settings.esp32">
|
||||
<CommandLine>-f interface/ftdi/tigard.cfg -c "adapter_khz 13000" -f target/esp32.cfg</CommandLine>
|
||||
<ExtraParameters>
|
||||
<Frequency xsi:nil="true" />
|
||||
<BoostedFrequency xsi:nil="true" />
|
||||
<ConnectUnderReset>false</ConnectUnderReset>
|
||||
</ExtraParameters>
|
||||
<LoadProgressGUIThreshold>131072</LoadProgressGUIThreshold>
|
||||
<ProgramMode>Enabled</ProgramMode>
|
||||
<StartupCommands>
|
||||
<string>set remotetimeout 60</string>
|
||||
<string>target remote :$$SYS:GDB_PORT$$</string>
|
||||
<string>mon gdb_breakpoint_override hard</string>
|
||||
<string>mon reset halt</string>
|
||||
<string>load</string>
|
||||
</StartupCommands>
|
||||
<ProgramFLASHUsingExternalTool>false</ProgramFLASHUsingExternalTool>
|
||||
<PreferredGDBPort>0</PreferredGDBPort>
|
||||
<PreferredTelnetPort>0</PreferredTelnetPort>
|
||||
<AlwaysPassSerialNumber>false</AlwaysPassSerialNumber>
|
||||
<SelectedCoreIndex xsi:nil="true" />
|
||||
<LiveMemoryTimeout>5000</LiveMemoryTimeout>
|
||||
<SuggestionLogicRevision>1</SuggestionLogicRevision>
|
||||
<CheckFLASHSize>true</CheckFLASHSize>
|
||||
<FLASHSettings>
|
||||
<Size>size2MB</Size>
|
||||
<Frequency>freq40M</Frequency>
|
||||
<Mode>DIO</Mode>
|
||||
</FLASHSettings>
|
||||
<PatchBootloader>true</PatchBootloader>
|
||||
</Configuration>
|
||||
</DebugMethod>
|
||||
<AutoDetectRTOS>true</AutoDetectRTOS>
|
||||
<SemihostingSupport>Disabled</SemihostingSupport>
|
||||
<SemihostingPollingDelay>0</SemihostingPollingDelay>
|
||||
<StepIntoEntryPoint>false</StepIntoEntryPoint>
|
||||
<ReloadFirmwareOnReset>false</ReloadFirmwareOnReset>
|
||||
<ValidateEndOfStackAddress>true</ValidateEndOfStackAddress>
|
||||
<StopAtEntryPoint>false</StopAtEntryPoint>
|
||||
<EnableVirtualHalts>false</EnableVirtualHalts>
|
||||
<DynamicAnalysisSettings />
|
||||
<EndOfStackSymbol>_estack</EndOfStackSymbol>
|
||||
<TimestampProviderTicksPerSecond>0</TimestampProviderTicksPerSecond>
|
||||
<KeepConsoleAfterExit>false</KeepConsoleAfterExit>
|
||||
<UnusedStackFillPattern xsi:nil="true" />
|
||||
<CheckInterfaceDrivers>true</CheckInterfaceDrivers>
|
||||
</Debug>
|
||||
</VisualGDBProjectSettings2>
|
|
@ -0,0 +1,516 @@
|
|||
#
|
||||
# Copyright (C) 2006-2023 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
|
||||
#
|
||||
# cmake for wolfssl Espressif projects
|
||||
#
|
||||
# See https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/build-system.html
|
||||
#
|
||||
|
||||
# allows /include/user_settings.h (ignores it).
|
||||
# user_settings.h file to use must be in [project]/components/wolfssl/include
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_USER_SETTINGS")
|
||||
set(CMAKE_CURRENT_SOURCE_DIR ".")
|
||||
set(COMPONENT_REQUIRES lwip) # we typically don't need lwip directly in wolfssl component
|
||||
set(WOLFCRYPT_PATH "wolfssl/wolfcrypt") # breadcrumb path to detect if we've found wolfssl
|
||||
|
||||
# find the user name to search for possible "wolfssl-username"
|
||||
if( "$ENV{USER}" STREQUAL "" ) # the bash user
|
||||
if( "$ENV{USERNAME}" STREQUAL "" ) # the Windows user
|
||||
message(STATUS "Could not find USER or USERNAME.")
|
||||
else()
|
||||
# the bash user is not blank, so we'll use it.
|
||||
set(THIS_USER "$ENV{USERNAME}")
|
||||
endif()
|
||||
else()
|
||||
# the bash user is not blank, so we'll use it.
|
||||
set(THIS_USER "$ENV{USER}")
|
||||
endif()
|
||||
message(STATUS "THIS_USER = ${THIS_USER}")
|
||||
|
||||
# COMPONENT_NAME = wolfssl
|
||||
# The component name is the directory name. "No feature to change this".
|
||||
# See https://github.com/espressif/esp-idf/issues/8978#issuecomment-1129892685
|
||||
|
||||
# set the root of wolfSSL in top-level project CMakelists.txt:
|
||||
# set(WOLFSSL_ROOT "C:/some path/with/spaces")
|
||||
# set(WOLFSSL_ROOT "c:/workspace/wolfssl-[username]")
|
||||
# set(WOLFSSL_ROOT "/mnt/c/some path/with/spaces")
|
||||
# or use this logic to assign value from Environment Variable WOLFSSL_ROOT,
|
||||
# or assume this is an example 7 subdirectories below:
|
||||
|
||||
# We are typically in [root]/IDE/Espressif/ESP-IDF/examples/wolfssl_test/components/wolfssl
|
||||
# The root of wolfSSL is 7 directories up from here:
|
||||
|
||||
if(CMAKE_BUILD_EARLY_EXPANSION)
|
||||
message(STATUS "wolfssl component CMAKE_BUILD_EARLY_EXPANSION:")
|
||||
idf_component_register(
|
||||
REQUIRES "${COMPONENT_REQUIRES}"
|
||||
PRIV_REQUIRES esp_timer driver # this will typically only be needed for wolfSSL benchmark
|
||||
)
|
||||
|
||||
else()
|
||||
# not CMAKE_BUILD_EARLY_EXPANSION
|
||||
message(STATUS "************************************************************************************************")
|
||||
message(STATUS "wolfssl component config:")
|
||||
message(STATUS "************************************************************************************************")
|
||||
|
||||
# Check to see if we're already in wolfssl, and only if WOLFSSL_ROOT not specified
|
||||
if ("${WOLFSSL_ROOT}" STREQUAL "")
|
||||
# wolfssl examples are 7 directories deep from wolfssl repo root
|
||||
# 1 2 3 4 5 6 7
|
||||
set(THIS_RELATIVE_PATH "../../../../../../..")
|
||||
get_filename_component(THIS_SEARCH_PATH "${THIS_RELATIVE_PATH}" ABSOLUTE)
|
||||
message(STATUS "Searching in path = ${THIS_SEARCH_PATH}")
|
||||
|
||||
if (EXISTS "${THIS_SEARCH_PATH}/${WOLFCRYPT_PATH}")
|
||||
# we're already in wolfssl examples!
|
||||
get_filename_component(WOLFSSL_ROOT "${THIS_SEARCH_PATH}" ABSOLUTE)
|
||||
message(STATUS "Using wolfSSL example with root ${WOLFSSL_ROOT}")
|
||||
else()
|
||||
# We're in some other repo such as wolfssh, so we'll search for an
|
||||
# adjacent-level directory for wolfssl. (8 directories up, then down one)
|
||||
#
|
||||
# For example wolfSSL examples:
|
||||
# C:\workspace\wolfssl-gojimmypi\IDE\Espressif\ESP-IDF\examples\wolfssl_benchmark\components\wolfssl
|
||||
#
|
||||
# For example wolfSSH examples:
|
||||
# C:\workspace\wolfssh-gojimmypi\ide\Espressif\ESP-IDF\examples\wolfssh_benchmark\components\wolfssl
|
||||
#
|
||||
# 1 2 3 4 5 6 7 8
|
||||
set(THIS_RELATIVE_PATH "../../../../../../../..")
|
||||
get_filename_component(THIS_SEARCH_PATH "${THIS_RELATIVE_PATH}" ABSOLUTE)
|
||||
message(STATUS "Searching next in path = ${THIS_SEARCH_PATH}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# search other possible locations
|
||||
if ("${WOLFSSL_ROOT}" STREQUAL "")
|
||||
# there's not a hard-coded WOLFSSL_ROOT value above, so let's see if we can find it.
|
||||
if( "$ENV{WOLFSSL_ROOT}" STREQUAL "" )
|
||||
message(STATUS "Environment Variable WOLFSSL_ROOT not set. Will search common locations.")
|
||||
|
||||
message(STATUS "CMAKE_CURRENT_SOURCE_DIR = ${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
get_filename_component(THIS_DIR "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE)
|
||||
message(STATUS "THIS_DIR = ${THIS_DIR}")
|
||||
|
||||
# This same makefile is used for both the wolfssl component, and other
|
||||
# components that may depend on wolfssl, such as wolfssh. Therefore
|
||||
# we need to determine if this makefile is in the wolfssl repo, or
|
||||
# some other repo.
|
||||
|
||||
if( "{THIS_USER}" STREQUAL "" )
|
||||
# This is highly unusual to not find a user name.
|
||||
# In this case, we'll just search for a "wolfssl" directory:
|
||||
message(STATUS "No username found!")
|
||||
get_filename_component(WOLFSSL_ROOT "${THIS_RELATIVE_PATH}/wolfssl" ABSOLUTE)
|
||||
else()
|
||||
# We found an environment USER name!
|
||||
# The first place to look for wolfssl will be in a user-clone called "wolfssl-[username]"
|
||||
message(STATUS "Using [THIS_USER = ${THIS_USER}] to see if there's a [relative path]/wolfssl-${THIS_USER} directory.")
|
||||
get_filename_component(WOLFSSL_ROOT "${THIS_RELATIVE_PATH}/wolfssl-${THIS_USER}" ABSOLUTE)
|
||||
|
||||
if( EXISTS "${WOLFSSL_ROOT}/${WOLFCRYPT_PATH}" )
|
||||
message(STATUS "Found wolfssl in user-suffix ${WOLFSSL_ROOT}")
|
||||
else()
|
||||
# If there's not a user-clone called "wolfssl-[username]",
|
||||
# perhaps there's simply a git clone called "wolfssl"?
|
||||
message(STATUS "Did not find wolfssl in ${WOLFSSL_ROOT}; continuing search...")
|
||||
get_filename_component(WOLFSSL_ROOT "${THIS_RELATIVE_PATH}/wolfssl" ABSOLUTE)
|
||||
|
||||
if( EXISTS "${WOLFSSL_ROOT}" )
|
||||
message(STATUS "Found wolfssl in standard ${WOLFSSL_ROOT}")
|
||||
else()
|
||||
# Things are looking pretty bleak. We'll likely not be able to compile.
|
||||
message(STATUS "Did not find wolfssl in ${WOLFSSL_ROOT}")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
else()
|
||||
# there's an environment variable, so use it.
|
||||
set(WOLFSSL_ROOT "$ENV{WOLFSSL_ROOT}")
|
||||
|
||||
if( EXISTS "${WOLFSSL_ROOT}/${WOLFCRYPT_PATH}" )
|
||||
get_filename_component(WOLFSSL_ROOT "$ENV{WOLFSSL_ROOT}" ABSOLUTE)
|
||||
message(STATUS "Found WOLFSSL_ROOT via Environment Variable: ${WOLFSSL_ROOT}")
|
||||
else()
|
||||
# message(FATAL_ERROR "WOLFSSL_ROOT Environment Variable defined, but path not found:")
|
||||
message(STATUS "$ENV{WOLFSSL_ROOT} not found or does not contain ${WOLFCRYPT_PATH}")
|
||||
endif()
|
||||
endif()
|
||||
# end of search for wolfssl component root
|
||||
else()
|
||||
# There's already a value assigned; we won't search for anything else.
|
||||
message(STATUS "Found user-specified WOLFSSL_ROOT value.")
|
||||
endif() # WOLFSSL_ROOT user defined
|
||||
|
||||
# After all the logic above, does our WOLFSSL_ROOT actually exist?
|
||||
if( EXISTS "${WOLFSSL_ROOT}/${WOLFCRYPT_PATH}" )
|
||||
message(STATUS "WOLFSSL_ROOT = ${WOLFSSL_ROOT}")
|
||||
else()
|
||||
# Perhaps we are in wolfssl-examples, 4 directories down from parallel wolfssl?
|
||||
# First, we'll see if we can find wolfssl in the wolfssl-[username] repo
|
||||
# 1 2 3 4 |- parallel parent
|
||||
set(NEXT_RELATIVE_PATH "../../../../../wolfssl-${THIS_USER}")
|
||||
get_filename_component(THIS_SEARCH_PATH "${NEXT_RELATIVE_PATH}" ABSOLUTE)
|
||||
message(STATUS "Searching for wolfssl in path: ${THIS_SEARCH_PATH}")
|
||||
if(EXISTS "${THIS_SEARCH_PATH}/${WOLFCRYPT_PATH}" )
|
||||
set(WOLFSSL_ROOT "${THIS_SEARCH_PATH}")
|
||||
message(STATUS "Found wolfssl in user suffix directory: ${WOLFSSL_ROOT}")
|
||||
else()
|
||||
# next, let's see if there's jsut a simple clone of wolfssl in the same parent directory
|
||||
set(NEXT_RELATIVE_PATH "../../../../../wolfssl")
|
||||
get_filename_component(THIS_SEARCH_PATH "${NEXT_RELATIVE_PATH}" ABSOLUTE)
|
||||
message(STATUS "Searching wolfssl-examples for path = ${THIS_SEARCH_PATH}")
|
||||
if( EXISTS "${THIS_SEARCH_PATH}/${WOLFCRYPT_PATH}" )
|
||||
set(WOLFSSL_ROOT "${THIS_SEARCH_PATH}")
|
||||
message(STATUS "Found wolfssl in same parent directory: ${WOLFSSL_ROOT}")
|
||||
else()
|
||||
message(STATUS "unable to find wolfssl.")
|
||||
message(STATUS "---- Try setting the WOLFSSL_ROOT environment variable")
|
||||
message(STATUS "---- Or set WOLFSSL_ROOT in the CMakeFile.txt")
|
||||
set(WOLFSSL_ROOT "../wolfssl")
|
||||
# Abort. We need wolfssl _somewhere_.
|
||||
message(FATAL_ERROR "Could not find wolfssl in ${WOLFSSL_ROOT}. Try setting environment variable or git clone.")
|
||||
endif() # checking [workspace]/wolfssl
|
||||
endif() # chcking [workspace]/wolfssl-[username]
|
||||
endif() # alternate check if in wolfssl-examples
|
||||
|
||||
|
||||
set(INCLUDE_PATH ${WOLFSSL_ROOT})
|
||||
|
||||
set(COMPONENT_SRCDIRS "\"${WOLFSSL_ROOT}/src/\""
|
||||
"\"${WOLFSSL_ROOT}/wolfcrypt/src\""
|
||||
"\"${WOLFSSL_ROOT}/wolfcrypt/src/port/Espressif\""
|
||||
"\"${WOLFSSL_ROOT}/wolfcrypt/src/port/atmel\""
|
||||
# "\"${WOLFSSL_ROOT}/wolfcrypt/benchmark\"" # the benchmark application
|
||||
# "\"${WOLFSSL_ROOT}/wolfcrypt/test\"" # the test application
|
||||
) # COMPONENT_SRCDIRS
|
||||
message(STATUS "This COMPONENT_SRCDIRS = ${COMPONENT_SRCDIRS}")
|
||||
|
||||
set(WOLFSSL_PROJECT_DIR "${CMAKE_HOME_DIRECTORY}/components/wolfssl")
|
||||
|
||||
# Espressif may take several passes through this makefile. Check to see if we found IDF
|
||||
string(COMPARE EQUAL "${PROJECT_SOURCE_DIR}" "" WOLFSSL_FOUND_IDF)
|
||||
|
||||
# get a list of all wolfcrypt assembly files; we'll exclude them as they don't target Xtensa
|
||||
file(GLOB EXCLUDE_ASM *.S)
|
||||
file(GLOB_RECURSE EXCLUDE_ASM ${CMAKE_SOURCE_DIR} "${WOLFSSL_ROOT}/wolfcrypt/src/*.S")
|
||||
|
||||
message(STATUS "IDF_PATH = $ENV{IDF_PATH}")
|
||||
message(STATUS "PROJECT_SOURCE_DIR = ${PROJECT_SOURCE_DIR}")
|
||||
message(STATUS "EXCLUDE_ASM = ${EXCLUDE_ASM}")
|
||||
|
||||
#
|
||||
# Check to see if there's both a local copy and EDP-IDF copy of the wolfssl and/or wolfssh components.
|
||||
#
|
||||
if( EXISTS "${WOLFSSL_PROJECT_DIR}" AND EXISTS "$ENV{IDF_PATH}/components/wolfssl/" )
|
||||
#
|
||||
# wolfSSL found in both ESP-IDF and local project - needs to be resolved by user
|
||||
#
|
||||
message(STATUS "")
|
||||
message(STATUS "**************************************************************************************")
|
||||
message(STATUS "")
|
||||
message(STATUS "Error: Found components/wolfssl in both local project and IDF_PATH")
|
||||
message(STATUS "")
|
||||
message(STATUS "To proceed: ")
|
||||
message(STATUS "")
|
||||
message(STATUS "Remove either the local project component: ${WOLFSSL_PROJECT_DIR} ")
|
||||
message(STATUS "or the Espressif shared component installed at: $ENV{IDF_PATH}/components/wolfssl/ ")
|
||||
message(STATUS "")
|
||||
message(FATAL_ERROR "Please use wolfSSL in either local project or Espressif components, but not both.")
|
||||
message(STATUS "")
|
||||
message(STATUS "**************************************************************************************")
|
||||
message(STATUS "")
|
||||
|
||||
# Optional: if you change the above FATAL_ERROR to STATUS you can warn at runtime with this macro definition:
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_MULTI_INSTALL_WARNING")
|
||||
|
||||
else()
|
||||
if( EXISTS "$ENV{IDF_PATH}/components/wolfssl/" )
|
||||
#
|
||||
# wolfSSL found in ESP-IDF components and is assumed to be already configured in user_settings.h via setup.
|
||||
#
|
||||
message(STATUS "")
|
||||
message(STATUS "Using components/wolfssl in IDF_PATH = $ENV{IDF_PATH}")
|
||||
message(STATUS "")
|
||||
else()
|
||||
#
|
||||
# wolfSSL is not an ESP-IDF component.
|
||||
# We need to now determine if it is local and if so if it is part of the wolfSSL repo,
|
||||
# or if wolfSSL is simply installed as a local component.
|
||||
#
|
||||
|
||||
if( EXISTS "${WOLFSSL_PROJECT_DIR}" )
|
||||
#
|
||||
# wolfSSL found in local project.
|
||||
#
|
||||
if( EXISTS "${WOLFSSL_PROJECT_DIR}/wolfcrypt/" )
|
||||
message(STATUS "")
|
||||
message(STATUS "Using installed project ./components/wolfssl in CMAKE_HOME_DIRECTORY = ${CMAKE_HOME_DIRECTORY}")
|
||||
message(STATUS "")
|
||||
#
|
||||
# Note we already checked above and confirmed there's not another wolfSSL installed in the ESP-IDF components.
|
||||
#
|
||||
# We won't do anything else here, as it will be assumed the original install completed successfully.
|
||||
#
|
||||
else() # full wolfSSL not installed in local project
|
||||
#
|
||||
# This is the developer repo mode. wolfSSL will be assumed to be not installed to ESP-IDF nor local project
|
||||
# In this configuration, we are likely running a wolfSSL example found directly in the repo.
|
||||
#
|
||||
message(STATUS "")
|
||||
message(STATUS "Using developer repo ./components/wolfssl in CMAKE_HOME_DIRECTORY = ${CMAKE_HOME_DIRECTORY}")
|
||||
message(STATUS "")
|
||||
|
||||
message(STATUS "************************************************************************************************")
|
||||
# When in developer mode, we are typically running wolfSSL examples such as benchmark or test directories.
|
||||
# However, the as-cloned or distributed wolfSSL does not have the ./include/ directory, so we'll add it as needed.
|
||||
#
|
||||
# first check if there's a [root]/include/user_settings.h
|
||||
if( EXISTS "${WOLFSSL_ROOT}/include/user_settings.h" )
|
||||
message(STATUS "Found wolfSSL EXCLUDED user_settings.h in "
|
||||
"${WOLFSSL_ROOT}/include/user_settings.h "
|
||||
" (using ${WOLFSSL_PROJECT_DIR}/include/user_settings.h )")
|
||||
else()
|
||||
# we won't overwrite an existing user settings file, just note that we already have one:
|
||||
if( EXISTS "${WOLFSSL_PROJECT_DIR}/include/user_settings.h" )
|
||||
message(STATUS "Using existing wolfSSL user_settings.h in "
|
||||
"${WOLFSSL_PROJECT_DIR}/include/user_settings.h")
|
||||
else()
|
||||
message(STATUS "Installing wolfSSL user_settings.h to "
|
||||
"${WOLFSSL_PROJECT_DIR}/include/user_settings.h")
|
||||
file(COPY "${WOLFSSL_ROOT}/IDE/Espressif/ESP-IDF/user_settings.h"
|
||||
DESTINATION "${CMAKE_HOME_DIRECTORY}/wolfssl/include/")
|
||||
endif()
|
||||
endif() # user_settings.h
|
||||
|
||||
# next check if there's a [root]/include/config.h
|
||||
if( EXISTS "${WOLFSSL_ROOT}/include/config.h" )
|
||||
# message(FATAL_ERROR "Found stray wolfSSL config.h in ${WOLFSSL_ROOT}/include/config.h (please move it to ${WOLFSSL_PROJECT_DIR}/include/config.h")
|
||||
else()
|
||||
# we won't overwrite an existing user settings file, just note that we already have one:
|
||||
if( EXISTS "${WOLFSSL_PROJECT_DIR}/include/config.h" )
|
||||
message(STATUS "Using existing wolfSSL config.h ${WOLFSSL_PROJECT_DIR}/include/config.h")
|
||||
else()
|
||||
message(STATUS "Installing wolfSSL config.h to ${WOLFSSL_PROJECT_DIR}/include/config.h")
|
||||
file(COPY "${WOLFSSL_ROOT}/IDE/Espressif/ESP-IDF/dummy_config_h" DESTINATION "${WOLFSSL_PROJECT_DIR}/include/")
|
||||
file(RENAME "${WOLFSSL_PROJECT_DIR}/include/dummy_config_h" "${WOLFSSL_PROJECT_DIR}/include/config.h")
|
||||
endif() # Project config.h
|
||||
endif() # WOLFSSL_ROOT config.h
|
||||
message(STATUS "************************************************************************************************")
|
||||
message(STATUS "")
|
||||
endif()
|
||||
|
||||
else()
|
||||
# we did not find a ./components/wolfssl/include/ directory from this pass of cmake.
|
||||
if($WOLFSSL_FOUND_IDF)
|
||||
message(STATUS "")
|
||||
message(STATUS "WARNING: wolfSSL not found.")
|
||||
message(STATUS "")
|
||||
else()
|
||||
# probably needs to be re-parsed by Espressif
|
||||
message(STATUS "wolfSSL found IDF. Project Source:${PROJECT_SOURCE_DIR}")
|
||||
endif() # else we have not found ESP-IDF yet
|
||||
endif() # else not a local wolfSSL component
|
||||
|
||||
endif() #else not an ESP-IDF component
|
||||
endif() # else not local copy and EDP-IDF wolfSSL
|
||||
|
||||
|
||||
# RTOS_IDF_PATH is typically:
|
||||
# "/Users/{username}/Desktop/esp-idf/components/freertos/include/freertos"
|
||||
# depending on the environment, we may need to swap backslashes with forward slashes
|
||||
string(REPLACE "\\" "/" RTOS_IDF_PATH "$ENV{IDF_PATH}/components/freertos/FreeRTOS-Kernel/include/freertos")
|
||||
|
||||
string(REPLACE "\\" "/" WOLFSSL_ROOT ${WOLFSSL_ROOT})
|
||||
|
||||
if(IS_DIRECTORY "${RTOS_IDF_PATH}")
|
||||
message(STATUS "Found current RTOS path: ${RTOS_IDF_PATH}")
|
||||
else()
|
||||
# ESP-IDF prior version 4.4x has a different RTOS directory structure
|
||||
string(REPLACE "\\" "/" RTOS_IDF_PATH "$ENV{IDF_PATH}/components/freertos/include/freertos")
|
||||
if(IS_DIRECTORY "${RTOS_IDF_PATH}")
|
||||
message(STATUS "Found legacy RTOS path: ${RTOS_IDF_PATH}")
|
||||
else()
|
||||
message(STATUS "Could not find RTOS path")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
set(COMPONENT_ADD_INCLUDEDIRS
|
||||
"./include" # this is the location of wolfssl user_settings.h
|
||||
"\"${WOLFSSL_ROOT}/\""
|
||||
"\"${WOLFSSL_ROOT}/wolfssl/\""
|
||||
"\"${WOLFSSL_ROOT}/wolfssl/wolfcrypt/\""
|
||||
"\"${RTOS_IDF_PATH}/\""
|
||||
)
|
||||
|
||||
|
||||
if(IS_DIRECTORY ${IDF_PATH}/components/cryptoauthlib)
|
||||
list(APPEND COMPONENT_ADD_INCLUDEDIRS "../cryptoauthlib/lib")
|
||||
endif()
|
||||
|
||||
list(APPEND COMPONENT_ADD_INCLUDEDIRS "\"${WOLFSSL_ROOT}/wolfssl/\"")
|
||||
list(APPEND COMPONENT_ADD_INCLUDEDIRS "\"${WOLFSSL_ROOT}/wolfssl/wolfcrypt/\"")
|
||||
|
||||
|
||||
|
||||
set(COMPONENT_SRCEXCLUDE
|
||||
"\"${WOLFSSL_ROOT}/include/user_settings.h\"" # use local file only
|
||||
"\"${WOLFSSL_ROOT}/src/bio.c\""
|
||||
"\"${WOLFSSL_ROOT}/src/conf.c\""
|
||||
"\"${WOLFSSL_ROOT}/src/misc.c\""
|
||||
"\"${WOLFSSL_ROOT}/src/pk.c\""
|
||||
"\"${WOLFSSL_ROOT}/src/ssl_asn1.c\"" # included by ssl.c
|
||||
"\"${WOLFSSL_ROOT}/src/ssl_certman.c\"" # included by ssl.c
|
||||
"\"${WOLFSSL_ROOT}/src/ssl_bn.c\"" # included by ssl.c
|
||||
"\"${WOLFSSL_ROOT}/src/ssl_misc.c\"" # included by ssl.c
|
||||
"\"${WOLFSSL_ROOT}/src/x509.c\""
|
||||
"\"${WOLFSSL_ROOT}/src/x509_str.c\""
|
||||
"\"${WOLFSSL_ROOT}/wolfcrypt/src/evp.c\""
|
||||
"\"${WOLFSSL_ROOT}/wolfcrypt/src/misc.c\""
|
||||
"\"${EXCLUDE_ASM}\""
|
||||
)
|
||||
|
||||
spaces2list(COMPONENT_REQUIRES)
|
||||
|
||||
separate_arguments(COMPONENT_SRCDIRS NATIVE_COMMAND "${COMPONENT_SRCDIRS}")
|
||||
separate_arguments(COMPONENT_SRCEXCLUDE NATIVE_COMMAND "${COMPONENT_SRCEXCLUDE}")
|
||||
separate_arguments(COMPONENT_ADD_INCLUDEDIRS NATIVE_COMMAND "${COMPONENT_ADD_INCLUDEDIRS}")
|
||||
|
||||
#
|
||||
# See https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/build-system.html#example-component-requirements
|
||||
#
|
||||
message(STATUS "COMPONENT_SRCDIRS = ${COMPONENT_SRCDIRS}")
|
||||
message(STATUS "COMPONENT_ADD_INCLUDEDIRS = ${COMPONENT_ADD_INCLUDEDIRS}")
|
||||
message(STATUS "COMPONENT_REQUIRES = ${COMPONENT_REQUIRES}")
|
||||
message(STATUS "COMPONENT_SRCEXCLUDE = ${COMPONENT_SRCEXCLUDE}")
|
||||
|
||||
#
|
||||
# see https://docs.espressif.com/projects/esp-idf/en/stable/esp32/migration-guides/release-5.x/build-system.html?highlight=space%20path
|
||||
#
|
||||
set(EXTRA_COMPONENT_DIRS "${COMPONENT_SRCDIRS}")
|
||||
idf_component_register(
|
||||
SRC_DIRS "${COMPONENT_SRCDIRS}"
|
||||
INCLUDE_DIRS "${COMPONENT_ADD_INCLUDEDIRS}"
|
||||
REQUIRES "${COMPONENT_REQUIRES}"
|
||||
EXCLUDE_SRCS "${COMPONENT_SRCEXCLUDE}"
|
||||
PRIV_REQUIRES esp_timer driver # this will typically only be needed for wolfSSL benchmark
|
||||
)
|
||||
# some optional diagnostics
|
||||
if (1)
|
||||
get_cmake_property(_variableNames VARIABLES)
|
||||
list (SORT _variableNames)
|
||||
message(STATUS "")
|
||||
message(STATUS "ALL VARIABLES BEGIN")
|
||||
message(STATUS "")
|
||||
foreach (_variableName ${_variableNames})
|
||||
message(STATUS "${_variableName}=${${_variableName}}")
|
||||
endforeach()
|
||||
message(STATUS "")
|
||||
message(STATUS "ALL VARIABLES END")
|
||||
message(STATUS "")
|
||||
endif()
|
||||
|
||||
# target_sources(wolfssl PRIVATE "\"${WOLFSSL_ROOT}/wolfssl/\"" "\"${WOLFSSL_ROOT}/wolfssl/wolfcrypt\"")
|
||||
endif() # CMAKE_BUILD_EARLY_EXPANSION
|
||||
|
||||
|
||||
|
||||
# check to see if there's both a local copy and EDP-IDF copy of the wolfssl components
|
||||
if( EXISTS "${WOLFSSL_PROJECT_DIR}" AND EXISTS "$ENV{IDF_PATH}/components/wolfssl/" )
|
||||
message(STATUS "")
|
||||
message(STATUS "")
|
||||
message(STATUS "********************************************************************")
|
||||
message(STATUS "WARNING: Found components/wolfssl in both local project and IDF_PATH")
|
||||
message(STATUS "********************************************************************")
|
||||
message(STATUS "")
|
||||
endif()
|
||||
# end multiple component check
|
||||
|
||||
|
||||
#
|
||||
# LIBWOLFSSL_SAVE_INFO(VAR_OUPUT THIS_VAR VAR_RESULT)
|
||||
#
|
||||
# Save the THIS_VAR as a string in a macro called VAR_OUPUT
|
||||
#
|
||||
# VAR_OUPUT: the name of the macro to define
|
||||
# THIS_VAR: the OUTPUT_VARIABLE result from a execute_process()
|
||||
# VAR_RESULT: the RESULT_VARIABLE from a execute_process(); "0" if successful.
|
||||
#
|
||||
function ( LIBWOLFSSL_SAVE_INFO VAR_OUPUT THIS_VAR VAR_RESULT )
|
||||
# is the RESULT_VARIABLE output value 0? If so, IS_VALID_VALUE is true.
|
||||
string(COMPARE EQUAL "${VAR_RESULT}" "0" IS_VALID_VALUE)
|
||||
|
||||
# if we had a successful operation, save the THIS_VAR in VAR_OUPUT
|
||||
if(${IS_VALID_VALUE})
|
||||
# strip newline chars in THIS_VAR parameter and save in VAR_VALUE
|
||||
string(REPLACE "\n" "" VAR_VALUE ${THIS_VAR})
|
||||
|
||||
# we'll could percolate the value to the parent for possible later use
|
||||
# set(${VAR_OUPUT} ${VAR_VALUE} PARENT_SCOPE)
|
||||
|
||||
# but we're only using it here in this function
|
||||
set(${VAR_OUPUT} ${VAR_VALUE})
|
||||
|
||||
# we'll print what we found to the console
|
||||
message(STATUS "Found ${VAR_OUPUT}=${VAR_VALUE}")
|
||||
|
||||
# the interesting part is defining the VAR_OUPUT name a value to use in the app
|
||||
add_definitions(-D${VAR_OUPUT}=\"${VAR_VALUE}\")
|
||||
else()
|
||||
# if we get here, check the execute_process command and parameters.
|
||||
message(STATUS "LIBWOLFSSL_SAVE_INFO encountered a non-zero VAR_RESULT")
|
||||
set(${VAR_OUPUT} "Unknown")
|
||||
endif()
|
||||
endfunction() # LIBWOLFSSL_SAVE_INFO
|
||||
|
||||
# create some programmatic #define values that will be used by ShowExtendedSystemInfo().
|
||||
# see wolfcrypt\src\port\Espressif\esp32_utl.c
|
||||
if(NOT CMAKE_BUILD_EARLY_EXPANSION)
|
||||
set (git_cmd "git")
|
||||
message(STATUS "Adding macro definitions:")
|
||||
|
||||
# LIBWOLFSSL_VERSION_GIT_ORIGIN: git config --get remote.origin.url
|
||||
execute_process(WORKING_DIRECTORY ${WOLFSSL_ROOT} COMMAND ${git_cmd} "config" "--get" "remote.origin.url" OUTPUT_VARIABLE TMP_OUT RESULT_VARIABLE TMP_RES ERROR_QUIET )
|
||||
LIBWOLFSSL_SAVE_INFO(LIBWOLFSSL_VERSION_GIT_ORIGIN "${TMP_OUT}" "${TMP_RES}")
|
||||
|
||||
# LIBWOLFSSL_VERSION_GIT_BRANCH: git rev-parse --abbrev-ref HEAD
|
||||
execute_process(WORKING_DIRECTORY ${WOLFSSL_ROOT} COMMAND ${git_cmd} "rev-parse" "--abbrev-ref" "HEAD" OUTPUT_VARIABLE TMP_OUT RESULT_VARIABLE TMP_RES ERROR_QUIET )
|
||||
LIBWOLFSSL_SAVE_INFO(LIBWOLFSSL_VERSION_GIT_BRANCH "${TMP_OUT}" "${TMP_RES}")
|
||||
|
||||
# LIBWOLFSSL_VERSION_GIT_HASH: git rev-parse HEAD
|
||||
execute_process(WORKING_DIRECTORY ${WOLFSSL_ROOT} COMMAND ${git_cmd} "rev-parse" "HEAD" OUTPUT_VARIABLE TMP_OUT RESULT_VARIABLE TMP_RES ERROR_QUIET )
|
||||
LIBWOLFSSL_SAVE_INFO(LIBWOLFSSL_VERSION_GIT_HASH "${TMP_OUT}" "${TMP_RES}")
|
||||
|
||||
# LIBWOLFSSL_VERSION_GIT_SHORT_HASH: git rev-parse --short HEAD
|
||||
execute_process(WORKING_DIRECTORY ${WOLFSSL_ROOT} COMMAND ${git_cmd} "rev-parse" "--short" "HEAD" OUTPUT_VARIABLE TMP_OUT RESULT_VARIABLE TMP_RES ERROR_QUIET )
|
||||
LIBWOLFSSL_SAVE_INFO(LIBWOLFSSL_VERSION_GIT_SHORT_HASH "${TMP_OUT}" "${TMP_RES}")
|
||||
|
||||
# LIBWOLFSSL_VERSION_GIT_HASH_DATE git show --no-patch --no-notes --pretty=\'\%cd\'
|
||||
execute_process(WORKING_DIRECTORY ${WOLFSSL_ROOT} COMMAND ${git_cmd} "show" "--no-patch" "--no-notes" "--pretty=\'\%cd\'" OUTPUT_VARIABLE TMP_OUT RESULT_VARIABLE TMP_RES )
|
||||
LIBWOLFSSL_SAVE_INFO(LIBWOLFSSL_VERSION_GIT_HASH_DATE "${TMP_OUT}" "${TMP_RES}")
|
||||
|
||||
message(STATUS "************************************************************************************************")
|
||||
message(STATUS "wolfssl component config complete!")
|
||||
message(STATUS "************************************************************************************************")
|
||||
endif()
|
|
@ -0,0 +1,33 @@
|
|||
#
|
||||
# Copyright (C) 2006-2022 wolfSSL Inc. All rights reserved.
|
||||
#
|
||||
# This file is part of wolfSSL.
|
||||
#
|
||||
# Contact licensing@wolfssl.com with any questions or comments.
|
||||
#
|
||||
# https://www.wolfssl.com
|
||||
#/
|
||||
#
|
||||
# Kconfig for wolfssl
|
||||
#
|
||||
menu "wolfSSL"
|
||||
|
||||
config TLS_STACK_WOLFSSL
|
||||
bool "Include wolfSSL in ESP-TLS"
|
||||
default y
|
||||
select FREERTOS_ENABLE_BACKWARD_COMPATIBILITY
|
||||
help
|
||||
Includes wolfSSL in ESP-TLS so that it can be compiled with wolfSSL as its SSL/TLS library.
|
||||
|
||||
config WOLFSSL_HAVE_ALPN
|
||||
bool "Enable ALPN (Application Layer Protocol Negotiation) in wolfSSL"
|
||||
default n
|
||||
|
||||
config WOLFSSL_ALLOW_TLS12
|
||||
bool "Allow TLS 1.2"
|
||||
default n
|
||||
help
|
||||
Allow TLS to fallback to TLS1.2. Memory footprint will likely be larger for TLS1.2.
|
||||
When disabled HTTPS and MQTT over TLS connections will fail if TLS1.3 not accepted.
|
||||
|
||||
endmenu # wolfSSL
|
|
@ -0,0 +1,33 @@
|
|||
#
|
||||
# Copyright (C) 2006-2022 wolfSSL Inc. All rights reserved.
|
||||
#
|
||||
# This file is part of wolfSSL.
|
||||
#
|
||||
# Contact licensing@wolfssl.com with any questions or comments.
|
||||
#
|
||||
# https://www.wolfssl.com
|
||||
#/
|
||||
#
|
||||
# Kconfig for wolfssl
|
||||
#
|
||||
menu "wolfSSL"
|
||||
|
||||
config TLS_STACK_WOLFSSL
|
||||
bool "Include wolfSSL in ESP-TLS"
|
||||
default y
|
||||
select FREERTOS_ENABLE_BACKWARD_COMPATIBILITY
|
||||
help
|
||||
Includes wolfSSL in ESP-TLS so that it can be compiled with wolfSSL as its SSL/TLS library.
|
||||
|
||||
config WOLFSSL_HAVE_ALPN
|
||||
bool "Enable ALPN (Application Layer Protocol Negotiation) in wolfSSL"
|
||||
default n
|
||||
|
||||
config WOLFSSL_ALLOW_TLS12
|
||||
bool "Allow TLS 1.2"
|
||||
default n
|
||||
help
|
||||
Allow TLS to fallback to TLS1.2. Memory footprint will likely be larger for TLS1.2.
|
||||
When disabled HTTPS and MQTT over TLS connections will fail if TLS1.3 not accepted.
|
||||
|
||||
endmenu # wolfSSL
|
|
@ -0,0 +1,38 @@
|
|||
#
|
||||
# Copyright (C) 2006-2023 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
|
||||
#
|
||||
|
||||
#
|
||||
# See https://docs.espressif.com/projects/esp-idf/en/v4.2-beta1/esp32/api-guides/build-system.html#kconfig-projbuild
|
||||
#
|
||||
# " This is an equivalent to project_include.cmake for Component Configuration
|
||||
# KConfig files. If you want to include configuration options at the top-level
|
||||
# of menuconfig, rather than inside the “Component Configuration” sub-menu,
|
||||
# then these can be defined in the KConfig.projbuild file alongside the
|
||||
# CMakeLists.txt file. "
|
||||
|
||||
menu "Example wolfSSL Configuration"
|
||||
|
||||
config EXAMPLE_CONNECT_WIFI
|
||||
bool "connect wolfssl using WiFi interface"
|
||||
depends on !IDF_TARGET_LINUX
|
||||
default y
|
||||
help
|
||||
Protocol examples can use Wi-Fi and/or Ethernet to connect to the network.
|
||||
Choose this option to connect with WiFi
|
|
@ -0,0 +1,24 @@
|
|||
/* config.h - dummy
|
||||
*
|
||||
* Copyright (C) 2006-2023 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
|
||||
*/
|
||||
|
||||
#ifndef _CONFIG_H_
|
||||
#define _CONFIG_H_
|
||||
#endif
|
|
@ -0,0 +1,24 @@
|
|||
/* config.h - dummy
|
||||
*
|
||||
* Copyright (C) 2006-2023 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
|
||||
*/
|
||||
|
||||
#ifndef _CONFIG_H_
|
||||
#define _CONFIG_H_
|
||||
#endif
|
|
@ -0,0 +1,306 @@
|
|||
/* user_settings.h
|
||||
*
|
||||
* Copyright (C) 2006-2023 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
|
||||
*/
|
||||
|
||||
#include <sdkconfig.h> /* essential to chip set detection */
|
||||
|
||||
#undef WOLFSSL_ESPIDF
|
||||
#undef WOLFSSL_ESP32
|
||||
#undef WOLFSSL_ESPWROOM32SE
|
||||
#undef WOLFSSL_ESP32
|
||||
#undef WOLFSSL_ESP8266
|
||||
|
||||
/* The Espressif sdkconfig will have chipset info.
|
||||
**
|
||||
** Possible values:
|
||||
**
|
||||
** CONFIG_IDF_TARGET_ESP32
|
||||
** CONFIG_IDF_TARGET_ESP32S2
|
||||
** CONFIG_IDF_TARGET_ESP32S3
|
||||
** CONFIG_IDF_TARGET_ESP32C3
|
||||
** CONFIG_IDF_TARGET_ESP32C6
|
||||
*/
|
||||
|
||||
#define WOLFSSL_ESPIDF
|
||||
|
||||
/*
|
||||
* choose ONE of these Espressif chips to define:
|
||||
*
|
||||
* WOLFSSL_ESP32
|
||||
* WOLFSSL_ESPWROOM32SE
|
||||
* WOLFSSL_ESP8266
|
||||
*/
|
||||
|
||||
#define WOLFSSL_ESP32
|
||||
|
||||
/* optionally turn off SHA512/224 SHA512/256 */
|
||||
/* #define WOLFSSL_NOSHA512_224 */
|
||||
/* #define WOLFSSL_NOSHA512_256 */
|
||||
|
||||
#define BENCH_EMBEDDED
|
||||
#define USE_CERT_BUFFERS_2048
|
||||
|
||||
/* TLS 1.3 */
|
||||
#define WOLFSSL_TLS13
|
||||
#define HAVE_TLS_EXTENSIONS
|
||||
#define WC_RSA_PSS
|
||||
#define HAVE_HKDF
|
||||
#define HAVE_AEAD
|
||||
#define HAVE_SUPPORTED_CURVES
|
||||
|
||||
#define WOLFSSL_BENCHMARK_FIXED_UNITS_KB
|
||||
|
||||
/* when you want to use SINGLE THREAD */
|
||||
/* #define SINGLE_THREADED */
|
||||
|
||||
#define NO_FILESYSTEM
|
||||
|
||||
#define HAVE_AESGCM
|
||||
|
||||
/* #define WOLFSSL_RIPEMD */
|
||||
/* when you want to use SHA224 */
|
||||
/* #define WOLFSSL_SHA224 */
|
||||
#define NO_OLD_TLS
|
||||
/* when you want to use SHA384 */
|
||||
/* #define WOLFSSL_SHA3 */
|
||||
|
||||
/* #define WOLFSSL_SHA384*/
|
||||
/* #define NO_SHA256*/
|
||||
/* #define WOLFSSL_SHA384*/
|
||||
#define WOLFSSL_SHA512
|
||||
#define HAVE_ECC
|
||||
|
||||
/* #define HAVE_CURVE25519 */
|
||||
/* #define CURVE25519_SMALL */
|
||||
/* #define HAVE_ED25519 */
|
||||
|
||||
/* when you want to use pkcs7 */
|
||||
/* #define HAVE_PKCS7 */
|
||||
|
||||
#if defined(HAVE_PKCS7)
|
||||
#define HAVE_AES_KEYWRAP
|
||||
#define HAVE_X963_KDF
|
||||
#define WOLFSSL_AES_DIRECT
|
||||
#endif
|
||||
|
||||
/* when you want to use aes counter mode */
|
||||
/* #define WOLFSSL_AES_DIRECT */
|
||||
/* #define WOLFSSL_AES_COUNTER */
|
||||
|
||||
/* esp32-wroom-32se specific definition */
|
||||
#if defined(WOLFSSL_ESPWROOM32SE)
|
||||
#define WOLFSSL_ATECC508A
|
||||
#define HAVE_PK_CALLBACKS
|
||||
/* when you want to use a custom slot allocation for ATECC608A */
|
||||
/* unless your configuration is unusual, you can use default */
|
||||
/* implementation. */
|
||||
/* #define CUSTOM_SLOT_ALLOCATION */
|
||||
#endif
|
||||
|
||||
/* rsa primitive specific definition */
|
||||
#if defined(WOLFSSL_ESP32) || defined(WOLFSSL_ESPWROOM32SE)
|
||||
/* Define USE_FAST_MATH and SMALL_STACK */
|
||||
#define ESP32_USE_RSA_PRIMITIVE
|
||||
/* threshold for performance adjustment for HW primitive use */
|
||||
/* X bits of G^X mod P greater than */
|
||||
#define EPS_RSA_EXPT_XBTIS 32 /* NOTE HW unreliable for small values! */
|
||||
/* X and Y of X * Y mod P greater than */
|
||||
#define ESP_RSA_MULM_BITS 9
|
||||
#endif
|
||||
|
||||
/* #define RSA_LOW_MEM */
|
||||
|
||||
/* debug options */
|
||||
/* #define DEBUG_WOLFSSL */
|
||||
/* #define WOLFSSL_ESP32_CRYPT_DEBUG */
|
||||
/* #define WOLFSSL_ATECC508A_DEBUG */
|
||||
|
||||
/* date/time */
|
||||
/* if it cannot adjust time in the device, */
|
||||
/* enable macro below */
|
||||
/* #define NO_ASN_TIME */
|
||||
/* #define XTIME time */
|
||||
|
||||
/* adjust wait-timeout count if you see timeout in RSA HW acceleration */
|
||||
#define ESP_RSA_TIMEOUT_CNT 0x249F00
|
||||
|
||||
#define HASH_SIZE_LIMIT /* for test.c */
|
||||
|
||||
/* only FAST_MATH has HW acceleration at this time */
|
||||
#define USE_FAST_MATH
|
||||
/* #define WOLFSSL_SP_MATH_ALL */
|
||||
/* #define WOLFSSL_SP_RISCV32 */ /* only valid on RISC-V chips */
|
||||
|
||||
/* optionally use SP_MATH */
|
||||
/* #define SP_MATH */
|
||||
|
||||
#define WOLFSSL_SMALL_STACK
|
||||
|
||||
#define HAVE_VERSION_EXTENDED_INFO
|
||||
#define HAVE_WC_INTROSPECTION
|
||||
|
||||
/* allows for all version info, even that suppressed with intospection */
|
||||
#define ALLOW_BINARY_MISMATCH_INTROSPECTION
|
||||
|
||||
/* Default is HW enabled unless turned off.
|
||||
** Uncomment these lines for SW: */
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32)
|
||||
/* #define NO_ESP32_CRYPT */
|
||||
/* #define NO_WOLFSSL_ESP32_CRYPT_HASH */
|
||||
/* #define NO_WOLFSSL_ESP32_CRYPT_AES */
|
||||
/* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI */
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32S2)
|
||||
#define NO_ESP32_CRYPT
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_HASH
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_AES
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32S3)
|
||||
/* #define NO_ESP32_CRYPT */
|
||||
/* #define NO_WOLFSSL_ESP32_CRYPT_HASH */
|
||||
/* #define NO_WOLFSSL_ESP32_CRYPT_AES */
|
||||
/* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI */
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32C2)
|
||||
#define NO_ESP32_CRYPT
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_HASH
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_AES
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32C3)
|
||||
#define NO_ESP32_CRYPT
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_HASH
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_AES
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32C6)
|
||||
#define NO_ESP32_CRYPT
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_HASH
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_AES
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32H2)
|
||||
#define NO_ESP32_CRYPT
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_HASH
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_AES
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI
|
||||
#else
|
||||
#define NO_ESP32_CRYPT
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_HASH
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_AES
|
||||
#define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI
|
||||
#endif
|
||||
|
||||
/* debug options */
|
||||
/* #define ESP_VERIFY_MEMBLOCK */
|
||||
#define WOLFSSL_HW_METRICS
|
||||
/* #define DEBUG_WOLFSSL_VERBOSE */
|
||||
/* #define DEBUG_WOLFSSL */
|
||||
/* #define WOLFSSL_ESP32_CRYPT_DEBUG */
|
||||
#define NO_RECOVER_SOFTWARE_CALC
|
||||
|
||||
/* optionally turn off individual math HW acceleration features */
|
||||
|
||||
/* Turn off Large Number Multiplication:
|
||||
** [Z = X * Y] in esp_mp_mul() */
|
||||
/* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MP_MUL */
|
||||
|
||||
/* Turn off Large Number Modular Exponentiation:
|
||||
** [Z = X^Y mod M] in esp_mp_exptmod() */
|
||||
/* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_EXPTMOD */
|
||||
|
||||
/* Turn off Large Number Modular Multiplication
|
||||
** [Z = X × Y mod M] in esp_mp_mulmod() */
|
||||
/* #define NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MULMOD */
|
||||
|
||||
|
||||
/* this is known to fail in TFM: */
|
||||
/* #define HONOR_MATH_USED_LENGTH */
|
||||
|
||||
/* this is known to fail in TFM */
|
||||
/* #define CHECK_MP_READ_UNSIGNED_BIN */
|
||||
|
||||
#define WOLFSSL_PUBLIC_MP /* used by benchmark */
|
||||
|
||||
/* optional SM4 Ciphers. See https://github.com/wolfSSL/wolfsm */
|
||||
//#define WOLFSSL_SM2
|
||||
//#define WOLFSSL_SM3
|
||||
//#define WOLFSSL_SM4
|
||||
|
||||
#if defined(WOLFSSL_SM2) || defined(WOLFSSL_SM3) || defined(WOLFSSL_SM4)
|
||||
#include <wolfssl/certs_test_sm.h>
|
||||
#define CTX_CA_CERT root_sm2
|
||||
#define CTX_CA_CERT_SIZE sizeof_root_sm2
|
||||
#define CTX_CA_CERT_TYPE WOLFSSL_FILETYPE_PEM
|
||||
#define CTX_SERVER_CERT server_sm2
|
||||
#define CTX_SERVER_CERT_SIZE sizeof_server_sm2
|
||||
#define CTX_SERVER_CERT_TYPE WOLFSSL_FILETYPE_PEM
|
||||
#define CTX_SERVER_KEY server_sm2_priv
|
||||
#define CTX_SERVER_KEY_SIZE sizeof_server_sm2_priv
|
||||
#define CTX_SERVER_KEY_TYPE WOLFSSL_FILETYPE_PEM
|
||||
#else
|
||||
#define USE_CERT_BUFFERS_2048
|
||||
#define USE_CERT_BUFFERS_256
|
||||
#define CTX_CA_CERT ca_cert_der_2048
|
||||
#define CTX_CA_CERT_SIZE sizeof_ca_cert_der_2048
|
||||
#define CTX_CA_CERT_TYPE WOLFSSL_FILETYPE_ASN1
|
||||
#define CTX_SERVER_CERT server_cert_der_2048
|
||||
#define CTX_SERVER_CERT_SIZE sizeof_server_cert_der_2048
|
||||
#define CTX_SERVER_CERT_TYPE WOLFSSL_FILETYPE_ASN1
|
||||
#define CTX_SERVER_KEY server_key_der_2048
|
||||
#define CTX_SERVER_KEY_SIZE sizeof_server_key_der_2048
|
||||
#define CTX_SERVER_KEY_TYPE WOLFSSL_FILETYPE_ASN1
|
||||
#endif
|
||||
|
||||
/* Optionally include alternate HW test library: alt_hw_test.h */
|
||||
/* When enabling, the ./components/wolfssl/CMakeLists.txt file
|
||||
* will need the name of the library in the idf_component_register
|
||||
* for the PRIV_REQUIRES list. */
|
||||
/* #define INCLUDE_ALT_HW_TEST */
|
||||
|
||||
/* #define NO_HW_MATH_TEST */
|
||||
|
||||
|
||||
/* when turning on ECC508 / ECC608 support
|
||||
#define WOLFSSL_ESPWROOM32SE
|
||||
#define HAVE_PK_CALLBACKS
|
||||
#define WOLFSSL_ATECC508A
|
||||
#define ATCA_WOLFSSL
|
||||
*/
|
||||
|
||||
/* USE_FAST_MATH is default */
|
||||
|
||||
/* use SP_MATH */
|
||||
/*
|
||||
#undef USE_FAST_MATH
|
||||
#define WOLFSSL_SP_MATH_ALL
|
||||
*/
|
||||
|
||||
/* use integer heap math */
|
||||
/*
|
||||
#undef USE_FAST_MATH
|
||||
#define USE_INTEGER_HEAP_MATH
|
||||
*/
|
||||
|
||||
/* optionally use DPORT_ACCESS_READ_BUFFER */
|
||||
/*
|
||||
#define USE_ESP_DPORT_ACCESS_READ_BUFFER
|
||||
*/
|
||||
|
||||
#define WOLFSSL_DTLS 1
|
||||
#define WOLFSSL_DTLS13
|
||||
#define WOLFSSL_SEND_HRR_COOKIE
|
||||
#define WOLFSSL_ENCRYPTED_KEYS
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
# This tag is used to include this file in the ESP Component Registry:
|
||||
# __ESP_COMPONENT_SOURCE__
|
||||
|
||||
#
|
||||
# wolfssl dtls 1.3 demo
|
||||
#
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_USER_SETTINGS")
|
||||
|
||||
set (git_cmd "git")
|
||||
|
||||
if( EXISTS "${CMAKE_HOME_DIRECTORY}/components/wolfssl/" AND EXISTS "$ENV{IDF_PATH}/components/wolfssl/" )
|
||||
#
|
||||
# wolfSSL found in both ESP-IDF and local project - needs to be resolved by user
|
||||
#
|
||||
message(STATUS "")
|
||||
message(STATUS "WARNING: Found components/wolfssl in both local project and IDF_PATH")
|
||||
message(STATUS "")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_MULTI_INSTALL_WARNING")
|
||||
endif()
|
||||
|
||||
## register_component()
|
||||
idf_component_register(
|
||||
SRCS main.c server-dtls13.c time_helper.c wifi_connect.c
|
||||
INCLUDE_DIRS "." "./include")
|
||||
#
|
||||
|
||||
#
|
||||
# LIBWOLFSSL_SAVE_INFO(VAR_OUPUT THIS_VAR VAR_RESULT)
|
||||
#
|
||||
# Save the THIS_VAR as a string in a macro called VAR_OUPUT
|
||||
#
|
||||
# VAR_OUPUT: the name of the macro to define
|
||||
# THIS_VAR: the OUTPUT_VARIABLE result from a execute_process()
|
||||
# VAR_RESULT: the RESULT_VARIABLE from a execute_process(); "0" if successful.
|
||||
#
|
||||
function ( LIBWOLFSSL_SAVE_INFO VAR_OUPUT THIS_VAR VAR_RESULT )
|
||||
# is the RESULT_VARIABLE output value 0? If so, IS_VALID_VALUE is true.
|
||||
string(COMPARE EQUAL "${VAR_RESULT}" "0" IS_VALID_VALUE)
|
||||
|
||||
# if we had a successful operation, save the THIS_VAR in VAR_OUPUT
|
||||
if(${IS_VALID_VALUE})
|
||||
# strip newline chars in THIS_VAR parameter and save in VAR_VALUE
|
||||
string(REPLACE "\n" "" VAR_VALUE ${THIS_VAR})
|
||||
|
||||
# we'll could percolate the value to the parent for possible later use
|
||||
# set(${VAR_OUPUT} ${VAR_VALUE} PARENT_SCOPE)
|
||||
|
||||
# but we're only using it here in this function
|
||||
set(${VAR_OUPUT} ${VAR_VALUE})
|
||||
|
||||
# we'll print what we found to the console
|
||||
message(STATUS "Found ${VAR_OUPUT}=${VAR_VALUE}")
|
||||
|
||||
# the interesting part is defining the VAR_OUPUT name a value to use in the app
|
||||
add_definitions(-D${VAR_OUPUT}=\"${VAR_VALUE}\")
|
||||
else()
|
||||
# if we get here, check the execute_process command and parameters.
|
||||
message(STATUS "LIBWOLFSSL_SAVE_INFO encountered a non-zero VAR_RESULT")
|
||||
set(${VAR_OUPUT} "Unknown")
|
||||
endif()
|
||||
endfunction() # LIBWOLFSSL_SAVE_INFO
|
||||
|
||||
if(NOT CMAKE_BUILD_EARLY_EXPANSION)
|
||||
# LIBWOLFSSL_VERSION_GIT_HASH
|
||||
execute_process(COMMAND ${git_cmd} "rev-parse" "HEAD" OUTPUT_VARIABLE TMP_OUT RESULT_VARIABLE TMP_RES ERROR_QUIET )
|
||||
LIBWOLFSSL_SAVE_INFO(LIBWOLFSSL_VERSION_GIT_HASH "${TMP_OUT}" "${TMP_RES}")
|
||||
|
||||
# LIBWOLFSSL_VERSION_GIT_SHORT_HASH
|
||||
execute_process(COMMAND ${git_cmd} "rev-parse" "--short" "HEAD" OUTPUT_VARIABLE TMP_OUT RESULT_VARIABLE TMP_RES ERROR_QUIET )
|
||||
LIBWOLFSSL_SAVE_INFO(LIBWOLFSSL_VERSION_GIT_SHORT_HASH "${TMP_OUT}" "${TMP_RES}")
|
||||
|
||||
# LIBWOLFSSL_VERSION_GIT_HASH_DATE
|
||||
execute_process(COMMAND ${git_cmd} "show" "--no-patch" "--no-notes" "--pretty=\'\%cd\'" OUTPUT_VARIABLE TMP_OUT RESULT_VARIABLE TMP_RES )
|
||||
LIBWOLFSSL_SAVE_INFO(LIBWOLFSSL_VERSION_GIT_HASH_DATE "${TMP_OUT}" "${TMP_RES}")
|
||||
endif()
|
||||
|
||||
message(STATUS "")
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
# This tag is used to include this file in the ESP Component Registry:
|
||||
# __ESP_COMPONENT_SOURCE__
|
||||
|
||||
#
|
||||
# wolfssl client test
|
||||
#
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_USER_SETTINGS")
|
||||
|
||||
set (git_cmd "git")
|
||||
|
||||
if( EXISTS "${CMAKE_HOME_DIRECTORY}/components/wolfssl/" AND EXISTS "$ENV{IDF_PATH}/components/wolfssl/" )
|
||||
#
|
||||
# wolfSSL found in both ESP-IDF and local project - needs to be resolved by user
|
||||
#
|
||||
message(STATUS "")
|
||||
message(STATUS "WARNING: Found components/wolfssl in both local project and IDF_PATH")
|
||||
message(STATUS "")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_MULTI_INSTALL_WARNING")
|
||||
endif()
|
||||
|
||||
## register_component()
|
||||
idf_component_register(
|
||||
SRCS main.c time_helper.c wifi_connect.c
|
||||
INCLUDE_DIRS "." "./include")
|
||||
#
|
||||
|
||||
#
|
||||
# LIBWOLFSSL_SAVE_INFO(VAR_OUPUT THIS_VAR VAR_RESULT)
|
||||
#
|
||||
# Save the THIS_VAR as a string in a macro called VAR_OUPUT
|
||||
#
|
||||
# VAR_OUPUT: the name of the macro to define
|
||||
# THIS_VAR: the OUTPUT_VARIABLE result from a execute_process()
|
||||
# VAR_RESULT: the RESULT_VARIABLE from a execute_process(); "0" if successful.
|
||||
#
|
||||
function ( LIBWOLFSSL_SAVE_INFO VAR_OUPUT THIS_VAR VAR_RESULT )
|
||||
# is the RESULT_VARIABLE output value 0? If so, IS_VALID_VALUE is true.
|
||||
string(COMPARE EQUAL "${VAR_RESULT}" "0" IS_VALID_VALUE)
|
||||
|
||||
# if we had a successful operation, save the THIS_VAR in VAR_OUPUT
|
||||
if(${IS_VALID_VALUE})
|
||||
# strip newline chars in THIS_VAR parameter and save in VAR_VALUE
|
||||
string(REPLACE "\n" "" VAR_VALUE ${THIS_VAR})
|
||||
|
||||
# we'll could percolate the value to the parent for possible later use
|
||||
# set(${VAR_OUPUT} ${VAR_VALUE} PARENT_SCOPE)
|
||||
|
||||
# but we're only using it here in this function
|
||||
set(${VAR_OUPUT} ${VAR_VALUE})
|
||||
|
||||
# we'll print what we found to the console
|
||||
message(STATUS "Found ${VAR_OUPUT}=${VAR_VALUE}")
|
||||
|
||||
# the interesting part is defining the VAR_OUPUT name a value to use in the app
|
||||
add_definitions(-D${VAR_OUPUT}=\"${VAR_VALUE}\")
|
||||
else()
|
||||
# if we get here, check the execute_process command and parameters.
|
||||
message(STATUS "LIBWOLFSSL_SAVE_INFO encountered a non-zero VAR_RESULT")
|
||||
set(${VAR_OUPUT} "Unknown")
|
||||
endif()
|
||||
endfunction() # LIBWOLFSSL_SAVE_INFO
|
||||
|
||||
if(NOT CMAKE_BUILD_EARLY_EXPANSION)
|
||||
# LIBWOLFSSL_VERSION_GIT_HASH
|
||||
execute_process(COMMAND ${git_cmd} "rev-parse" "HEAD" OUTPUT_VARIABLE TMP_OUT RESULT_VARIABLE TMP_RES ERROR_QUIET )
|
||||
LIBWOLFSSL_SAVE_INFO(LIBWOLFSSL_VERSION_GIT_HASH "${TMP_OUT}" "${TMP_RES}")
|
||||
|
||||
# LIBWOLFSSL_VERSION_GIT_SHORT_HASH
|
||||
execute_process(COMMAND ${git_cmd} "rev-parse" "--short" "HEAD" OUTPUT_VARIABLE TMP_OUT RESULT_VARIABLE TMP_RES ERROR_QUIET )
|
||||
LIBWOLFSSL_SAVE_INFO(LIBWOLFSSL_VERSION_GIT_SHORT_HASH "${TMP_OUT}" "${TMP_RES}")
|
||||
|
||||
# LIBWOLFSSL_VERSION_GIT_HASH_DATE
|
||||
execute_process(COMMAND ${git_cmd} "show" "--no-patch" "--no-notes" "--pretty=\'\%cd\'" OUTPUT_VARIABLE TMP_OUT RESULT_VARIABLE TMP_RES )
|
||||
LIBWOLFSSL_SAVE_INFO(LIBWOLFSSL_VERSION_GIT_HASH_DATE "${TMP_OUT}" "${TMP_RES}")
|
||||
endif()
|
||||
|
||||
message(STATUS "")
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* dtls-common.h
|
||||
*
|
||||
* Copyright (C) 2006-2022 wolfSSL Inc.
|
||||
*
|
||||
* This file is part of wolfSSL. (formerly known as CyaSSL)
|
||||
*
|
||||
* 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-1301, USA
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Define USE_DTLS12 to use DTLS 1.2 instead of DTLS 1.3
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef DTLS_COMMON_H_
|
||||
#define DTLS_COMMON_H_
|
||||
|
||||
#define INVALID_SOCKET -1
|
||||
#define MAXLINE 4096
|
||||
#define SERV_PORT 11111
|
||||
#define LOOP_LIMIT 5
|
||||
#define SFD_TIMEOUT 1
|
||||
|
||||
/* wolfSSL */
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
#include "user_settings.h" /* include before other wolfssl files */
|
||||
|
||||
/* Loc short for "location" */
|
||||
const char caCertLoc[] = "../certs/ca-cert.pem";
|
||||
const char servCertLoc[] = "../certs/server-cert.pem";
|
||||
const char servKeyLoc[] = "../certs/server-key.pem";
|
||||
|
||||
static inline void showConnInfo(WOLFSSL* ssl) {
|
||||
printf("New connection established using %s %s\n",
|
||||
wolfSSL_get_version(ssl), wolfSSL_get_cipher(ssl));
|
||||
}
|
||||
|
||||
|
||||
#endif /* DTLS_COMMON_H_ */
|
|
@ -0,0 +1,24 @@
|
|||
/* template main.h
|
||||
*
|
||||
* Copyright (C) 2006-2023 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
|
||||
*/
|
||||
#ifndef _MAIN_H_
|
||||
#define _MAIN_H_
|
||||
|
||||
#endif
|
|
@ -0,0 +1,51 @@
|
|||
/* server-dtls13.h
|
||||
*
|
||||
* Copyright (C) 2006-2023 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
|
||||
*/
|
||||
#ifndef _SERVER_DTLS13_
|
||||
#define _SERVER_DTLS13_
|
||||
|
||||
#define DEFAULT_PORT 11111
|
||||
|
||||
#define TLS_SMP_SERVER_TASK_NAME "dtls13"
|
||||
#if defined(WOLFSSL_SM2) || defined(WOLFSSL_SM3) || defined(WOLFSSL_SM4)
|
||||
#define TLS_SMP_SERVER_TASK_WORDS 20192 /* much larger for SM */
|
||||
#else
|
||||
#define TLS_SMP_SERVER_TASK_WORDS 8192 /* 32K bytes */
|
||||
#endif
|
||||
#define TLS_SMP_SERVER_TASK_PRIORITY 5
|
||||
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
#include "user_settings.h"
|
||||
|
||||
#include <wolfssl/ssl.h>
|
||||
|
||||
/* Function to show the ciphers available / in use. */
|
||||
int ShowCiphers(WOLFSSL* ssl);
|
||||
|
||||
/* This is the TLS Server function, possibly in an RTOS thread. */
|
||||
//WOLFSSL_ESP_TASK udp_server_task(void *pvParameters);
|
||||
|
||||
/* init will create an RTOS task, otherwise server is simply function call. */
|
||||
#if defined(SINGLE_THREADED)
|
||||
/* no init neded */
|
||||
#else
|
||||
int dtls13_smp_server_init(int port);
|
||||
#endif
|
||||
#endif /* _SERVER_TLS_ */
|
|
@ -0,0 +1,47 @@
|
|||
#ifndef _TIME_HELPER_H
|
||||
/*
|
||||
* Copyright (C) 2006-2023 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 tag is used to include this file in the ESP Component Registry:
|
||||
# __ESP_COMPONENT_SOURCE__
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* worst case, if GitHub time not available, used fixed time */
|
||||
int set_fixed_default_time();
|
||||
|
||||
/* set time from string (e.g. GitHub commit time) */
|
||||
int set_time_from_string(char* time_buffer);
|
||||
|
||||
/* set time from NTP servers,
|
||||
* also intitially calls set_fixed_default_time or set_time_from_string */
|
||||
int set_time(void);
|
||||
|
||||
int set_time_wait_for_ntp(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* #ifndef _TIME_HELPER_H */
|
|
@ -0,0 +1,82 @@
|
|||
/* wifi_connect.h
|
||||
*
|
||||
* Copyright (C) 2006-2023 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
|
||||
*/
|
||||
#ifndef _WIFI_CONNECT_H_
|
||||
#define _WIFI_CONNECT_H_
|
||||
|
||||
#include <esp_idf_version.h>
|
||||
#include <esp_log.h>
|
||||
|
||||
|
||||
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||
//#include "esp_wifi.h"
|
||||
//#include "esp_event.h"
|
||||
#else
|
||||
#include "esp_event_loop.h"
|
||||
#endif
|
||||
|
||||
/* ESP lwip */
|
||||
#define EXAMPLE_ESP_MAXIMUM_RETRY CONFIG_ESP_MAXIMUM_RETRY
|
||||
|
||||
#define TLS_SMP_WIFI_SSID CONFIG_WIFI_SSID
|
||||
#define TLS_SMP_WIFI_PASS CONFIG_WIFI_PASSWORD
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
******************************************************************************
|
||||
** USER APPLICATION SETTINGS BEGIN
|
||||
******************************************************************************
|
||||
******************************************************************************
|
||||
**/
|
||||
|
||||
/* when using a private config with plain text passwords, not my_private_config.h should be excluded from git updates */
|
||||
#define USE_MY_PRIVATE_CONFIG
|
||||
|
||||
#ifdef USE_MY_PRIVATE_CONFIG
|
||||
#if defined(WOLFSSL_CMAKE_SYSTEM_NAME_WINDOWS)
|
||||
#include "/workspace/my_private_config.h"
|
||||
#elif defined(WOLFSSL_CMAKE_SYSTEM_NAME_WSL)
|
||||
#include "/mnt/c/workspace/my_private_config.h"
|
||||
#elif defined(WOLFSSL_CMAKE_SYSTEM_NAME_LINUX)
|
||||
#include "~/workspace/my_private_config.h"
|
||||
#elif defined(WOLFSSL_CMAKE_SYSTEM_NAME_APPLE)
|
||||
#include "~/Documents/my_private_config.h"
|
||||
#else
|
||||
#warning "did not detect environment. using ~/my_private_config.h"
|
||||
#include "~/my_private_config.h"
|
||||
#endif
|
||||
#else
|
||||
|
||||
/*
|
||||
** The examples use WiFi configuration that you can set via project
|
||||
** configuration menu
|
||||
**
|
||||
** If you'd rather not, just change the below entries to strings with
|
||||
** the config you want - ie #define EXAMPLE_WIFI_SSID "mywifissid"
|
||||
*/
|
||||
#define EXAMPLE_ESP_WIFI_SSID CONFIG_ESP_WIFI_SSID
|
||||
#define EXAMPLE_ESP_WIFI_PASS CONFIG_ESP_WIFI_PASSWORD
|
||||
#endif
|
||||
|
||||
int wifi_init_sta(void);
|
||||
|
||||
int wifi_show_ip(void);
|
||||
|
||||
#endif /* _WIFI_CONNECT_H_ */
|
|
@ -0,0 +1,85 @@
|
|||
/* wifi_connect.h
|
||||
*
|
||||
* Copyright (C) 2006-2023 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
|
||||
*/
|
||||
#ifndef _WIFI_CONNECT_H_
|
||||
#define _WIFI_CONNECT_H_
|
||||
|
||||
#include <esp_idf_version.h>
|
||||
#include <esp_log.h>
|
||||
|
||||
|
||||
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||
//#include "esp_wifi.h"
|
||||
//#include "esp_event.h"
|
||||
#else
|
||||
#include "esp_event_loop.h"
|
||||
#endif
|
||||
|
||||
/* ESP lwip */
|
||||
#define EXAMPLE_ESP_MAXIMUM_RETRY CONFIG_ESP_MAXIMUM_RETRY
|
||||
#define TLS_SMP_WIFI_SSID CONFIG_WIFI_SSID
|
||||
#define TLS_SMP_WIFI_PASS CONFIG_WIFI_PASSWORD
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
******************************************************************************
|
||||
** USER APPLICATION SETTINGS BEGIN
|
||||
******************************************************************************
|
||||
******************************************************************************
|
||||
**/
|
||||
|
||||
/* when using a private config with plain text passwords, not my_private_config.h should be excluded from git updates */
|
||||
#define USE_MY_PRIVATE_CONFIG
|
||||
|
||||
#ifdef USE_MY_PRIVATE_CONFIG
|
||||
#if defined(WOLFSSL_CMAKE_SYSTEM_NAME_WINDOWS)
|
||||
#include "/workspace/my_private_config.h"
|
||||
#elif defined(WOLFSSL_CMAKE_SYSTEM_NAME_WSL)
|
||||
#include "/mnt/c/workspace/my_private_config.h"
|
||||
#elif defined(WOLFSSL_CMAKE_SYSTEM_NAME_LINUX)
|
||||
#include "~/workspace/my_private_config.h"
|
||||
#elif defined(WOLFSSL_CMAKE_SYSTEM_NAME_APPLE)
|
||||
#include "~/Documents/my_private_config.h"
|
||||
#else
|
||||
#warning "did not detect environment. using ~/my_private_config.h"
|
||||
#include "~/my_private_config.h"
|
||||
#warning "did not detect environment"
|
||||
#endif
|
||||
#else
|
||||
|
||||
/*
|
||||
** The examples use WiFi configuration that you can set via project
|
||||
** configuration menu
|
||||
**
|
||||
** If you'd rather not, just change the below entries to strings with
|
||||
** the config you want - ie #define EXAMPLE_WIFI_SSID "mywifissid"
|
||||
*/
|
||||
#define EXAMPLE_ESP_WIFI_SSID CONFIG_ESP_WIFI_SSID
|
||||
#define EXAMPLE_ESP_WIFI_PASS CONFIG_ESP_WIFI_PASSWORD
|
||||
#endif
|
||||
|
||||
/* ESP lwip */
|
||||
#define EXAMPLE_ESP_MAXIMUM_RETRY CONFIG_ESP_MAXIMUM_RETRY
|
||||
|
||||
int wifi_init_sta(void);
|
||||
|
||||
int wifi_show_ip(void);
|
||||
|
||||
#endif /* _WIFI_CONNECT_H_ */
|
|
@ -0,0 +1,141 @@
|
|||
/* main.c
|
||||
*
|
||||
* Copyright (C) 2006-2023 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
|
||||
*/
|
||||
|
||||
/* ESP specific */
|
||||
#include <nvs_flash.h>
|
||||
#include <esp_log.h>
|
||||
#include "esp_event.h"
|
||||
|
||||
/* wolfSSL */
|
||||
#include <wolfssl/wolfcrypt/port/Espressif/esp32-crypt.h>
|
||||
|
||||
/* project */
|
||||
#include "main.h"
|
||||
#include "time_helper.h"
|
||||
#include "server-dtls13.h"
|
||||
static const char* const TAG = "main task";
|
||||
|
||||
#define USE_WIFI_EXAMPLE
|
||||
#ifdef USE_WIFI_EXAMPLE
|
||||
#include "esp_netif.h"
|
||||
#include "protocol_examples_common.h" /* see project CMakeLists.txt */
|
||||
#else
|
||||
#include "wifi_connect.h"
|
||||
#endif
|
||||
void app_main(void)
|
||||
{
|
||||
esp_err_t ret;
|
||||
ESP_LOGI(TAG, "-------------- wolfSSL DTLS 1.3 Server Example ---------");
|
||||
ESP_LOGI(TAG, "--------------------------------------------------------");
|
||||
ESP_LOGI(TAG, "--------------------------------------------------------");
|
||||
ESP_LOGI(TAG, "---------------------- BEGIN MAIN ----------------------");
|
||||
ESP_LOGI(TAG, "--------------------------------------------------------");
|
||||
ESP_LOGI(TAG, "--------------------------------------------------------");
|
||||
#ifdef HAVE_VERSION_EXTENDED_INFO
|
||||
esp_ShowExtendedSystemInfo();
|
||||
#endif
|
||||
|
||||
/* see project CMakeLists.txt for detection of sample code in ESP-IDF */
|
||||
#ifdef FOUND_PROTOCOL_EXAMPLES_DIR
|
||||
ESP_LOGI(TAG, "FOUND_PROTOCOL_EXAMPLES_DIR is active, using example code.");
|
||||
ESP_ERROR_CHECK(nvs_flash_init());
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
|
||||
ret = set_time(); /* need to setup NTP before WiFi */
|
||||
ESP_ERROR_CHECK(example_connect());
|
||||
ret = set_time_wait_for_ntp();
|
||||
#else
|
||||
ESP_ERROR_CHECK(nvs_flash_init());
|
||||
|
||||
/* Initialize NVS */
|
||||
ret = nvs_flash_init();
|
||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES ||
|
||||
ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
ret = nvs_flash_init();
|
||||
}
|
||||
ESP_ERROR_CHECK(ret);
|
||||
|
||||
/* Initialize WiFi */
|
||||
ESP_LOGI(TAG, "ESP_WIFI_MODE_STA");
|
||||
ret = wifi_init_sta();
|
||||
while (ret != 0) {
|
||||
ESP_LOGI(TAG, "Waiting...");
|
||||
vTaskDelay(60000 / portTICK_PERIOD_MS);
|
||||
ESP_LOGI(TAG, "Trying WiFi again...");
|
||||
ret = wifi_init_sta();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* set time for cert validation */
|
||||
if (ret < -1) {
|
||||
/* a value of -1 means there was no NTP server, so no need to wait */
|
||||
ESP_LOGI(TAG, "Waiting 10 seconds for NTP to complete." );
|
||||
vTaskDelay(10000 / portTICK_PERIOD_MS); /* brute-force solution */
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "CONFIG_ESP_MAIN_TASK_STACK_SIZE = %d bytes (%d words)",
|
||||
CONFIG_ESP_MAIN_TASK_STACK_SIZE,
|
||||
(int)(CONFIG_ESP_MAIN_TASK_STACK_SIZE / sizeof(void*)));
|
||||
|
||||
/* HWM is maximum amount of stack space that has been unused, in words. */
|
||||
ESP_LOGI(TAG, "Initial Stack Used (before wolfSSL Server): %d bytes",
|
||||
CONFIG_ESP_MAIN_TASK_STACK_SIZE
|
||||
- (uxTaskGetStackHighWaterMark(NULL) / 4)
|
||||
);
|
||||
ESP_LOGI(TAG, "Starting TLS Server...\n");
|
||||
|
||||
#if defined(SINGLE_THREADED)
|
||||
/* just call the task */
|
||||
dtls13_smp_server_task((void*)NULL);
|
||||
#else
|
||||
/* start a thread with the task */
|
||||
dtls13_smp_server_init((int)NULL); /* NULL uses the DEFAULT_PORT value */
|
||||
#endif
|
||||
|
||||
#ifdef INCLUDE_uxTaskGetStackHighWaterMark
|
||||
ESP_LOGI(TAG, "Stack HWM: %d", uxTaskGetStackHighWaterMark(NULL));
|
||||
|
||||
ESP_LOGI(TAG, "Stack used: %d", CONFIG_ESP_MAIN_TASK_STACK_SIZE
|
||||
- (uxTaskGetStackHighWaterMark(NULL)));
|
||||
#endif
|
||||
|
||||
/* done */
|
||||
while (1) {
|
||||
ESP_LOGV(TAG, "\n\nLoop...\n\n");
|
||||
|
||||
#if defined(SINGLE_THREADED)
|
||||
ESP_LOGV(TAG, "\n\nDone!\n\n");
|
||||
while (1);
|
||||
#else
|
||||
ESP_LOGI(TAG, "\n\nvTaskDelete main...\n\n");
|
||||
vTaskDelay(1000);
|
||||
vTaskDelete(NULL);
|
||||
|
||||
/* if successful vTaskDelete, we should never get here: */
|
||||
ESP_LOGI(TAG, "\n\nvTaskDelete Complete, but failed?...\n\n");
|
||||
|
||||
vTaskDelay(60000);
|
||||
#endif
|
||||
} /* done whle */
|
||||
|
||||
} /* app_main */
|
|
@ -0,0 +1,466 @@
|
|||
/* server-dtls13.c
|
||||
*
|
||||
* Copyright (C) 2006-2022 wolfSSL Inc.
|
||||
*
|
||||
* This file is part of wolfSSL. (formerly known as CyaSSL)
|
||||
*
|
||||
* 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-1301, USA
|
||||
*
|
||||
*=============================================================================
|
||||
*
|
||||
* Bare-bones example of a DTLS 1.3 server for instructional/learning purposes.
|
||||
* This example can gonly accept one connection at a time.
|
||||
*
|
||||
* Define USE_DTLS12 to use DTLS 1.2 instead of DTLS 1.3
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code was adapted from the wolfSSL/wolfssl-examples/dtls located at:
|
||||
*
|
||||
* https://github.com/wolfSSL/wolfssl-examples/blob/master/dtls/client-dtls13.c
|
||||
*/
|
||||
#include "server-dtls13.h"
|
||||
|
||||
#if defined(SINGLE_THREADED)
|
||||
#define WOLFSSL_ESP_TASK int
|
||||
#else
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include <freertos/event_groups.h>
|
||||
#define WOLFSSL_ESP_TASK void
|
||||
#endif
|
||||
|
||||
/* Espressif socket */
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* #include <signal.h> not fully implemented in ESP-IDF */
|
||||
#include <lwip/netdb.h>
|
||||
#include <lwip/sockets.h>
|
||||
#include <stdio.h> /* standard in/out procedures */
|
||||
#include <stdlib.h> /* defines system calls */
|
||||
#include <string.h> /* necessary for memset */
|
||||
|
||||
/* wolfSSL */
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
#include "user_settings.h"
|
||||
|
||||
#include <wolfssl/ssl.h>
|
||||
#include <errno.h>
|
||||
#include <wolfssl/certs_test.h>
|
||||
|
||||
/* this app */
|
||||
#include "dtls-common.h"
|
||||
|
||||
/* convert macros values to string */
|
||||
#define STRINGIFY(x) #x
|
||||
|
||||
static const char* const TAG = "server-dtls13";
|
||||
|
||||
WOLFSSL_CTX* ctx = NULL;
|
||||
WOLFSSL* ssl = NULL;
|
||||
int listenfd = INVALID_SOCKET; /* Initialize our socket */
|
||||
|
||||
/* Note: not implemented at this time:
|
||||
* static void sig_handler(const int sig); */
|
||||
|
||||
static void free_resources(void);
|
||||
|
||||
/* show stack space for this task */
|
||||
static int ShowStackInfo(char* msg)
|
||||
{
|
||||
int ret;
|
||||
ret = TLS_SMP_SERVER_TASK_WORDS - (uxTaskGetStackHighWaterMark(NULL));
|
||||
ESP_LOGI(TAG, "%s: %d words", msg, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if 0
|
||||
int main(int argc, char** argv)
|
||||
#else
|
||||
WOLFSSL_ESP_TASK dtls13_smp_server_task(void *pvParameters)
|
||||
#endif
|
||||
{
|
||||
/* Loc short for "location" */
|
||||
#if defined(SINGLE_THREADED)
|
||||
#define TLS_SMP_SERVER_TASK_RET exitVal
|
||||
#else
|
||||
#define TLS_SMP_SERVER_TASK_RET
|
||||
#endif
|
||||
char buff[MAXLINE]; /* the incoming message */
|
||||
char ack[] = "I hear you fashizzle!\n";
|
||||
struct sockaddr_in servAddr = { 0 }; /* our server's address */
|
||||
struct sockaddr_in cliaddr = { 0 }; /* the client's address */
|
||||
socklen_t cliLen;
|
||||
int ret;
|
||||
int err;
|
||||
int recvLen = 0; /* length of message */
|
||||
int exitVal = 0;
|
||||
int ip_protocol = 0;
|
||||
exitVal = 1;
|
||||
|
||||
ESP_LOGI(TAG, "Init Stack: %d words", TLS_SMP_SERVER_TASK_WORDS);
|
||||
ShowStackInfo("Begin Stack used");
|
||||
|
||||
/* Initialize wolfSSL before assigning ctx */
|
||||
ret = wolfSSL_Init();
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
ESP_LOGI(TAG, "wolfSSL_Init success.");
|
||||
}
|
||||
else {
|
||||
ESP_LOGE(TAG, "wolfSSL_Init error %d.\n", ret);
|
||||
return TLS_SMP_SERVER_TASK_RET;
|
||||
}
|
||||
|
||||
/* Create new conext ctx & show some diagnostics */
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
ShowStackInfo("Init Stack used");
|
||||
|
||||
/* No-op when debugging is not compiled in */
|
||||
wolfSSL_Debugging_ON();
|
||||
|
||||
/* Set ctx to DTLS 1.3 unless DTLS1.2 explicitly enabled */
|
||||
#ifndef USE_DTLS12
|
||||
ESP_LOGI(TAG, "wolfSSL_CTX_new(wolfDTLSv1_3_server_method())");
|
||||
ctx = wolfSSL_CTX_new(wolfDTLSv1_3_server_method());
|
||||
#else
|
||||
ESP_LOGI(TAG, "wolfSSL_CTX_new(wolfDTLSv1_2_server_method())");
|
||||
ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method());
|
||||
#endif
|
||||
if(ctx == NULL) {
|
||||
ESP_LOGE(TAG, "wolfSSL_CTX_new error.\n");
|
||||
ret = WOLFSSL_FATAL_ERROR;
|
||||
}
|
||||
|
||||
(void)ctx;
|
||||
ShowStackInfo("Init ctx Stack used");
|
||||
} /* new ctx */
|
||||
|
||||
#ifdef NO_FILESYSTEM
|
||||
/* Load CA certificates */
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
/* caCertLoc[] = "../certs/ca-cert.pem"; */
|
||||
ret = wolfSSL_CTX_load_verify_buffer(ctx,
|
||||
CTX_CA_CERT,
|
||||
CTX_CA_CERT_SIZE,
|
||||
CTX_SERVER_CERT_TYPE);
|
||||
}
|
||||
|
||||
/* if successful, Load server certificates */
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
ESP_LOGI(TAG, "Success: wolfSSL_CTX_load_verify_buffer loaded %s",
|
||||
STRINGIFY(CTX_CA_CERT));
|
||||
|
||||
/* servCertLoc[] = "../certs/server-cert.pem"; */
|
||||
ret = wolfSSL_CTX_use_certificate_buffer(ctx,
|
||||
CTX_SERVER_CERT,
|
||||
CTX_SERVER_CERT_SIZE,
|
||||
CTX_SERVER_CERT_TYPE);
|
||||
}
|
||||
else {
|
||||
ESP_LOGE(TAG, "Failed CA wolfSSL_CTX_load_verify_buffer "
|
||||
"loading CA %s", STRINGIFY(CTX_SERVER_CERT));
|
||||
}
|
||||
|
||||
/* if successful Load server Keys */
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
ESP_LOGI(TAG, "Success: "
|
||||
"wolfSSL_CTX_use_certificate_chain_buffer_format "
|
||||
"loaded cert chain %s", STRINGIFY(CTX_SERVER_CERT));
|
||||
/* servKeyLoc[] = "../certs/server-key.pem"; */
|
||||
ret = wolfSSL_CTX_use_PrivateKey_buffer(ctx,
|
||||
CTX_SERVER_KEY,
|
||||
CTX_SERVER_KEY_SIZE,
|
||||
CTX_SERVER_KEY_TYPE);
|
||||
}
|
||||
else {
|
||||
ESP_LOGE(TAG, "Failed wolfSSL_CTX_use_certificate_chain_buffer_format "
|
||||
"loading private key %s", STRINGIFY(CTX_SERVER_KEY));
|
||||
}
|
||||
|
||||
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
ESP_LOGI(TAG, "Success: "
|
||||
"wolfSSL_CTX_use_PrivateKey_buffer "
|
||||
"loaded private key %s", STRINGIFY(CTX_SERVER_KEY));
|
||||
}
|
||||
else {
|
||||
ESP_LOGE(TAG, "Failed to load private key: %s",
|
||||
STRINGIFY(CTX_SERVER_KEY));
|
||||
}
|
||||
#else
|
||||
/* Load CA certificates */
|
||||
if (wolfSSL_CTX_load_verify_locations(ctx,caCertLoc,0) !=
|
||||
SSL_SUCCESS) {
|
||||
ESP_LOGE(TAG, "Error loading %s, please check the file.\n", caCertLoc);
|
||||
goto cleanup;
|
||||
}
|
||||
/* Load server certificates */
|
||||
if (wolfSSL_CTX_use_certificate_file(ctx, servCertLoc, SSL_FILETYPE_PEM) !=
|
||||
SSL_SUCCESS) {
|
||||
ESP_LOGE(TAG, "Error loading %s, please check the file.\n", servCertLoc);
|
||||
goto cleanup;
|
||||
}
|
||||
/* Load server Keys */
|
||||
if (wolfSSL_CTX_use_PrivateKey_file(ctx, servKeyLoc,
|
||||
SSL_FILETYPE_PEM) != SSL_SUCCESS) {
|
||||
ESP_LOGE(TAG, "Error loading %s, please check the file.\n", servKeyLoc);
|
||||
goto cleanup;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* initialize network vars */
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
memset((char *)&servAddr, 0, sizeof(servAddr));
|
||||
/* host-to-network-long conversion (htonl) */
|
||||
/* host-to-network-short conversion (htons) */
|
||||
servAddr.sin_family = AF_INET;
|
||||
servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
servAddr.sin_port = htons(SERV_PORT);
|
||||
ip_protocol = IPPROTO_IP;
|
||||
|
||||
/* Create a UDP/IP socket */
|
||||
listenfd = socket(AF_INET, SOCK_DGRAM, ip_protocol);
|
||||
if (listenfd < 0) {
|
||||
ESP_LOGE(TAG, "socket() failed: %d", listenfd);
|
||||
ret = WOLFSSL_FATAL_ERROR;
|
||||
}
|
||||
else {
|
||||
ESP_LOGI(TAG, "Socket allocated.");
|
||||
}
|
||||
} /* init network vars */
|
||||
|
||||
#if defined(CONFIG_LWIP_NETBUF_RECVINFO) && !defined(CONFIG_EXAMPLE_IPV6)
|
||||
int enable = 1;
|
||||
lwip_setsockopt(sock, IPPROTO_IP, IP_PKTINFO, &enable, sizeof(enable));
|
||||
#endif
|
||||
|
||||
/* init socket options */
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
struct timeval timeout;
|
||||
timeout.tv_sec = 1000; // 10 seconds
|
||||
timeout.tv_usec = 0;
|
||||
|
||||
if (setsockopt(listenfd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) == -1) {
|
||||
ESP_LOGE(TAG, "setsockopt for receive timeout");
|
||||
ret = WOLFSSL_FATAL_ERROR;
|
||||
}
|
||||
if (setsockopt(listenfd, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout)) == -1) {
|
||||
ESP_LOGE(TAG, "setsockopt for send timeout");
|
||||
ret = WOLFSSL_FATAL_ERROR;
|
||||
}
|
||||
} /* soctet options */
|
||||
|
||||
/* Bind Socket */
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
if (bind(listenfd, (struct sockaddr*)&servAddr, sizeof(servAddr)) < 0) {
|
||||
ESP_LOGE(TAG, "bind()");
|
||||
ret = WOLFSSL_FATAL_ERROR;
|
||||
}
|
||||
} /* bind socket */
|
||||
|
||||
#ifndef WOLFSSL_ESPIDF
|
||||
/* Signals and signal handling are not implemented in esp-idf.
|
||||
* Calling raise() will abort the program.
|
||||
* see https://esp32.com/viewtopic.php?t=29988&p=103871 */
|
||||
signal(SIGINT, sig_handler);
|
||||
#endif
|
||||
|
||||
ESP_LOGI(TAG, "While Stack used: %d words", TLS_SMP_SERVER_TASK_WORDS
|
||||
- (uxTaskGetStackHighWaterMark(NULL)));
|
||||
while (1) {
|
||||
printf("Awaiting client connection on port %d\n", SERV_PORT);
|
||||
|
||||
cliLen = sizeof(cliaddr);
|
||||
ret = (int)recvfrom(listenfd, (char *)&buff, sizeof(buff), MSG_PEEK,
|
||||
(struct sockaddr*)&cliaddr, &cliLen);
|
||||
|
||||
if (ret < 0) {
|
||||
ESP_LOGE(TAG, "recvfrom() < 0");
|
||||
ret = WOLFSSL_FATAL_ERROR;
|
||||
goto cleanup;
|
||||
}
|
||||
else if (ret == 0) {
|
||||
ESP_LOGE(TAG, "recvfrom zero return\n");
|
||||
ret = WOLFSSL_FATAL_ERROR;
|
||||
goto cleanup;
|
||||
}
|
||||
else {
|
||||
ret = WOLFSSL_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
ESP_LOGI(TAG, "Data!");
|
||||
/* Create the WOLFSSL Object */
|
||||
if ((ssl = wolfSSL_new(ctx)) == NULL) {
|
||||
ESP_LOGE(TAG, "wolfSSL_new error.\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (wolfSSL_dtls_set_peer(ssl, &cliaddr, cliLen) != WOLFSSL_SUCCESS) {
|
||||
ESP_LOGE(TAG, "wolfSSL_dtls_set_peer error.\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (wolfSSL_set_fd(ssl, listenfd) != WOLFSSL_SUCCESS) {
|
||||
ESP_LOGE(TAG, "wolfSSL_set_fd error.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if (wolfSSL_accept(ssl) != SSL_SUCCESS) {
|
||||
err = wolfSSL_get_error(ssl, 0);
|
||||
ESP_LOGE(TAG, "error = %d, %s\n",
|
||||
err, wolfSSL_ERR_reason_error_string(err));
|
||||
ESP_LOGE(TAG, "SSL_accept failed.\n");
|
||||
goto cleanup;
|
||||
}
|
||||
showConnInfo(ssl);
|
||||
while (1) {
|
||||
if ((recvLen = wolfSSL_read(ssl, buff, sizeof(buff)-1)) > 0) {
|
||||
ESP_LOGI(TAG, "heard %d bytes\n", recvLen);
|
||||
|
||||
buff[recvLen] = '\0';
|
||||
ESP_LOGI(TAG, "I heard this: \"%s\"\n", buff);
|
||||
}
|
||||
else if (recvLen <= 0) {
|
||||
err = wolfSSL_get_error(ssl, 0);
|
||||
if (err == WOLFSSL_ERROR_ZERO_RETURN) /* Received shutdown */
|
||||
break;
|
||||
ESP_LOGE(TAG, "error = %d, %s\n",
|
||||
err, wolfSSL_ERR_reason_error_string(err));
|
||||
ESP_LOGE(TAG, "SSL_read failed.\n");
|
||||
goto cleanup;
|
||||
}
|
||||
ESP_LOGI(TAG, "Sending reply.\n");
|
||||
if (wolfSSL_write(ssl, ack, sizeof(ack)) < 0) {
|
||||
err = wolfSSL_get_error(ssl, 0);
|
||||
ESP_LOGE(TAG, "error = %d, %s\n",
|
||||
err, wolfSSL_ERR_reason_error_string(err));
|
||||
ESP_LOGE(TAG, "wolfSSL_write failed.\n");
|
||||
goto cleanup;
|
||||
}
|
||||
ESP_LOGI(TAG, "reply sent \"%s\"\n", ack);
|
||||
} /* while */
|
||||
} /* got data */
|
||||
|
||||
printf("reply sent \"%s\"\n", ack);
|
||||
|
||||
/* Attempt a full shutdown */
|
||||
ret = wolfSSL_shutdown(ssl);
|
||||
if (ret == WOLFSSL_SHUTDOWN_NOT_DONE)
|
||||
ret = wolfSSL_shutdown(ssl);
|
||||
if (ret != WOLFSSL_SUCCESS) {
|
||||
err = wolfSSL_get_error(ssl, 0);
|
||||
ESP_LOGE(TAG, "err = %d, %s\n",
|
||||
err, wolfSSL_ERR_reason_error_string(err));
|
||||
ESP_LOGE(TAG, "wolfSSL_shutdown failed\n");
|
||||
}
|
||||
wolfSSL_free(ssl);
|
||||
ssl = NULL;
|
||||
|
||||
ESP_LOGI(TAG, "Awaiting new connection\n");
|
||||
//cleanup:
|
||||
// if (listenfd != -1) {
|
||||
// ESP_LOGE(TAG, "Shutting down socket and restarting...");
|
||||
// shutdown(listenfd, 0);
|
||||
// close(listenfd);
|
||||
// }
|
||||
// else {
|
||||
// ESP_LOGI(TAG, "restarting...");
|
||||
//
|
||||
// }
|
||||
}
|
||||
ESP_LOGI(TAG, "Exit %d", exitVal);
|
||||
exitVal = 0;
|
||||
cleanup:
|
||||
free_resources();
|
||||
wolfSSL_Cleanup();
|
||||
|
||||
vTaskDelete(NULL);
|
||||
|
||||
return TLS_SMP_SERVER_TASK_RET;
|
||||
}
|
||||
|
||||
|
||||
#ifndef WOLFSSL_ESPIDF
|
||||
static void sig_handler(const int sig)
|
||||
{
|
||||
(void)sig;
|
||||
free_resources();
|
||||
wolfSSL_Cleanup();
|
||||
}
|
||||
#endif
|
||||
|
||||
static void free_resources(void)
|
||||
{
|
||||
if (ssl != NULL) {
|
||||
wolfSSL_shutdown(ssl);
|
||||
wolfSSL_free(ssl);
|
||||
ssl = NULL;
|
||||
}
|
||||
if (ctx != NULL) {
|
||||
wolfSSL_CTX_free(ctx);
|
||||
ctx = NULL;
|
||||
}
|
||||
if (listenfd != INVALID_SOCKET) {
|
||||
close(listenfd);
|
||||
listenfd = INVALID_SOCKET;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(SINGLE_THREADED)
|
||||
/* we don't initialize a thread */
|
||||
#else
|
||||
/* create task */
|
||||
int dtls13_smp_server_init(int port)
|
||||
{
|
||||
int ret = 0;
|
||||
int thisPort;
|
||||
thisPort = port;
|
||||
if (thisPort == 0) {
|
||||
thisPort = DEFAULT_PORT;
|
||||
}
|
||||
|
||||
|
||||
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||
TaskHandle_t _handle;
|
||||
#else
|
||||
xTaskHandle _handle;
|
||||
#endif
|
||||
|
||||
/* http://esp32.info/docs/esp_idf/html/dd/d3c/group__xTaskCreate.html */
|
||||
ESP_LOGI(TAG, "Creating dtls13_smp_server_task with stack size = %d words",
|
||||
TLS_SMP_SERVER_TASK_WORDS);
|
||||
ret = xTaskCreate(dtls13_smp_server_task,
|
||||
TLS_SMP_SERVER_TASK_NAME,
|
||||
TLS_SMP_SERVER_TASK_WORDS, /* not bytes! */
|
||||
(void*)&thisPort,
|
||||
TLS_SMP_SERVER_TASK_PRIORITY,
|
||||
&_handle);
|
||||
|
||||
if (ret == pdPASS) {
|
||||
ESP_LOGI(TAG, "Success: create thread %s", TLS_SMP_SERVER_TASK_NAME);
|
||||
}
|
||||
else {
|
||||
ESP_LOGE(TAG, "create thread %s failed", TLS_SMP_SERVER_TASK_NAME);
|
||||
}
|
||||
|
||||
/* vTaskStartScheduler(); // called automatically in ESP-IDF */
|
||||
return ret;
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,502 @@
|
|||
/* server-dtls13.c
|
||||
*
|
||||
* Copyright (C) 2006-2022 wolfSSL Inc.
|
||||
*
|
||||
* This file is part of wolfSSL. (formerly known as CyaSSL)
|
||||
*
|
||||
* 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-1301, USA
|
||||
*
|
||||
*=============================================================================
|
||||
*
|
||||
* Bare-bones example of a DTLS 1.3 server for instructional/learning purposes.
|
||||
* This example can only accept one connection at a time.
|
||||
*
|
||||
* Define USE_DTLS12 to use DTLS 1.2 instead of DTLS 1.3
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code was adapted from the wolfSSL/wolfssl-examples/dtls located at:
|
||||
*
|
||||
* https://github.com/wolfSSL/wolfssl-examples/blob/master/dtls/client-dtls13.c
|
||||
*/
|
||||
#include "server-dtls13.h"
|
||||
|
||||
#if defined(SINGLE_THREADED)
|
||||
#define WOLFSSL_ESP_TASK int
|
||||
#else
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include <freertos/event_groups.h>
|
||||
#define WOLFSSL_ESP_TASK static void
|
||||
#endif
|
||||
|
||||
/* Espressif socket */
|
||||
#include <esp_log.h>
|
||||
#include <esp_netif.h>
|
||||
|
||||
#include <lwip/err.h>
|
||||
#include <lwip/sockets.h>
|
||||
#include <lwip/sys.h>
|
||||
#include <lwip/netdb.h>
|
||||
/* #include <signal.h> not fully implemented in ESP-IDF */
|
||||
|
||||
/* wolfSSL */
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
#include "user_settings.h" /* include before other wolfssl files */
|
||||
|
||||
#include <wolfssl/ssl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#if defined(WOLFSSL_SM2) || defined(WOLFSSL_SM3) || defined(WOLFSSL_SM4)
|
||||
#include <wolfssl/certs_test_sm.h>
|
||||
#else
|
||||
#include <wolfssl/certs_test.h>
|
||||
#endif
|
||||
/* this app */
|
||||
#include "dtls-common.h"
|
||||
|
||||
/* convert macros values to string */
|
||||
#define STRINGIFY(x) #x
|
||||
|
||||
static const char* const TAG = "server-dtls13";
|
||||
|
||||
WOLFSSL_CTX* ctx = NULL;
|
||||
WOLFSSL* ssl = NULL;
|
||||
int listenfd = INVALID_SOCKET; /* Initialize our socket */
|
||||
|
||||
/* Note: not implemented at this time:
|
||||
* static void sig_handler(const int sig); */
|
||||
|
||||
static void free_resources(void);
|
||||
|
||||
/* show stack space for this task */
|
||||
static int ShowStackInfo(char* msg)
|
||||
{
|
||||
int ret = 0;
|
||||
#ifdef INCLUDE_uxTaskGetStackHighWaterMark
|
||||
ret = uxTaskGetStackHighWaterMark(NULL);
|
||||
ESP_LOGI(TAG, "%s used: %d of %d words. %d free.", msg,
|
||||
TLS_SMP_SERVER_TASK_WORDS - ret,
|
||||
TLS_SMP_SERVER_TASK_WORDS,
|
||||
ret);
|
||||
#else
|
||||
ESP_LOGW(TAG, "Warning: uxTaskGetStackHighWaterMark() "
|
||||
"not available");
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef DTSL13_SERVER_IS_MAIN
|
||||
int main(int argc, char** argv)
|
||||
#else
|
||||
WOLFSSL_ESP_TASK dtls13_smp_server_task(void *pvParameters)
|
||||
#endif
|
||||
{
|
||||
/* Loc short for "location" */
|
||||
#if defined(SINGLE_THREADED)
|
||||
#define TLS_SMP_SERVER_TASK_RET exitVal
|
||||
#else
|
||||
#define TLS_SMP_SERVER_TASK_RET
|
||||
#endif
|
||||
char buff[MAXLINE]; /* the incoming message */
|
||||
char ack[] = "I hear you fashizzle!\n";
|
||||
struct sockaddr_in servAddr = { 0 }; /* our server's address */
|
||||
struct sockaddr_in cliaddr = { 0 }; /* the client's address */
|
||||
socklen_t cliLen;
|
||||
int err;
|
||||
int recvLen = 0; /* length of message */
|
||||
int ip_protocol = 0;
|
||||
int ret;
|
||||
|
||||
ESP_LOGI(TAG, "Init Stack: %d words", TLS_SMP_SERVER_TASK_WORDS);
|
||||
ShowStackInfo("Begin Stack");
|
||||
|
||||
/* Initialize wolfSSL before assigning ctx */
|
||||
ret = wolfSSL_Init();
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
ESP_LOGI(TAG, "wolfSSL_Init success.");
|
||||
}
|
||||
else {
|
||||
ESP_LOGE(TAG, "wolfSSL_Init error %d.\n", ret);
|
||||
return TLS_SMP_SERVER_TASK_RET;
|
||||
}
|
||||
|
||||
/* Create new conext ctx & show some diagnostics */
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
ShowStackInfo("Init Stack");
|
||||
|
||||
/* No-op when debugging is not compiled in */
|
||||
wolfSSL_Debugging_ON();
|
||||
|
||||
/* Set ctx to DTLS 1.3 unless DTLS1.2 explicitly enabled */
|
||||
#ifndef USE_DTLS12
|
||||
ESP_LOGI(TAG, "wolfSSL_CTX_new(wolfDTLSv1_3_server_method())");
|
||||
ctx = wolfSSL_CTX_new(wolfDTLSv1_3_server_method());
|
||||
#else
|
||||
ESP_LOGI(TAG, "wolfSSL_CTX_new(wolfDTLSv1_2_server_method())");
|
||||
ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method());
|
||||
#endif
|
||||
if(ctx == NULL) {
|
||||
ESP_LOGE(TAG, "wolfSSL_CTX_new error.\n");
|
||||
ret = WOLFSSL_FATAL_ERROR;
|
||||
}
|
||||
|
||||
(void)ctx;
|
||||
ShowStackInfo("Init ctx Stack");
|
||||
} /* new ctx */
|
||||
|
||||
#if defined(WOLFSSL_SM2) || defined(WOLFSSL_SM3) || defined(WOLFSSL_SM4)
|
||||
#define WOLFSSL_ESP32_CIPHER_SUITE "TLS13-SM4-GCM-SM3:" \
|
||||
"TLS13-SM4-CCM-SM3:"
|
||||
ret = wolfSSL_CTX_set_cipher_list(ctx, WOLFSSL_ESP32_CIPHER_SUITE);
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
printf("Set cipher list: %s\n", WOLFSSL_ESP32_CIPHER_SUITE);
|
||||
}
|
||||
else {
|
||||
printf("ERROR: failed to set cipher list: %s\n", WOLFSSL_ESP32_CIPHER_SUITE);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef NO_FILESYSTEM
|
||||
/* Load CA certificates */
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
/* caCertLoc[] = "../certs/ca-cert.pem"; */
|
||||
ret = wolfSSL_CTX_load_verify_buffer(ctx,
|
||||
CTX_CA_CERT,
|
||||
CTX_CA_CERT_SIZE,
|
||||
CTX_SERVER_CERT_TYPE);
|
||||
}
|
||||
|
||||
/* if successful, Load server certificates */
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
ESP_LOGI(TAG, "Success: wolfSSL_CTX_load_verify_buffer loaded %s",
|
||||
STRINGIFY(CTX_CA_CERT));
|
||||
|
||||
/* servCertLoc[] = "../certs/server-cert.pem"; */
|
||||
ret = wolfSSL_CTX_use_certificate_buffer(ctx,
|
||||
CTX_SERVER_CERT,
|
||||
CTX_SERVER_CERT_SIZE,
|
||||
CTX_SERVER_CERT_TYPE);
|
||||
}
|
||||
else {
|
||||
ESP_LOGE(TAG, "Failed CA wolfSSL_CTX_load_verify_buffer "
|
||||
"loading CA %s", STRINGIFY(CTX_SERVER_CERT));
|
||||
}
|
||||
|
||||
/* if successful Load server Keys */
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
ESP_LOGI(TAG, "Success: "
|
||||
"wolfSSL_CTX_use_certificate_chain_buffer_format "
|
||||
"loaded cert chain %s", STRINGIFY(CTX_SERVER_CERT));
|
||||
/* servKeyLoc[] = "../certs/server-key.pem"; */
|
||||
ret = wolfSSL_CTX_use_PrivateKey_buffer(ctx,
|
||||
CTX_SERVER_KEY,
|
||||
CTX_SERVER_KEY_SIZE,
|
||||
CTX_SERVER_KEY_TYPE);
|
||||
}
|
||||
else {
|
||||
ESP_LOGE(TAG, "Failed wolfSSL_CTX_use_certificate_chain_buffer_format "
|
||||
"loading private key %s", STRINGIFY(CTX_SERVER_KEY));
|
||||
}
|
||||
|
||||
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
ESP_LOGI(TAG, "Success: "
|
||||
"wolfSSL_CTX_use_PrivateKey_buffer "
|
||||
"loaded private key %s", STRINGIFY(CTX_SERVER_KEY));
|
||||
}
|
||||
else {
|
||||
ESP_LOGE(TAG, "Failed to load private key: %s",
|
||||
STRINGIFY(CTX_SERVER_KEY));
|
||||
}
|
||||
#else
|
||||
/* Load CA certificates */
|
||||
if (wolfSSL_CTX_load_verify_locations(ctx,caCertLoc,0) !=
|
||||
SSL_SUCCESS) {
|
||||
ESP_LOGE(TAG, "Error loading %s, please check the file.\n", caCertLoc);
|
||||
goto cleanup;
|
||||
}
|
||||
/* Load server certificates */
|
||||
if (wolfSSL_CTX_use_certificate_file(ctx, servCertLoc, SSL_FILETYPE_PEM) !=
|
||||
SSL_SUCCESS) {
|
||||
ESP_LOGE(TAG, "Error loading %s, please check the file.\n", servCertLoc);
|
||||
goto cleanup;
|
||||
}
|
||||
/* Load server Keys */
|
||||
if (wolfSSL_CTX_use_PrivateKey_file(ctx, servKeyLoc,
|
||||
SSL_FILETYPE_PEM) != SSL_SUCCESS) {
|
||||
ESP_LOGE(TAG, "Error loading %s, please check the file.\n", servKeyLoc);
|
||||
goto cleanup;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* initialize network vars */
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
memset((char *)&servAddr, 0, sizeof(servAddr));
|
||||
/* host-to-network-long conversion (htonl) */
|
||||
/* host-to-network-short conversion (htons) */
|
||||
servAddr.sin_family = AF_INET;
|
||||
servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
servAddr.sin_port = htons(SERV_PORT);
|
||||
ip_protocol = IPPROTO_IP;
|
||||
|
||||
/* Create a UDP/IP socket */
|
||||
listenfd = socket(AF_INET, SOCK_DGRAM, ip_protocol);
|
||||
if (listenfd < 0) {
|
||||
ESP_LOGE(TAG, "socket() failed: %d", listenfd);
|
||||
ret = WOLFSSL_FATAL_ERROR;
|
||||
}
|
||||
else {
|
||||
ESP_LOGI(TAG, "Socket allocated.");
|
||||
}
|
||||
} /* init network vars */
|
||||
|
||||
#if defined(CONFIG_LWIP_NETBUF_RECVINFO) && !defined(CONFIG_EXAMPLE_IPV6)
|
||||
int enable = 1;
|
||||
lwip_setsockopt(sock, IPPROTO_IP, IP_PKTINFO, &enable, sizeof(enable));
|
||||
#endif
|
||||
|
||||
#ifdef USE_SOCKET_TIMEOUT
|
||||
/* init socket options */
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
ESP_LOGI(TAG, "setsockopt timeout ");
|
||||
struct timeval timeout;
|
||||
timeout.tv_sec = 1000; // 10 seconds
|
||||
timeout.tv_usec = 0;
|
||||
|
||||
ESP_LOGI(TAG, "setsockopt timeout %d seconds", (int)timeout.tv_sec);
|
||||
|
||||
if (setsockopt(listenfd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) == -1) {
|
||||
ESP_LOGE(TAG, "setsockopt for receive timeout");
|
||||
ret = WOLFSSL_FATAL_ERROR;
|
||||
}
|
||||
if (setsockopt(listenfd, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout)) == -1) {
|
||||
ESP_LOGE(TAG, "setsockopt for send timeout");
|
||||
ret = WOLFSSL_FATAL_ERROR;
|
||||
}
|
||||
} /* soctet options */
|
||||
#endif
|
||||
|
||||
/* Bind Socket */
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
if (bind(listenfd, (struct sockaddr*)&servAddr, sizeof(servAddr)) < 0) {
|
||||
ESP_LOGE(TAG, "bind()");
|
||||
ret = WOLFSSL_FATAL_ERROR;
|
||||
}
|
||||
} /* bind socket */
|
||||
|
||||
#ifndef WOLFSSL_ESPIDF
|
||||
/* Signals and signal handling are not implemented in esp-idf.
|
||||
* Calling raise() will abort the program.
|
||||
* see https://esp32.com/viewtopic.php?t=29988&p=103871 */
|
||||
signal(SIGINT, sig_handler);
|
||||
#endif
|
||||
|
||||
ESP_LOGI(TAG, "While Stack used: %d words", TLS_SMP_SERVER_TASK_WORDS
|
||||
- (uxTaskGetStackHighWaterMark(NULL)));
|
||||
ShowStackInfo("While Stack");
|
||||
while (1) {
|
||||
ESP_LOGI(TAG, "\n\nAwaiting client connection on port %d\n", SERV_PORT);
|
||||
|
||||
cliLen = sizeof(cliaddr);
|
||||
ret = (int)recvfrom(listenfd,
|
||||
(char *)&buff, sizeof(buff),
|
||||
MSG_PEEK,
|
||||
(struct sockaddr*)&cliaddr, &cliLen
|
||||
);
|
||||
|
||||
if (ret < 0) {
|
||||
ESP_LOGE(TAG, "ERROR during recvfrom()");
|
||||
goto cleanup;
|
||||
}
|
||||
else if (ret == 0) {
|
||||
ESP_LOGE(TAG, "recvfrom zero return\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* Create the WOLFSSL Object */
|
||||
if ((ssl = wolfSSL_new(ctx)) == NULL) {
|
||||
ESP_LOGE(TAG, "wolfSSL_new error.\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (wolfSSL_dtls_set_peer(ssl, &cliaddr, cliLen) != WOLFSSL_SUCCESS) {
|
||||
ESP_LOGE(TAG, "wolfSSL_dtls_set_peer error.\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
#if defined(WOLFSSL_SM2)
|
||||
/* SM TLS1.3 Cipher needs to have key share explicitly set. */
|
||||
ESP_LOGI(TAG, "Setting WOLFSSL_ECC_SM2P256V1");
|
||||
ret = wolfSSL_UseKeyShare(ssl, WOLFSSL_ECC_SM2P256V1);
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
ESP_LOGI(TAG, "Successfully set WOLFSSL_ECC_SM2P256V1");
|
||||
}
|
||||
else {
|
||||
ESP_LOGE(TAG, "FAILED to set WOLFSSL_ECC_SM2P256V1");
|
||||
}
|
||||
#endif
|
||||
|
||||
ESP_LOGI(TAG, "Listen...");
|
||||
if (wolfSSL_set_fd(ssl, listenfd) != WOLFSSL_SUCCESS) {
|
||||
ESP_LOGE(TAG, "wolfSSL_set_fd error.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Accept..");
|
||||
if (wolfSSL_accept(ssl) != SSL_SUCCESS) {
|
||||
err = wolfSSL_get_error(ssl, 0);
|
||||
ESP_LOGE(TAG, "error = %d, %s\n", err, wolfSSL_ERR_reason_error_string(err));
|
||||
ESP_LOGE(TAG, "SSL_accept failed.\n");
|
||||
goto cleanup;
|
||||
}
|
||||
showConnInfo(ssl);
|
||||
while (1) {
|
||||
if ((recvLen = wolfSSL_read(ssl, buff, sizeof(buff)-1)) > 0) {
|
||||
ESP_LOGI(TAG, "wolfSSL_read heard %d bytes:\n\n"
|
||||
"%s", recvLen, buff);
|
||||
|
||||
buff[recvLen] = '\0';
|
||||
}
|
||||
else if (recvLen <= 0) {
|
||||
err = wolfSSL_get_error(ssl, 0);
|
||||
if (err == WOLFSSL_ERROR_ZERO_RETURN) { /* Received shutdown */
|
||||
break;
|
||||
}
|
||||
ESP_LOGE(TAG, "error = %d, %s\n",
|
||||
err, wolfSSL_ERR_reason_error_string(err));
|
||||
ESP_LOGE(TAG, "SSL_read failed.\n");
|
||||
goto cleanup;
|
||||
}
|
||||
ESP_LOGI(TAG, "Sending reply (check client for this text): %s",
|
||||
ack);
|
||||
if (wolfSSL_write(ssl, ack, sizeof(ack)) < 0) {
|
||||
err = wolfSSL_get_error(ssl, 0);
|
||||
ESP_LOGE(TAG, "error = %d, %s\n",
|
||||
err, wolfSSL_ERR_reason_error_string(err));
|
||||
ESP_LOGE(TAG, "wolfSSL_write failed.\n");
|
||||
goto cleanup;
|
||||
}
|
||||
ESP_LOGI(TAG, "Sending complete. Waiting for next message...");
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "reply sent \"%s\"\n", ack);
|
||||
|
||||
/* Attempt a full shutdown */
|
||||
ret = wolfSSL_shutdown(ssl);
|
||||
if (ret == WOLFSSL_SHUTDOWN_NOT_DONE) {
|
||||
ESP_LOGW(TAG, "WARNING: wolfSSL_shutdown not done the first "
|
||||
"time. Trying again...");
|
||||
ret = wolfSSL_shutdown(ssl);
|
||||
}
|
||||
if (ret != WOLFSSL_SUCCESS) {
|
||||
err = wolfSSL_get_error(ssl, 0);
|
||||
ESP_LOGE(TAG, "err = %d, %s\n",
|
||||
err, wolfSSL_ERR_reason_error_string(err));
|
||||
ESP_LOGE(TAG, "wolfSSL_shutdown failed\n");
|
||||
}
|
||||
wolfSSL_free(ssl);
|
||||
ssl = NULL;
|
||||
|
||||
ESP_LOGI(TAG, "Awaiting new connection\n");
|
||||
}
|
||||
|
||||
cleanup:
|
||||
free_resources();
|
||||
wolfSSL_Cleanup();
|
||||
|
||||
#if defined(SINGLE_THREADED)
|
||||
ESP_LOGV(TAG, "\n\nDone!\n\n");
|
||||
return TLS_SMP_SERVER_TASK_RET;
|
||||
#else
|
||||
ESP_LOGI(TAG, "\n\nvTaskDelete dtls13_smp_server_task...\n\n");
|
||||
vTaskDelay(1000);
|
||||
vTaskDelete(NULL);
|
||||
|
||||
/* if successful vTaskDelete, we should never get here: */
|
||||
ESP_LOGI(TAG, "\n\nvTaskDelete Complete, but failed?...\n\n");
|
||||
|
||||
vTaskDelay(60000);
|
||||
#endif
|
||||
|
||||
return TLS_SMP_SERVER_TASK_RET;
|
||||
}
|
||||
|
||||
#ifndef WOLFSSL_ESPIDF
|
||||
static void sig_handler(const int sig)
|
||||
{
|
||||
(void)sig;
|
||||
free_resources();
|
||||
wolfSSL_Cleanup();
|
||||
}
|
||||
#endif
|
||||
|
||||
static void free_resources(void)
|
||||
{
|
||||
if (ssl != NULL) {
|
||||
wolfSSL_shutdown(ssl);
|
||||
wolfSSL_free(ssl);
|
||||
ssl = NULL;
|
||||
}
|
||||
if (ctx != NULL) {
|
||||
wolfSSL_CTX_free(ctx);
|
||||
ctx = NULL;
|
||||
}
|
||||
if (listenfd != INVALID_SOCKET) {
|
||||
close(listenfd);
|
||||
listenfd = INVALID_SOCKET;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(SINGLE_THREADED)
|
||||
/* we don't initialize a thread */
|
||||
#else
|
||||
/* create task */
|
||||
int dtls13_smp_server_init(int port)
|
||||
{
|
||||
int ret = 0;
|
||||
int thisPort;
|
||||
thisPort = port;
|
||||
if (thisPort == 0) {
|
||||
thisPort = DEFAULT_PORT;
|
||||
}
|
||||
|
||||
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||
TaskHandle_t _handle;
|
||||
#else
|
||||
xTaskHandle _handle;
|
||||
#endif
|
||||
|
||||
/* see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/freertos_idf.html */
|
||||
ESP_LOGI(TAG, "Creating dtls13_smp_server_task with stack size = %d words",
|
||||
TLS_SMP_SERVER_TASK_WORDS);
|
||||
ret = xTaskCreate(dtls13_smp_server_task,
|
||||
TLS_SMP_SERVER_TASK_NAME,
|
||||
TLS_SMP_SERVER_TASK_WORDS, /* not bytes! */
|
||||
(void*)&thisPort,
|
||||
TLS_SMP_SERVER_TASK_PRIORITY,
|
||||
&_handle);
|
||||
|
||||
if (ret == pdPASS) {
|
||||
ESP_LOGI(TAG, "Success: create thread %s", TLS_SMP_SERVER_TASK_NAME);
|
||||
}
|
||||
else {
|
||||
ESP_LOGE(TAG, "create thread %s failed", TLS_SMP_SERVER_TASK_NAME);
|
||||
}
|
||||
|
||||
/* vTaskStartScheduler(); note needed; called automatically in ESP-IDF */
|
||||
return ret;
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,446 @@
|
|||
/* server-dtls13.c
|
||||
*
|
||||
* Copyright (C) 2006-2022 wolfSSL Inc.
|
||||
*
|
||||
* This file is part of wolfSSL. (formerly known as CyaSSL)
|
||||
*
|
||||
* 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-1301, USA
|
||||
*
|
||||
*=============================================================================
|
||||
*
|
||||
* Bare-bones example of a DTLS 1.3 server for instructional/learning purposes.
|
||||
* This example can only accept one connection at a time.
|
||||
*
|
||||
* Define USE_DTLS12 to use DTLS 1.2 instead of DTLS 1.3
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code was adapted from the wolfSSL/wolfssl-examples/dtls located at:
|
||||
*
|
||||
* https://github.com/wolfSSL/wolfssl-examples/blob/master/dtls/client-dtls13.c
|
||||
*/
|
||||
#include "server-dtls13.h"
|
||||
|
||||
#if defined(SINGLE_THREADED)
|
||||
#define WOLFSSL_ESP_TASK int
|
||||
#else
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#define WOLFSSL_ESP_TASK static void
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <sys/param.h>
|
||||
#include "esp_system.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "esp_netif.h"
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/sys.h"
|
||||
#include <lwip/netdb.h>
|
||||
|
||||
/* wolfSSL */
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
#include "user_settings.h"
|
||||
|
||||
#include <wolfssl/ssl.h>
|
||||
#include <errno.h>
|
||||
#include <wolfssl/certs_test.h>
|
||||
|
||||
/* this app */
|
||||
#include "dtls-common.h"
|
||||
|
||||
/* convert macros values to string */
|
||||
#define STRINGIFY(x) #x
|
||||
|
||||
static const char* const TAG = "server-dtls13";
|
||||
|
||||
WOLFSSL_CTX* ctx = NULL;
|
||||
WOLFSSL* ssl = NULL;
|
||||
int listenfd = INVALID_SOCKET; /* Initialize our socket */
|
||||
|
||||
/* Note: not implemented at this time:
|
||||
* static void sig_handler(const int sig); */
|
||||
|
||||
static void free_resources(void);
|
||||
|
||||
/* show stack space for this task */
|
||||
static int ShowStackInfo(char* msg)
|
||||
{
|
||||
int ret;
|
||||
ret = TLS_SMP_SERVER_TASK_WORDS - (uxTaskGetStackHighWaterMark(NULL));
|
||||
ESP_LOGI(TAG, "%s: %d words", msg, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if 0
|
||||
int main(int argc, char** argv)
|
||||
#else
|
||||
WOLFSSL_ESP_TASK dtls13_smp_server_task(void *pvParameters)
|
||||
#endif
|
||||
{
|
||||
/* Loc short for "location" */
|
||||
#if defined(SINGLE_THREADED)
|
||||
#define TLS_SMP_SERVER_TASK_RET exitVal
|
||||
#else
|
||||
#define TLS_SMP_SERVER_TASK_RET
|
||||
#endif
|
||||
char buff[MAXLINE]; /* the incoming message */
|
||||
char ack[] = "I hear you fashizzle!\n";
|
||||
struct sockaddr_in servAddr = { 0 }; /* our server's address */
|
||||
struct sockaddr_in cliaddr = { 0 }; /* the client's address */
|
||||
socklen_t cliLen;
|
||||
int ret;
|
||||
int err;
|
||||
int recvLen = 0; /* length of message */
|
||||
int exitVal = 0;
|
||||
int ip_protocol = 0;
|
||||
exitVal = 1;
|
||||
|
||||
ESP_LOGI(TAG, "Init Stack: %d words", TLS_SMP_SERVER_TASK_WORDS);
|
||||
ShowStackInfo("Begin Stack used");
|
||||
|
||||
/* Initialize wolfSSL before assigning ctx */
|
||||
ret = wolfSSL_Init();
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
ESP_LOGI(TAG, "wolfSSL_Init success.");
|
||||
}
|
||||
else {
|
||||
ESP_LOGE(TAG, "wolfSSL_Init error %d.\n", ret);
|
||||
return TLS_SMP_SERVER_TASK_RET;
|
||||
}
|
||||
|
||||
/* Create new conext ctx & show some diagnostics */
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
ShowStackInfo("Init Stack used");
|
||||
|
||||
/* No-op when debugging is not compiled in */
|
||||
wolfSSL_Debugging_ON();
|
||||
|
||||
/* Set ctx to DTLS 1.3 unless DTLS1.2 explicitly enabled */
|
||||
#ifndef USE_DTLS12
|
||||
ESP_LOGI(TAG, "wolfSSL_CTX_new(wolfDTLSv1_3_server_method())");
|
||||
ctx = wolfSSL_CTX_new(wolfDTLSv1_3_server_method());
|
||||
#else
|
||||
ESP_LOGI(TAG, "wolfSSL_CTX_new(wolfDTLSv1_2_server_method())");
|
||||
ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method());
|
||||
#endif
|
||||
if(ctx == NULL) {
|
||||
ESP_LOGE(TAG, "wolfSSL_CTX_new error.\n");
|
||||
ret = WOLFSSL_FATAL_ERROR;
|
||||
}
|
||||
|
||||
(void)ctx;
|
||||
ShowStackInfo("Init ctx Stack used");
|
||||
} /* new ctx */
|
||||
|
||||
#ifdef NO_FILESYSTEM
|
||||
/* Load CA certificates */
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
/* caCertLoc[] = "../certs/ca-cert.pem"; */
|
||||
ret = wolfSSL_CTX_load_verify_buffer(ctx,
|
||||
CTX_CA_CERT,
|
||||
CTX_CA_CERT_SIZE,
|
||||
CTX_SERVER_CERT_TYPE);
|
||||
}
|
||||
|
||||
/* if successful, Load server certificates */
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
ESP_LOGI(TAG, "Success: wolfSSL_CTX_load_verify_buffer loaded %s",
|
||||
STRINGIFY(CTX_CA_CERT));
|
||||
|
||||
/* servCertLoc[] = "../certs/server-cert.pem"; */
|
||||
ret = wolfSSL_CTX_use_certificate_buffer(ctx,
|
||||
CTX_SERVER_CERT,
|
||||
CTX_SERVER_CERT_SIZE,
|
||||
CTX_SERVER_CERT_TYPE);
|
||||
}
|
||||
else {
|
||||
ESP_LOGE(TAG, "Failed CA wolfSSL_CTX_load_verify_buffer "
|
||||
"loading CA %s", STRINGIFY(CTX_SERVER_CERT));
|
||||
}
|
||||
|
||||
/* if successful Load server Keys */
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
ESP_LOGI(TAG, "Success: "
|
||||
"wolfSSL_CTX_use_certificate_chain_buffer_format "
|
||||
"loaded cert chain %s", STRINGIFY(CTX_SERVER_CERT));
|
||||
/* servKeyLoc[] = "../certs/server-key.pem"; */
|
||||
ret = wolfSSL_CTX_use_PrivateKey_buffer(ctx,
|
||||
CTX_SERVER_KEY,
|
||||
CTX_SERVER_KEY_SIZE,
|
||||
CTX_SERVER_KEY_TYPE);
|
||||
}
|
||||
else {
|
||||
ESP_LOGE(TAG, "Failed wolfSSL_CTX_use_certificate_chain_buffer_format "
|
||||
"loading private key %s", STRINGIFY(CTX_SERVER_KEY));
|
||||
}
|
||||
|
||||
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
ESP_LOGI(TAG, "Success: "
|
||||
"wolfSSL_CTX_use_PrivateKey_buffer "
|
||||
"loaded private key %s", STRINGIFY(CTX_SERVER_KEY));
|
||||
}
|
||||
else {
|
||||
ESP_LOGE(TAG, "Failed to load private key: %s",
|
||||
STRINGIFY(CTX_SERVER_KEY));
|
||||
}
|
||||
#else
|
||||
/* Load CA certificates */
|
||||
if (wolfSSL_CTX_load_verify_locations(ctx,caCertLoc,0) !=
|
||||
SSL_SUCCESS) {
|
||||
ESP_LOGE(TAG, "Error loading %s, please check the file.\n", caCertLoc);
|
||||
goto cleanup;
|
||||
}
|
||||
/* Load server certificates */
|
||||
if (wolfSSL_CTX_use_certificate_file(ctx, servCertLoc, SSL_FILETYPE_PEM) !=
|
||||
SSL_SUCCESS) {
|
||||
ESP_LOGE(TAG, "Error loading %s, please check the file.\n", servCertLoc);
|
||||
goto cleanup;
|
||||
}
|
||||
/* Load server Keys */
|
||||
if (wolfSSL_CTX_use_PrivateKey_file(ctx, servKeyLoc,
|
||||
SSL_FILETYPE_PEM) != SSL_SUCCESS) {
|
||||
ESP_LOGE(TAG, "Error loading %s, please check the file.\n", servKeyLoc);
|
||||
goto cleanup;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* initialize network vars */
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
memset((char *)&servAddr, 0, sizeof(servAddr));
|
||||
/* host-to-network-long conversion (htonl) */
|
||||
/* host-to-network-short conversion (htons) */
|
||||
servAddr.sin_family = AF_INET;
|
||||
servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
servAddr.sin_port = htons(SERV_PORT);
|
||||
ip_protocol = IPPROTO_IP;
|
||||
|
||||
/* Create a UDP/IP socket */
|
||||
listenfd = socket(AF_INET, SOCK_DGRAM, ip_protocol);
|
||||
if (listenfd < 0) {
|
||||
ESP_LOGE(TAG, "socket() failed: %d", listenfd);
|
||||
ret = WOLFSSL_FATAL_ERROR;
|
||||
}
|
||||
else {
|
||||
ESP_LOGI(TAG, "Socket allocated.");
|
||||
}
|
||||
} /* init network vars */
|
||||
|
||||
#if defined(CONFIG_LWIP_NETBUF_RECVINFO) && !defined(CONFIG_EXAMPLE_IPV6)
|
||||
int enable = 1;
|
||||
lwip_setsockopt(sock, IPPROTO_IP, IP_PKTINFO, &enable, sizeof(enable));
|
||||
#endif
|
||||
|
||||
/* init socket options */
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
ESP_LOGI(TAG, "setsockopt timeout ");
|
||||
struct timeval timeout;
|
||||
timeout.tv_sec = 1000; // 10 seconds
|
||||
timeout.tv_usec = 0;
|
||||
|
||||
ESP_LOGI(TAG, "setsockopt timeout %d seconds", (int)timeout.tv_sec);
|
||||
|
||||
if (setsockopt(listenfd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) == -1) {
|
||||
ESP_LOGE(TAG, "setsockopt for receive timeout");
|
||||
ret = WOLFSSL_FATAL_ERROR;
|
||||
}
|
||||
if (setsockopt(listenfd, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout)) == -1) {
|
||||
ESP_LOGE(TAG, "setsockopt for send timeout");
|
||||
ret = WOLFSSL_FATAL_ERROR;
|
||||
}
|
||||
} /* soctet options */
|
||||
|
||||
/* Bind Socket */
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
if (bind(listenfd, (struct sockaddr*)&servAddr, sizeof(servAddr)) < 0) {
|
||||
ESP_LOGE(TAG, "bind()");
|
||||
ret = WOLFSSL_FATAL_ERROR;
|
||||
}
|
||||
} /* bind socket */
|
||||
|
||||
#ifndef WOLFSSL_ESPIDF
|
||||
/* Signals and signal handling are not implemented in esp-idf.
|
||||
* Calling raise() will abort the program.
|
||||
* see https://esp32.com/viewtopic.php?t=29988&p=103871 */
|
||||
signal(SIGINT, sig_handler);
|
||||
#endif
|
||||
|
||||
ESP_LOGI(TAG, "While Stack used: %d words", TLS_SMP_SERVER_TASK_WORDS
|
||||
- (uxTaskGetStackHighWaterMark(NULL)));
|
||||
while (1) {
|
||||
printf("Awaiting client connection on port %d\n", SERV_PORT);
|
||||
|
||||
cliLen = sizeof(cliaddr);
|
||||
ret = (int)recvfrom(listenfd, (char *)&buff, sizeof(buff), MSG_PEEK,
|
||||
(struct sockaddr*)&cliaddr, &cliLen);
|
||||
|
||||
if (ret < 0) {
|
||||
perror("recvfrom()");
|
||||
goto cleanup;
|
||||
}
|
||||
else if (ret == 0) {
|
||||
fprintf(stderr, "recvfrom zero return\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* Create the WOLFSSL Object */
|
||||
if ((ssl = wolfSSL_new(ctx)) == NULL) {
|
||||
fprintf(stderr, "wolfSSL_new error.\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (wolfSSL_dtls_set_peer(ssl, &cliaddr, cliLen) != WOLFSSL_SUCCESS) {
|
||||
fprintf(stderr, "wolfSSL_dtls_set_peer error.\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (wolfSSL_set_fd(ssl, listenfd) != WOLFSSL_SUCCESS) {
|
||||
fprintf(stderr, "wolfSSL_set_fd error.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if (wolfSSL_accept(ssl) != SSL_SUCCESS) {
|
||||
err = wolfSSL_get_error(ssl, 0);
|
||||
fprintf(stderr, "error = %d, %s\n", err, wolfSSL_ERR_reason_error_string(err));
|
||||
fprintf(stderr, "SSL_accept failed.\n");
|
||||
goto cleanup;
|
||||
}
|
||||
showConnInfo(ssl);
|
||||
while (1) {
|
||||
if ((recvLen = wolfSSL_read(ssl, buff, sizeof(buff)-1)) > 0) {
|
||||
printf("heard %d bytes\n", recvLen);
|
||||
|
||||
buff[recvLen] = '\0';
|
||||
printf("I heard this: \"%s\"\n", buff);
|
||||
}
|
||||
else if (recvLen <= 0) {
|
||||
err = wolfSSL_get_error(ssl, 0);
|
||||
if (err == WOLFSSL_ERROR_ZERO_RETURN) /* Received shutdown */
|
||||
break;
|
||||
fprintf(stderr, "error = %d, %s\n", err, wolfSSL_ERR_reason_error_string(err));
|
||||
fprintf(stderr, "SSL_read failed.\n");
|
||||
goto cleanup;
|
||||
}
|
||||
printf("Sending reply.\n");
|
||||
if (wolfSSL_write(ssl, ack, sizeof(ack)) < 0) {
|
||||
err = wolfSSL_get_error(ssl, 0);
|
||||
fprintf(stderr, "error = %d, %s\n", err, wolfSSL_ERR_reason_error_string(err));
|
||||
fprintf(stderr, "wolfSSL_write failed.\n");
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
printf("reply sent \"%s\"\n", ack);
|
||||
|
||||
/* Attempt a full shutdown */
|
||||
ret = wolfSSL_shutdown(ssl);
|
||||
if (ret == WOLFSSL_SHUTDOWN_NOT_DONE)
|
||||
ret = wolfSSL_shutdown(ssl);
|
||||
if (ret != WOLFSSL_SUCCESS) {
|
||||
err = wolfSSL_get_error(ssl, 0);
|
||||
fprintf(stderr, "err = %d, %s\n", err, wolfSSL_ERR_reason_error_string(err));
|
||||
fprintf(stderr, "wolfSSL_shutdown failed\n");
|
||||
}
|
||||
wolfSSL_free(ssl);
|
||||
ssl = NULL;
|
||||
|
||||
printf("Awaiting new connection\n");
|
||||
}
|
||||
ESP_LOGI(TAG, "Exit %d", exitVal);
|
||||
exitVal = 0;
|
||||
cleanup:
|
||||
// free_resources();
|
||||
wolfSSL_Cleanup();
|
||||
|
||||
vTaskDelete(NULL);
|
||||
|
||||
return TLS_SMP_SERVER_TASK_RET;
|
||||
}
|
||||
|
||||
|
||||
#ifndef WOLFSSL_ESPIDF
|
||||
static void sig_handler(const int sig)
|
||||
{
|
||||
(void)sig;
|
||||
free_resources();
|
||||
wolfSSL_Cleanup();
|
||||
}
|
||||
#endif
|
||||
|
||||
static void free_resources(void)
|
||||
{
|
||||
if (ssl != NULL) {
|
||||
wolfSSL_shutdown(ssl);
|
||||
wolfSSL_free(ssl);
|
||||
ssl = NULL;
|
||||
}
|
||||
if (ctx != NULL) {
|
||||
wolfSSL_CTX_free(ctx);
|
||||
ctx = NULL;
|
||||
}
|
||||
if (listenfd != INVALID_SOCKET) {
|
||||
close(listenfd);
|
||||
listenfd = INVALID_SOCKET;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(SINGLE_THREADED)
|
||||
/* we don't initialize a thread */
|
||||
#else
|
||||
/* create task */
|
||||
int dtls13_smp_server_init(int port)
|
||||
{
|
||||
int ret = 0;
|
||||
int thisPort;
|
||||
thisPort = port;
|
||||
if (thisPort == 0) {
|
||||
thisPort = DEFAULT_PORT;
|
||||
}
|
||||
|
||||
|
||||
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||
TaskHandle_t _handle;
|
||||
#else
|
||||
xTaskHandle _handle;
|
||||
#endif
|
||||
|
||||
/* http://esp32.info/docs/esp_idf/html/dd/d3c/group__xTaskCreate.html */
|
||||
ESP_LOGI(TAG, "Creating dtls13_smp_server_task with stack size = %d words",
|
||||
TLS_SMP_SERVER_TASK_WORDS);
|
||||
ret = xTaskCreate(dtls13_smp_server_task,
|
||||
TLS_SMP_SERVER_TASK_NAME,
|
||||
TLS_SMP_SERVER_TASK_WORDS, /* not bytes! */
|
||||
(void*)&thisPort,
|
||||
TLS_SMP_SERVER_TASK_PRIORITY,
|
||||
NULL);
|
||||
|
||||
if (ret == pdPASS) {
|
||||
ESP_LOGI(TAG, "Success: create thread %s", TLS_SMP_SERVER_TASK_NAME);
|
||||
}
|
||||
else {
|
||||
ESP_LOGE(TAG, "create thread %s failed", TLS_SMP_SERVER_TASK_NAME);
|
||||
}
|
||||
|
||||
/* vTaskStartScheduler(); // called automatically in ESP-IDF */
|
||||
return ret;
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,247 @@
|
|||
/* time_helper.c
|
||||
*
|
||||
* Copyright (C) 2006-2023 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 tag is used to include this file in the ESP Component Registry:
|
||||
# __ESP_COMPONENT_SOURCE__
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <lwip/apps/sntp.h>
|
||||
#include <esp_netif_sntp.h>
|
||||
#include "sdkconfig.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
#include "time_helper.h"
|
||||
|
||||
const static char* TAG = "time_helper";
|
||||
|
||||
#define TIME_ZONE "PST-8"
|
||||
/* NELEMS(x) number of elements
|
||||
* To determine the number of elements in the array, we can divide the total size of
|
||||
* the array by the size of the array element
|
||||
* See https://stackoverflow.com/questions/37538/how-do-i-determine-the-size-of-my-array-in-c
|
||||
**/
|
||||
#define NELEMS(x) ( (int)(sizeof(x) / sizeof((x)[0])) )
|
||||
#define NTP_SERVER_LIST ( (char*[]) { \
|
||||
"pool.ntp.org", \
|
||||
"time.nist.gov", \
|
||||
"utcnist.colorado.edu" \
|
||||
} \
|
||||
)
|
||||
/* #define NTP_SERVER_COUNT using NELEMS:
|
||||
*
|
||||
* (int)(sizeof(NTP_SERVER_LIST) / sizeof(NTP_SERVER_LIST[0]))
|
||||
*/
|
||||
#define NTP_SERVER_COUNT NELEMS(NTP_SERVER_LIST)
|
||||
char* ntpServerList[NTP_SERVER_COUNT] = NTP_SERVER_LIST;
|
||||
|
||||
/* our NTP server list is global info */
|
||||
extern char* ntpServerList[NTP_SERVER_COUNT];
|
||||
|
||||
/* the worst-case scenario is a hard-coded date/time */
|
||||
int set_fixed_default_time()
|
||||
{
|
||||
time_t interim_time;
|
||||
|
||||
/* ideally, we'd like to set time from network,
|
||||
* but let's set a default time, just in case */
|
||||
struct tm timeinfo = {
|
||||
.tm_year = 2023 - 1900,
|
||||
.tm_mon = 9,
|
||||
.tm_mday = 4,
|
||||
.tm_hour = 19,
|
||||
.tm_min = 4,
|
||||
.tm_sec = 0
|
||||
};
|
||||
struct timeval now;
|
||||
/* set interim static time */
|
||||
interim_time = mktime(&timeinfo);
|
||||
now = (struct timeval){ .tv_sec = interim_time };
|
||||
settimeofday(&now, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* set_time_from_string
|
||||
*
|
||||
* returns 0 = success if able to set the time from the provided string
|
||||
* error for any other value, typically -1 */
|
||||
int set_time_from_string(char* time_buffer)
|
||||
{
|
||||
/* expecting github default formatting: 'Thu Aug 31 12:41:45 2023 -0700' */
|
||||
const char *format = "%3s %3s %d %d:%d:%d %d %s";
|
||||
struct tm this_timeinfo;
|
||||
struct timeval now;
|
||||
time_t interim_time;
|
||||
char day_str[4];
|
||||
char month_str[4];
|
||||
char offset[6]; /* expecting trailing single quote, not used */
|
||||
int day, year, hour, minute, second;
|
||||
int quote_offset = 0;
|
||||
int ret = 0;
|
||||
|
||||
/* we are expecting the string to be encapsulated in single quotes */
|
||||
if (*time_buffer == 0x27) {
|
||||
quote_offset = 1;
|
||||
}
|
||||
|
||||
ret = sscanf(time_buffer + quote_offset,
|
||||
format,
|
||||
day_str, month_str,
|
||||
&day, &hour, &minute, &second, &year, &offset);
|
||||
|
||||
if (ret == 8) {
|
||||
/* we found a match for all componets */
|
||||
|
||||
const char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
|
||||
|
||||
for (int i = 0; i < 12; i++) {
|
||||
if (strcmp(month_str, months[i]) == 0) {
|
||||
this_timeinfo.tm_mon = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this_timeinfo.tm_mday = day;
|
||||
this_timeinfo.tm_hour = hour;
|
||||
this_timeinfo.tm_min = minute;
|
||||
this_timeinfo.tm_sec = second;
|
||||
this_timeinfo.tm_year = year - 1900; /* Number of years since 1900 */
|
||||
|
||||
interim_time = mktime(&this_timeinfo);
|
||||
now = (struct timeval){ .tv_sec = interim_time };
|
||||
settimeofday(&now, NULL);
|
||||
ESP_LOGI(TAG, "Time updated to %s", time_buffer);
|
||||
ret = 0; /* success */
|
||||
}
|
||||
else {
|
||||
ret = -1;
|
||||
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();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* set time; returns 0 if succecssfully configured with NTP */
|
||||
int set_time(void)
|
||||
{
|
||||
/* we'll also return a result code of zero */
|
||||
int res = 0;
|
||||
int i = 0; /* counter for time servers */
|
||||
|
||||
#ifdef LIBWOLFSSL_VERSION_GIT_HASH_DATE
|
||||
/* initialy set a default approximate time from recent git commit */
|
||||
ESP_LOGI(TAG, "Found git hash date, attempting to set system date.");
|
||||
set_time_from_string(LIBWOLFSSL_VERSION_GIT_HASH_DATE);
|
||||
|
||||
res = -4;
|
||||
#else
|
||||
/* otherwise set a fixed time that was hard coded */
|
||||
set_fixed_default_time();
|
||||
res = -3;
|
||||
#endif
|
||||
|
||||
#ifndef NTP_SERVER_COUNT
|
||||
ESP_LOGW(TAG, "WArning: no sntp server names defined. Setting to empty list");
|
||||
#define NTP_SERVER_COUNT 0
|
||||
char* ntpServerList[NTP_SERVER_COUNT];
|
||||
#endif /* not defined: NTP_SERVER_COUNT */
|
||||
|
||||
#ifndef TIME_ZONE
|
||||
#define TIME_ZONE "PST-8"
|
||||
#endif /* not defined: TIME_ZONE */
|
||||
|
||||
/* set timezone */
|
||||
setenv("TZ", TIME_ZONE, 1);
|
||||
tzset();
|
||||
|
||||
#if CONFIG_LWIP_SNTP_MAX_SERVERS > 1
|
||||
/* This demonstrates configuring more than one server
|
||||
*/
|
||||
esp_sntp_config_t config = ESP_NETIF_SNTP_DEFAULT_CONFIG_MULTIPLE(2,
|
||||
ESP_SNTP_SERVER_LIST(CONFIG_SNTP_TIME_SERVER, "pool.ntp.org" ) );
|
||||
#else
|
||||
/*
|
||||
* This is the basic default config with one server and starting the service
|
||||
*/
|
||||
esp_sntp_config_t config = ESP_NETIF_SNTP_DEFAULT_CONFIG(ntpServerList[0]);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SNTP_TIME_SYNC_METHOD_SMOOTH
|
||||
config.smooth_sync = true;
|
||||
#endif
|
||||
|
||||
if (NTP_SERVER_COUNT) {
|
||||
/* next, let's setup NTP time servers
|
||||
*
|
||||
* see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/system_time.html#sntp-time-synchronization
|
||||
*/
|
||||
sntp_setoperatingmode(SNTP_OPMODE_POLL);
|
||||
|
||||
ESP_LOGI(TAG, "sntp_setservername:");
|
||||
for (i = 0; i < NTP_SERVER_COUNT; i++) {
|
||||
const char* thisServer = ntpServerList[i];
|
||||
if (strncmp(thisServer, "\x00", 1) == 0) {
|
||||
/* just in case we run out of NTP servers */
|
||||
break;
|
||||
}
|
||||
ESP_LOGI(TAG, "%s", thisServer);
|
||||
sntp_setservername(i, thisServer);
|
||||
}
|
||||
esp_netif_sntp_init(&config);
|
||||
sntp_init();
|
||||
esp_netif_sntp_start();
|
||||
switch (res) {
|
||||
case ESP_ERR_INVALID_STATE:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
ESP_LOGI(TAG, "sntp_init done.");
|
||||
}
|
||||
else {
|
||||
ESP_LOGW(TAG, "No sntp time servers found.");
|
||||
res = -1;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/* wait for NTP to actually set the time */
|
||||
int set_time_wait_for_ntp(void)
|
||||
{
|
||||
int ret = 0;
|
||||
int ntp_retry = 0;
|
||||
const int ntp_retry_count = 2;
|
||||
ret = esp_netif_sntp_sync_wait(500 / portTICK_PERIOD_MS);
|
||||
|
||||
while (ret == ESP_ERR_TIMEOUT && ntp_retry++ < ntp_retry_count) {
|
||||
ret = esp_netif_sntp_sync_wait(2500 / portTICK_PERIOD_MS);
|
||||
ESP_LOGI(TAG, "Waiting for NTP to sync time... (%d/%d)",
|
||||
ntp_retry,
|
||||
ntp_retry_count);
|
||||
}
|
||||
ESP_LOGI(TAG, "set_time_wait_for_ntp result = 0x%0x: %s",
|
||||
ret, esp_err_to_name(ret));
|
||||
return ret;
|
||||
}
|
|
@ -0,0 +1,235 @@
|
|||
/* wifi_connect.c
|
||||
*
|
||||
* Copyright (C) 2006-2023 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
|
||||
*/
|
||||
#include "wifi_connect.h"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include <esp_wifi.h>
|
||||
#include <esp_log.h>
|
||||
|
||||
/* wolfSSL */
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
#include <user_settings.h>
|
||||
#include <wolfssl/version.h>
|
||||
#ifndef WOLFSSL_ESPIDF
|
||||
#warning "problem with wolfSSL user_settings. Check components/wolfssl/include"
|
||||
#endif
|
||||
|
||||
#if ESP_IDF_VERSION_MAJOR >= 5
|
||||
#elif ESP_IDF_VERSION_MAJOR >= 4
|
||||
#include "protocol_examples_common.h"
|
||||
#else
|
||||
const static int CONNECTED_BIT = BIT0;
|
||||
static EventGroupHandle_t wifi_event_group;
|
||||
#endif
|
||||
|
||||
/* breadcrumb prefix for logging */
|
||||
const static char *TAG = "dtls_server";
|
||||
|
||||
#if ESP_IDF_VERSION_MAJOR < 4
|
||||
/* event handler for wifi events */
|
||||
static esp_err_t wifi_event_handler(void *ctx, system_event_t *event)
|
||||
{
|
||||
switch (event->event_id)
|
||||
{
|
||||
case SYSTEM_EVENT_STA_START:
|
||||
esp_wifi_connect();
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_GOT_IP:
|
||||
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||
ESP_LOGI(TAG, "got ip:" IPSTR "\n",
|
||||
IP2STR(&event->event_info.got_ip.ip_info.ip));
|
||||
#else
|
||||
ESP_LOGI(TAG, "got ip:%s",
|
||||
ip4addr_ntoa(&event->event_info.got_ip.ip_info.ip));
|
||||
#endif
|
||||
/* see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/freertos_idf.html */
|
||||
xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_DISCONNECTED:
|
||||
esp_wifi_connect();
|
||||
xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
#else
|
||||
#define EXAMPLE_ESP_WIFI_SSID CONFIG_ESP_WIFI_SSID
|
||||
#define EXAMPLE_ESP_WIFI_PASS CONFIG_ESP_WIFI_PASSWORD
|
||||
|
||||
#ifdef CONFIG_ESP_MAXIMUM_RETRY
|
||||
#define EXAMPLE_ESP_MAXIMUM_RETRY CONFIG_ESP_MAXIMUM_RETRY
|
||||
#else
|
||||
#define CONFIG_ESP_MAXIMUM_RETRY 5
|
||||
#endif
|
||||
|
||||
|
||||
#if CONFIG_ESP_WIFI_AUTH_OPEN
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_OPEN
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WEP
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WEP
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WPA_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA_PSK
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WPA2_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_PSK
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WPA_WPA2_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA_WPA2_PSK
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WPA3_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA3_PSK
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WPA2_WPA3_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_WPA3_PSK
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WAPI_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WAPI_PSK
|
||||
#endif
|
||||
|
||||
#ifndef ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD
|
||||
#define CONFIG_ESP_WIFI_AUTH_WPA2_PSK 1
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD CONFIG_ESP_WIFI_AUTH_WPA2_PSK
|
||||
#endif
|
||||
|
||||
/* FreeRTOS event group to signal when we are connected*/
|
||||
static EventGroupHandle_t s_wifi_event_group;
|
||||
|
||||
/* The event group allows multiple bits for each event, but we only care about two events:
|
||||
* - we are connected to the AP with an IP
|
||||
* - we failed to connect after the maximum amount of retries */
|
||||
#define WIFI_CONNECTED_BIT BIT0
|
||||
#define WIFI_FAIL_BIT BIT1
|
||||
|
||||
|
||||
static int s_retry_num = 0;
|
||||
ip_event_got_ip_t* event;
|
||||
|
||||
|
||||
static void event_handler(void* arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void* event_data)
|
||||
{
|
||||
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
|
||||
esp_wifi_connect();
|
||||
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
|
||||
if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY) {
|
||||
esp_wifi_connect();
|
||||
s_retry_num++;
|
||||
ESP_LOGI(TAG, "retry to connect to the AP");
|
||||
} else {
|
||||
xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT);
|
||||
}
|
||||
ESP_LOGI(TAG,"connect to the AP fail");
|
||||
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
|
||||
event = (ip_event_got_ip_t*) event_data;
|
||||
wifi_show_ip();
|
||||
s_retry_num = 0;
|
||||
xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
|
||||
}
|
||||
}
|
||||
|
||||
int wifi_init_sta(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
s_wifi_event_group = xEventGroupCreate();
|
||||
|
||||
esp_netif_create_default_wifi_sta();
|
||||
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
|
||||
esp_event_handler_instance_t instance_any_id;
|
||||
esp_event_handler_instance_t instance_got_ip;
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
|
||||
ESP_EVENT_ANY_ID,
|
||||
&event_handler,
|
||||
NULL,
|
||||
&instance_any_id));
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT,
|
||||
IP_EVENT_STA_GOT_IP,
|
||||
&event_handler,
|
||||
NULL,
|
||||
&instance_got_ip));
|
||||
|
||||
wifi_config_t wifi_config = {
|
||||
.sta = {
|
||||
.ssid = EXAMPLE_ESP_WIFI_SSID,
|
||||
.password = EXAMPLE_ESP_WIFI_PASS,
|
||||
/* Authmode threshold resets to WPA2 as default if password matches
|
||||
* WPA2 standards (pasword len => 8). If you want to connect the
|
||||
* device to deprecated WEP/WPA networks, Please set the threshold
|
||||
* value WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK and set the password with
|
||||
* length and format matching to WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK
|
||||
* standards. */
|
||||
.threshold.authmode = ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD,
|
||||
.sae_pwe_h2e = WPA3_SAE_PWE_BOTH,
|
||||
},
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA) );
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config) );
|
||||
ESP_ERROR_CHECK(esp_wifi_start() );
|
||||
|
||||
ESP_LOGI(TAG, "wifi_init_sta finished.");
|
||||
|
||||
/* Waiting until either the connection is established (WIFI_CONNECTED_BIT)
|
||||
* or connection failed for the maximum number of re-tries (WIFI_FAIL_BIT).
|
||||
* The bits are set by event_handler() (see above) */
|
||||
EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group,
|
||||
WIFI_CONNECTED_BIT | WIFI_FAIL_BIT,
|
||||
pdFALSE,
|
||||
pdFALSE,
|
||||
portMAX_DELAY);
|
||||
|
||||
/* xEventGroupWaitBits() returns the bits before the call returned,
|
||||
* hence we can test which event actually happened. */
|
||||
#if defined(SHOW_SSID_AND_PASSWORD)
|
||||
ESP_LOGW(TAG, "Undefine SHOW_SSID_AND_PASSWORD to not show SSID/password");
|
||||
if (bits & WIFI_CONNECTED_BIT) {
|
||||
ESP_LOGI(TAG, "connected to ap SSID:%s password:%s",
|
||||
EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS);
|
||||
} else if (bits & WIFI_FAIL_BIT) {
|
||||
ESP_LOGI(TAG, "Failed to connect to SSID:%s, password:%s",
|
||||
EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "UNEXPECTED EVENT");
|
||||
}
|
||||
#else
|
||||
if (bits & WIFI_CONNECTED_BIT) {
|
||||
ESP_LOGI(TAG, "Connected to AP");
|
||||
} else if (bits & WIFI_FAIL_BIT) {
|
||||
ESP_LOGI(TAG, "Failed to connect to AP");
|
||||
ret = -1;
|
||||
} else {
|
||||
ESP_LOGE(TAG, "AP UNEXPECTED EVENT");
|
||||
ret = -2;
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wifi_show_ip(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip));
|
||||
return 0;
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,235 @@
|
|||
/* wifi_connect.c
|
||||
*
|
||||
* Copyright (C) 2006-2023 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
|
||||
*/
|
||||
/*ESP specific */
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "wifi_connect.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/netdb.h"
|
||||
#include "lwip/apps/sntp.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
/* wolfSSL */
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
#include <user_settings.h>
|
||||
#include <wolfssl/version.h>
|
||||
#ifndef WOLFSSL_ESPIDF
|
||||
#warning "problem with wolfSSL user_settings. Check components/wolfssl/include"
|
||||
#endif
|
||||
|
||||
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||
// #include "protocol_examples_common.h"
|
||||
#else
|
||||
const static int CONNECTED_BIT = BIT0;
|
||||
static EventGroupHandle_t wifi_event_group;
|
||||
#endif
|
||||
|
||||
/* breadcrumb prefix for logging */
|
||||
const static char *TAG = "tls_client";
|
||||
|
||||
#if ESP_IDF_VERSION_MAJOR < 4
|
||||
/* event handler for wifi events */
|
||||
static esp_err_t wifi_event_handler(void *ctx, system_event_t *event)
|
||||
{
|
||||
switch (event->event_id)
|
||||
{
|
||||
case SYSTEM_EVENT_STA_START:
|
||||
esp_wifi_connect();
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_GOT_IP:
|
||||
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||
ESP_LOGI(TAG, "got ip:" IPSTR "\n",
|
||||
IP2STR(&event->event_info.got_ip.ip_info.ip));
|
||||
#else
|
||||
ESP_LOGI(TAG, "got ip:%s",
|
||||
ip4addr_ntoa(&event->event_info.got_ip.ip_info.ip));
|
||||
#endif
|
||||
/* see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/freertos_idf.html */
|
||||
xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_DISCONNECTED:
|
||||
esp_wifi_connect();
|
||||
xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
#else
|
||||
#define EXAMPLE_ESP_WIFI_SSID CONFIG_ESP_WIFI_SSID
|
||||
#define EXAMPLE_ESP_WIFI_PASS CONFIG_ESP_WIFI_PASSWORD
|
||||
|
||||
#ifdef CONFIG_ESP_MAXIMUM_RETRY
|
||||
#define EXAMPLE_ESP_MAXIMUM_RETRY CONFIG_ESP_MAXIMUM_RETRY
|
||||
#else
|
||||
#define CONFIG_ESP_MAXIMUM_RETRY 5
|
||||
#endif
|
||||
|
||||
|
||||
#if CONFIG_ESP_WIFI_AUTH_OPEN
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_OPEN
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WEP
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WEP
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WPA_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA_PSK
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WPA2_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_PSK
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WPA_WPA2_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA_WPA2_PSK
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WPA3_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA3_PSK
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WPA2_WPA3_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_WPA3_PSK
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WAPI_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WAPI_PSK
|
||||
#endif
|
||||
|
||||
#ifndef ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD
|
||||
#define CONFIG_ESP_WIFI_AUTH_WPA2_PSK 1
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD CONFIG_ESP_WIFI_AUTH_WPA2_PSK
|
||||
#endif
|
||||
|
||||
/* FreeRTOS event group to signal when we are connected*/
|
||||
static EventGroupHandle_t s_wifi_event_group;
|
||||
|
||||
/* The event group allows multiple bits for each event, but we only care about two events:
|
||||
* - we are connected to the AP with an IP
|
||||
* - we failed to connect after the maximum amount of retries */
|
||||
#define WIFI_CONNECTED_BIT BIT0
|
||||
#define WIFI_FAIL_BIT BIT1
|
||||
|
||||
|
||||
static int s_retry_num = 0;
|
||||
ip_event_got_ip_t* event;
|
||||
|
||||
|
||||
static void event_handler(void* arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void* event_data)
|
||||
{
|
||||
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
|
||||
esp_wifi_connect();
|
||||
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
|
||||
if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY) {
|
||||
esp_wifi_connect();
|
||||
s_retry_num++;
|
||||
ESP_LOGI(TAG, "retry to connect to the AP");
|
||||
} else {
|
||||
xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT);
|
||||
}
|
||||
ESP_LOGI(TAG,"connect to the AP fail");
|
||||
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
|
||||
event = (ip_event_got_ip_t*) event_data;
|
||||
wifi_show_ip();
|
||||
s_retry_num = 0;
|
||||
xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
|
||||
}
|
||||
}
|
||||
|
||||
int wifi_init_sta(void)
|
||||
{
|
||||
int ret = 0;
|
||||
s_wifi_event_group = xEventGroupCreate();
|
||||
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
esp_netif_create_default_wifi_sta();
|
||||
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
|
||||
esp_event_handler_instance_t instance_any_id;
|
||||
esp_event_handler_instance_t instance_got_ip;
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
|
||||
ESP_EVENT_ANY_ID,
|
||||
&event_handler,
|
||||
NULL,
|
||||
&instance_any_id));
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT,
|
||||
IP_EVENT_STA_GOT_IP,
|
||||
&event_handler,
|
||||
NULL,
|
||||
&instance_got_ip));
|
||||
|
||||
wifi_config_t wifi_config = {
|
||||
.sta = {
|
||||
.ssid = EXAMPLE_ESP_WIFI_SSID,
|
||||
.password = EXAMPLE_ESP_WIFI_PASS,
|
||||
/* Authmode threshold resets to WPA2 as default if password matches
|
||||
* WPA2 standards (pasword len => 8). If you want to connect the
|
||||
* device to deprecated WEP/WPA networks, Please set the threshold
|
||||
* value WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK and set the password with
|
||||
* length and format matching to WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK
|
||||
* standards. */
|
||||
.threshold.authmode = ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD,
|
||||
.sae_pwe_h2e = WPA3_SAE_PWE_BOTH,
|
||||
},
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA) );
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config) );
|
||||
ESP_ERROR_CHECK(esp_wifi_start() );
|
||||
|
||||
ESP_LOGI(TAG, "wifi_init_sta finished.");
|
||||
|
||||
/* Waiting until either the connection is established (WIFI_CONNECTED_BIT)
|
||||
* or connection failed for the maximum number of re-tries (WIFI_FAIL_BIT).
|
||||
* The bits are set by event_handler() (see above) */
|
||||
EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group,
|
||||
WIFI_CONNECTED_BIT | WIFI_FAIL_BIT,
|
||||
pdFALSE,
|
||||
pdFALSE,
|
||||
portMAX_DELAY);
|
||||
|
||||
/* xEventGroupWaitBits() returns the bits before the call returned,
|
||||
* hence we can test which event actually happened. */
|
||||
#if defined(SHOW_SSID_AND_PASSWORD)
|
||||
ESP_LOGW(TAG, "Undefine SHOW_SSID_AND_PASSWORD to not show SSID/password");
|
||||
if (bits & WIFI_CONNECTED_BIT) {
|
||||
ESP_LOGI(TAG, "connected to ap SSID:%s password:%s",
|
||||
EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS);
|
||||
} else if (bits & WIFI_FAIL_BIT) {
|
||||
ESP_LOGI(TAG, "Failed to connect to SSID:%s, password:%s",
|
||||
EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "UNEXPECTED EVENT");
|
||||
}
|
||||
#else
|
||||
if (bits & WIFI_CONNECTED_BIT) {
|
||||
ESP_LOGI(TAG, "Connected to AP");
|
||||
} else if (bits & WIFI_FAIL_BIT) {
|
||||
ESP_LOGI(TAG, "Failed to connect to AP");
|
||||
ret = -1;
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Connect to AP UNEXPECTED EVENT");
|
||||
ret = -2;
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wifi_show_ip(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip));
|
||||
return 0;
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,31 @@
|
|||
# to view: idf.py partition-table
|
||||
#
|
||||
# ESP-IDF Partition Table
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
nvs, data, nvs, 0x9000, 24K,
|
||||
phy_init,data, phy, 0xf000, 4K,
|
||||
factory, app, factory, 0x10000, 1500K,
|
||||
|
||||
|
||||
# For other settings, see:
|
||||
# https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html#creating-custom-tables
|
||||
#
|
||||
# Here is the summary printed for the “Single factory app, no OTA” configuration:
|
||||
#
|
||||
# # ESP-IDF Partition Table
|
||||
# # Name, Type, SubType, Offset, Size, Flags
|
||||
# nvs, data, nvs, 0x9000, 0x6000,
|
||||
# phy_init, data, phy, 0xf000, 0x1000,
|
||||
# factory, app, factory, 0x10000, 1M,
|
||||
#
|
||||
#
|
||||
# Here is the summary printed for the “Factory app, two OTA definitions” configuration:
|
||||
#
|
||||
# # ESP-IDF Partition Table
|
||||
# # Name, Type, SubType, Offset, Size, Flags
|
||||
# nvs, data, nvs, 0x9000, 0x4000,
|
||||
# otadata, data, ota, 0xd000, 0x2000,
|
||||
# phy_init, data, phy, 0xf000, 0x1000,
|
||||
# factory, app, factory, 0x10000, 1M,
|
||||
# ota_0, app, ota_0, 0x110000, 1M,
|
||||
# ota_1, app, ota_1, 0x210000, 1M,
|
|
|
@ -0,0 +1,34 @@
|
|||
# This tag is used to include this file in the ESP Component Registry:
|
||||
# __ESP_COMPONENT_SOURCE__
|
||||
|
||||
# to view: idf.py partition-table
|
||||
#
|
||||
# ESP-IDF Partition Table
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
nvs, data, nvs, 0x9000, 24K,
|
||||
phy_init,data, phy, 0xf000, 4K,
|
||||
factory, app, factory, 0x10000, 1500K,
|
||||
|
||||
|
||||
# For other settings, see:
|
||||
# https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html#creating-custom-tables
|
||||
#
|
||||
# Here is the summary printed for the “Single factory app, no OTA” configuration:
|
||||
#
|
||||
# # ESP-IDF Partition Table
|
||||
# # Name, Type, SubType, Offset, Size, Flags
|
||||
# nvs, data, nvs, 0x9000, 0x6000,
|
||||
# phy_init, data, phy, 0xf000, 0x1000,
|
||||
# factory, app, factory, 0x10000, 1M,
|
||||
#
|
||||
#
|
||||
# Here is the summary printed for the “Factory app, two OTA definitions” configuration:
|
||||
#
|
||||
# # ESP-IDF Partition Table
|
||||
# # Name, Type, SubType, Offset, Size, Flags
|
||||
# nvs, data, nvs, 0x9000, 0x4000,
|
||||
# otadata, data, ota, 0xd000, 0x2000,
|
||||
# phy_init, data, phy, 0xf000, 0x1000,
|
||||
# factory, app, factory, 0x10000, 1M,
|
||||
# ota_0, app, ota_0, 0x110000, 1M,
|
||||
# ota_1, app, ota_1, 0x210000, 1M,
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,4 @@
|
|||
# This file was generated using idf.py save-defconfig. It can be edited manually.
|
||||
# Espressif IoT Development Framework (ESP-IDF) Project Minimal Configuration
|
||||
#
|
||||
CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE=y
|
|
@ -0,0 +1,50 @@
|
|||
# This file was generated using idf.py save-defconfig. It can be edited manually.
|
||||
# Espressif IoT Development Framework (ESP-IDF) Project Minimal Configuration
|
||||
#
|
||||
CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE=y
|
||||
CONFIG_COMPILER_STACK_CHECK_MODE_ALL=y
|
||||
CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=n
|
||||
CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1=n
|
||||
CONFIG_LWIP_IPV6=n
|
||||
|
||||
CONFIG_FREERTOS_HZ=1000
|
||||
CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y
|
||||
|
||||
#
|
||||
# Default main stack size
|
||||
#
|
||||
# This is typically way bigger than needed for stack size. See user_settings.h
|
||||
#
|
||||
CONFIG_ESP_MAIN_TASK_STACK_SIZE=55500
|
||||
# Legacy stack size for older ESP-IDF versions
|
||||
CONFIG_MAIN_TASK_STACK_SIZE=55500
|
||||
|
||||
#
|
||||
# Compiler options
|
||||
#
|
||||
CONFIG_COMPILER_OPTIMIZATION_DEFAULT=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTION_LEVEL=2
|
||||
CONFIG_COMPILER_HIDE_PATHS_MACROS=y
|
||||
CONFIG_COMPILER_STACK_CHECK_MODE_NORM=y
|
||||
CONFIG_COMPILER_STACK_CHECK=y
|
||||
|
||||
#
|
||||
# Partition Table
|
||||
#
|
||||
# CONFIG_PARTITION_TABLE_SINGLE_APP is not set
|
||||
CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE=y
|
||||
# CONFIG_PARTITION_TABLE_TWO_OTA is not set
|
||||
# CONFIG_PARTITION_TABLE_CUSTOM is not set
|
||||
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
|
||||
CONFIG_PARTITION_TABLE_FILENAME="partitions_singleapp_large.csv"
|
||||
CONFIG_PARTITION_TABLE_OFFSET=0x8000
|
||||
CONFIG_PARTITION_TABLE_MD5=y
|
||||
# end of Partition Table
|
||||
|
||||
|
||||
CONFIG_FREERTOS_HZ=100
|
||||
CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=1
|
||||
CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1=1
|
||||
CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0=CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0
|
||||
CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1=CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1
|
Loading…
Reference in New Issue