| 113 | } |
| 114 | |
| 115 | pub fn client_config(&self) -> Result<ClientConfig> { |
| 116 | CELL.get_or_init(install_default_tls_provider); |
| 117 | |
| 118 | let builder = if let Some(path) = self.ca_path() { |
| 119 | let mut root_store = RootCertStore::empty(); |
| 120 | root_store.add_parsable_certificates(parse_certificates(path)?); |
| 121 | ClientConfig::builder().with_root_certificates(root_store) |
| 122 | } else { |
| 123 | use rustls_platform_verifier::BuilderVerifierExt; |
| 124 | ClientConfig::builder().with_platform_verifier() |
| 125 | }; |
| 126 | |
| 127 | let (cert, key) = parse_cert_and_key(self.cert_path().as_ref(), self.key_path().as_ref())?; |
| 128 | |
| 129 | let config = builder |
| 130 | .with_client_auth_cert(cert, key) |
| 131 | .map_err(TlsError::FailedToParseConfig)?; |
| 132 | |
| 133 | Ok(config) |
| 134 | } |
| 135 | |
| 136 | fn cert_path(&self) -> Option<PathBuf> { |
| 137 | self.tls_cert.clone().or_else(|| self.cached_cert_path()) |