Skip to content

Commit

Permalink
download_sysext: read delta update file after downloading
Browse files Browse the repository at this point in the history
Read delta update file after downloading, and do not store sigfiles.
  • Loading branch information
dongsupark committed Sep 27, 2023
1 parent 59eda33 commit c1fd110
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/bin/download_sysext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::path::Path;
use std::fs::File;
use std::fs;
use std::io;
use std::io::Write;

#[macro_use]
extern crate log;
Expand Down Expand Up @@ -132,7 +131,6 @@ async fn main() -> Result<(), Box<dyn Error>> {
println!();

const PUBKEY_FILE: &str = "../src/testdata/public_key_test_pkcs8.pem";
const SIGFILE: &str = "./testsigfile";

////
// download
Expand All @@ -145,9 +143,6 @@ async fn main() -> Result<(), Box<dyn Error>> {
let path = unverified_dir.join(&*pkg.name);
let mut file = File::create(path.clone())?;

// Read update payload from file, read delta update header from the payload.
let updata = io::read_to_string(file.try_clone().unwrap());

println!("creating {}...", path.display());

let res = ue_rs::download_and_hash(&client, pkg.url, &mut file).await?;
Expand All @@ -156,24 +151,21 @@ async fn main() -> Result<(), Box<dyn Error>> {
println!("\tcalculated sha256: {}", res.hash);
println!("\tsha256 match? {}", pkg.hash == res.hash);

// Read update payload from file, read delta update header from the payload.
let updata = io::read_to_string(res.data.try_clone().unwrap());

let header = delta_update::read_delta_update_header(res.data)?;

// Extract signature from header.
let sigbytes = delta_update::get_signatures_bytes(res.data, &header)?;

// Parse signature data from the signature containing data, version, special fields.
let sigdata = match delta_update::parse_signature_data(updata.unwrap().as_bytes(), &sigbytes, PUBKEY_FILE) {
let _sigdata = match delta_update::parse_signature_data(updata.unwrap().as_bytes(), &sigbytes, PUBKEY_FILE) {
Some(data) => Box::leak(data),
_ => return Err("unable to parse signature data".into()),
};

println!("Parsed signature data from file {:?}", path);

// Store signature into a file.
let mut sigfile = File::create(SIGFILE.clone())?;
let _ = sigfile.write_all(sigdata);

println!("Wrote signature data into file {:?}", SIGFILE);
}

Ok(())
Expand Down

0 comments on commit c1fd110

Please sign in to comment.