Use generated certificate

This commit is contained in:
KingRainbow44
2022-05-29 22:27:04 -04:00
parent 1b945253b6
commit 2e90635ba5
6 changed files with 16 additions and 12 deletions

View File

@@ -2,6 +2,7 @@
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="HtmlUnknownBooleanAttribute" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="JSIgnoredPromiseFromCall" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
</profile>
</component>

View File

@@ -97,7 +97,7 @@ fn enable_process_watcher(process: String) {
}
#[tauri::command]
async fn connect(port: u16) {
async fn connect(port: u16, certificate_path: String) {
// Log message to console.
println!("Connecting to proxy...");
@@ -105,7 +105,7 @@ async fn connect(port: u16) {
proxy::connect_to_proxy(port);
// Create and start a proxy.
proxy::create_proxy(port).await;
proxy::create_proxy(port, certificate_path).await;
}
#[tauri::command]

View File

@@ -73,10 +73,10 @@ impl HttpHandler for ProxyHandler {
/**
* Starts an HTTP(S) proxy server.
*/
pub(crate) async fn create_proxy(proxy_port: u16) {
pub async fn create_proxy(proxy_port: u16, certificate_path: String) {
// Get the certificate and private key.
let mut private_key_bytes: &[u8] = include_bytes!("../resources/private-key.pem");
let mut ca_cert_bytes: &[u8] = include_bytes!("../resources/ca-certificate.pem");
let mut private_key_bytes: &[u8] = include_bytes!(format!("{}/private.key", certificate_path));
let mut ca_cert_bytes: &[u8] = include_bytes!(format!("{}/cert.crt", certificate_path));
// Parse the private key and certificate.
let private_key = rustls::PrivateKey(
@@ -110,7 +110,7 @@ pub(crate) async fn create_proxy(proxy_port: u16) {
/**
* Connects to the local HTTP(S) proxy server.
*/
pub(crate) fn connect_to_proxy(proxy_port: u16) {
pub fn connect_to_proxy(proxy_port: u16) {
if cfg!(target_os = "windows") {
// Create 'ProxyServer' string.
let server_string: String = format!("http=127.0.0.1:{};https=127.0.0.1:{}", proxy_port, proxy_port);
@@ -129,7 +129,7 @@ pub(crate) fn connect_to_proxy(proxy_port: u16) {
/**
* Disconnects from the local HTTP(S) proxy server.
*/
pub(crate) fn disconnect_from_proxy() {
pub fn disconnect_from_proxy() {
if cfg!(target_os = "windows") {
// Fetch the 'Internet Settings' registry key.
let settings = Hive::CurrentUser.open(r"Software\Microsoft\Windows\CurrentVersion\Internet Settings", Security::Write).unwrap();
@@ -147,7 +147,7 @@ pub(crate) fn disconnect_from_proxy() {
* Source: https://github.com/zu1k/good-mitm/raw/master/src/ca/gen.rs
*/
#[tauri::command]
pub(crate) fn generate_ca_files(path: &str) {
pub fn generate_ca_files(path: &str) {
let mut params = CertificateParams::default();
let mut details = DistinguishedName::new();
@@ -201,7 +201,7 @@ pub(crate) fn generate_ca_files(path: &str) {
/*
* Attempts to install the certificate authority's certificate into the Root CA store.
*/
pub(crate) fn install_ca_files(path: &str) {
pub fn install_ca_files(path: &str) {
if cfg!(target_os = "windows") {
run_command(format!("certutil -addstore -f \"ROOT\" {}\\ca\\certificate.crt", path).to_string());
} else {

View File

@@ -12,6 +12,7 @@ const root = ReactDOM.createRoot(
root.render(
<React.StrictMode>
<App />
{/*<Test />*/}
</React.StrictMode>
)
@@ -19,4 +20,4 @@ root.render(
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
import reportWebVitals from './utils/reportWebVitals'
reportWebVitals()
reportWebVitals()

View File

@@ -1,9 +1,10 @@
import React from 'react'
import {invoke} from '@tauri-apps/api/tauri'
import {dataDir} from '@tauri-apps/api/path'
async function startProxy() {
await invoke('connect', { port: 2222 })
await invoke('connect', { port: 2222, certificate_path: await dataDir() + '\\ca' })
}
async function stopProxy() {

View File

@@ -9,6 +9,7 @@ import { invoke } from '@tauri-apps/api/tauri'
import Server from '../../resources/icons/server.svg'
import './ServerLaunchSection.css'
import {dataDir} from '@tauri-apps/api/path'
interface IProps {
[key: string]: any
@@ -105,7 +106,7 @@ export default class ServerLaunchSection extends React.Component<IProps, IState>
})
// Connect to proxy
await invoke('connect', { port: 8365 })
await invoke('connect', { port: 8365, certificate_path: await dataDir() + '\\ca' })
}
// Launch the program