mirror of
https://github.com/rustdesk/rustdesk-server.git
synced 2026-11-28 08:44:34 +00:00
fix: key file perm (#705)
* fix: key file perm Signed-off-by: fufesou <linlong1266@gmail.com> * fix: enforce secure private key permissions on Unix Create new keys with mode 0600 and verify permissions before writing. Tighten existing keys to 0600 and propagate permission failures. Preserve dangling symlinks and clean up failed key creation. Signed-off-by: fufesou <linlong1266@gmail.com> * fix: preserve read-only keys and prevent public key clobbering Accept existing 0400 keys without changing their permissions. Write the public key only after private key creation and writing succeed. Signed-off-by: fufesou <linlong1266@gmail.com> * fix: generate missing public keys and reject mismatched key pairs Signed-off-by: fufesou <linlong1266@gmail.com> * fix: publish public keys atomically without overwriting existing files Signed-off-by: fufesou <linlong1266@gmail.com> * fix: key file perms, comments Signed-off-by: fufesou <linlong1266@gmail.com> * fix: reject key conflicts and clean up failed private key writes Reuse symlink resolution and simplify key loading and regression tests. Signed-off-by: fufesou <linlong1266@gmail.com> * fix: key file perm, simple refactor Signed-off-by: fufesou <linlong1266@gmail.com> --------- Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
1 parent
5e37f45dfe
commit
873230e35a
5 files changed
+382
-50
No files matched your search
+4
-4
@@ -51,7 +51,7 @@ pub async fn start_with_bind(
|
||||
port: &str,
|
||||
key: &str,
|
||||
) -> ResultType<()> {
|
||||
let key = get_server_sk(key);
|
||||
let key = get_server_sk(key)?;
|
||||
if let Ok(mut file) = std::fs::File::open(BLACKLIST_FILE) {
|
||||
let mut contents = String::new();
|
||||
if file.read_to_string(&mut contents).is_ok() {
|
||||
@@ -601,7 +601,7 @@ async fn relay(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_server_sk(key: &str) -> String {
|
||||
fn get_server_sk(key: &str) -> ResultType<String> {
|
||||
let mut key = key.to_owned();
|
||||
if let Ok(sk) = base64::decode(&key) {
|
||||
if sk.len() == sign::SECRETKEYBYTES {
|
||||
@@ -611,7 +611,7 @@ fn get_server_sk(key: &str) -> String {
|
||||
}
|
||||
|
||||
if key == "-" || key == "_" {
|
||||
let (pk, _) = crate::common::gen_sk(300);
|
||||
let (pk, _) = crate::common::gen_sk(300)?;
|
||||
key = pk;
|
||||
}
|
||||
|
||||
@@ -619,7 +619,7 @@ fn get_server_sk(key: &str) -> String {
|
||||
log::info!("Key: {}", key);
|
||||
}
|
||||
|
||||
key
|
||||
Ok(key)
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
|
||||
Reference in new issue
Block a user