(materials: &TlsMaterials)
| 201 | } |
| 202 | |
| 203 | pub fn build_rustls_config(materials: &TlsMaterials) -> Result<rustls::ClientConfig> { |
| 204 | let mut roots = RootCertStore::empty(); |
| 205 | let mut ca_cursor = Cursor::new(&materials.ca); |
| 206 | let ca_certs = rustls_pemfile::certs(&mut ca_cursor) |
| 207 | .collect::<Result<Vec<CertificateDer<'static>>, _>>() |
| 208 | .into_diagnostic()?; |
| 209 | for cert in ca_certs { |
| 210 | roots.add(cert).into_diagnostic()?; |
| 211 | } |
| 212 | |
| 213 | let mut cert_cursor = Cursor::new(&materials.cert); |
| 214 | let cert_chain = rustls_pemfile::certs(&mut cert_cursor) |
| 215 | .collect::<Result<Vec<CertificateDer<'static>>, _>>() |
| 216 | .into_diagnostic()?; |
| 217 | let key = load_private_key(&materials.key)?; |
| 218 | |
| 219 | rustls::ClientConfig::builder() |
| 220 | .with_root_certificates(roots) |
| 221 | .with_client_auth_cert(cert_chain, key) |
| 222 | .into_diagnostic() |
| 223 | } |
| 224 | |
| 225 | pub fn build_tonic_tls_config(materials: &TlsMaterials) -> ClientTlsConfig { |
| 226 | let ca_cert = Certificate::from_pem(materials.ca.clone()); |
no test coverage detected