Skip to content

Commit

Permalink
Add a flag to manually specify roots. (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
kixelated authored Oct 17, 2023
1 parent c5b3e5c commit a30f313
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
7 changes: 7 additions & 0 deletions moq-relay/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ pub struct Config {
#[arg(long)]
pub tls_key: Vec<path::PathBuf>,

/// Use the TLS root at this path, encoded as PEM.
///
/// This value can be provided multiple times for multiple roots.
/// If this is empty, system roots will be used instead
#[arg(long)]
pub tls_root: Vec<path::PathBuf>,

/// Optional: Use the moq-api via HTTP to store origin information.
#[arg(long)]
pub api: Option<Url>,
Expand Down
19 changes: 16 additions & 3 deletions moq-relay/src/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,22 @@ impl Tls {
// Create a list of acceptable root certificates.
let mut roots = RootCertStore::empty();

// Add the platform's native root certificates.
for cert in rustls_native_certs::load_native_certs().context("could not load platform certs")? {
roots.add(&Certificate(cert.0)).context("failed to add root cert")?;
if config.tls_root.is_empty() {
// Add the platform's native root certificates.
for cert in rustls_native_certs::load_native_certs().context("could not load platform certs")? {
roots.add(&Certificate(cert.0)).context("failed to add root cert")?;
}
} else {
// Add the specified root certificates.
for root in &config.tls_root {
let root = fs::File::open(root).context("failed to open root cert file")?;
let mut root = io::BufReader::new(root);
let root = rustls_pemfile::certs(&mut root).context("failed to read root cert")?;
anyhow::ensure!(root.len() == 1, "expected a single root cert");
let root = Certificate(root[0].to_owned());

roots.add(&root).context("failed to add root cert")?;
}
}

let certs = Self {
Expand Down

0 comments on commit a30f313

Please sign in to comment.