Skip to main content

luct_scanner/
config.rs

1use derive_builder::Builder;
2use serde::{Deserialize, Serialize};
3use url::Url;
4use web_time::Duration;
5
6/// Configuration values of the [`ScannerConfig`].
7///
8/// These values determine, how the [`Scanner`](crate::Scanner) behaves.
9#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Builder)]
10#[builder(setter(into))]
11pub struct ScannerConfig {
12    /// Set whether the certificate chain should be validated by the scanner
13    ///
14    /// This is generally not necessary inside a browser, as the chain has already
15    /// been validated by the browser, but e.g. it might make sense when fetching the
16    /// chain from a file system.
17    #[builder(default)]
18    pub(crate) validate_cert_chain: bool,
19
20    /// The url of the otlsp proxy
21    ///
22    /// If unset, no proxy is used
23    #[builder(default = "None")]
24    pub(crate) otlsp_url: Option<Url>,
25
26    /// Time until an otlsp connection is considered stale and will not be reused
27    #[builder(default = "Duration::from_secs(30)")]
28    pub(crate) otlsp_connection_timeout: Duration,
29
30    /// A STH that is younger than this time is considered fresh an STH that is older mature
31    ///
32    /// The policy evaluation requires a fresh STH to show that the log is still active
33    /// If the STH against which the inclusion proof has been made is mature, it will not require
34    /// additional STH validations
35    #[builder(default = "Duration::from_secs(60 * 60 * 24)")]
36    pub(crate) sth_freshness_threshold: Duration,
37
38    /// If the logs newest STH is older than this time, it will attempt to fetch a fresher value
39    ///
40    /// This value must not be larger than `sth_freshness_theshold`
41    #[builder(default = "Duration::from_secs(60 * 60 * 8)")]
42    pub(crate) sth_update_threshold: Duration,
43}
44
45impl ScannerConfig {
46    /// Return a [`ScannerConfigBuilder`]
47    pub fn builder() -> ScannerConfigBuilder {
48        ScannerConfigBuilder::default()
49    }
50
51    /// Returns `true`, if certificate chain validation is activated
52    pub fn validate_cert_chain(&self) -> bool {
53        self.validate_cert_chain
54    }
55
56    /// Returns the [`Url`] of the oblivious TLS proxy, if it exists
57    pub fn otlsp_url(&self) -> &Option<Url> {
58        &self.otlsp_url
59    }
60
61    /// Return the timeout value, after which a connection to an oblivious
62    /// TLS proxy is considered stale
63    pub fn otlsp_connection_timeout(&self) -> &Duration {
64        &self.otlsp_connection_timeout
65    }
66}