diff --git a/.github/workflows/gateway.yml b/.github/workflows/gateway.yml index 98798cb..3535c5d 100644 --- a/.github/workflows/gateway.yml +++ b/.github/workflows/gateway.yml @@ -19,6 +19,16 @@ env: IMAGE_NAME: ${{ github.repository }} jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt + - run: cargo fmt --check + - uses: EmbarkStudios/cargo-deny-action@v2 + test: runs-on: ubuntu-latest services: @@ -50,7 +60,7 @@ jobs: image: runs-on: ubuntu-latest - needs: test + needs: [lint, test] if: github.event_name != 'pull_request' steps: - uses: actions/checkout@v5 diff --git a/Cargo.lock b/Cargo.lock index 7ac41bd..479bec6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -21,7 +21,6 @@ dependencies = [ "p256", "rcgen", "rustls", - "rustls-pemfile", "rustls-pki-types", "serde", "sqlx", @@ -111,9 +110,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.102" +version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" +checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" [[package]] name = "asn1-rs" @@ -188,9 +187,9 @@ checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" [[package]] name = "aws-lc-rs" -version = "1.16.3" +version = "1.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ec6fb3fe69024a75fa7e1bfb48aa6cf59706a101658ea01bfd33b2b248a038f" +checksum = "b281d307588d634de920874890732659e2e7672f72b5e10e81badc1a8a83621e" dependencies = [ "aws-lc-sys", "zeroize", @@ -198,14 +197,15 @@ dependencies = [ [[package]] name = "aws-lc-sys" -version = "0.40.0" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f50037ee5e1e41e7b8f9d161680a725bd1626cb6f8c7e901f91f942850852fe7" +checksum = "9bff6c3b54fad79a2e60b8102caf565819711497c1f5f092f49508e2f5c31b27" dependencies = [ "cc", "cmake", "dunce", "fs_extra", + "pkg-config", ] [[package]] @@ -770,9 +770,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.4.14" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "171fefbc92fe4a4de27e0698d6a5b392d6a0e333506bc49133760b3bcf948733" +checksum = "7d29020232d6aa3fb1daca64c1127cf662cf97f254ae16c18c05b8ab635fc118" dependencies = [ "atomic-waker", "bytes", @@ -1768,9 +1768,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.40" +version = "0.23.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef86cd5876211988985292b91c96a8f2d298df24e75989a43a3c73f2d4d8168b" +checksum = "0d41d731c7d2f962d1ccc364cec258de3c0e93b38c2fb3ba97ac74513048d634" dependencies = [ "aws-lc-rs", "once_cell", @@ -1781,15 +1781,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "rustls-pemfile" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" -dependencies = [ - "rustls-pki-types", -] - [[package]] name = "rustls-pki-types" version = "1.14.1" @@ -1801,9 +1792,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.103.13" +version = "0.103.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61c429a8649f110dddef65e2a5ad240f747e85f7758a6bccc7e5777bd33f756e" +checksum = "f3c3cf1d8b1e7d4927e2d154c3fcb02979afb9939629c62cd9048d4f07b60ac2" dependencies = [ "aws-lc-rs", "ring", diff --git a/Cargo.toml b/Cargo.toml index aec46e3..42b2c0a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,8 +11,7 @@ pedantic = "deny" tokio = { version = "1", features = ["io-util", "macros", "net", "rt-multi-thread", "signal", "time"] } rustls = { version = "0.23", default-features = false, features = ["aws-lc-rs", "std", "tls12"] } tokio-rustls = { version = "0.26", default-features = false, features = ["aws-lc-rs", "tls12"] } -rustls-pemfile = "2" -rustls-pki-types = "1" +rustls-pki-types = { version = "1.12", features = ["std"] } x509-parser = { version = "0.18", default-features = false } hyper = { version = "1", features = ["server", "http2"] } hyper-util = { version = "0.1", features = ["tokio", "server-auto"] } diff --git a/deny.toml b/deny.toml new file mode 100644 index 0000000..3d8ba80 --- /dev/null +++ b/deny.toml @@ -0,0 +1,37 @@ +# cargo-deny configuration: https://embarkstudios.github.io/cargo-deny/ +[graph] +all-features = true + +[advisories] +# Vulnerabilities, unsound and unmaintained crates all fail the check. To accept one +# temporarily, add { id = "RUSTSEC-...", reason = "..." } here. +unmaintained = "all" +yanked = "deny" +ignore = [] + +[licenses] +allow = [ + "Apache-2.0", + "BSD-2-Clause", + "BSD-3-Clause", + "BSL-1.0", + "CC0-1.0", + "CDLA-Permissive-2.0", + "ISC", + "MIT", + "MIT-0", + "Unicode-3.0", + "Unlicense", + "Zlib", +] +confidence-threshold = 0.93 + +[bans] +multiple-versions = "warn" +wildcards = "deny" +allow-wildcard-paths = true + +[sources] +unknown-registry = "deny" +unknown-git = "deny" +allow-registry = ["https://github.com/rust-lang/crates.io-index"] diff --git a/src/tls.rs b/src/tls.rs index 22f6215..a9b70c7 100644 --- a/src/tls.rs +++ b/src/tls.rs @@ -1,5 +1,3 @@ -use std::fs::File; -use std::io::BufReader; use std::path::Path; use std::sync::Arc; @@ -10,6 +8,7 @@ use rustls::{ CertificateError, DigitallySignedStruct, DistinguishedName, Error as RustlsError, ServerConfig, SignatureScheme, }; +use rustls_pki_types::pem::{self, PemObject}; use rustls_pki_types::{CertificateDer, PrivateKeyDer, UnixTime}; pub use tokio_rustls::TlsAcceptor; use x509_parser::prelude::*; @@ -119,16 +118,16 @@ fn parse_certificate(cert: &CertificateDer<'_>) -> Result<(), RustlsError> { } fn load_cert_chain(path: &Path) -> anyhow::Result>> { - let file = File::open(path)?; - let mut reader = BufReader::new(file); - let certs = rustls_pemfile::certs(&mut reader).collect::, _>>()?; + let certs = CertificateDer::pem_file_iter(path) + .with_context(|| format!("opening {}", path.display()))? + .collect::, _>>()?; ensure!(!certs.is_empty(), "no certificates in {}", path.display()); Ok(certs) } fn load_private_key(path: &Path) -> anyhow::Result> { - let file = File::open(path)?; - let mut reader = BufReader::new(file); - rustls_pemfile::private_key(&mut reader)? - .ok_or_else(|| anyhow!("no private key in {}", path.display())) + match PrivateKeyDer::from_pem_file(path) { + Err(pem::Error::NoItemsFound) => Err(anyhow!("no private key in {}", path.display())), + res => res.with_context(|| format!("reading private key {}", path.display())), + } }