| 86 | } |
| 87 | |
| 88 | pub fn server_config(&self) -> Result<Option<ServerConfig>> { |
| 89 | if !self.is_secure() { |
| 90 | return Ok(None); |
| 91 | } |
| 92 | |
| 93 | CELL.get_or_init(install_default_tls_provider); |
| 94 | |
| 95 | let (mut cert_chain, key) = |
| 96 | parse_cert_and_key(self.cert_path().as_ref(), self.key_path().as_ref())?; |
| 97 | |
| 98 | if let Some(path) = self.ca_path() { |
| 99 | let certs = parse_certificates(path)?; |
| 100 | if !certs.is_empty() { |
| 101 | cert_chain.extend(certs); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | let mut config = ServerConfig::builder() |
| 106 | .with_no_client_auth() |
| 107 | .with_single_cert(cert_chain, key) |
| 108 | .map_err(TlsError::FailedToParseConfig)?; |
| 109 | |
| 110 | config.alpn_protocols = vec![b"h2".to_vec(), b"http/1.1".to_vec()]; |
| 111 | |
| 112 | Ok(Some(config)) |
| 113 | } |
| 114 | |
| 115 | pub fn client_config(&self) -> Result<ClientConfig> { |
| 116 | CELL.get_or_init(install_default_tls_provider); |