Added missing `string.h` for `strcasestr`.

pull/293/head
David Garske 2022-02-15 14:52:25 -08:00
parent b9b85d8efb
commit 894059f675
5 changed files with 33 additions and 15 deletions

View File

@ -23,6 +23,11 @@
#define BTLE_MSG_MAX_SIZE 1024 #define BTLE_MSG_MAX_SIZE 1024
#define BTLE_BLOCK_SIZE 16 #define BTLE_BLOCK_SIZE 16
#define _GNU_SOURCE
#include <string.h> /* for strcasestr */
#define EXIT_STRING "EXIT"
typedef enum { typedef enum {
BTLE_PKT_TYPE_NULL, BTLE_PKT_TYPE_NULL,
BTLE_PKT_TYPE_KEY, BTLE_PKT_TYPE_KEY,

View File

@ -19,17 +19,19 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
#include "../btle-sim.h"
#ifndef WOLFSSL_USER_SETTINGS #ifndef WOLFSSL_USER_SETTINGS
#include <wolfssl/options.h> #include <wolfssl/options.h>
#endif #endif
#include <wolfssl/wolfcrypt/settings.h> #include <wolfssl/wolfcrypt/settings.h>
#include <wolfssl/wolfcrypt/wc_port.h> #include <wolfssl/wolfcrypt/wc_port.h>
#include <wolfssl/wolfcrypt/ecc.h> #include <wolfssl/wolfcrypt/ecc.h>
#include "../btle-sim.h"
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
int ret; int ret = 0;
#ifdef HAVE_ECC_ENCRYPT
WC_RNG rng; WC_RNG rng;
ecEncCtx* cliCtx = NULL; ecEncCtx* cliCtx = NULL;
void* devCtx = NULL; void* devCtx = NULL;
@ -153,7 +155,10 @@ int main(int argc, char** argv)
/* get message to send */ /* get message to send */
printf("Enter text to send:\n"); printf("Enter text to send:\n");
plainSz = sizeof(plain)-1; plainSz = sizeof(plain)-1;
fgets((char*)plain, plainSz, stdin); if (fgets((char*)plain, plainSz, stdin) == NULL) {
printf("stdin get failed\n");
goto cleanup;
}
plainSz = strlen((char*)plain); plainSz = strlen((char*)plain);
/* pad message at 16 bytes for AES block size */ /* pad message at 16 bytes for AES block size */
ret = btle_msg_pad(plain, (int*)&plainSz, devCtx); ret = btle_msg_pad(plain, (int*)&plainSz, devCtx);
@ -196,7 +201,7 @@ int main(int argc, char** argv)
printf("Recv %d: %s\n", plainSz, plain); printf("Recv %d: %s\n", plainSz, plain);
/* check for exit flag */ /* check for exit flag */
if (strcasestr((char*)plain, "EXIT")) { if (strcasestr((char*)plain, EXIT_STRING)) {
printf("Exit, closing connection\n"); printf("Exit, closing connection\n");
break; break;
} }
@ -216,5 +221,8 @@ cleanup:
wolfCrypt_Cleanup(); wolfCrypt_Cleanup();
#else
printf("Please compile wolfSSL with --enable-eccencrypt or HAVE_ECC_ENCRYPT\n");
#endif
return ret; return ret;
} }

View File

@ -19,17 +19,19 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
#include "../btle-sim.h"
#ifndef WOLFSSL_USER_SETTINGS #ifndef WOLFSSL_USER_SETTINGS
#include <wolfssl/options.h> #include <wolfssl/options.h>
#endif #endif
#include <wolfssl/wolfcrypt/settings.h> #include <wolfssl/wolfcrypt/settings.h>
#include <wolfssl/wolfcrypt/wc_port.h> #include <wolfssl/wolfcrypt/wc_port.h>
#include <wolfssl/wolfcrypt/ecc.h> #include <wolfssl/wolfcrypt/ecc.h>
#include "../btle-sim.h"
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
int ret; int ret = 0;
#ifdef HAVE_ECC_ENCRYPT
WC_RNG rng; WC_RNG rng;
ecEncCtx* srvCtx = NULL; ecEncCtx* srvCtx = NULL;
void* devCtx = NULL; void* devCtx = NULL;
@ -189,7 +191,7 @@ int main(int argc, char** argv)
} }
/* check for exit flag */ /* check for exit flag */
if (strcasestr((char*)plain, "EXIT")) { if (strcasestr((char*)plain, EXIT_STRING)) {
printf("Exit, closing connection\n"); printf("Exit, closing connection\n");
break; break;
} }
@ -208,6 +210,8 @@ cleanup:
btle_close(devCtx); btle_close(devCtx);
wolfCrypt_Cleanup(); wolfCrypt_Cleanup();
#else
printf("Please compile wolfSSL with --enable-eccencrypt or HAVE_ECC_ENCRYPT\n");
#endif
return ret; return ret;
} }

View File

@ -23,6 +23,7 @@
* Example TLSv1.3 client over BTLE * Example TLSv1.3 client over BTLE
*/ */
#include "../btle-sim.h"
#ifndef WOLFSSL_USER_SETTINGS #ifndef WOLFSSL_USER_SETTINGS
#include <wolfssl/options.h> #include <wolfssl/options.h>
@ -31,8 +32,6 @@
#include <wolfssl/ssl.h> #include <wolfssl/ssl.h>
#include <wolfssl/wolfcrypt/wc_port.h> #include <wolfssl/wolfcrypt/wc_port.h>
#include "../btle-sim.h"
#define CERT_FILE "../../certs/client-cert.pem" #define CERT_FILE "../../certs/client-cert.pem"
#define KEY_FILE "../../certs/client-key.pem" #define KEY_FILE "../../certs/client-key.pem"
#define CA_FILE "../../certs/ca-cert.pem" #define CA_FILE "../../certs/ca-cert.pem"
@ -171,7 +170,10 @@ int main(int argc, char** argv)
printf("Enter text to send:\n"); printf("Enter text to send:\n");
plainSz = sizeof(plain)-1; plainSz = sizeof(plain)-1;
fgets((char*)plain, plainSz, stdin); if (fgets((char*)plain, plainSz, stdin) == NULL) {
printf("stdin get failed\n");
goto done;
}
plainSz = strlen((char*)plain); plainSz = strlen((char*)plain);
do { do {
@ -187,7 +189,7 @@ int main(int argc, char** argv)
printf("Read (%d): %s\n", ret, plain); printf("Read (%d): %s\n", ret, plain);
/* check for exit flag */ /* check for exit flag */
if (strcasestr((char*)plain, "EXIT")) { if (strcasestr((char*)plain, EXIT_STRING)) {
printf("Exit, closing connection\n"); printf("Exit, closing connection\n");
break; break;
} }

View File

@ -23,6 +23,7 @@
* Example TLS v1.3 server over BTLE * Example TLS v1.3 server over BTLE
*/ */
#include "../btle-sim.h"
#ifndef WOLFSSL_USER_SETTINGS #ifndef WOLFSSL_USER_SETTINGS
#include <wolfssl/options.h> #include <wolfssl/options.h>
@ -31,8 +32,6 @@
#include <wolfssl/ssl.h> #include <wolfssl/ssl.h>
#include <wolfssl/wolfcrypt/wc_port.h> #include <wolfssl/wolfcrypt/wc_port.h>
#include "../btle-sim.h"
#define CERT_FILE "../../certs/server-cert.pem" #define CERT_FILE "../../certs/server-cert.pem"
#define KEY_FILE "../../certs/server-key.pem" #define KEY_FILE "../../certs/server-key.pem"
#define CA_FILE "../../certs/client-cert.pem" #define CA_FILE "../../certs/client-cert.pem"
@ -178,7 +177,7 @@ int main(int argc, char** argv)
printf("Sent (%d): %s\n", ret, echoBuffer); printf("Sent (%d): %s\n", ret, echoBuffer);
/* check for exit flag */ /* check for exit flag */
if (strcasestr((char*)echoBuffer, "EXIT")) { if (strcasestr((char*)echoBuffer, EXIT_STRING)) {
printf("Exit, closing connection\n"); printf("Exit, closing connection\n");
break; break;
} }