Skip to content

Conversation

@phlip9
Copy link
Contributor

@phlip9 phlip9 commented Sep 22, 2025

By delegating to the existing certcrypto.ParsePEMPrivateKey impl, we can additionally support user-generated keypairs that are PKCS#8 encoded (vs today only SEC1 for ECDSA or PKCS#1 for RSA). For example, openssl genpkey will use this format. PKCS#8 PEM blocks use -----BEGIN PRIVATE KEY----- instead of -----BEGIN EC PRIVATE KEY----- or -----BEGIN RSA PRIVATE KEY-----.

I tested this out manually, renewing an existing cert with a SEC1 keypair and generating a new one with an openssl-generate PKCS#8 keypair:

$ openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -out test.key.pem
$ lego -d 'example.com' run --private-key 'test.key.pem`

Another location (generating a .pfx file) also tried to manually parse PEM private keys, so I took the liberty of switching that over to certcrypto.ParsePEMPrivateKey as well.

By delegating to the existing `certcrypto.ParsePEMPrivateKey` impl,
we can additionally support user-generated keypairs that are PKCS#8
encoded (vs just SEC1 for ECDSA or PKCS#1 for RSA). For example,
`openssl genpkey` will use this format.
@phlip9 phlip9 changed the title Cli pkcs8 private key cmd: support --private-key with a PKCS#8 keypair Sep 22, 2025
@ldez ldez changed the title cmd: support --private-key with a PKCS#8 keypair feat: support --private-key with a PKCS#8 keypair Sep 22, 2025
@ldez ldez self-requested a review September 22, 2025 19:40
@ldez ldez added this to the unreleased milestone Sep 22, 2025
Copy link
Member

@ldez ldez left a comment

Choose a reason for hiding this comment

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

LGTM

@ldez ldez merged commit ba156d5 into go-acme:master Sep 22, 2025
7 checks passed
@phlip9 phlip9 deleted the cli-pkcs8-private-key branch September 23, 2025 18:30
@ldez ldez modified the milestones: unreleased, v4.27 Oct 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants