feat: allow multiple trust certs in cert file (#102)

The `.ssl_cert_file()` option now can read files with multiple
certificate to trust. This is useful when using a single client instance
to access many minio servers.
This commit is contained in:
Aditya Manthramurthy 2024-10-28 10:51:13 -07:00 committed by GitHub
parent eae650296b
commit 903acae66a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 5 deletions

View File

@ -11,7 +11,7 @@ keywords = ["object-storage", "minio", "s3"]
categories = ["api-bindings", "web-programming::http-client"]
[dependencies.reqwest]
version = "0.12.5"
version = "0.12.8"
default-features = false
features = ["stream"]

View File

@ -91,13 +91,15 @@ impl ClientBuilder {
self
}
/// Set file for loading a trust certificate.
/// Set file for loading CAs certs to trust. This is in addition to the system
/// trust store. The file must contain PEM encoded certificates.
pub fn ssl_cert_file(mut self, ssl_cert_file: Option<&Path>) -> Self {
self.ssl_cert_file = ssl_cert_file.map(PathBuf::from);
self
}
/// Set flag to ignore certificate check.
/// Set flag to ignore certificate check. This is insecure and should only
/// be used for testing.
pub fn ignore_cert_check(mut self, ignore_cert_check: Option<bool>) -> Self {
self.ignore_cert_check = ignore_cert_check;
self
@ -137,9 +139,11 @@ impl ClientBuilder {
if let Some(v) = self.ssl_cert_file {
let mut buf = Vec::new();
File::open(v)?.read_to_end(&mut buf)?;
let cert = reqwest::Certificate::from_pem(&buf)?;
let certs = reqwest::Certificate::from_pem_bundle(&buf)?;
for cert in certs {
builder = builder.add_root_certificate(cert);
}
}
let client = builder.build()?;