summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'runtime')
-rw-r--r--runtime/examples/hello_runtime.rs2
-rw-r--r--runtime/http_util.rs10
-rw-r--r--runtime/ops/fetch.rs4
-rw-r--r--runtime/ops/websocket.rs17
-rw-r--r--runtime/web_worker.rs8
-rw-r--r--runtime/worker.rs8
6 files changed, 22 insertions, 27 deletions
diff --git a/runtime/examples/hello_runtime.rs b/runtime/examples/hello_runtime.rs
index dbe539281..c93bbc90b 100644
--- a/runtime/examples/hello_runtime.rs
+++ b/runtime/examples/hello_runtime.rs
@@ -26,7 +26,7 @@ async fn main() -> Result<(), AnyError> {
args: vec![],
debug_flag: false,
unstable: false,
- ca_filepath: None,
+ ca_data: None,
user_agent: "hello_runtime".to_string(),
seed: None,
js_error_create_fn: None,
diff --git a/runtime/http_util.rs b/runtime/http_util.rs
index 67703c214..4fe4dc7ec 100644
--- a/runtime/http_util.rs
+++ b/runtime/http_util.rs
@@ -7,14 +7,12 @@ use deno_fetch::reqwest::header::HeaderMap;
use deno_fetch::reqwest::header::USER_AGENT;
use deno_fetch::reqwest::redirect::Policy;
use deno_fetch::reqwest::Client;
-use std::fs::File;
-use std::io::Read;
/// Create new instance of async reqwest::Client. This client supports
/// proxies and doesn't follow redirects.
pub fn create_http_client(
user_agent: String,
- ca_file: Option<&str>,
+ ca_data: Option<Vec<u8>>,
) -> Result<Client, AnyError> {
let mut headers = HeaderMap::new();
headers.insert(USER_AGENT, user_agent.parse().unwrap());
@@ -23,10 +21,8 @@ pub fn create_http_client(
.default_headers(headers)
.use_rustls_tls();
- if let Some(ca_file) = ca_file {
- let mut buf = Vec::new();
- File::open(ca_file)?.read_to_end(&mut buf)?;
- let cert = reqwest::Certificate::from_pem(&buf)?;
+ if let Some(ca_data) = ca_data {
+ let cert = reqwest::Certificate::from_pem(&ca_data)?;
builder = builder.add_root_certificate(cert);
}
diff --git a/runtime/ops/fetch.rs b/runtime/ops/fetch.rs
index 0ef99f73d..c2f62d8ee 100644
--- a/runtime/ops/fetch.rs
+++ b/runtime/ops/fetch.rs
@@ -6,13 +6,13 @@ use deno_fetch::reqwest;
pub fn init(
rt: &mut deno_core::JsRuntime,
user_agent: String,
- maybe_ca_file: Option<&str>,
+ ca_data: Option<Vec<u8>>,
) {
{
let op_state = rt.op_state();
let mut state = op_state.borrow_mut();
state.put::<reqwest::Client>({
- http_util::create_http_client(user_agent, maybe_ca_file).unwrap()
+ http_util::create_http_client(user_agent, ca_data).unwrap()
});
}
super::reg_json_async(rt, "op_fetch", deno_fetch::op_fetch::<Permissions>);
diff --git a/runtime/ops/websocket.rs b/runtime/ops/websocket.rs
index a5681bc52..812844f39 100644
--- a/runtime/ops/websocket.rs
+++ b/runtime/ops/websocket.rs
@@ -23,8 +23,8 @@ use http::{Method, Request, Uri};
use serde::Deserialize;
use std::borrow::Cow;
use std::cell::RefCell;
-use std::fs::File;
use std::io::BufReader;
+use std::io::Cursor;
use std::rc::Rc;
use std::sync::Arc;
use tokio::net::TcpStream;
@@ -39,20 +39,20 @@ use tokio_tungstenite::{client_async, WebSocketStream};
use webpki::DNSNameRef;
#[derive(Clone)]
-struct WsCaFile(String);
+struct WsCaData(Vec<u8>);
#[derive(Clone)]
struct WsUserAgent(String);
pub fn init(
rt: &mut deno_core::JsRuntime,
- maybe_ca_file: Option<&str>,
+ ca_data: Option<Vec<u8>>,
user_agent: String,
) {
{
let op_state = rt.op_state();
let mut state = op_state.borrow_mut();
- if let Some(ca_file) = maybe_ca_file {
- state.put::<WsCaFile>(WsCaFile(ca_file.to_string()));
+ if let Some(ca_data) = ca_data {
+ state.put::<WsCaData>(WsCaData(ca_data));
}
state.put::<WsUserAgent>(WsUserAgent(user_agent));
}
@@ -130,7 +130,7 @@ pub async fn op_ws_create(
);
}
- let maybe_ca_file = state.borrow().try_borrow::<WsCaFile>().cloned();
+ let ws_ca_data = state.borrow().try_borrow::<WsCaData>().cloned();
let user_agent = state.borrow().borrow::<WsUserAgent>().0.clone();
let uri: Uri = args.url.parse()?;
let mut request = Request::builder().method(Method::GET).uri(&uri);
@@ -163,9 +163,8 @@ pub async fn op_ws_create(
.root_store
.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS);
- if let Some(ws_ca_file) = maybe_ca_file {
- let key_file = File::open(ws_ca_file.0)?;
- let reader = &mut BufReader::new(key_file);
+ if let Some(ws_ca_data) = ws_ca_data {
+ let reader = &mut BufReader::new(Cursor::new(ws_ca_data.0));
config.root_store.add_pem_file(reader).unwrap();
}
diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs
index c1713f815..988845840 100644
--- a/runtime/web_worker.rs
+++ b/runtime/web_worker.rs
@@ -137,7 +137,7 @@ pub struct WebWorkerOptions {
pub args: Vec<String>,
pub debug_flag: bool,
pub unstable: bool,
- pub ca_filepath: Option<String>,
+ pub ca_data: Option<Vec<u8>>,
pub user_agent: String,
pub seed: Option<u64>,
pub module_loader: Rc<dyn ModuleLoader>,
@@ -219,7 +219,7 @@ impl WebWorker {
ops::fetch::init(
js_runtime,
options.user_agent.clone(),
- options.ca_filepath.as_deref(),
+ options.ca_data.clone(),
);
ops::timers::init(js_runtime);
ops::worker_host::init(
@@ -237,7 +237,7 @@ impl WebWorker {
ops::io::init(js_runtime);
ops::websocket::init(
js_runtime,
- options.ca_filepath.as_deref(),
+ options.ca_data.clone(),
options.user_agent.clone(),
);
@@ -483,7 +483,7 @@ mod tests {
apply_source_maps: false,
debug_flag: false,
unstable: false,
- ca_filepath: None,
+ ca_data: None,
user_agent: "x".to_string(),
seed: None,
module_loader,
diff --git a/runtime/worker.rs b/runtime/worker.rs
index 58a35cc95..a05c9f758 100644
--- a/runtime/worker.rs
+++ b/runtime/worker.rs
@@ -45,7 +45,7 @@ pub struct WorkerOptions {
pub args: Vec<String>,
pub debug_flag: bool,
pub unstable: bool,
- pub ca_filepath: Option<String>,
+ pub ca_data: Option<Vec<u8>>,
pub user_agent: String,
pub seed: Option<u64>,
pub module_loader: Rc<dyn ModuleLoader>,
@@ -114,7 +114,7 @@ impl MainWorker {
ops::fetch::init(
js_runtime,
options.user_agent.clone(),
- options.ca_filepath.as_deref(),
+ options.ca_data.clone(),
);
ops::timers::init(js_runtime);
ops::worker_host::init(
@@ -143,7 +143,7 @@ impl MainWorker {
ops::tty::init(js_runtime);
ops::websocket::init(
js_runtime,
- options.ca_filepath.as_deref(),
+ options.ca_data.clone(),
options.user_agent.clone(),
);
}
@@ -270,7 +270,7 @@ mod tests {
args: vec![],
debug_flag: false,
unstable: false,
- ca_filepath: None,
+ ca_data: None,
seed: None,
js_error_create_fn: None,
create_web_worker_cb: Arc::new(|_| unreachable!()),