0
0
Fork 0
mirror of https://git.verdigado.com/NB-Public/simple-wkd.git synced 2024-10-30 09:05:52 +01:00

Allow to set sequoia StandardPolicy with a toml configuration file using the sequoia_policy_config crate.

This commit is contained in:
RisingOpsNinja 2024-09-04 11:37:31 +02:00
parent c2e5dfac76
commit 82895eddfe
3 changed files with 16 additions and 2 deletions

View file

@ -20,3 +20,4 @@ tokio = { version = "1.27.0", features = ["time"] }
toml = "0.7.3" toml = "0.7.3"
url = { version = "2.3.1", features = ["serde"] } url = { version = "2.3.1", features = ["serde"] }
zbase32 = "0.1.2" zbase32 = "0.1.2"
sequoia-policy-config = { version = "0.6" }

View file

@ -2,6 +2,7 @@ use lettre::{transport::smtp::authentication::Credentials, AsyncSmtpTransport, T
use log::{debug, error}; use log::{debug, error};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use sequoia_openpgp::policy::StandardPolicy; use sequoia_openpgp::policy::StandardPolicy;
use sequoia_policy_config::ConfiguredStandardPolicy;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::path::PathBuf; use std::path::PathBuf;
use url::Url; use url::Url;
@ -93,8 +94,19 @@ fn get_mailer() -> AsyncSmtpTransport<Tokio1Executor> {
.build() .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 ERROR_TEXT: &str = "An error occoured:";
pub const POLICY: &StandardPolicy = &StandardPolicy::new(); pub static POLICY: Lazy<StandardPolicy> = Lazy::new(get_policy);
pub const ROOT_FOLDER: &str = "data"; pub const ROOT_FOLDER: &str = "data";
pub static SETTINGS: Lazy<Settings> = Lazy::new(get_settings); pub static SETTINGS: Lazy<Settings> = Lazy::new(get_settings);
pub static MAILER: Lazy<AsyncSmtpTransport<Tokio1Executor>> = Lazy::new(get_mailer); pub static MAILER: Lazy<AsyncSmtpTransport<Tokio1Executor>> = Lazy::new(get_mailer);

View file

@ -4,6 +4,7 @@ use crate::log_err;
use crate::settings::Variant; use crate::settings::Variant;
use crate::settings::ROOT_FOLDER; use crate::settings::ROOT_FOLDER;
use crate::settings::SETTINGS; use crate::settings::SETTINGS;
use crate::settings::POLICY;
use actix_web::ResponseError; use actix_web::ResponseError;
use actix_web::{ use actix_web::{
@ -26,7 +27,7 @@ use std::{
}; };
pub fn validate_cert(cert: &Cert) -> Result<ValidCert> { pub fn validate_cert(cert: &Cert) -> Result<ValidCert> {
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, Ok(validcert) => validcert,
Err(_) => Err(SpecialErrors::InvalidCert)?, Err(_) => Err(SpecialErrors::InvalidCert)?,
}; };