|
| 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 | +BgNVBAsMB1N1cHBvcnQxGDA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nl |
| 93 | +hZvaU2Z/ByK/thnqQuukEQdi/zlfMzc6hyZxPROyyrhkOHuKmUgOpaRrsZlu4EZR |
| 94 | +vRlSrbymfip6fCOnzNteQ31rBMi33ZWt8JGAWcUZkSYnkbhIHOtVtqp9pDjxA7xs |
| 95 | +i6qU1jwFepbFBvEmFC51+93lNbMBLLOtYlohmgi+Vvz5okKHhuWpxZnPrhS+4LkI |
| 96 | +JA0dXNYU4UyfQLOp6S1Si0y/rEQxZ8GNBoXsD+SZ10t7IQZm1OT1nf+O8IY5WB2k |
| 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