mirror of
https://github.com/MercuryWorkshop/epoxy-tls.git
synced 2025-05-12 14:00:01 -04:00
add certs function
This commit is contained in:
parent
f1446a9b27
commit
5b4fb1392a
7 changed files with 45 additions and 5 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -357,7 +357,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "epoxy-client"
|
||||
version = "1.2.0"
|
||||
version = "1.2.1"
|
||||
dependencies = [
|
||||
"async-compression",
|
||||
"async_io_stream",
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -2,4 +2,5 @@ build.sh
|
|||
Cargo.toml
|
||||
serve.py
|
||||
src
|
||||
pkg/epoxy.wasm
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "epoxy-client"
|
||||
version = "1.2.0"
|
||||
version = "1.2.1"
|
||||
edition = "2021"
|
||||
license = "LGPL-3.0-only"
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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<JsValue, JsValue> {
|
||||
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<JsValue, JsValue> {
|
||||
Ok(webpki_roots::TLS_SERVER_ROOTS
|
||||
.iter()
|
||||
.map(cert_to_jval)
|
||||
.collect::<Result<Array, JsValue>>()?
|
||||
.into())
|
||||
}
|
||||
|
||||
#[wasm_bindgen(inspectable)]
|
||||
pub struct EpoxyClient {
|
||||
rustls_config: Arc<rustls::ClientConfig>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue