(server: &str, tls: &TlsOptions)
| 164 | } |
| 165 | |
| 166 | pub fn require_tls_materials(server: &str, tls: &TlsOptions) -> Result<TlsMaterials> { |
| 167 | let resolved = tls.with_default_paths(server); |
| 168 | let default_hint = default_tls_dir(server).map_or_else(String::new, |dir| { |
| 169 | format!(" or place certs in {}", dir.display()) |
| 170 | }); |
| 171 | let ca_path = resolved |
| 172 | .ca |
| 173 | .as_ref() |
| 174 | .ok_or_else(|| miette::miette!("TLS CA is required for https endpoints{default_hint}"))?; |
| 175 | let cert_path = resolved.cert.as_ref().ok_or_else(|| { |
| 176 | miette::miette!("TLS client cert is required for https endpoints{default_hint}") |
| 177 | })?; |
| 178 | let key_path = resolved.key.as_ref().ok_or_else(|| { |
| 179 | miette::miette!("TLS client key is required for https endpoints{default_hint}") |
| 180 | })?; |
| 181 | |
| 182 | let ca = std::fs::read(ca_path) |
| 183 | .into_diagnostic() |
| 184 | .wrap_err_with(|| format!("failed to read TLS CA from {}", ca_path.display()))?; |
| 185 | let cert = std::fs::read(cert_path) |
| 186 | .into_diagnostic() |
| 187 | .wrap_err_with(|| format!("failed to read TLS cert from {}", cert_path.display()))?; |
| 188 | let key = std::fs::read(key_path) |
| 189 | .into_diagnostic() |
| 190 | .wrap_err_with(|| format!("failed to read TLS key from {}", key_path.display()))?; |
| 191 | |
| 192 | Ok(TlsMaterials { ca, cert, key }) |
| 193 | } |
| 194 | |
| 195 | fn load_private_key(pem: &[u8]) -> Result<PrivateKeyDer<'static>> { |
| 196 | let mut cursor = Cursor::new(pem); |
no test coverage detected