From cb12a9350332860971387e3a1fb40dc77fa992d3 Mon Sep 17 00:00:00 2001 From: Matt Mastracci Date: Mon, 8 Apr 2024 15:01:02 -0600 Subject: refactor(ext/tls): use cppgc to deduplicate the tls key loading code (#23289) Pass the certificates and key files as CPPGC objects. Towards #23233 --- ext/fetch/lib.rs | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) (limited to 'ext/fetch/lib.rs') diff --git a/ext/fetch/lib.rs b/ext/fetch/lib.rs index aeac33973..e384a918e 100644 --- a/ext/fetch/lib.rs +++ b/ext/fetch/lib.rs @@ -44,6 +44,8 @@ use deno_tls::Proxy; use deno_tls::RootCertStoreProvider; use data_url::DataUrl; +use deno_tls::TlsKey; +use deno_tls::TlsKeys; use http_v02::header::CONTENT_LENGTH; use http_v02::Uri; use reqwest::header::HeaderMap; @@ -78,7 +80,7 @@ pub struct Options { pub request_builder_hook: Option Result>, pub unsafely_ignore_certificate_errors: Option>, - pub client_cert_chain_and_key: Option<(String, String)>, + pub client_cert_chain_and_key: Option, pub file_fetch_handler: Rc, } @@ -794,8 +796,6 @@ impl HttpClientResource { pub struct CreateHttpClientArgs { ca_certs: Vec, proxy: Option, - cert: Option, - key: Option, pool_max_idle_per_host: Option, pool_idle_timeout: Option, #[serde(default = "default_true")] @@ -815,6 +815,7 @@ fn default_true() -> bool { pub fn op_fetch_custom_client( state: &mut OpState, #[serde] args: CreateHttpClientArgs, + #[cppgc] tls_keys: &deno_tls::TlsKeys, ) -> Result where FP: FetchPermissions + 'static, @@ -825,19 +826,9 @@ where permissions.check_net_url(&url, "Deno.createHttpClient()")?; } - let client_cert_chain_and_key = { - if args.cert.is_some() || args.key.is_some() { - let cert_chain = args - .cert - .ok_or_else(|| type_error("No certificate chain provided"))?; - let private_key = args - .key - .ok_or_else(|| type_error("No private key provided"))?; - - Some((cert_chain, private_key)) - } else { - None - } + let client_cert_chain_and_key = match tls_keys { + TlsKeys::Null => None, + TlsKeys::Static(key) => Some(key.clone()), }; let options = state.borrow::(); @@ -885,7 +876,7 @@ pub struct CreateHttpClientOptions { pub ca_certs: Vec>, pub proxy: Option, pub unsafely_ignore_certificate_errors: Option>, - pub client_cert_chain_and_key: Option<(String, String)>, + pub client_cert_chain_and_key: Option, pub pool_max_idle_per_host: Option, pub pool_idle_timeout: Option>, pub http1: bool, -- cgit v1.2.3