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

@ -7,6 +7,8 @@ use openssl::pkey::{PKey, Public, Private};
use openssl::sign::{Signer, Verifier};
use openssl::hash::MessageDigest;
use crate::tools::epoch_now_u64;
pub const TICKET_LIFETIME: i64 = 3600*2; // 2 hours
@ -17,8 +19,7 @@ pub fn assemble_rsa_ticket(
secret_data: Option<&str>,
) -> Result<String, Error> {
let epoch = std::time::SystemTime::now().duration_since(
std::time::SystemTime::UNIX_EPOCH)?.as_secs();
let epoch = epoch_now_u64()?;
let timestamp = format!("{:08X}", epoch);
@ -101,8 +102,7 @@ pub fn verify_rsa_ticket(
}
let timestamp = i64::from_str_radix(parts.pop_back().unwrap(), 16)?;
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 - timestamp;
if age < min_age {