Skip to content

Commit 3baded2

Browse files
committed
Minor fixes after PR review
1 parent 1e6c852 commit 3baded2

8 files changed

+66
-20
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -581,10 +581,11 @@ Command | Description
581581
Sets the root URL for downloading self-updates.
582582

583583
- `RUSTUP_USE_UNSAFE_SSL` (default: none)
584-
If set, rustup will not validate the SSL certificate when downloading
585-
files. This parameter should be used only in exceptional circumstances
586-
when youre computer is behind a corporate proxy that injects its own
587-
certificates into HTTPS connections.
584+
If set to "ACCEPT_RISKS", rustup will not validate the SSL certificate
585+
when downloading files. This parameter should be used only in exceptional
586+
circumstances when your computer is behind a corporate proxy that injects
587+
its own certificates into HTTPS connections and you're unable to add these
588+
certificates to your root set.
588589

589590
## Other installation methods
590591

rustup-init.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ downloader() {
386386
_dld='curl or wget' # to be used in error message of need_cmd
387387
fi
388388

389-
if [ -n "$RUSTUP_USE_UNSAFE_SSL" ]; then
389+
if [ "$RUSTUP_USE_UNSAFE_SSL" = "ACCEPT_RISKS" ]; then
390390
_curl_unsafe = "--insecure"
391391
_wget_unsafe = "--no-check-certificate"
392392
else

src/download/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ hyper = "0.12"
2828
tempdir = "0.3.4"
2929
tokio = "0.1.11"
3030
tokio-tls = "0.2.1"
31-
native-tls = "0.2.1"
31+
native-tls = "0.2.1"

src/download/src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pub fn download_to_path_with_backend(
130130
}
131131

132132
fn use_unsafe_ssl() -> bool {
133-
env::var_os("RUSTUP_USE_UNSAFE_SSL").is_some()
133+
env::var_os("RUSTUP_USE_UNSAFE_SSL").unwrap_or("NO".into()) == "ACCEPT_RISKS"
134134
}
135135

136136
/// Download via libcurl; encrypt with the native (or OpenSSl) TLS
@@ -181,9 +181,11 @@ pub mod curl {
181181
.connect_timeout(Duration::new(30, 0))
182182
.chain_err(|| "failed to set connect timeout")?;
183183

184-
handle
185-
.ssl_verify_peer(!use_unsafe_ssl())
186-
.chain_err(|| "failed to configure unsafe SSL mode")?;
184+
if use_unsafe_ssl() {
185+
handle
186+
.ssl_verify_peer(false)
187+
.chain_err(|| "failed to configure unsafe SSL mode")?;
188+
}
187189

188190
{
189191
let cberr = RefCell::new(None);

src/download/tests/download-curl-safe.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ use download::*;
55
mod support;
66
use crate::support::{file_contents, serve_file, tmp_dir};
77

8-
/// There are two separate files because this crate caches curl handles
9-
/// and all tests in one file use either the safe or the unsafe handle
8+
// There are two separate files because this crate caches curl handles
9+
// and all tests in one file use either the safe or the unsafe handle.
10+
// See download-curl-unsafe.rs for the complementary test case.
1011

1112
#[test]
1213
fn downloading_with_no_certificate() {
@@ -40,3 +41,22 @@ fn downloading_with_bad_certificate() {
4041

4142
assert_eq!(file_contents(&target_path), "12345");
4243
}
44+
45+
#[test]
46+
#[should_panic]
47+
fn downloading_with_bad_certificate_using_wrong_env_value() {
48+
let tmpdir = tmp_dir();
49+
let target_path = tmpdir.path().join("downloaded");
50+
51+
let addr = serve_file(b"12345".to_vec(), true);
52+
let from_url = format!("https://{}", addr).parse().unwrap();
53+
54+
std::env::set_var("RUSTUP_USE_UNSAFE_SSL", "FOOBAR");
55+
56+
assert_eq!(std::env::var_os("RUSTUP_USE_UNSAFE_SSL").is_some(), true);
57+
58+
download_to_path_with_backend(Backend::Curl, &from_url, &target_path, false, None)
59+
.expect("Test download failed");
60+
61+
assert_eq!(file_contents(&target_path), "12345");
62+
}

src/download/tests/download-curl-unsafe.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ use download::*;
55
mod support;
66
use crate::support::{file_contents, serve_file, tmp_dir};
77

8-
/// There are two separate files because this crate caches reqwest handles
9-
/// and all tests in one file use either the safe or the unsafe handle
8+
// There are two separate files because this crate caches curl handles
9+
// and all tests in one file use either the safe or the unsafe handle.
10+
// See download-curl-safe.rs for the complementary test case.
1011

1112
#[test]
1213
fn downloading_with_bad_certificate_unsafely() {
@@ -16,7 +17,7 @@ fn downloading_with_bad_certificate_unsafely() {
1617
let addr = serve_file(b"12345".to_vec(), true);
1718
let from_url = format!("https://{}", addr).parse().unwrap();
1819

19-
std::env::set_var("RUSTUP_USE_UNSAFE_SSL", "1");
20+
std::env::set_var("RUSTUP_USE_UNSAFE_SSL", "ACCEPT_RISKS");
2021

2122
assert_eq!(std::env::var_os("RUSTUP_USE_UNSAFE_SSL").is_some(), true);
2223

src/download/tests/download-reqwest-safe.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ use download::*;
55
mod support;
66
use crate::support::{file_contents, serve_file, tmp_dir};
77

8-
/// There are two separate files because this crate caches reqwest handles
9-
/// and all tests in one file use either the safe or the unsafe handle
8+
// There are two separate files because this crate caches reqwest clients
9+
// and all tests in one file use either the safe or the unsafe client.
10+
// See download-reqwest-unsafe.rs for the complementary test case.
1011

1112
#[test]
1213
fn downloading_with_no_certificate() {
@@ -40,3 +41,23 @@ fn downloading_with_bad_certificate() {
4041

4142
assert_eq!(file_contents(&target_path), "12345");
4243
}
44+
45+
46+
#[test]
47+
#[should_panic]
48+
fn downloading_with_bad_certificate_using_wrong_env_value() {
49+
let tmpdir = tmp_dir();
50+
let target_path = tmpdir.path().join("downloaded");
51+
52+
let addr = serve_file(b"12345".to_vec(), true);
53+
let from_url = format!("https://{}", addr).parse().unwrap();
54+
55+
std::env::set_var("RUSTUP_USE_UNSAFE_SSL", "FOOBAR");
56+
57+
assert_eq!(std::env::var_os("RUSTUP_USE_UNSAFE_SSL").is_some(), true);
58+
59+
download_to_path_with_backend(Backend::Reqwest, &from_url, &target_path, false, None)
60+
.expect("Test download failed");
61+
62+
assert_eq!(file_contents(&target_path), "12345");
63+
}

src/download/tests/download-reqwest-unsafe.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ use download::*;
55
mod support;
66
use crate::support::{file_contents, serve_file, tmp_dir};
77

8-
/// There are two separate files because this crate caches reqwest handles
9-
/// and all tests in one file use either the safe or the unsafe handle
8+
// There are two separate files because this crate caches reqwest clients
9+
// and all tests in one file use either the safe or the unsafe client.
10+
// See download-reqwest-safe.rs for the complementary test case.
1011

1112
#[test]
1213
fn downloading_with_bad_certificate_unsafely() {
@@ -16,7 +17,7 @@ fn downloading_with_bad_certificate_unsafely() {
1617
let addr = serve_file(b"12345".to_vec(), true);
1718
let from_url = format!("https://{}", addr).parse().unwrap();
1819

19-
std::env::set_var("RUSTUP_USE_UNSAFE_SSL", "1");
20+
std::env::set_var("RUSTUP_USE_UNSAFE_SSL", "ACCEPT_RISKS");
2021

2122
assert_eq!(std::env::var_os("RUSTUP_USE_UNSAFE_SSL").is_some(), true);
2223

0 commit comments

Comments
 (0)