refactor time functions to tools

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Dominik Csapak
2020-06-10 12:02:56 +02:00
committed by Wolfgang Bumiller
parent 3d68536fc2
commit e693818afc
7 changed files with 39 additions and 33 deletions

View File

@ -10,6 +10,8 @@ use std::path::PathBuf;
use proxmox::tools::fs::{file_get_contents, replace_file, CreateOptions};
use proxmox::try_block;
use crate::tools::epoch_now_u64;
fn compute_csrf_secret_digest(
timestamp: i64,
secret: &[u8],
@ -29,8 +31,7 @@ pub fn assemble_csrf_prevention_token(
username: &str,
) -> String {
let epoch = std::time::SystemTime::now().duration_since(
std::time::SystemTime::UNIX_EPOCH).unwrap().as_secs() as i64;
let epoch = epoch_now_u64().unwrap() as i64;
let digest = compute_csrf_secret_digest(epoch, secret, username);
@ -67,8 +68,7 @@ pub fn verify_csrf_prevention_token(
bail!("invalid signature.");
}
let now = std::time::SystemTime::now().duration_since(
std::time::SystemTime::UNIX_EPOCH)?.as_secs() as i64;
let now = epoch_now_u64()? as i64;
let age = now - ttime;
if age < min_age {