Skip to content

Commit ee0e25d

Browse files
committed
Improved Arduino Support, ESP32, Due; (+ code review x2)
1 parent f9bf96d commit ee0e25d

File tree

19 files changed

+1164
-128
lines changed

19 files changed

+1164
-128
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,10 @@ wolfcrypt/src/port/intel/qat_test
322322
# Arduino Generated Files
323323
/IDE/ARDUINO/wolfSSL
324324
scripts/memtest.txt
325+
/IDE/ARDUINO/Arduino_README_prepend.md.tmp
326+
/IDE/ARDUINO/library.properties.tmp
327+
/IDE/ARDUINO/library.properties.tmp.backup
328+
/IDE/ARDUINO/PREPENDED_README.md
325329

326330
# Doxygen generated files
327331
doc/doxygen_warnings
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Arduino wolfSSL Library
2+
3+
The library is modified from wolfSSL Release ${WOLFSSL_VERSION} for the Arduino platform.
4+

IDE/ARDUINO/README.md

Lines changed: 106 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
### wolfSSL with Arduino
22

3+
Many of the supported devices are natively built-in to the [Arduino IDE Board Manager](https://docs.arduino.cc/software/ide-v2/tutorials/ide-v2-board-manager/)
4+
and by adding [additional cores](https://docs.arduino.cc/learn/starting-guide/cores/) as needed.
5+
6+
STM32 Support can be added by including this link in the "Additional Boards Managers URLs" field:
7+
8+
https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json
9+
10+
from [stm32duino/Arduino_Core_STM32](https://github.com/stm32duino/Arduino_Core_STM32?tab=readme-ov-file#getting-started) .
11+
12+
13+
314
##### Reformatting wolfSSL as a compatible Arduino Library
415
This is a shell script that will re-organize the wolfSSL library to be
516
compatible with Arduino projects that use Arduino IDE 1.5.0 or newer.
@@ -8,23 +19,42 @@ directory with a header file in the name of the library. This script moves all
819
src/ files to the `IDE/ARDUINO/wolfSSL/src` directory and creates a stub header
920
file called `wolfssl.h` inside that directory.
1021

11-
Step 1: To configure wolfSSL with Arduino, enter the following from within the
12-
wolfssl/IDE/ARDUINO directory:
22+
Step 1: To configure wolfSSL with Arduino, enter one of the following commands
23+
from within the `wolfssl/IDE/ARDUINO` directory:
1324

14-
`./wolfssl-arduino.sh`
25+
1. `./wolfssl-arduino.sh`
26+
- Creates an Arduino Library in `wolfSSL` directory
27+
2 `./wolfssl-arduino.sh INSTALL`
28+
- Creates an Arduino Library in `wolfSSL` directory
29+
- Moves that directory to the Arduino library directory:
30+
- `$HOME/Arduino/libraries` for most bash environments
31+
- `/mnt/c/Users/$USER/Documents/Arduino/libraries` (for WSL)
32+
3. `./wolfssl-arduino.sh INSTALL /path/to/repository`
33+
- Creates an Arduino Library in `wolfSSL` directory
34+
- Copies that directory contents to the specified `/path/to/repository`
35+
4. `./wolfssl-arduino.sh INSTALL /path/to/any/other/directory`
36+
- Creates an Arduino Library in `wolfSSL` directory
37+
- Copies that directory contents to the specified `/path/to/repository`
1538

16-
Step 2: Copy the directory wolfSSL that was just created to:
17-
`~/Documents/Arduino/libraries/` directory so the Arduino IDE can find it.
18-
19-
Step 3: Edit `<arduino-libraries>/wolfSSL/src/user_settings.h`
39+
Step 2: Edit `<arduino-libraries>/wolfSSL/src/user_settings.h`
2040
If building for Intel Galileo platform add: `#define INTEL_GALILEO`.
2141
Add any other custom settings, for a good start see the examples in wolfssl root
2242
"/examples/configs/user_settings_*.h"
2343

24-
Step 4: If you experience any issues with custom user_settings.h see the wolfssl
44+
Step 3: If you experience any issues with custom user_settings.h see the wolfssl
2545
porting guide here for more assistance: https://www.wolfssl.com/docs/porting-guide/
2646

27-
Step 5: If you still have any issues contact [email protected] for more help.
47+
If you have any issues contact [email protected] for help.
48+
49+
##### Including wolfSSL in Arduino Libraries (for Arduino version 2.0 or greater)
50+
51+
1. In the Arduino IDE:
52+
53+
The wolfSSL library should automatically be detected when found in the `libraries`
54+
directory.
55+
56+
- In `Sketch -> Include Library` choose wolfSSL for new sketches.
57+
2858

2959
##### Including wolfSSL in Arduino Libraries (for Arduino version 1.6.6)
3060

@@ -33,6 +63,72 @@ Step 5: If you still have any issues contact [email protected] for more help.
3363
`IDE/ARDUNIO/wolfSSL` folder.
3464
- In `Sketch -> Include Library` choose wolfSSL.
3565

36-
2. Open an example Arduino sketch for wolfSSL:
66+
##### wolfSSL Examples
67+
68+
Open an example Arduino sketch for wolfSSL:
69+
3770
- wolfSSL Client INO sketch: `sketches/wolfssl_client/wolfssl_client.ino`
71+
3872
- wolfSSL Server INO sketch: `sketches/wolfssl_server/wolfssl_server.ino`
73+
74+
#### Script Examples
75+
76+
Publish wolfSSL from WSL to a repository.
77+
78+
```bash
79+
rm -rf /mnt/c/Users/$USER/Documents/Arduino/libraries/wolfSSL
80+
rm -rf /mnt/c/workspace/wolfssl-$USER/IDE/ARDUINO/wolfSSL
81+
./wolfssl-arduino.sh INSTALL /mnt/c/workspace/Arduino-wolfSSL-$USER/
82+
```
83+
84+
Publish wolfSSL from WSL to default Windows local library.
85+
86+
```bash
87+
rm -rf /mnt/c/Users/$USER/Documents/Arduino/libraries/wolfSSL
88+
rm -rf /mnt/c/workspace/wolfssl-arduino/IDE/ARDUINO/wolfSSL
89+
./wolfssl-arduino.sh INSTALL
90+
```
91+
92+
Test the TLS server by running a local command-line client.
93+
94+
```bash
95+
cd /mnt/c/workspace/wolfssl-$USER
96+
./examples/client/client -h 192.168.1.43 -p 11111 -v 3
97+
```
98+
99+
Build wolfSSL to include wolfSSH support, but to an alternate development directory.
100+
101+
```bash
102+
cd /mnt/c/workspace/wolfssl-$USER
103+
./configure --prefix=/mnt/c/workspace/wolfssh-$USER/wolfssl_install --enable-ssh
104+
make
105+
make install
106+
```
107+
108+
Build wolfSSH with wolfSSL not installed to default directory.
109+
110+
```bash
111+
cd /mnt/c/workspace/wolfssh-$USER
112+
./configure --with-wolfssl=/mnt/c/workspace/wolfssh-$USER/wolfssl_install
113+
make
114+
./examples/client/client -u jill -h 192.168.1.34 -p 22222 -P upthehill
115+
```
116+
117+
Test the current wolfSSL.
118+
119+
```bash
120+
cd /mnt/c/workspace/wolfssl-arduino
121+
git status
122+
./autogen.sh
123+
./configure --enable-all
124+
make clean
125+
make && make test
126+
```
127+
128+
Build and run `testwolfcrypt`
129+
130+
```bash
131+
./autogen.sh
132+
./configure --enable-all
133+
make clean && make && ./wolfcrypt/test/testwolfcrypt
134+
```

IDE/ARDUINO/include.am

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
# All paths should be given relative to the root
44

55
EXTRA_DIST+= IDE/ARDUINO/README.md
6+
EXTRA_DIST+= IDE/ARDUINO/Arduino_README_prepend.md
7+
EXTRA_DIST+= IDE/ARDUINO/keywords.txt
8+
EXTRA_DIST+= IDE/ARDUINO/library.properties.template
9+
EXTRA_DIST+= IDE/ARDUINO/sketches/README.md
10+
EXTRA_DIST+= IDE/ARDUINO/sketches/wolfssl_client/README.md
611
EXTRA_DIST+= IDE/ARDUINO/sketches/wolfssl_client/wolfssl_client.ino
12+
EXTRA_DIST+= IDE/ARDUINO/sketches/wolfssl_server/README.md
713
EXTRA_DIST+= IDE/ARDUINO/sketches/wolfssl_server/wolfssl_server.ino
814
EXTRA_DIST+= IDE/ARDUINO/wolfssl-arduino.sh

IDE/ARDUINO/keywords.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Syntax Coloring Map For wolfSSL
2+
# See https://arduino.github.io/arduino-cli/0.35/library-specification/#keywords
3+
#
4+
# Be sure to use tabs, not spaces. This might help:
5+
# tr ' ' '\t' < keywords1.txt > keywords.txt
6+
7+
#=============================================
8+
# Datatypes (KEYWORD1)
9+
#=============================================
10+
11+
12+
#=============================================
13+
# Methods and Functions (KEYWORD2)
14+
#=============================================
15+
wolfSSL_SetIORecv KEYWORD1
16+
17+
#=============================================
18+
# Instances (KEYWORD2)
19+
#=============================================
20+
ctx KEYWORD2
21+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=wolfSSL
2+
version=${WOLFSSL_VERSION}${WOLFSSL_VERSION_ARUINO_SUFFIX}
3+
author=wolfSSL inc
4+
maintainer=wolfSSL inc <[email protected]>
5+
sentence=A lightweight SSL/TLS library written in ANSI C and targeted for embedded, RTOS, and resource-constrained environments.
6+
paragraph=Manual: https://www.wolfssl.com/documentation/manuals/wolfssl/index.html.
7+
category=Communication
8+
url=https://www.wolfssl.com/
9+
architectures=*

IDE/ARDUINO/sketches/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# wolfSSL Arduino Examples
2+
3+
There are currently two example Arduino sketches:
4+
5+
* [wolfssl_client](./wolfssl_client/README.md): Basic TLS listening client.
6+
* [wolfssl_server](./wolfssl_server/README.md): Basic TLS server.
7+
8+
Examples have been most recently confirmed operational on the
9+
[Arduino IDE](https://www.arduino.cc/en/software) 2.2.1.
10+
11+
For examples on other platforms, see the [IDE directory](https://github.com/wolfssl/wolfssl/tree/master/IDE).
12+
Additional examples can be found on [wolfSSL/wolfssl-examples](https://github.com/wolfSSL/wolfssl-examples/).
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Arduino Basic TLS Listening Client
2+
3+
Open the [wolfssl_client.ino](./wolfssl_client.ino) file in the Arduino IDE.
4+
5+
Other IDE products are also supported, such as:
6+
7+
- [PlatformIO in VS Code](https://docs.platformio.org/en/latest/frameworks/arduino.html)
8+
- [VisualGDB](https://visualgdb.com/tutorials/arduino/)
9+
- [VisualMicro](https://www.visualmicro.com/)
10+
11+
For examples on other platforms, see the [IDE directory](https://github.com/wolfssl/wolfssl/tree/master/IDE).
12+
Additional examples can be found on [wolfSSL/wolfssl-examples](https://github.com/wolfSSL/wolfssl-examples/).
13+
14+
15+
### Troubleshooting
16+
17+
When encountering odd errors such as `undefined reference to ``_impure_ptr'`, try cleaning the Arduino
18+
cache directories. For Windows, that's typically in:
19+
20+
```text
21+
C:\Users\%USERNAME%\AppData\Local\Temp\arduino\sketches
22+
```
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# Arduino Basic TLS Server
2+
3+
Open the [wolfssl_server.ino](./wolfssl_server.ino) file in the Arduino IDE.
4+
5+
Other IDE products are also supported, such as:
6+
7+
- [PlatformIO in VS Code](https://docs.platformio.org/en/latest/frameworks/arduino.html)
8+
- [VisualGDB](https://visualgdb.com/tutorials/arduino/)
9+
- [VisualMicro](https://www.visualmicro.com/)
10+
11+
For examples on other platforms, see the [IDE directory](https://github.com/wolfssl/wolfssl/tree/master/IDE).
12+
Additional examples can be found on [wolfSSL/wolfssl-examples](https://github.com/wolfSSL/wolfssl-examples/).
13+
14+
## Connect with an Arduino Sketch
15+
16+
See the companion [Arduino Sketch Client](../wolfssl_client/wolfssl_client.ino).
17+
18+
## Connect with Linux Client
19+
20+
See also the [wolfSSL Example TLS Client](https://github.com/wolfSSL/wolfssl/tree/master/examples/client)
21+
and [wolfSSL Example TLS Server](https://github.com/wolfSSL/wolfssl/tree/master/examples/server).
22+
23+
Assuming a listening [Arduino Sketch Server](./wolfssl_server.ino) at `192.168.1.38` on port `11111`,
24+
connect with the `client` executable:
25+
26+
```
27+
./examples/client/client -h 192.168.1.38 -p 11111 -v 3
28+
```
29+
30+
## wolfSSL Error -308 wolfSSL_connect error state on socket
31+
32+
When using a wired Ethernet connection, and this error is encountered, simply
33+
press the reset button or power cycle the Arduino before making a connection.
34+
35+
Here's one possible script to test the server from a command-line client:
36+
37+
```bash
38+
#!/bin/bash
39+
echo "client log " > client_log.txt
40+
counter=1
41+
THIS_ERR=0
42+
while [ $THIS_ERR -eq 0 ]; do
43+
./examples/client/client -h 192.168.1.38 -p 11111 -v 3 >> client_log.txt
44+
45+
THIS_ERR=$?
46+
if [ $? -ne 0 ]; then
47+
echo "Failed!"
48+
exit 1
49+
fi
50+
echo "Iteration $counter"
51+
echo "Iteration $counter" >> client_log.txt
52+
((counter++))
53+
done
54+
```
55+
56+
Output expected from the `client` command:
57+
58+
```
59+
$ ./examples/client/client -h 192.168.1.38 -p 11111 -v 3
60+
Alternate cert chain used
61+
issuer : /C=US/ST=Montana/L=Bozeman/O=Sawtooth/OU=Consulting/CN=www.wolfssl.com/[email protected]
62+
subject: /C=US/ST=Montana/L=Bozeman/O=wolfSSL/OU=Support/CN=www.wolfssl.com/[email protected]
63+
altname = example.com
64+
altname = 127.0.0.1
65+
serial number:01
66+
SSL version is TLSv1.2
67+
SSL cipher suite is ECDHE-RSA-AES128-GCM-SHA256
68+
SSL curve name is SECP256R1
69+
---
70+
Server certificate
71+
-----BEGIN CERTIFICATE-----
72+
MIIE6DCCA9CgAwIBAgIBATANBgkqhkiG9w0BAQsFADCBlDELMAkGA1UEBhMCVVMx
73+
EDAOBgNVBAgMB01vbnRhbmExEDAOBgNVBAcMB0JvemVtYW4xETAPBgNVBAoMCFNh
74+
d3Rvb3RoMRMwEQYDVQQLDApDb25zdWx0aW5nMRgwFgYDVQQDDA93d3cud29sZnNz
75+
bC5jb20xHzAdBgkqhkiG9w0BCQEWEGluZm9Ad29sZnNzbC5jb20wHhcNMjMxMjEz
76+
MjIxOTI4WhcNMjYwOTA4MjIxOTI4WjCBkDELMAkGA1UEBhMCVVMxEDAOBgNVBAgM
77+
B01vbnRhbmExEDAOBgNVBAcMB0JvemVtYW4xEDAOBgNVBAoMB3dvbGZTU0wxEDAO
78+
BgNVBAsMB1N1cHBvcnQxGDAWBgNVBAMMD3d3dy53b2xmc3NsLmNvbTEfMB0GCSqG
79+
SIb3DQEJARYQaW5mb0B3b2xmc3NsLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEP
80+
ADCCAQoCggEBAMCVCOFXQfJxbbfSRUEnAWXGRa7yvCQwuJXOL07W9hyIvHyf+6hn
81+
f/5cnFF194rKB+c1L4/hvXvAL3yrZKgX/Mp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2k
97+
W+Jj73zJGIeoAiUQPoco+fXvR56lgAgRkGj+0aOoUbk3/9XKfId/a7wsEsjFhYv8
98+
DMa5hrjJBMNRN9JP
99+
-----END CERTIFICATE-----
100+
Session timeout set to 500 seconds
101+
Client Random : 56A0BB9647B064D3F20947032B74B31FDB4C93DBAC9460BA8AEA213A2B2DD4A8
102+
SSL-Session:
103+
Protocol : TLSv1.2
104+
Cipher : TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
105+
Session-ID: 3255404E997FA9C27ECB4F1A20A70E722E4AA504B63A945FC175434D1907EC31
106+
Session-ID-ctx:
107+
Master-Key: 67F22168BBADD678643BBA76B398277270C29788AC18FD05B57F6B715F49A7BCEEF75BEAF7FE266B0CC058534AF76C1F
108+
TLS session ticket: NONE
109+
Start Time: 1705533296
110+
Timeout : 500 (sec)
111+
Extended master secret: no
112+
I hear you fa shizzle!
113+
```
114+
115+
### Troubleshooting
116+
117+
When encountering odd errors such as `undefined reference to ``_impure_ptr'`, such as this:
118+
119+
```text
120+
c:/users/gojimmypi/appdata/local/arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: C:\Users\gojimmypi\AppData\Local\Temp\arduino\sketches\EAB8D79A02D1ECF107884802D893914E\libraries\wolfSSL\wolfcrypt\src\logging.c.o:(.literal.wolfssl_log+0x8): undefined reference to `_impure_ptr'
121+
collect2.exe: error: ld returned 1 exit status
122+
123+
exit status 1
124+
125+
Compilation error: exit status 1
126+
```
127+
128+
Try cleaning the Arduino cache directories. For Windows, that's typically in:
129+
130+
```text
131+
C:\Users\%USERNAME%\AppData\Local\Temp\arduino\sketches
132+
```
133+
134+
Remove all other boards from other serial ports, leaving one the one being programmed.

0 commit comments

Comments
 (0)