Skip to content
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

[WIP] add support for root certificates #256

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ strum = "0.23"
strum_macros = "0.23"
tar = "0.4"
tokio = "1.0"
reqwest = { version = "0.11", default-features = false, features = ["json", "stream"] }
reqwest = { version = "0.11", default-features = false, features = ["json", "stream", "rustls-tls-native-roots", "native-tls"] }
sha2 = "^0.10.0"
bytes = "1.1"
pin-project = "1.0"
Expand Down
27 changes: 24 additions & 3 deletions src/v2/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use reqwest::Certificate;

use crate::{mediatypes::MediaTypes, v2::*};

/// Configuration for a `Client`.
Expand All @@ -10,6 +12,7 @@
password: Option<String>,
accept_invalid_certs: bool,
accepted_types: Option<Vec<(MediaTypes, Option<f64>)>>,
root_certificate: Option<Certificate>,
}

impl Config {
Expand Down Expand Up @@ -67,6 +70,12 @@
self
}

/// Set the root certificate if required for the registry
pub fn root_certificate(mut self, root_certificate: Certificate) -> Self {
self.root_certificate = Some(root_certificate);
self
}

/// Return a `Client` to interact with a v2 registry.
pub fn build(self) -> Result<Client> {
let base = if self.insecure_registry {
Expand All @@ -87,9 +96,20 @@
p.unwrap_or_else(|| "".into()),
)),
};
let client = reqwest::ClientBuilder::new()
.danger_accept_invalid_certs(self.accept_invalid_certs)
.build()?;

let client: reqwest::Client;

Check failure on line 100 in src/v2/config.rs

View workflow job for this annotation

GitHub Actions / Lints (stable)

unneeded late initialization
if self.root_certificate.is_some() {
client = reqwest::ClientBuilder::new()
.add_root_certificate(self.root_certificate.unwrap())
.use_native_tls()
.danger_accept_invalid_certs(self.accept_invalid_certs)
.build()?;
} else {
client = reqwest::ClientBuilder::new()
.use_native_tls()
.danger_accept_invalid_certs(self.accept_invalid_certs)
.build()?;
}

let accepted_types = match self.accepted_types {
Some(a) => a,
Expand Down Expand Up @@ -134,6 +154,7 @@
user_agent: Some(crate::USER_AGENT.to_owned()),
username: None,
password: None,
root_certificate: None,
}
}
}
Loading