From 89ecd20017cc5ff485ffe3146f6fd68dd6612e82 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 5 May 2016 18:50:13 +0000 Subject: [PATCH 01/14] Bump hyper to 0.9.2 --- Cargo.lock | 77 ++++------------------------------- Cargo.toml | 2 +- src/rustup-dist/Cargo.toml | 2 +- src/rustup-dist/tests/dist.rs | 12 ++---- src/rustup-mock/Cargo.toml | 2 +- src/rustup-utils/Cargo.toml | 2 +- src/rustup-utils/src/raw.rs | 2 +- 7 files changed, 16 insertions(+), 83 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9237e17b03..cd3513e68f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = "0.1.9" dependencies = [ "clap 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "error-chain 0.1.9", - "hyper 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", @@ -178,14 +178,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "hyper" -version = "0.7.2" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cookie 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "httparse 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "mime 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "mime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "openssl 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", @@ -194,7 +194,7 @@ dependencies = [ "traitobject 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "url 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -287,11 +287,10 @@ dependencies = [ [[package]] name = "mime" -version = "0.1.3" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -303,38 +302,6 @@ dependencies = [ "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "num" -version = "0.1.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", - "num-iter 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "num-integer" -version = "0.1.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "num-iter" -version = "0.1.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "num-traits" -version = "0.1.32" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "num_cpus" version = "0.2.11" @@ -444,7 +411,7 @@ version = "0.1.9" dependencies = [ "error-chain 0.1.9", "flate2 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", - "hyper 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)", "ole32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "openssl 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -462,7 +429,7 @@ name = "rustup-mock" version = "0.1.9" dependencies = [ "flate2 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", - "hyper 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", "openssl 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -481,7 +448,7 @@ version = "0.1.9" dependencies = [ "advapi32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "error-chain 0.1.9", - "hyper 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "ole32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -504,14 +471,6 @@ name = "semver" version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "serde" -version = "0.6.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "num 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "shell32-sys" version = "0.1.1" @@ -632,18 +591,6 @@ name = "unicode-width" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "url" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-bidi 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-normalization 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "uuid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "url" version = "1.0.0" @@ -676,14 +623,6 @@ name = "utf8-ranges" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "uuid" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "vec_map" version = "0.6.0" diff --git a/Cargo.toml b/Cargo.toml index 8d08526c54..049851bf48 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ error-chain = { path = "src/error-chain", version = "0.1.9" } clap = "2.2.4" regex = "0.1.41" openssl = "0.7.2" -hyper = "0.7.0" +hyper = "0.9.2" term = "0.4.4" itertools = "0.4.1" time = "0.1.34" diff --git a/src/rustup-dist/Cargo.toml b/src/rustup-dist/Cargo.toml index 1e96696879..67d8eba973 100644 --- a/src/rustup-dist/Cargo.toml +++ b/src/rustup-dist/Cargo.toml @@ -14,7 +14,7 @@ license = "MIT OR Apache-2.0" [dependencies] regex = "0.1.41" -hyper = "0.7.0" +hyper = "0.9.2" openssl = "0.7.2" itertools = "0.4.1" ole32-sys = "0.2.0" diff --git a/src/rustup-dist/tests/dist.rs b/src/rustup-dist/tests/dist.rs index 04b54a35e0..a966b0af4c 100644 --- a/src/rustup-dist/tests/dist.rs +++ b/src/rustup-dist/tests/dist.rs @@ -278,7 +278,7 @@ fn update_from_dist(dist_server: &Url, notify_handler: notify_handler.clone(), gpg_key: None, }; - let manifest_file = try!(download.get(&manifest_url.serialize())); + let manifest_file = try!(download.get(manifest_url.as_str())); let manifest_str = try!(utils::read_file("manifest", &manifest_file)); let manifest = try!(Manifest::parse(&manifest_str)); @@ -295,15 +295,9 @@ fn update_from_dist(dist_server: &Url, } fn make_manifest_url(dist_server: &Url, toolchain: &ToolchainDesc) -> Result { - let mut url = dist_server.clone(); - if let Some(mut p) = url.path_mut() { - p.push(format!("dist/channel-rust-{}.toml", toolchain.channel)); - } else { - // FIXME - panic!() - } + let url = format!("{}/dist/channel-rust-{}.toml", dist_server, toolchain.channel); - Ok(url) + Ok(Url::parse(&url).unwrap()) } fn uninstall(toolchain: &ToolchainDesc, prefix: &InstallPrefix, temp_cfg: &temp::Cfg, diff --git a/src/rustup-mock/Cargo.toml b/src/rustup-mock/Cargo.toml index 4e70154e1f..37113a7abd 100644 --- a/src/rustup-mock/Cargo.toml +++ b/src/rustup-mock/Cargo.toml @@ -10,7 +10,7 @@ homepage = "https://github.com/rust-lang-nursery/rustup.rs" repository = "https://github.com/rust-lang-nursery/rustup.rs" [dependencies] -hyper = "0.7.0" +hyper = "0.9.2" scopeguard = "0.1.2" lazy_static = "0.1.15" walkdir = "0.1.5" diff --git a/src/rustup-utils/Cargo.toml b/src/rustup-utils/Cargo.toml index e3360f3d51..4fe50aa983 100644 --- a/src/rustup-utils/Cargo.toml +++ b/src/rustup-utils/Cargo.toml @@ -13,7 +13,7 @@ license = "MIT OR Apache-2.0" [dependencies] openssl = "0.7.2" -hyper = "0.7.0" +hyper = "0.9.2" rand = "0.3.11" scopeguard = "0.1.2" error-chain = { path = "../error-chain", version = "0.1.9" } diff --git a/src/rustup-utils/src/raw.rs b/src/rustup-utils/src/raw.rs index fa94a9c9b7..b52cb311fa 100644 --- a/src/rustup-utils/src/raw.rs +++ b/src/rustup-utils/src/raw.rs @@ -202,7 +202,7 @@ pub fn download_file>(url: hyper::Url, use notifications::Notification; // The file scheme is mostly for use by tests to mock the dist server - if url.scheme == "file" { + if url.scheme() == "file" { let src = try!(url.to_file_path().map_err(|_| DownloadError::FilePathParse)); if !is_file(&src) { // Because some of multirust's logic depends on checking From 65c8655298308ae4ea08e8eb506ae9794bcfe53e Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 5 May 2016 20:01:23 +0000 Subject: [PATCH 02/14] Replace hyper dep with url dep in rustup-dist --- Cargo.lock | 56 +++++++++++++++++------------------ src/rustup-dist/Cargo.toml | 2 +- src/rustup-dist/src/lib.rs | 1 - src/rustup-dist/tests/dist.rs | 4 +-- 4 files changed, 31 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cd3513e68f..61e1c844f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,16 +2,16 @@ name = "rustup" version = "0.1.9" dependencies = [ - "clap 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "clap 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "error-chain 0.1.9", "hyper 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "openssl 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.1.68 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 0.1.69 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "rustup-dist 0.1.9", "rustup-mock 0.1.9", @@ -45,7 +45,7 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", @@ -65,7 +65,7 @@ dependencies = [ "cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -75,7 +75,7 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gcc 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -95,12 +95,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "clap" -version = "2.3.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "ansi_term 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "strsim 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-width 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "vec_map 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -114,7 +114,7 @@ dependencies = [ "openssl 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -138,7 +138,7 @@ name = "filetime" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -146,7 +146,7 @@ name = "flate2" version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "miniz-sys 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -194,7 +194,7 @@ dependencies = [ "traitobject 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -256,7 +256,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -282,7 +282,7 @@ name = "memchr" version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -299,7 +299,7 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gcc 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -307,7 +307,7 @@ name = "num_cpus" version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -327,7 +327,7 @@ dependencies = [ "bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "gcc 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-sys 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-sys-extras 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -338,7 +338,7 @@ version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gdi32-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "libressl-pnacl-sys 2.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "user32-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -350,7 +350,7 @@ version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gcc 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-sys 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -372,15 +372,15 @@ name = "rand" version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "regex" -version = "0.1.68" +version = "0.1.69" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "aho-corasick 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "aho-corasick 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", "regex-syntax 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "thread_local 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -411,16 +411,16 @@ version = "0.1.9" dependencies = [ "error-chain 0.1.9", "flate2 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", - "hyper 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)", "ole32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "openssl 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.1.68 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 0.1.69 (registry+https://github.com/rust-lang/crates.io-index)", "rustup-mock 0.1.9", "rustup-utils 0.1.9", "tar 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "tempdir 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "walkdir 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -500,7 +500,7 @@ version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "filetime 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -526,7 +526,7 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -543,7 +543,7 @@ version = "0.1.35" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -593,7 +593,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "url" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "idna 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/src/rustup-dist/Cargo.toml b/src/rustup-dist/Cargo.toml index 67d8eba973..3e8b62d581 100644 --- a/src/rustup-dist/Cargo.toml +++ b/src/rustup-dist/Cargo.toml @@ -14,10 +14,10 @@ license = "MIT OR Apache-2.0" [dependencies] regex = "0.1.41" -hyper = "0.9.2" openssl = "0.7.2" itertools = "0.4.1" ole32-sys = "0.2.0" +url = "1.1.0" tar = "0.4.0" flate2 = "0.2.9" tempdir = "0.3.4" diff --git a/src/rustup-dist/src/lib.rs b/src/rustup-dist/src/lib.rs index ecaa334193..86edc6ba7e 100644 --- a/src/rustup-dist/src/lib.rs +++ b/src/rustup-dist/src/lib.rs @@ -1,6 +1,5 @@ #![recursion_limit = "1024"] -extern crate hyper; extern crate regex; extern crate openssl; extern crate itertools; diff --git a/src/rustup-dist/tests/dist.rs b/src/rustup-dist/tests/dist.rs index a966b0af4c..8d3b584a19 100644 --- a/src/rustup-dist/tests/dist.rs +++ b/src/rustup-dist/tests/dist.rs @@ -11,7 +11,7 @@ extern crate toml; extern crate flate2; extern crate walkdir; extern crate itertools; -extern crate hyper; +extern crate url; use rustup_mock::dist::*; use rustup_mock::{MockCommand, MockInstallerBuilder}; @@ -25,7 +25,7 @@ use rustup_utils::raw as utils_raw; use rustup_dist::temp; use rustup_dist::manifestation::{Manifestation, UpdateStatus, Changes}; use rustup_dist::manifest::{Manifest, Component}; -use hyper::Url; +use url::Url; use std::fs; use std::io::Write; use std::path::Path; From e98f62ecb12a85a2faf69f66f05b089fa2acd408 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 5 May 2016 20:03:26 +0000 Subject: [PATCH 03/14] Replace hyper dep with url in rustup --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/rustup-cli/main.rs | 1 - src/rustup/lib.rs | 2 +- src/rustup/toolchain.rs | 4 ++-- 5 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 61e1c844f4..72c04101f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,6 @@ version = "0.1.9" dependencies = [ "clap 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "error-chain 0.1.9", - "hyper 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", @@ -20,6 +19,7 @@ dependencies = [ "tempdir 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "term 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "user32-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "winreg 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 049851bf48..f37ddcf395 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ error-chain = { path = "src/error-chain", version = "0.1.9" } clap = "2.2.4" regex = "0.1.41" openssl = "0.7.2" -hyper = "0.9.2" +url = "1.1.0" term = "0.4.4" itertools = "0.4.1" time = "0.1.34" diff --git a/src/rustup-cli/main.rs b/src/rustup-cli/main.rs index 87f29bfc9d..0208113efa 100644 --- a/src/rustup-cli/main.rs +++ b/src/rustup-cli/main.rs @@ -9,7 +9,6 @@ extern crate error_chain; #[macro_use] extern crate clap; extern crate regex; -extern crate hyper; #[macro_use] extern crate rustup; extern crate term; diff --git a/src/rustup/lib.rs b/src/rustup/lib.rs index 4de4ca2e32..2992225e63 100644 --- a/src/rustup/lib.rs +++ b/src/rustup/lib.rs @@ -5,7 +5,7 @@ extern crate rustup_dist; extern crate rustup_utils; #[macro_use] extern crate error_chain; -extern crate hyper; +extern crate url; extern crate regex; extern crate itertools; extern crate rustc_serialize; diff --git a/src/rustup/toolchain.rs b/src/rustup/toolchain.rs index 17c29350dc..113f33cc78 100644 --- a/src/rustup/toolchain.rs +++ b/src/rustup/toolchain.rs @@ -17,7 +17,7 @@ use std::path::{Path, PathBuf}; use std::ffi::OsStr; use std::env; -use hyper; +use url::Url; #[derive(Debug)] pub struct Toolchain<'a> { @@ -230,7 +230,7 @@ impl<'a> Toolchain<'a> { let is_url = installer_str.starts_with("file://") || installer_str.starts_with("http://") || installer_str.starts_with("https://"); - let url = hyper::Url::parse(installer_str).ok(); + let url = Url::parse(installer_str).ok(); let url = if is_url { url } else { None }; if let Some(url) = url { From d256d38b7f9be010f5bf864efc5f0ace30b1a599 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 5 May 2016 20:06:20 +0000 Subject: [PATCH 04/14] Simplify windows deps with cfg --- Cargo.lock | 30 +++++++++++++++--------------- Cargo.toml | 20 +------------------- src/rustup-mock/Cargo.toml | 14 +------------- src/rustup-utils/Cargo.toml | 28 +--------------------------- 4 files changed, 18 insertions(+), 74 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 72c04101f4..fc4d41029c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,7 +8,7 @@ dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.1.69 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", @@ -80,12 +80,12 @@ dependencies = [ [[package]] name = "bitflags" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "bitflags" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -111,7 +111,7 @@ name = "cookie" version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "openssl 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -187,7 +187,7 @@ dependencies = [ "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "mime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "solicit 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", @@ -321,20 +321,20 @@ dependencies = [ [[package]] name = "openssl" -version = "0.7.10" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "gcc 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-sys 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-sys-extras 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-sys 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-sys-extras 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "openssl-sys" -version = "0.7.10" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gdi32-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -346,12 +346,12 @@ dependencies = [ [[package]] name = "openssl-sys-extras" -version = "0.7.10" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gcc 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-sys 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-sys 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -413,7 +413,7 @@ dependencies = [ "flate2 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)", "ole32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.1.69 (registry+https://github.com/rust-lang/crates.io-index)", "rustup-mock 0.1.9", "rustup-utils 0.1.9", @@ -432,7 +432,7 @@ dependencies = [ "hyper 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", "scopeguard 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "tar 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "tempdir 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -452,7 +452,7 @@ dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "ole32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "scopeguard 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "shell32-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index f37ddcf395..c8967bafe1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,25 +34,7 @@ rand = "0.3.11" scopeguard = "0.1.2" rustc-serialize = "0.3" -[target.x86_64-pc-windows-gnu.dependencies] -winapi = "0.2.4" -winreg = "0.3.2" -user32-sys = "0.1.2" -kernel32-sys = "0.2.1" - -[target.x86_64-pc-windows-msvc.dependencies] -winapi = "0.2.4" -winreg = "0.3.2" -user32-sys = "0.1.2" -kernel32-sys = "0.2.1" - -[target.i686-pc-windows-gnu.dependencies] -winapi = "0.2.4" -winreg = "0.3.2" -user32-sys = "0.1.2" -kernel32-sys = "0.2.1" - -[target.i686-pc-windows-msvc.dependencies] +[target."cfg(windows)".dependencies] winapi = "0.2.4" winreg = "0.3.2" user32-sys = "0.1.2" diff --git a/src/rustup-mock/Cargo.toml b/src/rustup-mock/Cargo.toml index 37113a7abd..79b1a14925 100644 --- a/src/rustup-mock/Cargo.toml +++ b/src/rustup-mock/Cargo.toml @@ -21,18 +21,6 @@ itertools = "0.4.1" tar = "0.4.0" toml = "0.1.27" -[target.x86_64-pc-windows-gnu.dependencies] -winapi = "0.2.4" -winreg = "0.3.2" - -[target.x86_64-pc-windows-msvc.dependencies] -winapi = "0.2.4" -winreg = "0.3.2" - -[target.i686-pc-windows-gnu.dependencies] -winapi = "0.2.4" -winreg = "0.3.2" - -[target.i686-pc-windows-msvc.dependencies] +[target."cfg(windows)".dependencies] winapi = "0.2.4" winreg = "0.3.2" diff --git a/src/rustup-utils/Cargo.toml b/src/rustup-utils/Cargo.toml index 4fe50aa983..b8997e4799 100644 --- a/src/rustup-utils/Cargo.toml +++ b/src/rustup-utils/Cargo.toml @@ -19,7 +19,7 @@ scopeguard = "0.1.2" error-chain = { path = "../error-chain", version = "0.1.9" } libc = "0.2.0" -[target.x86_64-pc-windows-gnu.dependencies] +[target."cfg(windows)".dependencies] winapi = "0.2.4" winreg = "0.3.2" shell32-sys = "0.1.1" @@ -28,29 +28,3 @@ kernel32-sys = "0.2.1" advapi32-sys = "0.2.0" userenv-sys = "0.2.0" -[target.x86_64-pc-windows-msvc.dependencies] -winapi = "0.2.4" -winreg = "0.3.2" -shell32-sys = "0.1.1" -ole32-sys = "0.2.0" -kernel32-sys = "0.2.1" -advapi32-sys = "0.2.0" -userenv-sys = "0.2.0" - -[target.i686-pc-windows-gnu.dependencies] -winapi = "0.2.4" -winreg = "0.3.2" -shell32-sys = "0.1.1" -ole32-sys = "0.2.0" -kernel32-sys = "0.2.1" -advapi32-sys = "0.2.0" -userenv-sys = "0.2.0" - -[target.i686-pc-windows-msvc.dependencies] -winapi = "0.2.4" -winreg = "0.3.2" -shell32-sys = "0.1.1" -ole32-sys = "0.2.0" -kernel32-sys = "0.2.1" -advapi32-sys = "0.2.0" -userenv-sys = "0.2.0" From 273546de2bdf0ddf2c9a1488302beb46a0773ad5 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 5 May 2016 20:15:30 +0000 Subject: [PATCH 05/14] Extract download-from-file logic from download_file --- src/rustup-utils/src/raw.rs | 64 ++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/src/rustup-utils/src/raw.rs b/src/rustup-utils/src/raw.rs index b52cb311fa..6bc2a7e27d 100644 --- a/src/rustup-utils/src/raw.rs +++ b/src/rustup-utils/src/raw.rs @@ -198,35 +198,14 @@ pub fn download_file>(url: hyper::Url, mut hasher: Option<&mut Hasher>, notify_handler: NotifyHandler) -> DownloadResult<()> { - use hyper::header::ContentLength; - use notifications::Notification; - - // The file scheme is mostly for use by tests to mock the dist server - if url.scheme() == "file" { - let src = try!(url.to_file_path().map_err(|_| DownloadError::FilePathParse)); - if !is_file(&src) { - // Because some of multirust's logic depends on checking - // the error when a downloaded file doesn't exist, make - // the file case return the same error value as the - // network case. - return Err(DownloadError::Status(hyper::status::StatusCode::NotFound)); - } - try!(fs::copy(&src, path.as_ref()).map_err(|e| DownloadError::File(e))); - - if let Some(ref mut h) = hasher { - let ref mut f = try!(fs::File::open(path.as_ref()).map_err(|e| DownloadError::File(e))); - - let ref mut buffer = vec![0u8; 0x10000]; - loop { - let bytes_read = try!(io::Read::read(f, buffer).map_err(|e| DownloadError::File(e))); - if bytes_read == 0 { break } - try!(io::Write::write_all(*h, &buffer[0..bytes_read]).map_err(|e| DownloadError::File(e))); - } - } + if try!(download_from_file_url(&url, &path, &mut hasher)) { return Ok(()); } + use hyper::header::ContentLength; + use notifications::Notification; + let client = Client::new(); let mut res = try!(client.get(url).send().map_err(DownloadError::Network)); @@ -237,7 +216,7 @@ pub fn download_file>(url: hyper::Url, let buffer_size = 0x10000; let mut buffer = vec![0u8; buffer_size]; - let mut file = try!(fs::File::create(path).map_err(DownloadError::File)); + let mut file = try!(fs::File::create(&path).map_err(DownloadError::File)); if let Some(len) = res.headers.get::().cloned() { notify_handler.call(Notification::DownloadContentLengthReceived(len.0)); @@ -264,6 +243,39 @@ pub fn download_file>(url: hyper::Url, } } +fn download_from_file_url>(url: &hyper::Url, + path: P, + hasher: &mut Option<&mut Hasher>) + -> DownloadResult { + // The file scheme is mostly for use by tests to mock the dist server + if url.scheme() == "file" { + let src = try!(url.to_file_path().map_err(|_| DownloadError::FilePathParse)); + if !is_file(&src) { + // Because some of multirust's logic depends on checking + // the error when a downloaded file doesn't exist, make + // the file case return the same error value as the + // network case. + return Err(DownloadError::Status(hyper::status::StatusCode::NotFound)); + } + try!(fs::copy(&src, path.as_ref()).map_err(|e| DownloadError::File(e))); + + if let Some(ref mut h) = *hasher { + let ref mut f = try!(fs::File::open(path.as_ref()).map_err(|e| DownloadError::File(e))); + + let ref mut buffer = vec![0u8; 0x10000]; + loop { + let bytes_read = try!(io::Read::read(f, buffer).map_err(|e| DownloadError::File(e))); + if bytes_read == 0 { break } + try!(io::Write::write_all(*h, &buffer[0..bytes_read]).map_err(|e| DownloadError::File(e))); + } + } + + Ok(true) + } else { + Ok(false) + } +} + pub fn symlink_dir(src: &Path, dest: &Path) -> io::Result<()> { #[cfg(windows)] fn symlink_dir_inner(src: &Path, dest: &Path) -> io::Result<()> { From 650b3a56f0538c12e2683a3e5743635e7f5d2b0d Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 5 May 2016 23:37:26 +0000 Subject: [PATCH 06/14] Remove DownloadError in favor of Error --- src/rustup-utils/src/errors.rs | 4 ++ src/rustup-utils/src/raw.rs | 86 ++++++++++------------------------ src/rustup-utils/src/utils.rs | 2 +- 3 files changed, 30 insertions(+), 62 deletions(-) diff --git a/src/rustup-utils/src/errors.rs b/src/rustup-utils/src/errors.rs index 8f22f110c1..1c54032e63 100644 --- a/src/rustup-utils/src/errors.rs +++ b/src/rustup-utils/src/errors.rs @@ -67,6 +67,10 @@ error_chain! { description("could not rename directory") display("could not rename {} directory from '{}' to '{}'", name, src.display(), dest.display()) } + HttpStatus(e: hyper::status::StatusCode) { + description("http request returned an unsuccessful status code") + display("http request returned an unsuccessful status code: {}", e) + } DownloadingFile { url: hyper::Url, path: PathBuf, diff --git a/src/rustup-utils/src/raw.rs b/src/rustup-utils/src/raw.rs index 6bc2a7e27d..50d82427e8 100644 --- a/src/rustup-utils/src/raw.rs +++ b/src/rustup-utils/src/raw.rs @@ -5,7 +5,7 @@ use std::fs; use std::path::Path; use std::io; use std::char::from_u32; -use std::io::{Write, ErrorKind}; +use std::io::Write; use std::process::{Command, Stdio, ExitStatus}; use std::ffi::{OsStr, OsString}; use std::fmt; @@ -13,6 +13,7 @@ use std::thread; use std::time::Duration; use hyper::{self, Client}; use openssl::crypto::hash::Hasher; +use errors::*; use rand::random; @@ -151,53 +152,11 @@ pub fn tee_file(path: &Path, mut w: &mut W) -> io::Result<()> { } } -#[derive(Debug)] -pub enum DownloadError { - Status(hyper::status::StatusCode), - Network(hyper::Error), - File(io::Error), - FilePathParse, -} -pub type DownloadResult = Result; - -impl error::Error for DownloadError { - fn description(&self) -> &str { - use self::DownloadError::*; - match *self { - Status(_) => "unsuccessful HTTP status", - Network(_) => "network error", - File(_) => "error writing file", - FilePathParse => "failed to parse URL as file path", - } - } - - fn cause(&self) -> Option<&error::Error> { - use self::DownloadError::*; - match *self { - Network(ref e) => Some(e), - File(ref e) => Some(e), - Status(_) | - FilePathParse => None, - } - } -} - -impl fmt::Display for DownloadError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match *self { - DownloadError::Status(ref s) => write!(f, "Status: {}", s), - DownloadError::Network(ref e) => write!(f, "Network: {}", e), - DownloadError::File(ref e) => write!(f, "File: {}", e), - DownloadError::FilePathParse => write!(f, "failed to parse URL as file path"), - } - } -} - pub fn download_file>(url: hyper::Url, path: P, mut hasher: Option<&mut Hasher>, notify_handler: NotifyHandler) - -> DownloadResult<()> { + -> Result<()> { if try!(download_from_file_url(&url, &path, &mut hasher)) { return Ok(()); @@ -208,15 +167,17 @@ pub fn download_file>(url: hyper::Url, let client = Client::new(); - let mut res = try!(client.get(url).send().map_err(DownloadError::Network)); + let mut res = try!(client.get(url).send() + .chain_err(|| "failed to make network request")); if res.status != hyper::Ok { - return Err(DownloadError::Status(res.status)); + return Err(ErrorKind::HttpStatus(res.status).into()); } let buffer_size = 0x10000; let mut buffer = vec![0u8; buffer_size]; - let mut file = try!(fs::File::create(&path).map_err(DownloadError::File)); + let mut file = try!(fs::File::create(&path).chain_err( + || "error creating file for download")); if let Some(len) = res.headers.get::().cloned() { notify_handler.call(Notification::DownloadContentLengthReceived(len.0)); @@ -224,19 +185,18 @@ pub fn download_file>(url: hyper::Url, loop { let bytes_read = try!(io::Read::read(&mut res, &mut buffer) - .map_err(hyper::Error::Io) - .map_err(DownloadError::Network)); + .chain_err(|| "error reading from socket")); if bytes_read != 0 { if let Some(ref mut h) = hasher { try!(io::Write::write_all(*h, &mut buffer[0..bytes_read]) - .map_err(DownloadError::File)); + .chain_err(|| "unable to hash download")); } try!(io::Write::write_all(&mut file, &mut buffer[0..bytes_read]) - .map_err(DownloadError::File)); + .chain_err(|| "unable to write download to disk")); notify_handler.call(Notification::DownloadDataReceived(bytes_read)); } else { - try!(file.sync_data().map_err(DownloadError::File)); + try!(file.sync_data().chain_err(|| "unable to sync download to disk")); notify_handler.call(Notification::DownloadFinished); return Ok(()); } @@ -246,27 +206,31 @@ pub fn download_file>(url: hyper::Url, fn download_from_file_url>(url: &hyper::Url, path: P, hasher: &mut Option<&mut Hasher>) - -> DownloadResult { + -> Result { // The file scheme is mostly for use by tests to mock the dist server if url.scheme() == "file" { - let src = try!(url.to_file_path().map_err(|_| DownloadError::FilePathParse)); + let src = try!(url.to_file_path() + .map_err(|_| Error::from(format!("bogus file url: '{}'", url)))); if !is_file(&src) { // Because some of multirust's logic depends on checking // the error when a downloaded file doesn't exist, make // the file case return the same error value as the // network case. - return Err(DownloadError::Status(hyper::status::StatusCode::NotFound)); + return Err(ErrorKind::HttpStatus(hyper::status::StatusCode::NotFound).into()); } - try!(fs::copy(&src, path.as_ref()).map_err(|e| DownloadError::File(e))); + try!(fs::copy(&src, path.as_ref()).chain_err(|| "failure copying file")); if let Some(ref mut h) = *hasher { - let ref mut f = try!(fs::File::open(path.as_ref()).map_err(|e| DownloadError::File(e))); + let ref mut f = try!(fs::File::open(path.as_ref()) + .chain_err(|| "unable to open downloaded file")); let ref mut buffer = vec![0u8; 0x10000]; loop { - let bytes_read = try!(io::Read::read(f, buffer).map_err(|e| DownloadError::File(e))); + let bytes_read = try!(io::Read::read(f, buffer) + .chain_err(|| "unable to read downloaded file")); if bytes_read == 0 { break } - try!(io::Write::write_all(*h, &buffer[0..bytes_read]).map_err(|e| DownloadError::File(e))); + try!(io::Write::write_all(*h, &buffer[0..bytes_read]) + .chain_err(|| "unable to write to hasher")); } } @@ -395,7 +359,7 @@ pub enum CommandError { Status(ExitStatus), } -pub type CommandResult = Result; +pub type CommandResult = ::std::result::Result; impl error::Error for CommandError { fn description(&self) -> &str { @@ -477,7 +441,7 @@ fn rm_rf(path: &Path) -> io::Result<()> { match fs::remove_file(file) { Ok(()) => {} Err(ref e) if cfg!(windows) && - e.kind() == ErrorKind::PermissionDenied => { + e.kind() == io::ErrorKind::PermissionDenied => { let mut p = file.metadata().unwrap().permissions(); p.set_readonly(false); fs::set_permissions(file, p).unwrap(); diff --git a/src/rustup-utils/src/utils.rs b/src/rustup-utils/src/utils.rs index 5acf4f96ff..45264f6904 100644 --- a/src/rustup-utils/src/utils.rs +++ b/src/rustup-utils/src/utils.rs @@ -149,7 +149,7 @@ pub fn download_file(url: hyper::Url, notify_handler.call(Notification::DownloadingFile(&url, path)); match raw::download_file(url.clone(), path, hasher, notify_handler) { Ok(_) => Ok(()), - Err(e @ raw::DownloadError::Status(NotFound)) => { + Err(e @ Error(ErrorKind::HttpStatus(NotFound), _)) => { Err(e).chain_err(|| ErrorKind::Download404 { url: url, path: path.to_path_buf(), From 5df063a38d2156a4b36eb17773a1b920a1314da1 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 6 May 2016 00:21:19 +0000 Subject: [PATCH 07/14] Use native-tls for TLS This makes hyper use the platform TLS on Windows and OS X, and adds hostname validation on all platforms. --- Cargo.lock | 95 +++++++++++++++++++++++++++++++++++-- Cargo.toml | 2 +- src/rustup-dist/Cargo.toml | 2 +- src/rustup-mock/Cargo.toml | 2 +- src/rustup-utils/Cargo.toml | 7 ++- src/rustup-utils/src/lib.rs | 1 + src/rustup-utils/src/raw.rs | 74 ++++++++++++++++++++++++++++- 7 files changed, 173 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fc4d41029c..70bf7c9bb1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -117,6 +117,32 @@ dependencies = [ "url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "core-foundation" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "core-foundation-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "core-foundation-sys" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crypt32-sys" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "dbghelp-sys" version = "0.2.0" @@ -178,7 +204,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "hyper" -version = "0.9.2" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cookie 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -302,6 +328,17 @@ dependencies = [ "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "native-tls" +version = "0.1.0" +source = "git+https://github.com/sfackler/rust-native-tls.git#2bd06d4686a31d46f83f243a6b10650ac013ffa0" +dependencies = [ + "openssl 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-verify 0.1.0 (git+https://github.com/sfackler/rust-openssl-verify)", + "schannel 0.0.2 (git+https://github.com/sfackler/schannel-rs)", + "security-framework 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "num_cpus" version = "0.2.11" @@ -354,6 +391,14 @@ dependencies = [ "openssl-sys 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "openssl-verify" +version = "0.1.0" +source = "git+https://github.com/sfackler/rust-openssl-verify#6fd9fd9209749361079e627eab69d2edb8cb3dec" +dependencies = [ + "openssl 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "pkg-config" version = "0.3.8" @@ -429,7 +474,7 @@ name = "rustup-mock" version = "0.1.9" dependencies = [ "flate2 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", - "hyper 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", "openssl 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", @@ -448,9 +493,10 @@ version = "0.1.9" dependencies = [ "advapi32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "error-chain 0.1.9", - "hyper 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "native-tls 0.1.0 (git+https://github.com/sfackler/rust-native-tls.git)", "ole32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "openssl 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", @@ -461,11 +507,52 @@ dependencies = [ "winreg 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "schannel" +version = "0.0.2" +source = "git+https://github.com/sfackler/schannel-rs#47720eec165456b7fb77684555db6bbb16eb0de6" +dependencies = [ + "crypt32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "secur32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "scopeguard" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "secur32-sys" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "security-framework" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "core-foundation 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "core-foundation-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "security-framework-sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "security-framework-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "core-foundation-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "semver" version = "0.1.20" diff --git a/Cargo.toml b/Cargo.toml index c8967bafe1..a3688dd338 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ rustup-utils = { path = "src/rustup-utils", version = "0.1.9" } error-chain = { path = "src/error-chain", version = "0.1.9" } clap = "2.2.4" regex = "0.1.41" -openssl = "0.7.2" +openssl = "0.7.11" url = "1.1.0" term = "0.4.4" itertools = "0.4.1" diff --git a/src/rustup-dist/Cargo.toml b/src/rustup-dist/Cargo.toml index 3e8b62d581..57a51524d0 100644 --- a/src/rustup-dist/Cargo.toml +++ b/src/rustup-dist/Cargo.toml @@ -14,7 +14,7 @@ license = "MIT OR Apache-2.0" [dependencies] regex = "0.1.41" -openssl = "0.7.2" +openssl = "0.7.11" itertools = "0.4.1" ole32-sys = "0.2.0" url = "1.1.0" diff --git a/src/rustup-mock/Cargo.toml b/src/rustup-mock/Cargo.toml index 79b1a14925..7fa8365645 100644 --- a/src/rustup-mock/Cargo.toml +++ b/src/rustup-mock/Cargo.toml @@ -16,7 +16,7 @@ lazy_static = "0.1.15" walkdir = "0.1.5" flate2 = "0.2.9" tempdir = "0.3.4" -openssl = "0.7.2" +openssl = "0.7.11" itertools = "0.4.1" tar = "0.4.0" toml = "0.1.27" diff --git a/src/rustup-utils/Cargo.toml b/src/rustup-utils/Cargo.toml index b8997e4799..30dabbf5fd 100644 --- a/src/rustup-utils/Cargo.toml +++ b/src/rustup-utils/Cargo.toml @@ -12,12 +12,12 @@ repository = "https://github.com/rust-lang-nursery/rustup.rs" license = "MIT OR Apache-2.0" [dependencies] -openssl = "0.7.2" -hyper = "0.9.2" +openssl = "0.7.11" rand = "0.3.11" scopeguard = "0.1.2" error-chain = { path = "../error-chain", version = "0.1.9" } libc = "0.2.0" +native-tls = { git = "https://github.com/sfackler/rust-native-tls.git" } [target."cfg(windows)".dependencies] winapi = "0.2.4" @@ -28,3 +28,6 @@ kernel32-sys = "0.2.1" advapi32-sys = "0.2.0" userenv-sys = "0.2.0" +[dependencies.hyper] +version = "0.9.2" +default-features = false diff --git a/src/rustup-utils/src/lib.rs b/src/rustup-utils/src/lib.rs index 066cc43004..e595eff3d7 100644 --- a/src/rustup-utils/src/lib.rs +++ b/src/rustup-utils/src/lib.rs @@ -8,6 +8,7 @@ extern crate rand; extern crate scopeguard; #[macro_use] extern crate error_chain; +extern crate native_tls; #[cfg(windows)] extern crate winapi; diff --git a/src/rustup-utils/src/raw.rs b/src/rustup-utils/src/raw.rs index 50d82427e8..6f48e755ff 100644 --- a/src/rustup-utils/src/raw.rs +++ b/src/rustup-utils/src/raw.rs @@ -158,14 +158,86 @@ pub fn download_file>(url: hyper::Url, notify_handler: NotifyHandler) -> Result<()> { + // Short-circuit hyper for the "file:" URL scheme if try!(download_from_file_url(&url, &path, &mut hasher)) { return Ok(()); } + use hyper::error::Result as HyperResult; use hyper::header::ContentLength; + use hyper::net::{SslClient, NetworkStream, HttpsConnector}; + use native_tls; use notifications::Notification; + use std::io::Result as IoResult; + use std::io::{Read, Write}; + use std::net::{SocketAddr}; + use std::sync::{Arc, Mutex}; + + // This is just a defensive measure to make sure I'm not sending + // anything through hyper I haven't tested. + if url.scheme() != "https" { + return Err(format!("unsupported URL scheme: '{}'", url.scheme()).into()); + } + + // All the following is adapter code to use native_tls with hyper. + + struct NativeSslClient; + + impl SslClient for NativeSslClient { + type Stream = NativeSslStream; + + fn wrap_client(&self, stream: T, host: &str) -> HyperResult { + use native_tls::ClientBuilder as TlsClientBuilder; + use hyper::error::Error as HyperError; + + let mut ssl_builder = try!(TlsClientBuilder::new() + .map_err(|e| HyperError::Ssl(Box::new(e)))); + let ssl_stream = try!(ssl_builder.handshake(host, stream) + .map_err(|e| HyperError::Ssl(Box::new(e)))); + + Ok(NativeSslStream(Arc::new(Mutex::new(ssl_stream)))) + } + } + + #[derive(Clone)] + struct NativeSslStream(Arc>>); + + impl NetworkStream for NativeSslStream + where T: NetworkStream + { + fn peer_addr(&mut self) -> IoResult { + self.0.lock().expect("").get_mut().peer_addr() + } + fn set_read_timeout(&self, dur: Option) -> IoResult<()> { + self.0.lock().expect("").get_ref().set_read_timeout(dur) + } + fn set_write_timeout(&self, dur: Option) -> IoResult<()> { + self.0.lock().expect("").get_ref().set_read_timeout(dur) + } + } + + impl Read for NativeSslStream + where T: Read + Write + { + fn read(&mut self, buf: &mut [u8]) -> IoResult { + self.0.lock().expect("").read(buf) + } + } + + impl Write for NativeSslStream + where T: Read + Write + { + fn write(&mut self, buf: &[u8]) -> IoResult { + self.0.lock().expect("").write(buf) + } + fn flush(&mut self) -> IoResult<()> { + self.0.lock().expect("").flush() + } + } + + // Connect with hyper + native_tls - let client = Client::new(); + let client = Client::with_connector(HttpsConnector::new(NativeSslClient)); let mut res = try!(client.get(url).send() .chain_err(|| "failed to make network request")); From cb60dff8d33475e76fdfc9271cb4afb38bce6a00 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 6 May 2016 01:28:40 +0000 Subject: [PATCH 08/14] Remove openssl dependency --- Cargo.lock | 25 ++++++++++++++++++---- Cargo.toml | 2 +- src/rustup-cli/main.rs | 2 +- src/rustup-cli/self_update.rs | 31 ++++++++++++++++------------ src/rustup-dist/Cargo.toml | 2 +- src/rustup-dist/src/dist.rs | 10 ++++----- src/rustup-dist/src/download.rs | 11 ++++------ src/rustup-dist/src/lib.rs | 2 +- src/rustup-dist/src/manifestation.rs | 10 ++++----- src/rustup-dist/tests/dist.rs | 1 - src/rustup-mock/Cargo.toml | 2 +- src/rustup-mock/src/dist.rs | 9 ++++---- src/rustup-mock/src/lib.rs | 2 +- src/rustup-utils/Cargo.toml | 2 +- src/rustup-utils/src/lib.rs | 2 +- src/rustup-utils/src/raw.rs | 13 ++++++------ src/rustup-utils/src/utils.rs | 4 ++-- 17 files changed, 72 insertions(+), 58 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 70bf7c9bb1..692ac60dbc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,9 +8,9 @@ dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.1.69 (registry+https://github.com/rust-lang/crates.io-index)", + "rust-crypto 0.2.35 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "rustup-dist 0.1.9", "rustup-mock 0.1.9", @@ -280,6 +280,11 @@ name = "lazy_static" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "libc" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "libc" version = "0.2.11" @@ -437,6 +442,18 @@ name = "regex-syntax" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "rust-crypto" +version = "0.2.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "gcc 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rustc-serialize" version = "0.3.19" @@ -458,8 +475,8 @@ dependencies = [ "flate2 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)", "ole32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.1.69 (registry+https://github.com/rust-lang/crates.io-index)", + "rust-crypto 0.2.35 (registry+https://github.com/rust-lang/crates.io-index)", "rustup-mock 0.1.9", "rustup-utils 0.1.9", "tar 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -477,7 +494,7 @@ dependencies = [ "hyper 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", + "rust-crypto 0.2.35 (registry+https://github.com/rust-lang/crates.io-index)", "scopeguard 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "tar 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "tempdir 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -498,8 +515,8 @@ dependencies = [ "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "native-tls 0.1.0 (git+https://github.com/sfackler/rust-native-tls.git)", "ole32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "rust-crypto 0.2.35 (registry+https://github.com/rust-lang/crates.io-index)", "scopeguard 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "shell32-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "userenv-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index a3688dd338..b70b8827b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ rustup-utils = { path = "src/rustup-utils", version = "0.1.9" } error-chain = { path = "src/error-chain", version = "0.1.9" } clap = "2.2.4" regex = "0.1.41" -openssl = "0.7.11" +rust-crypto = "0.2.35" url = "1.1.0" term = "0.4.4" itertools = "0.4.1" diff --git a/src/rustup-cli/main.rs b/src/rustup-cli/main.rs index 0208113efa..871940c602 100644 --- a/src/rustup-cli/main.rs +++ b/src/rustup-cli/main.rs @@ -12,7 +12,7 @@ extern crate regex; #[macro_use] extern crate rustup; extern crate term; -extern crate openssl; +extern crate crypto; extern crate itertools; extern crate time; extern crate rand; diff --git a/src/rustup-cli/self_update.rs b/src/rustup-cli/self_update.rs index 953ee3f222..8abccb98c2 100644 --- a/src/rustup-cli/self_update.rs +++ b/src/rustup-cli/self_update.rs @@ -36,12 +36,14 @@ use rustup::{NotifyHandler}; use errors::*; use rustup_dist::dist; use rustup_utils::utils; -use openssl::crypto::hash::{Type, Hasher}; +use crypto::sha2::Sha256; +use crypto::digest::Digest; use std::env; use std::env::consts::EXE_SUFFIX; use std::path::{Path, PathBuf}; use std::process::{self, Command}; -use std::fs; +use std::fs::{self, File}; +use std::io::Read; use tempdir::TempDir; pub struct InstallOpts { @@ -1038,12 +1040,18 @@ pub fn prepare_update() -> Result> { let url = format!("{}/{}/rustup-init{}", update_root, triple, EXE_SUFFIX); // Calculate own hash - let mut hasher = Hasher::new(Type::SHA256); - try!(utils::tee_file("self", multirust_path, &mut hasher)); - let current_hash = hasher.finish() - .iter() - .map(|b| format!("{:02x}", b)) - .join(""); + let mut hasher = Sha256::new(); + let mut self_exe = try!(File::open(multirust_path) + .chain_err(|| "can't open self exe to calculate hash")); + let ref mut buf = [0; 4096]; + loop { + let bytes = try!(self_exe.read(buf) + .chain_err(|| "failed to read from self exe while calculating hash")); + if bytes == 0 { break; } + hasher.input(&buf[0..bytes]); + } + let current_hash = hasher.result_str(); + drop(self_exe); // Download latest hash info!("checking for self-updates"); @@ -1064,15 +1072,12 @@ pub fn prepare_update() -> Result> { // Download new version info!("downloading self-update"); - let mut hasher = Hasher::new(Type::SHA256); + let mut hasher = Sha256::new(); try!(utils::download_file(download_url, &setup_path, Some(&mut hasher), ntfy!(&NotifyHandler::none()))); - let download_hash = hasher.finish() - .iter() - .map(|b| format!("{:02x}", b)) - .join(""); + let download_hash = hasher.result_str(); // Check that hash is correct if latest_hash != download_hash { diff --git a/src/rustup-dist/Cargo.toml b/src/rustup-dist/Cargo.toml index 57a51524d0..5c88fdac52 100644 --- a/src/rustup-dist/Cargo.toml +++ b/src/rustup-dist/Cargo.toml @@ -14,7 +14,7 @@ license = "MIT OR Apache-2.0" [dependencies] regex = "0.1.41" -openssl = "0.7.11" +rust-crypto = "0.2.35" itertools = "0.4.1" ole32-sys = "0.2.0" url = "1.1.0" diff --git a/src/rustup-dist/src/dist.rs b/src/rustup-dist/src/dist.rs index 94f6060cc5..580687db00 100644 --- a/src/rustup-dist/src/dist.rs +++ b/src/rustup-dist/src/dist.rs @@ -12,7 +12,8 @@ use std::path::Path; use std::fmt; use regex::Regex; -use openssl::crypto::hash::{Type, Hasher}; +use crypto::sha2::Sha256; +use crypto::digest::Digest; use itertools::Itertools; pub const DEFAULT_DIST_ROOT: &'static str = "https://static.rust-lang.org/dist"; @@ -341,12 +342,9 @@ pub fn download_and_check<'a>(url_str: &str, let url = try!(utils::parse_url(url_str)); let file = try!(cfg.temp_cfg.new_file_with_ext("", ext)); - let mut hasher = Hasher::new(Type::SHA256); + let mut hasher = Sha256::new(); try!(utils::download_file(url, &file, Some(&mut hasher), ntfy!(&cfg.notify_handler))); - let actual_hash = hasher.finish() - .iter() - .map(|b| format!("{:02x}", b)) - .join(""); + let actual_hash = hasher.result_str(); if hash != actual_hash { // Incorrect hash diff --git a/src/rustup-dist/src/download.rs b/src/rustup-dist/src/download.rs index 31bd0c142b..bbcbe2ad76 100644 --- a/src/rustup-dist/src/download.rs +++ b/src/rustup-dist/src/download.rs @@ -3,8 +3,8 @@ use notifications::*; use rustup_utils::utils; use temp; -use openssl::crypto::hash::{Type, Hasher}; -use itertools::Itertools; +use crypto::sha2::Sha256; +use crypto::digest::Digest; use std::path::Path; use std::process::Command; @@ -66,7 +66,7 @@ impl<'a> DownloadCfg<'a> { try!(utils::download_file(hash_url, &hash_file, None, ntfy!(&self.notify_handler))); let hash = try!(utils::read_file("hash", &hash_file).map(|s| s[0..64].to_owned())); - let mut hasher = Hasher::new(Type::SHA256); + let mut hasher = Sha256::new(); let target_url = try!(utils::parse_url(url)); let target_file = try!(self.temp_cfg.new_file()); @@ -75,10 +75,7 @@ impl<'a> DownloadCfg<'a> { Some(&mut hasher), ntfy!(&self.notify_handler))); - let actual_hash = hasher.finish() - .iter() - .map(|b| format!("{:02x}", b)) - .join(""); + let actual_hash = hasher.result_str(); if hash != actual_hash { // Incorrect hash diff --git a/src/rustup-dist/src/lib.rs b/src/rustup-dist/src/lib.rs index 86edc6ba7e..b3eeb9d237 100644 --- a/src/rustup-dist/src/lib.rs +++ b/src/rustup-dist/src/lib.rs @@ -1,7 +1,7 @@ #![recursion_limit = "1024"] extern crate regex; -extern crate openssl; +extern crate crypto; extern crate itertools; extern crate tempdir; extern crate walkdir; diff --git a/src/rustup-dist/src/manifestation.rs b/src/rustup-dist/src/manifestation.rs index 7c9ca49d9f..e32b5efe49 100644 --- a/src/rustup-dist/src/manifestation.rs +++ b/src/rustup-dist/src/manifestation.rs @@ -10,7 +10,8 @@ use errors::*; use notifications::*; use rustup_utils::utils; use prefix::InstallPrefix; -use openssl::crypto::hash::{Type, Hasher}; +use crypto::sha2::Sha256; +use crypto::digest::Digest; use itertools::Itertools; use std::path::Path; @@ -135,14 +136,11 @@ impl Manifestation { let temp_file = try!(temp_cfg.new_file()); let url_url = try!(utils::parse_url(&url)); - let mut hasher = Hasher::new(Type::SHA256); + let mut hasher = Sha256::new(); try!(utils::download_file(url_url, &temp_file, Some(&mut hasher), ntfy!(¬ify_handler)) .chain_err(|| ErrorKind::ComponentDownloadFailed(component.clone()))); - let actual_hash = hasher.finish() - .iter() - .map(|b| format!("{:02x}", b)) - .join(""); + let actual_hash = hasher.result_str(); if hash != actual_hash { // Incorrect hash diff --git a/src/rustup-dist/tests/dist.rs b/src/rustup-dist/tests/dist.rs index 8d3b584a19..16b60b69d4 100644 --- a/src/rustup-dist/tests/dist.rs +++ b/src/rustup-dist/tests/dist.rs @@ -6,7 +6,6 @@ extern crate rustup_utils; extern crate rustup_mock; extern crate tempdir; extern crate tar; -extern crate openssl; extern crate toml; extern crate flate2; extern crate walkdir; diff --git a/src/rustup-mock/Cargo.toml b/src/rustup-mock/Cargo.toml index 7fa8365645..2611bacf75 100644 --- a/src/rustup-mock/Cargo.toml +++ b/src/rustup-mock/Cargo.toml @@ -16,7 +16,7 @@ lazy_static = "0.1.15" walkdir = "0.1.5" flate2 = "0.2.9" tempdir = "0.3.4" -openssl = "0.7.11" +rust-crypto = "0.2.35" itertools = "0.4.1" tar = "0.4.0" toml = "0.1.27" diff --git a/src/rustup-mock/src/dist.rs b/src/rustup-mock/src/dist.rs index b30dc62fa2..7ce6f80b4e 100644 --- a/src/rustup-mock/src/dist.rs +++ b/src/rustup-mock/src/dist.rs @@ -8,7 +8,8 @@ use std::fs::{self, File}; use std::collections::HashMap; use std::io::{Read, Write}; use tempdir::TempDir; -use openssl::crypto::hash; +use crypto::sha2::Sha256; +use crypto::digest::Digest; use itertools::Itertools; use toml; use flate2; @@ -304,9 +305,9 @@ fn create_tarball(relpath: &Path, src: &Path, dst: &Path) { pub fn calc_hash(src: &Path) -> String { let ref mut buf = Vec::new(); File::open(src).unwrap().read_to_end(buf).unwrap(); - let mut hasher = hash::Hasher::new(hash::Type::SHA256); - hasher.write_all(&buf).unwrap(); - let hex = hasher.finish().iter().map(|b| format!("{:02x}", b)).join(""); + let mut hasher = Sha256::new(); + hasher.input(buf); + let hex = hasher.result_str(); hex } diff --git a/src/rustup-mock/src/lib.rs b/src/rustup-mock/src/lib.rs index 27d8ac0489..a6d9d2a564 100644 --- a/src/rustup-mock/src/lib.rs +++ b/src/rustup-mock/src/lib.rs @@ -7,7 +7,7 @@ extern crate scopeguard; extern crate walkdir; extern crate flate2; extern crate tempdir; -extern crate openssl; +extern crate crypto; extern crate itertools; extern crate tar; extern crate toml; diff --git a/src/rustup-utils/Cargo.toml b/src/rustup-utils/Cargo.toml index 30dabbf5fd..00ada297c8 100644 --- a/src/rustup-utils/Cargo.toml +++ b/src/rustup-utils/Cargo.toml @@ -12,7 +12,7 @@ repository = "https://github.com/rust-lang-nursery/rustup.rs" license = "MIT OR Apache-2.0" [dependencies] -openssl = "0.7.11" +rust-crypto = "0.2.35" rand = "0.3.11" scopeguard = "0.1.2" error-chain = { path = "../error-chain", version = "0.1.9" } diff --git a/src/rustup-utils/src/lib.rs b/src/rustup-utils/src/lib.rs index e595eff3d7..1f28aef510 100644 --- a/src/rustup-utils/src/lib.rs +++ b/src/rustup-utils/src/lib.rs @@ -3,7 +3,7 @@ #![recursion_limit = "1024"] // for error_chain! extern crate hyper; -extern crate openssl; +extern crate crypto; extern crate rand; extern crate scopeguard; #[macro_use] diff --git a/src/rustup-utils/src/raw.rs b/src/rustup-utils/src/raw.rs index 6f48e755ff..f38f79f6b1 100644 --- a/src/rustup-utils/src/raw.rs +++ b/src/rustup-utils/src/raw.rs @@ -12,7 +12,8 @@ use std::fmt; use std::thread; use std::time::Duration; use hyper::{self, Client}; -use openssl::crypto::hash::Hasher; +use crypto::sha2::Sha256; +use crypto::digest::Digest; use errors::*; use rand::random; @@ -154,7 +155,7 @@ pub fn tee_file(path: &Path, mut w: &mut W) -> io::Result<()> { pub fn download_file>(url: hyper::Url, path: P, - mut hasher: Option<&mut Hasher>, + mut hasher: Option<&mut Sha256>, notify_handler: NotifyHandler) -> Result<()> { @@ -261,8 +262,7 @@ pub fn download_file>(url: hyper::Url, if bytes_read != 0 { if let Some(ref mut h) = hasher { - try!(io::Write::write_all(*h, &mut buffer[0..bytes_read]) - .chain_err(|| "unable to hash download")); + h.input(&buffer[0..bytes_read]); } try!(io::Write::write_all(&mut file, &mut buffer[0..bytes_read]) .chain_err(|| "unable to write download to disk")); @@ -277,7 +277,7 @@ pub fn download_file>(url: hyper::Url, fn download_from_file_url>(url: &hyper::Url, path: P, - hasher: &mut Option<&mut Hasher>) + hasher: &mut Option<&mut Sha256>) -> Result { // The file scheme is mostly for use by tests to mock the dist server if url.scheme() == "file" { @@ -301,8 +301,7 @@ fn download_from_file_url>(url: &hyper::Url, let bytes_read = try!(io::Read::read(f, buffer) .chain_err(|| "unable to read downloaded file")); if bytes_read == 0 { break } - try!(io::Write::write_all(*h, &buffer[0..bytes_read]) - .chain_err(|| "unable to write to hasher")); + h.input(&buffer[0..bytes_read]); } } diff --git a/src/rustup-utils/src/utils.rs b/src/rustup-utils/src/utils.rs index 45264f6904..cc2ce0f6ac 100644 --- a/src/rustup-utils/src/utils.rs +++ b/src/rustup-utils/src/utils.rs @@ -6,7 +6,7 @@ use std::process::Command; use std::ffi::OsString; use std::env; use hyper; -use openssl::crypto::hash::Hasher; +use crypto::sha2::Sha256; use notify::Notifyable; use notifications::{Notification, NotifyHandler}; use raw; @@ -141,7 +141,7 @@ pub fn tee_file(name: &'static str, path: &Path, w: &mut W) -> Res pub fn download_file(url: hyper::Url, path: &Path, - hasher: Option<&mut Hasher>, + hasher: Option<&mut Sha256>, notify_handler: NotifyHandler) -> Result<()> { use hyper::status::StatusCode::NotFound; From a8118ed272a2b9d30235cf6623f856cca053008c Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 3 May 2016 22:10:24 +0000 Subject: [PATCH 09/14] Upgrade OpenSSL on Unix --- ci/run-docker.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/run-docker.sh b/ci/run-docker.sh index 66fe17894c..976a39f8a5 100644 --- a/ci/run-docker.sh +++ b/ci/run-docker.sh @@ -18,8 +18,8 @@ export LD_LIBRARY_PATH=/travis-rust/lib:$LD_LIBRARY_PATH # distribute (this can be changed by others of course). # ============================================================================== -OPENSSL_VERS=1.0.2g -OPENSSL_SHA256=b784b1b3907ce39abf4098702dade6365522a253ad1552e267a9a0e89594aa33 +OPENSSL_VERS=1.0.2h +OPENSSL_SHA256=1d4007e53aad94a5b2002fe045ee7bb0b3d98f1a47f8b2bc851dcd1c74332919 case $TARGET in x86_64-*-linux-*) From 04a3be7a64a2a01adb28128189fbbe54fbc564ee Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 6 May 2016 02:11:29 +0000 Subject: [PATCH 10/14] Windows builds don't need OpenSSL --- appveyor.yml | 9 --------- ci/appveyor-cargo-config.toml | 19 ------------------- 2 files changed, 28 deletions(-) delete mode 100644 ci/appveyor-cargo-config.toml diff --git a/appveyor.yml b/appveyor.yml index 295c91a69b..154087f3be 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -21,20 +21,11 @@ install: .\rust-nightly.exe /VERYSILENT /NORESTART /DIR="C:\rust" | Out-Null $env:PATH="$env:PATH;C:\rust\bin" - New-Item .cargo -type directory - Copy-Item ci/appveyor-cargo-config.toml .cargo/config - # For -gnu builds if ($env:TARGET -match "-gnu$") { $env:PATH="$env:PATH;C:\msys64\mingw${env:BITS}\bin" } - # For -msvc builds - if ($env:TARGET -match "-msvc$") { - Start-FileDownload "http://www.npcglib.org/~stathis/downloads/openssl-1.0.2d-vs2015.7z" -FileName "openssl.7z" - 7z x openssl.7z -o"C:\OpenSSL" | Out-Null - } - # Print version info rustc -vV cargo -vV diff --git a/ci/appveyor-cargo-config.toml b/ci/appveyor-cargo-config.toml deleted file mode 100644 index 511cb481d5..0000000000 --- a/ci/appveyor-cargo-config.toml +++ /dev/null @@ -1,19 +0,0 @@ -[target.x86_64-pc-windows-msvc.openssl] -rustc-link-search = ['native=C:\OpenSSL\openssl-1.0.2d-vs2015\lib64'] -rustc-link-lib = ['static=ssleay32MT', 'static=libeay32MT', 'gdi32', 'user32'] -include = 'C:\OpenSSL\openssl-1.0.2d-vs2015\include' - -[target.i686-pc-windows-msvc.openssl] -rustc-link-search = ['native=C:\OpenSSL\openssl-1.0.2d-vs2015\lib'] -rustc-link-lib = ['static=ssleay32MT', 'static=libeay32MT', 'gdi32', 'user32'] -include = 'C:\OpenSSL\openssl-1.0.2d-vs2015\include' - -[target.x86_64-pc-windows-gnu.openssl] -rustc-link-search = ['native=C:\msys64\mingw64\lib'] -rustc-link-lib = ['static=ssl', 'static=crypto', 'gdi32', 'user32'] -include = 'C:\msys64\mingw64\include' - -[target.i686-pc-windows-gnu.openssl] -rustc-link-search = ['native=C:\msys64\mingw32\lib'] -rustc-link-lib = ['static=ssl', 'static=crypto', 'gdi32', 'user32'] -include = 'C:\msys64\mingw32\include' From 5e3ee9afcc50d101583b9d4694ff6229a86740f2 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 6 May 2016 03:30:19 +0000 Subject: [PATCH 11/14] Replace rust-crypto with a copy of rustc's SHA-256 --- Cargo.lock | 23 +- Cargo.toml | 1 - src/rustup-cli/main.rs | 1 - src/rustup-cli/self_update.rs | 3 +- src/rustup-dist/Cargo.toml | 1 - src/rustup-dist/src/dist.rs | 3 +- src/rustup-dist/src/download.rs | 3 +- src/rustup-dist/src/lib.rs | 1 - src/rustup-dist/src/manifestation.rs | 3 +- src/rustup-mock/Cargo.toml | 2 +- src/rustup-mock/src/dist.rs | 3 +- src/rustup-mock/src/lib.rs | 2 +- src/rustup-utils/Cargo.toml | 2 +- src/rustup-utils/src/lib.rs | 4 +- src/rustup-utils/src/raw.rs | 3 +- src/rustup-utils/src/sha2.rs | 682 +++++++++++++++++++++++++++ src/rustup-utils/src/utils.rs | 2 +- 17 files changed, 697 insertions(+), 42 deletions(-) create mode 100644 src/rustup-utils/src/sha2.rs diff --git a/Cargo.lock b/Cargo.lock index 692ac60dbc..e2049f65bc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,7 +10,6 @@ dependencies = [ "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.1.69 (registry+https://github.com/rust-lang/crates.io-index)", - "rust-crypto 0.2.35 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "rustup-dist 0.1.9", "rustup-mock 0.1.9", @@ -280,11 +279,6 @@ name = "lazy_static" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "libc" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "libc" version = "0.2.11" @@ -442,18 +436,6 @@ name = "regex-syntax" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "rust-crypto" -version = "0.2.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "gcc 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "rustc-serialize" version = "0.3.19" @@ -476,7 +458,6 @@ dependencies = [ "itertools 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)", "ole32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.1.69 (registry+https://github.com/rust-lang/crates.io-index)", - "rust-crypto 0.2.35 (registry+https://github.com/rust-lang/crates.io-index)", "rustup-mock 0.1.9", "rustup-utils 0.1.9", "tar 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -494,7 +475,7 @@ dependencies = [ "hyper 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", - "rust-crypto 0.2.35 (registry+https://github.com/rust-lang/crates.io-index)", + "rustup-utils 0.1.9", "scopeguard 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "tar 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "tempdir 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -516,7 +497,7 @@ dependencies = [ "native-tls 0.1.0 (git+https://github.com/sfackler/rust-native-tls.git)", "ole32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", - "rust-crypto 0.2.35 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "scopeguard 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "shell32-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "userenv-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index b70b8827b3..8dcb2e0997 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,6 @@ rustup-utils = { path = "src/rustup-utils", version = "0.1.9" } error-chain = { path = "src/error-chain", version = "0.1.9" } clap = "2.2.4" regex = "0.1.41" -rust-crypto = "0.2.35" url = "1.1.0" term = "0.4.4" itertools = "0.4.1" diff --git a/src/rustup-cli/main.rs b/src/rustup-cli/main.rs index 871940c602..3a45e96164 100644 --- a/src/rustup-cli/main.rs +++ b/src/rustup-cli/main.rs @@ -12,7 +12,6 @@ extern crate regex; #[macro_use] extern crate rustup; extern crate term; -extern crate crypto; extern crate itertools; extern crate time; extern crate rand; diff --git a/src/rustup-cli/self_update.rs b/src/rustup-cli/self_update.rs index 8abccb98c2..fa6495712d 100644 --- a/src/rustup-cli/self_update.rs +++ b/src/rustup-cli/self_update.rs @@ -36,8 +36,7 @@ use rustup::{NotifyHandler}; use errors::*; use rustup_dist::dist; use rustup_utils::utils; -use crypto::sha2::Sha256; -use crypto::digest::Digest; +use rustup_utils::sha2::{Sha256, Digest}; use std::env; use std::env::consts::EXE_SUFFIX; use std::path::{Path, PathBuf}; diff --git a/src/rustup-dist/Cargo.toml b/src/rustup-dist/Cargo.toml index 5c88fdac52..7c5b20f985 100644 --- a/src/rustup-dist/Cargo.toml +++ b/src/rustup-dist/Cargo.toml @@ -14,7 +14,6 @@ license = "MIT OR Apache-2.0" [dependencies] regex = "0.1.41" -rust-crypto = "0.2.35" itertools = "0.4.1" ole32-sys = "0.2.0" url = "1.1.0" diff --git a/src/rustup-dist/src/dist.rs b/src/rustup-dist/src/dist.rs index 580687db00..4eccd42ab1 100644 --- a/src/rustup-dist/src/dist.rs +++ b/src/rustup-dist/src/dist.rs @@ -12,8 +12,7 @@ use std::path::Path; use std::fmt; use regex::Regex; -use crypto::sha2::Sha256; -use crypto::digest::Digest; +use rustup_utils::sha2::{Sha256, Digest}; use itertools::Itertools; pub const DEFAULT_DIST_ROOT: &'static str = "https://static.rust-lang.org/dist"; diff --git a/src/rustup-dist/src/download.rs b/src/rustup-dist/src/download.rs index bbcbe2ad76..2852711523 100644 --- a/src/rustup-dist/src/download.rs +++ b/src/rustup-dist/src/download.rs @@ -3,8 +3,7 @@ use notifications::*; use rustup_utils::utils; use temp; -use crypto::sha2::Sha256; -use crypto::digest::Digest; +use rustup_utils::sha2::{Sha256, Digest}; use std::path::Path; use std::process::Command; diff --git a/src/rustup-dist/src/lib.rs b/src/rustup-dist/src/lib.rs index b3eeb9d237..764d2a0ed6 100644 --- a/src/rustup-dist/src/lib.rs +++ b/src/rustup-dist/src/lib.rs @@ -1,7 +1,6 @@ #![recursion_limit = "1024"] extern crate regex; -extern crate crypto; extern crate itertools; extern crate tempdir; extern crate walkdir; diff --git a/src/rustup-dist/src/manifestation.rs b/src/rustup-dist/src/manifestation.rs index e32b5efe49..93effbf1bf 100644 --- a/src/rustup-dist/src/manifestation.rs +++ b/src/rustup-dist/src/manifestation.rs @@ -10,8 +10,7 @@ use errors::*; use notifications::*; use rustup_utils::utils; use prefix::InstallPrefix; -use crypto::sha2::Sha256; -use crypto::digest::Digest; +use rustup_utils::sha2::{Sha256, Digest}; use itertools::Itertools; use std::path::Path; diff --git a/src/rustup-mock/Cargo.toml b/src/rustup-mock/Cargo.toml index 2611bacf75..016a8ac3f6 100644 --- a/src/rustup-mock/Cargo.toml +++ b/src/rustup-mock/Cargo.toml @@ -16,10 +16,10 @@ lazy_static = "0.1.15" walkdir = "0.1.5" flate2 = "0.2.9" tempdir = "0.3.4" -rust-crypto = "0.2.35" itertools = "0.4.1" tar = "0.4.0" toml = "0.1.27" +rustup-utils = { path = "../rustup-utils", version = "0.1.9" } [target."cfg(windows)".dependencies] winapi = "0.2.4" diff --git a/src/rustup-mock/src/dist.rs b/src/rustup-mock/src/dist.rs index 7ce6f80b4e..3a453f8697 100644 --- a/src/rustup-mock/src/dist.rs +++ b/src/rustup-mock/src/dist.rs @@ -8,8 +8,7 @@ use std::fs::{self, File}; use std::collections::HashMap; use std::io::{Read, Write}; use tempdir::TempDir; -use crypto::sha2::Sha256; -use crypto::digest::Digest; +use rustup_utils::sha2::{Sha256, Digest}; use itertools::Itertools; use toml; use flate2; diff --git a/src/rustup-mock/src/lib.rs b/src/rustup-mock/src/lib.rs index a6d9d2a564..2c8a5e7e52 100644 --- a/src/rustup-mock/src/lib.rs +++ b/src/rustup-mock/src/lib.rs @@ -7,10 +7,10 @@ extern crate scopeguard; extern crate walkdir; extern crate flate2; extern crate tempdir; -extern crate crypto; extern crate itertools; extern crate tar; extern crate toml; +extern crate rustup_utils; #[cfg(windows)] extern crate winapi; diff --git a/src/rustup-utils/Cargo.toml b/src/rustup-utils/Cargo.toml index 00ada297c8..78ca8cd47a 100644 --- a/src/rustup-utils/Cargo.toml +++ b/src/rustup-utils/Cargo.toml @@ -12,12 +12,12 @@ repository = "https://github.com/rust-lang-nursery/rustup.rs" license = "MIT OR Apache-2.0" [dependencies] -rust-crypto = "0.2.35" rand = "0.3.11" scopeguard = "0.1.2" error-chain = { path = "../error-chain", version = "0.1.9" } libc = "0.2.0" native-tls = { git = "https://github.com/sfackler/rust-native-tls.git" } +rustc-serialize = "0.3.19" [target."cfg(windows)".dependencies] winapi = "0.2.4" diff --git a/src/rustup-utils/src/lib.rs b/src/rustup-utils/src/lib.rs index 1f28aef510..33a3b1b06a 100644 --- a/src/rustup-utils/src/lib.rs +++ b/src/rustup-utils/src/lib.rs @@ -1,14 +1,15 @@ #![feature(core_intrinsics)] // For type_name(). #![feature(fundamental)] +#![feature(step_by)] #![recursion_limit = "1024"] // for error_chain! extern crate hyper; -extern crate crypto; extern crate rand; extern crate scopeguard; #[macro_use] extern crate error_chain; extern crate native_tls; +extern crate rustc_serialize; #[cfg(windows)] extern crate winapi; @@ -34,6 +35,7 @@ pub mod notifications; pub mod raw; pub mod tty; pub mod utils; +pub mod sha2; pub use errors::*; pub use notifications::{Notification, NotifyHandler}; diff --git a/src/rustup-utils/src/raw.rs b/src/rustup-utils/src/raw.rs index f38f79f6b1..edf5e706cb 100644 --- a/src/rustup-utils/src/raw.rs +++ b/src/rustup-utils/src/raw.rs @@ -12,8 +12,7 @@ use std::fmt; use std::thread; use std::time::Duration; use hyper::{self, Client}; -use crypto::sha2::Sha256; -use crypto::digest::Digest; +use sha2::{Sha256, Digest}; use errors::*; use rand::random; diff --git a/src/rustup-utils/src/sha2.rs b/src/rustup-utils/src/sha2.rs new file mode 100644 index 0000000000..1b1b6877ac --- /dev/null +++ b/src/rustup-utils/src/sha2.rs @@ -0,0 +1,682 @@ +// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! This module implements only the Sha256 function since that is all that is needed for internal +//! use. This implementation is not intended for external use or for any use where security is +//! important. + +use rustc_serialize::hex::ToHex; + +/// Write a u32 into a vector, which must be 4 bytes long. The value is written in big-endian +/// format. +fn write_u32_be(dst: &mut[u8], input: u32) { + dst[0] = (input >> 24) as u8; + dst[1] = (input >> 16) as u8; + dst[2] = (input >> 8) as u8; + dst[3] = input as u8; +} + +/// Read the value of a vector of bytes as a u32 value in big-endian format. +fn read_u32_be(input: &[u8]) -> u32 { + return + (input[0] as u32) << 24 | + (input[1] as u32) << 16 | + (input[2] as u32) << 8 | + (input[3] as u32); +} + +/// Read a vector of bytes into a vector of u32s. The values are read in big-endian format. +fn read_u32v_be(dst: &mut[u32], input: &[u8]) { + assert!(dst.len() * 4 == input.len()); + let mut pos = 0; + for chunk in input.chunks(4) { + dst[pos] = read_u32_be(chunk); + pos += 1; + } +} + +trait ToBits { + /// Convert the value in bytes to the number of bits, a tuple where the 1st item is the + /// high-order value and the 2nd item is the low order value. + fn to_bits(self) -> (Self, Self); +} + +impl ToBits for u64 { + fn to_bits(self) -> (u64, u64) { + return (self >> 61, self << 3); + } +} + +/// Adds the specified number of bytes to the bit count. panic!() if this would cause numeric +/// overflow. +fn add_bytes_to_bits(bits: u64, bytes: u64) -> u64 { + let (new_high_bits, new_low_bits) = bytes.to_bits(); + + if new_high_bits > 0 { + panic!("numeric overflow occurred.") + } + + match bits.checked_add(new_low_bits) { + Some(x) => return x, + None => panic!("numeric overflow occurred.") + } +} + +/// A FixedBuffer, likes its name implies, is a fixed size buffer. When the buffer becomes full, it +/// must be processed. The input() method takes care of processing and then clearing the buffer +/// automatically. However, other methods do not and require the caller to process the buffer. Any +/// method that modifies the buffer directory or provides the caller with bytes that can be modified +/// results in those bytes being marked as used by the buffer. +trait FixedBuffer { + /// Input a vector of bytes. If the buffer becomes full, process it with the provided + /// function and then clear the buffer. + fn input(&mut self, input: &[u8], func: F) where + F: FnMut(&[u8]); + + /// Reset the buffer. + fn reset(&mut self); + + /// Zero the buffer up until the specified index. The buffer position currently must not be + /// greater than that index. + fn zero_until(&mut self, idx: usize); + + /// Get a slice of the buffer of the specified size. There must be at least that many bytes + /// remaining in the buffer. + fn next<'s>(&'s mut self, len: usize) -> &'s mut [u8]; + + /// Get the current buffer. The buffer must already be full. This clears the buffer as well. + fn full_buffer<'s>(&'s mut self) -> &'s [u8]; + + /// Get the current position of the buffer. + fn position(&self) -> usize; + + /// Get the number of bytes remaining in the buffer until it is full. + fn remaining(&self) -> usize; + + /// Get the size of the buffer + fn size(&self) -> usize; +} + +/// A FixedBuffer of 64 bytes useful for implementing Sha256 which has a 64 byte blocksize. +struct FixedBuffer64 { + buffer: [u8; 64], + buffer_idx: usize, +} + +impl FixedBuffer64 { + /// Create a new FixedBuffer64 + fn new() -> FixedBuffer64 { + return FixedBuffer64 { + buffer: [0; 64], + buffer_idx: 0 + }; + } +} + +impl FixedBuffer for FixedBuffer64 { + fn input(&mut self, input: &[u8], mut func: F) where + F: FnMut(&[u8]), + { + let mut i = 0; + + let size = self.size(); + + // If there is already data in the buffer, copy as much as we can into it and process + // the data if the buffer becomes full. + if self.buffer_idx != 0 { + let buffer_remaining = size - self.buffer_idx; + if input.len() >= buffer_remaining { + self.buffer[self.buffer_idx..size] + .copy_from_slice(&input[..buffer_remaining]); + self.buffer_idx = 0; + func(&self.buffer); + i += buffer_remaining; + } else { + self.buffer[self.buffer_idx..self.buffer_idx + input.len()] + .copy_from_slice(input); + self.buffer_idx += input.len(); + return; + } + } + + // While we have at least a full buffer size chunk's worth of data, process that data + // without copying it into the buffer + while input.len() - i >= size { + func(&input[i..i + size]); + i += size; + } + + // Copy any input data into the buffer. At this point in the method, the amount of + // data left in the input vector will be less than the buffer size and the buffer will + // be empty. + let input_remaining = input.len() - i; + self.buffer[..input_remaining].copy_from_slice(&input[i..]); + self.buffer_idx += input_remaining; + } + + fn reset(&mut self) { + self.buffer_idx = 0; + } + + fn zero_until(&mut self, idx: usize) { + assert!(idx >= self.buffer_idx); + for slot in self.buffer[self.buffer_idx..idx].iter_mut() { + *slot = 0; + } + self.buffer_idx = idx; + } + + fn next<'s>(&'s mut self, len: usize) -> &'s mut [u8] { + self.buffer_idx += len; + return &mut self.buffer[self.buffer_idx - len..self.buffer_idx]; + } + + fn full_buffer<'s>(&'s mut self) -> &'s [u8] { + assert!(self.buffer_idx == 64); + self.buffer_idx = 0; + return &self.buffer[..64]; + } + + fn position(&self) -> usize { self.buffer_idx } + + fn remaining(&self) -> usize { 64 - self.buffer_idx } + + fn size(&self) -> usize { 64 } +} + +/// The StandardPadding trait adds a method useful for Sha256 to a FixedBuffer struct. +trait StandardPadding { + /// Add padding to the buffer. The buffer must not be full when this method is called and is + /// guaranteed to have exactly rem remaining bytes when it returns. If there are not at least + /// rem bytes available, the buffer will be zero padded, processed, cleared, and then filled + /// with zeros again until only rem bytes are remaining. + fn standard_padding(&mut self, rem: usize, func: F) where F: FnMut(&[u8]); +} + +impl StandardPadding for T { + fn standard_padding(&mut self, rem: usize, mut func: F) where F: FnMut(&[u8]) { + let size = self.size(); + + self.next(1)[0] = 128; + + if self.remaining() < rem { + self.zero_until(size); + func(self.full_buffer()); + } + + self.zero_until(size - rem); + } +} + +/// The Digest trait specifies an interface common to digest functions, such as SHA-1 and the SHA-2 +/// family of digest functions. +pub trait Digest { + /// Provide message data. + /// + /// # Arguments + /// + /// * input - A vector of message data + fn input(&mut self, input: &[u8]); + + /// Retrieve the digest result. This method may be called multiple times. + /// + /// # Arguments + /// + /// * out - the vector to hold the result. Must be large enough to contain output_bits(). + fn result(&mut self, out: &mut [u8]); + + /// Reset the digest. This method must be called after result() and before supplying more + /// data. + fn reset(&mut self); + + /// Get the output size in bits. + fn output_bits(&self) -> usize; + + /// Convenience function that feeds a string into a digest. + /// + /// # Arguments + /// + /// * `input` The string to feed into the digest + fn input_str(&mut self, input: &str) { + self.input(input.as_bytes()); + } + + /// Convenience function that retrieves the result of a digest as a + /// newly allocated vec of bytes. + fn result_bytes(&mut self) -> Vec { + let mut buf = vec![0; (self.output_bits()+7)/8]; + self.result(&mut buf); + buf + } + + /// Convenience function that retrieves the result of a digest as a + /// String in hexadecimal format. + fn result_str(&mut self) -> String { + self.result_bytes().to_hex().to_string() + } +} + +// A structure that represents that state of a digest computation for the SHA-2 512 family of digest +// functions +struct Engine256State { + h0: u32, + h1: u32, + h2: u32, + h3: u32, + h4: u32, + h5: u32, + h6: u32, + h7: u32, +} + +impl Engine256State { + fn new(h: &[u32; 8]) -> Engine256State { + return Engine256State { + h0: h[0], + h1: h[1], + h2: h[2], + h3: h[3], + h4: h[4], + h5: h[5], + h6: h[6], + h7: h[7] + }; + } + + fn reset(&mut self, h: &[u32; 8]) { + self.h0 = h[0]; + self.h1 = h[1]; + self.h2 = h[2]; + self.h3 = h[3]; + self.h4 = h[4]; + self.h5 = h[5]; + self.h6 = h[6]; + self.h7 = h[7]; + } + + fn process_block(&mut self, data: &[u8]) { + fn ch(x: u32, y: u32, z: u32) -> u32 { + ((x & y) ^ ((!x) & z)) + } + + fn maj(x: u32, y: u32, z: u32) -> u32 { + ((x & y) ^ (x & z) ^ (y & z)) + } + + fn sum0(x: u32) -> u32 { + ((x >> 2) | (x << 30)) ^ ((x >> 13) | (x << 19)) ^ ((x >> 22) | (x << 10)) + } + + fn sum1(x: u32) -> u32 { + ((x >> 6) | (x << 26)) ^ ((x >> 11) | (x << 21)) ^ ((x >> 25) | (x << 7)) + } + + fn sigma0(x: u32) -> u32 { + ((x >> 7) | (x << 25)) ^ ((x >> 18) | (x << 14)) ^ (x >> 3) + } + + fn sigma1(x: u32) -> u32 { + ((x >> 17) | (x << 15)) ^ ((x >> 19) | (x << 13)) ^ (x >> 10) + } + + let mut a = self.h0; + let mut b = self.h1; + let mut c = self.h2; + let mut d = self.h3; + let mut e = self.h4; + let mut f = self.h5; + let mut g = self.h6; + let mut h = self.h7; + + let mut w = [0; 64]; + + // Sha-512 and Sha-256 use basically the same calculations which are implemented + // by these macros. Inlining the calculations seems to result in better generated code. + macro_rules! schedule_round { ($t:expr) => ( + w[$t] = sigma1(w[$t - 2]).wrapping_add(w[$t - 7]) + .wrapping_add(sigma0(w[$t - 15])).wrapping_add(w[$t - 16]); + ) + } + + macro_rules! sha2_round { + ($A:ident, $B:ident, $C:ident, $D:ident, + $E:ident, $F:ident, $G:ident, $H:ident, $K:ident, $t:expr) => ( + { + $H = $H.wrapping_add(sum1($E)).wrapping_add(ch($E, $F, $G)) + .wrapping_add($K[$t]).wrapping_add(w[$t]); + $D = $D.wrapping_add($H); + $H = $H.wrapping_add(sum0($A)).wrapping_add(maj($A, $B, $C)); + } + ) + } + + read_u32v_be(&mut w[0..16], data); + + // Putting the message schedule inside the same loop as the round calculations allows for + // the compiler to generate better code. + for t in (0..48).step_by(8) { + schedule_round!(t + 16); + schedule_round!(t + 17); + schedule_round!(t + 18); + schedule_round!(t + 19); + schedule_round!(t + 20); + schedule_round!(t + 21); + schedule_round!(t + 22); + schedule_round!(t + 23); + + sha2_round!(a, b, c, d, e, f, g, h, K32, t); + sha2_round!(h, a, b, c, d, e, f, g, K32, t + 1); + sha2_round!(g, h, a, b, c, d, e, f, K32, t + 2); + sha2_round!(f, g, h, a, b, c, d, e, K32, t + 3); + sha2_round!(e, f, g, h, a, b, c, d, K32, t + 4); + sha2_round!(d, e, f, g, h, a, b, c, K32, t + 5); + sha2_round!(c, d, e, f, g, h, a, b, K32, t + 6); + sha2_round!(b, c, d, e, f, g, h, a, K32, t + 7); + } + + for t in (48..64).step_by(8) { + sha2_round!(a, b, c, d, e, f, g, h, K32, t); + sha2_round!(h, a, b, c, d, e, f, g, K32, t + 1); + sha2_round!(g, h, a, b, c, d, e, f, K32, t + 2); + sha2_round!(f, g, h, a, b, c, d, e, K32, t + 3); + sha2_round!(e, f, g, h, a, b, c, d, K32, t + 4); + sha2_round!(d, e, f, g, h, a, b, c, K32, t + 5); + sha2_round!(c, d, e, f, g, h, a, b, K32, t + 6); + sha2_round!(b, c, d, e, f, g, h, a, K32, t + 7); + } + + self.h0 = self.h0.wrapping_add(a); + self.h1 = self.h1.wrapping_add(b); + self.h2 = self.h2.wrapping_add(c); + self.h3 = self.h3.wrapping_add(d); + self.h4 = self.h4.wrapping_add(e); + self.h5 = self.h5.wrapping_add(f); + self.h6 = self.h6.wrapping_add(g); + self.h7 = self.h7.wrapping_add(h); + } +} + +static K32: [u32; 64] = [ + 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, + 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, + 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, + 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, + 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, + 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, + 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, + 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, + 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, + 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, + 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, + 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, + 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, + 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, + 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, + 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 +]; + +// A structure that keeps track of the state of the Sha-256 operation and contains the logic +// necessary to perform the final calculations. +struct Engine256 { + length_bits: u64, + buffer: FixedBuffer64, + state: Engine256State, + finished: bool, +} + +impl Engine256 { + fn new(h: &[u32; 8]) -> Engine256 { + return Engine256 { + length_bits: 0, + buffer: FixedBuffer64::new(), + state: Engine256State::new(h), + finished: false + } + } + + fn reset(&mut self, h: &[u32; 8]) { + self.length_bits = 0; + self.buffer.reset(); + self.state.reset(h); + self.finished = false; + } + + fn input(&mut self, input: &[u8]) { + assert!(!self.finished); + // Assumes that input.len() can be converted to u64 without overflow + self.length_bits = add_bytes_to_bits(self.length_bits, input.len() as u64); + let self_state = &mut self.state; + self.buffer.input(input, |input: &[u8]| { self_state.process_block(input) }); + } + + fn finish(&mut self) { + if self.finished { + return; + } + + let self_state = &mut self.state; + self.buffer.standard_padding(8, |input: &[u8]| { self_state.process_block(input) }); + write_u32_be(self.buffer.next(4), (self.length_bits >> 32) as u32 ); + write_u32_be(self.buffer.next(4), self.length_bits as u32); + self_state.process_block(self.buffer.full_buffer()); + + self.finished = true; + } +} + +/// The SHA-256 hash algorithm +pub struct Sha256 { + engine: Engine256 +} + +impl Sha256 { + /// Construct a new instance of a SHA-256 digest. + /// Do not – under any circumstances – use this where timing attacks might be possible! + pub fn new() -> Sha256 { + Sha256 { + engine: Engine256::new(&H256) + } + } +} + +impl Digest for Sha256 { + fn input(&mut self, d: &[u8]) { + self.engine.input(d); + } + + fn result(&mut self, out: &mut [u8]) { + self.engine.finish(); + + write_u32_be(&mut out[0..4], self.engine.state.h0); + write_u32_be(&mut out[4..8], self.engine.state.h1); + write_u32_be(&mut out[8..12], self.engine.state.h2); + write_u32_be(&mut out[12..16], self.engine.state.h3); + write_u32_be(&mut out[16..20], self.engine.state.h4); + write_u32_be(&mut out[20..24], self.engine.state.h5); + write_u32_be(&mut out[24..28], self.engine.state.h6); + write_u32_be(&mut out[28..32], self.engine.state.h7); + } + + fn reset(&mut self) { + self.engine.reset(&H256); + } + + fn output_bits(&self) -> usize { 256 } +} + +static H256: [u32; 8] = [ + 0x6a09e667, + 0xbb67ae85, + 0x3c6ef372, + 0xa54ff53a, + 0x510e527f, + 0x9b05688c, + 0x1f83d9ab, + 0x5be0cd19 +]; + +#[cfg(test)] +mod tests { + #![allow(deprecated)] + extern crate rand; + + use self::rand::Rng; + use self::rand::isaac::IsaacRng; + use serialize::hex::FromHex; + use std::u64; + use super::{Digest, Sha256, FixedBuffer}; + + // A normal addition - no overflow occurs + #[test] + fn test_add_bytes_to_bits_ok() { + assert!(super::add_bytes_to_bits(100, 10) == 180); + } + + // A simple failure case - adding 1 to the max value + #[test] + #[should_panic] + fn test_add_bytes_to_bits_overflow() { + super::add_bytes_to_bits(u64::MAX, 1); + } + + struct Test { + input: String, + output_str: String, + } + + fn test_hash(sh: &mut D, tests: &[Test]) { + // Test that it works when accepting the message all at once + for t in tests { + sh.reset(); + sh.input_str(&t.input); + let out_str = sh.result_str(); + assert!(out_str == t.output_str); + } + + // Test that it works when accepting the message in pieces + for t in tests { + sh.reset(); + let len = t.input.len(); + let mut left = len; + while left > 0 { + let take = (left + 1) / 2; + sh.input_str(&t.input[len - left..take + len - left]); + left = left - take; + } + let out_str = sh.result_str(); + assert!(out_str == t.output_str); + } + } + + #[test] + fn test_sha256() { + // Examples from wikipedia + let wikipedia_tests = vec!( + Test { + input: "".to_string(), + output_str: "e3b0c44298fc1c149afb\ + f4c8996fb92427ae41e4649b934ca495991b7852b855".to_string() + }, + Test { + input: "The quick brown fox jumps over the lazy \ + dog".to_string(), + output_str: "d7a8fbb307d7809469ca\ + 9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592".to_string() + }, + Test { + input: "The quick brown fox jumps over the lazy \ + dog.".to_string(), + output_str: "ef537f25c895bfa78252\ + 6529a9b63d97aa631564d5d789c2b765448c8635fb6c".to_string() + }); + + let tests = wikipedia_tests; + + let mut sh: Box<_> = box Sha256::new(); + + test_hash(&mut *sh, &tests); + } + + /// Feed 1,000,000 'a's into the digest with varying input sizes and check that the result is + /// correct. + fn test_digest_1million_random(digest: &mut D, blocksize: usize, expected: &str) { + let total_size = 1000000; + let buffer = vec![b'a'; blocksize * 2]; + let mut rng = IsaacRng::new_unseeded(); + let mut count = 0; + + digest.reset(); + + while count < total_size { + let next: usize = rng.gen_range(0, 2 * blocksize + 1); + let remaining = total_size - count; + let size = if next > remaining { remaining } else { next }; + digest.input(&buffer[..size]); + count += size; + } + + let result_str = digest.result_str(); + let result_bytes = digest.result_bytes(); + + assert_eq!(expected, result_str); + + let expected_vec: Vec = expected.from_hex() + .unwrap() + .into_iter() + .collect(); + assert_eq!(expected_vec, result_bytes); + } + + #[test] + fn test_1million_random_sha256() { + let mut sh = Sha256::new(); + test_digest_1million_random( + &mut sh, + 64, + "cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0"); + } +} + +#[cfg(test)] +mod bench { + extern crate test; + use self::test::Bencher; + use super::{Sha256, FixedBuffer, Digest}; + + #[bench] + pub fn sha256_10(b: &mut Bencher) { + let mut sh = Sha256::new(); + let bytes = [1; 10]; + b.iter(|| { + sh.input(&bytes); + }); + b.bytes = bytes.len() as u64; + } + + #[bench] + pub fn sha256_1k(b: &mut Bencher) { + let mut sh = Sha256::new(); + let bytes = [1; 1024]; + b.iter(|| { + sh.input(&bytes); + }); + b.bytes = bytes.len() as u64; + } + + #[bench] + pub fn sha256_64k(b: &mut Bencher) { + let mut sh = Sha256::new(); + let bytes = [1; 65536]; + b.iter(|| { + sh.input(&bytes); + }); + b.bytes = bytes.len() as u64; + } +} diff --git a/src/rustup-utils/src/utils.rs b/src/rustup-utils/src/utils.rs index cc2ce0f6ac..50cd29a5c0 100644 --- a/src/rustup-utils/src/utils.rs +++ b/src/rustup-utils/src/utils.rs @@ -6,7 +6,7 @@ use std::process::Command; use std::ffi::OsString; use std::env; use hyper; -use crypto::sha2::Sha256; +use sha2::Sha256; use notify::Notifyable; use notifications::{Notification, NotifyHandler}; use raw; From b41005b6221b24068f2b903ce899d6dd9475a0a7 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 6 May 2016 17:43:13 +0000 Subject: [PATCH 12/14] Override NetworkStream::close Passing this call through seems like the safe thing to do. --- src/rustup-utils/src/raw.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rustup-utils/src/raw.rs b/src/rustup-utils/src/raw.rs index edf5e706cb..61246588ba 100644 --- a/src/rustup-utils/src/raw.rs +++ b/src/rustup-utils/src/raw.rs @@ -170,7 +170,7 @@ pub fn download_file>(url: hyper::Url, use notifications::Notification; use std::io::Result as IoResult; use std::io::{Read, Write}; - use std::net::{SocketAddr}; + use std::net::{SocketAddr, Shutdown}; use std::sync::{Arc, Mutex}; // This is just a defensive measure to make sure I'm not sending @@ -214,6 +214,9 @@ pub fn download_file>(url: hyper::Url, fn set_write_timeout(&self, dur: Option) -> IoResult<()> { self.0.lock().expect("").get_ref().set_read_timeout(dur) } + fn close(&mut self, how: Shutdown) -> IoResult<()> { + self.0.lock().expect("").get_mut().close(how) + } } impl Read for NativeSslStream From 9a9bb74bef2718411156a72a27f56fd7c323da90 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 6 May 2016 17:47:29 +0000 Subject: [PATCH 13/14] Remove step_by feature --- src/rustup-utils/src/lib.rs | 1 - src/rustup-utils/src/sha2.rs | 10 ++++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/rustup-utils/src/lib.rs b/src/rustup-utils/src/lib.rs index 33a3b1b06a..987caaab19 100644 --- a/src/rustup-utils/src/lib.rs +++ b/src/rustup-utils/src/lib.rs @@ -1,6 +1,5 @@ #![feature(core_intrinsics)] // For type_name(). #![feature(fundamental)] -#![feature(step_by)] #![recursion_limit = "1024"] // for error_chain! extern crate hyper; diff --git a/src/rustup-utils/src/sha2.rs b/src/rustup-utils/src/sha2.rs index 1b1b6877ac..b812407dcd 100644 --- a/src/rustup-utils/src/sha2.rs +++ b/src/rustup-utils/src/sha2.rs @@ -361,7 +361,8 @@ impl Engine256State { // Putting the message schedule inside the same loop as the round calculations allows for // the compiler to generate better code. - for t in (0..48).step_by(8) { + let mut t = 0; + while t < 48 { schedule_round!(t + 16); schedule_round!(t + 17); schedule_round!(t + 18); @@ -379,9 +380,12 @@ impl Engine256State { sha2_round!(d, e, f, g, h, a, b, c, K32, t + 5); sha2_round!(c, d, e, f, g, h, a, b, K32, t + 6); sha2_round!(b, c, d, e, f, g, h, a, K32, t + 7); + + t += 8; } - for t in (48..64).step_by(8) { + let mut t = 48; + while t < 64 { sha2_round!(a, b, c, d, e, f, g, h, K32, t); sha2_round!(h, a, b, c, d, e, f, g, K32, t + 1); sha2_round!(g, h, a, b, c, d, e, f, K32, t + 2); @@ -390,6 +394,8 @@ impl Engine256State { sha2_round!(d, e, f, g, h, a, b, c, K32, t + 5); sha2_round!(c, d, e, f, g, h, a, b, K32, t + 6); sha2_round!(b, c, d, e, f, g, h, a, K32, t + 7); + + t += 8; } self.h0 = self.h0.wrapping_add(a); From 13ba54d2c8ca9972feb227ac71579e95ed27c2ba Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 6 May 2016 11:09:41 -0700 Subject: [PATCH 14/14] Remove hyper dependency from rustup-mock --- Cargo.lock | 5 +---- src/rustup-mock/Cargo.toml | 2 +- src/rustup-mock/src/clitools.rs | 2 +- src/rustup-mock/src/dist.rs | 2 +- src/rustup-mock/src/lib.rs | 2 +- 5 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e2049f65bc..64ec06f049 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -110,8 +110,6 @@ name = "cookie" version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "openssl 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -212,7 +210,6 @@ dependencies = [ "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "mime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "solicit 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", @@ -472,7 +469,6 @@ name = "rustup-mock" version = "0.1.9" dependencies = [ "flate2 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", - "hyper 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", "rustup-utils 0.1.9", @@ -480,6 +476,7 @@ dependencies = [ "tar 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "tempdir 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "walkdir 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "winreg 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/src/rustup-mock/Cargo.toml b/src/rustup-mock/Cargo.toml index 016a8ac3f6..77622da495 100644 --- a/src/rustup-mock/Cargo.toml +++ b/src/rustup-mock/Cargo.toml @@ -10,7 +10,7 @@ homepage = "https://github.com/rust-lang-nursery/rustup.rs" repository = "https://github.com/rust-lang-nursery/rustup.rs" [dependencies] -hyper = "0.9.2" +url = "1.1.0" scopeguard = "0.1.2" lazy_static = "0.1.15" walkdir = "0.1.5" diff --git a/src/rustup-mock/src/clitools.rs b/src/rustup-mock/src/clitools.rs index 53f6fa3b40..6d32f25f2f 100644 --- a/src/rustup-mock/src/clitools.rs +++ b/src/rustup-mock/src/clitools.rs @@ -13,7 +13,7 @@ use {MockInstallerBuilder, MockCommand}; use dist::{MockDistServer, MockChannel, MockPackage, MockTargettedPackage, MockComponent, change_channel_date, ManifestVersion}; -use hyper::Url; +use url::Url; use scopeguard; /// The configuration used by the tests in this module diff --git a/src/rustup-mock/src/dist.rs b/src/rustup-mock/src/dist.rs index 3a453f8697..bb8d488d27 100644 --- a/src/rustup-mock/src/dist.rs +++ b/src/rustup-mock/src/dist.rs @@ -2,7 +2,7 @@ //! distribution server, with v1 and v2 manifests. use MockInstallerBuilder; -use hyper::Url; +use url::Url; use std::path::{PathBuf, Path}; use std::fs::{self, File}; use std::collections::HashMap; diff --git a/src/rustup-mock/src/lib.rs b/src/rustup-mock/src/lib.rs index 2c8a5e7e52..436b4b5c08 100644 --- a/src/rustup-mock/src/lib.rs +++ b/src/rustup-mock/src/lib.rs @@ -1,6 +1,6 @@ //! Mocks for testing -extern crate hyper; +extern crate url; #[macro_use] extern crate lazy_static; extern crate scopeguard;