Skip to content

Commit

Permalink
no password required for file transfer action in remote control menu (r…
Browse files Browse the repository at this point in the history
…ustdesk#9731)

Signed-off-by: 21pages <[email protected]>
  • Loading branch information
21pages authored Oct 24, 2024
1 parent 7a3e1fe commit 445e9ac
Show file tree
Hide file tree
Showing 16 changed files with 222 additions and 52 deletions.
5 changes: 5 additions & 0 deletions flutter/lib/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2304,16 +2304,19 @@ connectMainDesktop(String id,
required bool isRDP,
bool? forceRelay,
String? password,
String? connToken,
bool? isSharedPassword}) async {
if (isFileTransfer) {
await rustDeskWinManager.newFileTransfer(id,
password: password,
isSharedPassword: isSharedPassword,
connToken: connToken,
forceRelay: forceRelay);
} else if (isTcpTunneling || isRDP) {
await rustDeskWinManager.newPortForward(id, isRDP,
password: password,
isSharedPassword: isSharedPassword,
connToken: connToken,
forceRelay: forceRelay);
} else {
await rustDeskWinManager.newRemoteDesktop(id,
Expand All @@ -2333,6 +2336,7 @@ connect(BuildContext context, String id,
bool isRDP = false,
bool forceRelay = false,
String? password,
String? connToken,
bool? isSharedPassword}) async {
if (id == '') return;
if (!isDesktop || desktopType == DesktopType.main) {
Expand Down Expand Up @@ -2374,6 +2378,7 @@ connect(BuildContext context, String id,
'password': password,
'isSharedPassword': isSharedPassword,
'forceRelay': forceRelay,
'connToken': connToken,
});
}
} else {
Expand Down
16 changes: 14 additions & 2 deletions flutter/lib/common/widgets/toolbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,32 @@ List<TTextMenu> toolbarControls(BuildContext context, String id, FFI ffi) {
child: Text(translate('Reset canvas')),
onPressed: () => ffi.cursorModel.reset()));
}

connectWithToken(
{required bool isFileTransfer, required bool isTcpTunneling}) {
final connToken = bind.sessionGetConnToken(sessionId: ffi.sessionId);
connect(context, id,
isFileTransfer: isFileTransfer,
isTcpTunneling: isTcpTunneling,
connToken: connToken);
}

// transferFile
if (isDesktop) {
v.add(
TTextMenu(
child: Text(translate('Transfer file')),
onPressed: () => connect(context, id, isFileTransfer: true)),
onPressed: () =>
connectWithToken(isFileTransfer: true, isTcpTunneling: false)),
);
}
// tcpTunneling
if (isDesktop) {
v.add(
TTextMenu(
child: Text(translate('TCP tunneling')),
onPressed: () => connect(context, id, isTcpTunneling: true)),
onPressed: () =>
connectWithToken(isFileTransfer: false, isTcpTunneling: true)),
);
}
// note
Expand Down
1 change: 1 addition & 0 deletions flutter/lib/desktop/pages/desktop_home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ class _DesktopHomePageState extends State<DesktopHomePage>
isRDP: call.arguments['isRDP'],
password: call.arguments['password'],
forceRelay: call.arguments['forceRelay'],
connToken: call.arguments['connToken'],
);
} else if (call.method == kWindowEventMoveTabToNewWindow) {
final args = call.arguments.split(',');
Expand Down
3 changes: 3 additions & 0 deletions flutter/lib/desktop/pages/file_manager_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ class FileManagerPage extends StatefulWidget {
required this.password,
required this.isSharedPassword,
this.tabController,
this.connToken,
this.forceRelay})
: super(key: key);
final String id;
final String? password;
final bool? isSharedPassword;
final bool? forceRelay;
final String? connToken;
final DesktopTabController? tabController;

@override
Expand All @@ -90,6 +92,7 @@ class _FileManagerPageState extends State<FileManagerPage>
isFileTransfer: true,
password: widget.password,
isSharedPassword: widget.isSharedPassword,
connToken: widget.connToken,
forceRelay: widget.forceRelay);
WidgetsBinding.instance.addPostFrameCallback((_) {
_ffi.dialogManager
Expand Down
4 changes: 3 additions & 1 deletion flutter/lib/desktop/pages/file_manager_tab_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class _FileManagerTabPageState extends State<FileManagerTabPage> {
isSharedPassword: params['isSharedPassword'],
tabController: tabController,
forceRelay: params['forceRelay'],
connToken: params['connToken'],
)));
}

Expand All @@ -56,7 +57,7 @@ class _FileManagerTabPageState extends State<FileManagerTabPage> {
super.initState();

rustDeskWinManager.setMethodHandler((call, fromWindowId) async {
print(
debugPrint(
"[FileTransfer] call ${call.method} with args ${call.arguments} from window $fromWindowId to ${windowId()}");
// for simplify, just replace connectionId
if (call.method == kWindowEventNewFileTransfer) {
Expand All @@ -76,6 +77,7 @@ class _FileManagerTabPageState extends State<FileManagerTabPage> {
isSharedPassword: args['isSharedPassword'],
tabController: tabController,
forceRelay: args['forceRelay'],
connToken: args['connToken'],
)));
} else if (call.method == "onDestroy") {
tabController.clear();
Expand Down
3 changes: 3 additions & 0 deletions flutter/lib/desktop/pages/port_forward_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ class PortForwardPage extends StatefulWidget {
required this.isRDP,
required this.isSharedPassword,
this.forceRelay,
this.connToken,
}) : super(key: key);
final String id;
final String? password;
final DesktopTabController tabController;
final bool isRDP;
final bool? forceRelay;
final bool? isSharedPassword;
final String? connToken;

@override
State<PortForwardPage> createState() => _PortForwardPageState();
Expand All @@ -62,6 +64,7 @@ class _PortForwardPageState extends State<PortForwardPage>
password: widget.password,
isSharedPassword: widget.isSharedPassword,
forceRelay: widget.forceRelay,
connToken: widget.connToken,
isRdp: widget.isRDP);
Get.put<FFI>(_ffi, tag: 'pf_${widget.id}');
debugPrint("Port forward page init success with id ${widget.id}");
Expand Down
2 changes: 2 additions & 0 deletions flutter/lib/desktop/pages/port_forward_tab_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class _PortForwardTabPageState extends State<PortForwardTabPage> {
tabController: tabController,
isRDP: isRDP,
forceRelay: params['forceRelay'],
connToken: params['connToken'],
)));
}

Expand Down Expand Up @@ -82,6 +83,7 @@ class _PortForwardTabPageState extends State<PortForwardTabPage> {
isRDP: isRDP,
tabController: tabController,
forceRelay: args['forceRelay'],
connToken: args['connToken'],
)));
} else if (call.method == "onDestroy") {
tabController.clear();
Expand Down
2 changes: 1 addition & 1 deletion flutter/lib/desktop/pages/remote_tab_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
RemoteCountState.find().value = tabController.length;

Future<dynamic> _remoteMethodHandler(call, fromWindowId) async {
print(
debugPrint(
"[Remote Page] call ${call.method} with args ${call.arguments} from window $fromWindowId");

dynamic returnValue;
Expand Down
4 changes: 3 additions & 1 deletion flutter/lib/models/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ class FfiModel with ChangeNotifier {
} else if (name == 'plugin_option') {
handleOption(evt);
} else if (name == "sync_peer_hash_password_to_personal_ab") {
if (desktopType == DesktopType.main || isWeb) {
if (desktopType == DesktopType.main || isWeb || isMobile) {
final id = evt['id'];
final hash = evt['hash'];
if (id != null && hash != null) {
Expand Down Expand Up @@ -2462,6 +2462,7 @@ class FFI {
String? switchUuid,
String? password,
bool? isSharedPassword,
String? connToken,
bool? forceRelay,
int? tabWindowId,
int? display,
Expand Down Expand Up @@ -2498,6 +2499,7 @@ class FFI {
forceRelay: forceRelay ?? false,
password: password ?? '',
isSharedPassword: isSharedPassword ?? false,
connToken: connToken,
);
} else if (display != null) {
if (displays == null) {
Expand Down
25 changes: 21 additions & 4 deletions flutter/lib/utils/multi_window_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ class RustDeskMultiWindowManager {
String? switchUuid,
bool? isRDP,
bool? isSharedPassword,
String? connToken,
}) async {
var params = {
"type": type.index,
Expand All @@ -217,6 +218,9 @@ class RustDeskMultiWindowManager {
if (isSharedPassword != null) {
params['isSharedPassword'] = isSharedPassword;
}
if (connToken != null) {
params['connToken'] = connToken;
}
final msg = jsonEncode(params);

// separate window for file transfer is not supported
Expand Down Expand Up @@ -254,8 +258,13 @@ class RustDeskMultiWindowManager {
);
}

Future<MultiWindowCallResult> newFileTransfer(String remoteId,
{String? password, bool? isSharedPassword, bool? forceRelay}) async {
Future<MultiWindowCallResult> newFileTransfer(
String remoteId, {
String? password,
bool? isSharedPassword,
bool? forceRelay,
String? connToken,
}) async {
return await newSession(
WindowType.FileTransfer,
kWindowEventNewFileTransfer,
Expand All @@ -264,11 +273,18 @@ class RustDeskMultiWindowManager {
password: password,
forceRelay: forceRelay,
isSharedPassword: isSharedPassword,
connToken: connToken,
);
}

Future<MultiWindowCallResult> newPortForward(String remoteId, bool isRDP,
{String? password, bool? isSharedPassword, bool? forceRelay}) async {
Future<MultiWindowCallResult> newPortForward(
String remoteId,
bool isRDP, {
String? password,
bool? isSharedPassword,
bool? forceRelay,
String? connToken,
}) async {
return await newSession(
WindowType.PortForward,
kWindowEventNewPortForward,
Expand All @@ -278,6 +294,7 @@ class RustDeskMultiWindowManager {
forceRelay: forceRelay,
isRDP: isRDP,
isSharedPassword: isSharedPassword,
connToken: connToken,
);
}

Expand Down
41 changes: 37 additions & 4 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crossbeam_queue::ArrayQueue;
use magnum_opus::{Channels::*, Decoder as AudioDecoder};
#[cfg(not(any(target_os = "android", target_os = "linux")))]
use ringbuf::{ring_buffer::RbBase, Rb};
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use std::{
collections::HashMap,
Expand Down Expand Up @@ -1274,7 +1275,7 @@ impl VideoHandler {
}

// The source of sent password
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
enum PasswordSource {
PersonalAb(Vec<u8>),
SharedAb(String),
Expand Down Expand Up @@ -1320,6 +1321,13 @@ impl PasswordSource {
}
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
struct ConnToken {
password: Vec<u8>,
password_source: PasswordSource,
session_id: u64,
}

/// Login config handler for [`Client`].
#[derive(Default)]
pub struct LoginConfigHandler {
Expand Down Expand Up @@ -1376,6 +1384,7 @@ impl LoginConfigHandler {
mut force_relay: bool,
adapter_luid: Option<i64>,
shared_password: Option<String>,
conn_token: Option<String>,
) {
let mut id = id;
if id.contains("@") {
Expand Down Expand Up @@ -1419,10 +1428,22 @@ impl LoginConfigHandler {
let config = self.load_config();
self.remember = !config.password.is_empty();
self.config = config;
let mut sid = rand::random();

let conn_token = conn_token
.map(|x| serde_json::from_str::<ConnToken>(&x).ok())
.flatten();
let mut sid = 0;
if let Some(token) = conn_token {
sid = token.session_id;
self.password = token.password; // use as last password
self.password_source = token.password_source;
}
if sid == 0 {
// you won the lottery
sid = 1;
sid = rand::random();
if sid == 0 {
// you won the lottery
sid = 1;
}
}
self.session_id = sid;
self.supported_encoding = Default::default();
Expand Down Expand Up @@ -2223,6 +2244,18 @@ impl LoginConfigHandler {
msg_out.set_misc(misc);
msg_out
}

pub fn get_conn_token(&self) -> Option<String> {
if self.password.is_empty() {
return None;
}
serde_json::to_string(&ConnToken {
password: self.password.clone(),
password_source: self.password_source.clone(),
session_id: self.session_id,
})
.ok()
}
}

/// Media data.
Expand Down
2 changes: 2 additions & 0 deletions src/flutter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,7 @@ pub fn session_add(
force_relay: bool,
password: String,
is_shared_password: bool,
conn_token: Option<String>,
) -> ResultType<FlutterSession> {
let conn_type = if is_file_transfer {
ConnType::FILE_TRANSFER
Expand Down Expand Up @@ -1180,6 +1181,7 @@ pub fn session_add(
force_relay,
get_adapter_luid(),
shared_password,
conn_token,
);

let session = Arc::new(session.clone());
Expand Down
10 changes: 10 additions & 0 deletions src/flutter_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ pub fn session_add_sync(
force_relay: bool,
password: String,
is_shared_password: bool,
conn_token: Option<String>,
) -> SyncReturn<String> {
if let Err(e) = session_add(
&session_id,
Expand All @@ -132,6 +133,7 @@ pub fn session_add_sync(
force_relay,
password,
is_shared_password,
conn_token,
) {
SyncReturn(format!("Failed to add session with id {}, {}", &id, e))
} else {
Expand Down Expand Up @@ -1341,6 +1343,14 @@ pub fn session_close_voice_call(session_id: SessionID) {
}
}

pub fn session_get_conn_token(session_id: SessionID) -> SyncReturn<Option<String>> {
if let Some(session) = sessions::get_session_by_session_id(&session_id) {
SyncReturn(session.get_conn_token())
} else {
SyncReturn(None)
}
}

pub fn cm_handle_incoming_voice_call(id: i32, accept: bool) {
crate::ui_cm_interface::handle_incoming_voice_call(id, accept);
}
Expand Down
Loading

0 comments on commit 445e9ac

Please sign in to comment.