diff --git a/Cargo.lock b/Cargo.lock index 26f9aec..a1bdf3e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -357,7 +357,7 @@ dependencies = [ [[package]] name = "epoxy-client" -version = "1.2.0" +version = "1.2.1" dependencies = [ "async-compression", "async_io_stream", diff --git a/README.md b/README.md index effdf6d..8b8d636 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,13 @@ import epoxy from "./epoxy-module-bundled.js"; // or // importScripts("epoxy-bundled.js"); -const { EpoxyClient } = await epoxy(); +const { EpoxyClient, certs } = await epoxy(); + let client = await new EpoxyClient("wss://localhost:4000", navigator.userAgent, 10); +// You can view the certificates compiled in +console.log(certs()) + // You can view and change the user agent and redirect limit console.log(client.userAgent); client.redirect_limit = 5; diff --git a/client/.npmignore b/client/.npmignore index b60043a..de95065 100644 --- a/client/.npmignore +++ b/client/.npmignore @@ -2,4 +2,5 @@ build.sh Cargo.toml serve.py src +pkg/epoxy.wasm diff --git a/client/Cargo.toml b/client/Cargo.toml index e9d5e6f..e1238e7 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "epoxy-client" -version = "1.2.0" +version = "1.2.1" edition = "2021" license = "LGPL-3.0-only" diff --git a/client/demo.js b/client/demo.js index 8858e13..1fab06e 100644 --- a/client/demo.js +++ b/client/demo.js @@ -27,7 +27,9 @@ onmessage = async (msg) => { postMessage(JSON.stringify(str, null, 4)); } - const { EpoxyClient } = await epoxy(); + const { EpoxyClient, certs } = await epoxy(); + + console.log("certs:", certs()); const tconn0 = performance.now(); // args: websocket url, user agent, redirect limit diff --git a/client/package.json b/client/package.json index 3c3a2c6..51c35bb 100644 --- a/client/package.json +++ b/client/package.json @@ -1,6 +1,6 @@ { "name": "@mercuryworkshop/epoxy-tls", - "version": "1.2.0", + "version": "1.2.1", "description": "A wasm library for using raw encrypted tls/ssl/https/websocket streams on the browser", "scripts": { "build": "./build.sh" diff --git a/client/src/lib.rs b/client/src/lib.rs index ce8e495..4a4584c 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -22,6 +22,7 @@ use http::{uri, HeaderName, HeaderValue, Request, Response}; use hyper::{body::Incoming, Uri}; use hyper_util_wasm::client::legacy::Client; use js_sys::{Array, Function, Object, Reflect, Uint8Array}; +use rustls::pki_types::TrustAnchor; use tokio_rustls::{client::TlsStream, rustls, rustls::RootCertStore, TlsConnector}; use tokio_util::{ either::Either, @@ -65,6 +66,38 @@ fn init() { intern("rawHeaders"); } +fn cert_to_jval(cert: &TrustAnchor) -> Result { + let val = Object::new(); + Reflect::set( + &val, + &jval!("subject"), + &Uint8Array::from(cert.subject.as_ref()), + )?; + Reflect::set( + &val, + &jval!("subject_public_key_info"), + &Uint8Array::from(cert.subject_public_key_info.as_ref()), + )?; + Reflect::set( + &val, + &jval!("name_constraints"), + &jval!(cert + .name_constraints + .as_ref() + .map(|x| Uint8Array::from(x.as_ref()))), + )?; + Ok(val.into()) +} + +#[wasm_bindgen] +pub fn certs() -> Result { + Ok(webpki_roots::TLS_SERVER_ROOTS + .iter() + .map(cert_to_jval) + .collect::>()? + .into()) +} + #[wasm_bindgen(inspectable)] pub struct EpoxyClient { rustls_config: Arc,