mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-12 23:24:35 +01:00
Update proxy to handle traffic
This commit is contained in:
11
src-tauri/Cargo.lock
generated
11
src-tauri/Cargo.lock
generated
@@ -671,6 +671,7 @@ dependencies = [
|
||||
"serde_json",
|
||||
"tauri",
|
||||
"tauri-build",
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
"tokio-tungstenite",
|
||||
"tracing",
|
||||
@@ -3302,6 +3303,15 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "signal-hook-registry"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "0.3.10"
|
||||
@@ -3877,6 +3887,7 @@ dependencies = [
|
||||
"num_cpus",
|
||||
"once_cell",
|
||||
"pin-project-lite",
|
||||
"signal-hook-registry",
|
||||
"socket2",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
@@ -18,10 +18,10 @@ tauri-build = { version = "1.0.0-rc.8", features = [] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
tauri = { version = "1.0.0-rc.9", features = ["api-all"] }
|
||||
|
||||
# zip library
|
||||
# ZIP-archive library.
|
||||
zip-extract = "0.1.1"
|
||||
|
||||
# For creating a "global" downloads list
|
||||
# For creating a "global" downloads list.
|
||||
lazy_static = "1.4.0"
|
||||
|
||||
# Access to the Windows Registry.
|
||||
@@ -38,6 +38,7 @@ hudsucker = "0.17.2"
|
||||
tracing = "0.1.21"
|
||||
tokio-rustls = "0.23.0"
|
||||
tokio-tungstenite = "0.17.0"
|
||||
tokio = { version = "1.18.2", features = ["signal"] }
|
||||
rustls-pemfile = "1.0.0"
|
||||
reqwest = { version = "0.11.3", features = ["stream"] }
|
||||
futures-util = "0.3.14"
|
||||
|
||||
22
src-tauri/resources/cert.crt
Normal file
22
src-tauri/resources/cert.crt
Normal file
@@ -0,0 +1,22 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDkzCCAnugAwIBAgIJAMdLw5xpuf6yMA0GCSqGSIb3DQEBCwUAMGYxHTAbBgNV
|
||||
BAMMFEh1ZHN1Y2tlciBJbmR1c3RyaWVzMR0wGwYDVQQKDBRIdWRzdWNrZXIgSW5k
|
||||
dXN0cmllczELMAkGA1UEBgwCVVMxCzAJBgNVBAgMAk5ZMQwwCgYDVQQHDANOWUMw
|
||||
IBcNNzUwMTAxMDAwMDAwWhgPNDA5NjAxMDEwMDAwMDBaMGYxHTAbBgNVBAMMFEh1
|
||||
ZHN1Y2tlciBJbmR1c3RyaWVzMR0wGwYDVQQKDBRIdWRzdWNrZXIgSW5kdXN0cmll
|
||||
czELMAkGA1UEBgwCVVMxCzAJBgNVBAgMAk5ZMQwwCgYDVQQHDANOWUMwggEiMA0G
|
||||
CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCaHrZ9VUL7SKqgJdeG/dciikuummsr
|
||||
Ds4Cn+p01J5mURQ/bq62EU5IiWFsM0LgwkO0UlTGE9gU+U1w1GeDxlDeVqcwitx+
|
||||
sPjup59ybC2l/iNihETjrLuFUaZVFH/eqdXqNgiRf1fBHV/RD27BlPN6OPo8Z6qT
|
||||
fuRlVAUbpj+IViIkdQtmymgCJDrQabtnnwpPqZA0MQFnsAvmelOrWyTX1ASjzFAl
|
||||
WWq7JDvFsrYcqPeMv8QaN/teESFN5pMSNDbvYm2guwcRu4jVL75hMezqm6StXe5p
|
||||
CbbZOKPHLGqtRUAHnUFHEV1khOEz5HhOsC6m0DvWvKf5QiUvqcYFYxFZAgMBAAGj
|
||||
QjBAMA4GA1UdDwEB/wQEAwIBBjAdBgNVHQ4EFgQUsv65aZzDS8dPy3NWpXkAOKf0
|
||||
2rMwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAVnXJDTCCcV/c
|
||||
79IidGy3Hh/st+4e2A6R3YueE01Rwo340Asp9Tp3IewDQcF3oRosgDp/i9daRrxv
|
||||
c2q76CNmo57qUSjbdyu4o5SDqj7lmr263YgM4ZnVOQR9CaWwCL21C65tpgHa8Grm
|
||||
hNil9REdnpM7br4H0yeX2nFjOYI8sUguxNle3ojTFLl0sWXZIPJE/koEaaHGSJD1
|
||||
XR72llJbbExYbTzaEV3uw7sJsuwldMC/QL+oWm/Jnwc2WfLTl3HjLOaK9r/smF/E
|
||||
RtYk5yo7J6pMALrIP7SPHpFooez5JHn2ucP42HcUwOXmrDIOUt6gJQ4w8DBE46Bo
|
||||
oMKSHK2k0g==
|
||||
-----END CERTIFICATE-----
|
||||
@@ -4,6 +4,7 @@ windows_subsystem = "windows"
|
||||
)]
|
||||
|
||||
use open;
|
||||
use tokio::sync::oneshot::Sender;
|
||||
use structs::{APIQuery};
|
||||
|
||||
mod file_helpers;
|
||||
@@ -38,17 +39,20 @@ fn main() {
|
||||
#[tauri::command]
|
||||
async fn connect(port: u16) {
|
||||
// Log message to console.
|
||||
println!("Connecting to proxy...");
|
||||
|
||||
// Create and start a proxy.
|
||||
proxy::create_proxy(port).await;
|
||||
println!("Connecting to proxy...");
|
||||
|
||||
// Change proxy settings.
|
||||
proxy::connect_to_proxy(port);
|
||||
|
||||
// Create and start a proxy.
|
||||
proxy::create_proxy(port).await;
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn disconnect() {
|
||||
// Log message to console.
|
||||
println!("Disconnecting from proxy...");
|
||||
|
||||
// Change proxy settings.
|
||||
proxy::disconnect_from_proxy();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* https://github.com/omjadas/hudsucker/blob/main/examples/log.rs
|
||||
*/
|
||||
|
||||
use std::borrow::Borrow;
|
||||
use hudsucker::{
|
||||
async_trait::async_trait,
|
||||
certificate_authority::RcgenAuthority,
|
||||
@@ -14,12 +15,12 @@ use std::net::SocketAddr;
|
||||
use registry::{Hive, Data, Security};
|
||||
|
||||
use rustls_pemfile as pemfile;
|
||||
use tauri::http::Uri;
|
||||
use tokio::sync::oneshot::Sender;
|
||||
|
||||
/**
|
||||
* Application shutdown handler.
|
||||
*/
|
||||
async fn shutdown_signal() {
|
||||
disconnect_from_proxy();
|
||||
async unsafe fn shutdown_signal() {
|
||||
tokio::signal::ctrl_c().await
|
||||
.expect("Failed to install CTRL+C signal handler");
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -31,11 +32,32 @@ impl HttpHandler for ProxyHandler {
|
||||
_context: &HttpContext,
|
||||
request: Request<Body>
|
||||
) -> RequestOrResponse {
|
||||
println!("{:?}", request.uri().path());
|
||||
RequestOrResponse::Request(request)
|
||||
// Get request parts.
|
||||
let (parts, body) = request.into_parts();
|
||||
|
||||
// Parse request URI.
|
||||
let mut uri = parts.uri.clone();
|
||||
let path = uri.to_string();
|
||||
|
||||
// Check URI against constraints.
|
||||
if path.contains("hoyoverse.com") || path.contains("mihoyo.com") || path.contains("yuanshen.com") {
|
||||
let mut new_uri = String::new();
|
||||
new_uri.push_str("127.0.0.1");
|
||||
new_uri.push_str(uri.path());
|
||||
|
||||
uri = Uri::from_static(new_uri.as_str());
|
||||
}
|
||||
|
||||
let builder = Request::builder()
|
||||
.method(&parts.method)
|
||||
.uri(&uri)
|
||||
.version(parts.version);
|
||||
let modified = builder.body(body).unwrap();
|
||||
|
||||
RequestOrResponse::Request(modified)
|
||||
}
|
||||
|
||||
async fn handle_response(&mut self,
|
||||
async fn handle_response(&mut self,
|
||||
_context: &HttpContext,
|
||||
response: Response<Body>
|
||||
) -> Response<Body> { response }
|
||||
@@ -73,10 +95,11 @@ pub(crate) async fn create_proxy(proxy_port: u16) {
|
||||
.with_ca(authority)
|
||||
.with_http_handler(ProxyHandler)
|
||||
.build();
|
||||
|
||||
// Create the proxy & listen for errors.
|
||||
proxy.start(shutdown_signal()).await
|
||||
.expect("Failed to start proxy");
|
||||
|
||||
// Start the proxy.
|
||||
unsafe {
|
||||
tokio::spawn(proxy.start(shutdown_signal()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,4 +132,6 @@ pub(crate) fn disconnect_from_proxy() {
|
||||
// Set registry values.
|
||||
settings.set_value("ProxyEnable", &Data::U32(0)).unwrap();
|
||||
}
|
||||
|
||||
println!("Disconnected from proxy.");
|
||||
}
|
||||
Reference in New Issue
Block a user