Skip to content

Commit 6d96701

Browse files
Add FreeRTOS + wolfIP + wolfSSL HTTPS example
This example demonstrates a full-stack embedded networking application using: - FreeRTOS (POSIX port) for RTOS simulation - wolfIP for zero-allocation networking - wolfSSL for TLS 1.3 security Features: - Virtual networking through TAP interface - HTTPS server with TLS 1.3 - UDP echo server for testing - Comprehensive test scripts Co-Authored-By: [email protected] <[email protected]>
1 parent f126104 commit 6d96701

File tree

12 files changed

+457
-25
lines changed

12 files changed

+457
-25
lines changed

fullstack/freertos-wolfip-wolfssl-https/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
freertos/FreeRTOS/
33
freertos/FreeRTOS-Kernel/
44

5+
# Certificate files
6+
certs/
7+
58

69
# Build directory
710
build/

fullstack/freertos-wolfip-wolfssl-https/CMakeLists.txt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ project(freertos_wolfssl_demo C)
55
set(CMAKE_C_STANDARD 11)
66
set(CMAKE_C_STANDARD_REQUIRED ON)
77

8+
# wolfSSL configuration
9+
add_definitions(-DWOLFSSL_USER_SETTINGS)
10+
811
# FreeRTOS Kernel source files for POSIX port
912
set(FREERTOS_PORT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/freertos/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix)
1013
set(FREERTOS_HEAP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/freertos/FreeRTOS-Kernel/portable/MemMang)
@@ -14,8 +17,12 @@ include_directories(
1417
${CMAKE_CURRENT_SOURCE_DIR}/include
1518
${CMAKE_CURRENT_SOURCE_DIR}/freertos/FreeRTOS-Kernel/include
1619
${FREERTOS_PORT_DIR}
17-
/home/ubuntu/repos/wolfip/src
18-
/home/ubuntu/repos/wolfip
20+
${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfip/src
21+
${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfip
22+
${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfip/src/http
23+
${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfip/src/port
24+
${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfssl
25+
${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfssl/include
1926
)
2027

2128
# FreeRTOS source files
@@ -33,17 +40,21 @@ set(FREERTOS_SOURCES
3340

3441
# Add wolfIP library
3542
add_library(wolfip STATIC
36-
/home/ubuntu/repos/wolfip/src/wolfip.c
43+
${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfip/src/wolfip.c
44+
${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfip/src/http/httpd.c
45+
${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfip/src/port/wolfssl_io.c
3746
)
3847

3948
# Add the main application
4049
add_executable(freertos_sim
4150
${FREERTOS_SOURCES}
4251
src/main.c
4352
src/wolfip_freertos.c
53+
src/https_server.c
4454
)
4555

4656
target_link_libraries(freertos_sim
4757
pthread
4858
wolfip
59+
wolfssl
4960
)
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# FreeRTOS + wolfIP + wolfSSL HTTPS Example
2+
3+
This example demonstrates a full-stack embedded networking application using FreeRTOS, wolfIP, and wolfSSL. It implements a secure HTTPS server running on a simulated FreeRTOS environment with TLS 1.3 support.
4+
5+
## Stack Components
6+
7+
The example integrates the following components:
8+
- FreeRTOS (POSIX port) - Real-time operating system
9+
- wolfIP - TCP/IP networking stack
10+
- wolfSSL - TLS 1.3 security layer
11+
- TAP interface - Virtual network interface
12+
13+
## Building and Running
14+
15+
### Prerequisites
16+
- wolfSSL library
17+
- wolfIP library
18+
- CMake (>= 3.13)
19+
- GCC
20+
- Linux with TUN/TAP support
21+
22+
### Setup
23+
1. Run the setup script to clone FreeRTOS repositories:
24+
```bash
25+
./setup.sh
26+
```
27+
28+
2. Configure the network interface (requires root):
29+
```bash
30+
sudo ./setup_network.sh
31+
```
32+
33+
3. Build the example:
34+
```bash
35+
mkdir -p build && cd build
36+
cmake ..
37+
make
38+
```
39+
40+
4. Run the example (requires root):
41+
```bash
42+
sudo ./freertos_sim
43+
```
44+
45+
### Testing
46+
Test the HTTPS server using curl:
47+
```bash
48+
sudo ./test_https.sh
49+
```
50+
51+
Or manually:
52+
```bash
53+
curl -v --cacert /path/to/wolfssl/certs/ca-cert.pem \
54+
--tlsv1.3 --insecure https://10.10.0.10:443/
55+
```
56+
57+
## Software Bill of Materials (SBOM)
58+
59+
| Component | Version | License | Source |
60+
|-----------|---------|----------|---------|
61+
| FreeRTOS | Latest | MIT | https://github.com/FreeRTOS/FreeRTOS |
62+
| FreeRTOS-Kernel | Latest | MIT | https://github.com/FreeRTOS/FreeRTOS-Kernel |
63+
| wolfSSL | Latest | GPLv2 | https://github.com/wolfSSL/wolfssl |
64+
| wolfIP | Latest | GPLv2 | https://github.com/wolfSSL/wolfip |
65+
66+
## Features
67+
- TLS 1.3 support with wolfSSL
68+
- Zero dynamic memory allocation networking with wolfIP
69+
- Virtual networking through TAP interface
70+
- UDP echo server for testing
71+
- HTTPS server with demo page
72+
- FreeRTOS task management and scheduling
73+
74+
## Network Configuration
75+
- TAP Interface: 10.10.0.1/24 (Host)
76+
- FreeRTOS IP: 10.10.0.10/24
77+
- Default Gateway: 10.10.0.1
78+
79+
## Security Features
80+
- TLS 1.3 with modern cipher suites
81+
- Certificate-based authentication
82+
- Support for various cryptographic algorithms:
83+
- AES (ECB, CBC, GCM)
84+
- ChaCha20-Poly1305
85+
- Curve25519
86+
- ED25519
87+
- SHA-2 and SHA-3 family

fullstack/freertos-wolfip-wolfssl-https/include/FreeRTOSConfig.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
/* FreeRTOSConfig.h
2+
*
3+
* Copyright (C) 2006-2024 wolfSSL Inc.
4+
*
5+
* This file is part of wolfSSL.
6+
*
7+
* wolfSSL is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation; either version 2 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* wolfSSL is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20+
*/
21+
122
#ifndef FREERTOS_CONFIG_H
223
#define FREERTOS_CONFIG_H
324

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* user_settings.h
2+
*
3+
* Copyright (C) 2006-2024 wolfSSL Inc.
4+
*
5+
* This file is part of wolfSSL.
6+
*
7+
* wolfSSL is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation; either version 2 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* wolfSSL is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20+
*/
21+
22+
/* wolfSSL configuration */
23+
#ifndef USER_SETTINGS_H
24+
#define USER_SETTINGS_H
25+
26+
#define WOLFSSL_TLS13
27+
#define HAVE_TLS_EXTENSIONS
28+
#define HAVE_SUPPORTED_CURVES
29+
#define HAVE_FFDHE_2048
30+
#define HAVE_HKDF
31+
#define HAVE_AEAD
32+
#define HAVE_CHACHA
33+
#define HAVE_POLY1305
34+
#define WOLFSSL_AES_COUNTER
35+
#define WOLFSSL_AES_DIRECT
36+
#define HAVE_AES_ECB
37+
#define HAVE_AES_CBC
38+
#define HAVE_AES_GCM
39+
#define HAVE_AESGCM
40+
#define HAVE_CURVE25519
41+
#define HAVE_ED25519
42+
#define WOLFSSL_SHA384
43+
#define WOLFSSL_SHA512
44+
#define WOLFSSL_SHA224
45+
#define WOLFSSL_SHA3
46+
#define WOLFSSL_SHAKE256
47+
48+
#endif /* USER_SETTINGS_H */
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
# Configure host TAP interface for wolfSSL embedded testing
3+
# Creates a TAP interface for virtual networking between host and FreeRTOS
4+
5+
# Check if running as root
6+
if [ "$EUID" -ne 0 ]; then
7+
echo "Please run as root (sudo)"
8+
exit 1
9+
fi
10+
11+
# Remove existing interface if present
12+
ip link show wtap0 >/dev/null 2>&1 && ip link delete wtap0
13+
14+
# Create new TAP interface and configure it
15+
ip tuntap add dev wtap0 mode tap
16+
ip link set wtap0 down
17+
ip addr flush dev wtap0
18+
ip addr add 10.10.0.1/24 dev wtap0
19+
ip link set wtap0 up
20+
21+
echo "TAP interface wtap0 configured with IP 10.10.0.1/24"
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/* https_server.c
2+
*
3+
* Copyright (C) 2006-2024 wolfSSL Inc.
4+
*
5+
* This file is part of wolfSSL.
6+
*
7+
* wolfSSL is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation; either version 2 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* wolfSSL is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20+
*/
21+
22+
#include "https_server.h"
23+
#include "httpd.h"
24+
#include <wolfssl/ssl.h>
25+
#include <wolfssl/wolfcrypt/error-crypt.h>
26+
27+
static WOLFSSL_CTX *g_ssl_ctx = NULL;
28+
static struct httpd g_httpd;
29+
30+
/* Root page handler */
31+
static int handle_root(struct httpd *httpd, struct http_client *hc, struct http_request *req) {
32+
const char *response = "<html><body><h1>wolfSSL HTTPS Demo</h1>"
33+
"<p>TLS 1.3 + FreeRTOS + wolfIP</p></body></html>";
34+
http_send_response_headers(hc, HTTP_STATUS_OK, "OK", "text/html", strlen(response));
35+
http_send_response_body(hc, response, strlen(response));
36+
return 0;
37+
}
38+
39+
int https_server_init(struct wolfIP *ipstack) {
40+
int ret;
41+
42+
/* Initialize wolfSSL */
43+
if ((ret = wolfSSL_Init()) != WOLFSSL_SUCCESS) {
44+
printf("Failed to initialize wolfSSL\n");
45+
return -1;
46+
}
47+
48+
/* Create and initialize WOLFSSL_CTX */
49+
if ((g_ssl_ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method())) == NULL) {
50+
printf("Failed to create WOLFSSL_CTX\n");
51+
return -1;
52+
}
53+
54+
/* Load server certificates */
55+
if ((ret = wolfSSL_CTX_use_certificate_file(g_ssl_ctx, CERT_FILE,
56+
WOLFSSL_FILETYPE_PEM)) != WOLFSSL_SUCCESS) {
57+
printf("Failed to load %s\n", CERT_FILE);
58+
return -1;
59+
}
60+
61+
/* Load server key */
62+
if ((ret = wolfSSL_CTX_use_PrivateKey_file(g_ssl_ctx, KEY_FILE,
63+
WOLFSSL_FILETYPE_PEM)) != WOLFSSL_SUCCESS) {
64+
printf("Failed to load %s\n", KEY_FILE);
65+
return -1;
66+
}
67+
68+
/* Initialize HTTP server with SSL context */
69+
if (httpd_init(&g_httpd, ipstack, HTTPS_PORT, g_ssl_ctx) != 0) {
70+
printf("Failed to initialize HTTPS server\n");
71+
return -1;
72+
}
73+
74+
/* Register handlers */
75+
if (httpd_register_handler(&g_httpd, "/", handle_root) != 0) {
76+
printf("Failed to register root handler\n");
77+
return -1;
78+
}
79+
80+
printf("HTTPS server initialized on port %d\n", HTTPS_PORT);
81+
return 0;
82+
}
83+
84+
static void https_server_task(void* pvParameters) {
85+
const TickType_t xDelay = pdMS_TO_TICKS(100);
86+
87+
printf("HTTPS server task started\n");
88+
89+
/* Task main loop - wolfIP handles connections in callbacks */
90+
for(;;) {
91+
vTaskDelay(xDelay);
92+
}
93+
}
94+
95+
int https_server_start(void) {
96+
BaseType_t ret;
97+
98+
ret = xTaskCreate(https_server_task,
99+
"HTTPS_Server",
100+
HTTPS_TASK_STACK_SIZE,
101+
NULL,
102+
HTTPS_TASK_PRIORITY,
103+
NULL);
104+
105+
return (ret == pdPASS) ? 0 : -1;
106+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* https_server.h
2+
*
3+
* Copyright (C) 2006-2024 wolfSSL Inc.
4+
*
5+
* This file is part of wolfSSL.
6+
*
7+
* wolfSSL is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation; either version 2 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* wolfSSL is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20+
*/
21+
22+
#ifndef HTTPS_SERVER_H
23+
#define HTTPS_SERVER_H
24+
25+
#include "FreeRTOS.h"
26+
#include "task.h"
27+
#include "wolfip.h"
28+
#include "httpd.h"
29+
#include <wolfssl/ssl.h>
30+
31+
/* HTTPS server configuration */
32+
#define HTTPS_PORT 443
33+
#define HTTPS_TASK_STACK_SIZE (16 * 1024)
34+
#define HTTPS_TASK_PRIORITY (tskIDLE_PRIORITY + 2)
35+
36+
/* Certificate paths */
37+
#define CERT_FILE "./certs/server-cert.pem"
38+
#define KEY_FILE "./certs/server-key.pem"
39+
#define CA_FILE "./certs/ca-cert.pem"
40+
41+
/* Initialize HTTPS server with wolfSSL and wolfIP */
42+
int https_server_init(struct wolfIP *ipstack);
43+
44+
/* Start HTTPS server task */
45+
int https_server_start(void);
46+
47+
#endif /* HTTPS_SERVER_H */

0 commit comments

Comments
 (0)