Skip to content

Commit 2edea27

Browse files
AlvenixAbdullah Alyan
authored andcommitted
Support ECDSA_P521_SHA512 when using aes_lc_rs feature
1 parent b61393a commit 2edea27

File tree

12 files changed

+147
-20
lines changed

12 files changed

+147
-20
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ jobs:
3333
matrix:
3434
features:
3535
- --all-features
36-
- --no-default-features
36+
# rustls-cert-gen require either aws_lc_rs or ring feature
37+
- -p rcgen --no-default-features
3738
- --no-default-features --features ring
3839
- --no-default-features --features aws_lc_rs
3940
- --no-default-features --features aws_lc_rs,pem
@@ -138,10 +139,9 @@ jobs:
138139
run: cargo test --verbose --features x509-parser
139140
- name: Run the tests with aws_lc_rs backend enabled
140141
run: cargo test --verbose --no-default-features --features aws_lc_rs,pem
141-
- name: Run the tests with FIPS aws_lc_rs module
142-
run: cargo test --verbose --no-default-features --features fips,pem
142+
# rustls-cert-gen require either aws_lc_rs or ring feature
143143
- name: Run the tests with no features enabled
144-
run: cargo test --verbose --no-default-features
144+
run: cargo test -p rcgen --verbose --no-default-features
145145

146146
build:
147147
strategy:
@@ -181,8 +181,6 @@ jobs:
181181
run: cargo test --verbose --features x509-parser
182182
- name: Run the tests with aws_lc_rs backend enabled
183183
run: cargo test --verbose --no-default-features --features aws_lc_rs,pem
184-
- name: Run the tests with FIPS aws_lc_rs module
185-
run: cargo test --verbose --no-default-features --features fips,pem
186184

187185
# Build rustls-cert-gen as a standalone package, see this PR for why it's needed:
188186
# https://github.com/rustls/rcgen/pull/206#pullrequestreview-1816197358

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ members = ["rcgen", "rustls-cert-gen"]
33
resolver = "2"
44

55
[workspace.dependencies]
6+
aws-lc-rs = "1.6.0"
67
pem = "3.0.2"
78
pki-types = { package = "rustls-pki-types", version = "1.3.0" }
89
rand = "0.8"

rcgen/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ name = "simple"
2626
required-features = ["crypto"]
2727

2828
[dependencies]
29-
aws-lc-rs = { version = "1.6.0", optional = true }
29+
aws-lc-rs = { workspace = true, optional = true }
3030
yasna = { version = "0.5.2", features = ["time", "std"] }
3131
ring = { workspace = true, optional = true }
3232
pem = { workspace = true, optional = true }

rcgen/src/key_pair.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,18 @@ impl KeyPair {
249249
let rsakp = RsaKeyPair::from_pkcs8(&serialized_der)._err()?;
250250
KeyPairKind::Rsa(rsakp, &signature::RSA_PSS_SHA256)
251251
} else {
252+
#[cfg(all(feature = "aws_lc_rs", not(feature = "ring")))]
253+
if alg == &PKCS_ECDSA_P521_SHA512 {
254+
KeyPairKind::Ec(ecdsa_from_pkcs8(
255+
&signature::ECDSA_P521_SHA512_ASN1_SIGNING,
256+
&serialized_der,
257+
rng,
258+
)?)
259+
} else {
260+
panic!("Unknown SignatureAlgorithm specified!");
261+
}
262+
263+
#[cfg(feature = "ring")]
252264
panic!("Unknown SignatureAlgorithm specified!");
253265
};
254266

@@ -290,7 +302,19 @@ impl KeyPair {
290302
&PKCS_RSA_SHA256,
291303
)
292304
} else {
293-
return Err(Error::CouldNotParseKeyPair);
305+
#[cfg(all(feature = "aws_lc_rs", not(feature = "ring")))]
306+
if let Ok(eckp) =
307+
ecdsa_from_pkcs8(&signature::ECDSA_P521_SHA512_ASN1_SIGNING, pkcs8, &rng)
308+
{
309+
(KeyPairKind::Ec(eckp), &PKCS_ECDSA_P521_SHA512)
310+
} else {
311+
return Err(Error::CouldNotParseKeyPair);
312+
}
313+
314+
#[cfg(feature = "ring")]
315+
{
316+
return Err(Error::CouldNotParseKeyPair);
317+
}
294318
};
295319
Ok((kind, alg))
296320
}

rcgen/src/oid.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ pub(crate) const EC_PUBLIC_KEY: &[u64] = &[1, 2, 840, 10045, 2, 1];
2020
pub(crate) const EC_SECP_256_R1: &[u64] = &[1, 2, 840, 10045, 3, 1, 7];
2121
/// secp384r1 in [RFC 5480](https://datatracker.ietf.org/doc/html/rfc5480#appendix-A)
2222
pub(crate) const EC_SECP_384_R1: &[u64] = &[1, 3, 132, 0, 34];
23+
/// secp521r1 in [RFC 5480](https://datatracker.ietf.org/doc/html/rfc5480#appendix-A)
24+
/// Currently this is only supported with the `aws_lc_rs` feature
25+
#[cfg(all(feature = "aws_lc_rs", not(feature = "ring")))]
26+
pub(crate) const EC_SECP_521_R1: &[u64] = &[1, 3, 132, 0, 35];
2327

2428
/// rsaEncryption in [RFC 4055](https://www.rfc-editor.org/rfc/rfc4055#section-6)
2529
pub(crate) const RSA_ENCRYPTION: &[u64] = &[1, 2, 840, 113549, 1, 1, 1];

rcgen/src/sign_algo.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ impl fmt::Debug for SignatureAlgorithm {
5656
} else if self == &PKCS_ED25519 {
5757
write!(f, "PKCS_ED25519")
5858
} else {
59+
#[cfg(all(feature = "aws_lc_rs", not(feature = "ring")))]
60+
if self == &PKCS_ECDSA_P521_SHA512 {
61+
return write!(f, "PKCS_ECDSA_P521_SHA512");
62+
}
63+
5964
write!(f, "Unknown")
6065
}
6166
}
@@ -86,6 +91,8 @@ impl SignatureAlgorithm {
8691
//&PKCS_RSA_PSS_SHA256,
8792
&PKCS_ECDSA_P256_SHA256,
8893
&PKCS_ECDSA_P384_SHA384,
94+
#[cfg(all(feature = "aws_lc_rs", not(feature = "ring")))]
95+
&PKCS_ECDSA_P521_SHA512,
8996
&PKCS_ED25519,
9097
];
9198
ALGORITHMS.iter()
@@ -178,8 +185,17 @@ pub(crate) mod algo {
178185
oid_components: &[1, 2, 840, 10045, 4, 3, 3],
179186
params: SignatureAlgorithmParams::None,
180187
};
181-
182-
// TODO PKCS_ECDSA_P521_SHA512 https://github.com/briansmith/ring/issues/824
188+
/// ECDSA signing using the P-521 curves and SHA-512 hashing as per [RFC 5758](https://tools.ietf.org/html/rfc5758#section-3.2)
189+
/// Currently this is only supported with the `aws_lc_rs` feature
190+
#[cfg(all(feature = "aws_lc_rs", not(feature = "ring")))]
191+
pub static PKCS_ECDSA_P521_SHA512: SignatureAlgorithm = SignatureAlgorithm {
192+
oids_sign_alg: &[&EC_PUBLIC_KEY, &EC_SECP_521_R1],
193+
#[cfg(feature = "crypto")]
194+
sign_alg: SignAlgo::EcDsa(&signature::ECDSA_P521_SHA512_ASN1_SIGNING),
195+
// ecdsa-with-SHA512 in RFC 5758
196+
oid_components: &[1, 2, 840, 10045, 4, 3, 4],
197+
params: SignatureAlgorithmParams::None,
198+
};
183199

184200
/// ED25519 curve signing as per [RFC 8410](https://tools.ietf.org/html/rfc8410)
185201
pub static PKCS_ED25519: SignatureAlgorithm = SignatureAlgorithm {

rcgen/tests/botan.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ fn test_botan_384() {
7575
check_cert(cert.der(), &cert);
7676
}
7777

78+
#[test]
79+
#[cfg(all(feature = "aws_lc_rs", not(feature = "ring")))]
80+
fn test_botan_521() {
81+
let (params, _) = default_params();
82+
let key_pair = KeyPair::generate_for(&rcgen::PKCS_ECDSA_P521_SHA512).unwrap();
83+
let cert = params.self_signed(&key_pair).unwrap();
84+
85+
// Now verify the certificate.
86+
check_cert(cert.der(), &cert);
87+
}
88+
7889
#[test]
7990
fn test_botan_25519() {
8091
let (params, _) = default_params();

rcgen/tests/generic.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ mod test_key_params_mismatch {
1919
&rcgen::PKCS_RSA_SHA256,
2020
&rcgen::PKCS_ECDSA_P256_SHA256,
2121
&rcgen::PKCS_ECDSA_P384_SHA384,
22+
#[cfg(all(feature = "aws_lc_rs", not(feature = "ring")))]
23+
&rcgen::PKCS_ECDSA_P521_SHA512,
2224
&rcgen::PKCS_ED25519,
2325
];
2426
for (i, kalg_1) in available_key_params.iter().enumerate() {

rcgen/tests/openssl.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,18 @@ fn test_openssl_384() {
213213
verify_csr(&cert, &key_pair);
214214
}
215215

216+
#[test]
217+
#[cfg(all(feature = "aws_lc_rs", not(feature = "ring")))]
218+
fn test_openssl_521() {
219+
let (params, _) = util::default_params();
220+
let key_pair = KeyPair::generate_for(&rcgen::PKCS_ECDSA_P521_SHA512).unwrap();
221+
let cert = params.self_signed(&key_pair).unwrap();
222+
223+
// Now verify the certificate.
224+
verify_cert(&cert, &key_pair);
225+
verify_csr(&cert, &key_pair);
226+
}
227+
216228
#[test]
217229
fn test_openssl_25519() {
218230
let (params, _) = util::default_params();

0 commit comments

Comments
 (0)