11use bincode;
22use serde:: { Deserialize , Serialize } ;
33use tauri:: Manager ;
4+ use zeroize:: Zeroize ;
45use std:: collections:: HashMap ;
56use std:: fs:: { self , File } ;
7+ use std:: os:: unix:: fs:: PermissionsExt ;
68use std:: io:: { Read , Write } ;
79use std:: path:: PathBuf ;
810use totp_rs:: { Algorithm , Secret , TOTP } ;
@@ -241,6 +243,11 @@ impl Storage {
241243 }
242244 let path = self . storage_path ( app) ;
243245 let mut file = File :: open ( path) . map_err ( |_| ( ) ) ?;
246+
247+ // @TODO: Set permissions for windows and macOS too
248+ self . set_permissions ( & file) ;
249+
250+
244251 let mut buf = Vec :: new ( ) ;
245252 file. read_to_end ( & mut buf) . map_err ( |_| ( ) ) ?;
246253
@@ -348,6 +355,13 @@ impl Storage {
348355 self . signing_key = key;
349356 self . salt = Some ( salt) ;
350357 }
358+
359+ fn set_permissions ( & self , file : & File ) {
360+ let metadata = file. metadata ( ) . unwrap ( ) ;
361+ let mut permissions = metadata. permissions ( ) ;
362+ permissions. set_mode ( 0o644 ) ; // Read/write for owner, read for group and others
363+ file. set_permissions ( permissions) . unwrap ( ) ;
364+ }
351365}
352366
353367impl ServicesTokens for Storage {
@@ -363,6 +377,14 @@ impl ServicesTokens for Storage {
363377 }
364378}
365379
380+ impl Drop for Storage {
381+ fn drop ( & mut self ) {
382+ self . signing_key . zeroize ( ) ;
383+ self . salt . zeroize ( ) ;
384+ self . key_access_pass . zeroize ( ) ;
385+ }
386+ }
387+
366388#[ cfg( test) ]
367389mod tests {
368390 use super :: * ;
0 commit comments