RustCrypto / RustCrypto/formats
Sec1 round-trip fails with AlgorithmParametersMissing
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 338
- Forks
- 188
- Avg merge
- 4d 6h
- Merged PRs (30d)
- 15
Description
While testing with rustls I noticed that sec1-der and pem exported ec private keys would fail to decode. The following is a minimal reproducer. I will say, this could be my fault for mishandling the API somehow, but after a lot of testing and verification I think there may be a fault in the way that sec1 is encoded.
Any advice would be welcome.
#[cfg(test)]
mod tests {
use p384::ecdsa::SigningKey;
use p384::pkcs8::DecodePrivateKey;
use p384::pkcs8::EncodePrivateKey;
use p384::SecretKey;
use sec1::DecodeEcPrivateKey;
#[test]
fn sec1_pem() {
let mut rng = rand::thread_rng();
let signing_key = SigningKey::random(&mut rng);
let server_private_key_pem = SecretKey::from(&signing_key)
.to_sec1_pem(Default::default())
.unwrap();
let _ = SigningKey::from_sec1_pem(server_private_key_pem.as_str()).unwrap();
}
#[test]
fn sec1_der() {
let mut rng = rand::thread_rng();
let signing_key = SigningKey::random(&mut rng);
let server_private_key_pem = SecretKey::from(&signing_key).to_sec1_der().unwrap();
let _ = SigningKey::from_sec1_der(server_private_key_pem.as_slice()).unwrap();
}
}
thread 'tests::sec1_pem' panicked at src/lib.rs:19:76:
called `Result::unwrap()` on an `Err` value: Pkcs8(PublicKey(AlgorithmParametersMissing))
thread 'tests::sec1_der' panicked at src/lib.rs:30:78:
called `Result::unwrap()` on an `Err` value: Pkcs8(PublicKey(AlgorithmParametersMissing))
[package]
name = "rustcrypto-sec1"
version = "0.1.0"
edition = "2021"
[dependencies]
p384 = "0.13"
sec1 = "0.7"
rand = "0.8"
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided sec1_pem and sec1_der tests in src/lib.rs and reproducing AlgorithmParametersMissing with the listed p384 and sec1 versions. Trace the failure through the SEC1 and PKCS#8 decoding paths. Done means the encoded private key round-trips successfully in both PEM and DER forms, with regression coverage for both cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cryptography
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100