Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rsa keypair generation using the rsa crate. #247

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion rcgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ aws-lc-rs = { version = "1.0.0", optional = true }
yasna = { version = "0.5.2", features = ["time", "std"] }
ring = { version = "0.17", optional = true }
pem = { workspace = true, optional = true }
rand = { version = "0.8.5", optional = true }
rsa = { version = "0.9.6", optional = true }
time = { version = "0.3.6", default-features = false }
x509-parser = { version = "0.15", features = ["verify"], optional = true }
zeroize = { version = "1.2", optional = true }

[features]
default = ["pem", "ring"]
default = ["pem", "ring", "rsa"]
aws_lc_rs = ["dep:aws-lc-rs"]
ring = ["dep:ring"]
rsa = ["dep:rsa", "dep:rand"]

[package.metadata.docs.rs]
features = ["x509-parser"]
Expand Down
12 changes: 12 additions & 0 deletions rcgen/src/key_pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,21 @@
serialized_der: key_pair_serialized,
})
},
#[cfg(feature = "rsa")]
SignAlgo::Rsa() => {
use rsa::pkcs8::EncodePrivateKey;
let bits = 4096;
let mut rng = rand::thread_rng();
let priv_key = rsa::RsaPrivateKey::new(&mut rng, bits).map_err(|_| Error::CouldNotParseKeyPair)?;
let pkcs8 = priv_key.to_pkcs8_der().map_err(|_| Error::CouldNotParseKeyPair)?.to_bytes();
Ok(
KeyPair::from_der(&pkcs8)?

Check warning on line 215 in rcgen/src/key_pair.rs

View check run for this annotation

Codecov / codecov/patch

rcgen/src/key_pair.rs#L210-L215

Added lines #L210 - L215 were not covered by tests
)
}
// Ring doesn't have RSA key generation yet:
// https://github.com/briansmith/ring/issues/219
// https://github.com/briansmith/ring/pull/733
#[cfg(not(feature = "rsa"))]
SignAlgo::Rsa() => Err(Error::KeyGenerationUnavailable),
}
}
Expand Down
Loading