Skip to content

Commit 9de29ff

Browse files
committed
Warn Windows 7 users about old TLS
An eyepatch for #5066.
1 parent e3949fb commit 9de29ff

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

src/cargo/util/network.rs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,33 @@ fn maybe_spurious(err: &Error) -> bool {
3333
false
3434
}
3535

36+
37+
/// Suggest the user to update their windows 7 to support modern TLS versions.
38+
/// See https://github.com/rust-lang/cargo/issues/5066 for details.
39+
#[cfg(windows)]
40+
fn should_warn_about_old_tls_for_win7(err: &Error) -> bool {
41+
err.causes()
42+
.filter_map(|e| e.downcast_ref::<git2::Error>())
43+
.find(|e| e.class() == git2::ErrorClass::Net && e.code() == git2::ErrorCode::Certificate)
44+
.is_some()
45+
}
46+
47+
#[cfg(not(windows))]
48+
fn should_warn_about_old_tls_for_win7(_err: &Error) -> bool {
49+
false
50+
}
51+
52+
const WIN7_TLS_WARNING: &str = "\
53+
Certificate check failure might be caused by outdated TLS on older versions of Windows.
54+
If you are using Windows 7, Windows Server 2008 R2 or Windows Server 2012,
55+
please follow these instructions to enable more secure TLS:
56+
57+
https://support.microsoft.com/en-us/help/3140245/
58+
59+
See https://github.com/rust-lang/cargo/issues/5066 for details.
60+
";
61+
62+
3663
/// Wrapper method for network call retry logic.
3764
///
3865
/// Retry counts provided by Config object `net.retry`. Config shell outputs
@@ -54,9 +81,14 @@ pub fn with_retry<T, F>(config: &Config, mut callback: F) -> CargoResult<T>
5481
match callback() {
5582
Ok(ret) => return Ok(ret),
5683
Err(ref e) if maybe_spurious(e) && remaining > 0 => {
57-
let msg = format!("spurious network error ({} tries \
58-
remaining): {}", remaining, e);
59-
config.shell().warn(msg)?;
84+
config.shell().warn(
85+
format!("spurious network error ({} tries remaining): {}", remaining, e)
86+
)?;
87+
88+
if should_warn_about_old_tls_for_win7(e) {
89+
config.shell().warn(WIN7_TLS_WARNING)?;
90+
}
91+
6092
remaining -= 1;
6193
}
6294
//todo impl from

0 commit comments

Comments
 (0)