feat: update connect-rs, add keyring-rs
This commit is contained in:
169
connect-rs/Cargo.lock
generated
169
connect-rs/Cargo.lock
generated
@@ -88,6 +88,12 @@ dependencies = [
|
||||
"windows-link 0.2.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.21.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.22.1"
|
||||
@@ -179,8 +185,11 @@ name = "connect-rs"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"keyring",
|
||||
"reqwest",
|
||||
"rust-crypto-hatter-fork",
|
||||
"rust_util",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -193,6 +202,16 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation"
|
||||
version = "0.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6"
|
||||
dependencies = [
|
||||
"core-foundation-sys",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation-sys"
|
||||
version = "0.8.7"
|
||||
@@ -253,7 +272,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys 0.60.2",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -298,6 +317,12 @@ dependencies = [
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fuchsia-cprng"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
|
||||
|
||||
[[package]]
|
||||
name = "futures-channel"
|
||||
version = "0.3.31"
|
||||
@@ -305,6 +330,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-sink",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -313,6 +339,12 @@ version = "0.3.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e"
|
||||
|
||||
[[package]]
|
||||
name = "futures-io"
|
||||
version = "0.3.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6"
|
||||
|
||||
[[package]]
|
||||
name = "futures-sink"
|
||||
version = "0.3.31"
|
||||
@@ -332,11 +364,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-io",
|
||||
"futures-sink",
|
||||
"futures-task",
|
||||
"memchr",
|
||||
"pin-project-lite",
|
||||
"pin-utils",
|
||||
"slab",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gcc"
|
||||
version = "0.3.55"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.16"
|
||||
@@ -397,6 +439,12 @@ version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||
|
||||
[[package]]
|
||||
name = "hex"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
||||
|
||||
[[package]]
|
||||
name = "http"
|
||||
version = "1.3.1"
|
||||
@@ -497,7 +545,7 @@ version = "0.1.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3c6995591a8f1380fcb4ba966a252a4b29188d51d2b89e3a252f5305be65aea8"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"base64 0.22.1",
|
||||
"bytes",
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
@@ -683,6 +731,18 @@ dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "keyring"
|
||||
version = "3.6.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eebcc3aff044e5944a8fbaf69eb277d11986064cba30c468730e8b9909fb551c"
|
||||
dependencies = [
|
||||
"log",
|
||||
"security-framework 2.11.1",
|
||||
"security-framework 3.5.1",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.5.0"
|
||||
@@ -767,7 +827,7 @@ dependencies = [
|
||||
"openssl-probe",
|
||||
"openssl-sys",
|
||||
"schannel",
|
||||
"security-framework",
|
||||
"security-framework 2.11.1",
|
||||
"security-framework-sys",
|
||||
"tempfile",
|
||||
]
|
||||
@@ -894,6 +954,53 @@ version = "5.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.3.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand 0.4.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293"
|
||||
dependencies = [
|
||||
"fuchsia-cprng",
|
||||
"libc",
|
||||
"rand_core 0.3.1",
|
||||
"rdrand",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
|
||||
dependencies = [
|
||||
"rand_core 0.4.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"
|
||||
|
||||
[[package]]
|
||||
name = "rdrand"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
|
||||
dependencies = [
|
||||
"rand_core 0.3.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_users"
|
||||
version = "0.4.6"
|
||||
@@ -911,10 +1018,12 @@ version = "0.12.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d429f34c8092b2d42c7c93cec323bb4adeb7c67698f70839adec842ec10c7ceb"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"base64 0.22.1",
|
||||
"bytes",
|
||||
"encoding_rs",
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
"futures-util",
|
||||
"h2",
|
||||
"http",
|
||||
"http-body",
|
||||
@@ -959,6 +1068,20 @@ dependencies = [
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rust-crypto-hatter-fork"
|
||||
version = "0.2.36"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d98d0ee2782d25af4e3f61fe6def8aba687f2ee821a575a47595eb4642429b02"
|
||||
dependencies = [
|
||||
"base64 0.21.7",
|
||||
"gcc",
|
||||
"hex",
|
||||
"libc",
|
||||
"rand 0.3.23",
|
||||
"time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rust_util"
|
||||
version = "0.6.50"
|
||||
@@ -987,7 +1110,7 @@ dependencies = [
|
||||
"errno",
|
||||
"libc",
|
||||
"linux-raw-sys",
|
||||
"windows-sys 0.60.2",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1051,7 +1174,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"core-foundation",
|
||||
"core-foundation 0.9.4",
|
||||
"core-foundation-sys",
|
||||
"libc",
|
||||
"security-framework-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "security-framework"
|
||||
version = "3.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b3297343eaf830f66ede390ea39da1d462b6b0c1b000f420d0a83f898bbbe6ef"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"core-foundation 0.10.1",
|
||||
"core-foundation-sys",
|
||||
"libc",
|
||||
"security-framework-sys",
|
||||
@@ -1206,7 +1342,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"core-foundation",
|
||||
"core-foundation 0.9.4",
|
||||
"system-configuration-sys",
|
||||
]
|
||||
|
||||
@@ -1230,7 +1366,7 @@ dependencies = [
|
||||
"getrandom 0.3.3",
|
||||
"once_cell",
|
||||
"rustix",
|
||||
"windows-sys 0.60.2",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1274,6 +1410,17 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.1.45"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"wasi 0.10.0+wasi-snapshot-preview1",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinystr"
|
||||
version = "0.8.1"
|
||||
@@ -1455,6 +1602,12 @@ dependencies = [
|
||||
"try-lock",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.1+wasi-snapshot-preview1"
|
||||
|
||||
@@ -5,5 +5,9 @@ edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.5.48", features = ["derive"] }
|
||||
reqwest = "0.12.23"
|
||||
keyring = { version = "3.6.3", features = ["apple-native"] }
|
||||
reqwest = { version = "0.12.23", features = ["blocking"] }
|
||||
rust_util = "0.6.50"
|
||||
serde_json = "1.0.145"
|
||||
rust-crypto-hatter-fork = "0.2"
|
||||
|
||||
|
||||
@@ -3,12 +3,22 @@
|
||||
//! ```cargo
|
||||
//! [dependencies]
|
||||
//! clap = { version = "4.5.48", features = ["derive"] }
|
||||
//! reqwest = "0.12.23"
|
||||
//! keyring = { version = "3.6.3", features = ["apple-native"] }
|
||||
//! reqwest = { version = "0.12.23", features = ["blocking"] }
|
||||
//! rust_util = "0.6.50"
|
||||
//! serde_json = "1.0.145"
|
||||
//! rust-crypto-hatter-fork = "0.2"
|
||||
//! ```
|
||||
|
||||
use clap::{Args, Parser, Subcommand};
|
||||
use rust_util::{failure, success, util_cmd};
|
||||
use crypto::digest::Digest;
|
||||
use crypto::sha2::Sha256;
|
||||
use keyring::Entry;
|
||||
use rust_util::{
|
||||
failure, information, opt_result, simple_error, success, util_cmd, util_file, XResult,
|
||||
};
|
||||
use serde_json::Value;
|
||||
use std::fs;
|
||||
use std::process::Command;
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
@@ -47,7 +57,7 @@ fn main() {
|
||||
match args.command {
|
||||
Commands::Connect(cmd) => {
|
||||
if cmd.update {
|
||||
update_proxy();
|
||||
update_pac_file_ignore_error();
|
||||
}
|
||||
turn_proxy_off();
|
||||
run_command(
|
||||
@@ -60,15 +70,48 @@ fn main() {
|
||||
turn_proxy_off();
|
||||
}
|
||||
Commands::Update => {
|
||||
update_proxy();
|
||||
update_pac_file_ignore_error();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn update_proxy() {
|
||||
// TODO ...
|
||||
// check file exists and digest: __proxy__.pac
|
||||
// &digest=1 // get digest
|
||||
fn update_pac_file_ignore_error() {
|
||||
match update_pac_file() {
|
||||
Ok(_) => success!("Update proxy successfully"),
|
||||
Err(error) => failure!("Update proxy failed: {}", error),
|
||||
}
|
||||
}
|
||||
|
||||
fn update_pac_file() -> XResult<()> {
|
||||
let digest = get_pac_digest()?;
|
||||
|
||||
let pac_file = "__proxy__.pac";
|
||||
let pac_file_content = util_file::read_file_content(pac_file)?;
|
||||
|
||||
let mut sha256 = Sha256::new();
|
||||
sha256.input(pac_file_content.as_bytes());
|
||||
let pac_file_digest = format!("sha256-{}", sha256.result_str());
|
||||
|
||||
if digest == pac_file_digest {
|
||||
success!("Pac file digest matches.");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
information!(
|
||||
"Pac file digest mismatch, \n - remote: {}, \n - local : {}",
|
||||
digest,
|
||||
pac_file_digest
|
||||
);
|
||||
|
||||
let pac_content = get_pac_content()?;
|
||||
opt_result!(
|
||||
fs::write(pac_file, pac_content),
|
||||
"Write file {}, failed: {}",
|
||||
pac_file
|
||||
);
|
||||
|
||||
success!("Pac file updated successfully.");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn turn_proxy_off() {
|
||||
@@ -101,5 +144,75 @@ fn run_command(program: &str, args: &[&str], message: &str) {
|
||||
}
|
||||
}
|
||||
|
||||
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20251013T231311+08:00.MEYCIQCuJnrPEuafEEzqTyyW
|
||||
// TkvJvXUUg9c2+OiVtcr1owBkEwIhALCq8vFJyJTb2ftplPN1Q3PzRZFNkfdWovo8DMiyaEc5
|
||||
fn get_pac_content() -> XResult<String> {
|
||||
let auth_token = get_pac_auth_token()?;
|
||||
let url = format!(
|
||||
"https://hatter.ink/pac/get_pac.action?__auth_token={}",
|
||||
auth_token
|
||||
);
|
||||
|
||||
let pac_content_response =
|
||||
opt_result!(reqwest::blocking::get(&url), "Get pac content failed: {}");
|
||||
if pac_content_response.status().as_u16() != 200 {
|
||||
return simple_error!(
|
||||
"Get pac content HTTP status error: {}",
|
||||
pac_content_response.status().as_u16()
|
||||
);
|
||||
}
|
||||
let pac_content_text = opt_result!(
|
||||
pac_content_response.text(),
|
||||
"Get pac digest response failed: {}"
|
||||
);
|
||||
Ok(pac_content_text)
|
||||
}
|
||||
|
||||
fn get_pac_digest() -> XResult<String> {
|
||||
let auth_token = get_pac_auth_token()?;
|
||||
let url = format!(
|
||||
"https://hatter.ink/pac/get_pac.action?digest=1&__auth_token={}",
|
||||
auth_token
|
||||
);
|
||||
|
||||
let pac_digest_response =
|
||||
opt_result!(reqwest::blocking::get(&url), "Get pac digest failed: {}");
|
||||
if pac_digest_response.status().as_u16() != 200 {
|
||||
return simple_error!(
|
||||
"Get pac digest HTTP status error: {}",
|
||||
pac_digest_response.status().as_u16()
|
||||
);
|
||||
}
|
||||
let pac_digest_text = opt_result!(
|
||||
pac_digest_response.text(),
|
||||
"Get pac digest response failed: {}"
|
||||
);
|
||||
let pac_digest_value: Value = opt_result!(
|
||||
serde_json::from_str(&pac_digest_text),
|
||||
"Parse pac digest failed: {}"
|
||||
);
|
||||
if let Some(data) = pac_digest_value.get("data") {
|
||||
if let Some(digest) = data.get("digest") {
|
||||
match digest {
|
||||
Value::String(digest) => Ok(digest.to_string()),
|
||||
_ => simple_error!("Cannot get pac digest data.digest not string"),
|
||||
}
|
||||
} else {
|
||||
simple_error!("Cannot get pac digest data.digest")
|
||||
}
|
||||
} else {
|
||||
simple_error!("Cannot get pac digest data")
|
||||
}
|
||||
}
|
||||
|
||||
fn get_pac_auth_token() -> XResult<String> {
|
||||
let entry = opt_result!(
|
||||
Entry::new("hatter.ink", "get_pac_auth_token"),
|
||||
"New entry failed: {}"
|
||||
);
|
||||
Ok(opt_result!(
|
||||
entry.get_password(),
|
||||
"get password from keyring failed: {}"
|
||||
))
|
||||
}
|
||||
|
||||
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20251019T152450+08:00.MEUCIQDzZTpk54DYe9u/FrsQ
|
||||
// 7OPRmEHLjUelAZUevqPHa7nFEgIgf/Xw73PwCE3miSNXmXawWh6CsrGfk1urRW0zpZOH30M=
|
||||
|
||||
Reference in New Issue
Block a user