Skip to content

Commit 5c33874

Browse files
Add encryption support (#1)
* Add encryption support * Cleanup * Hook channels * Show fingerprint in Ui * Disconnect client properly * Cleanups * Minor Fixes * Minor Fixes * Update Ios
1 parent bc0e6b4 commit 5c33874

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+8460
-140
lines changed

flutter_rust_bridge.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
rust_input: crate::api
2+
rust_root: rust/
3+
dart_output: lib/app/rust

ios/Podfile.lock

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,46 @@
11
PODS:
22
- Flutter (1.0.0)
3+
- integration_test (0.0.1):
4+
- Flutter
35
- network_info_plus (0.0.1):
46
- Flutter
7+
- path_provider_foundation (0.0.1):
8+
- Flutter
9+
- FlutterMacOS
10+
- rust_lib_lan_mouse_mobile (0.0.1):
11+
- Flutter
512
- shared_preferences_foundation (0.0.1):
613
- Flutter
714
- FlutterMacOS
815

916
DEPENDENCIES:
1017
- Flutter (from `Flutter`)
18+
- integration_test (from `.symlinks/plugins/integration_test/ios`)
1119
- network_info_plus (from `.symlinks/plugins/network_info_plus/ios`)
20+
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
21+
- rust_lib_lan_mouse_mobile (from `.symlinks/plugins/rust_lib_lan_mouse_mobile/ios`)
1222
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
1323

1424
EXTERNAL SOURCES:
1525
Flutter:
1626
:path: Flutter
27+
integration_test:
28+
:path: ".symlinks/plugins/integration_test/ios"
1729
network_info_plus:
1830
:path: ".symlinks/plugins/network_info_plus/ios"
31+
path_provider_foundation:
32+
:path: ".symlinks/plugins/path_provider_foundation/darwin"
33+
rust_lib_lan_mouse_mobile:
34+
:path: ".symlinks/plugins/rust_lib_lan_mouse_mobile/ios"
1935
shared_preferences_foundation:
2036
:path: ".symlinks/plugins/shared_preferences_foundation/darwin"
2137

2238
SPEC CHECKSUMS:
2339
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
40+
integration_test: 252f60fa39af5e17c3aa9899d35d908a0721b573
2441
network_info_plus: 6613d9d7cdeb0e6f366ed4dbe4b3c51c52d567a9
42+
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
43+
rust_lib_lan_mouse_mobile: fc8afa15f8c195a2159ced883a82be086f09bce8
2544
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78
2645

2746
PODFILE CHECKSUM: 819463e6a0290f5a72f145ba7cde16e8b6ef0796

lib/app/models/client.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import 'dart:convert';
22

33
class Client {
4-
final String host;
5-
final int port;
4+
String host;
5+
int port;
66

77
Client({required this.host, required this.port});
88

lib/app/modules/home/widgets/home_connections.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class _HomeConnectionsState extends State<HomeConnections> {
2424
}
2525

2626
void connectClient(Client client) async {
27-
lanMouseServer.startServer(ignoreIfAlreadyRunning: true);
2827
Navigator.push(
2928
context,
3029
MaterialPageRoute(

lib/app/modules/home/widgets/home_general.dart

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,41 @@ class HomeGeneral extends StatefulWidget {
1212

1313
class _HomeGeneralState extends State<HomeGeneral> {
1414
LanMouseServer lanMouseServer = LanMouseServer.instance;
15+
String fingerprint = "";
1516

1617
var portController = TextEditingController();
1718
var hostnameController = TextEditingController();
1819

1920
@override
2021
void initState() {
2122
super.initState();
22-
loadIp();
23+
portController.text = lanMouseServer.defaultClient.port.toString();
24+
hostnameController.text = lanMouseServer.defaultClient.host;
25+
_refreshData();
2326
}
2427

25-
void loadIp() async {
26-
hostnameController.text = lanMouseServer.host;
27-
portController.text = lanMouseServer.port.toString();
28+
void _refreshData() async {
29+
// Load Ip
2830
try {
2931
NetworkInfo network = NetworkInfo();
3032
hostnameController.text = (await network.getWifiIP()) ?? "127.0.0.1";
3133
} catch (e) {
32-
print("NetworkInfoError: $e");
34+
showSnackbar("NetworkInfoError: $e");
3335
}
34-
_syncHostAndPort();
35-
}
36-
37-
void toggleServer(bool isRunning) async {
38-
_syncHostAndPort();
36+
// Load FingerPrint
3937
try {
40-
if (!isRunning) {
41-
await lanMouseServer.startServer();
38+
String? data = await lanMouseServer.getFingerprint();
39+
if (data != null) {
40+
setState(() {
41+
fingerprint = data;
42+
});
4243
} else {
43-
lanMouseServer.stopServer();
44+
showSnackbar("Failed to get fingerprint");
4445
}
4546
} catch (e) {
46-
showSnackbar(e);
47+
showSnackbar("Failed to get fingerprint: $e");
4748
}
49+
_syncHost();
4850
}
4951

5052
void showSnackbar(message) {
@@ -55,9 +57,9 @@ class _HomeGeneralState extends State<HomeGeneral> {
5557
}
5658
}
5759

58-
void _syncHostAndPort() {
59-
lanMouseServer.host = hostnameController.text;
60-
lanMouseServer.port = int.parse(portController.text);
60+
void _syncHost() {
61+
lanMouseServer.defaultClient.host = hostnameController.text;
62+
lanMouseServer.defaultClient.port = int.parse(portController.text);
6163
}
6264

6365
@override
@@ -72,17 +74,9 @@ class _HomeGeneralState extends State<HomeGeneral> {
7274
"General",
7375
style: Theme.of(context).textTheme.titleSmall,
7476
),
75-
ValueListenableBuilder<bool>(
76-
valueListenable: lanMouseServer.isSocketRunning,
77-
builder: (context, isRunning, _) {
78-
return IconButton(
79-
onPressed: () => toggleServer(isRunning),
80-
icon: Icon(
81-
Icons.lan,
82-
color: isRunning ? Colors.green : null,
83-
),
84-
);
85-
},
77+
IconButton(
78+
onPressed: _refreshData,
79+
icon: const Icon(Icons.refresh),
8680
),
8781
],
8882
),
@@ -133,12 +127,35 @@ class _HomeGeneralState extends State<HomeGeneral> {
133127
),
134128
const SizedBox(width: 2),
135129
InkWell(
136-
onTap: loadIp,
137-
child: const Icon(Icons.refresh),
130+
onTap: () {
131+
Clipboard.setData(
132+
ClipboardData(text: hostnameController.text),
133+
);
134+
},
135+
child: const Icon(Icons.copy),
138136
),
139137
],
140138
),
141-
)
139+
),
140+
const Divider(),
141+
Padding(
142+
padding: const EdgeInsets.symmetric(horizontal: 8.0),
143+
child: ListTile(
144+
minVerticalPadding: 0,
145+
contentPadding: EdgeInsets.zero,
146+
leading: const Icon(Icons.fingerprint),
147+
title: const Text("Certificate Fingerprint"),
148+
subtitle: Text(
149+
fingerprint,
150+
style: Theme.of(context).textTheme.bodySmall,
151+
),
152+
onTap: () {
153+
Clipboard.setData(ClipboardData(text: fingerprint));
154+
showSnackbar("Fingerprint copied to clipboard");
155+
},
156+
),
157+
),
158+
const SizedBox(height: 15),
142159
],
143160
),
144161
)

lib/app/modules/server/server.dart

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@ class _ServerState extends State<Server> {
2929
setState(() {
3030
waitingForAck = true;
3131
});
32-
bool entered = await lanMouseServer.enterClient(client: widget.client);
32+
await lanMouseServer.enterClient(
33+
client: widget.client,
34+
onError: (String err) {
35+
_showErrorDialog(err);
36+
},
37+
);
3338
setState(() {
3439
waitingForAck = false;
3540
});
36-
if (!entered) _showRefreshDialog();
3741
}
3842

3943
@override
@@ -42,29 +46,22 @@ class _ServerState extends State<Server> {
4246
lanMouseServer.leaveClient();
4347
}
4448

45-
void _showRefreshDialog() {
49+
void _showErrorDialog(String error) {
4650
if (!context.mounted) return;
4751
showAdaptiveDialog(
4852
context: context,
4953
barrierDismissible: false,
5054
builder: (_) {
5155
return AlertDialog.adaptive(
5256
title: const Text("Error"),
53-
content: const Text("Failed to connect to client, please try again"),
57+
content: Text(error),
5458
actions: [
55-
TextButton(
56-
onPressed: () {
57-
Navigator.pop(context);
58-
enterClient();
59-
},
60-
child: const Text("Retry"),
61-
),
6259
TextButton(
6360
onPressed: () {
6461
Navigator.pop(context);
6562
Navigator.pop(context);
6663
},
67-
child: const Text("Cancel"),
64+
child: const Text("Ok"),
6865
)
6966
],
7067
);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// This file is automatically generated, so please do not edit it.
2+
// @generated by `flutter_rust_bridge`@ 2.6.0.
3+
4+
// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import
5+
6+
import '../frb_generated.dart';
7+
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
8+
9+
// These functions are ignored because they are not marked as `pub`: `get_certificate`
10+
11+
Future<(SenderWrapper, ReceiverWrapper)> createChannel() =>
12+
RustLib.instance.api.crateApiLanMouseServerCreateChannel();
13+
14+
/// Start a UdbSocket and create connection with given Client
15+
Stream<Uint8List> connect(
16+
{required String basePath,
17+
required String ipAddr,
18+
required int port,
19+
required String targetAddr,
20+
required int targetPort,
21+
required ReceiverWrapper rx}) =>
22+
RustLib.instance.api.crateApiLanMouseServerConnect(
23+
basePath: basePath,
24+
ipAddr: ipAddr,
25+
port: port,
26+
targetAddr: targetAddr,
27+
targetPort: targetPort,
28+
rx: rx);
29+
30+
Future<String?> getFingerprint({required String path}) =>
31+
RustLib.instance.api.crateApiLanMouseServerGetFingerprint(path: path);
32+
33+
// Rust type: RustOpaqueMoi<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<ReceiverWrapper>>
34+
abstract class ReceiverWrapper implements RustOpaqueInterface {}
35+
36+
// Rust type: RustOpaqueMoi<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<SenderWrapper>>
37+
abstract class SenderWrapper implements RustOpaqueInterface {
38+
Future<void> send({required List<int> data});
39+
}

0 commit comments

Comments
 (0)