Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
eatradish committed May 6, 2024
1 parent 5f3377b commit 55373b5
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions oma-refresh/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ impl InReleaseVerifier {
_mirror: mirror.to_string(),
})
}

pub fn str(mirror: &str, gpg: &str) -> VerifyResult<Self> {
let mut certs: Vec<Cert> = Vec::new();
let cert = CertParser::from_bytes(gpg.as_bytes())?;
for maybe_cert in cert {
certs.push(maybe_cert?);
}

Ok(InReleaseVerifier {
certs,
_mirror: mirror.to_string(),
})
}
}

impl VerificationHelper for InReleaseVerifier {
Expand Down Expand Up @@ -101,6 +114,7 @@ pub fn verify<P: AsRef<Path>>(
}

let mut cert_files = vec![];
let mut trust = None;

if let Some(trust_files) = trust_files {
let trust_files = trust_files.split(',');
Expand All @@ -109,7 +123,12 @@ pub fn verify<P: AsRef<Path>>(
if p.is_absolute() {
cert_files.push(p.to_path_buf());
} else {
cert_files.push(rootfs.join("etc/apt/trusted.gpg.d").join(file))
let p = rootfs.join("etc/apt/trusted.gpg.d").join(file);
if p.exists() {
cert_files.push(p.to_path_buf());
} else {
trust = Some(file)
}
}
}
} else {
Expand Down Expand Up @@ -138,7 +157,11 @@ pub fn verify<P: AsRef<Path>>(
let mut v = VerifierBuilder::from_bytes(s.as_bytes())?.with_policy(
&p,
None,
InReleaseVerifier::new(&cert_files, mirror)?,
if let Some(t) = trust {
InReleaseVerifier::str(mirror, t)?
} else {
InReleaseVerifier::new(&cert_files, mirror)?
},
)?;

let mut res = String::new();
Expand Down

0 comments on commit 55373b5

Please sign in to comment.