default-connect-password option

This commit is contained in:
rustdesk 2024-07-23 10:46:50 +08:00
parent 22c6f5e589
commit 97f26f880b
2 changed files with 19 additions and 3 deletions

View File

@ -2113,6 +2113,7 @@ pub mod keys {
pub const OPTION_HIDE_PROXY_SETTINGS: &str = "hide-proxy-settings";
pub const OPTION_HIDE_USERNAME_ON_CARD: &str = "hide-username-on-card";
pub const OPTION_HIDE_HELP_CARDS: &str = "hide-help-cards";
pub const OPTION_DEFAULT_CONNECT_PASSWORD: &str = "default-connect-password";
// flutter local options
pub const OPTION_FLUTTER_REMOTE_MENUBAR_STATE: &str = "remoteMenubarState";
@ -2254,6 +2255,7 @@ pub mod keys {
OPTION_HIDE_PROXY_SETTINGS,
OPTION_HIDE_USERNAME_ON_CARD,
OPTION_HIDE_HELP_CARDS,
OPTION_DEFAULT_CONNECT_PASSWORD,
];
}

View File

@ -543,7 +543,7 @@ impl Client {
conn: &mut Stream,
) -> ResultType<Option<Vec<u8>>> {
let rs_pk = get_rs_pk(if key.is_empty() {
hbb_common::config::RS_PUB_KEY
config::RS_PUB_KEY
} else {
key
});
@ -2625,7 +2625,7 @@ struct LoginErrorMsgBox {
lazy_static::lazy_static! {
static ref LOGIN_ERROR_MAP: Arc<HashMap<&'static str, LoginErrorMsgBox>> = {
use hbb_common::config::LINK_HEADLESS_LINUX_SUPPORT;
use config::LINK_HEADLESS_LINUX_SUPPORT;
let map = HashMap::from([(LOGIN_SCREEN_WAYLAND, LoginErrorMsgBox{
msgtype: "error",
title: "Login Error",
@ -2791,6 +2791,20 @@ pub async fn handle_hash(
if password.is_empty() {
try_get_password_from_personal_ab(lc.clone(), &mut password);
}
if password.is_empty() {
let p =
crate::ui_interface::get_buildin_option(config::keys::OPTION_DEFAULT_CONNECT_PASSWORD);
if !p.is_empty() {
let mut hasher = Sha256::new();
hasher.update(p.clone());
hasher.update(&hash.salt);
let res = hasher.finalize();
password = res[..].into();
lc.write().unwrap().password_source = PasswordSource::SharedAb(p); // reuse SharedAb here
}
}
lc.write().unwrap().password = password.clone();
let password = if password.is_empty() {
// login without password, the remote side can click accept
@ -2813,7 +2827,7 @@ pub async fn handle_hash(
#[inline]
fn try_get_password_from_personal_ab(lc: Arc<RwLock<LoginConfigHandler>>, password: &mut Vec<u8>) {
let access_token = LocalConfig::get_option("access_token");
let ab = hbb_common::config::Ab::load();
let ab = config::Ab::load();
if !access_token.is_empty() && access_token == ab.access_token {
let id = lc.read().unwrap().id.clone();
if let Some(ab) = ab.ab_entries.iter().find(|a| a.personal()) {