mirror of
https://github.com/svenstaro/miniserve
synced 2024-07-08 20:05:56 +00:00
Switch TLS conditional compilation to feature
This commit is contained in:
parent
c79bcaae04
commit
2ea23ceb41
14
.github/workflows/publish.yml
vendored
14
.github/workflows/publish.yml
vendored
|
@ -32,6 +32,7 @@ jobs:
|
||||||
cross: true
|
cross: true
|
||||||
strip: true
|
strip: true
|
||||||
compress: true
|
compress: true
|
||||||
|
cargo_flags: ""
|
||||||
- os: ubuntu-latest
|
- os: ubuntu-latest
|
||||||
target: aarch64-unknown-linux-musl
|
target: aarch64-unknown-linux-musl
|
||||||
artifact_name: target/aarch64-unknown-linux-musl/release/miniserve
|
artifact_name: target/aarch64-unknown-linux-musl/release/miniserve
|
||||||
|
@ -39,6 +40,7 @@ jobs:
|
||||||
cross: true
|
cross: true
|
||||||
strip: false
|
strip: false
|
||||||
compress: true
|
compress: true
|
||||||
|
cargo_flags: ""
|
||||||
- os: ubuntu-latest
|
- os: ubuntu-latest
|
||||||
target: armv7-unknown-linux-musleabihf
|
target: armv7-unknown-linux-musleabihf
|
||||||
artifact_name: target/armv7-unknown-linux-musleabihf/release/miniserve
|
artifact_name: target/armv7-unknown-linux-musleabihf/release/miniserve
|
||||||
|
@ -46,6 +48,7 @@ jobs:
|
||||||
cross: true
|
cross: true
|
||||||
strip: false
|
strip: false
|
||||||
compress: true
|
compress: true
|
||||||
|
cargo_flags: ""
|
||||||
- os: ubuntu-latest
|
- os: ubuntu-latest
|
||||||
target: arm-unknown-linux-musleabihf
|
target: arm-unknown-linux-musleabihf
|
||||||
artifact_name: target/arm-unknown-linux-musleabihf/release/miniserve
|
artifact_name: target/arm-unknown-linux-musleabihf/release/miniserve
|
||||||
|
@ -53,6 +56,7 @@ jobs:
|
||||||
cross: true
|
cross: true
|
||||||
strip: false
|
strip: false
|
||||||
compress: true
|
compress: true
|
||||||
|
cargo_flags: ""
|
||||||
- os: ubuntu-latest
|
- os: ubuntu-latest
|
||||||
target: mips-unknown-linux-musl
|
target: mips-unknown-linux-musl
|
||||||
artifact_name: target/mips-unknown-linux-musl/release/miniserve
|
artifact_name: target/mips-unknown-linux-musl/release/miniserve
|
||||||
|
@ -60,6 +64,7 @@ jobs:
|
||||||
cross: true
|
cross: true
|
||||||
strip: false
|
strip: false
|
||||||
compress: true
|
compress: true
|
||||||
|
cargo_flags: "--no-default-features"
|
||||||
- os: ubuntu-latest
|
- os: ubuntu-latest
|
||||||
target: mipsel-unknown-linux-musl
|
target: mipsel-unknown-linux-musl
|
||||||
artifact_name: target/mipsel-unknown-linux-musl/release/miniserve
|
artifact_name: target/mipsel-unknown-linux-musl/release/miniserve
|
||||||
|
@ -67,6 +72,7 @@ jobs:
|
||||||
cross: true
|
cross: true
|
||||||
strip: false
|
strip: false
|
||||||
compress: true
|
compress: true
|
||||||
|
cargo_flags: "--no-default-features"
|
||||||
- os: ubuntu-latest
|
- os: ubuntu-latest
|
||||||
target: mips64-unknown-linux-gnuabi64
|
target: mips64-unknown-linux-gnuabi64
|
||||||
artifact_name: target/mips64-unknown-linux-gnuabi64/release/miniserve
|
artifact_name: target/mips64-unknown-linux-gnuabi64/release/miniserve
|
||||||
|
@ -74,6 +80,7 @@ jobs:
|
||||||
cross: true
|
cross: true
|
||||||
strip: false
|
strip: false
|
||||||
compress: false
|
compress: false
|
||||||
|
cargo_flags: "--no-default-features"
|
||||||
- os: ubuntu-latest
|
- os: ubuntu-latest
|
||||||
target: mips64el-unknown-linux-gnuabi64
|
target: mips64el-unknown-linux-gnuabi64
|
||||||
artifact_name: target/mips64el-unknown-linux-gnuabi64/release/miniserve
|
artifact_name: target/mips64el-unknown-linux-gnuabi64/release/miniserve
|
||||||
|
@ -81,6 +88,7 @@ jobs:
|
||||||
cross: true
|
cross: true
|
||||||
strip: false
|
strip: false
|
||||||
compress: false
|
compress: false
|
||||||
|
cargo_flags: "--no-default-features"
|
||||||
- os: ubuntu-latest
|
- os: ubuntu-latest
|
||||||
target: riscv64gc-unknown-linux-gnu
|
target: riscv64gc-unknown-linux-gnu
|
||||||
artifact_name: target/riscv64gc-unknown-linux-gnu/release/miniserve
|
artifact_name: target/riscv64gc-unknown-linux-gnu/release/miniserve
|
||||||
|
@ -88,6 +96,7 @@ jobs:
|
||||||
cross: true
|
cross: true
|
||||||
strip: false
|
strip: false
|
||||||
compress: false
|
compress: false
|
||||||
|
cargo_flags: "--no-default-features"
|
||||||
- os: windows-latest
|
- os: windows-latest
|
||||||
target: x86_64-pc-windows-msvc
|
target: x86_64-pc-windows-msvc
|
||||||
artifact_name: target/x86_64-pc-windows-msvc/release/miniserve.exe
|
artifact_name: target/x86_64-pc-windows-msvc/release/miniserve.exe
|
||||||
|
@ -95,6 +104,7 @@ jobs:
|
||||||
cross: false
|
cross: false
|
||||||
strip: true
|
strip: true
|
||||||
compress: true
|
compress: true
|
||||||
|
cargo_flags: ""
|
||||||
- os: macos-latest
|
- os: macos-latest
|
||||||
target: x86_64-apple-darwin
|
target: x86_64-apple-darwin
|
||||||
artifact_name: target/x86_64-apple-darwin/release/miniserve
|
artifact_name: target/x86_64-apple-darwin/release/miniserve
|
||||||
|
@ -102,6 +112,7 @@ jobs:
|
||||||
cross: false
|
cross: false
|
||||||
strip: true
|
strip: true
|
||||||
compress: true
|
compress: true
|
||||||
|
cargo_flags: ""
|
||||||
- os: ubuntu-latest
|
- os: ubuntu-latest
|
||||||
target: x86_64-unknown-freebsd
|
target: x86_64-unknown-freebsd
|
||||||
artifact_name: target/x86_64-unknown-freebsd/release/miniserve
|
artifact_name: target/x86_64-unknown-freebsd/release/miniserve
|
||||||
|
@ -109,6 +120,7 @@ jobs:
|
||||||
cross: true
|
cross: true
|
||||||
strip: false
|
strip: false
|
||||||
compress: false
|
compress: false
|
||||||
|
cargo_flags: ""
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
|
@ -124,7 +136,7 @@ jobs:
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: build
|
command: build
|
||||||
args: --release --locked --target=${{ matrix.target }}
|
args: --release --locked --target=${{ matrix.target }} ${{ matrix.cargo_flags }}
|
||||||
use-cross: ${{ matrix.cross }}
|
use-cross: ${{ matrix.cross }}
|
||||||
|
|
||||||
- name: Compress binaries
|
- name: Compress binaries
|
||||||
|
|
|
@ -51,14 +51,15 @@ httparse = "1"
|
||||||
http = "0.2"
|
http = "0.2"
|
||||||
bytes = "1"
|
bytes = "1"
|
||||||
atty = "0.2"
|
atty = "0.2"
|
||||||
|
rustls = { version = "0.18", optional = true }
|
||||||
|
|
||||||
# Use rustls only on architecturs supported by ring.
|
[features]
|
||||||
|
default = ["tls"]
|
||||||
|
# This feature allows us to use rustls only on architectures supported by ring.
|
||||||
# See also https://github.com/briansmith/ring/issues/1182
|
# See also https://github.com/briansmith/ring/issues/1182
|
||||||
# and https://github.com/briansmith/ring/issues/562
|
# and https://github.com/briansmith/ring/issues/562
|
||||||
# and https://github.com/briansmith/ring/issues/1367
|
# and https://github.com/briansmith/ring/issues/1367
|
||||||
[target.'cfg(any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64", target_arch = "arm"))'.dependencies]
|
tls = ["rustls", "actix-web/rustls"]
|
||||||
rustls = "0.18"
|
|
||||||
actix-web = { version = "3", features = ["rustls"] }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
assert_cmd = "2"
|
assert_cmd = "2"
|
||||||
|
|
14
src/args.rs
14
src/args.rs
|
@ -135,22 +135,12 @@ pub struct CliArgs {
|
||||||
pub print_completions: Option<structopt::clap::Shell>,
|
pub print_completions: Option<structopt::clap::Shell>,
|
||||||
|
|
||||||
/// TLS certificate to use
|
/// TLS certificate to use
|
||||||
#[cfg(any(
|
#[cfg(feature = "tls")]
|
||||||
target_arch = "x86",
|
|
||||||
target_arch = "x86_64",
|
|
||||||
target_arch = "aarch64",
|
|
||||||
target_arch = "arm"
|
|
||||||
))]
|
|
||||||
#[structopt(long = "tls-cert", requires = "tls-key")]
|
#[structopt(long = "tls-cert", requires = "tls-key")]
|
||||||
pub tls_cert: Option<PathBuf>,
|
pub tls_cert: Option<PathBuf>,
|
||||||
|
|
||||||
/// TLS private key to use
|
/// TLS private key to use
|
||||||
#[cfg(any(
|
#[cfg(feature = "tls")]
|
||||||
target_arch = "x86",
|
|
||||||
target_arch = "x86_64",
|
|
||||||
target_arch = "aarch64",
|
|
||||||
target_arch = "arm"
|
|
||||||
))]
|
|
||||||
#[structopt(long = "tls-key", requires = "tls-cert")]
|
#[structopt(long = "tls-key", requires = "tls-cert")]
|
||||||
pub tls_key: Option<PathBuf>,
|
pub tls_key: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,12 +8,7 @@ use std::{
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use http::HeaderMap;
|
use http::HeaderMap;
|
||||||
|
|
||||||
#[cfg(any(
|
#[cfg(feature = "tls")]
|
||||||
target_arch = "x86",
|
|
||||||
target_arch = "x86_64",
|
|
||||||
target_arch = "aarch64",
|
|
||||||
target_arch = "arm"
|
|
||||||
))]
|
|
||||||
use rustls::internal::pemfile::{certs, pkcs8_private_keys};
|
use rustls::internal::pemfile::{certs, pkcs8_private_keys};
|
||||||
|
|
||||||
use crate::{args::CliArgs, auth::RequiredAuth};
|
use crate::{args::CliArgs, auth::RequiredAuth};
|
||||||
|
@ -102,20 +97,10 @@ pub struct MiniserveConfig {
|
||||||
pub hide_version_footer: bool,
|
pub hide_version_footer: bool,
|
||||||
|
|
||||||
/// If set, use provided rustls config for TLS
|
/// If set, use provided rustls config for TLS
|
||||||
#[cfg(any(
|
#[cfg(feature = "tls")]
|
||||||
target_arch = "x86",
|
|
||||||
target_arch = "x86_64",
|
|
||||||
target_arch = "aarch64",
|
|
||||||
target_arch = "arm"
|
|
||||||
))]
|
|
||||||
pub tls_rustls_config: Option<rustls::ServerConfig>,
|
pub tls_rustls_config: Option<rustls::ServerConfig>,
|
||||||
|
|
||||||
#[cfg(not(any(
|
#[cfg(not(feature = "tls"))]
|
||||||
target_arch = "x86",
|
|
||||||
target_arch = "x86_64",
|
|
||||||
target_arch = "aarch64",
|
|
||||||
target_arch = "arm"
|
|
||||||
)))]
|
|
||||||
pub tls_rustls_config: Option<()>,
|
pub tls_rustls_config: Option<()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,12 +137,7 @@ impl MiniserveConfig {
|
||||||
_ => args.port,
|
_ => args.port,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(any(
|
#[cfg(feature = "tls")]
|
||||||
target_arch = "x86",
|
|
||||||
target_arch = "x86_64",
|
|
||||||
target_arch = "aarch64",
|
|
||||||
target_arch = "arm"
|
|
||||||
))]
|
|
||||||
let tls_rustls_server_config = if let (Some(tls_cert), Some(tls_key)) =
|
let tls_rustls_server_config = if let (Some(tls_cert), Some(tls_key)) =
|
||||||
(args.tls_cert, args.tls_key)
|
(args.tls_cert, args.tls_key)
|
||||||
{
|
{
|
||||||
|
@ -178,12 +158,7 @@ impl MiniserveConfig {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(not(any(
|
#[cfg(not(feature = "tls"))]
|
||||||
target_arch = "x86",
|
|
||||||
target_arch = "x86_64",
|
|
||||||
target_arch = "aarch64",
|
|
||||||
target_arch = "arm"
|
|
||||||
)))]
|
|
||||||
let tls_rustls_server_config = None;
|
let tls_rustls_server_config = None;
|
||||||
|
|
||||||
Ok(MiniserveConfig {
|
Ok(MiniserveConfig {
|
||||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -227,12 +227,7 @@ async fn run(miniserve_config: MiniserveConfig) -> Result<(), ContextualError> {
|
||||||
.default_service(web::get().to(error_404))
|
.default_service(web::get().to(error_404))
|
||||||
});
|
});
|
||||||
|
|
||||||
#[cfg(any(
|
#[cfg(feature = "tls")]
|
||||||
target_arch = "x86",
|
|
||||||
target_arch = "x86_64",
|
|
||||||
target_arch = "aarch64",
|
|
||||||
target_arch = "arm"
|
|
||||||
))]
|
|
||||||
let srv = if let Some(tls_config) = miniserve_config.tls_rustls_config {
|
let srv = if let Some(tls_config) = miniserve_config.tls_rustls_config {
|
||||||
srv.bind_rustls(socket_addresses.as_slice(), tls_config)
|
srv.bind_rustls(socket_addresses.as_slice(), tls_config)
|
||||||
.map_err(|e| ContextualError::IoError("Failed to bind server".to_string(), e))?
|
.map_err(|e| ContextualError::IoError("Failed to bind server".to_string(), e))?
|
||||||
|
@ -245,12 +240,7 @@ async fn run(miniserve_config: MiniserveConfig) -> Result<(), ContextualError> {
|
||||||
.run()
|
.run()
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(not(any(
|
#[cfg(not(feature = "tls"))]
|
||||||
target_arch = "x86",
|
|
||||||
target_arch = "x86_64",
|
|
||||||
target_arch = "aarch64",
|
|
||||||
target_arch = "arm"
|
|
||||||
)))]
|
|
||||||
let srv = srv
|
let srv = srv
|
||||||
.bind(socket_addresses.as_slice())
|
.bind(socket_addresses.as_slice())
|
||||||
.map_err(|e| ContextualError::IoError("Failed to bind server".to_string(), e))?
|
.map_err(|e| ContextualError::IoError("Failed to bind server".to_string(), e))?
|
||||||
|
|
Loading…
Reference in New Issue
Block a user