mirror of
https://github.com/rustdesk/hbb_common.git
synced 2026-02-16 02:20:43 +00:00
fix: improve machine_uid handling and add pk decryption fallback
- Cache machine_uid in get_uuid with retry logic for macOS - Fallback to pk decryption when machine_uid decryption fails - Add is_encrypted check to prevent duplicate encryption - Add get_existing_key_pair to get key pair without generating new one Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
@@ -588,6 +588,7 @@ impl Config {
|
||||
store = true;
|
||||
}
|
||||
if !id_valid {
|
||||
log::warn!("ID is invalid, generating new one");
|
||||
for _ in 0..3 {
|
||||
if let Some(id) = Config::gen_id() {
|
||||
config.id = id;
|
||||
@@ -918,6 +919,7 @@ impl Config {
|
||||
id = (id << 8) | (*x as u32);
|
||||
}
|
||||
id &= 0x1FFFFFFF;
|
||||
log::info!("Generated id {}", id);
|
||||
Some(id.to_string())
|
||||
} else {
|
||||
None
|
||||
@@ -996,6 +998,27 @@ impl Config {
|
||||
KEY_PAIR.lock().unwrap().clone().map(|k| k.1)
|
||||
}
|
||||
|
||||
/// Get existing key pair without generating a new one.
|
||||
/// Returns None if no key pair exists in cache or config file.
|
||||
pub fn get_existing_key_pair() -> Option<KeyPair> {
|
||||
let mut lock = KEY_PAIR.lock().unwrap();
|
||||
if let Some(p) = lock.as_ref() {
|
||||
return Some(p.clone());
|
||||
}
|
||||
|
||||
// IMPORTANT: this path is called while holding KEY_PAIR lock.
|
||||
// Config::load_ must remain a raw conf load/deserialize path and must never
|
||||
// call decrypt_* / symmetric_crypt (directly or indirectly), otherwise this
|
||||
// can re-enter key loading and deadlock.
|
||||
let config = Config::load_::<Config>("");
|
||||
if !config.key_pair.0.is_empty() {
|
||||
*lock = Some(config.key_pair.clone());
|
||||
Some(config.key_pair)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn no_register_device() -> bool {
|
||||
BUILTIN_SETTINGS
|
||||
.read()
|
||||
|
||||
Reference in New Issue
Block a user