diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 243810e..dfebeae 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -37,10 +37,12 @@ fn main() { req_get, get_bg_file, base64_decode, + system_helpers::run_command, system_helpers::run_program, system_helpers::run_jar, system_helpers::open_in_browser, proxy::set_proxy_addr, + proxy::generate_ca_files, unzip::unzip, file_helpers::rename, file_helpers::dir_exists, diff --git a/src-tauri/src/proxy.rs b/src-tauri/src/proxy.rs index 76e5221..c5c9396 100644 --- a/src-tauri/src/proxy.rs +++ b/src-tauri/src/proxy.rs @@ -146,7 +146,8 @@ pub(crate) fn disconnect_from_proxy() { * Additionally installs the certificate and private key in the Root CA store. * Source: https://github.com/zu1k/good-mitm/raw/master/src/ca/gen.rs */ -pub(crate) fn generate_ca_files() { +#[tauri::command] +pub(crate) fn generate_ca_files(path: &str) { let mut params = CertificateParams::default(); let mut details = DistinguishedName::new(); @@ -169,8 +170,23 @@ pub(crate) fn generate_ca_files() { // Create certificate. let cert = Certificate::from_params(params).unwrap(); let cert_crt = cert.serialize_pem().unwrap(); + let cert_path = format!("{}\\ca", path); + + fs::create_dir(&cert_path).unwrap(); + + println!("{}", cert_crt); - // TODO: Save certificates. + match fs::write(format!("{}\\cert.crt", &cert_path), cert_crt) { + Ok(_) => println!("Wrote certificate to {}", &cert_path), + Err(e) => println!("Error writing certificate to {}: {}", &cert_path, e), + } + + let private_key = cert.serialize_private_key_pem(); + + match fs::write(format!("{}\\private.key", &cert_path), private_key) { + Ok(_) => println!("Wrote private key to {}", &cert_path), + Err(e) => println!("Error writing private key to {}: {}", &cert_path, e), + } // Install certificate into the system's Root CA store. install_ca_files(); diff --git a/src-tauri/src/system_helpers.rs b/src-tauri/src/system_helpers.rs index 3794ced..ed497e9 100644 --- a/src-tauri/src/system_helpers.rs +++ b/src-tauri/src/system_helpers.rs @@ -15,11 +15,11 @@ pub fn run_program(path: String) { } #[tauri::command] -pub fn run_command(command: String) -> String { +pub fn run_command(command: String) { // Run the specified command. let output = if cfg!(target_os = "windows") { Command::new("cmd") - .args(["/C", command]) + .args(["/C", command.as_str()]) .output() .expect("failed to execute process") } else { @@ -29,8 +29,6 @@ pub fn run_command(command: String) -> String { .output() .expect("failed to execute process") }; - - output.stdout.to_string() } #[tauri::command]