mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-03-22 12:41:14 +03:00
trust this device to skip 2fa (#9012)
* trust this device to skip 2fa Signed-off-by: 21pages <sunboeasy@gmail.com> * Update connection.rs --------- Signed-off-by: 21pages <sunboeasy@gmail.com> Co-authored-by: RustDesk <71636191+rustdesk@users.noreply.github.com>
This commit is contained in:
@@ -4,7 +4,7 @@ use hbb_common::{
|
||||
config::Config,
|
||||
get_time,
|
||||
password_security::{decrypt_vec_or_original, encrypt_vec_or_original},
|
||||
tokio, ResultType,
|
||||
ResultType,
|
||||
};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::sync::Mutex;
|
||||
@@ -165,9 +165,7 @@ pub async fn send_2fa_code_to_telegram(text: &str, bot: TelegramBot) -> ResultTy
|
||||
pub fn get_chatid_telegram(bot_token: &str) -> ResultType<Option<String>> {
|
||||
let url = format!("https://api.telegram.org/bot{}/getUpdates", bot_token);
|
||||
// because caller is in tokio runtime, so we must call post_request_sync in new thread.
|
||||
let handle = std::thread::spawn(move || {
|
||||
crate::post_request_sync(url, "".to_owned(), "")
|
||||
});
|
||||
let handle = std::thread::spawn(move || crate::post_request_sync(url, "".to_owned(), ""));
|
||||
let resp = handle.join().map_err(|_| anyhow!("Thread panicked"))??;
|
||||
let value = serde_json::from_str::<serde_json::Value>(&resp).map_err(|e| anyhow!(e))?;
|
||||
|
||||
|
||||
@@ -1329,6 +1329,7 @@ pub struct LoginConfigHandler {
|
||||
pub peer_info: Option<PeerInfo>,
|
||||
password_source: PasswordSource, // where the sent password comes from
|
||||
shared_password: Option<String>, // Store the shared password
|
||||
pub enable_trusted_devices: bool,
|
||||
}
|
||||
|
||||
impl Deref for LoginConfigHandler {
|
||||
@@ -2156,6 +2157,11 @@ impl LoginConfigHandler {
|
||||
let my_platform = whoami::platform().to_string();
|
||||
#[cfg(target_os = "android")]
|
||||
let my_platform = "Android".into();
|
||||
let hwid = if self.get_option("trust-this-device") == "Y" {
|
||||
crate::get_hwid()
|
||||
} else {
|
||||
Bytes::new()
|
||||
};
|
||||
let mut lr = LoginRequest {
|
||||
username: pure_id,
|
||||
password: password.into(),
|
||||
@@ -2171,6 +2177,7 @@ impl LoginConfigHandler {
|
||||
..Default::default()
|
||||
})
|
||||
.into(),
|
||||
hwid,
|
||||
..Default::default()
|
||||
};
|
||||
match self.conn_type {
|
||||
@@ -2827,6 +2834,12 @@ pub fn handle_login_error(
|
||||
interface.msgbox("re-input-password", err, "Do you want to enter again?", "");
|
||||
true
|
||||
} else if err == LOGIN_MSG_2FA_WRONG || err == REQUIRE_2FA {
|
||||
let enabled = lc.read().unwrap().get_option("trust-this-device") == "Y";
|
||||
if enabled {
|
||||
lc.write()
|
||||
.unwrap()
|
||||
.set_option("trust-this-device".to_string(), "".to_string());
|
||||
}
|
||||
interface.msgbox("input-2fa", err, "", "");
|
||||
true
|
||||
} else if LOGIN_ERROR_MAP.contains_key(err) {
|
||||
|
||||
@@ -1135,6 +1135,10 @@ impl<T: InvokeUiSession> Remote<T> {
|
||||
}
|
||||
Some(message::Union::LoginResponse(lr)) => match lr.union {
|
||||
Some(login_response::Union::Error(err)) => {
|
||||
if err == client::REQUIRE_2FA {
|
||||
self.handler.lc.write().unwrap().enable_trusted_devices =
|
||||
lr.enable_trusted_devices;
|
||||
}
|
||||
if !self.handler.handle_login_error(&err) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1494,6 +1494,15 @@ pub fn is_empty_uni_link(arg: &str) -> bool {
|
||||
arg[prefix.len()..].chars().all(|c| c == '/')
|
||||
}
|
||||
|
||||
pub fn get_hwid() -> Bytes {
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
let uuid = hbb_common::get_uuid();
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(&uuid);
|
||||
Bytes::from(hasher.finalize().to_vec())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@@ -208,12 +208,21 @@ pub fn session_login(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn session_send2fa(session_id: SessionID, code: String) {
|
||||
pub fn session_send2fa(session_id: SessionID, code: String, trust_this_device: bool) {
|
||||
if let Some(session) = sessions::get_session_by_session_id(&session_id) {
|
||||
session.send2fa(code);
|
||||
session.send2fa(code, trust_this_device);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn session_get_enable_trusted_devices(session_id: SessionID) -> SyncReturn<bool> {
|
||||
let v = if let Some(session) = sessions::get_session_by_session_id(&session_id) {
|
||||
session.get_enable_trusted_devices()
|
||||
} else {
|
||||
false
|
||||
};
|
||||
SyncReturn(v)
|
||||
}
|
||||
|
||||
pub fn session_close(session_id: SessionID) {
|
||||
if let Some(session) = sessions::remove_session_by_session_id(&session_id) {
|
||||
session.close_event_stream(session_id);
|
||||
@@ -2240,6 +2249,18 @@ pub fn main_check_hwcodec() {
|
||||
check_hwcodec()
|
||||
}
|
||||
|
||||
pub fn main_get_trusted_devices() -> String {
|
||||
get_trusted_devices()
|
||||
}
|
||||
|
||||
pub fn main_remove_trusted_devices(json: String) {
|
||||
remove_trusted_devices(&json)
|
||||
}
|
||||
|
||||
pub fn main_clear_trusted_devices() {
|
||||
clear_trusted_devices()
|
||||
}
|
||||
|
||||
pub fn session_request_new_display_init_msgs(session_id: SessionID, display: usize) {
|
||||
if let Some(session) = sessions::get_session_by_session_id(&session_id) {
|
||||
session.request_init_msgs(display);
|
||||
|
||||
49
src/ipc.rs
49
src/ipc.rs
@@ -25,7 +25,9 @@ use hbb_common::{
|
||||
config::{self, Config, Config2},
|
||||
futures::StreamExt as _,
|
||||
futures_util::sink::SinkExt,
|
||||
log, password_security as password, timeout,
|
||||
log, password_security as password,
|
||||
sodiumoxide::base64,
|
||||
timeout,
|
||||
tokio::{
|
||||
self,
|
||||
io::{AsyncRead, AsyncWrite},
|
||||
@@ -260,6 +262,8 @@ pub enum Data {
|
||||
// Although the key is not neccessary, it is used to avoid hardcoding the key.
|
||||
WaylandScreencastRestoreToken((String, String)),
|
||||
HwCodecConfig(Option<String>),
|
||||
RemoveTrustedDevices(Vec<Bytes>),
|
||||
ClearTrustedDevices,
|
||||
}
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
@@ -486,6 +490,8 @@ async fn handle(data: Data, stream: &mut Connection) {
|
||||
value = crate::audio_service::get_voice_call_input_device();
|
||||
} else if name == "unlock-pin" {
|
||||
value = Some(Config::get_unlock_pin());
|
||||
} else if name == "trusted-devices" {
|
||||
value = Some(Config::get_trusted_devices_json());
|
||||
} else {
|
||||
value = None;
|
||||
}
|
||||
@@ -638,6 +644,12 @@ async fn handle(data: Data, stream: &mut Connection) {
|
||||
);
|
||||
}
|
||||
}
|
||||
Data::RemoveTrustedDevices(v) => {
|
||||
Config::remove_trusted_devices(&v);
|
||||
}
|
||||
Data::ClearTrustedDevices => {
|
||||
Config::clear_trusted_devices();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@@ -866,6 +878,17 @@ pub async fn set_config_async(name: &str, value: String) -> ResultType<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
pub async fn set_data(data: &Data) -> ResultType<()> {
|
||||
set_data_async(data).await
|
||||
}
|
||||
|
||||
pub async fn set_data_async(data: &Data) -> ResultType<()> {
|
||||
let mut c = connect(1000, "").await?;
|
||||
c.send(data).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
pub async fn set_config(name: &str, value: String) -> ResultType<()> {
|
||||
set_config_async(name, value).await
|
||||
@@ -926,6 +949,30 @@ pub fn get_unlock_pin() -> String {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "flutter")]
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
pub fn get_trusted_devices() -> String {
|
||||
if let Ok(Some(v)) = get_config("trusted-devices") {
|
||||
v
|
||||
} else {
|
||||
Config::get_trusted_devices_json()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "flutter")]
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
pub fn remove_trusted_devices(hwids: Vec<Bytes>) {
|
||||
Config::remove_trusted_devices(&hwids);
|
||||
allow_err!(set_data(&Data::RemoveTrustedDevices(hwids)));
|
||||
}
|
||||
|
||||
#[cfg(feature = "flutter")]
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
pub fn clear_trusted_devices() {
|
||||
Config::clear_trusted_devices();
|
||||
allow_err!(set_data(&Data::ClearTrustedDevices));
|
||||
}
|
||||
|
||||
pub fn get_id() -> String {
|
||||
if let Ok(Some(v)) = get_config("id") {
|
||||
// update salt also, so that next time reinstallation not causing first-time auto-login failure
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", "الوثوق بهذا الجهاز"),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", "Даверыць гэтую прыладу"),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", "Доверете се на това устройство"),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", "Confia en aquest dispositiu"),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", "不少于{}个字符"),
|
||||
("Wrong PIN", "PIN 码错误"),
|
||||
("Set PIN", "设置 PIN 码"),
|
||||
("Enable trusted devices", "启用信任设备"),
|
||||
("Manage trusted devices", "管理信任设备"),
|
||||
("Trust this device", "信任此设备"),
|
||||
("Platform", "平台"),
|
||||
("Days remaining", "剩余天数"),
|
||||
("enable-trusted-devices-tip", "允许受信任的设备跳过 2FA 验证"),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", "Důvěřovat tomuto zařízení"),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", "Husk denne enhed"),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", "Erfordert mindestens {} Zeichen"),
|
||||
("Wrong PIN", "Falsche PIN"),
|
||||
("Set PIN", "PIN festlegen"),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", "Diesem Gerät vertrauen"),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", "Εμπιστεύομαι αυτή την συσκευή"),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -232,6 +232,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("cancel-2fa-confirm-tip", "Are you sure you want to cancel 2FA?"),
|
||||
("cancel-bot-confirm-tip", "Are you sure you want to cancel Telegram bot?"),
|
||||
("About RustDesk", ""),
|
||||
("network_error_tip", "Please check your network connection, then click retry.")
|
||||
("network_error_tip", "Please check your network connection, then click retry."),
|
||||
("enable-trusted-devices-tip", "Skip 2FA verification on trusted devices"),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", ""),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", "Confiar en este dispositivo"),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", ""),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", "Gailu honetaz fidatu"),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", "حداقل به {} کاراکترها نیاز دارد"),
|
||||
("Wrong PIN", "پین اشتباه است"),
|
||||
("Set PIN", "پین را تنظیم کنید"),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", "به این دستگاه اعتماد کنید"),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", "Faire confiance à cet appareil"),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", ""),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", "Vjeruj ovom uređaju"),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", ""),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", "Izinkan perangkat ini"),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", "Richiede almeno {} caratteri"),
|
||||
("Wrong PIN", "PIN errato"),
|
||||
("Set PIN", "Imposta PIN"),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", "Registra questo dispositivo come attendibile"),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", "このデバイスを信頼する"),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", "이 장치 신뢰"),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", ""),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", "Pasitikėk šiuo įrenginiu"),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", "Uzticēties šai ierīcei"),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", "Husk denne enheten"),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", "Vereist minstens {} tekens"),
|
||||
("Wrong PIN", "Verkeerde PIN-code"),
|
||||
("Set PIN", "PIN-code instellen"),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", "Vertrouw dit apparaat"),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", "Dodaj to urządzenie do zaufanych"),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", ""),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", "PIN Errado"),
|
||||
("Set PIN", "Definir PIN"),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", "Confiar neste dispositivo"),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", "Acest dispozitiv este de încredere"),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", "Требуется не менее {} символов"),
|
||||
("Wrong PIN", "Неправильный PIN-код"),
|
||||
("Set PIN", "Установить PIN-код"),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", "Доверенное устройство"),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", "Dôverovať tomuto zariadeniu"),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", ""),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", ""),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", ""),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", "Lita på denna enhet"),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", ""),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", "เชื่อถืออุปกรณ์นี้"),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", ""),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", "信任此裝置"),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", "Потрібно щонайменше {} символів"),
|
||||
("Wrong PIN", "Неправильний PIN-код"),
|
||||
("Set PIN", "Встановити PIN-код"),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", "Довірений пристрій"),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -636,5 +636,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Requires at least {} characters", ""),
|
||||
("Wrong PIN", ""),
|
||||
("Set PIN", ""),
|
||||
("Enable trusted devices", ""),
|
||||
("Manage trusted devices", ""),
|
||||
("Trust this device", "Tin thiết bị này"),
|
||||
("Platform", ""),
|
||||
("Days remaining", ""),
|
||||
("enable-trusted-devices-tip", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ use hbb_common::platform::linux::run_cmds;
|
||||
#[cfg(target_os = "android")]
|
||||
use hbb_common::protobuf::EnumOrUnknown;
|
||||
use hbb_common::{
|
||||
config::{self, Config},
|
||||
config::{self, Config, TrustedDevice},
|
||||
fs::{self, can_enable_overwrite_detection},
|
||||
futures::{SinkExt, StreamExt},
|
||||
get_time, get_version_number,
|
||||
@@ -1482,6 +1482,9 @@ impl Connection {
|
||||
let mut msg_out = Message::new();
|
||||
let mut res = LoginResponse::new();
|
||||
res.set_error(err.to_string());
|
||||
if err.to_string() == crate::client::REQUIRE_2FA {
|
||||
res.enable_trusted_devices = Self::enable_trusted_devices();
|
||||
}
|
||||
msg_out.set_login_response(res);
|
||||
self.send(msg_out).await;
|
||||
}
|
||||
@@ -1623,11 +1626,32 @@ impl Connection {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn enable_trusted_devices() -> bool {
|
||||
config::option2bool(
|
||||
config::keys::OPTION_ENABLE_TRUSTED_DEVICES,
|
||||
&Config::get_option(config::keys::OPTION_ENABLE_TRUSTED_DEVICES),
|
||||
)
|
||||
}
|
||||
|
||||
async fn handle_login_request_without_validation(&mut self, lr: &LoginRequest) {
|
||||
self.lr = lr.clone();
|
||||
if let Some(o) = lr.option.as_ref() {
|
||||
self.options_in_login = Some(o.clone());
|
||||
}
|
||||
if self.require_2fa.is_some() && !lr.hwid.is_empty() && Self::enable_trusted_devices() {
|
||||
let devices = Config::get_trusted_devices();
|
||||
if let Some(device) = devices.iter().find(|d| d.hwid == lr.hwid) {
|
||||
if !device.outdate()
|
||||
&& device.id == lr.my_id
|
||||
&& device.name == lr.my_name
|
||||
&& device.platform == lr.my_platform
|
||||
{
|
||||
log::info!("2FA bypassed by trusted devices");
|
||||
self.require_2fa = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
self.video_ack_required = lr.video_ack_required;
|
||||
}
|
||||
|
||||
@@ -1841,6 +1865,15 @@ impl Connection {
|
||||
},
|
||||
);
|
||||
}
|
||||
if !tfa.hwid.is_empty() && Self::enable_trusted_devices() {
|
||||
Config::add_trusted_device(TrustedDevice {
|
||||
hwid: tfa.hwid,
|
||||
time: hbb_common::get_time(),
|
||||
id: self.lr.my_id.clone(),
|
||||
name: self.lr.my_name.clone(),
|
||||
platform: self.lr.my_platform.clone(),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
self.update_failure(failure, false, 1);
|
||||
self.send_login_error(crate::client::LOGIN_MSG_2FA_WRONG)
|
||||
|
||||
@@ -268,7 +268,7 @@ function msgbox(type, title, content, link="", callback=null, height=180, width=
|
||||
view.close();
|
||||
return;
|
||||
}
|
||||
handler.send2fa(res.code);
|
||||
handler.send2fa(res.code, res.trust_this_device || false);
|
||||
msgbox("connecting", "Connecting...", "Logging in...");
|
||||
};
|
||||
} else if (type == "session-login" || type == "session-re-login") {
|
||||
|
||||
@@ -66,9 +66,11 @@ class MsgboxComponent: Reactor.Component {
|
||||
}
|
||||
|
||||
function get2faContent() {
|
||||
var enable_trusted_devices = handler.get_enable_trusted_devices();
|
||||
return <div .form>
|
||||
<div>{translate('enter-2fa-title')}</div>
|
||||
<div .code><input name='code' type='text' .outline-focus /></div>
|
||||
{enable_trusted_devices ? <div><button|checkbox(trust_this_device) {ts}>{translate('Trust this device')}</button></div> : ""}
|
||||
</div>;
|
||||
}
|
||||
|
||||
|
||||
@@ -433,7 +433,8 @@ impl sciter::EventHandler for SciterSession {
|
||||
fn is_port_forward();
|
||||
fn is_rdp();
|
||||
fn login(String, String, String, bool);
|
||||
fn send2fa(String);
|
||||
fn send2fa(String, bool);
|
||||
fn get_enable_trusted_devices();
|
||||
fn new_rdp();
|
||||
fn send_mouse(i32, i32, i32, bool, bool, bool, bool);
|
||||
fn enter(String);
|
||||
|
||||
@@ -1471,3 +1471,28 @@ pub fn set_unlock_pin(pin: String) -> String {
|
||||
Err(err) => err.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "flutter")]
|
||||
pub fn get_trusted_devices() -> String {
|
||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||
return Config::get_trusted_devices_json();
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
return ipc::get_trusted_devices();
|
||||
}
|
||||
|
||||
#[cfg(feature = "flutter")]
|
||||
pub fn remove_trusted_devices(json: &str) {
|
||||
let hwids = serde_json::from_str::<Vec<Bytes>>(json).unwrap_or_default();
|
||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||
Config::remove_trusted_devices(&hwids);
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
ipc::remove_trusted_devices(hwids);
|
||||
}
|
||||
|
||||
#[cfg(feature = "flutter")]
|
||||
pub fn clear_trusted_devices() {
|
||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||
Config::clear_trusted_devices();
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
ipc::clear_trusted_devices();
|
||||
}
|
||||
|
||||
@@ -1156,15 +1156,29 @@ impl<T: InvokeUiSession> Session<T> {
|
||||
self.send(Data::Login((os_username, os_password, password, remember)));
|
||||
}
|
||||
|
||||
pub fn send2fa(&self, code: String) {
|
||||
pub fn send2fa(&self, code: String, trust_this_device: bool) {
|
||||
let mut msg_out = Message::new();
|
||||
let hwid = if trust_this_device {
|
||||
crate::get_hwid()
|
||||
} else {
|
||||
Bytes::new()
|
||||
};
|
||||
self.lc.write().unwrap().set_option(
|
||||
"trust-this-device".to_string(),
|
||||
if trust_this_device { "Y" } else { "" }.to_string(),
|
||||
);
|
||||
msg_out.set_auth_2fa(Auth2FA {
|
||||
code,
|
||||
hwid,
|
||||
..Default::default()
|
||||
});
|
||||
self.send(Data::Message(msg_out));
|
||||
}
|
||||
|
||||
pub fn get_enable_trusted_devices(&self) -> bool {
|
||||
self.lc.read().unwrap().enable_trusted_devices
|
||||
}
|
||||
|
||||
pub fn new_rdp(&self) {
|
||||
self.send(Data::NewRDP);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user