Skip to content

Commit

Permalink
feat(sender): allow adding additional root certificates
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Jan 30, 2024
1 parent c216adc commit dd684e2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions common/src/sender/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
pub mod provider;

mod error;

pub use error::*;
use std::path::PathBuf;

use crate::sender::provider::{TokenInjector, TokenProvider};
use anyhow::Context;
use reqwest::{header, IntoUrl, Method, RequestBuilder};
use std::sync::Arc;
use std::time::Duration;
Expand All @@ -19,6 +22,7 @@ pub struct HttpSender {
pub struct Options {
pub connect_timeout: Option<Duration>,
pub timeout: Option<Duration>,
pub additional_root_certificates: Vec<PathBuf>,
}

const USER_AGENT: &str = concat!("CSAF-Walker/", env!("CARGO_PKG_VERSION"));
Expand All @@ -41,6 +45,13 @@ impl HttpSender {
client = client.timeout(timeout);
}

for cert in options.additional_root_certificates {
let cert = std::fs::read(&cert)
.with_context(|| format!("Reading certificate: {}", cert.display()))?;
let cert = reqwest::tls::Certificate::from_pem(&cert)?;
client = client.add_root_certificate(cert);
}

Ok(Self {
client: client.build()?,
provider: Arc::new(provider),
Expand Down
6 changes: 6 additions & 0 deletions extras/src/visitors/send/clap.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::visitors::SendVisitor;
use reqwest::Url;
use std::path::PathBuf;
use walker_common::sender::{self, provider::OpenIdTokenProviderConfigArguments, HttpSender};

#[derive(Debug, clap::Parser)]
Expand All @@ -16,6 +17,10 @@ pub struct SendArguments {
#[arg(id = "sender-timeout", long, default_value = "5m")]
pub timeout: humantime::Duration,

/// Additional root certificates
#[arg(id = "sender-root-certificate", long)]
pub additional_root_certificates: Vec<PathBuf>,

/// Number of retries in case of temporary failures
#[arg(id = "sender-retries", long, default_value = "0")]
pub retries: usize,
Expand All @@ -36,6 +41,7 @@ impl SendArguments {
sender::Options {
connect_timeout: Some(self.connect_timeout.into()),
timeout: Some(self.timeout.into()),
additional_root_certificates: self.additional_root_certificates,
},
)
.await?;
Expand Down

0 comments on commit dd684e2

Please sign in to comment.