Skip to content

Commit 8a4f8a4

Browse files
Fix build with "ring" instead of "aws_lc_rs" feature (#540)
Since there are feature flags for ring and aws-lc in libunftp, it seems unintended to pull aws-lc-sys unconditionally via the tokio-rustls default features. Furthermore, the build failed with "aws_lc_rs" disabled, since `tls.rs` unconditionally imported `rustls::crypto::aws_lc_rs`. With this PR merged, there will be a meaningful error message if neither "ring" nor "aws_lc_rs" are enabled, and enabling "ring" without "aws_lc_rs" is supported again. Last commit just removes some dead code which caused a warning. --------- Co-authored-by: Hannes de Jager <hannes.de.jager@gmail.com>
1 parent 178e456 commit 8a4f8a4

3 files changed

Lines changed: 20 additions & 21 deletions

File tree

Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ rustls = { version = "0.23.35", default-features = false }
6060
rustls-pemfile = "2.2.0"
6161
slog = { version = "2.8.2", features = ["max_level_trace", "release_max_level_info"] }
6262
slog-stdlog = "4.1.1"
63-
thiserror = "2.0.17"
64-
tokio = { version = "1.48.0", features = ["macros", "rt", "net", "process", "sync", "io-util", "time"] }
65-
tokio-rustls = "0.26.4"
66-
tokio-util = { version = "0.7.17", features = ["codec"] }
67-
tracing = { version = "0.1.44", default-features = false }
68-
tracing-attributes = "0.1.31"
69-
uuid = { version = "1.19.0", features = ["v4"] }
63+
thiserror = "2.0.12"
64+
tokio = { version = "1.44.2", features = ["macros", "rt", "net", "process", "sync", "io-util", "time"] }
65+
tokio-rustls = { version = "0.26.2", default-features = false }
66+
tokio-util = { version = "0.7.15", features = ["codec"] }
67+
tracing = { version = "0.1.41", default-features = false }
68+
tracing-attributes = "0.1.28"
69+
uuid = { version = "1.16.0", features = ["v4"] }
7070
x509-parser = "0.17.0"
7171
dashmap = "6.1.0"
7272
libc = "0.2"

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,6 @@ pub mod storage;
5252
pub use crate::server::ftpserver::{Server, ServerBuilder, error::ServerError, options};
5353

5454
type BoxError = Box<dyn std::error::Error + Send + Sync + 'static>;
55+
56+
#[cfg(not(any(feature = "aws_lc_rs", feature = "ring")))]
57+
compile_error!("Need to enable either aws_lc_rs or ring feature for libunftp");

src/server/tls.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
use crate::options::{FtpsClientAuth, TlsFlags};
22
use rustls::{
33
NoKeyLog, RootCertStore, ServerConfig, SupportedProtocolVersion,
4-
crypto::{aws_lc_rs, aws_lc_rs::Ticketer},
54
pki_types::{CertificateDer, PrivateKeyDer},
65
server::{ClientCertVerifierBuilder, NoServerSessionStorage, StoresServerSessions, WebPkiClientVerifier},
76
version::{TLS12, TLS13},
87
};
8+
9+
// Enable aws_lc_rs, unless the flag is disabled (in which case ring has to be enabled).
10+
// If both are enabled, aws_lc_rs is preferred.
11+
#[cfg(feature = "aws_lc_rs")]
12+
use rustls::crypto::{aws_lc_rs as crypto_impl, aws_lc_rs::Ticketer};
13+
#[cfg(all(not(feature = "aws_lc_rs"), feature = "ring"))]
14+
use rustls::crypto::{ring as crypto_impl, ring::Ticketer};
15+
916
use std::{
10-
fmt::{self, Display, Formatter},
17+
fmt::{self, Formatter},
1118
fs::File,
1219
io::{self, BufReader},
1320
path::{Path, PathBuf},
@@ -34,17 +41,6 @@ impl fmt::Debug for FtpsConfig {
3441
}
3542
}
3643

37-
#[derive(Debug, Copy, Clone)]
38-
pub struct FtpsNotAvailable;
39-
40-
impl Display for FtpsNotAvailable {
41-
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
42-
write!(f, "FTPS not configured/available")
43-
}
44-
}
45-
46-
impl std::error::Error for FtpsNotAvailable {}
47-
4844
// The error returned by new_config
4945
#[derive(Error, Debug)]
5046
#[error("TLS configuration error")]
@@ -96,7 +92,7 @@ pub fn new_config<P: AsRef<Path>>(
9692
versions.push(&TLS13)
9793
}
9894

99-
let provider = Arc::new(aws_lc_rs::default_provider());
95+
let provider = Arc::new(crypto_impl::default_provider());
10096
let mut config = ServerConfig::builder_with_provider(provider)
10197
.with_protocol_versions(&versions)
10298
.map_err(ConfigError::RustlsInit)?

0 commit comments

Comments
 (0)