fix: support SEC1 EC keys with full domain parameters - #719
Merged
Conversation
The sec1 crate cannot parse EC private keys that use full domain parameters instead of a named curve OID in the [0] parameters field. This affects keys generated with 'openssl ecparam -param_enc explicit' and similar tools. Add a manual DER parser as a fallback in decode_pkcs8 that: 1. Detects SEC1 keys with full domain parameters 2. Extracts the curve OID from the prime field length 3. Constructs the EC keypair directly from the private key bytes Includes a test with a P-256 key using explicit domain parameters. Fixes #718
Owner
|
Thank you! I've updated the code to use the |
Owner
|
@all-contributors please add @SakuraPuare for code |
Contributor
|
I've put up a pull request to add @SakuraPuare! 🎉 |
Eugeny
pushed a commit
that referenced
this pull request
Jun 5, 2026
Adds @SakuraPuare as a contributor for code. This was requested by Eugeny [in this comment](#719 (comment)) [skip ci] --------- Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
This was referenced Jul 27, 2026
Merged
7 tasks
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.
Problem
SEC1 EC private keys that use full domain parameters (instead of a named curve OID) fail to parse with:
This affects keys generated with
openssl ecparam -param_enc explicitand similar tools that embed the full EC domain parameters in the[0]parameters field of the SEC1 structure.Fixes #718
Root Cause
The
sec1crate'sEcPrivateKeydecoder expects the[0]parameters field to contain either a named curve OID or nothing (optional field). But some key generators produce a full EC domain parameters SEQUENCE instead, which thesec1crate rejects with aTagUnexpectederror.Fix
Added a manual DER parser as a fallback in
decode_pkcs8that:sec1::EcPrivateKeydecode fails)p256/p384/p521cratesThe fallback only runs when the
sec1crate's strict parser fails, so there is no performance impact on normal keys.Changes
russh/src/keys/format/pkcs8.rs: Added fallback parser functions for SEC1 keys with full domain parametersrussh/src/keys/format/tests.rs: Added tests for P-256 and P-521 keys with explicit domain parameters, and negative tests for malformed DERTesting