Skip to content

Commit

Permalink
Add built-in TLS 1.3 stack: server side, EC support
Browse files Browse the repository at this point in the history
  • Loading branch information
cpq committed Dec 19, 2023
1 parent df3c216 commit c6f7572
Show file tree
Hide file tree
Showing 18 changed files with 15,600 additions and 3,567 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ mongoose.c: Makefile $(wildcard src/*.c) $(wildcard src/drivers/*.c)
(cat src/license.h; echo; echo '#include "mongoose.h"' ; (for F in src/*.c src/drivers/*.c ; do echo; echo '#ifdef MG_ENABLE_LINES'; echo "#line 1 \"$$F\""; echo '#endif'; cat $$F | sed -e 's,#include ".*,,'; done))> $@

mongoose.h: $(HDRS) Makefile
(cat src/license.h; echo; echo '#ifndef MONGOOSE_H'; echo '#define MONGOOSE_H'; echo; cat src/version.h ; echo; echo '#ifdef __cplusplus'; echo 'extern "C" {'; echo '#endif'; cat src/arch.h src/arch_*.h src/net_ft.h src/net_lwip.h src/net_rl.h src/config.h src/str.h src/queue.h src/fmt.h src/printf.h src/log.h src/timer.h src/fs.h src/util.h src/url.h src/iobuf.h src/base64.h src/md5.h src/sha1.h src/event.h src/net.h src/profile.h src/http.h src/ssi.h src/tls.h src/tls_mbed.h src/tls_openssl.h src/ws.h src/sntp.h src/mqtt.h src/dns.h src/json.h src/rpc.h src/ota.h src/device.h src/net_builtin.h src/drivers/*.h | sed -e '/keep/! s,#include ".*,,' -e 's,^#pragma once,,'; echo; echo '#ifdef __cplusplus'; echo '}'; echo '#endif'; echo '#endif // MONGOOSE_H')> $@
(cat src/license.h; echo; echo '#ifndef MONGOOSE_H'; echo '#define MONGOOSE_H'; echo; cat src/version.h ; echo; echo '#ifdef __cplusplus'; echo 'extern "C" {'; echo '#endif'; cat src/arch.h src/arch_*.h src/net_ft.h src/net_lwip.h src/net_rl.h src/config.h src/str.h src/queue.h src/fmt.h src/printf.h src/log.h src/timer.h src/fs.h src/util.h src/url.h src/iobuf.h src/base64.h src/md5.h src/sha1.h src/sha256.h src/tls_aes128.h src/tls_uecc.h src/event.h src/net.h src/http.h src/ssi.h src/tls.h src/tls_mbed.h src/tls_openssl.h src/ws.h src/sntp.h src/mqtt.h src/dns.h src/json.h src/rpc.h src/ota.h src/device.h src/net_builtin.h src/profile.h src/drivers/*.h | sed -e '/keep/! s,#include ".*,,' -e 's,^#pragma once,,'; echo; echo '#ifdef __cplusplus'; echo '}'; echo '#endif'; echo '#endif // MONGOOSE_H')> $@


clean: clean_examples clean_embedded
rm -rf $(PROG) *.exe *.o *.dSYM *_test* ut fuzzer *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb slow-unit* _CL_* infer-out data.txt crash-* test/packed_fs.c pack
Expand Down
2 changes: 2 additions & 0 deletions examples/device-dashboard/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ ifeq ($(TLS), mbedtls)
CFLAGS += -DMG_TLS=MG_TLS_MBED -Wno-conversion -Imbedtls/include
CFLAGS += -DMBEDTLS_CONFIG_FILE=\"mbedtls_config.h\" mbedtls/library/*.c
$(PROG): mbedtls
else
CFLAGS += -DMG_TLS=MG_TLS_BUILTIN
endif

# Cleanup. Delete built program and all build artifacts
Expand Down
12 changes: 5 additions & 7 deletions examples/device-dashboard/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ static void handle_debug(struct mg_connection *c, struct mg_http_message *hm) {
}

static size_t print_int_arr(void (*out)(char, void *), void *ptr, va_list *ap) {
size_t len = 0, num = va_arg(*ap, size_t); // Number of items in the array
size_t i, len = 0, num = va_arg(*ap, size_t); // Number of items in the array
int *arr = va_arg(*ap, int *); // Array ptr
for (size_t i = 0; i < num; i++) {
for (i = 0; i < num; i++) {
len += mg_xprintf(out, ptr, "%s%d", i == 0 ? "" : ",", arr[i]);
}
return len;
Expand Down Expand Up @@ -168,21 +168,19 @@ static void handle_events_get(struct mg_connection *c,

static void handle_settings_set(struct mg_connection *c, struct mg_str body) {
struct settings settings;
char *s = mg_json_get_str(body, "$.device_name");
bool ok = true;
memset(&settings, 0, sizeof(settings));
mg_json_get_bool(body, "$.log_enabled", &settings.log_enabled);
settings.log_level = mg_json_get_long(body, "$.log_level", 0);
settings.brightness = mg_json_get_long(body, "$.brightness", 0);
char *s = mg_json_get_str(body, "$.device_name");
if (s && strlen(s) < MAX_DEVICE_NAME) {
free(settings.device_name);
settings.device_name = s;
} else {
free(s);
}

// Save to the device flash
s_settings = settings;
bool ok = true;
s_settings = settings; // Save to the device flash
mg_http_reply(c, 200, s_json_header,
"{%m:%s,%m:%m}", //
MG_ESC("status"), ok ? "true" : "false", //
Expand Down
4 changes: 2 additions & 2 deletions examples/device-dashboard/packed_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ static const unsigned char v1[] = {
0, 0 // .
};
static const unsigned char v2[] = {
31, 139, 8, 8, 246, 5, 126, 101, 0, 3, 99, 111, // ......~e..co
31, 139, 8, 8, 87, 102, 129, 101, 0, 3, 99, 111, // ....Wf.e..co
109, 112, 111, 110, 101, 110, 116, 115, 46, 106, 115, 0, // mponents.js.
237, 93, 235, 115, 219, 70, 146, 255, 238, 191, 98, 162, // .].s.F....b.
242, 45, 169, 181, 0, 225, 77, 64, 182, 148, 114, 156, // .-....M@..r.
Expand Down Expand Up @@ -2668,7 +2668,7 @@ static const struct packed_file {
time_t mtime;
} packed_files[] = {
{"/web_root/bundle.js.gz", v1, sizeof(v1), 1695912421},
{"/web_root/components.js.gz", v2, sizeof(v2), 1702757878},
{"/web_root/components.js.gz", v2, sizeof(v2), 1702979159},
{"/web_root/history.min.js.gz", v3, sizeof(v3), 1695912421},
{"/web_root/index.html.gz", v4, sizeof(v4), 1693654553},
{"/web_root/main.css.gz", v5, sizeof(v5), 1702757929},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ SOURCES += mongoose.c net.c packed_fs.c

# Example specific build options. See README.md
CFLAGS += -DHTTP_URL=\"http://0.0.0.0/\" -DHTTPS_URL=\"https://0.0.0.0/\"
CFLAGS += -DMG_TLS=MG_TLS_BUILTIN

ifeq ($(OS),Windows_NT)
RM = cmd /C del /Q /F /S
Expand Down
3 changes: 2 additions & 1 deletion examples/stm32/nucleo-h723zg-make-baremetal-builtin/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ void mg_random(void *buf, size_t len) { // Use on-board RNG
}

#ifdef MQTT_DASHBOARD
void hal_gpio_write(int pin, bool status) { // For MQTT dashboard HAL
bool hal_gpio_write(int pin, bool status) { // For MQTT dashboard HAL
gpio_write((uint16_t) pin, status);
return true;
}

bool hal_gpio_read(int pin) { // For MQTT dashboard HAL
Expand Down
Loading

0 comments on commit c6f7572

Please sign in to comment.