Skip to content

Commit

Permalink
feat: Trust all server cert
Browse files Browse the repository at this point in the history
Signed-off-by: zu1k <[email protected]>
  • Loading branch information
zu1k committed Jun 4, 2022
1 parent 3b33d24 commit 8324981
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ tokio = { version = "1", features = ["rt"] }
tokio-rustls = { version = "0.23", default-features = false, features = ["tls12"] }
tokio-util = { version = "0.7", features = ["io"] }
wildmatch = "2.1"
quick-js = { version = "0.4", features = ["log"] }
quick-js = { version = "0.4", features = ["log"] }
rustls = { version = "0.20", features = ["dangerous_configuration"] }
31 changes: 30 additions & 1 deletion core/src/http_client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use std::{sync::Arc, time::SystemTime};

use hyper::{client::HttpConnector, Client};
use hyper_proxy::{Proxy as UpstreamProxy, ProxyConnector};
use hyper_rustls::{HttpsConnector, HttpsConnectorBuilder};
use rustls::{
client::{ServerCertVerified, ServerCertVerifier},
ClientConfig,
};

#[derive(Clone)]
pub enum HttpClient {
Expand All @@ -10,7 +16,13 @@ pub enum HttpClient {

pub fn gen_client(upstream_proxy: Option<UpstreamProxy>) -> HttpClient {
let https = HttpsConnectorBuilder::new()
.with_webpki_roots()
.with_tls_config({
let cert_resolver = Arc::new(TrustAllCertVerifier::default());
ClientConfig::builder()
.with_safe_defaults()
.with_custom_certificate_verifier(cert_resolver)
.with_no_client_auth()
})
.https_or_http()
.enable_http1()
.enable_http2()
Expand All @@ -36,3 +48,20 @@ pub fn gen_client(upstream_proxy: Option<UpstreamProxy>) -> HttpClient {
)
}
}

#[derive(Default)]
struct TrustAllCertVerifier;

impl ServerCertVerifier for TrustAllCertVerifier {
fn verify_server_cert(
&self,
_end_entity: &rustls::Certificate,
_intermediates: &[rustls::Certificate],
_server_name: &rustls::ServerName,
_scts: &mut dyn Iterator<Item = &[u8]>,
_ocsp_response: &[u8],
_n_ow: SystemTime,
) -> Result<ServerCertVerified, rustls::Error> {
Ok(ServerCertVerified::assertion())
}
}
10 changes: 10 additions & 0 deletions rules/yuanshen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- name: "redirect yuanshen"
filter:
- domain-suffix: 'mihoyo.com'
- domain-suffix: 'hoyoverse.com'
- domain-suffix: 'yuanshen.com'
action:
modify-request:
url:
re: 'https?:\/\/(.+)\.(.+)\.com(.*)'
new: 'https://192.168.226.200:443$3'

1 comment on commit 8324981

@vercel
Copy link

@vercel vercel bot commented on 8324981 Jun 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.