use crate::{
auth::UserDetail,
server::controlchan::{
Reply, ReplyCode,
error::ControlChanError,
handler::{CommandContext, CommandHandler},
},
storage::{Metadata, StorageBackend},
};
use async_trait::async_trait;
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum ProtParam {
Clear,
Safe,
Confidential,
Private,
}
#[derive(Debug)]
pub struct Prot {
param: ProtParam,
}
impl Prot {
pub fn new(param: ProtParam) -> Self {
Prot { param }
}
}
#[async_trait]
impl<Storage, User> CommandHandler<Storage, User> for Prot
where
User: UserDetail,
Storage: StorageBackend<User> + 'static,
Storage::Metadata: 'static + Metadata,
{
#[tracing_attributes::instrument]
async fn handle(&self, args: CommandContext<Storage, User>) -> Result<Reply, ControlChanError> {
match (args.tls_configured, self.param.clone()) {
(true, ProtParam::Clear) => {
let mut session = args.session.lock().await;
session.data_tls = false;
Ok(Reply::new(ReplyCode::CommandOkay, "PROT OK. Switching data channel to plaintext"))
}
(true, ProtParam::Private) => {
let mut session = args.session.lock().await;
session.data_tls = true;
Ok(Reply::new(ReplyCode::CommandOkay, "PROT OK. Securing data channel"))
}
(true, _) => Ok(Reply::new(ReplyCode::CommandNotImplementedForParameter, "PROT S/E not implemented")),
(false, _) => Ok(Reply::new(ReplyCode::CommandNotImplemented, "TLS/SSL not configured")),
}
}
}