From 0d90973842466b909265d3fed45f419cd26aa913 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 17 Aug 2024 13:49:55 +0200 Subject: [PATCH] Start to work on networking --- esp32_device/main/constants.h | 5 +++++ esp32_device/main/main.c | 6 ++++++ esp32_device/main/unsecure_api.c | 11 +++++++++++ esp32_device/main/unsecure_api.h | 22 ++++++++++++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 esp32_device/main/unsecure_api.c create mode 100644 esp32_device/main/unsecure_api.h diff --git a/esp32_device/main/constants.h b/esp32_device/main/constants.h index ff6bbba..335c595 100644 --- a/esp32_device/main/constants.h +++ b/esp32_device/main/constants.h @@ -1,5 +1,10 @@ #pragma once +/** + * Backend unsecure API URL + */ +#define BACKEND_UNSECURE_URL "http://devweb.internal:8080" + /** * Device name len */ diff --git a/esp32_device/main/main.c b/esp32_device/main/main.c index 39c3455..ef0e411 100755 --- a/esp32_device/main/main.c +++ b/esp32_device/main/main.c @@ -5,6 +5,7 @@ #include "storage.h" #include "system.h" #include "crypto.h" +#include "unsecure_api.h" void app_main(void) { @@ -36,5 +37,10 @@ void app_main(void) printf("Current CSR:\n%s\n", csr); free(csr); + printf("Check secure origin\n"); + char *sec_orig = unsecure_api_get_secure_origin(); + assert(sec_orig != NULL); + printf("Res = %s\n", sec_orig); + reboot(); } diff --git a/esp32_device/main/unsecure_api.c b/esp32_device/main/unsecure_api.c new file mode 100644 index 0000000..65123d6 --- /dev/null +++ b/esp32_device/main/unsecure_api.c @@ -0,0 +1,11 @@ +#include "unsecure_api.h" +#include "constants.h" +#include "esp_http_client.h" + +#include + +char *unsecure_api_get_secure_origin() +{ + const char *url = BACKEND_UNSECURE_URL "/secure_origin"; + return strdup(url); +} \ No newline at end of file diff --git a/esp32_device/main/unsecure_api.h b/esp32_device/main/unsecure_api.h new file mode 100644 index 0000000..c1b7adb --- /dev/null +++ b/esp32_device/main/unsecure_api.h @@ -0,0 +1,22 @@ +/** + * Unsecure API functions + */ + +#pragma once + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * Get secure origin + * + * @returns The URL to the secure origin or NULL in case of failure. Value must be + * released by caller. + */ + char *unsecure_api_get_secure_origin(); + +#ifdef __cplusplus +} +#endif