Skip to content

Commit dc36abd

Browse files
authored
Merge pull request wolfSSL#491 from wolfSSL/devin/1740502756-add-freertos-fullstack-example
Add FreeRTOS + wolfIP + wolfSSL HTTPS example
2 parents 8573325 + 468fd86 commit dc36abd

14 files changed

Lines changed: 1020 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# FreeRTOS directories managed by setup script
2+
freertos/FreeRTOS/
3+
freertos/FreeRTOS-Kernel/
4+
5+
# Certificate files
6+
certs/
7+
8+
9+
# Build directory
10+
build/
11+
12+
# Object files
13+
*.o
14+
*.ko
15+
*.obj
16+
*.elf
17+
18+
# Libraries
19+
*.lib
20+
*.a
21+
*.la
22+
*.lo
23+
24+
# Executables
25+
*.exe
26+
*.out
27+
*.app
28+
*.i*86
29+
*.x86_64
30+
*.hex
31+
32+
# Debug files
33+
*.dSYM/
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
project(freertos_wolfssl_demo C)
3+
4+
# Set C standard
5+
set(CMAKE_C_STANDARD 11)
6+
set(CMAKE_C_STANDARD_REQUIRED ON)
7+
8+
# wolfSSL configuration
9+
add_definitions(-DWOLFSSL_USER_SETTINGS)
10+
add_definitions(-DWOLFSSL_WOLFIP)
11+
12+
# FreeRTOS Kernel source files for POSIX port
13+
set(FREERTOS_PORT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/freertos/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix)
14+
set(FREERTOS_HEAP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/freertos/FreeRTOS-Kernel/portable/MemMang)
15+
16+
# Include directories
17+
include_directories(
18+
${CMAKE_CURRENT_SOURCE_DIR}/include
19+
${CMAKE_CURRENT_SOURCE_DIR}/freertos/FreeRTOS-Kernel/include
20+
${FREERTOS_PORT_DIR}
21+
${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfip/src
22+
${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfip
23+
${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfip/src/http
24+
${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfip/src/port
25+
${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfssl
26+
${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfssl/include
27+
)
28+
29+
# FreeRTOS source files
30+
set(FREERTOS_SOURCES
31+
${CMAKE_CURRENT_SOURCE_DIR}/freertos/FreeRTOS-Kernel/tasks.c
32+
${CMAKE_CURRENT_SOURCE_DIR}/freertos/FreeRTOS-Kernel/queue.c
33+
${CMAKE_CURRENT_SOURCE_DIR}/freertos/FreeRTOS-Kernel/list.c
34+
${CMAKE_CURRENT_SOURCE_DIR}/freertos/FreeRTOS-Kernel/timers.c
35+
${CMAKE_CURRENT_SOURCE_DIR}/freertos/FreeRTOS-Kernel/event_groups.c
36+
${CMAKE_CURRENT_SOURCE_DIR}/freertos/FreeRTOS-Kernel/stream_buffer.c
37+
${FREERTOS_PORT_DIR}/port.c
38+
${FREERTOS_HEAP_DIR}/heap_3.c
39+
${CMAKE_CURRENT_SOURCE_DIR}/freertos/utils/utils.c
40+
)
41+
42+
# Add wolfIP library
43+
add_library(wolfip STATIC
44+
${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfip/src/wolfip.c
45+
${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfip/src/http/httpd.c
46+
${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfip/src/port/wolfssl_io.c
47+
)
48+
49+
# Add the main application
50+
add_executable(freertos_sim
51+
${FREERTOS_SOURCES}
52+
src/main.c
53+
src/wolfip_freertos.c
54+
src/https_server.c
55+
)
56+
57+
target_link_libraries(freertos_sim
58+
pthread
59+
wolfip
60+
wolfssl
61+
)
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
cd build && cmake .. && make
36+
```
37+
38+
4. Run the example (requires root):
39+
```bash
40+
sudo ./freertos_sim
41+
```
42+
43+
### Testing
44+
Test the HTTPS server using curl:
45+
```bash
46+
sudo ./test_https.sh
47+
```
48+
49+
Or manually:
50+
```bash
51+
curl -v --cacert /path/to/wolfssl/certs/ca-cert.pem \
52+
--tlsv1.3 --insecure https://10.10.0.10:443/
53+
```
54+
55+
## Software Bill of Materials (SBOM)
56+
57+
| Component | Version | License | Source |
58+
|-----------|---------|----------|---------|
59+
| FreeRTOS | Latest | MIT | https://github.com/FreeRTOS/FreeRTOS |
60+
| FreeRTOS-Kernel | Latest | MIT | https://github.com/FreeRTOS/FreeRTOS-Kernel |
61+
| wolfSSL | Latest | GPLv2 | https://github.com/wolfSSL/wolfssl |
62+
| wolfIP | Latest | GPLv2 | https://github.com/wolfSSL/wolfip |
63+
64+
## Features
65+
- TLS 1.3 support with wolfSSL
66+
- Zero dynamic memory allocation networking with wolfIP
67+
- Virtual networking through TAP interface
68+
- UDP echo server for testing
69+
- HTTPS server with demo page
70+
- FreeRTOS task management and scheduling
71+
72+
## Network Configuration
73+
- TAP Interface: 10.10.0.1/24 (Host)
74+
- FreeRTOS IP: 10.10.0.10/24
75+
- Default Gateway: 10.10.0.1
76+
77+
## Security Features
78+
- TLS 1.3 with modern cipher suites
79+
- Certificate-based authentication
80+
- Support for various cryptographic algorithms:
81+
- AES (ECB, CBC, GCM)
82+
- ChaCha20-Poly1305
83+
- Curve25519
84+
- ED25519
85+
- SHA-2 and SHA-3 family
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include <errno.h>
2+
#include <pthread.h>
3+
#include <signal.h>
4+
#include <stdio.h>
5+
#include <stdlib.h>
6+
#include <unistd.h>
7+
8+
typedef struct event_t {
9+
pthread_mutex_t mutex;
10+
pthread_cond_t cond;
11+
int value;
12+
} event_t;
13+
14+
event_t *event_create(void) {
15+
event_t *event = malloc(sizeof(event_t));
16+
if (event != NULL) {
17+
pthread_mutex_init(&event->mutex, NULL);
18+
pthread_cond_init(&event->cond, NULL);
19+
event->value = 0;
20+
}
21+
return event;
22+
}
23+
24+
void event_delete(event_t *event) {
25+
if (event != NULL) {
26+
pthread_mutex_destroy(&event->mutex);
27+
pthread_cond_destroy(&event->cond);
28+
free(event);
29+
}
30+
}
31+
32+
void event_signal(event_t *event) {
33+
if (event != NULL) {
34+
pthread_mutex_lock(&event->mutex);
35+
event->value = 1;
36+
pthread_cond_signal(&event->cond);
37+
pthread_mutex_unlock(&event->mutex);
38+
}
39+
}
40+
41+
void event_wait(event_t *event) {
42+
if (event != NULL) {
43+
pthread_mutex_lock(&event->mutex);
44+
while (event->value == 0) {
45+
pthread_cond_wait(&event->cond, &event->mutex);
46+
}
47+
event->value = 0;
48+
pthread_mutex_unlock(&event->mutex);
49+
}
50+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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+
22+
#ifndef FREERTOS_CONFIG_H
23+
#define FREERTOS_CONFIG_H
24+
25+
/* Scheduler Related */
26+
#define configUSE_PREEMPTION 1
27+
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
28+
#define configUSE_TICKLESS_IDLE 0
29+
#define configCPU_CLOCK_HZ ( ( unsigned long ) 60000000 )
30+
#define configTICK_RATE_HZ ( ( TickType_t ) 1000 )
31+
#define configMAX_PRIORITIES 5
32+
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 4096 )
33+
#define configMAX_TASK_NAME_LEN 16
34+
#define configUSE_16_BIT_TICKS 0
35+
#define configIDLE_SHOULD_YIELD 1
36+
#define configUSE_TASK_NOTIFICATIONS 1
37+
#define configTASK_NOTIFICATION_ARRAY_ENTRIES 3
38+
#define configUSE_MUTEXES 1
39+
#define configUSE_RECURSIVE_MUTEXES 1
40+
#define configUSE_COUNTING_SEMAPHORES 1
41+
#define configQUEUE_REGISTRY_SIZE 10
42+
#define configUSE_QUEUE_SETS 0
43+
#define configUSE_TIME_SLICING 1
44+
#define configUSE_NEWLIB_REENTRANT 0
45+
#define configENABLE_BACKWARD_COMPATIBILITY 0
46+
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 5
47+
#define configUSE_MINI_LIST_ITEM 1
48+
49+
/* Memory allocation related definitions. */
50+
#define configSUPPORT_STATIC_ALLOCATION 0
51+
#define configSUPPORT_DYNAMIC_ALLOCATION 1
52+
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 60 * 1024 ) )
53+
#define configAPPLICATION_ALLOCATED_HEAP 0
54+
55+
/* Hook function related definitions. */
56+
#define configUSE_IDLE_HOOK 0
57+
#define configUSE_TICK_HOOK 0
58+
#define configCHECK_FOR_STACK_OVERFLOW 0
59+
#define configUSE_MALLOC_FAILED_HOOK 0
60+
#define configUSE_DAEMON_TASK_STARTUP_HOOK 0
61+
62+
/* Run time and task stats gathering related definitions. */
63+
#define configGENERATE_RUN_TIME_STATS 0
64+
#define configUSE_TRACE_FACILITY 0
65+
#define configUSE_STATS_FORMATTING_FUNCTIONS 0
66+
67+
/* Co-routine related definitions. */
68+
#define configUSE_CO_ROUTINES 0
69+
#define configMAX_CO_ROUTINE_PRIORITIES 1
70+
71+
/* Software timer related definitions. */
72+
#define configUSE_TIMERS 1
73+
#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
74+
#define configTIMER_QUEUE_LENGTH 10
75+
#define configTIMER_TASK_STACK_DEPTH configMINIMAL_STACK_SIZE
76+
77+
/* Define to trap errors during development. */
78+
#define configASSERT( x )
79+
80+
/* Optional functions - most linkers will remove unused functions anyway. */
81+
#define INCLUDE_vTaskPrioritySet 1
82+
#define INCLUDE_uxTaskPriorityGet 1
83+
#define INCLUDE_vTaskDelete 1
84+
#define INCLUDE_vTaskSuspend 1
85+
#define INCLUDE_xResumeFromISR 1
86+
#define INCLUDE_vTaskDelayUntil 1
87+
#define INCLUDE_vTaskDelay 1
88+
#define INCLUDE_xTaskGetSchedulerState 1
89+
#define INCLUDE_xTaskGetCurrentTaskHandle 1
90+
#define INCLUDE_uxTaskGetStackHighWaterMark 0
91+
#define INCLUDE_xTaskGetIdleTaskHandle 0
92+
#define INCLUDE_eTaskGetState 0
93+
#define INCLUDE_xEventGroupSetBitFromISR 1
94+
#define INCLUDE_xTimerPendFunctionCall 0
95+
#define INCLUDE_xTaskAbortDelay 0
96+
#define INCLUDE_xTaskGetHandle 0
97+
#define INCLUDE_xTaskResumeFromISR 1
98+
99+
/* POSIX Port specific definitions. */
100+
#define configPOSIX_STACK_SIZE ( ( unsigned short ) 8192 )
101+
102+
#endif /* FREERTOS_CONFIG_H */
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 */

0 commit comments

Comments
 (0)