From 3891bbbe3d229d2a9958fbd994142364349497be Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Mon, 23 May 2022 00:05:31 -0400 Subject: [PATCH] Install CA certificate --- src-tauri/src/proxy.rs | 18 +++++++++++++++++- src-tauri/src/system_helpers.rs | 22 +++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/proxy.rs b/src-tauri/src/proxy.rs index facd55a..76e5221 100644 --- a/src-tauri/src/proxy.rs +++ b/src-tauri/src/proxy.rs @@ -20,6 +20,7 @@ use registry::{Hive, Data, Security}; use rustls_pemfile as pemfile; use tauri::http::Uri; +use crate::system_helpers::run_command; async fn shutdown_signal() { tokio::signal::ctrl_c().await @@ -170,5 +171,20 @@ pub(crate) fn generate_ca_files() { let cert_crt = cert.serialize_pem().unwrap(); // TODO: Save certificates. - // TODO: Install certificates. + + // Install certificate into the system's Root CA store. + install_ca_files(); +} + +/* + * Attempts to install the certificate authority's certificate into the Root CA store. + */ +pub(crate) fn install_ca_files() { + if cfg!(target_os = "windows") { + run_command("certutil -addstore -f \"ROOT\" ca/certificate.crt".to_string()); + } else { + run_command("sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ca/certificate.crt".to_string()); + } + + println!("Installed certificate."); } \ No newline at end of file diff --git a/src-tauri/src/system_helpers.rs b/src-tauri/src/system_helpers.rs index b56f0bb..3794ced 100644 --- a/src-tauri/src/system_helpers.rs +++ b/src-tauri/src/system_helpers.rs @@ -1,5 +1,6 @@ use std::thread; +use std::process::Command; use tauri; use open; @@ -7,12 +8,31 @@ use open; pub fn run_program(path: String) { // Open the program from the specified path. - // Open in new thread to prevent blocking + // Open in new thread to prevent blocking. thread::spawn(move || { open::that(&path).unwrap(); }); } +#[tauri::command] +pub fn run_command(command: String) -> String { + // Run the specified command. + let output = if cfg!(target_os = "windows") { + Command::new("cmd") + .args(["/C", command]) + .output() + .expect("failed to execute process") + } else { + Command::new("sh") + .arg("-c") + .arg(command) + .output() + .expect("failed to execute process") + }; + + output.stdout.to_string() +} + #[tauri::command] pub fn run_jar(path: String, execute_in: String, java_path: String) { let command = if java_path.is_empty() {