Skip to content

internal: allow PEM private-key decode without WOLFSSH_CERTS#1119

Open
shaunchokshi wants to merge 1 commit into
wolfSSL:masterfrom
CK-Consulting:fix/pem-privkey-without-certs
Open

internal: allow PEM private-key decode without WOLFSSH_CERTS#1119
shaunchokshi wants to merge 1 commit into
wolfSSL:masterfrom
CK-Consulting:fix/pem-privkey-without-certs

Conversation

@shaunchokshi

Copy link
Copy Markdown

In wolfSSH_ProcessBuffer() (src/internal.c) the entire WOLFSSH_FORMAT_PEM branch — including the private-key path — sits inside #ifdef WOLFSSH_CERTS. A caller doing wolfSSH_CTX_UsePrivateKey_buffer(..., WOLFSSH_FORMAT_PEM) on a build without certificate support therefore gets WS_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 without WOLFSSH_CERTS still returns WS_UNIMPLEMENTED_E as 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:

Build Before After
default (no --enable-certs) -1017 (WS_UNIMPLEMENTED_E) 0
--enable-certs 0 0 (no regression)

Both configurations build warning-free.

Independent of #1118 — that one fixes wolfsshd by 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 requiring WOLFSSH_CERTS."

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.
@wolfSSL-Bot

Copy link
Copy Markdown

Can one of the admins verify this patch?

@dgarske

dgarske commented Jul 22, 2026

Copy link
Copy Markdown
Member

See ZD 22185

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_CERTS guard.
  • Keeps certificate/CA PEM decode (wc_CertPemToDer) gated behind WOLFSSH_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.

Comment thread src/internal.c
Comment thread src/internal.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants