Skip to content

Commit cfce35c

Browse files
committed
Make sure PEM contains certificates
1 parent 2d894b4 commit cfce35c

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

rust/truststore-merger/src/cli_args.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{fs, path::PathBuf};
22

3-
use anyhow::Context;
3+
use anyhow::{Context, ensure};
44
use clap::Parser;
55
use openssl::x509::X509;
66

@@ -68,12 +68,21 @@ impl CertInput {
6868
fs::read(self.path()).with_context(|| format!("failed to read file from {self:?}"))?;
6969

7070
match self {
71-
CertInput::Pem(_) => parse_pem_contents(&file_contents).with_context(|| {
72-
format!(
73-
"failed to parse PEM contents from {path:?}",
71+
CertInput::Pem(_) => {
72+
let certs = parse_pem_contents(&file_contents).with_context(|| {
73+
format!(
74+
"failed to parse PEM contents from {path:?}",
75+
path = self.path()
76+
)
77+
})?;
78+
ensure!(
79+
!certs.is_empty(),
80+
"The PEM file {path:?} contained no certificates",
7481
path = self.path()
75-
)
76-
}),
82+
);
83+
84+
Ok(certs)
85+
}
7786
CertInput::Pkcs12(Pkcs12Source { password, .. }) => {
7887
parse_pkcs12_file_workaround(&file_contents, password)
7988
}

rust/truststore-merger/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ pub fn main() -> anyhow::Result<()> {
4545

4646
let mut certificates = HashMap::<Vec<u8>, X509>::new();
4747
for (source, certificates_list) in certificate_sources.into_iter() {
48+
info!(?source, "Importing certificates");
49+
4850
for certificate in certificates_list {
4951
let sha256 = certificate.sha256_digest()?;
5052

0 commit comments

Comments
 (0)