Hi, I'm trying to connect my ESP32 S3 DevKitC 1 N16R8 to an MQTT broker using TLS certificates. I'm trying to include them as files to create an automatic update system, but I'm having trouble.
I've tried many methods, but none have worked. Can anyone tell me how to include them correctly?
Thanks in advance.
Import TLS certificates as files
Re: Import TLS certificates as files
If you still haven’t found the answer here is how I’m doing on my side when connecting esp32 devices to mosquito MQTT broker using TLS and 2-way certificate authentication.

- Edit CMakeLists.txt in the root folder of your project and add the following lines
Where
Code: Select all
target_add_binary_data(${CMAKE_PROJECT_NAME}.elf "path/client.crt" TEXT) target_add_binary_data(${CMAKE_PROJECT_NAME}.elf "path/client.key" TEXT) target_add_binary_data(${CMAKE_PROJECT_NAME}.elf "path/ca.crt" TEXT)
- path/ is the path to your certificates and key
- client.crt/key is the client certificate and key esp32 mqtt client will use to authenticate to the broker
- ca.crt is the root ca of your PKI infrastructure , esp32 mqtt client will use to validate broker certificate
[] - modify client configuration file (esp_mqtt_client_config_t) and add the fields below
[]
Code: Select all
esp_mqtt_client_config_t mqtt_cfg = { ... .broker.verification.certificate = (const char *)ca_cert_pem_start, .credentials = { .client_id = USER_MQTT, .authentication = { .certificate = (const char *)client_cert_pem_start, .key = (const char *)client_key_pem_start, }, }, ... }; - make sure …..pem_start fields are declared in external directives like this
Code: Select all
extern const uint8_t client_cert_pem_start[] asm("_binary_client_crt_start"); extern const uint8_t client_cert_pem_end[] asm("_binary_client_crt_end"); extern const uint8_t client_key_pem_start[] asm("_binary_client_key_start"); extern const uint8_t client_key_pem_end[] asm("_binary_client_key_end"); extern const uint8_t ca_cert_pem_start[] asm("_binary_ca_crt_start"); extern const uint8_t ca_cert_pem_end[] asm("_binary_ca_crt_end");
-
nopnop2002
- Posts: 347
- Joined: Thu Oct 03, 2019 10:52 pm
- Contact:
Re: Import TLS certificates as files
If you have information about the MQTT broker you want to use, you may be able to get a more accurate answer.I'm trying to connect my ESP32 S3 DevKitC 1 N16R8 to an MQTT broker using TLS certificates.
-
Craige Hales
- Posts: 98
- Joined: Tue Sep 07, 2021 12:07 pm
Re: Import TLS certificates as files
several years and versions ago I discovered a trailing nul was needed.
note the difference between embed files vs embed txtfiles...a text file got an extra nul byte that prevented something from reading off the end.
Code: Select all
EMBED_FILES
# "spiffsdata/favicon.ico"
"upload_script.html"
# adds a trailing nul? makes it work?
EMBED_TXTFILES
"certs/cacert.pem"
"certs/prvtkey.pem"Craige
Who is online
Users browsing this forum: Baidu [Spider], ChatGPT-User, meta-externalagent and 9 guests