Update build, use EC certs
Some checks failed
Build and test - essentials / linux ${{ matrix.target }} CC=${{ matrix.cc }} SSL=${{ matrix.ssl }} (clang++, , mip_test) (push) Has been cancelled
Build and test - essentials / linux ${{ matrix.target }} CC=${{ matrix.cc }} SSL=${{ matrix.ssl }} (clang++, , test) (push) Has been cancelled
Build and test - essentials / linux ${{ matrix.target }} CC=${{ matrix.cc }} SSL=${{ matrix.ssl }} (clang++, BUILTIN, mip_test) (push) Has been cancelled
Build and test - essentials / linux ${{ matrix.target }} CC=${{ matrix.cc }} SSL=${{ matrix.ssl }} (clang++, BUILTIN, test) (push) Has been cancelled
Build and test - essentials / linux ${{ matrix.target }} CC=${{ matrix.cc }} SSL=${{ matrix.ssl }} (gcc, , mip_test) (push) Has been cancelled
Build and test - essentials / linux ${{ matrix.target }} CC=${{ matrix.cc }} SSL=${{ matrix.ssl }} (gcc, , test) (push) Has been cancelled
Build and test - essentials / linux ${{ matrix.target }} CC=${{ matrix.cc }} SSL=${{ matrix.ssl }} (gcc, BUILTIN, mip_test) (push) Has been cancelled
Build and test - essentials / linux ${{ matrix.target }} CC=${{ matrix.cc }} SSL=${{ matrix.ssl }} (gcc, BUILTIN, test) (push) Has been cancelled
Build and test - essentials / s390 (push) Has been cancelled
Build and test - essentials / armhf (push) Has been cancelled
Build and test - essentials / unamalgamated-mg_prefix (push) Has been cancelled
Build and test - essentials / macos SSL=${{ matrix.ssl }} () (push) Has been cancelled
Build and test - essentials / macos SSL=${{ matrix.ssl }} (BUILTIN) (push) Has been cancelled
Build and test - essentials / windows ${{ matrix.target }} (mingw++) (push) Has been cancelled
Build and test - essentials / windows ${{ matrix.target }} (vc22) (push) Has been cancelled
Build and test - essentials / windows ${{ matrix.target }} (vc98) (push) Has been cancelled
Build and test - essentials / arm (push) Has been cancelled
Build and test - essentials / riscv (push) Has been cancelled
Build and test - essentials / examples (push) Has been cancelled
Build and test - essentials / examples_win (push) Has been cancelled
Build and test - essentials / examples_mac (push) Has been cancelled
Build and test - essentials / refprojs (push) Has been cancelled
Build and test - essentials / refprojs_win (push) Has been cancelled
Build and test - essentials / refprojs_mac (push) Has been cancelled
Build and test - essentials / tutorials (push) Has been cancelled
Build and test - essentials / tutorials_win (push) Has been cancelled
Build and test - essentials / tutorials_mac (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:nxp/frdm-mcxn947-make-baremetal-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:nxp/frdm-mcxn947-make-freertos-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:nxp/rt1020-evk-make-baremetal-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:nxp/rt1060-evk-make-baremetal-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:nxp/rt1170-evk-make-baremetal-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:stm32/nucleo-f429zi-make-baremetal-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:stm32/nucleo-f429zi-make-freertos-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:stm32/nucleo-f746zg-make-baremetal-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:stm32/nucleo-f746zg-make-freertos-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:stm32/nucleo-h563zi-make-baremetal-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:stm32/nucleo-h563zi-make-freertos-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:stm32/nucleo-h723zg-make-baremetal-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:stm32/nucleo-h723zg-make-freertos-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:stm32/nucleo-h743zi-make-baremetal-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:stm32/nucleo-h743zi-make-freertos-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:stm32/stm32h573i-dk-make-baremetal-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:stm32/stm32h573i-dk-make-freertos-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:ti/ek-tm4c1294xl-make-baremetal-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:ti/ek-tm4c1294xl-make-freertos-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:esp32/uart-bridge]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:esp8266/http-client-server]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:infineon/infineon-xmc4700_4800-lwip-rtx-rtos]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:stm32/nucleo-g031-make-baremetal-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:esp32/device-dashboard]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:infineon/infineon-xmc7200]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:microchip/same54-xpro/device-dashboard]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:nxp/rt1020-evk-make-freertos-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:nxp/rt1060-evk-make-freertos-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:nxp/rt1170-evk-make-freertos-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:renesas/ek-ra6m4-make-baremetal-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:rp2040/pico-rndis-dashboard]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:rp2040/pico-w5500]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:rp2040/pico-w]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:stm32/nucleo-f746zg-make-baremetal-builtin-cmsis_driver]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:stm32/nucleo-f746zg-make-freertos-tcp]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:rp2040/pico-rndis-device]) (push) Has been cancelled
Build and test - essentials / cube_examples (push) Has been cancelled
Build and test - essentials / test_f7 (push) Has been cancelled
Build and test - essentials / test_f4 (push) Has been cancelled
Build and test - essentials / test_h743 (push) Has been cancelled
Build and test - essentials / test_h723 (push) Has been cancelled
Build and test - essentials / test_h5 (push) Has been cancelled
Build and test - essentials / test_rt1020 (push) Has been cancelled
Build and test - essentials / test_rt1060 (push) Has been cancelled
Build and test - essentials / test_rt1170 (push) Has been cancelled
Build and test - essentials / test_ra6m4 (push) Has been cancelled
Build and test - essentials / test_tm4c (push) Has been cancelled
Build and test - essentials / test_same54 (push) Has been cancelled
Build and test - essentials / test_pico_w5500 (push) Has been cancelled

This commit is contained in:
Sergey Lyubka 2024-11-10 08:45:34 +00:00
parent 51a5dc78d7
commit 0aa61ce58f
3 changed files with 36 additions and 33 deletions

View File

@ -1,11 +1,14 @@
PROG ?= example # Program we are building
DELETE = rm -rf # Command to remove files
OUT ?= -o $(PROG) # Compiler argument for output file
SOURCES = main.c mongoose.c packed_fs.c # Source code files, packed_fs.c contains ca.pem, which contains CA certs for TLS
CFLAGS = -W -Wall -Wextra -g -I. # Build options
SOURCES = main.c mongoose.c mongoose_fs.c
# Mongoose build options. See https://mongoose.ws/documentation/#build-options
CFLAGS_MONGOOSE += -DMG_ENABLE_LINES=1 -DMG_ENABLE_PACKED_FS=1
CFLAGS_MONGOOSE += -DMG_ENABLE_PACKED_FS=1
#CFLAGS_MONGOOSE += -DMG_TLS=MG_TLS_BUILTIN
CFLAGS_MONGOOSE += -DMG_TLS=MG_TLS_OPENSSL -lssl -lcrypto -I/opt/homebrew/opt/openssl@3.4/include/ -L/opt/homebrew/opt/openssl@3.4/lib
#CFLAGS_MONGOOSE += -DMG_TLS=MG_TLS_MBED -lmbedtls -lmbedcrypto -lmbedx509 -I/opt/homebrew/opt/mbedtls/include/ -L/opt/homebrew/opt/mbedtls/lib
ifeq ($(OS),Windows_NT) # Windows settings. Assume MinGW compiler. To use VC: make CC=cl CFLAGS=/MD OUT=/Feprog.exe
PROG ?= example.exe # Use .exe suffix for the binary
@ -16,17 +19,18 @@ ifeq ($(OS),Windows_NT) # Windows settings. Assume MinGW compiler. To use VC:
MAKE += WINDOWS=1 CC=$(CC)
endif
all: $(PROG) # Default target. Build and run program
all: $(PROG)
$(RUN) ./$(PROG) $(ARGS)
$(PROG): $(SOURCES) # Build program from sources
$(PROG): $(SOURCES) Makefile
$(CC) $(SOURCES) $(CFLAGS) $(CFLAGS_MONGOOSE) $(CFLAGS_EXTRA) $(OUT)
clean: # Cleanup. Delete built program and all build artifacts
csr:
openssl ecparam -noout -name prime256v1 -genkey -out key.pem
openssl req -new -key key.pem -subj /CN=Mongoose -out crt.csr
mongoose_fs.c: ca.pem crt.pem key.pem
node ../../../test/pack.js ca.pem crt.pem key.pem > $@
clean:
$(DELETE) $(PROG) *.o *.obj *.exe *.dSYM mbedtls
# see https://mongoose.ws/tutorials/tls/#how-to-build for TLS build options
mbedtls: # Pull and build mbedTLS library
git clone --depth 1 -b v2.28.2 https://github.com/mbed-tls/mbedtls $@
$(MAKE) -C mbedtls/library

View File

@ -6,32 +6,29 @@
// 2. When connected, subscribes to the topic `s_rx_topic`
// 3. Publishes message `hello` to the `s_tx_topic` periodically
//
// This example requires TLS support. By default, it is built with mbedTLS,
// therefore make sure mbedTLS is installed. To build with OpenSSL, execute:
// make clean all CFLAGS="-W -Wall -DMG_ENABLE_OPENSSL=1 -lssl"
// In order to get MQTT URL, login to AWS IoT, click on "Settings" on the left
// bar, copy the "Endpoint" URL.
static const char *s_url =
"mqtts://a1pjwh2bop1ojt-ats.iot.eu-west-1.amazonaws.com";
// To create certificates:
// 1. Click Policies -> Create, fill fields:
// Name : Policy1
// How to build and run this example:
// 1. Login to AWS IoT
// 2. Click "Settings" on the left bar, copy the domain, change s_url below
// 3. Click Security -> Policies -> Create Policy, fill fields:
// Name : PolicyAllow
// Action : iot:*
// Resource ARN: *
// Effect : allow
// then, click "Create"
// 2. Click Manage -> Things -> Create things -> Create single thing -> Next
// Thing name: t1, no shadow, Next
// Auto-generate new certificate, Next
// Select policy Policy1, Create thing
// 3. From the dialog box that appears, download:
// xxx-certificate.pem.crt as cert.pem to the example directory
// xxx-private.pem.key as key.pem to the example directory
// static const char *s_cert = "cert.pem";
// static const char *s_key = "key.pem";
// 4. Create EC private key file and CSR (Certificate Signing Request)
// type "make csr", see Makefile
// 5. Click Security -> Certificates -> Add Certificate -> Create Certificate
// Choose "Create certificate with certificate signing request (CSR)"
// Choose "crt.csr" created on a previous step
// Choose "Active" to activate certificate
// Click Create
// Downoad AmazonRootCA1.pem as ca.pem and generated certificate as crt.pem
// Select certificate, attach PolicyAllow to it
// 6. Type "make" to build and run the example
static const char *s_url =
"mqtts://a1pjwh2bop1ojt-ats.iot.eu-west-1.amazonaws.com";
static const char *s_rx_topic = "d/rx";
static const char *s_tx_topic = "d/tx";
static int s_qos = 1;
@ -43,7 +40,9 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
// c->is_hexdumping = 1;
} else if (ev == MG_EV_CONNECT) {
if (mg_url_is_ssl(s_url)) {
struct mg_tls_opts opts = {.ca = mg_unpacked("/certs/ca.pem"),
struct mg_tls_opts opts = {.ca = mg_unpacked("/ca.pem"),
.cert = mg_unpacked("/crt.pem"),
.key = mg_unpacked("/key.pem"),
.name = mg_url_host(s_url)};
mg_tls_init(c, &opts);
}
@ -92,6 +91,7 @@ int main(void) {
struct mg_mgr mgr;
struct mg_mqtt_opts opts = {.clean = true};
bool done = false;
mg_log_set(MG_LL_DEBUG);
mg_mgr_init(&mgr); // Initialise event manager
MG_INFO(("Connecting to %s", s_url)); // Inform that we're starting
mg_mqtt_connect(&mgr, s_url, &opts, fn, &done); // Create client connection

View File

@ -1 +0,0 @@
../../http/http-client/packed_fs.c