ossh: check the key-type parse before the ID lookup - #1193
Merged
Conversation
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.
- 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(), gated on WOLFSSH_TPM and WOLFSSH_TEST_INTERNAL, covering a truncated type string, a truncated length prefix, an empty type, an unsupported type and a well-formed ssh-rsa blob. - Each case asserts idx alongside the return code: UINT32_SZ for a truncated type string, 0 for a truncated length prefix, and the full blob size for the empty type, the unsupported type and the ssh-rsa key. Issue: F-11650
yosuke-wolfssl
force-pushed
the
fix/f_11650
branch
from
August 26, 2026 01:49
fc2dd75 to
517f6eb
Compare
ejohnstown
approved these changes
Aug 26, 2026
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()callsGetUint32(), which stores the wire length in*strSzonsuccess;
GetStringRef()'s own bounds check (src/internal.c:4569) then fails for atruncated key-type string and returns
WS_BUFFER_Eat line 4578 without everassigning
*str. The caller'spublicKeyTypeis an uninitialized local, soNameToId()compared through an indeterminate pointer using a length taken from thewire. The unchecked
retwas then overwritten by the switch, so the parse failure wasreported 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:idxout"ssh"under a length of 7WS_BUFFER_EWS_BUFFER_EWS_UNIMPLEMENTED_Essh-dsstype name, unsupportedWS_UNIMPLEMENTED_Essh-rsa+ mpinte+ mpintnWS_SUCCESSidxis asserted on the failure cases too: it keeps whatever was successfullyconsumed and is not rolled back, matching every other
Get*in the tree.Runs upstream in the
tpm-ssh.ymlecc/ibmswtpm2/raw cell, which builds thecheck_PROGRAMs with-DWOLFSSH_TPMand runsmake check TESTS=tests/api.test.Not in this PR
GetOpenSshPublicKey()accepts trailing bytes after a well-formed blob;OsshCertParse()rejects them. Pre-existing, separate hardening.--enable-tpmfailstestsuite.test,kex.testandauth.teston master; CI runsonly
tests/api.testfor that config, so it has never seen those. Pre-existing.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).