Skip to main content

Mountain/Binary/Build/TlsCommands/
tls_renew_certificate.rs

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