Skip to content

Croak when passphrase is passed with DER-encoded key#176

Closed
toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
toddr-bot:koan.toddr.bot/croak-passphrase-with-der
Closed

Croak when passphrase is passed with DER-encoded key#176
toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
toddr-bot:koan.toddr.bot/croak-passphrase-with-der

Conversation

@toddr-bot
Copy link
Copy Markdown
Contributor

@toddr-bot toddr-bot commented Apr 23, 2026

What

new_private_key() now croaks when a passphrase is provided for DER-encoded keys.

Why

_new_private_key_der() has no passphrase parameter, so @rest from the Perl wrapper was silently dropped. A user calling new_private_key($der_key, "secret") would get no indication that the passphrase was ignored — a silent failure that could lead to incorrect security assumptions.

How

Added a check for @rest in the DER branch of new_private_key(). If non-empty, croaks with "passphrase argument not supported for DER-encoded keys". This is consistent with how the module handles other invalid argument combinations.

Testing

  • Added test in t/der.t verifying the croak message
  • Full test suite passes (all existing tests unaffected)

🤖 Generated with Claude Code


Quality Report

Changes: 2 files changed, 8 insertions(+), 2 deletions(-)

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

new_private_key() accepts @rest (passphrase) but _new_private_key_der()
has no passphrase parameter, so the argument was silently dropped. Users
expecting passphrase-protected DER loading got no indication it was
ignored. Now croaks with a clear message instead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@timlegge
Copy link
Copy Markdown
Member

@toddr-bot would it not be better to add passphrase support to der-encoded keys

@toddr-bot
Copy link
Copy Markdown
Contributor Author

Good call @timlegge#180 implements passphrase support for encrypted PKCS#8 DER keys instead of rejecting them. Works on both pre-3.x (via d2i_PKCS8PrivateKey_bio) and 3.x (via OSSL_DECODER_CTX_set_passphrase). This PR can be closed in favor of that one.

@timlegge timlegge closed this Apr 23, 2026
toddr-bot added a commit to toddr-bot/Crypt-OpenSSL-RSA that referenced this pull request Apr 23, 2026
_new_private_key_der() now accepts an optional passphrase to decrypt
encrypted PKCS#8 DER (EncryptedPrivateKeyInfo) private keys. On
OpenSSL 3.x, sets OSSL_DECODER_CTX_set_passphrase() on the existing
decoder context. On pre-3.x, uses d2i_PKCS8PrivateKey_bio() via a
helper placed before the EVP_PKEY->RSA compatibility macros.

Addresses review feedback on PR cpan-authors#176 — rather than croaking when a
passphrase is provided for DER keys, we now support the use case.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

2 participants