Skip to content

Commit d8af8d6

Browse files
Cargo.toml: Temporary patch rcgen crate for RSA-PSS CSR support
RSA-PSS CSR creation functionality has been recently added. For creating the CSRs, we are currently using rcgen. For RSA-PSS, rcgen defined the PKCS_RSA_PSS_SHA256 type, which should be used instead of the currently used one (PKCS_RSA_SHA256). Unfortunately, rcgen does not expose this type as there have been some issues validating the CSR creation of this type. This has been tested using real RSA PSS keys and the functionality works as expected. * Patch rcgen to expose the PKCS_RSA_PSS_SHA256 type. The patch applies until these changes get fixed/merged upstream in rcgen. * Use this type in parsec-tool CSR creation for RSA-PSS. Signed-off-by: Tomás González <tomasagustin.gonzalezorlando@arm.com>
1 parent 6387589 commit d8af8d6

File tree

6 files changed

+76
-9
lines changed

6 files changed

+76
-9
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
/target
2-
*patch
32
.devcontainer

Cargo.lock

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

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ sha2 = "0.9.9"
2929
log = "0.4.14"
3030
rcgen = { version = "0.9.2", features = ["pem"] }
3131

32+
[package.metadata.patch]
33+
crates=["rcgen"]
34+
35+
[patch.crates-io]
36+
rcgen = { path = './target/patch/rcgen-0.9.3' }
37+
3238
[lib]
3339
name = "parsec_tool"
3440
path = "src/lib.rs"

patches/rcgen+0.9.3.patch

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
diff --git a/src/lib.rs b/src/lib.rs
2+
index 565b3d6..23998c3 100644
3+
--- a/src/lib.rs
4+
+++ b/src/lib.rs
5+
@@ -1500,6 +1500,9 @@ impl KeyPair {
6+
} else if alg == &PKCS_RSA_PSS_SHA256 {
7+
let rsakp = RsaKeyPair::from_pkcs8(pkcs8)?;
8+
KeyPairKind::Rsa(rsakp, &signature::RSA_PSS_SHA256)
9+
+ } else if alg == &PKCS_RSA_PSS_SHA384 {
10+
+ let rsakp = RsaKeyPair::from_pkcs8(pkcs8)?;
11+
+ KeyPairKind::Rsa(rsakp, &signature::RSA_PSS_SHA384)
12+
} else {
13+
panic!("Unknown SignatureAlgorithm specified!");
14+
};
15+
@@ -1886,6 +1889,7 @@ impl SignatureAlgorithm {
16+
&PKCS_RSA_SHA384,
17+
&PKCS_RSA_SHA512,
18+
//&PKCS_RSA_PSS_SHA256,
19+
+ //&PKCS_RSA_PSS_SHA384,
20+
&PKCS_ECDSA_P256_SHA256,
21+
&PKCS_ECDSA_P384_SHA384,
22+
&PKCS_ED25519
23+
@@ -1938,17 +1942,32 @@ pub static PKCS_RSA_SHA512 :SignatureAlgorithm = SignatureAlgorithm {
24+
// support those: https://github.com/briansmith/ring/issues/1353
25+
//
26+
/// RSA signing with PKCS#1 2.1 RSASSA-PSS padding and SHA-256 hashing as per [RFC 4055](https://tools.ietf.org/html/rfc4055)
27+
-static PKCS_RSA_PSS_SHA256 :SignatureAlgorithm = SignatureAlgorithm {
28+
+pub static PKCS_RSA_PSS_SHA256 :SignatureAlgorithm = SignatureAlgorithm {
29+
// We could also use OID_RSA_ENCRYPTION here, but it's recommended
30+
// to use ID-RSASSA-PSS if possible.
31+
oids_sign_alg :&[&OID_RSASSA_PSS],
32+
sign_alg :SignAlgo::Rsa(),
33+
- oid_components : &OID_RSASSA_PSS,//&[1, 2, 840, 113549, 1, 1, 13],
34+
+ oid_components : &OID_RSASSA_PSS,//&[1, 2, 840, 113549, 1, 1, 11],
35+
// rSASSA-PSS-SHA256-Params in RFC 4055
36+
params : SignatureAlgorithmParams::RsaPss {
37+
// id-sha256 in https://datatracker.ietf.org/doc/html/rfc4055#section-2.1
38+
hash_algorithm : &[2, 16, 840, 1, 101, 3, 4, 2, 1],
39+
- salt_length : 20,
40+
+ salt_length : 32,
41+
+ },
42+
+};
43+
+
44+
+/// RSA signing with PKCS#1 2.1 RSASSA-PSS padding and SHA-384 hashing as per [RFC 4055](https://tools.ietf.org/html/rfc4055)
45+
+pub static PKCS_RSA_PSS_SHA384 :SignatureAlgorithm = SignatureAlgorithm {
46+
+ // We could also use OID_RSA_ENCRYPTION here, but it's recommended
47+
+ // to use ID-RSASSA-PSS if possible.
48+
+ oids_sign_alg :&[&OID_RSASSA_PSS],
49+
+ sign_alg :SignAlgo::Rsa(),
50+
+ oid_components : &OID_RSASSA_PSS,//&[1, 2, 840, 113549, 1, 1, 12],
51+
+ // rSASSA-PSS-SHA384-Params in RFC 4055
52+
+ params : SignatureAlgorithmParams::RsaPss {
53+
+ // id-sha384 in https://datatracker.ietf.org/doc/html/rfc4055#section-2.1
54+
+ hash_algorithm : &[2, 16, 840, 1, 101, 3, 4, 2, 2],
55+
+ salt_length : 48,
56+
},
57+
};
58+

src/subcommands/create_csr.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use parsec_client::core::interface::operations::psa_key_attributes::{EccFamily,
1414
use parsec_client::BasicClient;
1515
use rcgen::{
1616
Certificate, CertificateParams, DistinguishedName, DnType, KeyPair, RcgenError, RemoteKeyPair,
17-
SignatureAlgorithm, PKCS_ECDSA_P256_SHA256, PKCS_ECDSA_P384_SHA384, PKCS_RSA_SHA256,
18-
PKCS_RSA_SHA384, PKCS_RSA_SHA512,
17+
SignatureAlgorithm, PKCS_ECDSA_P256_SHA256, PKCS_ECDSA_P384_SHA384, PKCS_RSA_PSS_SHA256,
18+
PKCS_RSA_PSS_SHA384, PKCS_RSA_SHA256, PKCS_RSA_SHA384, PKCS_RSA_SHA512,
1919
};
2020

2121
/// Creates an X509 Certificate Signing Request (CSR) from a keypair, using the signing algorithm
@@ -183,10 +183,9 @@ impl CreateCsr {
183183
Err(ToolErrorKind::NotSupported.into())
184184
}
185185
AsymmetricSignature::RsaPss { hash_alg } => match hash_alg {
186-
SignHash::Specific(Hash::Sha256) => Ok(&PKCS_RSA_SHA256),
187-
SignHash::Specific(Hash::Sha384) => Ok(&PKCS_RSA_SHA384),
188-
SignHash::Specific(Hash::Sha512) => Ok(&PKCS_RSA_SHA512),
189-
SignHash::Any => Ok(&PKCS_RSA_SHA256), // Default hash algorithm for the tool.
186+
SignHash::Specific(Hash::Sha256) => Ok(&PKCS_RSA_PSS_SHA256),
187+
SignHash::Specific(Hash::Sha384) => Ok(&PKCS_RSA_PSS_SHA384),
188+
SignHash::Any => Ok(&PKCS_RSA_PSS_SHA256), // Default hash algorithm for the tool.
190189
_ => {
191190
// The algorithm is specific, but not one that RCGEN can use, so fail the operation.
192191
error!("Signing key requires use of hashing algorithm ({:?}), which is not supported for certificate requests.", alg);

tests/ci.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ error_msg () {
1414
export PARSEC_SERVICE_ENDPOINT="unix:/tmp/parsec.sock"
1515
export RUST_LOG=error
1616

17+
#TODO: This applies the rcgen patch that exposes the PKCS_RSA_PSS_SHA256 and PKCS_RSA_PSS_SHA384 types. Remove this
18+
# when the corresponding patch gets merged. Also remove rcgen+0.9.3.patch.
19+
rustup install 1.77.1 # We know that this version works for patch-crate
20+
cargo +1.77.1 install patch-crate --version 0.1.9
21+
cargo patch-crate
22+
1723
##################
1824
# Get Parameters #
1925
##################
@@ -56,6 +62,7 @@ fi
5662
#########
5763
# Build #
5864
#########
65+
rustup --version
5966
RUST_BACKTRACE=1 cargo build
6067
RUST_BACKTRACE=1 cargo build --features spiffe-auth
6168

0 commit comments

Comments
 (0)