mirror of
https://github.com/FluxaMedia/fluxa-desktop.git
synced 2026-07-26 20:02:09 +00:00
Create storage key file with 0600 from the start
fs::write followed by set_permissions left a window where the key was world-readable.
This commit is contained in:
parent
3f8368dbae
commit
4411d78580
1 changed files with 7 additions and 3 deletions
|
|
@ -39,12 +39,16 @@ fn load_or_create_key(dir: &Path) -> Result<Key<Aes256Gcm>, String> {
|
|||
}
|
||||
fs::create_dir_all(dir).map_err(|e| e.to_string())?;
|
||||
let key = Aes256Gcm::generate_key(&mut OsRng);
|
||||
fs::write(&path, key.as_slice()).map_err(|e| e.to_string())?;
|
||||
let mut options = fs::OpenOptions::new();
|
||||
options.write(true).create(true).truncate(true);
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
let _ = fs::set_permissions(&path, fs::Permissions::from_mode(0o600));
|
||||
use std::os::unix::fs::OpenOptionsExt;
|
||||
options.mode(0o600);
|
||||
}
|
||||
use std::io::Write;
|
||||
let mut file = options.open(&path).map_err(|e| e.to_string())?;
|
||||
file.write_all(key.as_slice()).map_err(|e| e.to_string())?;
|
||||
Ok(key)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue