Skip to content

fix: validate private key before export in get_private_key_string()#143

Merged
atoomic merged 1 commit into
cpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-private-key-export-check
Apr 3, 2026
Merged

fix: validate private key before export in get_private_key_string()#143
atoomic merged 1 commit into
cpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-private-key-export-check

Conversation

@toddr-bot
Copy link
Copy Markdown
Contributor

What

Add _is_private() check to get_private_key_string() for consistent behavior across all OpenSSL versions.

Why

Every private-key operation (decrypt, sign, private_encrypt, check_key) validates the key is actually private before proceeding. get_private_key_string() was the only one missing this guard, causing version-dependent behavior when called on a public-only key:

  • Pre-3.x: silently produces a PEM with only public components (misleading)
  • 3.x: croaks with a cryptic OpenSSL error

How

Single _is_private() check added before the passphrase/cipher logic. Follows the exact same pattern used by decrypt(), sign(), etc. Test updated from pass() (always succeeds) to like() matching the new error message.

Testing

Full test suite: 507 tests pass on OpenSSL 3.5.1. The specific test (t/format.t) now verifies the croak message rather than just checking it doesn't crash.

🤖 Generated with Claude Code

Every other private-key operation (decrypt, sign, private_encrypt,
check_key) validates _is_private() first. get_private_key_string()
was the only one missing this check, leading to version-dependent
behavior: silent garbage PEM on pre-3.x, cryptic OpenSSL error on
3.x. Now croaks with a clear message on all versions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@timlegge timlegge marked this pull request as ready for review April 3, 2026 15:47
@timlegge
Copy link
Copy Markdown
Member

timlegge commented Apr 3, 2026

looks finr @atoomic or @toddr

@atoomic atoomic merged commit ee505b2 into cpan-authors:main Apr 3, 2026
28 checks passed
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.

3 participants