-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
57 additions
and
80 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 |
---|---|---|
@@ -1,34 +1,39 @@ | ||
use crate::RootStoreBuilder; | ||
use crate::Certificate; | ||
|
||
use std::io::{Error, ErrorKind}; | ||
use std::io::BufReader; | ||
use std::fs::File; | ||
use std::path::Path; | ||
|
||
fn load_file(builder: &mut impl RootStoreBuilder, path: &Path) -> Result<(), Error> { | ||
fn load_file(certs: &mut Vec<Certificate>, path: &Path) -> Result<(), Error> { | ||
let f = File::open(&path)?; | ||
let mut f = BufReader::new(f); | ||
if builder.load_pem_file(&mut f).is_err() { | ||
Err(Error::new(ErrorKind::InvalidData, | ||
format!("Could not load PEM file {:?}", path))) | ||
} else { | ||
Ok(()) | ||
match rustls_pemfile::certs(&mut f) { | ||
Ok(contents) => { | ||
certs.extend(contents.into_iter().map(Certificate)); | ||
Ok(()) | ||
} | ||
Err(_) => Err(Error::new( | ||
ErrorKind::InvalidData, | ||
format!("Could not load PEM file {:?}", path), | ||
)), | ||
} | ||
} | ||
|
||
pub fn build_native_certs<B: RootStoreBuilder>(builder: &mut B) -> Result<(), Error> { | ||
pub fn load_native_certs() -> Result<Vec<Certificate>, Error> { | ||
let likely_locations = openssl_probe::probe(); | ||
let mut first_error = None; | ||
let mut certs = Vec::new(); | ||
|
||
if let Some(file) = likely_locations.cert_file { | ||
if let Err(err) = load_file(builder, &file) { | ||
if let Err(err) = load_file(&mut certs, &file) { | ||
first_error = first_error.or(Some(err)); | ||
} | ||
} | ||
|
||
if let Some(err) = first_error { | ||
Err(err) | ||
} else { | ||
Ok(()) | ||
Ok(certs) | ||
} | ||
} |
This file contains 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 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 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