Skip to main content

Mountain/Binary/Build/TlsCommands/
tls_get_ca_cert.rs

1#![allow(non_snake_case)]
2
3//! `tls_get_ca_cert` Tauri command - returns the CA certificate
4//! PEM so the webview can pin it or install it into the system
5//! trust store.
6
7use std::sync::{Arc, Mutex};
8
9use tauri::{AppHandle, Manager};
10
11use crate::{Binary::Build::CertificateManager::CertificateManager, dev_log};
12
13#[tauri::command]
14pub async fn tls_get_ca_cert(app_handle:AppHandle) -> Result<String, String> {
15	dev_log!("security", "getting CA certificate");
16
17	let state = app_handle
18		.try_state::<Arc<Mutex<CertificateManager>>>()
19		.ok_or("Certificate manager not found")?;
20	let cert_manager = state.clone();
21
22	let manager = cert_manager.lock().map_err(|e| format!("Failed to acquire lock: {}", e))?;
23	let cert_pem = manager.get_ca_cert_pem().ok_or("CA certificate not initialized")?;
24
25	String::from_utf8(cert_pem).map_err(|e| format!("Invalid certificate UTF-8: {}", e))
26}