diff --git a/docs/index.md b/docs/index.md
index 424e4f8..a12eae7 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -132,6 +132,7 @@ Termix connects to a [RustDesk](https://rustdesk.com) device the way the RustDes
- By default Termix finds the device through the public RustDesk server. To use your own, set the ID server, relay server and key in the admin settings, under Remote Desktop. The key is the contents of `id_ed25519.pub` on your server. A host can also set its own server.
- The Termix server talks to the ID server on TCP 21116 and the relay on TCP 21117. It always goes through the relay, since a server can't hole punch.
- Direct IP access connects to the host address on port 21118 instead, with no ID server. Turn on Direct IP access in RustDesk on the device first. The connection is encrypted, but with no ID server nothing proves which device answered. Jump hosts work in this mode.
+- Older RustDesk versions answer direct IP access without encryption, and Termix refuses that by default. Turn on Allow unencrypted sessions on the host to connect anyway, and only over a network you trust, such as a VPN.
- Video stays in RustDesk's own format and your browser decodes it, so it needs a recent Chrome, Edge, Firefox or Safari. VP9, AV1 and VP8 are used, never H.264 or H.265.
- Clipboard text works both ways, and you hear the remote's audio. With more than one monitor, the toolbar has a button for each.
- Not supported yet: file transfer and recording.
diff --git a/locales/en.json b/locales/en.json
index 23ed82f..d0b46b2 100644
--- a/locales/en.json
+++ b/locales/en.json
@@ -303,6 +303,8 @@
"rustdesk": {
"direct": "Direct IP access",
"directDesc": "Connect to the host address instead of looking up a RustDesk ID. Direct IP access must be on in RustDesk on that device.",
+ "allowPlain": "Allow unencrypted sessions",
+ "allowPlainDesc": "Older RustDesk versions answer direct IP access without encryption. Only turn this on over a network you trust, such as a VPN.",
"port": "Direct IP port",
"directNote": "The connection is encrypted, but with no ID server there is nothing to prove which device answered.",
"id": "RustDesk ID",
@@ -562,6 +564,9 @@
"rustdeskDirect": {
"label": "RustDesk direct IP access"
},
+ "rustdeskAllowPlain": {
+ "label": "RustDesk unencrypted direct IP sessions"
+ },
"rustdeskIdServer": {
"label": "RustDesk ID server"
},
diff --git a/src/backend/engine/worker/rustdesk/client.ts b/src/backend/engine/worker/rustdesk/client.ts
index 19f2380..be1c419 100644
--- a/src/backend/engine/worker/rustdesk/client.ts
+++ b/src/backend/engine/worker/rustdesk/client.ts
@@ -172,8 +172,16 @@ export class RustDeskClient implements RemoteClient {
route.conn.close();
return;
}
- await secure(route.conn, peerId, route, { key, direct, idServer });
- this.host.log("debug", "RustDesk session secured", { direct });
+ const { plain } = await secure(route.conn, peerId, route, {
+ key,
+ direct,
+ idServer,
+ allowPlain: s.bool("allow-plain"),
+ });
+ this.host.log("debug", "RustDesk session secured", {
+ direct,
+ encrypted: !plain,
+ });
this.loginTimer = setTimeout(() => {
if (this.loggedIn || this.stopped) return;
this.abort(
@@ -200,6 +208,8 @@ export class RustDeskClient implements RemoteClient {
});
}
});
+ // An unencrypted peer already sent its password challenge.
+ if (plain) this.receive(plain, peerId);
}
/** Ends the session with an error, once. */
diff --git a/src/backend/engine/worker/rustdesk/handshake.ts b/src/backend/engine/worker/rustdesk/handshake.ts
index 9b1084e..533852c 100644
--- a/src/backend/engine/worker/rustdesk/handshake.ts
+++ b/src/backend/engine/worker/rustdesk/handshake.ts
@@ -285,9 +285,15 @@ export async function secure(
conn: Connection,
peerId: string,
route: Route,
- options: { key: string; direct: boolean; idServer: string },
+ options: {
+ key: string;
+ direct: boolean;
+ idServer: string;
+ /** Carry on when a direct peer skips the key exchange. */
+ allowPlain?: boolean;
+ },
timeoutMs = 10_000,
-): Promise<{ verified: boolean }> {
+): Promise<{ verified: boolean; plain?: Uint8Array }> {
let peerSignPk: Uint8Array | null = null;
if (!options.direct) {
const rsKey = serverKey(
@@ -311,9 +317,19 @@ export async function secure(
peerSignPk = idPk.pk;
}
- const first = PbMessage.decode(await conn.next(timeoutMs));
+ const frame = await conn.next(timeoutMs);
+ const first = PbMessage.decode(frame);
const signedId = first.message(MSG.signedId);
if (!signedId) {
+ // Older RustDesk answers direct IP access with the password challenge
+ // straight away and never encrypts the session.
+ if (options.direct && first.has(MSG.hash)) {
+ if (options.allowPlain) return { verified: false, plain: frame };
+ throw new RustDeskError(
+ "The remote device answered without encryption. Allow unencrypted sessions on this host to connect anyway",
+ UPSTREAM_ERROR,
+ );
+ }
throw new RustDeskError(
"The remote device did not start a secure session",
UPSTREAM_ERROR,
diff --git a/src/backend/host-settings.ts b/src/backend/host-settings.ts
index c81c3c5..37e7b6d 100644
--- a/src/backend/host-settings.ts
+++ b/src/backend/host-settings.ts
@@ -21,6 +21,7 @@ export interface RemoteDesktopHostSettings {
rustdeskRelayServer: string;
rustdeskKey: string;
rustdeskDirect: boolean;
+ rustdeskAllowPlain: boolean;
moonlightPort: number;
moonlightHostId: number;
moonlightAppId: number;
@@ -140,6 +141,7 @@ export async function readHostSettings(
rustdeskRelayServer: asText(values.rustdeskRelayServer),
rustdeskKey: asText(values.rustdeskKey),
rustdeskDirect: values.rustdeskDirect === true,
+ rustdeskAllowPlain: values.rustdeskAllowPlain === true,
moonlightPort: asPort(values.moonlightPort) ?? MOONLIGHT_DEFAULT_PORT,
moonlightHostId: asCount(values.moonlightHostId),
moonlightAppId: asCount(values.moonlightAppId),
@@ -218,6 +220,8 @@ export function normalizeImportedHost(
}
const direct = asBool(pick("rustdeskDirect"));
if (direct !== undefined) out.rustdeskDirect = direct;
+ const allowPlain = asBool(pick("rustdeskAllowPlain"));
+ if (allowPlain !== undefined) out.rustdeskAllowPlain = allowPlain;
const moonlight = asBool(pick("enableMoonlight"));
if (moonlight !== undefined) out.enableMoonlight = moonlight;
const moonlightPort = asPort(pick("moonlightPort"));
diff --git a/src/backend/routes.ts b/src/backend/routes.ts
index 56ca9f4..60ccedd 100644
--- a/src/backend/routes.ts
+++ b/src/backend/routes.ts
@@ -96,6 +96,7 @@ export async function rustdeskSettings(
password: input.password,
"rustdesk-id": settings.rustdeskId,
direct: settings.rustdeskDirect,
+ "allow-plain": settings.rustdeskDirect && settings.rustdeskAllowPlain,
"id-server": ownServer
? settings.rustdeskIdServer
: await admin("rustdeskIdServer"),
diff --git a/src/frontend/HostEditorRustdeskTab.tsx b/src/frontend/HostEditorRustdeskTab.tsx
index 694933d..e51059f 100644
--- a/src/frontend/HostEditorRustdeskTab.tsx
+++ b/src/frontend/HostEditorRustdeskTab.tsx
@@ -66,6 +66,17 @@ export function HostEditorRustdeskTab({
onChange={(v) => setField("rustdeskDirect", v)}
/>
+ {form.rustdeskDirect && (
+