Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various networking fixes #400

Merged
merged 14 commits into from
May 6, 2016
231 changes: 126 additions & 105 deletions Cargo.lock

Large diffs are not rendered by default.

23 changes: 2 additions & 21 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +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"
hyper = "0.7.0"
url = "1.1.0"
term = "0.4.4"
itertools = "0.4.1"
time = "0.1.34"
Expand All @@ -34,25 +33,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"
Expand Down
9 changes: 0 additions & 9 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 0 additions & 19 deletions ci/appveyor-cargo-config.toml

This file was deleted.

4 changes: 2 additions & 2 deletions ci/run-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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-*)
Expand Down
2 changes: 0 additions & 2 deletions src/rustup-cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ extern crate error_chain;
#[macro_use]
extern crate clap;
extern crate regex;
extern crate hyper;
#[macro_use]
extern crate rustup;
extern crate term;
extern crate openssl;
extern crate itertools;
extern crate time;
extern crate rand;
Expand Down
30 changes: 17 additions & 13 deletions src/rustup-cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ use rustup::{NotifyHandler};
use errors::*;
use rustup_dist::dist;
use rustup_utils::utils;
use openssl::crypto::hash::{Type, Hasher};
use rustup_utils::sha2::{Sha256, 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 {
Expand Down Expand Up @@ -1038,12 +1039,18 @@ pub fn prepare_update() -> Result<Option<PathBuf>> {
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");
Expand All @@ -1064,15 +1071,12 @@ pub fn prepare_update() -> Result<Option<PathBuf>> {

// 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 {
Expand Down
3 changes: 1 addition & 2 deletions src/rustup-dist/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ license = "MIT OR Apache-2.0"

[dependencies]
regex = "0.1.41"
hyper = "0.7.0"
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"
Expand Down
9 changes: 3 additions & 6 deletions src/rustup-dist/src/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::path::Path;
use std::fmt;

use regex::Regex;
use openssl::crypto::hash::{Type, Hasher};
use rustup_utils::sha2::{Sha256, Digest};
use itertools::Itertools;

pub const DEFAULT_DIST_ROOT: &'static str = "https://static.rust-lang.org/dist";
Expand Down Expand Up @@ -341,12 +341,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
Expand Down
10 changes: 3 additions & 7 deletions src/rustup-dist/src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use notifications::*;
use rustup_utils::utils;
use temp;

use openssl::crypto::hash::{Type, Hasher};
use itertools::Itertools;
use rustup_utils::sha2::{Sha256, Digest};

use std::path::Path;
use std::process::Command;
Expand Down Expand Up @@ -66,7 +65,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());
Expand All @@ -75,10 +74,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
Expand Down
2 changes: 0 additions & 2 deletions src/rustup-dist/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#![recursion_limit = "1024"]

extern crate hyper;
extern crate regex;
extern crate openssl;
extern crate itertools;
extern crate tempdir;
extern crate walkdir;
Expand Down
9 changes: 3 additions & 6 deletions src/rustup-dist/src/manifestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use errors::*;
use notifications::*;
use rustup_utils::utils;
use prefix::InstallPrefix;
use openssl::crypto::hash::{Type, Hasher};
use rustup_utils::sha2::{Sha256, Digest};
use itertools::Itertools;
use std::path::Path;

Expand Down Expand Up @@ -135,14 +135,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!(&notify_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
Expand Down
17 changes: 5 additions & 12 deletions src/rustup-dist/tests/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ 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;
extern crate itertools;
extern crate hyper;
extern crate url;

use rustup_mock::dist::*;
use rustup_mock::{MockCommand, MockInstallerBuilder};
Expand All @@ -25,7 +24,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;
Expand Down Expand Up @@ -278,7 +277,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));

Expand All @@ -295,15 +294,9 @@ fn update_from_dist(dist_server: &Url,
}

fn make_manifest_url(dist_server: &Url, toolchain: &ToolchainDesc) -> Result<Url> {
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,
Expand Down
18 changes: 3 additions & 15 deletions src/rustup-mock/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,17 @@ homepage = "https://github.com/rust-lang-nursery/rustup.rs"
repository = "https://github.com/rust-lang-nursery/rustup.rs"

[dependencies]
hyper = "0.7.0"
url = "1.1.0"
scopeguard = "0.1.2"
lazy_static = "0.1.15"
walkdir = "0.1.5"
flate2 = "0.2.9"
tempdir = "0.3.4"
openssl = "0.7.2"
itertools = "0.4.1"
tar = "0.4.0"
toml = "0.1.27"
rustup-utils = { path = "../rustup-utils", version = "0.1.9" }

[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"
2 changes: 1 addition & 1 deletion src/rustup-mock/src/clitools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/rustup-mock/src/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
//! 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;
use std::io::{Read, Write};
use tempdir::TempDir;
use openssl::crypto::hash;
use rustup_utils::sha2::{Sha256, Digest};
use itertools::Itertools;
use toml;
use flate2;
Expand Down Expand Up @@ -304,9 +304,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
}
Expand Down
Loading