]> git.proxmox.com Git - proxmox-backup.git/blobdiff - src/auth_helpers.rs
sync: verify size and checksum of pulled archives
[proxmox-backup.git] / src / auth_helpers.rs
index 5382da27a7105447db4156d4f76fc20a5493d3ed..a121235547553f8e80ed51381b4a8f6c52f3b12e 100644 (file)
@@ -1,4 +1,4 @@
-use failure::*;
+use anyhow::{bail, format_err, Error};
 use lazy_static::lazy_static;
 
 use openssl::rsa::{Rsa};
@@ -7,10 +7,10 @@ use openssl::sha;
 
 use std::path::PathBuf;
 
-use proxmox::tools::{
-    try_block,
-    fs::{file_get_contents, replace_file, CreateOptions},
-};
+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,
@@ -31,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);
 
@@ -69,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 {