diff options
author | Quentin Dufour <quentin@deuxfleurs.fr> | 2023-12-06 20:57:25 +0100 |
---|---|---|
committer | Quentin Dufour <quentin@deuxfleurs.fr> | 2023-12-06 20:57:25 +0100 |
commit | 3ddbce4529225fe004acde3ab2e95261673bafc3 (patch) | |
tree | 799b7fa0e1aa8d173c89a2124ffc2865f3d6ced0 /src/login/static_provider.rs | |
parent | 2779837a3750c3b2964c3a4d5d43de25218bc605 (diff) | |
download | aerogramme-3ddbce4529225fe004acde3ab2e95261673bafc3.tar.gz aerogramme-3ddbce4529225fe004acde3ab2e95261673bafc3.zip |
WIP refactor
Diffstat (limited to 'src/login/static_provider.rs')
-rw-r--r-- | src/login/static_provider.rs | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/src/login/static_provider.rs b/src/login/static_provider.rs index 0b726cb..3f6a840 100644 --- a/src/login/static_provider.rs +++ b/src/login/static_provider.rs @@ -1,5 +1,6 @@ use std::collections::HashMap; use std::sync::Arc; +use std::path::PathBuf; use anyhow::{anyhow, bail, Result}; use async_trait::async_trait; @@ -10,13 +11,28 @@ use crate::login::*; use crate::storage; pub struct StaticLoginProvider { - users: HashMap<String, Arc<LoginStaticUser>>, - users_by_email: HashMap<String, Arc<LoginStaticUser>>, + user_list: PathBuf, + users: HashMap<String, Arc<UserEntry>>, + users_by_email: HashMap<String, Arc<UserEntry>>, } impl StaticLoginProvider { pub fn new(config: LoginStaticConfig) -> Result<Self> { - let users = config + let mut lp = Self { + user_list: config.user_list, + users: HashMap::new(), + users_by_email: HashMap::new(), + }; + + lp.update_user_list(); + + Ok(lp) + } + + pub fn update_user_list(&mut self) -> Result<()> { + let ulist: UserList = read_config(self.user_list)?; + + let users = ulist .into_iter() .map(|(k, v)| (k, Arc::new(v))) .collect::<HashMap<_, _>>(); @@ -29,11 +45,7 @@ impl StaticLoginProvider { users_by_email.insert(m.clone(), u.clone()); } } - - Ok(Self { - users, - users_by_email, - }) + Ok(()) } } @@ -64,24 +76,18 @@ impl LoginProvider for StaticLoginProvider { }), }; - let keys = match (&user.master_key, &user.secret_key) { - (Some(m), Some(s)) => { + let keys = match user.crypto_root { /*(&user.master_key, &user.secret_key) {*/ + CryptographyRoot::InPlace { master_key: m, secret_key: s } => { let master_key = Key::from_slice(&base64::decode(m)?).ok_or(anyhow!("Invalid master key"))?; let secret_key = SecretKey::from_slice(&base64::decode(s)?) .ok_or(anyhow!("Invalid secret key"))?; CryptoKeys::open_without_password(&storage, &master_key, &secret_key).await? } - (None, None) => { - let user_secrets = UserSecrets { - user_secret: user.user_secret.clone(), - alternate_user_secrets: user.alternate_user_secrets.clone(), - }; - CryptoKeys::open(&storage, &user_secrets, password).await? + CryptographyRoot::PasswordProtected => { + CryptoKeys::open(&storage, password).await? } - _ => bail!( - "Either both master and secret key or none of them must be specified for user" - ), + CryptographyRoot::Keyring => unimplemented!(), }; tracing::debug!(user=%username, "logged"); |