Skip to content

Commit 43acafd

Browse files
committed
Fetch intermediates if configured
1 parent 744573a commit 43acafd

3 files changed

Lines changed: 45 additions & 4 deletions

File tree

upki/src/intermediates.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,34 @@
1+
use std::process::ExitCode;
2+
13
use serde::{Deserialize, Serialize};
24

5+
use crate::Config;
6+
use crate::data::{MANIFEST_JSON, Manifest, fetch_inner};
7+
use crate::revocation::Error;
8+
9+
/// Update the local intermediates cache by fetching updates over the network.
10+
///
11+
/// `dry_run` means this call fetches the new manifest, but does not fetch any
12+
/// required files; but the necessary files are printed to stdout. Therefore
13+
/// such a call is not completely "dry" -- perhaps "moist".
14+
pub async fn fetch(dry_run: bool, config: &Config) -> Result<ExitCode, Error> {
15+
let Some(intermediates) = &config.intermediates else {
16+
return Ok(ExitCode::SUCCESS);
17+
};
18+
let mut manifest_path = config.intermediates_cache_dir();
19+
manifest_path.push(MANIFEST_JSON);
20+
let old_manifest = Manifest::from_file(&manifest_path).ok();
21+
let manifest_url = format!("{}{MANIFEST_JSON}", intermediates.fetch_url);
22+
fetch_inner(
23+
dry_run,
24+
&intermediates.fetch_url,
25+
manifest_url,
26+
&old_manifest,
27+
config.intermediates_cache_dir(),
28+
)
29+
.await
30+
}
31+
332
/// Details about intermediate preloading.
433
#[derive(Debug, Deserialize, Serialize)]
534
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
@@ -14,7 +43,7 @@ impl Default for IntermediatesConfig {
1443
fn default() -> Self {
1544
Self {
1645
enabled: false,
17-
fetch_url: "https://upki.rustls.dev/".into(),
46+
fetch_url: "https://upki.rustls.dev/intermediates/".into(),
1847
}
1948
}
2049
}

upki/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ impl Config {
6161
pub(crate) fn revocation_cache_dir(&self) -> PathBuf {
6262
self.cache_dir.join("revocation")
6363
}
64+
65+
fn intermediates_cache_dir(&self) -> PathBuf {
66+
self.cache_dir.join("intermediates")
67+
}
6468
}
6569

6670
/// How the path to a configuration file was decided upon.

upki/src/main.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use clap::{Parser, Subcommand};
88
use eyre::{Context, Report};
99
use rustls_pki_types::CertificateDer;
1010
use rustls_pki_types::pem::PemObject;
11-
use upki::revocation::{Index, Manifest, RevocationCheckInput, fetch};
12-
use upki::{Config, ConfigPath};
11+
use upki::revocation::{Index, Manifest, RevocationCheckInput};
12+
use upki::{Config, ConfigPath, intermediates, revocation};
1313

1414
#[tokio::main(flavor = "current_thread")]
1515
async fn main() -> Result<ExitCode, Report> {
@@ -33,7 +33,15 @@ async fn main() -> Result<ExitCode, Report> {
3333
let config = Config::from_file_or_default(&config_path)?;
3434

3535
Ok(match args.command {
36-
Command::Fetch { dry_run } => fetch(dry_run, &config).await?,
36+
Command::Fetch { dry_run } => {
37+
match (
38+
revocation::fetch(dry_run, &config).await?,
39+
intermediates::fetch(dry_run, &config).await?,
40+
) {
41+
(ExitCode::SUCCESS, ExitCode::SUCCESS) => ExitCode::SUCCESS,
42+
(..) => ExitCode::FAILURE,
43+
}
44+
}
3745
Command::Verify => Manifest::from_config(&config)?.verify(&config)?,
3846
Command::ShowConfigPath => unreachable!(),
3947
Command::ShowConfig => {

0 commit comments

Comments
 (0)