MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / require_tls_materials

Function require_tls_materials

crates/openshell-cli/src/tls.rs:166–193  ·  view source on GitHub ↗
(server: &str, tls: &TlsOptions)

Source from the content-addressed store, hash-verified

164}
165
166pub 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
195fn load_private_key(pem: &[u8]) -> Result<PrivateKeyDer<'static>> {
196 let mut cursor = Cursor::new(pem);

Callers 2

build_channelFunction · 0.85
http_health_checkFunction · 0.85

Calls 2

default_tls_dirFunction · 0.85
with_default_pathsMethod · 0.80

Tested by

no test coverage detected