Repository navigation
fix(mbedtls): preserve partial headers with dynamic RX buffers - #132
Merged
floitsch merged 2 commits intoSep 8, 2026
Merged
Conversation
This was referenced Sep 8, 2026
floitsch
added a commit
to toitlang/toit
that referenced
this pull request
Sep 9, 2026
Reduce TLS heap use on ESP32 by enabling dynamic mbedTLS buffers and disabling retention of the peer certificate after verification. Apply both settings to all six supported targets (ESP32, C3, C6, P4, S2, and S3); certificate verification remains enabled. The required partial-header fix for nonblocking dynamic TLS receives ([toitware/esp-idf#132](toitware/esp-idf#132)) is available on master through #3216. Generate `sdkconfig.defaults` with `idf.py save-defconfig`, then recreate `sdkconfig` from those defaults for each target. Keep the existing 7800/3700-byte record limits and leave dynamic freeing of configuration/CA data disabled. TLS 1.3 remains disabled; these settings would need revisiting when enabling it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Nonblocking receives can return
WANT_READafter only part of a TLS record header. The dynamic RX wrapper retains the received-byte count but stores the header bytes on the stack, so a later call can process a corrupted header and fail withMBEDTLS_ERR_SSL_INVALID_RECORD.Preserve partial headers in the connection's idle RX buffer, adding five bytes after the counter/IV cache. Allocate the full record buffer before releasing that cache so allocation failure also preserves the input and cryptographic state for a retry.
Add Unity regression tests and a dynamic-buffer CI configuration covering all header split positions, repeated
WANT_READ, interleaved connections, buffer reuse, counter/IV preservation, and close/reset buffer paths after partial reads, timeout, or EOF.Validation:
Based on the current
patch-head-5.4.2head. Its mbedTLS files match the version used for validation.