You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.7 KiB

//! Authentication
use super::*;
pub struct Sha256Hash(pub sha256::Sha256Hash);
type RsaSignature = rsa::Signature;
impl str::FromStr for Sha256Hash
{
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
todo!() //read encoded base64(?)/hex into `Signature`
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)]
pub struct AuthRequest
{
id: uuid::Uuid,
sign_this: [u8; 32],
salt: [u8; 16],
passwd_is_allowed: bool,
ttl_ms: u64
}
impl AuthRequest
{
/// Create a new auth request
pub fn new(cfg: &settings::Settings) -> Self
{
let mut empty = Self {
id: uuid::Uuid::new_v4(),
sign_this: [0; 32],
salt: [0;16],
passwd_is_allowed: cfg.allow_passwd_auth,
ttl_ms: cfg.auth_req_ttl_millis.jitter(),
};
getrandom(&mut empty.sign_this[..]).expect("fatal rng");
getrandom(&mut empty.salt[..]).expect("fatal rng");
empty
}
}
pub async fn auth_req(who: source::IpAddr, state: Arc<state::State>) -> Result<AuthRequest, Infallible>
{
let req = AuthRequest::new(state.cfg());
trace!("{:?} auth req", who);
// TODO: Add `req` into `state` somehow for later.
// TODO: Use `DelayQueue` to remove `req.id` from the hashmap after `ttl` expires.
Ok(req)
}
pub async fn auth_key(who: source::IpAddr, state: Arc<state::State>, req_id: uuid::Uuid, num: usize, body: Bytes) -> Result<(), Infallible>
{
trace!("{:?} auth resp key <{}>:{}", who, req_id, num);
Ok(())
}
pub async fn auth_pass(who: source::IpAddr, state: Arc<state::State>, req_id: uuid::Uuid, passhash: sha256::Sha256Hash) -> Result<(), Infallible>
{
trace!("{:?} auth resp pass <{}>: \"{}\"", who, req_id, passhash);
Ok(())
}