Skip to content

Commit 81e18de

Browse files
committed
Warn about TLS for github specifically
1 parent 9de29ff commit 81e18de

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

src/cargo/sources/git/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ pub fn with_fetch_options(git_config: &git2::Config,
591591
-> CargoResult<()>
592592
{
593593
let mut progress = Progress::new("Fetch", config);
594-
network::with_retry(config, || {
594+
network::with_retry(config, url, || {
595595
with_authentication(url.as_str(), git_config, |f| {
596596
let mut rcb = git2::RemoteCallbacks::new();
597597
rcb.credentials(f);

src/cargo/sources/registry/remote.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,13 @@ impl<'cfg> RegistryData for RemoteRegistry<'cfg> {
224224
// TODO: don't download into memory, but ensure that if we ctrl-c a
225225
// download we should resume either from the start or the middle
226226
// on the next time
227-
let url = url.to_string();
228227
let mut handle = self.config.http()?.borrow_mut();
229228
handle.get(true)?;
230-
handle.url(&url)?;
229+
handle.url(&url.to_string())?;
231230
handle.follow_location(true)?;
232231
let mut state = Sha256::new();
233232
let mut body = Vec::new();
234-
network::with_retry(self.config, || {
233+
network::with_retry(self.config, &url, || {
235234
state = Sha256::new();
236235
body = Vec::new();
237236
let mut pb = Progress::new("Fetch", self.config);
@@ -250,8 +249,10 @@ impl<'cfg> RegistryData for RemoteRegistry<'cfg> {
250249
}
251250
let code = handle.response_code()?;
252251
if code != 200 && code != 0 {
253-
let url = handle.effective_url()?.unwrap_or(&url);
254-
Err(HttpNot200 { code, url: url.to_string() }.into())
252+
let url = handle.effective_url()?
253+
.map(|url| url.to_string())
254+
.unwrap_or_else(|| url.to_string());
255+
Err(HttpNot200 { code, url }.into())
255256
} else {
256257
Ok(())
257258
}

src/cargo/util/network.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use curl;
22
use git2;
3+
use url::Url;
34

45
use failure::Error;
56

@@ -37,15 +38,17 @@ fn maybe_spurious(err: &Error) -> bool {
3738
/// Suggest the user to update their windows 7 to support modern TLS versions.
3839
/// See https://github.com/rust-lang/cargo/issues/5066 for details.
3940
#[cfg(windows)]
40-
fn should_warn_about_old_tls_for_win7(err: &Error) -> bool {
41-
err.causes()
41+
fn should_warn_about_old_tls_for_win7(url: &Url, err: &Error) -> bool {
42+
let is_github = url.host_str() == Some("github.com");
43+
let is_cert_error = err.causes()
4244
.filter_map(|e| e.downcast_ref::<git2::Error>())
4345
.find(|e| e.class() == git2::ErrorClass::Net && e.code() == git2::ErrorCode::Certificate)
44-
.is_some()
46+
.is_some();
47+
is_github && is_cert_error
4548
}
4649

4750
#[cfg(not(windows))]
48-
fn should_warn_about_old_tls_for_win7(_err: &Error) -> bool {
51+
fn should_warn_about_old_tls_for_win7(_url: &Url, _err: &Error) -> bool {
4952
false
5053
}
5154

@@ -71,9 +74,9 @@ See https://github.com/rust-lang/cargo/issues/5066 for details.
7174
///
7275
/// ```ignore
7376
/// use util::network;
74-
/// cargo_result = network.with_retry(&config, || something.download());
77+
/// cargo_result = network::with_retry(&config, || something.download());
7578
/// ```
76-
pub fn with_retry<T, F>(config: &Config, mut callback: F) -> CargoResult<T>
79+
pub fn with_retry<T, F>(config: &Config, url: &Url, mut callback: F) -> CargoResult<T>
7780
where F: FnMut() -> CargoResult<T>
7881
{
7982
let mut remaining = config.net_retry()?;
@@ -85,7 +88,7 @@ pub fn with_retry<T, F>(config: &Config, mut callback: F) -> CargoResult<T>
8588
format!("spurious network error ({} tries remaining): {}", remaining, e)
8689
)?;
8790

88-
if should_warn_about_old_tls_for_win7(e) {
91+
if should_warn_about_old_tls_for_win7(url, e) {
8992
config.shell().warn(WIN7_TLS_WARNING)?;
9093
}
9194

@@ -103,7 +106,8 @@ fn with_retry_repeats_the_call_then_works() {
103106
let error2 = HttpNot200 { code: 502, url: "Uri".to_string() }.into();
104107
let mut results: Vec<CargoResult<()>> = vec![Ok(()), Err(error1), Err(error2)];
105108
let config = Config::default().unwrap();
106-
let result = with_retry(&config, || results.pop().unwrap());
109+
let url = "http://example.com".parse().unwrap();
110+
let result = with_retry(&config, &url, || results.pop().unwrap());
107111
assert_eq!(result.unwrap(), ())
108112
}
109113

@@ -119,6 +123,7 @@ fn with_retry_finds_nested_spurious_errors() {
119123
let error2 = CargoError::from(error2.context("A second chained error"));
120124
let mut results: Vec<CargoResult<()>> = vec![Ok(()), Err(error1), Err(error2)];
121125
let config = Config::default().unwrap();
122-
let result = with_retry(&config, || results.pop().unwrap());
126+
let url = "http://example.com".parse().unwrap();
127+
let result = with_retry(&config, &url, || results.pop().unwrap());
123128
assert_eq!(result.unwrap(), ())
124129
}

0 commit comments

Comments
 (0)