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

tls: Update dependencies and fixes for removed types #2392

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
95 changes: 13 additions & 82 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/trigger-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ http-body-util = { workspace = true }
indexmap = "1"
outbound-http = { path = "../outbound-http" }
percent-encoding = "2"
rustls-pemfile = "0.3.0"
rustls-pemfile = "2.1.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1"
spin-app = { path = "../app" }
Expand All @@ -33,7 +33,7 @@ spin-world = { path = "../world" }
terminal = { path = "../terminal" }
tls-listener = { version = "0.10.0", features = ["rustls"] }
tokio = { version = "1.23", features = ["full"] }
tokio-rustls = { version = "0.23.2" }
tokio-rustls = { version = "0.25.0" }
url = "2.4.1"
tracing = { workspace = true }
wasmtime = { workspace = true }
Expand Down
20 changes: 10 additions & 10 deletions crates/trigger-http/src/tls.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::tls::rustls::pki_types::{CertificateDer, PrivatePkcs8KeyDer};
use rustls_pemfile::{certs, pkcs8_private_keys};
use std::{
fs, io,
Expand All @@ -22,25 +23,24 @@ impl TlsConfig {
let mut keys = load_keys(&self.key_path)?;

let cfg = rustls::ServerConfig::builder()
.with_safe_defaults()
.with_safe_default_protocol_versions()
.with_no_client_auth()
.with_single_cert(certs, keys.remove(0))
.with_single_cert(
certs,
tokio_rustls::rustls::pki_types::PrivateKeyDer::Pkcs8(keys.remove(0)),
)
.map_err(|e| anyhow::anyhow!("{}", e))?;

Ok(Arc::new(cfg).into())
}
}

// Loads public certificate from file.
fn load_certs(path: impl AsRef<Path>) -> io::Result<Vec<rustls::Certificate>> {
certs(&mut io::BufReader::new(fs::File::open(path)?))
.map_err(|_| io::Error::new(io::ErrorKind::InvalidInput, "invalid cert"))
.map(|mut certs| certs.drain(..).map(rustls::Certificate).collect())
fn load_certs(path: impl AsRef<Path>) -> io::Result<Vec<CertificateDer<'static>>> {
certs(&mut io::BufReader::new(fs::File::open(path)?)).collect()
}

// Loads private key from file.
fn load_keys(path: impl AsRef<Path>) -> io::Result<Vec<rustls::PrivateKey>> {
pkcs8_private_keys(&mut io::BufReader::new(fs::File::open(path)?))
.map_err(|_| io::Error::new(io::ErrorKind::InvalidInput, "invalid key"))
.map(|mut keys| keys.drain(..).map(rustls::PrivateKey).collect())
fn load_keys(path: impl AsRef<Path>) -> io::Result<Vec<PrivatePkcs8KeyDer<'static>>> {
pkcs8_private_keys(&mut io::BufReader::new(fs::File::open(path)?)).collect()
}
Loading