Skip to content

Commit 20162df

Browse files
authored
Merge pull request #280 from sagebind/mesalink-ssl
Add support for MesaLink as a TLS backend
2 parents 0ba03a4 + 13ddb2d commit 20162df

File tree

5 files changed

+59
-30
lines changed

5 files changed

+59
-30
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ members = ["systest"]
4040

4141
[features]
4242
default = ["ssl"]
43-
ssl = ["openssl-sys", "openssl-probe", "curl-sys/ssl"]
43+
ssl = ["openssl-sys", "openssl-probe", "curl-sys/ssl"] # OpenSSL/system TLS backend
44+
mesalink = ["curl-sys/mesalink"] # MesaLink TLS backend
4445
http2 = ["curl-sys/http2"]
4546
static-curl = ["curl-sys/static-curl"]
4647
static-ssl = ["curl-sys/static-ssl"]

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ By default, this crate will attempt to dynamically link to the system-wide
131131
libcurl and the system-wide SSL library. Some of this behavior can be customized
132132
with various Cargo features:
133133

134-
- `ssl`: Enable SSL support. Enabled by default.
134+
- `ssl`: Enable SSL/TLS support using the platform-default TLS backend. On Windows this is [Schannel], on macOS [Secure Transport], and [OpenSSL] (or equivalent) on all other platforms. Enabled by default.
135+
- `mesalink`: Enable SSL/TLS support via [MesaLink], an alternative TLS backend written in Rust based on [Rustls]. MesaLink is always statically linked. Disabled by default.
135136
- `http2`: Enable HTTP/2 support via libnghttp2. Disabled by default.
136137
- `static-curl`: Use a bundled libcurl version and statically link to it. Disabled by default.
137138
- `static-ssl`: Use a bundled OpenSSL version and statically link to it. Only applies on platforms that use OpenSSL. Disabled by default.
@@ -169,3 +170,9 @@ In order to avoid this failure you can either
169170

170171
The `curl-rust` crate is licensed under the MIT license, see `LICENSE` for more
171172
details.
173+
174+
175+
[OpenSSL]: https://www.openssl.org/
176+
[Rustls]: https://github.com/ctz/rustls
177+
[Schannel]: https://docs.microsoft.com/en-us/windows/win32/com/schannel
178+
[Secure Transport]: https://developer.apple.com/documentation/security/secure_transport

curl-sys/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ libz-sys = "1.0.18"
2323
libc = "0.2.2"
2424
libnghttp2-sys = { optional = true, version = "0.1" }
2525

26+
[dependencies.mesalink]
27+
version = "1.1.0-cratesio"
28+
optional = true
29+
default-features = false
30+
features = ["client_apis", "error_strings", "tls13", "aesgcm", "chachapoly", "x25519", "ecdh", "ecdsa", "verifier"]
31+
2632
[target.'cfg(all(unix, not(target_os = "macos")))'.dependencies]
2733
openssl-sys = { version = "0.9", optional = true }
2834

curl-sys/build.rs

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -211,21 +211,56 @@ fn main() {
211211
.file("curl/lib/vauth/vauth.c");
212212
}
213213

214-
if windows {
215-
cfg.define("USE_THREADS_WIN32", None)
216-
.define("HAVE_IOCTLSOCKET_FIONBIO", None)
217-
.define("USE_WINSOCK", None)
218-
.file("curl/lib/system_win32.c");
214+
// Configure TLS backend. Since Cargo does not support mutually exclusive
215+
// features, make sure we only compile one vtls.
216+
if cfg!(feature = "mesalink") {
217+
cfg.define("USE_MESALINK", None)
218+
.file("curl/lib/vtls/mesalink.c");
219+
220+
if let Some(path) = env::var_os("DEP_MESALINK_INCLUDE") {
221+
cfg.include(path);
222+
}
219223

220-
if cfg!(feature = "ssl") {
224+
if windows {
225+
cfg.define("HAVE_WINDOWS", None);
226+
} else {
227+
cfg.define("HAVE_UNIX", None);
228+
}
229+
} else if cfg!(feature = "ssl") {
230+
if windows {
221231
cfg.define("USE_WINDOWS_SSPI", None)
222232
.define("USE_SCHANNEL", None)
223233
.file("curl/lib/x509asn1.c")
224234
.file("curl/lib/curl_sspi.c")
225235
.file("curl/lib/socks_sspi.c")
226236
.file("curl/lib/vtls/schannel.c")
227237
.file("curl/lib/vtls/schannel_verify.c");
238+
} else if target.contains("-apple-") {
239+
cfg.define("USE_SECTRANSP", None)
240+
.file("curl/lib/vtls/sectransp.c");
241+
if xcode_major_version().map_or(true, |v| v >= 9) {
242+
// On earlier Xcode versions (<9), defining HAVE_BUILTIN_AVAILABLE
243+
// would cause __bultin_available() to fail to compile due to
244+
// unrecognized platform names, so we try to check for Xcode
245+
// version first (if unknown, assume it's recent, as in >= 9).
246+
cfg.define("HAVE_BUILTIN_AVAILABLE", "1");
247+
}
248+
} else {
249+
cfg.define("USE_OPENSSL", None)
250+
.file("curl/lib/vtls/openssl.c");
251+
252+
println!("cargo:rustc-cfg=link_openssl");
253+
if let Some(path) = env::var_os("DEP_OPENSSL_INCLUDE") {
254+
cfg.include(path);
255+
}
228256
}
257+
}
258+
259+
if windows {
260+
cfg.define("USE_THREADS_WIN32", None)
261+
.define("HAVE_IOCTLSOCKET_FIONBIO", None)
262+
.define("USE_WINSOCK", None)
263+
.file("curl/lib/system_win32.c");
229264

230265
if cfg!(feature = "spnego") {
231266
cfg.file("curl/lib/vauth/spnego_sspi.c");
@@ -265,28 +300,6 @@ fn main() {
265300
.define("SIZEOF_INT", "4")
266301
.define("SIZEOF_SHORT", "2");
267302

268-
if cfg!(feature = "ssl") {
269-
if target.contains("-apple-") {
270-
cfg.define("USE_SECTRANSP", None)
271-
.file("curl/lib/vtls/sectransp.c");
272-
if xcode_major_version().map_or(true, |v| v >= 9) {
273-
// On earlier Xcode versions (<9), defining HAVE_BUILTIN_AVAILABLE
274-
// would cause __bultin_available() to fail to compile due to
275-
// unrecognized platform names, so we try to check for Xcode
276-
// version first (if unknown, assume it's recent, as in >= 9).
277-
cfg.define("HAVE_BUILTIN_AVAILABLE", "1");
278-
}
279-
} else {
280-
cfg.define("USE_OPENSSL", None)
281-
.file("curl/lib/vtls/openssl.c");
282-
283-
println!("cargo:rustc-cfg=link_openssl");
284-
if let Some(path) = env::var_os("DEP_OPENSSL_INCLUDE") {
285-
cfg.include(path);
286-
}
287-
}
288-
}
289-
290303
if cfg!(feature = "spnego") {
291304
cfg.define("HAVE_GSSAPI", None)
292305
.file("curl/lib/curl_gssapi.c")

curl-sys/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ extern crate libc;
66
extern crate libnghttp2_sys;
77
#[cfg(link_libz)]
88
extern crate libz_sys;
9+
#[cfg(feature = "mesalink")]
10+
extern crate mesalink; // ensure lib is linked to
911
#[cfg(link_openssl)]
1012
extern crate openssl_sys;
1113
#[cfg(windows)]

0 commit comments

Comments
 (0)