Repository navigation
Keep the pairing builders, notes and PSK minting off the aborting heap - #239
Merged
Merged
Conversation
- The pairing builders encode each base64 field through write_b64url(), a stack buffer the document copies from and that is wiped afterwards, in place of heap std::string temporaries. - PairingNote::text is an IdText; note_display_pairing_code() takes a string_view like its siblings, and the main-loop drain builds the listener's std::string. - resolve_pairing_outcome() mints the PSK into the self-wiping outcome and derives its psk_id with the fallible psk_id_for() overload; a pairing that cannot hash its PSK fails with pair/abort instead of aborting the process. - internals.md "Memory" names the remaining aborting paths.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The base64 comment still references the removed pairing-PSK encoding path and needs to state the general requirement to wipe returned strings when encoding secrets.
1 open issue
What changed in this PR
Reduces abort-prone heap use in Sendspin’s protocol-task pairing paths, particularly on ESPHome, while preserving existing listener interfaces.
Changes:
- Encode pairing fields through wiped stack buffers and hold queued note text inline.
- Make pairing outcomes fallible and abort pairing cleanly when PSK identifier hashing fails.
- Adapt tests and update documentation for the allocation behavior.
| File | Description |
|---|---|
tests/test_record_store.cpp |
Adapt successful pairing tests to optional outcomes. |
tests/test_pairing_state_machine.cpp |
Verify pairing failures identify the attempt’s server. |
src/record_store.h |
Declare optional pairing outcomes and document failure. |
src/record_store.cpp |
Mint secrets into self-wiping storage and handle hash failure. |
src/protocol.cpp |
Replace base64 string temporaries with wiped stack buffers. |
src/crypto/keys.h |
Document hash failure in fallible PSK identifier derivation. |
src/connection_manager_pairing.cpp |
Handle minting failure in both pairing flows. |
src/client.cpp |
Store note text inline and build listener strings during draining. |
include/sendspin/client.h |
Change the private code-note parameter to std::string_view. |
docs/internals.md |
Update pairing allocations and remaining abort behavior. |
Review effort: Max
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.

Summary
Group C of the allocation follow-ups (Sendspin/backlog#92): the pairing paths still built heap temporaries for every base64 field and every pairing note, and minting a new long-term PSK aborted the process if noise-c could not allocate the hash state. On ESPHome
operator newis internal-RAM-only and aborts, so these run on the protocol task during every pairing exchange.Change
write_b64url()inprotocol.cppencodes each base64 field into a stack buffer (at most 89 bytes), assigns it to the document, which copies it, and wipes the buffer. All eight pairing fields use it, replacingb64url_encode()temporaries and their hand-written wipes.PairingNote::textis anIdText(astatic_assertchecks every emitted code fits);note_display_pairing_code()takes astd::string_viewlike its siblings; the main-loop drain builds the listener'sstd::string, per theconventions.mdrule.RecordStore::resolve_pairing_outcome()returnsstd::optional. It mints the PSK straight into the self-wipingPairingOutcomeand derives itspsk_idwith the falliblepsk_id_for(ptr, len); both pairing flows answer a failure withpair/abort(METHOD_NOT_SUPPORTED, like the other internal failures). The abortingstd::arrayoverload now runs only whilestart()loads the record store.internals.md"Memory" updates the exception sentence and the pairing row.platform_random_bytes()still aborts when noise-c cannot allocate its random state; that is left for a separate change.Tests
AbortAfterConfirmDoesNotReclearAlreadyWithdrawnCodenow asserts the failure names the attempt's server.