Skip to content

feat(cloud-relay): real TLS via stock espressif32 platform - #6

Merged
johnsonflix merged 3 commits into
evolights/mainfrom
feat/firmware-tls-via-platform-switch
May 3, 2026
Merged

johnsonflix merged 3 commits into
evolights/mainfrom
feat/firmware-tls-via-platform-switch

Conversation

@johnsonflix

Copy link
Copy Markdown
Owner

Summary

The Tasmota slim framework-arduinoespressif32 v2.0.18 used by upstream WLED envs intentionally strips mbedtls SSL and WiFiClientSecure. Linking real TLS on top of that produces dozens of undefined reference to mbedtls_ssl_* errors. This PR overrides platform = espressif32 @ 6.7.0 (PIO stock, full mbedtls + the upstream WiFiClientSecure) on the *_evolights envs only, so upstream WLED envs are unaffected.

Changes

  • platformio.ini: [evolights_common] now sets platform = espressif32 @ 6.7.0 and empty platform_packages. Each *_evolights env inherits these via explicit platform = ${evolights_common.platform} lines so they win over the parent env's Tasmota platform. Wrapped in new EVOLIGHTS-ANCHOR: platform-stock-espressif32 markers.
  • usermods/cloud_relay/cloud_relay.cpp: WiFiClient g_tcp → WiFiClientSecure g_tls. Pins g_tls.setCACert(g_caCertPem.c_str()) before each connect. Fails CLOSED if no CA is pinned. No setInsecure() anywhere. Default port stays 8883. Stale "TLS TODO" header replaced with a "TLS via stock platform" header.
  • usermods/cloud_relay/ota_verifier.cpp: artifact download now goes over HTTPS via WiFiClientSecure. Uses setInsecure() here because the Ed25519 sig over version|url|sha256 plus the sha256 verify on the bytes is the documented trust anchor (see EVOLIGHTS-ANCHOR: ota-trust-model).
  • tools/verify-evolights-integration.sh: new positive TLS guards — WiFiClientSecure g_tls, g_tls.setCACert(, new PubSubClient(g_tls), no setInsecure() in cloud_relay.cpp, and platform-stock-espressif32:platformio.ini anchor. A future refactor that drops the platform override or reverts to plaintext fails the check.

Test plan

  • bash tools/verify-evolights-integration.sh → 59 passed, 0 failed
  • CI: esp32dev_evolights builds green
  • CI: esp32_eth_evolights builds green
  • CI: esp32s3dev_8MB_qspi_evolights builds green
  • (post-merge) Wire-test: device pairs, opens TLS to broker:8883, broker presents pinned CA, MQTT command roundtrip succeeds. With CA scrubbed from wsec, cloud_relay refuses to connect.

arjohnson15 and others added 3 commits May 3, 2026 13:13
The Tasmota slim framework-arduinoespressif32 v2.0.18 used by upstream WLED
envs strips mbedtls SSL and WiFiClientSecure entirely, making real MQTT-over-
TLS unlinkable from the cloud_relay usermod. This commit:

  * Overrides the platform on each *_evolights env to stock
    PlatformIO espressif32 @ 6.7.0 (full mbedtls + WiFiClientSecure).
    Wrapped in EVOLIGHTS-ANCHOR: platform-stock-espressif32.
  * Switches cloud_relay.cpp from plain WiFiClient to WiFiClientSecure with
    setCACert(broker_ca) — fails CLOSED if no CA is pinned. Default port 8883.
  * Switches ota_verifier.cpp to WiFiClientSecure for the artifact download.
    Uses setInsecure() because the Ed25519 sig over (version|url|sha256) plus
    the sha256 verify on the bytes is the documented trust anchor.
  * Adds positive TLS guards to verify-evolights-integration.sh so a future
    refactor that drops the platform override or reverts to plain WiFiClient
    fails the integration check before it can ship.

Tested-by: tools/verify-evolights-integration.sh (59 passed, 0 failed)

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
WiFiClientSecure::setCACert stores the const char* pointer (not a copy).
Document the actual lifetime constraint instead of claiming a copy that
doesn't happen.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Stock espressif32 with full mbedtls SSL + WiFiClientSecure adds ~240 KB
to the sketch vs the Tasmota slim framework. The default
WLED_ESP32_4MB_1MB_FS partition (1.5 MB sketch slot) overflows by:
  esp32dev_evolights:     1812257 / 1572864 bytes (115.2%)
  esp32_eth_evolights:    1850985 / 1572864 bytes (117.7%)

Switch both 4 MB envs to big_partitions = WLED_ESP32_4MB_256KB_FS.csv
(1.875 MB sketch / 256 KB FS) — leaves ~80 KB headroom. The ESP32-S3
8 MB env was already on extreme_partitions and didn't overflow.

Trade-off: LittleFS shrinks from 960 KB to 256 KB. WLED's preset/config
storage is well under 256 KB in practice; if a deployment hits the wall
they should move to an 8 MB board (and we already ship that variant).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@johnsonflix

Copy link
Copy Markdown
Owner Author

CI green at 0713ff7

All 4 required checks pass:

Check Result Time Flash usage
verify pass 5s (script)
build (esp32dev_evolights) pass 2m35s 95.4% (1812257 / 1900544 B)
build (esp32_eth_evolights) pass 2m23s 97.4% (1850985 / 1900544 B)
build (esp32s3dev_8MB_qspi_evolights) pass 2m53s 83.4% (1748265 / 2097152 B)

WiFiClientSecure.cpp.o, ssl_client.cpp.o, and esp_crt_bundle.c.o are all compiled, archived into libWiFiClientSecure.a, and linked into all three binaries — confirmed via INFO: Code from usermod libraries found in binary: audioreactive, cloud_relay.

The 4 MB ESP32 envs are tight (esp32_eth_evolights at 49 KB headroom). If we add more code to the cloud relay surface in the future, those two envs will need to either jump to an 8 MB part or shed something. The S3 env has 350 KB of room.

@johnsonflix
johnsonflix merged commit cfe15b5 into evolights/main May 3, 2026
20 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants