Skip to main content

Mountain/Binary/Build/TlsCommands/
tls_renew_certificate.rs

1#![allow(non_snake_case)]
2
3//! `tls_renew_certificate` Tauri command - regenerates the
4//! cached server cert for `hostname`. The renewal fires inside a
5//! `std::sync::Mutex` so the lock must not be held across an await
6//! point today. A future migration to `tokio::sync::Mutex` will let
7//! this function await the renewal directly.
8
9use std::sync::{Arc, Mutex};
10
11use tauri::{AppHandle, Manager};
12
13use crate::{Binary::Build::CertificateManager::CertificateManager, dev_log};
14
15#[tauri::command]
16pub async fn tls_renew_certificate(app_handle:AppHandle, hostname:String) -> Result<String, String> {
17	dev_log!("security", "renewing certificate for {}", hostname);
18
19	let state = app_handle
20		.try_state::<Arc<Mutex<CertificateManager>>>()
21		.ok_or("Certificate manager not found")?;
22
23	let cert_manager = state.clone();
24
25	{
26		let mut manager = cert_manager.lock().map_err(|e| format!("Failed to acquire lock: {}", e))?;
27
28		let _result = manager.renew_certificate(&hostname);
29	}
30
31	Ok(format!("Certificate renewed for {}", hostname))
32}