Uh oh!
There was an error while loading. Please reload this page.
Load every PEM block when adding root CAs, not just the first - #1149
Load every PEM block when adding root CAs, not just the first#1149yosuke-wolfssl wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
This PR fixes CA bundle loading so wolfSSH_CTX_AddRootCert_*() processes all PEM certificate blocks in a buffer/file instead of only the first, and adds tests covering multi-block and malformed-bundle behavior.
Changes:
- Add
LoadRootCaPemBuffer()to iterate through PEM blocks and load each CA into the cert manager. - Update
wolfSSH_ProcessBuffer()to use the bundle-walking loader for PEM CA buffers. - Add an API test to validate multi-CA bundles, malformed blocks, and interstitial text behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
wolfssh/ssh.h | Clarifies API behavior for multi-PEM inputs (leaf-only vs CA bundle loading). |
tests/api.c | Adds bundle-focused tests and a helper to build multi-block PEM buffers in memory. |
src/internal.c | Implements PEM bundle walking for CA loading and wires it into PEM CA processing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
48d0971 to
b114e26Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1149
Scan targets checked:wolfssh-bugs, wolfssh-src
Findings: 5
5 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Findings are non-blocking.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
b114e26 to
60b08baCompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1149
Scan targets checked:wolfssh-bugs, wolfssh-src
Findings: 4
4 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Findings are non-blocking.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
60b08ba to
91eb466CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1149
Scan targets checked:wolfssh-bugs, wolfssh-src
Findings: 9
9 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Findings are non-blocking.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
91eb466 to
03c09ffCompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1149
Scan targets checked:wolfssh-bugs, wolfssh-src
Findings: 2
2 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Findings are non-blocking.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
03c09ff to
2f905c6Compare2f905c6 to
5c11e36Compareyosuke-wolfssl
commented
Aug 7, 2026
Hi @ejohnstown , |
Problem
The certificate readers added in PR #1140 call
wc_CertPemToDer()once, whichdecodes the first PEM block and stops. For a host certificate that is correct.
For
wolfSSH_CTX_AddRootCert_file()/_buffer()it is a trap: a CA bundleloads exactly one CA and returns
WS_SUCCESS, so trust the caller believes isinstalled is not. The outcome also depends on block order —
[ca, malformed]returned
WS_SUCCESS,[malformed, ca]returnedWS_PARSE_E.Reachable today:
examples/echoserverpasses a whole-a caCertfile to thebuffer form, as does
wolfsshd'sUserCAKeysFile.Fix (
src/internal.c)LoadRootCaPemBuffer()walks every block in a PEM CA buffer:wc_PemGetHeaderFooter()supplies theCERTIFICATEheader, so textbetween or before blocks is stepped over rather than treated as malformed.
wc_PemToDer()decodes each block;info.consumedgives the exact blocklength, the same mechanism wolfSSL's own chain loader uses.
wolfSSH_CERTMAN_LoadRootCA_buffer().The walk stops at the first block that will not decode or that the cert
manager refuses, and returns that error. Per-block return codes are unchanged.
No signatures change;
UseCert_*,ReadCert_*and the DER paths are untouched.Behavior change
[ca, ca]WS_SUCCESSWS_SUCCESS[ca, malformed]WS_SUCCESSWS_BAD_FILE_E[malformed, ca]A trailing malformed block used to be invisible; it now fails the call. On
failure, what the blocks ahead of it left installed is unspecified — wolfSSL
exposes no per-CA unload, so the API cannot promise an empty store. Treat a
failure as a failed load.
Tests
test_wolfSSH_CTX_AddRootCert_bundle()intests/api.cbuilds bundles inmemory from the existing keys, covering multi-CA, leading and trailing bad
blocks, interstitial text, and a buffer with no certificate. Guarded on
WOLFSSH_NO_ECDSAlike the sibling cert tests.Verification
make check: 11 passed, 0 failed, 1 skipped (external).-Werroracross 6 GCC configurations.against 5000 in a negative control with the DER free removed.
fails, and in a
WOLFSSH_NO_FPKIbuild a CA in the second block is neverinstalled so its leaf fails to verify.