Skip to content

Commit

Permalink
chore: update rustls-pemfile usage
Browse files Browse the repository at this point in the history
  • Loading branch information
omjadas committed Dec 1, 2023
1 parent 6fb41a4 commit 33a7fea
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 21 deletions.
9 changes: 7 additions & 2 deletions benches/certificate_authorities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ fn build_rcgen_ca(cache_size: u64) -> RcgenAuthority {
let mut ca_cert_bytes: &[u8] = include_bytes!("../examples/ca/hudsucker.cer");
let private_key = rustls::PrivateKey(
pemfile::pkcs8_private_keys(&mut private_key_bytes)
.next()
.unwrap()
.expect("Failed to parse private key")
.remove(0),
.secret_pkcs8_der()
.to_vec(),
);
let ca_cert = rustls::Certificate(
pemfile::certs(&mut ca_cert_bytes)
.next()
.unwrap()
.expect("Failed to parse CA certificate")
.remove(0),
.to_vec(),
);

RcgenAuthority::new(private_key, ca_cert, cache_size)
Expand Down
9 changes: 7 additions & 2 deletions benches/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@ fn build_ca() -> RcgenAuthority {
let mut ca_cert_bytes: &[u8] = include_bytes!("../examples/ca/hudsucker.cer");
let private_key = rustls::PrivateKey(
pemfile::pkcs8_private_keys(&mut private_key_bytes)
.next()
.unwrap()
.expect("Failed to parse private key")
.remove(0),
.secret_pkcs8_der()
.to_vec(),
);
let ca_cert = rustls::Certificate(
pemfile::certs(&mut ca_cert_bytes)
.next()
.unwrap()
.expect("Failed to parse CA certificate")
.remove(0),
.to_vec(),
);

RcgenAuthority::new(private_key, ca_cert, 1_000)
Expand Down
9 changes: 7 additions & 2 deletions examples/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,18 @@ async fn main() {
let mut ca_cert_bytes: &[u8] = include_bytes!("ca/hudsucker.cer");
let private_key = rustls::PrivateKey(
pemfile::pkcs8_private_keys(&mut private_key_bytes)
.next()
.unwrap()
.expect("Failed to parse private key")
.remove(0),
.secret_pkcs8_der()
.to_vec(),
);
let ca_cert = rustls::Certificate(
pemfile::certs(&mut ca_cert_bytes)
.next()
.unwrap()
.expect("Failed to parse CA certificate")
.remove(0),
.to_vec(),
);

let ca = RcgenAuthority::new(private_key, ca_cert, 1_000)
Expand Down
9 changes: 7 additions & 2 deletions examples/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@ async fn main() {
let mut ca_cert_bytes: &[u8] = include_bytes!("ca/hudsucker.cer");
let private_key = rustls::PrivateKey(
pemfile::pkcs8_private_keys(&mut private_key_bytes)
.next()
.unwrap()
.expect("Failed to parse private key")
.remove(0),
.secret_pkcs8_der()
.to_vec(),
);
let ca_cert = rustls::Certificate(
pemfile::certs(&mut ca_cert_bytes)
.next()
.unwrap()
.expect("Failed to parse CA certificate")
.remove(0),
.to_vec(),
);

let ca = RcgenAuthority::new(private_key, ca_cert, 1_000)
Expand Down
18 changes: 14 additions & 4 deletions src/certificate_authority/rcgen_authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,18 @@ use tracing::debug;
/// let mut ca_cert_bytes: &[u8] = include_bytes!("../../examples/ca/hudsucker.cer");
/// let private_key = rustls::PrivateKey(
/// pemfile::pkcs8_private_keys(&mut private_key_bytes)
/// .next()
/// .unwrap()
/// .remove(0),
/// .expect("Failed to parse private key")
/// .secret_pkcs8_der()
/// .to_vec(),
/// );
/// let ca_cert = rustls::Certificate(
/// pemfile::certs(&mut ca_cert_bytes)
/// .next()
/// .unwrap()
/// .remove(0),
/// .expect("Failed to parse CA certificate")
/// .to_vec(),
/// );
///
/// let ca = RcgenAuthority::new(private_key, ca_cert, 1_000).unwrap();
Expand Down Expand Up @@ -159,13 +164,18 @@ mod tests {
let mut ca_cert_bytes: &[u8] = include_bytes!("../../examples/ca/hudsucker.cer");
let private_key = rustls::PrivateKey(
pemfile::pkcs8_private_keys(&mut private_key_bytes)
.next()
.unwrap()
.expect("Failed to parse private key")
.remove(0),
.secret_pkcs8_der()
.to_vec(),
);
let ca_cert = rustls::Certificate(
pemfile::certs(&mut ca_cert_bytes)
.next()
.unwrap()
.expect("Failed to parse CA certificate")
.remove(0),
.to_vec(),
);

RcgenAuthority::new(private_key, ca_cert, cache_size).unwrap()
Expand Down
9 changes: 7 additions & 2 deletions src/proxy/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@ use tokio_tungstenite::Connector;
/// # let mut ca_cert_bytes: &[u8] = include_bytes!("../../examples/ca/hudsucker.cer");
/// # let private_key = rustls::PrivateKey(
/// # pemfile::pkcs8_private_keys(&mut private_key_bytes)
/// # .next()
/// # .unwrap()
/// # .expect("Failed to parse private key")
/// # .remove(0),
/// # .secret_pkcs8_der()
/// # .to_vec(),
/// # );
/// # let ca_cert = rustls::Certificate(
/// # pemfile::certs(&mut ca_cert_bytes)
/// # .next()
/// # .unwrap()
/// # .expect("Failed to parse CA certificate")
/// # .remove(0),
/// # .to_vec(),
/// # );
/// #
/// # let ca = RcgenAuthority::new(private_key, ca_cert, 1_000)
Expand Down
9 changes: 7 additions & 2 deletions src/proxy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,18 @@ pub use builder::ProxyBuilder;
/// # let mut ca_cert_bytes: &[u8] = include_bytes!("../../examples/ca/hudsucker.cer");
/// # let private_key = rustls::PrivateKey(
/// # pemfile::pkcs8_private_keys(&mut private_key_bytes)
/// # .next()
/// # .unwrap()
/// # .expect("Failed to parse private key")
/// # .remove(0),
/// # .secret_pkcs8_der()
/// # .to_vec(),
/// # );
/// # let ca_cert = rustls::Certificate(
/// # pemfile::certs(&mut ca_cert_bytes)
/// # .next()
/// # .unwrap()
/// # .expect("Failed to parse CA certificate")
/// # .remove(0),
/// # .to_vec(),
/// # );
/// #
/// # let ca = RcgenAuthority::new(private_key, ca_cert, 1_000)
Expand Down
8 changes: 7 additions & 1 deletion tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,13 @@ fn rustls_client_config() -> rustls::ClientConfig {
}

let mut ca_cert_bytes: &[u8] = include_bytes!("../../examples/ca/hudsucker.cer");
let ca_cert = rustls::Certificate(pemfile::certs(&mut ca_cert_bytes).unwrap().remove(0));
let ca_cert = rustls::Certificate(
pemfile::certs(&mut ca_cert_bytes)
.next()
.unwrap()
.expect("Failed to parse CA certificate")
.to_vec(),
);

roots.add(&ca_cert).unwrap();

Expand Down
9 changes: 7 additions & 2 deletions tests/rcgen_ca.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ fn build_ca() -> RcgenAuthority {
let mut ca_cert_bytes: &[u8] = include_bytes!("../examples/ca/hudsucker.cer");
let private_key = rustls::PrivateKey(
pemfile::pkcs8_private_keys(&mut private_key_bytes)
.next()
.unwrap()
.expect("Failed to parse private key")
.remove(0),
.secret_pkcs8_der()
.to_vec(),
);
let ca_cert = rustls::Certificate(
pemfile::certs(&mut ca_cert_bytes)
.next()
.unwrap()
.expect("Failed to parse CA certificate")
.remove(0),
.to_vec(),
);

RcgenAuthority::new(private_key, ca_cert, 1_000)
Expand Down
9 changes: 7 additions & 2 deletions tests/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ fn build_ca() -> RcgenAuthority {
let mut ca_cert_bytes: &[u8] = include_bytes!("../examples/ca/hudsucker.cer");
let private_key = rustls::PrivateKey(
pemfile::pkcs8_private_keys(&mut private_key_bytes)
.next()
.unwrap()
.expect("Failed to parse private key")
.remove(0),
.secret_pkcs8_der()
.to_vec(),
);
let ca_cert = rustls::Certificate(
pemfile::certs(&mut ca_cert_bytes)
.next()
.unwrap()
.expect("Failed to parse CA certificate")
.remove(0),
.to_vec(),
);

RcgenAuthority::new(private_key, ca_cert, 1_000)
Expand Down

0 comments on commit 33a7fea

Please sign in to comment.