Skip to content

Commit 2ae79a8

Browse files
authored
fix(oma-refresh,oma-repo-vertify)!: handle deb822 Signed-By is empty (#405)
1 parent 32d3706 commit 2ae79a8

File tree

2 files changed

+32
-28
lines changed

2 files changed

+32
-28
lines changed

oma-refresh/src/sourceslist.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,7 @@ impl MirrorSource<'_, '_> {
264264
}
265265

266266
pub fn signed_by(&self) -> Option<&Signature> {
267-
self.sources.iter().find_map(|x| {
268-
if let Some(x) = &x.signed_by() {
269-
Some(x)
270-
} else {
271-
None
272-
}
273-
})
267+
self.sources.iter().find_map(|x| x.signed_by().as_ref())
274268
}
275269

276270
pub fn url(&self) -> &str {

oma-repo-verify/src/lib.rs

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -197,16 +197,6 @@ fn find_certs(
197197
) -> VerifyResult<(Vec<PathBuf>, Option<&str>)> {
198198
let rootfs = rootfs.as_ref();
199199

200-
let mut dir = std::fs::read_dir(rootfs.join("etc/apt/trusted.gpg.d"))
201-
.map_err(|_| VerifyError::TrustedDirNotExist)?
202-
.collect::<Vec<_>>();
203-
204-
let etc_keyring = std::fs::read_dir(rootfs.join("etc/apt/keyrings"));
205-
206-
if let Ok(keyring) = etc_keyring {
207-
dir.extend(keyring);
208-
}
209-
210200
let mut certs = vec![];
211201
let mut deb822_inner_signed_by_str = None;
212202

@@ -217,6 +207,10 @@ fn find_certs(
217207
debug!(deb822_inner_signed_by_str);
218208
}
219209
Signature::KeyPath(paths) => {
210+
if paths.is_empty() {
211+
certs = find_default_dir_certs(rootfs)?;
212+
}
213+
220214
for p in paths {
221215
if p.is_absolute() {
222216
certs.push(p.to_path_buf());
@@ -227,20 +221,36 @@ fn find_certs(
227221
}
228222
}
229223
} else {
230-
for i in dir.iter().flatten() {
231-
let path = i.path();
232-
let ext = path.extension().and_then(|x| x.to_str());
233-
if ext == Some("gpg") || ext == Some("asc") {
234-
certs.push(i.path().to_path_buf());
235-
}
236-
}
224+
certs = find_default_dir_certs(rootfs)?;
225+
}
237226

238-
let trust_main = rootfs.join("etc/apt/trusted.gpg").to_path_buf();
227+
Ok((certs, deb822_inner_signed_by_str))
228+
}
229+
230+
fn find_default_dir_certs(rootfs: &Path) -> Result<Vec<PathBuf>, VerifyError> {
231+
let mut certs = vec![];
232+
let mut dir = std::fs::read_dir(rootfs.join("etc/apt/trusted.gpg.d"))
233+
.map_err(|_| VerifyError::TrustedDirNotExist)?
234+
.collect::<Vec<_>>();
235+
let etc_keyring = std::fs::read_dir(rootfs.join("etc/apt/keyrings"));
239236

240-
if trust_main.is_file() {
241-
certs.push(trust_main);
237+
if let Ok(keyring) = etc_keyring {
238+
dir.extend(keyring);
239+
}
240+
241+
for i in dir.iter().flatten() {
242+
let path = i.path();
243+
let ext = path.extension().and_then(|x| x.to_str());
244+
if ext == Some("gpg") || ext == Some("asc") {
245+
certs.push(i.path().to_path_buf());
242246
}
243247
}
244248

245-
Ok((certs, deb822_inner_signed_by_str))
249+
let trust_main = rootfs.join("etc/apt/trusted.gpg").to_path_buf();
250+
251+
if trust_main.is_file() {
252+
certs.push(trust_main);
253+
}
254+
255+
Ok(certs)
246256
}

0 commit comments

Comments
 (0)