Skip to content

Commit 8ad47f4

Browse files
committed
Use newer rustls-pki-types PEM parser API
1 parent c81c028 commit 8ad47f4

File tree

6 files changed

+23
-37
lines changed

6 files changed

+23
-37
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ rcgen = "0.14"
3939
ring = "0.17"
4040
rustc-hash = "2"
4141
rustls = { version = "0.23.5", default-features = false, features = ["std"] }
42-
rustls-pemfile = "2"
4342
rustls-platform-verifier = "0.6"
4443
rustls-pki-types = "1.7"
4544
serde = { version = "1.0", features = ["derive"] }

perf/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ quinn = { path = "../quinn" }
3434
quinn-proto = { path = "../quinn-proto" }
3535
rcgen = { workspace = true }
3636
rustls = { workspace = true }
37-
rustls-pemfile = { workspace = true }
3837
serde = { workspace = true, optional = true }
3938
serde_json = { workspace = true, optional = true }
4039
socket2 = { workspace = true }

perf/src/server.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use std::{fs, net::SocketAddr, path::PathBuf, sync::Arc, time::Duration};
1+
use std::{net::SocketAddr, path::PathBuf, sync::Arc, time::Duration};
22

33
use anyhow::{Context, Result};
44
use bytes::Bytes;
55
use clap::Parser;
66
use quinn::{TokioRuntime, crypto::rustls::QuicServerConfig};
7-
use rustls::pki_types::{CertificateDer, PrivatePkcs8KeyDer};
7+
use rustls::pki_types::{CertificateDer, PrivateKeyDer, PrivatePkcs8KeyDer, pem::PemObject};
88
use tracing::{debug, error, info};
99

1010
use crate::{CommonOpt, PERF_CIPHER_SUITES, noprotection::NoProtectionServerConfig};
@@ -28,20 +28,17 @@ pub struct Opt {
2828

2929
pub async fn run(opt: Opt) -> Result<()> {
3030
let (key, cert) = match (&opt.key, &opt.cert) {
31-
(Some(key), Some(cert)) => {
32-
let key = fs::read(key).context("reading key")?;
33-
let cert = fs::read(cert).expect("reading cert");
34-
(
35-
PrivatePkcs8KeyDer::from(key),
36-
rustls_pemfile::certs(&mut cert.as_ref())
37-
.collect::<Result<_, _>>()
38-
.context("parsing cert")?,
39-
)
40-
}
31+
(Some(key), Some(cert)) => (
32+
PrivateKeyDer::from_pem_file(key).context("reading private key")?,
33+
CertificateDer::pem_file_iter(cert)
34+
.context("reading certificate chain file")?
35+
.collect::<Result<_, _>>()
36+
.context("reading certificate chain")?,
37+
),
4138
_ => {
4239
let cert = rcgen::generate_simple_self_signed(vec!["localhost".into()]).unwrap();
4340
(
44-
PrivatePkcs8KeyDer::from(cert.signing_key.serialize_der()),
41+
PrivatePkcs8KeyDer::from(cert.signing_key.serialize_der()).into(),
4542
vec![CertificateDer::from(cert.cert)],
4643
)
4744
}
@@ -57,7 +54,7 @@ pub async fn run(opt: Opt) -> Result<()> {
5754
.with_protocol_versions(&[&rustls::version::TLS13])
5855
.unwrap()
5956
.with_no_client_auth()
60-
.with_single_cert(cert, key.into())
57+
.with_single_cert(cert, key)
6158
.unwrap();
6259
crypto.alpn_protocols = vec![b"perf".to_vec()];
6360

quinn/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ bencher = { workspace = true }
8080
directories-next = { workspace = true }
8181
rand = { workspace = true }
8282
rcgen = { workspace = true }
83-
rustls-pemfile = { workspace = true }
8483
clap = { workspace = true }
8584
tokio = { workspace = true, features = ["rt", "rt-multi-thread", "time", "macros"] }
8685
tracing-subscriber = { workspace = true }

quinn/examples/server.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::{
1313
use anyhow::{Context, Result, anyhow, bail};
1414
use clap::Parser;
1515
use proto::crypto::rustls::QuicServerConfig;
16-
use rustls::pki_types::{CertificateDer, PrivateKeyDer, PrivatePkcs8KeyDer};
16+
use rustls::pki_types::{CertificateDer, PrivateKeyDer, PrivatePkcs8KeyDer, pem::PemObject};
1717
use tracing::{error, info, info_span};
1818
use tracing_futures::Instrument as _;
1919

@@ -69,19 +69,22 @@ fn main() {
6969
#[tokio::main]
7070
async fn run(options: Opt) -> Result<()> {
7171
let (certs, key) = if let (Some(key_path), Some(cert_path)) = (&options.key, &options.cert) {
72-
let key = fs::read(key_path).context("failed to read private key")?;
7372
let key = if key_path.extension().is_some_and(|x| x == "der") {
74-
PrivateKeyDer::Pkcs8(PrivatePkcs8KeyDer::from(key))
73+
PrivateKeyDer::Pkcs8(PrivatePkcs8KeyDer::from(
74+
fs::read(key_path).context("failed to read private key file")?,
75+
))
7576
} else {
76-
rustls_pemfile::private_key(&mut &*key)
77-
.context("malformed PKCS #1 private key")?
78-
.ok_or_else(|| anyhow::Error::msg("no private keys found"))?
77+
PrivateKeyDer::from_pem_file(key_path)
78+
.context("failed to read PEM from private key file")?
7979
};
80-
let cert_chain = fs::read(cert_path).context("failed to read certificate chain")?;
80+
8181
let cert_chain = if cert_path.extension().is_some_and(|x| x == "der") {
82-
vec![CertificateDer::from(cert_chain)]
82+
vec![CertificateDer::from(
83+
fs::read(cert_path).context("failed to read certificate chain file")?,
84+
)]
8385
} else {
84-
rustls_pemfile::certs(&mut &*cert_chain)
86+
CertificateDer::pem_file_iter(cert_path)
87+
.context("failed to read PEM from certificate chain file")?
8588
.collect::<Result<_, _>>()
8689
.context("invalid PEM-encoded certificate")?
8790
};

0 commit comments

Comments
 (0)