Merge pull request #134 from flokli/keyfile-mode

Set mode when creating key file
This commit is contained in:
Lee Smet authored and GitHub committed 2024-02-27 23:19:57 +01:00
commit 9feff0806d
1 file changed
+17 -2
+17 -2
View File
@@ -309,8 +309,23 @@ async fn load_key_file(path: &Path) -> Result<crypto::SecretKey, io::Error> {
}
async fn save_key_file(key: &crypto::SecretKey, path: &Path) -> io::Result<()> {
let mut file = File::create(path).await?;
file.write_all(key.as_bytes()).await?;
#[cfg(target_family = "unix")]
{
use tokio::fs::OpenOptions;
let mut file = OpenOptions::new()
.create(true)
.write(true)
.mode(0o600) // rw by the owner, not readable by group or others
.open(path)
.await?;
file.write_all(key.as_bytes()).await?;
}
#[cfg(not(target_family = "unix"))]
{
let mut file = File::create(path).await?;
file.write_all(key.as_bytes()).await?;
}
Ok(())
}