Skip to content

Commit 05d88bf

Browse files
author
Guanqun Lu
committed
add an option to specify ssl version
Fixes #6684
1 parent 74383b4 commit 05d88bf

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ cargo-platform = { path = "crates/cargo-platform", version = "0.1" }
2525
crates-io = { path = "crates/crates-io", version = "0.28" }
2626
crossbeam-utils = "0.6"
2727
crypto-hash = "0.3.1"
28-
curl = { version = "0.4.21", features = ['http2'] }
29-
curl-sys = "0.4.18"
28+
curl = { version = "0.4.23", features = ['http2'] }
29+
curl-sys = "0.4.21"
3030
env_logger = "0.7.0"
3131
pretty_env_logger = { version = "0.3", optional = true }
3232
failure = "0.1.5"

src/cargo/ops/registry.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::time::Duration;
77
use std::{cmp, env};
88

99
use crates_io::{NewCrate, NewCrateDependency, Registry};
10-
use curl::easy::{Easy, InfoType, SslOpt};
10+
use curl::easy::{Easy, InfoType, SslOpt, SslVersion};
1111
use failure::{bail, format_err};
1212
use log::{log, Level};
1313
use percent_encoding::{percent_encode, NON_ALPHANUMERIC};
@@ -413,12 +413,14 @@ pub fn needs_custom_http_transport(config: &Config) -> CargoResult<bool> {
413413
let cainfo = config.get_path("http.cainfo")?;
414414
let check_revoke = config.get_bool("http.check-revoke")?;
415415
let user_agent = config.get_string("http.user-agent")?;
416+
let ssl_version = config.get_string("http.ssl-version")?;
416417

417418
Ok(proxy_exists
418419
|| timeout
419420
|| cainfo.is_some()
420421
|| check_revoke.is_some()
421-
|| user_agent.is_some())
422+
|| user_agent.is_some()
423+
|| ssl_version.is_some())
422424
}
423425

424426
/// Configure a libcurl http handle with the defaults options for Cargo
@@ -438,6 +440,21 @@ pub fn configure_http_handle(config: &Config, handle: &mut Easy) -> CargoResult<
438440
handle.useragent(&version().to_string())?;
439441
}
440442

443+
if let Some(ssl_version) = config.get_string("http.ssl-version")? {
444+
let version = match ssl_version.val.as_str() {
445+
"default" => SslVersion::Default,
446+
"sslv2" => SslVersion::Sslv2,
447+
"sslv3" => SslVersion::Sslv3,
448+
"tlsv1" => SslVersion::Tlsv1,
449+
"tlsv1.0" => SslVersion::Tlsv10,
450+
"tlsv1.1" => SslVersion::Tlsv11,
451+
"tlsv1.2" => SslVersion::Tlsv12,
452+
"tlsv1.3" => SslVersion::Tlsv13,
453+
_ => bail!("Invalid ssl version `{}`, choose from 'default', 'sslv2', 'sslv3', 'tlsv1', 'tlsv1.0', 'tlsv1.1', 'tlsv1.2', 'tlsv1.3'.", &ssl_version.val),
454+
};
455+
handle.ssl_min_max_version(version, version)?;
456+
}
457+
441458
if let Some(true) = config.get::<Option<bool>>("http.debug")? {
442459
handle.verbose(true)?;
443460
handle.debug_function(|kind, data| {

src/doc/src/reference/config.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ proxy = "host:port" # HTTP proxy to use for HTTP requests (defaults to none)
107107
timeout = 30 # Timeout for each HTTP request, in seconds
108108
cainfo = "cert.pem" # Path to Certificate Authority (CA) bundle (optional)
109109
check-revoke = true # Indicates whether SSL certs are checked for revocation
110+
ssl-version = "tlsv1.3" # Indicates which SSL version to use (defaults to
111+
# "default", "sslv2", "sslv3", "tlsv1", "tlsv1.0",
112+
# "tlsv1.1", "tlsv1.2", "tlsv1.3")
110113
low-speed-limit = 5 # Lower threshold for bytes/sec (10 = default, 0 = disabled)
111114
multiplexing = true # whether or not to use HTTP/2 multiplexing where possible
112115

0 commit comments

Comments
 (0)