-
Notifications
You must be signed in to change notification settings - Fork 9
Support fetching intermediates #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ctz
wants to merge
9
commits into
main
Choose a base branch
from
jbp-intermediate-fetch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2542b09
Extract parameters to `fetch()` for reuse
ctz 40c9391
Customise revocation-specific behaviour in `fetch()`
ctz 6d08a64
Generalise and reuse `Manifest` and associated
ctz 2cb4e6c
Support configuration of intermediate fetching
ctz 83bd503
Hook up intermediates fetching
ctz baf1994
Align integration tests with how mirrors now work
ctz b7e9619
Allow test configs to be customised per-test
ctz 620f190
Test intermediate fetching
ctz 816722c
Avoid using `ExitCode::SUCCESS` as unit type
ctz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,7 @@ cache-dir = "not-exist/" | |
|
|
||
| [revocation] | ||
| fetch-url = "" | ||
|
|
||
| [intermediates] | ||
| enabled = false | ||
| fetch-url = "" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| #[cfg(feature = "__fetch")] | ||
| use std::{fs::File, io::BufReader, path::PathBuf}; | ||
|
|
||
| use chrono::{DateTime, Utc}; | ||
| use serde::{Deserialize, Serialize}; | ||
| use tracing::info; | ||
|
|
||
| use crate::revocation::Error; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: this seems a little wrong? |
||
|
|
||
| /// The structure contained in a manifest.json | ||
| #[derive(Clone, Debug, Deserialize, Serialize)] | ||
| pub struct Manifest { | ||
| /// When this file was generated. | ||
| /// | ||
| /// UNIX timestamp in seconds. | ||
| pub generated_at: u64, | ||
|
|
||
| /// Some human-readable text. | ||
| pub comment: String, | ||
|
|
||
| /// List of required files. | ||
| #[serde(alias = "filters")] | ||
| pub files: Vec<ManifestFile>, | ||
| } | ||
|
|
||
| impl Manifest { | ||
| #[cfg(feature = "__fetch")] | ||
| pub(crate) fn from_file(file_name: PathBuf) -> Result<Self, Error> { | ||
| let file = match File::open(&file_name) { | ||
| Ok(f) => f, | ||
| Err(error) => { | ||
| return Err(Error::FileRead { | ||
| error, | ||
| path: Some(file_name), | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| serde_json::from_reader(BufReader::new(file)).map_err(|error| Error::FileDecode { | ||
| error: Box::new(error), | ||
| path: Some(file_name), | ||
| }) | ||
| } | ||
|
|
||
| /// Logs metadata fields in this manifest. | ||
| pub fn introduce(&self) -> Result<(), Error> { | ||
| let dt = match DateTime::<Utc>::from_timestamp(self.generated_at as i64, 0) { | ||
| Some(dt) => dt.to_rfc3339(), | ||
| None => { | ||
| return Err(Error::InvalidTimestamp { | ||
| input: self.generated_at.to_string(), | ||
| context: "manifest generated (in s)", | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| info!(comment = self.comment, date = dt, "parsed manifest"); | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| /// Manifest data for a single manifest file. | ||
| #[derive(Clone, Debug, Deserialize, Serialize)] | ||
| pub struct ManifestFile { | ||
| /// Relative filename. | ||
| /// | ||
| /// This is also the suggested local filename. | ||
| pub filename: String, | ||
|
|
||
| /// File size, indicative. Allows a fetcher to predict data usage. | ||
| pub size: usize, | ||
|
|
||
| /// SHA256 hash of file contents. | ||
| #[serde(with = "hex::serde")] | ||
| pub hash: Vec<u8>, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| /// Details about intermediate preloading. | ||
| #[derive(Debug, Deserialize, Serialize)] | ||
| #[serde(rename_all = "kebab-case", deny_unknown_fields, default)] | ||
| pub struct IntermediatesConfig { | ||
| /// Whether to fetch things at all. | ||
| pub enabled: bool, | ||
| /// Where to fetch intermediate certificates. | ||
| pub fetch_url: String, | ||
| } | ||
|
|
||
| impl Default for IntermediatesConfig { | ||
| fn default() -> Self { | ||
| Self { | ||
| enabled: false, | ||
| fetch_url: "https://upki.rustls.dev/intermediates/".into(), | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,14 @@ pub(crate) mod sha256; | |
|
|
||
| /// Determining revocation status of publicly trusted certificates. | ||
| pub mod revocation; | ||
|
|
||
| /// Fetching intermediate certificates to assist chain building. | ||
| pub mod intermediates; | ||
|
|
||
| /// Common data storage formats. | ||
| pub mod data; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the |
||
|
|
||
| use crate::intermediates::IntermediatesConfig; | ||
| use crate::revocation::RevocationConfig; | ||
|
|
||
| /// Foreign function interface. | ||
|
|
@@ -29,6 +37,10 @@ pub struct Config { | |
|
|
||
| /// Configuration for crlite-style revocation. | ||
| pub revocation: RevocationConfig, | ||
|
|
||
| /// Configuration for intermediate preloading. | ||
| #[serde(default)] | ||
| pub intermediates: IntermediatesConfig, | ||
| } | ||
|
|
||
| impl Config { | ||
|
|
@@ -71,6 +83,7 @@ impl Config { | |
| } | ||
| }, | ||
| revocation: RevocationConfig::default(), | ||
| intermediates: IntermediatesConfig::default(), | ||
| }) | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of
enabled, I think we should makeintermediates(andrevocation)Optionin the top-levelConfig?