Skip to content

Commit f08c7af

Browse files
benthecarmanclaude
andcommitted
Restrict TLS private key file permissions
The generated TLS private key was written with default permissions (typically 0644), making it world-readable. Set permissions to 0400 (owner-read-only) after writing, matching the existing API key file handling. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent fb4338f commit f08c7af

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

ldk-server/src/util/tls.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use std::fs;
1111
use std::net::IpAddr;
12+
use std::os::unix::fs::PermissionsExt;
1213

1314
use base64::Engine;
1415
use ring::rand::SystemRandom;
@@ -134,6 +135,8 @@ fn generate_self_signed_cert(
134135

135136
fs::write(key_path, &key_pem)
136137
.map_err(|e| format!("Failed to write TLS key to '{key_path}': {e}"))?;
138+
fs::set_permissions(key_path, fs::Permissions::from_mode(0o400))
139+
.map_err(|e| format!("Failed to set TLS key permissions for '{key_path}': {e}"))?;
137140
fs::write(cert_path, &cert_pem)
138141
.map_err(|e| format!("Failed to write TLS certificate to '{cert_path}': {e}"))?;
139142

0 commit comments

Comments
 (0)