Skip to main content

Mountain/Binary/Build/TlsCommands/
tls_renew_certificate.rs

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