]> git.proxmox.com Git - proxmox-backup.git/blobdiff - src/api2/config/access/tfa.rs
update to proxmox-sys 0.2 crate
[proxmox-backup.git] / src / api2 / config / access / tfa.rs
index 6ac9b5de6ee1b845362188bd43f9818e44b2e934..f4720f41f3a64920f9f5131801f50d2ce72419d0 100644 (file)
@@ -2,11 +2,13 @@
 //! If we add more, it should be moved into a sub module.
 
 use anyhow::Error;
+use hex::FromHex;
 
-use crate::api2::types::PROXMOX_CONFIG_DIGEST_SCHEMA;
-use proxmox::api::{api, Permission, Router, RpcEnvironment, SubdirMap};
-use proxmox::api::schema::Updatable;
-use proxmox::list_subdirs_api_method;
+use proxmox_router::{Router, RpcEnvironment, Permission, SubdirMap};
+use proxmox_schema::api;
+use proxmox_router::list_subdirs_api_method;
+
+use pbs_api_types::PROXMOX_CONFIG_DIGEST_SCHEMA;
 
 use crate::config::tfa::{self, WebauthnConfig, WebauthnConfigUpdater};
 
@@ -41,7 +43,7 @@ pub fn get_webauthn_config(
         Some(c) => c,
         None => return Ok(None),
     };
-    rpcenv["digest"] = proxmox::tools::digest_to_hex(&digest).into();
+    rpcenv["digest"] = hex::encode(&digest).into();
     Ok(Some(config))
 }
 
@@ -71,12 +73,20 @@ pub fn update_webauthn_config(
 
     if let Some(wa) = &mut tfa.webauthn {
         if let Some(ref digest) = digest {
-            let digest = proxmox::tools::hex_to_digest(digest)?;
-            crate::tools::detect_modified_configuration_file(&digest, &wa.digest()?)?;
+            let digest = <[u8; 32]>::from_hex(digest)?;
+            crate::tools::detect_modified_configuration_file(
+                &digest,
+                &crate::config::tfa::webauthn_config_digest(&wa)?,
+            )?;
         }
-        wa.update_from::<&str>(webauthn, &[])?;
+        if let Some(ref rp) = webauthn.rp { wa.rp = rp.clone(); }
+        if let Some(ref origin) = webauthn.origin { wa.origin = origin.clone(); }
+        if let Some(ref id) = webauthn.id { wa.id = id.clone(); }
     } else {
-        tfa.webauthn = Some(WebauthnConfig::try_build_from(webauthn)?);
+        let rp = webauthn.rp.unwrap();
+        let origin = webauthn.origin.unwrap();
+        let id = webauthn.id.unwrap();
+        tfa.webauthn = Some(WebauthnConfig { rp, origin, id });
     }
 
     tfa::write(&tfa)?;