Cleanups for Arduino examples. Resolves PR #3126

pull/4259/head
David Garske 2021-07-28 09:50:37 -07:00
parent 8376a2adc2
commit c29a373308
4 changed files with 58 additions and 38 deletions

View File

@ -17,8 +17,8 @@ Step 2: Copy the directory wolfSSL that was just created to:
Step 3: Edit `<arduino-libraries>/wolfSSL/user_settings.h` Step 3: Edit `<arduino-libraries>/wolfSSL/user_settings.h`
If building for Intel Galileo platform add: `#define INTEL_GALILEO`. If building for Intel Galileo platform add: `#define INTEL_GALILEO`.
Add any other custom settings, for a good start see the below in wolfssl root. Add any other custom settings, for a good start see the examples in wolfssl root
(See wolfssl/IDE/ROWLEY-CROSSWORKS-ARM/user_settings.h) "/examples/configs/user_settings_*.h"
Step 4: If you experience any issues with custom user_settings.h see the wolfssl Step 4: If you experience any issues with custom user_settings.h see the wolfssl
porting guide here for more assistance: https://www.wolfssl.com/docs/porting-guide/ porting guide here for more assistance: https://www.wolfssl.com/docs/porting-guide/

View File

@ -24,8 +24,8 @@
#include <wolfssl/ssl.h> #include <wolfssl/ssl.h>
#include <Ethernet.h> #include <Ethernet.h>
const char host[] = "192.168.1.148"; // server to connect to const char host[] = "192.168.1.148"; /* server to connect to */
const int port = 11111; // port on server to connect to const int port = 11111; /* port on server to connect to */
int EthernetSend(WOLFSSL* ssl, char* msg, int sz, void* ctx); int EthernetSend(WOLFSSL* ssl, char* msg, int sz, void* ctx);
int EthernetReceive(WOLFSSL* ssl, char* reply, int sz, void* ctx); int EthernetReceive(WOLFSSL* ssl, char* reply, int sz, void* ctx);
@ -51,7 +51,7 @@ void setup() {
Serial.println("unable to get ctx"); Serial.println("unable to get ctx");
return; return;
} }
// initialize wolfSSL using callback functions /* initialize wolfSSL using callback functions */
wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0); wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0);
wolfSSL_SetIOSend(ctx, EthernetSend); wolfSSL_SetIOSend(ctx, EthernetSend);
wolfSSL_SetIORecv(ctx, EthernetReceive); wolfSSL_SetIORecv(ctx, EthernetReceive);
@ -119,7 +119,10 @@ void loop() {
if ((wolfSSL_write(ssl, msg, msgSz)) == msgSz) { if ((wolfSSL_write(ssl, msg, msgSz)) == msgSz) {
Serial.print("Server response: "); Serial.print("Server response: ");
while (client.available() || wolfSSL_pending(ssl)) { /* wait for data */
while (!client.available()) {}
/* read data */
while (wolfSSL_pending(ssl)) {
input = wolfSSL_read(ssl, reply, sizeof(reply) - 1); input = wolfSSL_read(ssl, reply, sizeof(reply) - 1);
total_input += input; total_input += input;
if (input < 0) { if (input < 0) {

View File

@ -31,7 +31,7 @@
#error Please undefine NO_WOLFSSL_SERVER for this example #error Please undefine NO_WOLFSSL_SERVER for this example
#endif #endif
const int port = 11111; // port to listen on const int port = 11111; /* port to listen on */
int EthernetSend(WOLFSSL* ssl, char* msg, int sz, void* ctx); int EthernetSend(WOLFSSL* ssl, char* msg, int sz, void* ctx);
int EthernetReceive(WOLFSSL* ssl, char* reply, int sz, void* ctx); int EthernetReceive(WOLFSSL* ssl, char* reply, int sz, void* ctx);
@ -59,12 +59,12 @@ void setup() {
return; return;
} }
// initialize wolfSSL using callback functions /* initialize wolfSSL using callback functions */
wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0); wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0);
wolfSSL_SetIOSend(ctx, EthernetSend); wolfSSL_SetIOSend(ctx, EthernetSend);
wolfSSL_SetIORecv(ctx, EthernetReceive); wolfSSL_SetIORecv(ctx, EthernetReceive);
// setup the private key and certificate /* setup the private key and certificate */
err = wolfSSL_CTX_use_PrivateKey_buffer(ctx, ecc_key_der_256, err = wolfSSL_CTX_use_PrivateKey_buffer(ctx, ecc_key_der_256,
sizeof_ecc_key_der_256, WOLFSSL_FILETYPE_ASN1); sizeof_ecc_key_der_256, WOLFSSL_FILETYPE_ASN1);
if (err != WOLFSSL_SUCCESS) { if (err != WOLFSSL_SUCCESS) {
@ -78,7 +78,7 @@ void setup() {
return; return;
} }
// Start the server /* Start the server */
server.begin(); server.begin();
return; return;
@ -110,7 +110,7 @@ void loop() {
int replySz = 0; int replySz = 0;
const char* cipherName; const char* cipherName;
// Listen for incoming client requests. /* Listen for incoming client requests. */
client = server.available(); client = server.available();
if (!client) { if (!client) {
return; return;
@ -142,7 +142,10 @@ void loop() {
Serial.println(cipherName); Serial.println(cipherName);
Serial.print("Server Read: "); Serial.print("Server Read: ");
while (client.available() || wolfSSL_pending(ssl)) { /* wait for data */
while (!client.available()) {}
/* read data */
while (wolfSSL_pending(ssl)) {
input = wolfSSL_read(ssl, reply, sizeof(reply) - 1); input = wolfSSL_read(ssl, reply, sizeof(reply) - 1);
if (input < 0) { if (input < 0) {
err = wolfSSL_get_error(ssl, 0); err = wolfSSL_get_error(ssl, 0);
@ -159,7 +162,7 @@ void loop() {
} }
} }
// echo data /* echo data */
if ((wolfSSL_write(ssl, reply, replySz)) != replySz) { if ((wolfSSL_write(ssl, reply, replySz)) != replySz) {
err = wolfSSL_get_error(ssl, 0); err = wolfSSL_get_error(ssl, 0);
wolfSSL_ERR_error_string(err, errBuf); wolfSSL_ERR_error_string(err, errBuf);

View File

@ -11,20 +11,29 @@ space(){
} }
if [ "$DIR" = "ARDUINO" ]; then if [ "$DIR" = "ARDUINO" ]; then
rm -rf wolfSSL if [ ! -d "wolfSSL" ]; then
mkdir wolfSSL mkdir wolfSSL
fi
cp ../../src/*.c ./wolfSSL cp ../../src/*.c ./wolfSSL
cp ../../wolfcrypt/src/*.c ./wolfSSL cp ../../wolfcrypt/src/*.c ./wolfSSL
if [ ! -d "wolfSSL/wolfssl" ]; then
mkdir wolfSSL/wolfssl mkdir wolfSSL/wolfssl
fi
cp ../../wolfssl/*.h ./wolfSSL/wolfssl cp ../../wolfssl/*.h ./wolfSSL/wolfssl
if [ ! -d "wolfSSL/wolfssl/wolfcrypt" ]; then
mkdir wolfSSL/wolfssl/wolfcrypt mkdir wolfSSL/wolfssl/wolfcrypt
fi
cp ../../wolfssl/wolfcrypt/*.h ./wolfSSL/wolfssl/wolfcrypt cp ../../wolfssl/wolfcrypt/*.h ./wolfSSL/wolfssl/wolfcrypt
# support misc.c as include in wolfcrypt/src # support misc.c as include in wolfcrypt/src
if [ ! -d "./wolfSSL/wolfcrypt" ]; then
mkdir ./wolfSSL/wolfcrypt mkdir ./wolfSSL/wolfcrypt
fi
if [ ! -d "./wolfSSL/wolfcrypt/src" ]; then
mkdir ./wolfSSL/wolfcrypt/src mkdir ./wolfSSL/wolfcrypt/src
fi
cp ../../wolfcrypt/src/misc.c ./wolfSSL/wolfcrypt/src cp ../../wolfcrypt/src/misc.c ./wolfSSL/wolfcrypt/src
cp ../../wolfcrypt/src/asm.c ./wolfSSL/wolfcrypt/src cp ../../wolfcrypt/src/asm.c ./wolfSSL/wolfcrypt/src
@ -37,31 +46,36 @@ if [ "$DIR" = "ARDUINO" ]; then
cp ./wolfSSL/wolfssl/bio.c ./wolfSSL/wolfcrypt/src/bio.c cp ./wolfSSL/wolfssl/bio.c ./wolfSSL/wolfcrypt/src/bio.c
# copy openssl compatibility headers to their appropriate location # copy openssl compatibility headers to their appropriate location
if [ ! -d "./wolfSSL/wolfssl/openssl" ]; then
mkdir ./wolfSSL/wolfssl/openssl mkdir ./wolfSSL/wolfssl/openssl
fi
cp ../../wolfssl/openssl/* ./wolfSSL/wolfssl/openssl cp ../../wolfssl/openssl/* ./wolfSSL/wolfssl/openssl
echo "/* Generated wolfSSL header file for Arduino */" > ./wolfSSL/wolfssl.h echo "/* Generated wolfSSL header file for Arduino */" > ./wolfSSL/wolfssl.h
echo "#include <user_settings.h>" >> ./wolfSSL/wolfssl.h
echo "#include <wolfssl/wolfcrypt/settings.h>" >> ./wolfSSL/wolfssl.h echo "#include <wolfssl/wolfcrypt/settings.h>" >> ./wolfSSL/wolfssl.h
echo "#include <wolfssl/ssl.h>" >> ./wolfSSL/wolfssl.h echo "#include <wolfssl/ssl.h>" >> ./wolfSSL/wolfssl.h
if [ ! -f "./wolfSSL/user_settings.h" ]; then
echo "/* Generated wolfSSL user_settings.h file for Arduino */" > ./wolfSSL/user_settings.h echo "/* Generated wolfSSL user_settings.h file for Arduino */" > ./wolfSSL/user_settings.h
echo "#ifndef ARDUINO_USER_SETTINGS_H" >> ./wolfSSL/user_settings.h echo "#ifndef ARDUINO_USER_SETTINGS_H" >> ./wolfSSL/user_settings.h
echo "#define ARDUINO_USER_SETTINGS_H" >> ./wolfSSL/user_settings.h echo "#define ARDUINO_USER_SETTINGS_H" >> ./wolfSSL/user_settings.h
space wolfSSL/user_settings.h space ./wolfSSL/user_settings.h
echo "/* Platform */" >> ./wolfSSL/user_settings.h echo "/* Platform */" >> ./wolfSSL/user_settings.h
echo "#define WOLFSSL_ARDUINO" >> ./wolfSSL/user_settings.h echo "#define WOLFSSL_ARDUINO" >> ./wolfSSL/user_settings.h
space wolfSSL/user_settings.h space ./wolfSSL/user_settings.h
echo "/* Math library (remove this to use normal math)*/" >> ./wolfSSL/user_settings.h echo "/* Math library (remove this to use normal math)*/" >> ./wolfSSL/user_settings.h
echo "#define USE_FAST_MATH" >> ./wolfSSL/user_settings.h echo "#define USE_FAST_MATH" >> ./wolfSSL/user_settings.h
echo "#define TFM_NO_ASM" >> ./wolfSSL/user_settings.h echo "#define TFM_NO_ASM" >> ./wolfSSL/user_settings.h
space wolfSSL/user_settings.h space ./wolfSSL/user_settings.h
echo "/* RNG DEFAULT !!FOR TESTING ONLY!! */" >> ./wolfSSL/user_settings.h echo "/* RNG DEFAULT !!FOR TESTING ONLY!! */" >> ./wolfSSL/user_settings.h
echo "/* comment out the error below to get started w/ bad entropy source" >> ./wolfSSL/user_settings.h echo "/* comment out the error below to get started w/ bad entropy source" >> ./wolfSSL/user_settings.h
echo " * This will need fixed before distribution but is OK to test with */" >> ./wolfSSL/user_settings.h echo " * This will need fixed before distribution but is OK to test with */" >> ./wolfSSL/user_settings.h
echo "#error \"needs solved, see: https://www.wolfssl.com/docs/porting-guide/\"" >> ./wolfSSL/user_settings.h echo "#error \"needs solved, see: https://www.wolfssl.com/docs/porting-guide/\"" >> ./wolfSSL/user_settings.h
echo "#define WOLFSSL_GENSEED_FORTEST" >> ./wolfSSL/user_settings.h echo "#define WOLFSSL_GENSEED_FORTEST" >> ./wolfSSL/user_settings.h
space wolfSSL/user_settings.h space ./wolfSSL/user_settings.h
echo "#endif /* ARDUINO_USER_SETTINGS_H */" >> ./wolfSSL/user_settings.h echo "#endif /* ARDUINO_USER_SETTINGS_H */" >> ./wolfSSL/user_settings.h
fi
cp wolfSSL/wolfssl/wolfcrypt/settings.h wolfSSL/wolfssl/wolfcrypt/settings.h.bak cp wolfSSL/wolfssl/wolfcrypt/settings.h wolfSSL/wolfssl/wolfcrypt/settings.h.bak
echo " /* wolfSSL Generated ARDUINO settings */" > ./wolfSSL/wolfssl/wolfcrypt/settings.h echo " /* wolfSSL Generated ARDUINO settings */" > ./wolfSSL/wolfssl/wolfcrypt/settings.h