bws_web_server/ssl/
acme.rs1use log::{info, warn};
3use serde::{Deserialize, Serialize};
4use std::path::PathBuf;
5
6#[derive(Debug, Clone, Deserialize, Serialize)]
7pub struct AcmeConfig {
8 pub directory_url: String,
9 pub contact_email: String, pub terms_agreed: bool, pub challenge_dir: String,
12 pub account_key_file: String,
13 pub enabled: bool,
14 pub staging: bool,
15}
16
17impl Default for AcmeConfig {
18 fn default() -> Self {
19 Self {
20 directory_url: "https://acme-v02.api.letsencrypt.org/directory".to_string(),
21 contact_email: "admin@example.com".to_string(),
22 terms_agreed: false,
23 challenge_dir: "./acme-challenges".to_string(),
24 account_key_file: "./acme-account.key".to_string(),
25 enabled: false,
26 staging: false,
27 }
28 }
29}
30
31#[derive(Debug, Clone)]
32pub struct AcmeClient {
33 config: AcmeConfig,
34}
35
36impl AcmeClient {
37 pub fn new(config: AcmeConfig) -> Self {
38 Self { config }
39 }
40
41 pub async fn obtain_certificate(
42 &mut self,
43 domains: &[String],
44 ) -> Result<(String, String), Box<dyn std::error::Error + Send + Sync>> {
45 self.request_certificate(domains).await
46 }
47
48 pub fn get_challenge_content(&self, _token: &str) -> Option<String> {
49 None
51 }
52
53 pub async fn request_certificate(
54 &mut self,
55 domains: &[String],
56 ) -> Result<(String, String), Box<dyn std::error::Error + Send + Sync>> {
57 warn!("ACME certificate request not implemented in this version");
58 info!("Requested certificate for domains: {:?}", domains);
59
60 Err("ACME implementation is a placeholder".into())
62 }
63
64 pub fn get_challenge_path(&self, token: &str) -> PathBuf {
65 PathBuf::from(&self.config.challenge_dir)
66 .join(".well-known")
67 .join("acme-challenge")
68 .join(token)
69 }
70
71 pub fn is_enabled(&self) -> bool {
72 self.config.enabled
73 }
74}