mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-14 08:04:52 +01:00
Use generated certificate
This commit is contained in:
1
.idea/inspectionProfiles/Project_Default.xml
generated
1
.idea/inspectionProfiles/Project_Default.xml
generated
@@ -2,6 +2,7 @@
|
|||||||
<profile version="1.0">
|
<profile version="1.0">
|
||||||
<option name="myName" value="Project Default" />
|
<option name="myName" value="Project Default" />
|
||||||
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
|
<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" />
|
<inspection_tool class="JSIgnoredPromiseFromCall" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
||||||
</profile>
|
</profile>
|
||||||
</component>
|
</component>
|
||||||
@@ -97,7 +97,7 @@ fn enable_process_watcher(process: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn connect(port: u16) {
|
async fn connect(port: u16, certificate_path: String) {
|
||||||
// Log message to console.
|
// Log message to console.
|
||||||
println!("Connecting to proxy...");
|
println!("Connecting to proxy...");
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ async fn connect(port: u16) {
|
|||||||
proxy::connect_to_proxy(port);
|
proxy::connect_to_proxy(port);
|
||||||
|
|
||||||
// Create and start a proxy.
|
// Create and start a proxy.
|
||||||
proxy::create_proxy(port).await;
|
proxy::create_proxy(port, certificate_path).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
|
|||||||
@@ -73,10 +73,10 @@ impl HttpHandler for ProxyHandler {
|
|||||||
/**
|
/**
|
||||||
* Starts an HTTP(S) proxy server.
|
* 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.
|
// Get the certificate and private key.
|
||||||
let mut private_key_bytes: &[u8] = include_bytes!("../resources/private-key.pem");
|
let mut private_key_bytes: &[u8] = include_bytes!(format!("{}/private.key", certificate_path));
|
||||||
let mut ca_cert_bytes: &[u8] = include_bytes!("../resources/ca-certificate.pem");
|
let mut ca_cert_bytes: &[u8] = include_bytes!(format!("{}/cert.crt", certificate_path));
|
||||||
|
|
||||||
// Parse the private key and certificate.
|
// Parse the private key and certificate.
|
||||||
let private_key = rustls::PrivateKey(
|
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.
|
* 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") {
|
if cfg!(target_os = "windows") {
|
||||||
// Create 'ProxyServer' string.
|
// Create 'ProxyServer' string.
|
||||||
let server_string: String = format!("http=127.0.0.1:{};https=127.0.0.1:{}", proxy_port, proxy_port);
|
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.
|
* Disconnects from the local HTTP(S) proxy server.
|
||||||
*/
|
*/
|
||||||
pub(crate) fn disconnect_from_proxy() {
|
pub fn disconnect_from_proxy() {
|
||||||
if cfg!(target_os = "windows") {
|
if cfg!(target_os = "windows") {
|
||||||
// Fetch the 'Internet Settings' registry key.
|
// Fetch the 'Internet Settings' registry key.
|
||||||
let settings = Hive::CurrentUser.open(r"Software\Microsoft\Windows\CurrentVersion\Internet Settings", Security::Write).unwrap();
|
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
|
* Source: https://github.com/zu1k/good-mitm/raw/master/src/ca/gen.rs
|
||||||
*/
|
*/
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub(crate) fn generate_ca_files(path: &str) {
|
pub fn generate_ca_files(path: &str) {
|
||||||
let mut params = CertificateParams::default();
|
let mut params = CertificateParams::default();
|
||||||
let mut details = DistinguishedName::new();
|
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.
|
* 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") {
|
if cfg!(target_os = "windows") {
|
||||||
run_command(format!("certutil -addstore -f \"ROOT\" {}\\ca\\certificate.crt", path).to_string());
|
run_command(format!("certutil -addstore -f \"ROOT\" {}\\ca\\certificate.crt", path).to_string());
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ const root = ReactDOM.createRoot(
|
|||||||
root.render(
|
root.render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
<App />
|
<App />
|
||||||
|
{/*<Test />*/}
|
||||||
</React.StrictMode>
|
</React.StrictMode>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
import {invoke} from '@tauri-apps/api/tauri'
|
import {invoke} from '@tauri-apps/api/tauri'
|
||||||
|
import {dataDir} from '@tauri-apps/api/path'
|
||||||
|
|
||||||
async function startProxy() {
|
async function startProxy() {
|
||||||
await invoke('connect', { port: 2222 })
|
await invoke('connect', { port: 2222, certificate_path: await dataDir() + '\\ca' })
|
||||||
}
|
}
|
||||||
|
|
||||||
async function stopProxy() {
|
async function stopProxy() {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { invoke } from '@tauri-apps/api/tauri'
|
|||||||
|
|
||||||
import Server from '../../resources/icons/server.svg'
|
import Server from '../../resources/icons/server.svg'
|
||||||
import './ServerLaunchSection.css'
|
import './ServerLaunchSection.css'
|
||||||
|
import {dataDir} from '@tauri-apps/api/path'
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
[key: string]: any
|
[key: string]: any
|
||||||
@@ -105,7 +106,7 @@ export default class ServerLaunchSection extends React.Component<IProps, IState>
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Connect to proxy
|
// Connect to proxy
|
||||||
await invoke('connect', { port: 8365 })
|
await invoke('connect', { port: 8365, certificate_path: await dataDir() + '\\ca' })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Launch the program
|
// Launch the program
|
||||||
|
|||||||
Reference in New Issue
Block a user