mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-12 15:14:35 +01:00
generate and install cert based on config setting
This commit is contained in:
@@ -172,7 +172,13 @@ pub(crate) fn generate_ca_files(path: &str) {
|
|||||||
let cert_crt = cert.serialize_pem().unwrap();
|
let cert_crt = cert.serialize_pem().unwrap();
|
||||||
let cert_path = format!("{}\\ca", path);
|
let cert_path = format!("{}\\ca", path);
|
||||||
|
|
||||||
fs::create_dir(&cert_path).unwrap();
|
match fs::create_dir(&cert_path) {
|
||||||
|
Ok(_) => {},
|
||||||
|
Err(e) => {
|
||||||
|
println!("{}", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
println!("{}", cert_crt);
|
println!("{}", cert_crt);
|
||||||
|
|
||||||
@@ -189,17 +195,17 @@ pub(crate) fn generate_ca_files(path: &str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Install certificate into the system's Root CA store.
|
// Install certificate into the system's Root CA store.
|
||||||
install_ca_files();
|
install_ca_files(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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() {
|
pub(crate) fn install_ca_files(path: &str) {
|
||||||
if cfg!(target_os = "windows") {
|
if cfg!(target_os = "windows") {
|
||||||
run_command("certutil -addstore -f \"ROOT\" ca/certificate.crt".to_string());
|
run_command(format!("certutil -addstore -f \"ROOT\" {}\\ca\\certificate.crt", path).to_string());
|
||||||
} else {
|
} else {
|
||||||
run_command("sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ca/certificate.crt".to_string());
|
run_command(format!("sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain {}/ca/certificate.crt", path).to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("Installed certificate.");
|
println!("Installed certificate.");
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import NewsSection from './components/news/NewsSection'
|
|||||||
import RightBar from './components/RightBar'
|
import RightBar from './components/RightBar'
|
||||||
import { getConfigOption, setConfigOption } from '../utils/configuration'
|
import { getConfigOption, setConfigOption } from '../utils/configuration'
|
||||||
import { invoke } from '@tauri-apps/api'
|
import { invoke } from '@tauri-apps/api'
|
||||||
|
import { dataDir } from '@tauri-apps/api/path'
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
[key: string]: never;
|
[key: string]: never;
|
||||||
@@ -52,6 +53,7 @@ class App extends React.Component<IProps, IState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
|
const cert_generated = await getConfigOption('cert_generated')
|
||||||
const game_exe = await getConfigOption('game_install_path')
|
const game_exe = await getConfigOption('game_install_path')
|
||||||
const game_path = game_exe.substring(0, game_exe.lastIndexOf('\\'))
|
const game_path = game_exe.substring(0, game_exe.lastIndexOf('\\'))
|
||||||
const root_path = game_path.substring(0, game_path.lastIndexOf('\\'))
|
const root_path = game_path.substring(0, game_path.lastIndexOf('\\'))
|
||||||
@@ -68,6 +70,15 @@ class App extends React.Component<IProps, IState> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!cert_generated) {
|
||||||
|
// Generate the certificate
|
||||||
|
await invoke('generate_ca_files', {
|
||||||
|
path: await dataDir() + 'cultivation'
|
||||||
|
})
|
||||||
|
|
||||||
|
await setConfigOption('cert_generated', true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ let defaultConfig: Configuration
|
|||||||
last_port: '',
|
last_port: '',
|
||||||
language: 'en',
|
language: 'en',
|
||||||
customBackground: '',
|
customBackground: '',
|
||||||
|
cert_generated: false,
|
||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
|
|
||||||
@@ -35,6 +36,7 @@ export interface Configuration {
|
|||||||
last_port: string
|
last_port: string
|
||||||
language: string
|
language: string
|
||||||
customBackground: string
|
customBackground: string
|
||||||
|
cert_generated: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function setConfigOption(key: string, value: any): Promise<void> {
|
export async function setConfigOption(key: string, value: any): Promise<void> {
|
||||||
@@ -94,7 +96,6 @@ async function readConfigFile() {
|
|||||||
await fs.createDir(local + 'cultivation\\grasscutter')
|
await fs.createDir(local + 'cultivation\\grasscutter')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const dataFiles = await fs.readDir(local + 'cultivation')
|
const dataFiles = await fs.readDir(local + 'cultivation')
|
||||||
|
|
||||||
// Ensure config exists
|
// Ensure config exists
|
||||||
|
|||||||
Reference in New Issue
Block a user