Skip to content

Commit

Permalink
default-connect-password option
Browse files Browse the repository at this point in the history
  • Loading branch information
rustdesk committed Jul 23, 2024
1 parent 22c6f5e commit 97f26f8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions libs/hbb_common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -2254,6 +2255,7 @@ pub mod keys {
OPTION_HIDE_PROXY_SETTINGS,
OPTION_HIDE_USERNAME_ON_CARD,
OPTION_HIDE_HELP_CARDS,
OPTION_DEFAULT_CONNECT_PASSWORD,
];
}

Expand Down
20 changes: 17 additions & 3 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand All @@ -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()) {
Expand Down

0 comments on commit 97f26f8

Please sign in to comment.