New azsphere example for CI testing

This commit is contained in:
kaleb-himes
2022-06-03 08:04:50 -06:00
parent 56c48b31ad
commit 55f3b7c277
21 changed files with 1146 additions and 0 deletions

View File

@@ -0,0 +1,138 @@
/* client.c
*
* Copyright (C) 2006-2021 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 "client.h"
/* the usual suspects */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/* socket includes */
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <unistd.h>
/* utility functions shared between client and server */
#include <shared/util.h>
/* wolfSSL */
#include <wolfssl/wolfcrypt/settings.h>
#include <wolfssl/ssl.h>
#include <wolfssl/certs_test.h>
/* Azure Sphere */
#include <applibs/networking.h>
#ifndef NO_MAIN_DRIVER
int main(int argc, char** argv)
#else
int azsphere_client_app(int argc, char** argv)
#endif
{
bool isNetworkingReady = false;
SOCKET_T sockfd = 0;
char buff[256];
size_t len;
int ret;
/* declare wolfSSL objects */
WOLFSSL_CTX* ctx = NULL;
WOLFSSL* ssl = NULL;
util_PrintIfAddr();
/* Check if the Azure Sphere Dev Board has network connectivity. */
if ((Networking_IsNetworkingReady(&isNetworkingReady) < 0) || !isNetworkingReady) {
fprintf(stderr, "ERROR: network is not up.\n");
return -1;
}
ret = wolfIO_TcpConnect(&sockfd, SERVER_IP, DEFAULT_PORT, 0);
if ((ret != 0) || ((int)sockfd < 0)) {
fprintf(stderr, "ERROR: failed to create socket.");
return -1;
}
/* Initialize wolfSSL */
wolfSSL_Init();
/* Create and initialize WOLFSSL_CTX */
ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method());
if (ctx == NULL) {
fprintf(stderr, "ERROR: failed to create WOLFSSL_CTX\n");
util_Cleanup(sockfd,ctx,ssl);
return -1;
}
/* Load client certificates into WOLFSSL_CTX */
ret = wolfSSL_CTX_load_verify_buffer(ctx, CERT, SIZEOF_CERT, WOLFSSL_FILETYPE_ASN1);
if (ret != SSL_SUCCESS) {
fprintf(stderr, "ERROR: failed to load client certificate, "
"please check the buffer.\n");
util_Cleanup(sockfd,ctx,ssl);
return -1;
}
/* Create a WOLFSSL object */
if ((ssl = wolfSSL_new(ctx)) == NULL) {
fprintf(stderr, "ERROR: failed to create WOLFSSL object\n");
util_Cleanup(sockfd,ctx,ssl);
return -1;
}
/* Attach wolfSSL to the socket */
wolfSSL_set_fd(ssl, sockfd);
/* Connect to wolfSSL on the server side */
if (wolfSSL_connect(ssl) != SSL_SUCCESS) {
fprintf(stderr, "ERROR: failed to connect to wolfSSL\n");
util_Cleanup(sockfd,ctx,ssl);
return -1;
}
/* Get length of message for server. */
printf("\nMessage for server: %s\n",msg);
len = strnlen(msg, sizeof(msg));
/* Send the message to the server */
if (wolfSSL_write(ssl, msg, (int)len) != len) {
fprintf(stderr, "ERROR: failed to write\n");
util_Cleanup(sockfd,ctx,ssl);
return -1;
}
/* Read the server data into our buff array */
memset(buff, 0, sizeof(buff));
if (wolfSSL_read(ssl, buff, sizeof(buff) - 1) == -1) {
fprintf(stderr, "ERROR: failed to read\n");
util_Cleanup(sockfd,ctx,ssl);
return -1;
}
/* Print to stdout any data the server sends */
printf("Server Reply: %s\n", buff);
/* Cleanup and return */
util_Cleanup(sockfd,ctx,ssl);
return 0; /* Return reporting a success */
}

View File

@@ -0,0 +1,125 @@
/* client.h
*
* Copyright (C) 2006-2022 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 WOLFSSL_CLIENT_H
#define WOLFSSL_CLIENT_H
#include <wolfssl/wolfcrypt/settings.h>
#ifdef NO_MAIN_DRIVER
int azsphere_client_app(int argc, char** argv);
#endif
static const unsigned char wolfssl_website_root_ca[] =
{
0x30, 0x82, 0x03, 0x75, 0x30, 0x82, 0x02, 0x5D, 0xA0, 0x03,
0x02, 0x01, 0x02, 0x02, 0x0B, 0x04, 0x00, 0x00, 0x00, 0x00,
0x01, 0x15, 0x4B, 0x5A, 0xC3, 0x94, 0x30, 0x0D, 0x06, 0x09,
0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x05, 0x05,
0x00, 0x30, 0x57, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55,
0x04, 0x06, 0x13, 0x02, 0x42, 0x45, 0x31, 0x19, 0x30, 0x17,
0x06, 0x03, 0x55, 0x04, 0x0A, 0x13, 0x10, 0x47, 0x6C, 0x6F,
0x62, 0x61, 0x6C, 0x53, 0x69, 0x67, 0x6E, 0x20, 0x6E, 0x76,
0x2D, 0x73, 0x61, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03, 0x55,
0x04, 0x0B, 0x13, 0x07, 0x52, 0x6F, 0x6F, 0x74, 0x20, 0x43,
0x41, 0x31, 0x1B, 0x30, 0x19, 0x06, 0x03, 0x55, 0x04, 0x03,
0x13, 0x12, 0x47, 0x6C, 0x6F, 0x62, 0x61, 0x6C, 0x53, 0x69,
0x67, 0x6E, 0x20, 0x52, 0x6F, 0x6F, 0x74, 0x20, 0x43, 0x41,
0x30, 0x1E, 0x17, 0x0D, 0x39, 0x38, 0x30, 0x39, 0x30, 0x31,
0x31, 0x32, 0x30, 0x30, 0x30, 0x30, 0x5A, 0x17, 0x0D, 0x32,
0x38, 0x30, 0x31, 0x32, 0x38, 0x31, 0x32, 0x30, 0x30, 0x30,
0x30, 0x5A, 0x30, 0x57, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03,
0x55, 0x04, 0x06, 0x13, 0x02, 0x42, 0x45, 0x31, 0x19, 0x30,
0x17, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x13, 0x10, 0x47, 0x6C,
0x6F, 0x62, 0x61, 0x6C, 0x53, 0x69, 0x67, 0x6E, 0x20, 0x6E,
0x76, 0x2D, 0x73, 0x61, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03,
0x55, 0x04, 0x0B, 0x13, 0x07, 0x52, 0x6F, 0x6F, 0x74, 0x20,
0x43, 0x41, 0x31, 0x1B, 0x30, 0x19, 0x06, 0x03, 0x55, 0x04,
0x03, 0x13, 0x12, 0x47, 0x6C, 0x6F, 0x62, 0x61, 0x6C, 0x53,
0x69, 0x67, 0x6E, 0x20, 0x52, 0x6F, 0x6F, 0x74, 0x20, 0x43,
0x41, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0D, 0x06, 0x09, 0x2A,
0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00,
0x03, 0x82, 0x01, 0x0F, 0x00, 0x30, 0x82, 0x01, 0x0A, 0x02,
0x82, 0x01, 0x01, 0x00, 0xDA, 0x0E, 0xE6, 0x99, 0x8D, 0xCE,
0xA3, 0xE3, 0x4F, 0x8A, 0x7E, 0xFB, 0xF1, 0x8B, 0x83, 0x25,
0x6B, 0xEA, 0x48, 0x1F, 0xF1, 0x2A, 0xB0, 0xB9, 0x95, 0x11,
0x04, 0xBD, 0xF0, 0x63, 0xD1, 0xE2, 0x67, 0x66, 0xCF, 0x1C,
0xDD, 0xC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E, 0x0C, 0x88, 0x0A, 0x1D, 0xD6, 0x66,
0x55, 0xE2, 0xFC, 0x48, 0xC9, 0x29, 0x26, 0x69, 0xE0
};
static const int sizeof_wolfssl_website_root_ca = sizeof(wolfssl_website_root_ca);
#endif /* WOLFSSL_CLIENT_H */

View File

@@ -0,0 +1,24 @@
# vim:ft=automake
# included from Top Level Makefile.am
# All paths should be given relative to the root
EXTRA_DIST+= IDE/MSVS-2019-AZSPHERE/client/client.c
EXTRA_DIST+= IDE/MSVS-2019-AZSPHERE/client/client.h
EXTRA_DIST+= IDE/MSVS-2019-AZSPHERE/server/server.c
EXTRA_DIST+= IDE/MSVS-2019-AZSPHERE/server/server.h
EXTRA_DIST+= IDE/MSVS-2019-AZSPHERE/shared/util.h
EXTRA_DIST+= IDE/MSVS-2019-AZSPHERE/user_settings.h
EXTRA_DIST+= IDE/MSVS-2019-AZSPHERE/wolfssl_new_azsphere/.gitignore
EXTRA_DIST+= IDE/MSVS-2019-AZSPHERE/wolfssl_new_azsphere/CMakeLists.txt
EXTRA_DIST+= IDE/MSVS-2019-AZSPHERE/wolfssl_new_azsphere/CMakeSettings.json
EXTRA_DIST+= IDE/MSVS-2019-AZSPHERE/wolfssl_new_azsphere/HardwareDefinitions/avnet_mt3620_sk/inc/hw/template_appliance.h
EXTRA_DIST+= IDE/MSVS-2019-AZSPHERE/wolfssl_new_azsphere/HardwareDefinitions/avnet_mt3620_sk/template_appliance.json
EXTRA_DIST+= IDE/MSVS-2019-AZSPHERE/wolfssl_new_azsphere/HardwareDefinitions/mt3620_rdb/inc/hw/template_appliance.h
EXTRA_DIST+= IDE/MSVS-2019-AZSPHERE/wolfssl_new_azsphere/HardwareDefinitions/mt3620_rdb/template_appliance.json
EXTRA_DIST+= IDE/MSVS-2019-AZSPHERE/wolfssl_new_azsphere/HardwareDefinitions/seeed_mt3620_mdb/inc/hw/template_appliance.h
EXTRA_DIST+= IDE/MSVS-2019-AZSPHERE/wolfssl_new_azsphere/HardwareDefinitions/seeed_mt3620_mdb/template_appliance.json
EXTRA_DIST+= IDE/MSVS-2019-AZSPHERE/wolfssl_new_azsphere/app_manifest.json
EXTRA_DIST+= IDE/MSVS-2019-AZSPHERE/wolfssl_new_azsphere/applibs_versions.h
EXTRA_DIST+= IDE/MSVS-2019-AZSPHERE/wolfssl_new_azsphere/launch.vs.json
EXTRA_DIST+= IDE/MSVS-2019-AZSPHERE/wolfssl_new_azsphere/main.c

View File

@@ -0,0 +1,213 @@
/* server.c
*
* Copyright (C) 2006-2021 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 "server.h"
/* the usual suspects */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/* socket includes */
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <unistd.h>
/* <shared/util.h> includes */
#include <shared/util.h>
/* wolfSSL */
#include <wolfssl/wolfcrypt/settings.h>
#include <wolfssl/ssl.h>
#include <wolfssl/certs_test.h>
/* Azure Sphere */
#include <applibs/log.h>
#include <applibs/networking.h>
#define BIND_PORT 11111
#define CERT_BUF server_cert_der_2048
#define SIZEOF_CERT_BUF sizeof_server_cert_der_2048
#define KEY_BUF server_key_der_2048
#define SIZEOF_KEY_BUF sizeof_server_key_der_2048
#ifndef NO_MAIN_DRIVER
int main(void)
#else
int azsphere_server_app(void)
#endif
{
bool isNetworkingReady = false;
int sockfd;
int connd;
struct sockaddr_in servAddr;
struct sockaddr_in clientAddr;
socklen_t size = sizeof(clientAddr);
char buff[256];
size_t len;
int shutdown = 0;
int ret;
const char* reply = "I hear ya fa shizzle!\n";
/* declare wolfSSL objects */
WOLFSSL_CTX* ctx = NULL;
WOLFSSL* ssl = NULL;
util_PrintIfAddr();
/* Check if the Azure Sphere Dev Board has network connectivity. */
if ((Networking_IsNetworkingReady(&isNetworkingReady) < 0) || !isNetworkingReady) {
fprintf(stderr,"Error: Network is not up.\n");
return -1;
}
/* Initialize wolfSSL */
wolfSSL_Init();
/* Create a socket that uses an internet IPv4 address,
* Sets the socket to be stream based (TCP),
* 0 means choose the default protocol. */
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
fprintf(stderr, "ERROR: failed to create the socket\n");
util_Cleanup(sockfd, ctx, ssl);
return -1;
}
/* Create and initialize WOLFSSL_CTX */
if ((ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method())) == NULL) {
fprintf(stderr, "ERROR: failed to create WOLFSSL_CTX\n");
util_Cleanup(sockfd, ctx, ssl);
return -1;
}
/* Load server certificates into WOLFSSL_CTX */
if (wolfSSL_CTX_use_certificate_buffer(ctx, CERT_BUF, SIZEOF_CERT_BUF, SSL_FILETYPE_ASN1)
!= SSL_SUCCESS) {
fprintf(stderr, "ERROR: failed to load %s, please check the file.\n",
CERT_BUF);
util_Cleanup(sockfd, ctx, ssl);
return -1;
}
/* Load server key into WOLFSSL_CTX */
if (wolfSSL_CTX_use_PrivateKey_buffer(ctx, KEY_BUF, SIZEOF_KEY_BUF, SSL_FILETYPE_ASN1)
!= SSL_SUCCESS) {
fprintf(stderr, "ERROR: failed to load %s, please check the file.\n",
KEY_BUF);
util_Cleanup(sockfd, ctx, ssl);
return -1;
}
/* Initialize the server address struct with zeros */
memset(&servAddr, 0, sizeof(servAddr));
/* Fill in the server address */
servAddr.sin_family = AF_INET; /* using IPv4 */
servAddr.sin_port = htons(BIND_PORT); /* on BIND_PORT */
servAddr.sin_addr.s_addr = INADDR_ANY; /* from anywhere */
/* Bind the server socket to our port */
if (bind(sockfd, (struct sockaddr*)&servAddr, sizeof(servAddr)) == -1) {
fprintf(stderr, "ERROR: failed to bind\n");
util_Cleanup(sockfd, ctx, ssl);
return -1;
}
/* Listen for a new connection, allow 5 pending connections */
if (listen(sockfd, 5) == -1) {
fprintf(stderr, "ERROR: failed to listen\n");
util_Cleanup(sockfd, ctx, ssl);
return -1;
}
/* Continue to accept clients until shutdown is issued */
while (!shutdown) {
printf("Waiting for a connection...\n");
/* Accept client connections */
if ((connd = accept(sockfd, (struct sockaddr*)&clientAddr, &size))
== -1) {
fprintf(stderr, "ERROR: failed to accept the connection\n\n");
util_Cleanup(sockfd, ctx, ssl);
return -1;
}
/* Create a WOLFSSL object */
if ((ssl = wolfSSL_new(ctx)) == NULL) {
fprintf(stderr, "ERROR: failed to create WOLFSSL object\n");
util_Cleanup(sockfd, ctx, ssl);
return -1;
}
/* Attach wolfSSL to the socket */
wolfSSL_set_fd(ssl, connd);
/* Establish TLS connection */
ret = wolfSSL_accept(ssl);
if (ret != SSL_SUCCESS) {
fprintf(stderr, "wolfSSL_accept error = %d\n",
wolfSSL_get_error(ssl, ret));
util_Cleanup(sockfd, ctx, ssl);
return -1;
}
printf("Client connected successfully\n");
/* Read the client data into our buff array */
memset(buff, 0, sizeof(buff));
if (wolfSSL_read(ssl, buff, sizeof(buff)-1) == -1) {
fprintf(stderr, "ERROR: failed to read\n");
util_Cleanup(sockfd, ctx, ssl);
return -1;
}
/* Print to stdout any data the client sends */
printf("Client: %s\n", buff);
/* Check for server shutdown command */
if (strncmp(buff, "shutdown", 8) == 0) {
printf("Shutdown command issued!\n");
shutdown = 1;
}
/* Write our reply into buff */
memset(buff, 0, sizeof(buff));
memcpy(buff, reply, strlen(reply));
len = strnlen(buff, sizeof(buff));
/* Reply back to the client */
if (wolfSSL_write(ssl, buff, (int)len) != len) {
fprintf(stderr, "ERROR: failed to write\n");
util_Cleanup(sockfd, ctx, ssl);
return -1;
}
/* Cleanup after this connection */
wolfSSL_free(ssl); /* Free the wolfSSL object */
close(connd); /* Close the connection to the client */
}
printf("Shutdown complete\n");
/* Cleanup and return */
util_Cleanup(sockfd, ctx, ssl);
return 0; /* Return reporting a success */
}

View File

@@ -0,0 +1,33 @@
/* server.h
*
* Copyright (C) 2006-2021 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 WOLFSSL_SERVER_H
#define WOLFSSL_SERVER_H
#include <wolfssl/wolfcrypt/settings.h>
#ifdef NO_MAIN_DRIVER
int azsphere_server_app(void);
#endif
#endif /* WOLFSSL_SERVER_H */

View File

@@ -0,0 +1,61 @@
#ifndef _UTIL_H_
#define _UTIL_H_
#include <stdio.h>
#include <wolfssl/ssl.h>
#include <ifaddrs.h>
#include <applibs/log.h>
#define _GNU_SOURCE /* defines NI_NUMERICHOST */
#ifndef NI_MAXHOST
#define NI_MAXHOST 256
#endif
static void util_Cleanup(int sockfd, WOLFSSL_CTX* ctx, WOLFSSL* ssl)
{
wolfSSL_free(ssl); /* Free the wolfSSL object */
wolfSSL_CTX_free(ctx); /* Free the wolfSSL context object */
wolfSSL_Cleanup(); /* Cleanup the wolfSSL environment */
close(sockfd); /* Close the connection to the server */
}
/* Displays each AF_INET interface and it's IP Address
* Return: WOLFSSL_SUCCESS if print is successful else WOLFSSL_FAILURE
*/
static int util_PrintIfAddr(void)
{
char host[NI_MAXHOST];
struct ifaddrs* ifaddr, * nxt;
int family, info, n;
/* Get a linked list of 'struct ifaddrs*' */
if (getifaddrs(&ifaddr) != 0) {
fprintf(stderr, "ERROR: Getting network interface and IP address");
return WOLFSSL_FAILURE;
}
printf("\nInterface IP Address\n");
/* Traverse ifaddr linked list using nxt */
for (nxt = ifaddr; nxt != NULL; nxt = nxt->ifa_next) {
if (nxt->ifa_addr == NULL)
continue;
family = nxt->ifa_addr->sa_family;
/* Display the address of each AF_INET* interface */
if (family == AF_INET) {
info = getnameinfo(nxt->ifa_addr, sizeof(struct sockaddr_in),
host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
if (info != 0) {
fprintf(stderr, "Failed to getnameinfo");
freeifaddrs(ifaddr);
return WOLFSSL_FAILURE;
}
/* Determine amount of space, n, to justify IP Address */
n = (int)strlen("Interface ") - (int)strlen(nxt->ifa_name);
n = (n > 0) ? n : 1; /* Set space to 1 if n is negative */
printf("%s %*c%s>\n", nxt->ifa_name, n, '<', host);
}
}
printf("\n");
freeifaddrs(ifaddr);
return WOLFSSL_SUCCESS;
}
#endif

View File

@@ -0,0 +1,74 @@
#define SERVER_IP "192.168.1.123"
#define CUSTOM_SERVER_CONNECTION
#ifndef _USER_SETTINGS_H_
#define _USER_SETTINGS_H_
#define WOLFSSL_AZSPHERE
/* Client connects to the server with these details. */
#ifdef CUSTOM_SERVER_CONNECTION
#ifndef SERVER_IP
#define SERVER_IP "192.168.1.200" /* Local Test Server IP */
#endif
#ifndef DEFAULT_PORT
#define DEFAULT_PORT 11111
#endif
#define CERT ca_cert_der_2048
#define SIZEOF_CERT sizeof_ca_cert_der_2048
static const char msg[] = "Are you listening wolfSSL Server?";
#else
#ifndef SERVER_IP
#define SERVER_IP "www.wolfssl.com"
#endif
#ifndef DEFAULT_PORT
#define DEFAULT_PORT 443
#endif
#define CERT wolfssl_website_root_ca
#define SIZEOF_CERT sizeof_wolfssl_website_root_ca
static const char msg[] = "GET /index.html HTTP/1.1\r\n\r\n";
#endif
/* Math: Normal (!USE_FAST_MATH) */
#define SIZEOF_LONG_LONG 8
#define WC_RSA_BLINDING
#define ECC_TIMING_RESISTANT
/* Enable options */
#define HAVE_CHACHA
#define HAVE_POLY1305
#define HAVE_ECC
#define HAVE_SUPPORTED_CURVES
#define HAVE_TLS_EXTENSIONS
#define HAVE_ONE_TIME_AUTH
#define HAVE_TRUNCATED_HMAC
#define HAVE_EXTENDED_MASTER
#define HAVE_ALPN
#define HAVE_SNI
#define HAVE_OCSP
#define HAVE_AESGCM
/* Disable options */
#define NO_PWDBASED
#define NO_DSA
#define NO_DES3
#define NO_RC4
#define NO_MD4
/* Benchmark / Testing */
#define BENCH_EMBEDDED
#define USE_CERT_BUFFERS_2048
#define USE_CERT_BUFFERS_256
/* OS */
#define SINGLE_THREADED
/* Filesystem */
#define NO_FILESYSTEM
/* Debug */
#include <applibs/log.h>
#define printf Log_Debug
#define WOLFIO_DEBUG
#define NO_MAIN_DRIVER
#endif /* _USER_SETTINGS_H_ */

View File

@@ -0,0 +1,3 @@
# Ignore output directories
/out/
/install/

View File

@@ -0,0 +1,58 @@
# CMakeList.txt
#
# Copyright (C) 2006-2022 wolfSSL Inc.
#
# This file is part of wolfSSL. (formerly known as CyaSSL)
#
# Usage:
# In MSVS 2019 with Azure Sphere plugin installed choose option
# "Open Local Folder" and browse to wolfssl-root/IDE/MSVS-2019-AZSPHERE"
# highlight wolfssl_new_azsphere and select "Open"
#
# To build:
# go to MSVS menu option "Build" and select "Build All"
#
# See https://docs.microsoft.com/en-us/azure-sphere/install/overview for how
# to get started with an Azure sphere device. Once you have completed the step
# to build/flash and run the Blinky example you will be ready to build/flash
# and run this example!
cmake_minimum_required (VERSION 3.4.1)
project (wolfssl_new_azsphere C)
azsphere_configure_tools(TOOLS_REVISION "22.02")
azsphere_configure_api(TARGET_API_SET "12")
# add wolfSSL preprocessor directives
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_USER_SETTINGS -Wno-conversion -Wno-sign-conversion")
# add a shared object for SSL/TLS and CRYPTO
set( SSL_SRC_DIR "../../../src" )
set( CRYPTO_SRC_DIR "../../../wolfcrypt/src" )
set( INCLUDE_DIR "../../.." )
aux_source_directory( ${SSL_SRC_DIR} SSL_SOURCES )
list( REMOVE_ITEM SSL_SOURCES ../../../src/bio.c )
list( REMOVE_ITEM SSL_SOURCES ../../../src/conf.c )
list( REMOVE_ITEM SSL_SOURCES ../../../src/x509.c )
list( REMOVE_ITEM SSL_SOURCES ../../../src/x509_str.c )
list( REMOVE_ITEM SSL_SOURCES ../../../src/pk.c )
aux_source_directory( ${CRYPTO_SRC_DIR} CRYPTO_SOURCES )
list( REMOVE_ITEM CRYPTO_SOURCES ../../../wolfcrypt/src/evp.c )
list( REMOVE_ITEM CRYPTO_SOURCES ../../../wolfcrypt/src/misc.c )
add_library( wolfssl STATIC ${SSL_SOURCES} ${CRYPTO_SOURCES} )
# Create executable that uses library
set( SERVER_APP_DIR "../server" )
set( CLIENT_APP_DIR "../client" )
set( USER_SETTINGS_DIR ".." )
set( APP_INCLUDE_DIRS ${SERVER_APP_DIR} ${CLIENT_APP_DIR} ${USER_SETTINGS_DIR} )
add_executable (${PROJECT_NAME} main.c ${SERVER_APP_DIR}/server.c ${CLIENT_APP_DIR}/client.c )
target_link_libraries (${PROJECT_NAME} applibs pthread gcc_s c wolfssl)
include_directories( ${INCLUDE_DIR} ${APP_INCLUDE_DIRS})
# azsphere_target_hardware_definition(${PROJECT_NAME} TARGET_DIRECTORY "HardwareDefinitions/mt3620_rdb" TARGET_DEFINITION "template_appliance.json")
azsphere_target_hardware_definition(${PROJECT_NAME} TARGET_DIRECTORY "HardwareDefinitions/seeed_mt3620_mdb" TARGET_DEFINITION "template_appliance.json")
azsphere_target_add_image_package(${PROJECT_NAME})

View File

@@ -0,0 +1,47 @@
{
"environments": [
{
"environment": "AzureSphere"
}
],
"configurations": [
{
"name": "ARM-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [
"AzureSphere"
],
"buildRoot": "${projectDir}\\out\\${name}",
"installRoot": "${projectDir}\\out\\${name}",
"cmakeToolchain": "${env.AzureSphereDefaultSDKDir}CMakeFiles\\AzureSphereToolchain.cmake",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"variables": [
{
"name": "AZURE_SPHERE_TARGET_API_SET",
"value": "latest-lts"
}
]
},
{
"name": "ARM-Release",
"generator": "Ninja",
"configurationType": "Release",
"inheritEnvironments": [
"AzureSphere"
],
"buildRoot": "${projectDir}\\out\\${name}",
"installRoot": "${projectDir}\\out\\${name}",
"cmakeToolchain": "${env.AzureSphereDefaultSDKDir}CMakeFiles\\AzureSphereToolchain.cmake",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"variables": [
{
"name": "AZURE_SPHERE_TARGET_API_SET",
"value": "latest-lts"
}
]
}
]
}

View File

@@ -0,0 +1,36 @@
/* template_appliance.h
*
* Copyright (C) 2006-2021 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 file maps the Avnet MT3620 Starter Kit (SK)
* to the 'template appliance' abstraction used by the templates.
* Some peripherals are on-board, while other peripherals must be
* attached externally (conditionally).
* See https://aka.ms/AzureSphereHardwareDefinitions for more
* information on how to use hardware abstractions .
*/
#pragma once
#include "avnet_mt3620_sk.h"
/* MT3620 SK: wolfssl azsphere CI app */
#define WOLF_AZSPHERE AVNET_MT3620_SK_USER_LED_RED

View File

@@ -0,0 +1,41 @@
{
"Metadata": {
"Type": "Azure Sphere Hardware Definition",
"Version": 1
},
"Description":
{
"Name": "Template hardware abstraction for Avnet MT3620 SK",
"MainCoreHeaderFileTopContent": [
"/* Copyright (C) 2006-2022 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 file maps the Avnet MT3620 Starter Kit (SK)",
" * to the 'template appliance' abstraction used by the templates.",
" * Some peripherals are on-board, while other peripherals must be",
" * attached externally (conditionally).",
" * See https://aka.ms/AzureSphereHardwareDefinitions for more",
" * information on how to use hardware abstractions .",
" */"
]
},
"Imports" : [ {"Path": "avnet_mt3620_sk.json"} ],
"Peripherals": [
{"Name": "WOLF_AZSPHERE", "Type": "Gpio", "Mapping": "AVNET_MT3620_SK_USER_LED_RED", "Comment": "MT3620 SK: User LED."}
]
}

View File

@@ -0,0 +1,32 @@
/* Copyright (C) 2006-2022 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 file maps the MT3620 reference development board (RDB)
* to the 'template appliance' abstraction used by the templates.
* Some peripherals are on-board, while other peripherals must be
* attached externally (conditionally).
* See https://aka.ms/AzureSphereHardwareDefinitions for more
* information on how to use hardware abstractions .
*/"
#pragma once
#include "mt3620_rdb.h"
/* MT3620 SK: wolfssl azsphere CI app */
#define WOLF_AZSPHERE MT3620_RDB_LED1_RED

View File

@@ -0,0 +1,41 @@
{
"Metadata": {
"Type": "Azure Sphere Hardware Definition",
"Version": 1
},
"Description":
{
"Name": "Template hardware abstraction for MT3620 RDB",
"MainCoreHeaderFileTopContent": [
"/* Copyright (C) 2006-2022 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 file maps the MT3620 reference development board (RDB)",
" * to the 'template appliance' abstraction used by the templates.",
" * Some peripherals are on-board, while other peripherals must be",
" * attached externally (conditionally).",
" * See https://aka.ms/AzureSphereHardwareDefinitions for more",
" * information on how to use hardware abstractions .",
" */"
]
},
"Imports" : [ {"Path": "mt3620_rdb.json"} ],
"Peripherals": [
{"Name": "WOLF_AZSPHERE", "Type": "Gpio", "Mapping": "MT3620_RDB_LED1_RED", "Comment": "MT3620 RDB: LED 1 (red channel)"}
]
}

View File

@@ -0,0 +1,35 @@
/* template_appliance.h
*
* Copyright (C) 2006-2021 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 file maps the Seeed MT3620 Mini Development Board (MDB)
* to the 'template appliance' abstraction used by the templates.
* Some peripherals are on-board, while other peripherals must be
* attached externally (conditionally).
* See https://aka.ms/AzureSphereHardwareDefinitions for more
* information on how to use hardware abstractions .
*/
#pragma once
#include "seeed_mt3620_mdb.h"
/* MT3620 SK: wolfssl azsphere CI app */
#define WOLF_AZSPHERE SEEED_MT3620_MDB_USER_LED

View File

@@ -0,0 +1,41 @@
{
"Metadata": {
"Type": "Azure Sphere Hardware Definition",
"Version": 1
},
"Description":
{
"Name": "Template hardware abstraction for Seeed MT3620 MDB",
"MainCoreHeaderFileTopContent": [
"/* Copyright (C) 2006-2022 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 file maps the Seeed MT3620 Mini Development Board (MDB)",
" * to the 'template appliance' abstraction used by the templates.",
" * Some peripherals are on-board, while other peripherals must be",
" * attached externally (conditionally).",
" * See https://aka.ms/AzureSphereHardwareDefinitions for more",
" * information on how to use hardware abstractions .",
" */"
]
},
"Imports" : [ {"Path": "seeed_mt3620_mdb.json"} ],
"Peripherals": [
{"Name": "WOLF_AZSPHERE", "Type": "Gpio", "Mapping": "SEEED_MT3620_MDB_USER_LED", "Comment": "MT3620 MDB: User LED."}
]
}

View File

@@ -0,0 +1,12 @@
{
"SchemaVersion": 1,
"Name": "wolfssl_new_azsphere",
"ComponentId": "959b4478-a9a3-440a-b1e7-9bb0b1f1d357",
"EntryPoint": "/bin/app",
"CmdArgs": [],
"Capabilities": {
"Gpio": [ "$WOLF_AZSPHERE" ],
"AllowedApplicationConnections": []
},
"ApplicationType": "Default"
}

View File

@@ -0,0 +1,25 @@
#pragma once
/// <summary>
/// This identifier should be defined before including any of the networking-related header files.
/// It indicates which version of the Wi-Fi data structures the application uses.
/// </summary>
#define NETWORKING_STRUCTS_VERSION 1
/// <summary>
/// This identifier must be defined before including any of the Wi-Fi related header files.
/// It indicates which version of the Wi-Fi data structures the application uses.
/// </summary>
#define WIFICONFIG_STRUCTS_VERSION 1
/// <summary>
/// This identifier must be defined before including any of the UART-related header files.
/// It indicates which version of the UART data structures the application uses.
/// </summary>
#define UART_STRUCTS_VERSION 1
/// <summary>
/// This identifier must be defined before including any of the SPI-related header files.
/// It indicates which version of the SPI data structures the application uses.
/// </summary>
#define SPI_STRUCTS_VERSION 1

View File

@@ -0,0 +1,14 @@
{
"version": "0.2.1",
"configurations": [
{
"type": "azurespheredbg",
"name": "wolfssl_new_azsphere (HLCore)",
"project": "CMakeLists.txt",
"workingDirectory": "${workspaceRoot}",
"applicationPath": "${debugInfo.target}",
"imagePath": "${debugInfo.targetImage}",
"partnerComponents": []
}
]
}

View File

@@ -0,0 +1,92 @@
/* main.c
*
* Copyright (C) 2006-2021 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 <stdbool.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <applibs/log.h>
#include <applibs/gpio.h>
#include <wolfssl/wolfcrypt/settings.h>
#ifndef WOLFSSL_USER_SETTINGS
#error "user_settings.h not included"
#endif
#include <server.h>
#include <client.h>
/*
* The following #include imports a "template appliance" definition. This app
* comes with multiple implementations of the template appliance, each in a
* separate directory, which allow the code to run unchanged on different
* hardware.
*
* By default, this app targets hardware that follows the MT3620-mini Reference
* Development Board (MDB) specification, such as the MT3620-mini Dev Kit from
* Seeed Studio.
*
* To target different hardware, you'll need to update CMakeLists.txt.
* For example, to target the Avnet MT3620 Starter Kit, make this update:
* azsphere_target_hardware_definition(${PROJECT_NAME}
* TARGET_DIRECTORY "HardwareDefinitions/avnet_mt3620_sk"
* TARGET_DEFINITION "template_appliance.json")
*
* See https://aka.ms/AzureSphereHardwareDefinitions for more details.
*/
#include <hw/template_appliance.h>
typedef enum {
ExitCode_Success = 0,
ExitCode_Main_Led = 1
} ExitCode;
int main(void)
{
Log_Debug(
"\nVisit https://github.com/Azure/azure-sphere-samples for other"
" examples.\n");
int ret;
int fd = GPIO_OpenAsOutput(WOLF_AZSPHERE, GPIO_OutputMode_PushPull, GPIO_Value_High);
if (fd < 0) {
Log_Debug(
"Error opening GPIO: %s (%d). Check that app_manifest.json includes"
" the GPIO used.\n",
strerror(errno), errno);
return ExitCode_Main_Led;
}
const struct timespec sleepTime = {.tv_sec = 1, .tv_nsec = 0};
printf("Launching the server...\n");
ret = azsphere_server_app();
printf("ret azsphere_server_app = %d\n", ret);
/* if server exists continually blink the red LED indicating server needs
* to be rebooted */
while (true) {
GPIO_SetValue(fd, GPIO_Value_Low);
nanosleep(&sleepTime, NULL);
GPIO_SetValue(fd, GPIO_Value_High);
nanosleep(&sleepTime, NULL);
}
}

View File

@@ -16,6 +16,7 @@ include IDE/INTIME-RTOS/include.am
include IDE/KDS/include.am include IDE/KDS/include.am
include IDE/STM32Cube/include.am include IDE/STM32Cube/include.am
include IDE/VS-ARM/include.am include IDE/VS-ARM/include.am
include IDE/MSVS-2019-AZSPHERE/include.am
include IDE/VS-AZURE-SPHERE/include.am include IDE/VS-AZURE-SPHERE/include.am
include IDE/GCC-ARM/include.am include IDE/GCC-ARM/include.am
include IDE/CSBENCH/include.am include IDE/CSBENCH/include.am