Left over changes
This commit is contained in:
parent
7640a235ca
commit
b748ef36d6
7 changed files with 219 additions and 10 deletions
12
src/auth.rs
12
src/auth.rs
|
|
@ -24,15 +24,15 @@ use yescrypt::{PasswordHash, PasswordVerifier, Yescrypt};
|
|||
static JWT_SECRET: OnceLock<String> = OnceLock::new();
|
||||
|
||||
const ROTATION_DAYS: u64 = 7;
|
||||
const CREDENTIAL_DIR: &str = "/var/lib/server-dash-api/webauthn-credentials";
|
||||
pub(crate) const CREDENTIAL_DIR: &str = "/var/lib/server-dash-api/webauthn-credentials";
|
||||
const CHALLENGE_TTL: Duration = Duration::from_secs(300);
|
||||
const RP_ID: &str = "jackmechem.dev";
|
||||
const RP_ORIGIN: &str = "https://dashboard.jackmechem.dev";
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct StoredCredentials {
|
||||
user_id: Uuid,
|
||||
credentials: Vec<SecurityKey>,
|
||||
pub(crate) struct StoredCredentials {
|
||||
pub(crate) user_id: Uuid,
|
||||
pub(crate) credentials: Vec<SecurityKey>,
|
||||
}
|
||||
|
||||
pub struct AppState {
|
||||
|
|
@ -183,13 +183,13 @@ fn verify_shadow_hash(password: &str, hash: &str) -> bool {
|
|||
.is_ok()
|
||||
}
|
||||
|
||||
fn load_credentials(username: &str) -> Option<StoredCredentials> {
|
||||
pub(crate) fn load_credentials(username: &str) -> Option<StoredCredentials> {
|
||||
let path = PathBuf::from(CREDENTIAL_DIR).join(format!("{}.json", username));
|
||||
let data = std::fs::read_to_string(path).ok()?;
|
||||
serde_json::from_str(&data).ok()
|
||||
}
|
||||
|
||||
fn save_credentials(username: &str, creds: &StoredCredentials) -> Result<(), String> {
|
||||
pub(crate) fn save_credentials(username: &str, creds: &StoredCredentials) -> Result<(), String> {
|
||||
let dir = PathBuf::from(CREDENTIAL_DIR);
|
||||
std::fs::create_dir_all(&dir).map_err(|e| e.to_string())?;
|
||||
let path = dir.join(format!("{}.json", username));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue