منبع منتشرشده
دانلود ZIP منبع
CH-J Tools
پوشهها و فایلهای یک نسخهٔ مشخص از برنامه را مرور کنید.
CH-J / Server Manager
1704 فایل
0.1.2-beta
افزودهشده: · ساختهشده:
1
//! Vault and OS-protected unlocking commands.3
use super::{envelope, logged, main_core, payload, text, CommandResult};4
use crate::core::app::CoreSlot;5
use crate::core::error::{CoreError, CoreResult};6
use serde_json::{json, Value};7
use tauri::{Manager, State, Webview};9
fn status_value(status: crate::core::vault::VaultStatus) -> Value {10
serde_json::to_value(status).unwrap_or_else(|_| json!({}))11
}13
#[tauri::command]14
pub async fn core_vault_status(webview: Webview, slot: State<'_, CoreSlot>) -> CommandResult {15
Ok(status_value(main_core(&webview, &slot)?.vault.status()))16
}18
#[tauri::command]19
pub async fn core_vault_create(webview: Webview, slot: State<'_, CoreSlot>, payload: Option<Value>) -> CommandResult {20
let core = main_core(&webview, &slot)?;21
let payload = super::payload(payload);22
let result = core.vault.create(text(&payload, "password")).await.map(status_value);23
if result.is_ok() {24
core.services.lock.activity();25
}26
core.services.availability.changed();27
logged(&core, "vault:create", result)28
}30
#[tauri::command]31
pub async fn core_vault_unlock(webview: Webview, slot: State<'_, CoreSlot>, payload: Option<Value>) -> CommandResult {32
let core = main_core(&webview, &slot)?;33
let payload = super::payload(payload);34
core.services.biometrics.cancel();35
let result = core.vault.unlock(text(&payload, "password")).await.map(status_value);36
if result.is_ok() {37
core.services.biometrics.disarm_auto_unlock();38
core.services.lock.activity();39
}40
core.services.availability.changed();41
logged(&core, "vault:unlock", result)42
}44
#[tauri::command]45
pub async fn core_vault_lock(webview: Webview, slot: State<'_, CoreSlot>) -> CommandResult {46
let core = main_core(&webview, &slot)?;47
let status = core.services.lock.lock(&core, "manual").await;48
core.services.availability.changed();49
Ok(status_value(status))50
}52
#[tauri::command]53
pub async fn core_vault_reset(webview: Webview, slot: State<'_, CoreSlot>, payload: Option<Value>) -> CommandResult {54
let core = main_core(&webview, &slot)?;55
let payload = super::payload(payload);56
let result = async {57
let confirmation = text(&payload, "confirmation");58
if confirmation != "SMAZAT" {59
return Err(CoreError::new("VAULT_RESET_CONFIRMATION_REQUIRED", "Vault reset confirmation is invalid."));60
}61
if core.vault.is_unlocked() {62
core.services.biometrics.require_sensitive_action().await?;63
}64
core.services.biometrics.disable(true).await?;65
core.services.modules.close_all(&core);66
core.services.sessions.disconnect_all("vault-reset").await;67
let status = core.vault.reset(confirmation)?;68
core.logger.warn("Encrypted user vault was reset by the user.", json!({}));69
Ok(status_value(status))70
}71
.await;72
logged(&core, "vault:reset", result)73
}75
async fn biometric<F>(webview: Webview, slot: State<'_, CoreSlot>, work: impl FnOnce(std::sync::Arc<crate::core::app::Core>) -> F) -> CommandResult76
where77
F: std::future::Future<Output = CoreResult<Value>>,78
{79
let core = main_core(&webview, &slot)?;80
Ok(envelope(work(core).await, "SSH_OPERATION_FAILED", None))81
}83
#[tauri::command]84
pub async fn core_biometrics_status(webview: Webview, slot: State<'_, CoreSlot>) -> CommandResult {85
biometric(webview, slot, |core| async move { Ok(core.services.biometrics.status().await) }).await86
}88
#[tauri::command]89
pub async fn core_biometrics_enable(webview: Webview, slot: State<'_, CoreSlot>) -> CommandResult {90
biometric(webview, slot, |core| async move { core.services.biometrics.enable().await }).await91
}93
#[tauri::command]94
pub async fn core_biometrics_disable(webview: Webview, slot: State<'_, CoreSlot>) -> CommandResult {95
biometric(webview, slot, |core| async move { core.services.biometrics.disable(false).await }).await96
}98
#[tauri::command]99
pub async fn core_biometrics_unlock(webview: Webview, slot: State<'_, CoreSlot>) -> CommandResult {100
biometric(webview, slot, |core| async move {101
let status = core.services.biometrics.unlock().await?;102
core.services.lock.activity();103
Ok(status)104
})105
.await106
}108
#[tauri::command]109
pub async fn core_biometrics_auto_unlock(webview: Webview, slot: State<'_, CoreSlot>) -> CommandResult {110
let window = webview.window();111
let ready = window.is_visible().unwrap_or(false) && !window.is_minimized().unwrap_or(true);112
let _ = window.app_handle();113
biometric(webview, slot, move |core| async move {114
if !ready {115
return Ok(json!({ "attempted": false, "reason": "WINDOW_NOT_READY" }));116
}117
let result = core.services.biometrics.auto_unlock().await;118
if result["status"]["unlocked"] == true {119
core.services.lock.activity();120
}121
Ok(result)122
})123
.await124
}126
#[tauri::command]127
pub async fn core_biometrics_authenticate(webview: Webview, slot: State<'_, CoreSlot>) -> CommandResult {128
biometric(webview, slot, |core| async move { core.services.biometrics.authenticate_sensitive_action().await }).await129
}131
pub fn _unused(value: Option<Value>) -> Value {132
payload(value)133
}SHA-256
5be63baad1ff0f34b902f3c5699309907a5a8c4dac3af44ceebbec4605f8309aCH-J Proprietary Software License 1.14 · کد منبع تحت CH-J Proprietary Software License 1.14 ارائه میشود. در دسترس بودن آن شرایط مجوز را تغییر نمیدهد و حق اضافهای اعطا نمیکند.
SHA-256 بایگانی
ac8fe790f4ba60fc098f8c985fc2656cfcc6cdc21fb34b30e308a2b54e62258f