Skip to content

Commit 51febec

Browse files
committed
ESP32: Fix EAP mode
Since switching to mbedTLS for 802.1x, cert and key blobs need to be NUL terminated and NUL included in the blob length. h/t @harold-martin
1 parent 18c36a1 commit 51febec

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/esp32/esp32_wifi.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,13 @@ bool mgos_wifi_dev_sta_setup(const struct mgos_config_wifi_sta *cfg) {
409409
LOG(LL_ERROR, ("Failed to read %s", cfg->ca_cert));
410410
goto out;
411411
}
412+
/* For mbedTLS to parse certificate as PEM, mbedtls_x509_crt_parse needs
413+
* teh blob to be NUL terminated and NUL byte included in the blob length.
414+
* Luckily, cs_read_file is nice enough to NUL-terminate the data for us
415+
* (just in case) though it returns size without the NUL.
416+
* Hence the len + 1 below. */
412417
esp_wifi_sta_wpa2_ent_set_ca_cert((unsigned char *) s_ca_cert_pem,
413-
(int) len);
418+
(int) len + 1);
414419
} else {
415420
esp_wifi_sta_wpa2_ent_clear_ca_cert();
416421
}
@@ -430,8 +435,8 @@ bool mgos_wifi_dev_sta_setup(const struct mgos_config_wifi_sta *cfg) {
430435
goto out;
431436
}
432437
esp_wifi_sta_wpa2_ent_set_cert_key(
433-
(unsigned char *) s_cert_pem, (int) cert_len,
434-
(unsigned char *) s_key_pem, (int) key_len,
438+
(unsigned char *) s_cert_pem, (int) cert_len + 1,
439+
(unsigned char *) s_key_pem, (int) key_len + 1,
435440
NULL /* private_key_passwd */, 0 /* private_key_passwd_len */);
436441
} else {
437442
esp_wifi_sta_wpa2_ent_clear_cert_key();

0 commit comments

Comments
 (0)