feat: v0.2.0-rc, add generate_self_signed_ca.rs
This commit is contained in:
12
README.md
12
README.md
@@ -23,8 +23,16 @@
|
||||
}
|
||||
```
|
||||
|
||||
Generate self signed certificate:
|
||||
|
||||
```shell
|
||||
$ cargo r --example generate_self_signed_ca
|
||||
```
|
||||
|
||||
Important
|
||||
|
||||
* intermediate certificate only tested ECDSA(P384) with SHA384
|
||||
* Intermediate certificate tested:
|
||||
* ECDSA(P384) with SHA384
|
||||
* P256 with SHA256
|
||||
* P384 with SHA256 is NOT supported
|
||||
* P256 with SHA256 should be supported, but not tested
|
||||
|
||||
|
||||
18
examples/generate_self_signed_ca.rs
Normal file
18
examples/generate_self_signed_ca.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
use rcgen::{BasicConstraints, Certificate, CertificateParams, DistinguishedName, DnType, IsCa, KeyPair, PKCS_ECDSA_P256_SHA256};
|
||||
|
||||
fn main() {
|
||||
let key_pair = KeyPair::generate(&PKCS_ECDSA_P256_SHA256).expect("Generate key pair failed");
|
||||
let key_pem = key_pair.serialize_pem();
|
||||
let mut certificate_params = CertificateParams::default();
|
||||
certificate_params.key_pair = Some(key_pair);
|
||||
certificate_params.is_ca = IsCa::Ca(BasicConstraints::Constrained(0));
|
||||
let mut distinguished_name = DistinguishedName::new();
|
||||
distinguished_name.push(DnType::CommonName, "Proxy Inspector Test CA");
|
||||
certificate_params.distinguished_name = distinguished_name;
|
||||
|
||||
let certificate = Certificate::from_params(certificate_params)
|
||||
.unwrap_or_else(|e| panic!("Generate cert failed: {}", e));
|
||||
let certificate_pem = certificate.serialize_pem_with_signer(&certificate).expect("Sign cert failed");
|
||||
println!("CERTIFICATE:\n{}", certificate_pem);
|
||||
println!("KEY:\n{}", key_pem);
|
||||
}
|
||||
Reference in New Issue
Block a user