ossh: check the key-type parse before the ID lookup - #1193
Open
yosuke-wolfssl wants to merge 1 commit into
Open
Conversation
- GetOpenSshPublicKey() calls NameToId() and enters the key-type switch only when GetStringRef() returns WS_SUCCESS, and returns that result otherwise. - publicKeyType starts NULL and keyId starts ID_UNKNOWN. - tests/api.c adds test_GetOpenSshPublicKey_type(), covering a truncated type string, a truncated length prefix, an empty type, an unsupported type and a well-formed ssh-rsa blob. Issue: F-11650
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes TPM-only OpenSSH public-key parsing by preserving malformed key-type errors and adding regression coverage.
Changes:
- Gates key lookup on successful parsing.
- Initializes parser state safely.
- Adds malformed and valid key tests.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
tests/api.c |
Adds TPM-gated regression tests. |
src/ossh.c |
Fixes key-type parsing and error handling. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1193
Scan targets checked: wolfssh-bugs, wolfssh-src
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
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.
Problem
GetOpenSshPublicKey()overwrote the result ofGetStringRef()before checking it:GetStringRef()sets*strSzinsideGetUint32()before its bounds check, so atruncated key-type string returns
WS_BUFFER_Ewith*strnever assigned. Thecaller's
publicKeyTypeis an uninitialized local, soNameToId()compared throughan indeterminate pointer using a length taken from the wire. The unchecked
retwasthen overwritten by the switch, so the parse failure was reported as
WS_UNIMPLEMENTED_Einstead ofWS_BUFFER_E.Compiled only under
WOLFSSH_TPM. The single call site isPrepareUserAuthRequestRsa(), on the branch where the private key lives in the TPMand only a public key blob is available — the input is the local user's public key
material, not a remote peer's. Closes f-11650.
Fix (
src/ossh.c)NameToId()and the key-type switch run only whenGetStringRef()returnsWS_SUCCESS; that result is returned otherwise.publicKeyTypestartsNULLandkeyIdstartsID_UNKNOWN.The switch body is unchanged apart from indentation. Every other
GetStringRef()/GetMpint()call in the file already gated onret == WS_SUCCESS; this was the onlyone that did not.
Tests (
tests/api.c)test_GetOpenSshPublicKey_type(), gated onWOLFSSH_TPM+WOLFSSH_TEST_INTERNAL:"ssh"under a length of 7WS_BUFFER_EWS_BUFFER_EWS_UNIMPLEMENTED_Essh-dss(well-formed, unsupported)WS_UNIMPLEMENTED_Essh-rsa+ mpinte+ mpintnWS_SUCCESS,idxfully consumedRuns upstream in the
tpm-ssh.ymlecc/ibmswtpm2/raw cell, which builds thecheck_PROGRAMs with-DWOLFSSH_TPMand runsmake check TESTS=tests/api.test.Verification
--enable-tpm --enable-certs: build clean,tests/api.testpasses.src/ossh.chunk reverted, the truncated-type casefails —
-1017 != -1004.-O2 -Werrorsweep: clean across 6 configs (enable-all, zephyr-defines,sftp-only, scp-only, default, smallstack).