diff --git a/backend/Cargo.toml b/backend/Cargo.toml index cf317ff..8228ad0 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -20,3 +20,4 @@ tokio = { version = "1.27.0", features = ["time"] } toml = "0.7.3" url = { version = "2.3.1", features = ["serde"] } zbase32 = "0.1.2" +sequoia-policy-config = { version = "0.6" } diff --git a/backend/src/settings.rs b/backend/src/settings.rs index 3b330f1..8ec2473 100644 --- a/backend/src/settings.rs +++ b/backend/src/settings.rs @@ -2,6 +2,7 @@ use lettre::{transport::smtp::authentication::Credentials, AsyncSmtpTransport, T use log::{debug, error}; use once_cell::sync::Lazy; use sequoia_openpgp::policy::StandardPolicy; +use sequoia_policy_config::ConfiguredStandardPolicy; use serde::{Deserialize, Serialize}; use std::path::PathBuf; use url::Url; @@ -93,8 +94,19 @@ fn get_mailer() -> AsyncSmtpTransport { .build() } +fn get_policy<'a>() -> StandardPolicy<'a> { + let mut p = ConfiguredStandardPolicy::new(); + + match p.parse_default_config() { + Ok(_) => {}, + Err(e) => error!("{e}"), + } + + p.build() +} + pub const ERROR_TEXT: &str = "An error occoured:"; -pub const POLICY: &StandardPolicy = &StandardPolicy::new(); +pub static POLICY: Lazy = Lazy::new(get_policy); pub const ROOT_FOLDER: &str = "data"; pub static SETTINGS: Lazy = Lazy::new(get_settings); pub static MAILER: Lazy> = Lazy::new(get_mailer); diff --git a/backend/src/utils.rs b/backend/src/utils.rs index 9a8f94e..cd2238a 100644 --- a/backend/src/utils.rs +++ b/backend/src/utils.rs @@ -4,6 +4,7 @@ use crate::log_err; use crate::settings::Variant; use crate::settings::ROOT_FOLDER; use crate::settings::SETTINGS; +use crate::settings::POLICY; use actix_web::ResponseError; use actix_web::{ @@ -26,7 +27,7 @@ use std::{ }; pub fn validate_cert(cert: &Cert) -> Result { - let validcert = match log_err!(cert.with_policy(crate::settings::POLICY, None), debug) { + let validcert = match log_err!(cert.with_policy(&*POLICY, None), debug) { Ok(validcert) => validcert, Err(_) => Err(SpecialErrors::InvalidCert)?, };