Upgrade example to rcgen 0.13

This commit is contained in:
Dirkjan Ochtman 2024-07-26 10:15:19 +02:00
parent f90227429d
commit 7648ebb509
2 changed files with 7 additions and 7 deletions

View File

@ -38,7 +38,7 @@ thiserror = "1.0.30"
[dev-dependencies]
anyhow = "1.0.66"
clap = { version = "4.0.29", features = ["derive"] }
rcgen = { version = "0.12", default-features = false, features = ["pem"] }
rcgen = { version = "0.13", default-features = false, features = ["pem"] }
tokio = { version = "1.22.0", features = ["macros", "rt", "rt-multi-thread", "time"] }
tracing = "0.1.37"
tracing-subscriber = "0.3.16"

View File

@ -1,7 +1,7 @@
use std::{io, time::Duration};
use clap::Parser;
use rcgen::{Certificate, CertificateParams, DistinguishedName};
use rcgen::{CertificateParams, DistinguishedName, KeyPair};
use tokio::time::sleep;
use tracing::{error, info};
@ -128,14 +128,14 @@ async fn main() -> anyhow::Result<()> {
// If the order is ready, we can provision the certificate.
// Use the rcgen library to create a Certificate Signing Request.
let mut params = CertificateParams::new(names.clone());
let mut params = CertificateParams::new(names.clone())?;
params.distinguished_name = DistinguishedName::new();
let cert = Certificate::from_params(params).unwrap();
let csr = cert.serialize_request_der()?;
let private_key = KeyPair::generate()?;
let csr = params.serialize_request(&private_key)?;
// Finalize the order and print certificate chain, private key and account credentials.
order.finalize(&csr).await.unwrap();
order.finalize(csr.der()).await.unwrap();
let cert_chain_pem = loop {
match order.certificate().await.unwrap() {
Some(cert_chain_pem) => break cert_chain_pem,
@ -144,7 +144,7 @@ async fn main() -> anyhow::Result<()> {
};
info!("certficate chain:\n\n{}", cert_chain_pem);
info!("private key:\n\n{}", cert.serialize_private_key_pem());
info!("private key:\n\n{}", private_key.serialize_pem());
Ok(())
}