internal: allow PEM private-key decode without WOLFSSH_CERTS#1119
Open
shaunchokshi wants to merge 1 commit into
Open
internal: allow PEM private-key decode without WOLFSSH_CERTS#1119shaunchokshi wants to merge 1 commit into
shaunchokshi wants to merge 1 commit into
Conversation
In wolfSSH_ProcessBuffer() the entire WOLFSSH_FORMAT_PEM branch, including the private-key path, was inside #ifdef WOLFSSH_CERTS. A caller doing wolfSSH_CTX_UsePrivateKey_buffer(..., WOLFSSH_FORMAT_PEM) on a build without certificate support therefore got WS_UNIMPLEMENTED_E, even though decoding a PEM private key has nothing to do with certificates. Move the private-key PEM path (wc_KeyPemToDer) out of the guard. The certificate PEM path (wc_CertPemToDer) stays guarded, and a certificate/CA PEM buffer on a build without WOLFSSH_CERTS still returns WS_UNIMPLEMENTED_E. Tested with an ML-DSA-65 PKCS#8 PEM key via UsePrivateKey_buffer(FORMAT_PEM): without certs, -1017 (WS_UNIMPLEMENTED_E) before, 0 after; with --enable-certs, 0 before and after. Both configurations build warning-free.
|
Can one of the admins verify this patch? |
Member
|
See ZD 22185 |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates wolfSSH_ProcessBuffer() to allow PEM private key buffers (WOLFSSH_FORMAT_PEM + BUFTYPE_PRIVKEY) to be decoded even when wolfSSH is built without WOLFSSH_CERTS, avoiding WS_UNIMPLEMENTED_E for a capability that is independent of certificate support.
Changes:
- Moves the PEM private-key decode path (
wc_KeyPemToDer) outside the#ifdef WOLFSSH_CERTSguard. - Keeps certificate/CA PEM decode (
wc_CertPemToDer) gated behindWOLFSSH_CERTS. - Preserves zeroization of partially-decoded private-key material on PEM decode failure.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ejohnstown
approved these changes
Jul 23, 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.
In
wolfSSH_ProcessBuffer()(src/internal.c) the entireWOLFSSH_FORMAT_PEMbranch — including the private-key path — sits inside#ifdef WOLFSSH_CERTS. A caller doingwolfSSH_CTX_UsePrivateKey_buffer(..., WOLFSSH_FORMAT_PEM)on a build without certificate support therefore getsWS_UNIMPLEMENTED_E, even though decoding a PEM private key has nothing to do with certificates.This moves the private-key PEM path (
wc_KeyPemToDer) out of the guard. The certificate PEM path (wc_CertPemToDer) stays guarded, and a certificate/CA PEM buffer on a build withoutWOLFSSH_CERTSstill returnsWS_UNIMPLEMENTED_Eas before.Testing
wolfSSH_CTX_UsePrivateKey_buffer(ctx, pem, sz, WOLFSSH_FORMAT_PEM)on an ML-DSA-65 PKCS#8 PEM key, patch toggled in each configuration:--enable-certs)-1017(WS_UNIMPLEMENTED_E)0--enable-certs00(no regression)Both configurations build warning-free.
Independent of #1118 — that one fixes
wolfsshdby feeding the library the format it accepts; this makes the library API consistent for any caller. No ordering dependency between them.Suggested ChangeLog entry: "
wolfSSH_ProcessBuffer()now decodes PEM private keys without requiringWOLFSSH_CERTS."