Skip to content

Commit 03775d2

Browse files
tyethclaude
andcommitted
zephyr-cp: make TLS 1.2 ECDHE and PEM certificates work on the Pico W boards
Two Kconfig gaps kept an HTTPS server (or client) from ever completing a handshake on these boards: - Zephyr's mbedTLS 4 default serves secp256r1 through the p256-m PSA driver and leaves the builtin ECP module out. mbedTLS then defines the dummy MBEDTLS_ECP_MAX_BITS 1, and ssl.h sizes the TLS 1.2 premaster buffer (union mbedtls_ssl_premaster_secret._pms_ecdh[MBEDTLS_ECP_MAX_BYTES]) from it: sizeof(handshake->premaster) was 1 in the firmware (DWARF). Every ECDHE key agreement then failed -- "psa_raw_key_agreement() returned -138 (-0x008a)", PSA_ERROR_BUFFER_TOO_SMALL for a 32-byte shared secret -- and the raw PSA status leaked through mbedtls_ssl_read() as OSError 138 on the first read of any TLS connection. Disabling the p256-m driver brings the builtin ECP module back and the buffer is 32 bytes again. This is an upstream sizing bug (ssl.h should size that buffer from PSA when the ECP module is absent); the Kconfig is the workaround until it is fixed. - PEM parsing was not compiled in, so load_cert_chain() with the usual fullchain.pem / key.pem could only fail; the collector's certstore is PEM. Verified on a Pico 2 W: an RSA-2048 PEM certificate served from CIRCUITPY over the softAP; an ESP32-C6 client completed the handshake and received "HTTP/1.0 200 OK" in 2.0 s. Flash +1,868 B (PEM) and +4,716 B (builtin ECP instead of p256-m) on the Pico 2 W; no static RAM change. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent ba0232c commit 03775d2

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

‎ports/zephyr-cp/boards/raspberrypi/rpi_pico2_w_zephyr/board.conf‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@ CONFIG_MBEDTLS_CIPHERSUITE_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256=y
2525
CONFIG_MBEDTLS_ENTROPY_C=y
2626
CONFIG_MBEDTLS_CTR_DRBG_C=y
2727

28+
# The collector's captive portal serves HTTPS from a PEM certificate chain
29+
# (fullchain.pem / key.pem via ssl.SSLContext.load_cert_chain); mbedTLS only
30+
# parses DER unless PEM decoding is compiled in.
31+
CONFIG_MBEDTLS_PEM_PARSE_C=y
32+
33+
# TLS 1.2 ECDHE. Zephyr's mbedTLS 4 default serves secp256r1 through the p256-m
34+
# PSA driver and leaves the builtin ECP module out. mbedTLS then defines a dummy
35+
# MBEDTLS_ECP_MAX_BITS of 1, and ssl.h sizes the TLS 1.2 premaster buffer
36+
# (union mbedtls_ssl_premaster_secret._pms_ecdh[MBEDTLS_ECP_MAX_BYTES]) from
37+
# it, so every ECDHE key agreement fails with PSA_ERROR_BUFFER_TOO_SMALL -- a
38+
# 1-byte buffer for a 32-byte shared secret -- and surfaces as OSError 138 on
39+
# the first read of any TLS connection, client or server. Keep the builtin
40+
# ECP module (p256-m off) until the header sizes that buffer from PSA.
41+
CONFIG_MBEDTLS_PSA_P256M_DRIVER_ENABLED=n
42+
2843
# Bluetooth over the shared gSPI bus (CONFIG_BT itself comes from the
2944
# zephyr,bt-hci chosen node in the overlay).
3045
#

‎ports/zephyr-cp/boards/raspberrypi/rpi_pico_w_zephyr/board.conf‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@ CONFIG_MBEDTLS_CIPHERSUITE_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256=y
2525
CONFIG_MBEDTLS_ENTROPY_C=y
2626
CONFIG_MBEDTLS_CTR_DRBG_C=y
2727

28+
# The collector's captive portal serves HTTPS from a PEM certificate chain
29+
# (fullchain.pem / key.pem via ssl.SSLContext.load_cert_chain); mbedTLS only
30+
# parses DER unless PEM decoding is compiled in.
31+
CONFIG_MBEDTLS_PEM_PARSE_C=y
32+
33+
# TLS 1.2 ECDHE. Zephyr's mbedTLS 4 default serves secp256r1 through the p256-m
34+
# PSA driver and leaves the builtin ECP module out. mbedTLS then defines a dummy
35+
# MBEDTLS_ECP_MAX_BITS of 1, and ssl.h sizes the TLS 1.2 premaster buffer
36+
# (union mbedtls_ssl_premaster_secret._pms_ecdh[MBEDTLS_ECP_MAX_BYTES]) from
37+
# it, so every ECDHE key agreement fails with PSA_ERROR_BUFFER_TOO_SMALL -- a
38+
# 1-byte buffer for a 32-byte shared secret -- and surfaces as OSError 138 on
39+
# the first read of any TLS connection, client or server. Keep the builtin
40+
# ECP module (p256-m off) until the header sizes that buffer from PSA.
41+
CONFIG_MBEDTLS_PSA_P256M_DRIVER_ENABLED=n
42+
2843
# File descriptors. Zephyr sizes the fd table from the subsystems' declared
2944
# needs (ZVFS_OPEN_ADD_SIZE_*), which came to 4 here; the DHCPv4 server takes
3045
# one socket plus the socket-service eventfd, leaving a program two, and

0 commit comments

Comments
 (0)