Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set mode when creating key file #134

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Loading