mirror of
https://git.verdigado.com/NB-Public/simple-wkd.git
synced 2024-10-30 11:05:53 +01:00
Move validate_cert from macro to function
This commit is contained in:
parent
a61f03f412
commit
711d626aa9
3 changed files with 11 additions and 14 deletions
|
@ -5,8 +5,8 @@ use log::{debug, error, warn};
|
||||||
use crate::errors::SpecialErrors;
|
use crate::errors::SpecialErrors;
|
||||||
use crate::management::{delete_key, Action, Pending};
|
use crate::management::{delete_key, Action, Pending};
|
||||||
use crate::settings::{MAILER, SETTINGS};
|
use crate::settings::{MAILER, SETTINGS};
|
||||||
use crate::utils::{get_email_from_cert, insert_key, parse_pem, read_file};
|
use crate::utils::{get_email_from_cert, insert_key, parse_pem, read_file, validate_cert};
|
||||||
use crate::{log_err, pending_path, validate_cert};
|
use crate::{log_err, pending_path};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
use lettre::{AsyncTransport, Message};
|
use lettre::{AsyncTransport, Message};
|
||||||
|
@ -25,7 +25,7 @@ pub fn confirm_action(token: &str) -> Result<(Action, String)> {
|
||||||
let address = match key.action() {
|
let address = match key.action() {
|
||||||
Action::Add => {
|
Action::Add => {
|
||||||
let cert = parse_pem(key.data())?;
|
let cert = parse_pem(key.data())?;
|
||||||
let validcert = validate_cert!(cert)?;
|
let validcert = validate_cert(&cert)?;
|
||||||
let email = get_email_from_cert(&validcert)?;
|
let email = get_email_from_cert(&validcert)?;
|
||||||
log_err!(insert_key(&validcert), warn)?;
|
log_err!(insert_key(&validcert), warn)?;
|
||||||
email
|
email
|
||||||
|
|
|
@ -11,7 +11,7 @@ use crate::management::{clean_stale, store_pending_addition, store_pending_delet
|
||||||
use crate::settings::{ROOT_FOLDER, SETTINGS};
|
use crate::settings::{ROOT_FOLDER, SETTINGS};
|
||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
gen_random_token, get_email_from_cert, is_email_allowed, key_exists, parse_pem, read_file,
|
gen_random_token, get_email_from_cert, is_email_allowed, key_exists, parse_pem, read_file,
|
||||||
return_outcome,
|
return_outcome, validate_cert
|
||||||
};
|
};
|
||||||
|
|
||||||
use actix_files::Files;
|
use actix_files::Files;
|
||||||
|
@ -102,7 +102,7 @@ async fn index(req: HttpRequest) -> Result<HttpResponse, CompatErr> {
|
||||||
#[post("/api/submit")]
|
#[post("/api/submit")]
|
||||||
async fn submit(pem: web::Form<Key>) -> Result<HttpResponse, CompatErr> {
|
async fn submit(pem: web::Form<Key>) -> Result<HttpResponse, CompatErr> {
|
||||||
let cert = parse_pem(&pem.key)?;
|
let cert = parse_pem(&pem.key)?;
|
||||||
let validcert = validate_cert!(cert)?;
|
let validcert = validate_cert(&cert)?;
|
||||||
if validcert.is_tsk() {
|
if validcert.is_tsk() {
|
||||||
Err(SpecialErrors::ContainsSecret)?
|
Err(SpecialErrors::ContainsSecret)?
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,14 +24,11 @@ use std::{
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[macro_export]
|
pub fn validate_cert(cert: &Cert) -> Result<ValidCert> {
|
||||||
macro_rules! validate_cert {
|
match log_err!(cert.with_policy(crate::settings::POLICY, None), debug) {
|
||||||
( $x:expr ) => {
|
|
||||||
match log_err!($x.with_policy($crate::settings::POLICY, None), debug) {
|
|
||||||
Ok(validcert) => Ok(validcert),
|
Ok(validcert) => Ok(validcert),
|
||||||
Err(_) => Err($crate::errors::SpecialErrors::InvalidCert),
|
Err(_) => Err(SpecialErrors::InvalidCert)?,
|
||||||
}
|
}
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn encode_local(local: &str) -> String {
|
pub fn encode_local(local: &str) -> String {
|
||||||
|
@ -106,7 +103,7 @@ pub fn parse_pem(pemfile: &str) -> Result<Cert> {
|
||||||
Ok(cert) => cert,
|
Ok(cert) => cert,
|
||||||
Err(_) => Err(SpecialErrors::MalformedCert)?,
|
Err(_) => Err(SpecialErrors::MalformedCert)?,
|
||||||
};
|
};
|
||||||
validate_cert!(cert)?;
|
validate_cert(&cert)?;
|
||||||
Ok(cert)
|
Ok(cert)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue