Add root_ca_certificate
This commit is contained in:
parent
59d266a111
commit
faa016e4b7
|
@ -9,9 +9,10 @@ homepage = "https://solana.com/"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
log = "0.4.8"
|
|
||||||
goauth = "0.7.1"
|
goauth = "0.7.1"
|
||||||
|
log = "0.4.8"
|
||||||
smpl_jwt = "0.5.0"
|
smpl_jwt = "0.5.0"
|
||||||
|
tonic = {version="0.3.0", features = ["tls", "transport"]}
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["lib"]
|
crate-type = ["lib"]
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
mod access_token;
|
mod access_token;
|
||||||
|
mod root_ca_certificate;
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
use std::{fs::File, io::Read};
|
||||||
|
use tonic::transport::Certificate;
|
||||||
|
|
||||||
|
pub fn load() -> Result<Certificate, String> {
|
||||||
|
// Respect the standard GRPC_DEFAULT_SSL_ROOTS_FILE_PATH environment variable if present,
|
||||||
|
// otherwise use the built-in root certificate
|
||||||
|
let pem = match std::env::var("GRPC_DEFAULT_SSL_ROOTS_FILE_PATH").ok() {
|
||||||
|
Some(cert_file) => File::open(&cert_file)
|
||||||
|
.and_then(|mut file| {
|
||||||
|
let mut pem = Vec::new();
|
||||||
|
file.read_to_end(&mut pem).map(|_| pem)
|
||||||
|
})
|
||||||
|
.map_err(|err| format!("Failed to read {}: {}", cert_file, err))?,
|
||||||
|
None => {
|
||||||
|
// PEM file from Google Trust Services (https://pki.goog/roots.pem)
|
||||||
|
include_bytes!("pki-goog-roots.pem").to_vec()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Ok(Certificate::from_pem(&pem))
|
||||||
|
}
|
Loading…
Reference in New Issue