Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions omaha/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl FromStr for ActionEvent {
"postinstall" => ActionEvent::PostInstall,
"update" => ActionEvent::Update,

_ => return Err(format!("unknown success action \"{}\"", s)),
_ => return Err(format!("unknown success action \"{s}\"")),
})
}
}
Expand Down Expand Up @@ -98,7 +98,7 @@ impl FromStr for SuccessAction {
"exitsilently" => SuccessAction::ExitSilently,
"exitsilentlyonlaunchcmd" => SuccessAction::ExitSilentlyOnLaunchCommand,

_ => return Err(format!("unknown success action \"{}\"", s)),
_ => return Err(format!("unknown success action \"{s}\"")),
})
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/bin/download_sysext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl Package<'_> {
) {
Ok(ok) => ok,
Err(err) => {
error!("Downloading failed with error {}", err);
error!("Downloading failed with error {err}");
self.status = PackageStatus::DownloadFailed;
bail!("unable to download data(url {})", self.url);
}
Expand All @@ -130,10 +130,10 @@ impl Package<'_> {

fn verify_checksum(&mut self, calculated_sha256: omaha::Hash<omaha::Sha256>, calculated_sha1: omaha::Hash<omaha::Sha1>) -> bool {
debug!(" expected sha256: {:?}", self.hash_sha256);
debug!(" calculated sha256: {}", calculated_sha256);
debug!(" calculated sha256: {calculated_sha256}");
debug!(" sha256 match? {}", self.hash_sha256 == Some(calculated_sha256.clone()));
debug!(" expected sha1: {:?}", self.hash_sha1);
debug!(" calculated sha1: {}", calculated_sha1);
debug!(" calculated sha1: {calculated_sha1}");
debug!(" sha1 match? {}", self.hash_sha1 == Some(calculated_sha1.clone()));

if self.hash_sha256.is_some() && self.hash_sha256 != Some(calculated_sha256.clone()) || self.hash_sha1.is_some() && self.hash_sha1 != Some(calculated_sha1.clone()) {
Expand Down Expand Up @@ -198,7 +198,7 @@ impl Package<'_> {
}
};

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

self.status = PackageStatus::Verified;
Ok(datablobspath)
Expand Down Expand Up @@ -255,7 +255,7 @@ where
U: reqwest::IntoUrl + From<U> + std::clone::Clone + std::fmt::Debug,
Url: From<U>,
{
let r = ue_rs::download_and_hash(client, input_url.clone(), path, None, None).context(format!("unable to download data(url {:?})", input_url))?;
let r = ue_rs::download_and_hash(client, input_url.clone(), path, None, None).context(format!("unable to download data(url {input_url:?})"))?;

Ok(Package {
name: Cow::Borrowed(path.file_name().unwrap_or(OsStr::new("fakepackage")).to_str().unwrap_or("fakepackage")),
Expand All @@ -280,7 +280,7 @@ fn do_download_verify(pkg: &mut Package<'_>, output_filename: Option<String>, ou
let datablobspath = pkg.verify_signature_on_disk(&pkg_unverified, pubkey_file).context(format!("unable to verify signature \"{}\"", pkg.name))?;

// write extracted data into the final data.
debug!("data blobs written into file {:?}", pkg_verified);
debug!("data blobs written into file {pkg_verified:?}");
fs::rename(datablobspath, pkg_verified)?;

Ok(())
Expand Down Expand Up @@ -339,7 +339,7 @@ fn main() -> Result<(), Box<dyn Error>> {
env_logger::init();

let args: Args = argh::from_env();
println!("{:?}", args);
println!("{args:?}");

if args.payload_url.is_none() && !args.take_first_match && args.target_filename.is_some() {
return Err("--target-filename can only be specified with --take-first-match".into());
Expand Down Expand Up @@ -411,7 +411,7 @@ fn main() -> Result<(), Box<dyn Error>> {
};

let response_text = res_local.ok_or(anyhow!("failed to get response text"))?;
debug!("response_text: {:?}", response_text);
debug!("response_text: {response_text:?}");

////
// parse response
Expand All @@ -420,7 +420,7 @@ fn main() -> Result<(), Box<dyn Error>> {

let mut pkgs_to_dl = get_pkgs_to_download(&resp, &glob_set)?;

debug!("pkgs:\n\t{:#?}", pkgs_to_dl);
debug!("pkgs:\n\t{pkgs_to_dl:#?}");
debug!("");

////
Expand Down
10 changes: 5 additions & 5 deletions src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn hash_on_disk<T: omaha::HashAlgo>(path: &Path, maxlen: Option<usize>) -> R

let mut databuf = vec![0u8; chunklen];

freader.read_exact(&mut databuf).context(format!("failed to read_exact(chunklen {:?})", chunklen))?;
freader.read_exact(&mut databuf).context(format!("failed to read_exact(chunklen {chunklen:?})"))?;

maxlen_to_read -= chunklen;

Expand Down Expand Up @@ -97,11 +97,11 @@ where
let calculated_sha256 = hash_on_disk::<omaha::Sha256>(path, None)?;
let calculated_sha1 = hash_on_disk::<omaha::Sha1>(path, None)?;

debug!(" expected sha256: {:?}", expected_sha256);
debug!(" calculated sha256: {}", calculated_sha256);
debug!(" expected sha256: {expected_sha256:?}");
debug!(" calculated sha256: {calculated_sha256}");
debug!(" sha256 match? {}", expected_sha256 == Some(calculated_sha256.clone()));
debug!(" expected sha1: {:?}", expected_sha1);
debug!(" calculated sha1: {}", calculated_sha1);
debug!(" expected sha1: {expected_sha1:?}");
debug!(" calculated sha1: {calculated_sha1}");
debug!(" sha1 match? {}", expected_sha1 == Some(calculated_sha1.clone()));

if expected_sha256.is_some() && expected_sha256 != Some(calculated_sha256.clone()) {
Expand Down
2 changes: 1 addition & 1 deletion src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub fn perform(client: &reqwest::blocking::Client, parameters: Parameters<'_>) -
};

// TODO: remove
println!("request body:\n\t{}", req_body);
println!("request body:\n\t{req_body}");
println!();

#[rustfmt::skip]
Expand Down
10 changes: 3 additions & 7 deletions test/crau_verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,17 @@ fn main() -> Result<(), Box<dyn Error>> {
let sigdata = match delta_update::parse_signature_data(&sigbytes, hdhashvec.as_slice(), PUBKEY_FILE) {
Ok(data) => data,
_ => {
return Err(format!(
"unable to parse and verify signature, sigbytes ({:?}), hdhash ({:?}), pubkey_path ({:?})",
sigbytes, hdhash, PUBKEY_FILE,
)
.into());
return Err(format!("unable to parse and verify signature, sigbytes ({sigbytes:?}), hdhash ({hdhash:?}), pubkey_path ({PUBKEY_FILE:?})",).into());
}
};

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

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

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

Ok(())
}
21 changes: 10 additions & 11 deletions update-format-crau/src/delta_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ pub fn get_header_data_length(header: &DeltaUpdateFileHeader, manifest: &proto::
// Return path to data blobs, without header, manifest, or signatures.
pub fn get_data_blobs<'a>(f: &'a File, header: &'a DeltaUpdateFileHeader, manifest: &proto::DeltaArchiveManifest, tmpfile: &Path) -> Result<()> {
let tmpdir = tmpfile.parent().ok_or(anyhow!("unable to get parent directory"))?;
fs::create_dir_all(tmpdir).context(format!("failed to create directory {:?}", tmpdir))?;
let mut outfile = File::create(tmpfile).context(format!("failed to create file {:?}", tmpfile))?;
fs::create_dir_all(tmpdir).context(format!("failed to create directory {tmpdir:?}"))?;
let mut outfile = File::create(tmpfile).context(format!("failed to create file {tmpfile:?}"))?;

// Read from the beginning of header, which means buffer including only data blobs.
// It means it is necessary to call header.translate_offset(), in contrast to
Expand All @@ -137,21 +137,20 @@ pub fn get_data_blobs<'a>(f: &'a File, header: &'a DeltaUpdateFileHeader, manife

let translated_offset = header.translate_offset(data_offset.into());
f.read_exact_at(&mut partdata, translated_offset).context(format!(
"failed to read data with length {:?} at {:?}",
data_length, translated_offset
"failed to read data with length {data_length:?} at {translated_offset:?}",
))?;

// In case of bzip2-compressed chunks, extract.
if pop.type_.ok_or(anyhow!("unable to get type_ from partition operations"))? == proto::install_operation::Type::REPLACE_BZ.into() {
let mut bzdecoder = BzDecoder::new(&partdata[..]);
let mut partdata_unpacked = Vec::new();
bzdecoder.read_to_end(&mut partdata_unpacked).context(format!("failed to unpack bzip2ed data at offset {:?}", translated_offset))?;
bzdecoder.read_to_end(&mut partdata_unpacked).context(format!("failed to unpack bzip2ed data at offset {translated_offset:?}"))?;

outfile.write_all_at(&partdata_unpacked, start_block).context(format!("failed to copy unpacked data at offset {:?}", translated_offset))?;
outfile.write_all_at(&partdata_unpacked, start_block).context(format!("failed to copy unpacked data at offset {translated_offset:?}"))?;
} else {
outfile.write_all_at(&partdata, start_block).context(format!("failed to copy plain data at offset {:?}", translated_offset))?;
outfile.write_all_at(&partdata, start_block).context(format!("failed to copy plain data at offset {translated_offset:?}"))?;
}
outfile.flush().context(format!("failed to flush at offset {:?}", translated_offset))?;
outfile.flush().context(format!("failed to flush at offset {translated_offset:?}"))?;
}

Ok(())
Expand Down Expand Up @@ -204,23 +203,23 @@ pub fn verify_sig_pubkey(digest: &[u8], sig: &Signature, pubkeyfile: &str) -> Re
_ => bail!("empty signature data, nothing to verify"),
};

debug!("digest: {:?}", digest);
debug!("digest: {digest:?}");
debug!("data: {:?}", sig.data());
debug!("special_fields: {:?}", sig.special_fields());

// verify signature with pubkey
let pkcspem_pubkey = match get_public_key_pkcs_pem(pubkeyfile, KeyTypePkcs8) {
Ok(key) => key,
Err(err) => {
bail!("failed to get PKCS8 PEM public key ({:?}) with error {:?}", pubkeyfile, err);
bail!("failed to get PKCS8 PEM public key ({pubkeyfile:?}) with error {err:?}");
}
};

let res_verify = verify_sig::verify_rsa_pkcs_prehash(digest, sig.data(), pkcspem_pubkey);
match res_verify {
Ok(res_verify) => res_verify,
Err(err) => {
bail!("verify_rsa_pkcs signature ({:?}) failed with error {:?}", sig, err);
bail!("verify_rsa_pkcs signature ({sig:?}) failed with error {err:?}");
}
};

Expand Down
20 changes: 10 additions & 10 deletions update-format-crau/src/verify_sig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn verify_rsa_pkcs_buf(databuf: &[u8], signature: &[u8], public_key: RsaPubl
databuf,
&pkcs1v15::Signature::try_from(signature).context(anyhow!("unable to convert signature into pkcs1v15::Signature"))?,
)
.context(format!("failed to verify signature ({:?})", signature))
.context(format!("failed to verify signature ({signature:?})"))
}

// Takes a data buffer, signature and a public key, to verify the data
Expand All @@ -62,37 +62,37 @@ pub fn verify_rsa_pkcs_prehash(digestbuf: &[u8], signature: &[u8], public_key: R
digestbuf,
&pkcs1v15::Signature::try_from(signature).context(anyhow!("unable to convert signature into pkcs1v15::Signature"))?,
)
.context(format!("failed to verify_prehash signature ({:?})", signature))
.context(format!("failed to verify_prehash signature ({signature:?})"))
}

pub fn get_private_key_pkcs_pem(private_key_path: &str, key_type: KeyType) -> Result<RsaPrivateKey> {
let private_key_buf = fs::read_to_string(private_key_path).context(format!("failed to read private key from path {:?}", private_key_path))?;
let private_key_buf = fs::read_to_string(private_key_path).context(format!("failed to read private key from path {private_key_path:?}"))?;
let out_key = match key_type {
KeyType::KeyTypePkcs1 => RsaPrivateKey::from_pkcs1_pem(private_key_buf.as_str()).or_else(|error| {
bail!("failed to parse PKCS1 PEM message: {:?}", error);
bail!("failed to parse PKCS1 PEM message: {error:?}");
}),
KeyType::KeyTypePkcs8 => RsaPrivateKey::from_pkcs8_pem(private_key_buf.as_str()).or_else(|error| {
bail!("failed to parse PKCS8 PEM message: {:?}", error);
bail!("failed to parse PKCS8 PEM message: {error:?}");
}),
KeyType::KeyTypeNone => {
bail!("invalid key type: {:?}", key_type);
bail!("invalid key type: {key_type:?}");
}
};

out_key
}

pub fn get_public_key_pkcs_pem(public_key_path: &str, key_type: KeyType) -> Result<RsaPublicKey> {
let public_key_buf = fs::read_to_string(public_key_path).context(format!("failed to read public key from path {:?}", public_key_path))?;
let public_key_buf = fs::read_to_string(public_key_path).context(format!("failed to read public key from path {public_key_path:?}"))?;
let out_key = match key_type {
KeyType::KeyTypePkcs1 => RsaPublicKey::from_pkcs1_pem(public_key_buf.as_str()).or_else(|error| {
bail!("failed to parse PKCS1 PEM message: {:?}", error);
bail!("failed to parse PKCS1 PEM message: {error:?}");
}),
KeyType::KeyTypePkcs8 => RsaPublicKey::from_public_key_pem(public_key_buf.as_str()).or_else(|error| {
bail!("failed to parse PKCS8 PEM message: {:?}", error);
bail!("failed to parse PKCS8 PEM message: {error:?}");
}),
KeyType::KeyTypeNone => {
bail!("invalid key type: {:?}", key_type);
bail!("invalid key type: {key_type:?}");
}
};

Expand Down
Loading