Skip to content

Commit

Permalink
tuftool: Require flag to download root.json
Browse files Browse the repository at this point in the history
If the user doesn't provide a root.json require the
--allow-root-download flag before downloading a remote root.json, and
follow it up with a big warning.

Fixes #353

Signed-off-by: Samuel Mendoza-Jonas <samjonas@amazon.com>
  • Loading branch information
sam-aws committed Oct 16, 2019
1 parent d98805d commit 660ff95
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions workspaces/tuftool/src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,30 @@ pub(crate) struct DownloadArgs {
#[structopt(short = "t", long = "target-url")]
target_base_url: String,

/// Allow downloading the root.json file (unsafe)
#[structopt(long)]
allow_root_download: bool,

/// Output directory of targets
indir: PathBuf,
}

fn root_warning(path: &PathBuf) {
#[rustfmt::skip]
eprintln!("\
=================================================================
WARNING: Downloading root.json to {:?}
This is unsafe and will not establish trust, use only for testing
=================================================================",
path);
}

impl DownloadArgs {
pub(crate) fn run(&self) -> Result<()> {
// use local root.json or download from repository
let root_path = if let Some(path) = &self.root {
PathBuf::from(path)
} else {
} else if self.allow_root_download {
let name = if let Some(version) = self.root_version {
format!("{}.root.json", version)
} else {
Expand All @@ -53,7 +67,9 @@ impl DownloadArgs {
.context(error::UrlParse {
url: &self.metadata_base_url,
})?;
println!("Downloading {} to {:?}", &name, &path);

root_warning(&path);

let mut f = OpenOptions::new()
.write(true)
.create(true)
Expand All @@ -64,6 +80,9 @@ impl DownloadArgs {
.copy_to(&mut f)
.context(error::ReqwestCopy)?;
path
} else {
eprintln!("No root.json available");
std::process::exit(1);
};

// load repository
Expand Down

0 comments on commit 660ff95

Please sign in to comment.