19 Commits
Author SHA1 Message Date
lejianwen a11e3636c8 Up Version 2025-01-21 19:22:26 +08:00
lejianwen ea3d353aa6 Merge branch 'master' into forapi
# Conflicts:
#	.github/workflows/build.yaml
#	debian/changelog
2025-01-21 19:19:51 +08:00
lejianwen 45c900a7e6 Merge branch 'master' into forapi
# Conflicts:
#	Cargo.lock
#	libs/hbb_common/protos/rendezvous.proto
#	libs/hbb_common/src/tcp.rs
#	libs/hbb_common~master
2025-01-20 22:43:32 +08:00
lejianwen 8470471e9c docs: up readme 2025-01-15 22:00:33 +08:00
lejianwen 9416a98e48 docs: up readme 2025-01-15 20:28:42 +08:00
lejianwen bc980a3b84 feat: check token via jwt 2025-01-15 19:19:18 +08:00
lejianwen 42b836d064 chore: version 2025-01-12 21:27:11 +08:00
lejianwen ec534abc5e docs: Up Readme 2025-01-12 20:14:07 +08:00
lejianwen c72e0dc3e1 docs: Up Readme 2025-01-12 20:10:12 +08:00
lejianwen 4e37dc8090 feat: Add MUST_LOGIN Env 2025-01-12 20:07:38 +08:00
lejianwen e5ac30e2bc feat: Add online request from webclient 2025-01-12 19:32:31 +08:00
lejianwen d793bcf569 docs: up readme 2025-01-12 19:17:53 +08:00
lejianwen bb45a621a4 style: Remove Unnecessary log in tcp.rs 2025-01-12 14:21:51 +08:00
lejianwen 14198e7586 fix: remove build i386 s6 image because api not support i386 2025-01-12 14:13:17 +08:00
lejianwen 7ff5eee69b fix: remove build i386 s6 image because api not support i386 2025-01-12 13:53:11 +08:00
lejianwen b317b9e9e5 fix: remove build i386 image because api not support i386 2025-01-11 22:58:36 +08:00
lejianwen a2b4e8e4a5 feat: add api 2025-01-11 22:51:33 +08:00
lejianwen 10c23984a7 fix: rust-toolchain 2025-01-11 21:54:34 +08:00
lejianwen 9bae660559 feat: Add KeyExchange and Encrypted tcpstream
From https://github.com/rustdesk/rustdesk-server/pull/400/commits/7e6ddf06a988d31beaf80dc6ea12ad70068b38cb

------
2025-01-11 19:52:42 +08:00
21 changed files with 881 additions and 525 deletions
+18 -7
View File
@@ -47,7 +47,7 @@ jobs:
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: "1.81"
toolchain: stable
override: true
default: true
components: rustfmt
@@ -88,7 +88,7 @@ jobs:
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: "1.81"
toolchain: stable
override: true
default: true
components: rustfmt
@@ -220,7 +220,7 @@ jobs:
- { name: "amd64", docker_platform: "linux/amd64", s6_platform: "x86_64" }
- { name: "arm64v8", docker_platform: "linux/arm64", s6_platform: "aarch64" }
- { name: "armv7", docker_platform: "linux/arm/v7", s6_platform: "armhf" }
- { name: "i386", docker_platform: "linux/386", s6_platform: "i686" }
# - { name: "i386", docker_platform: "linux/386", s6_platform: "i686" }
steps:
@@ -311,7 +311,11 @@ jobs:
if: github.event_name != 'workflow_dispatch'
with:
base-image: ${{ secrets.DOCKER_IMAGE }}:${{ env.GIT_TAG }}
extra-images: ${{ secrets.DOCKER_IMAGE }}:${{ env.GIT_TAG }}-amd64,${{ secrets.DOCKER_IMAGE }}:${{ env.GIT_TAG }}-arm64v8,${{ secrets.DOCKER_IMAGE }}:${{ env.GIT_TAG }}-armv7,${{ secrets.DOCKER_IMAGE }}:${{ env.GIT_TAG }}-i386
extra-images: |
${{ secrets.DOCKER_IMAGE }}:${{ env.GIT_TAG }}-amd64,
${{ secrets.DOCKER_IMAGE }}:${{ env.GIT_TAG }}-arm64v8,
${{ secrets.DOCKER_IMAGE }}:${{ env.GIT_TAG }}-armv7,
# ${{ secrets.DOCKER_IMAGE }}:${{ env.GIT_TAG }}-i386
push: true
# manifest for :1 tag (major release)
@@ -319,7 +323,11 @@ jobs:
uses: Noelware/docker-manifest-action@master
with:
base-image: ${{ secrets.DOCKER_IMAGE }}:${{ env.MAJOR_TAG }}
extra-images: ${{ secrets.DOCKER_IMAGE }}:${{ env.MAJOR_TAG }}-amd64,${{ secrets.DOCKER_IMAGE }}:${{ env.MAJOR_TAG }}-arm64v8,${{ secrets.DOCKER_IMAGE }}:${{ env.MAJOR_TAG }}-armv7,${{ secrets.DOCKER_IMAGE }}:${{ env.MAJOR_TAG }}-i386
extra-images: |
${{ secrets.DOCKER_IMAGE }}:${{ env.MAJOR_TAG }}-amd64,
${{ secrets.DOCKER_IMAGE }}:${{ env.MAJOR_TAG }}-arm64v8,
${{ secrets.DOCKER_IMAGE }}:${{ env.MAJOR_TAG }}-armv7,
# ${{ secrets.DOCKER_IMAGE }}:${{ env.MAJOR_TAG }}-i386
push: true
# manifest for :latest tag
@@ -327,7 +335,11 @@ jobs:
uses: Noelware/docker-manifest-action@master
with:
base-image: ${{ secrets.DOCKER_IMAGE }}:${{ env.LATEST_TAG }}
extra-images: ${{ secrets.DOCKER_IMAGE }}:${{ env.LATEST_TAG }}-amd64,${{ secrets.DOCKER_IMAGE }}:${{ env.LATEST_TAG }}-arm64v8,${{ secrets.DOCKER_IMAGE }}:${{ env.LATEST_TAG }}-armv7,${{ secrets.DOCKER_IMAGE }}:${{ env.LATEST_TAG }}-i386
extra-images: |
${{ secrets.DOCKER_IMAGE }}:${{ env.LATEST_TAG }}-amd64,
${{ secrets.DOCKER_IMAGE }}:${{ env.LATEST_TAG }}-arm64v8,
${{ secrets.DOCKER_IMAGE }}:${{ env.LATEST_TAG }}-armv7,
# ${{ secrets.DOCKER_IMAGE }}:${{ env.LATEST_TAG }}-i386
push: true
@@ -407,7 +419,6 @@ jobs:
name: Docker manifest
needs: docker
runs-on: ubuntu-22.04
steps:
- name: Log in to Docker Hub
+7 -7
View File
@@ -42,7 +42,7 @@ jobs:
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@v1
with:
toolchain: "1.70.0"
toolchain: stable
targets: ${{ matrix.job.target }}
components: "rustfmt"
@@ -82,7 +82,7 @@ jobs:
- { name: "amd64", docker_platform: "linux/amd64", s6_platform: "x86_64" }
- { name: "arm64v8", docker_platform: "linux/arm64", s6_platform: "aarch64" }
- { name: "armv7", docker_platform: "linux/arm/v7", s6_platform: "armhf" }
- { name: "i386", docker_platform: "linux/386", s6_platform: "i686" }
# - { name: "i386", docker_platform: "linux/386", s6_platform: "i686" }
steps:
- name: Checkout
@@ -176,7 +176,7 @@ jobs:
ghcr.io/${{ github.repository }}-s6:${{ env.GIT_TAG }}-amd64,
ghcr.io/${{ github.repository }}-s6:${{ env.GIT_TAG }}-arm64v8,
ghcr.io/${{ github.repository }}-s6:${{ env.GIT_TAG }}-armv7,
ghcr.io/${{ github.repository }}-s6:${{ env.GIT_TAG }}-i386
# ghcr.io/${{ github.repository }}-s6:${{ env.GIT_TAG }}-i386
push: true
# Create and push manifest for :major tag
@@ -188,7 +188,7 @@ jobs:
ghcr.io/${{ github.repository }}-s6:${{ env.MAJOR_TAG }}-amd64,
ghcr.io/${{ github.repository }}-s6:${{ env.MAJOR_TAG }}-arm64v8,
ghcr.io/${{ github.repository }}-s6:${{ env.MAJOR_TAG }}-armv7,
ghcr.io/${{ github.repository }}-s6:${{ env.MAJOR_TAG }}-i386
# ghcr.io/${{ github.repository }}-s6:${{ env.MAJOR_TAG }}-i386
push: true
# Create and push manifest for :latest tag
@@ -200,7 +200,7 @@ jobs:
ghcr.io/${{ github.repository }}-s6:${{ env.LATEST_TAG }}-amd64,
ghcr.io/${{ github.repository }}-s6:${{ env.LATEST_TAG }}-arm64v8,
ghcr.io/${{ github.repository }}-s6:${{ env.LATEST_TAG }}-armv7,
ghcr.io/${{ github.repository }}-s6:${{ env.LATEST_TAG }}-i386
# ghcr.io/${{ github.repository }}-s6:${{ env.LATEST_TAG }}-i386
push: true
# Build and push single-arch Docker images to ghcr.io
@@ -235,7 +235,7 @@ jobs:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
@@ -246,7 +246,7 @@ jobs:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
+2 -2
View File
@@ -1,6 +1,6 @@
[package]
name = "hbbs"
version = "1.1.13"
version = "1.1.14"
authors = ["rustdesk <info@rustdesk.com>"]
edition = "2021"
build = "build.rs"
@@ -36,7 +36,7 @@ async-trait = "0.1"
async-speed-limit = { git = "https://github.com/open-trade/async-speed-limit" }
uuid = { version = "1.0", features = ["v4"] }
bcrypt = "0.13"
chrono = "0.4"
chrono = { version = "0.4", features = ["serde"] }
jsonwebtoken = "8"
headers = "0.3"
once_cell = "1.8"
+354
View File
@@ -0,0 +1,354 @@
<p align="center">
<a href="#how-to-build-manually">Manually</a> •
<a href="#docker-images">Docker</a> •
<a href="#s6-overlay-based-images">S6-overlay</a> •
<a href="#how-to-create-a-keypair">Keypair</a> •
<a href="#deb-packages">Debian</a> •
<a href="#env-variables">Variables</a><br>
[<a href="README-DE.md">Deutsch</a>] | [<a href="README-NL.md">Nederlands</a>] | [<a href="README-TW.md">繁體中文</a>] | [<a href="README-ZH.md">简体中文</a>]<br>
</p>
# RustDesk Server Program
[![build](https://github.com/rustdesk/rustdesk-server/actions/workflows/build.yaml/badge.svg)](https://github.com/rustdesk/rustdesk-server/actions/workflows/build.yaml)
[**Download**](https://github.com/rustdesk/rustdesk-server/releases)
[**Manual**](https://rustdesk.com/docs/en/self-host/)
[**FAQ**](https://github.com/rustdesk/rustdesk/wiki/FAQ)
Self-host your own RustDesk server, it is free and open source.
## How to build manually
```bash
cargo build --release
```
Three executables will be generated in target/release.
- hbbs - RustDesk ID/Rendezvous server
- hbbr - RustDesk relay server
- rustdesk-utils - RustDesk CLI utilities
You can find updated binaries on the [Releases](https://github.com/rustdesk/rustdesk-server/releases) page.
If you want extra features, [RustDesk Server Pro](https://rustdesk.com/pricing.html) might suit you better.
If you want to develop your own server, [rustdesk-server-demo](https://github.com/rustdesk/rustdesk-server-demo) might be a better and simpler start for you than this repo.
## Docker images
Docker images are automatically generated and published to [Docker Hub](https://hub.docker.com/r/rustdesk) and [GitHub Container Registry](https://github.com/rustdesk?tab=packages&repo_name=rustdesk-server) on every GitHub release. We have 2 kind of images.
### Classic image
These images are built from scratch with two main binaries (`hbbs` and `hbbr`). They're available on [Docker Hub](https://hub.docker.com/r/rustdesk/rustdesk-server/) and [GitHub Container Registry](https://github.com/rustdesk/rustdesk-server/pkgs/container/rustdesk-server) with these architectures:
* amd64
* arm64v8
* armv7
You could use `latest` tag or major version tag `1` with supported architectures:
| Version | image:tag |
| ------------- | --------------------------------- |
| latest | `rustdesk/rustdesk-server:latest` |
| Major version | `rustdesk/rustdesk-server:1` |
You can start these images directly with `docker run` with these commands:
```bash
docker run --name hbbs --net=host -v "$PWD/data:/root" -d rustdesk/rustdesk-server:latest hbbs -r <relay-server-ip[:port]>
docker run --name hbbr --net=host -v "$PWD/data:/root" -d rustdesk/rustdesk-server:latest hbbr
```
or without `--net=host`, but P2P direct connection can not work.
For systems using SELinux, replacing `/root` by `/root:z` is required for the containers to run correctly. Alternatively, SELinux container separation can be disabled completely adding the option `--security-opt label=disable`.
```bash
docker run --name hbbs -p 21115:21115 -p 21116:21116 -p 21116:21116/udp -p 21118:21118 -v "$PWD/data:/root" -d rustdesk/rustdesk-server:latest hbbs -r <relay-server-ip[:port]>
docker run --name hbbr -p 21117:21117 -p 21119:21119 -v "$PWD/data:/root" -d rustdesk/rustdesk-server:latest hbbr
```
The `relay-server-ip` parameter is the IP address (or dns name) of the server running these containers. The **optional** `port` parameter has to be used if you use a port different than **21117** for `hbbr`.
You can also use docker-compose, using this configuration as a template:
```yaml
version: '3'
networks:
rustdesk-net:
external: false
services:
hbbs:
container_name: hbbs
ports:
- 21115:21115
- 21116:21116
- 21116:21116/udp
- 21118:21118
image: rustdesk/rustdesk-server:latest
command: hbbs -r rustdesk.example.com:21117
volumes:
- ./data:/root
networks:
- rustdesk-net
depends_on:
- hbbr
restart: unless-stopped
hbbr:
container_name: hbbr
ports:
- 21117:21117
- 21119:21119
image: rustdesk/rustdesk-server:latest
command: hbbr
volumes:
- ./data:/root
networks:
- rustdesk-net
restart: unless-stopped
```
Edit line 16 to point to your relay server (the one listening on port 21117). You can also edit the volume lines (line 18 and line 33) if you need.
(docker-compose credit goes to @lukebarone and @QuiGonLeong)
> [!NOTE]
> The rustdesk/rustdesk-server:latest in China may be replaced with the latest version number on Docker Hub, such as `rustdesk-server:1.1.10-3`. Otherwise, the old version may be pulled due to image acceleration.
> [!NOTE]
> If you are experiencing issues pulling from Docker Hub, try pulling from the [GitHub Container Registry](https://github.com/rustdesk/rustdesk-server/pkgs/container/rustdesk-server) instead.
## S6-overlay based images
These images are build against `busybox:stable` with the addition of the binaries (both `hbbs` and `hbbr`) and [S6-overlay](https://github.com/just-containers/s6-overlay). They're available on [Docker hub](https://hub.docker.com/r/rustdesk/rustdesk-server-s6/) and [GitHub Container Registry](https://github.com/rustdesk/rustdesk-server/pkgs/container/rustdesk-server) with these architectures:
* amd64
* i386
* arm64v8
* armv7
You could use `latest` tag or major version tag `1` with supported architectures:
| Version | image:tag |
| ------------- | ------------------------------------ |
| latest | `rustdesk/rustdesk-server-s6:latest` |
| Major version | `rustdesk/rustdesk-server-s6:1` |
The S6-overlay acts as a supervisor and keeps both process running, so with this image, there's no need to have two separate running containers.
You can start these images directly with `docker run` with this command:
```bash
docker run --name rustdesk-server \
--net=host \
-e "RELAY=rustdeskrelay.example.com" \
-e "ENCRYPTED_ONLY=1" \
-v "$PWD/data:/data" -d rustdesk/rustdesk-server-s6:latest
```
or without `--net=host`, but P2P direct connection cannot work.
```bash
docker run --name rustdesk-server \
-p 21115:21115 -p 21116:21116 -p 21116:21116/udp \
-p 21117:21117 -p 21118:21118 -p 21119:21119 \
-e "RELAY=rustdeskrelay.example.com" \
-e "ENCRYPTED_ONLY=1" \
-v "$PWD/data:/data" -d rustdesk/rustdesk-server-s6:latest
```
Or you can use a docker-compose file:
```yaml
version: '3'
services:
rustdesk-server:
container_name: rustdesk-server
ports:
- 21115:21115
- 21116:21116
- 21116:21116/udp
- 21117:21117
- 21118:21118
- 21119:21119
image: rustdesk/rustdesk-server-s6:latest
environment:
- "RELAY=rustdesk.example.com:21117"
- "ENCRYPTED_ONLY=1"
volumes:
- ./data:/data
restart: unless-stopped
```
For this container image, you can use these environment variables, **in addition** to the ones specified in the following **ENV variables** section:
| variable | optional | description |
| --- | --- | --- |
| RELAY | no | the IP address/DNS name of the machine running this container |
| ENCRYPTED_ONLY | yes | if set to **"1"** unencrypted connection will not be accepted |
| KEY_PUB | yes | public part of the key pair |
| KEY_PRIV | yes | private part of the key pair |
### Secret management in S6-overlay based images
You can obviously keep the key pair in a docker volume, but the best practices tells you to not write the keys on the filesystem; so we provide a couple of options.
On container startup, the presence of the keypair is checked (`/data/id_ed25519.pub` and `/data/id_ed25519`) and if one of these keys doesn't exist, it's recreated from ENV variables or docker secrets.
Then the validity of the keypair is checked: if public and private keys doesn't match, the container will stop.
If you provide no keys, `hbbs` will generate one for you, and it'll place it in the default location.
#### Use ENV to store the key pair
You can use docker environment variables to store the keys. Just follow this examples:
```bash
docker run --name rustdesk-server \
--net=host \
-e "RELAY=rustdeskrelay.example.com" \
-e "ENCRYPTED_ONLY=1" \
-e "DB_URL=/db/db_v2.sqlite3" \
-e "KEY_PRIV=FR2j78IxfwJNR+HjLluQ2Nh7eEryEeIZCwiQDPVe+PaITKyShphHAsPLn7So0OqRs92nGvSRdFJnE2MSyrKTIQ==" \
-e "KEY_PUB=iEyskoaYRwLDy5+0qNDqkbPdpxr0kXRSZxNjEsqykyE=" \
-v "$PWD/db:/db" -d rustdesk/rustdesk-server-s6:latest
```
```yaml
version: '3'
services:
rustdesk-server:
container_name: rustdesk-server
ports:
- 21115:21115
- 21116:21116
- 21116:21116/udp
- 21117:21117
- 21118:21118
- 21119:21119
image: rustdesk/rustdesk-server-s6:latest
environment:
- "RELAY=rustdesk.example.com:21117"
- "ENCRYPTED_ONLY=1"
- "DB_URL=/db/db_v2.sqlite3"
- "KEY_PRIV=FR2j78IxfwJNR+HjLluQ2Nh7eEryEeIZCwiQDPVe+PaITKyShphHAsPLn7So0OqRs92nGvSRdFJnE2MSyrKTIQ=="
- "KEY_PUB=iEyskoaYRwLDy5+0qNDqkbPdpxr0kXRSZxNjEsqykyE="
volumes:
- ./db:/db
restart: unless-stopped
```
#### Use Docker secrets to store the key pair
You can alternatively use docker secrets to store the keys.
This is useful if you're using **docker-compose** or **Docker Swarm**.
Just follow this examples:
```bash
cat secrets/id_ed25519.pub | docker secret create key_pub -
cat secrets/id_ed25519 | docker secret create key_priv -
docker service create --name rustdesk-server \
--secret key_priv --secret key_pub \
--net=host \
-e "RELAY=rustdeskrelay.example.com" \
-e "ENCRYPTED_ONLY=1" \
-e "DB_URL=/db/db_v2.sqlite3" \
--mount "type=bind,source=$PWD/db,destination=/db" \
rustdesk/rustdesk-server-s6:latest
```
```yaml
version: '3'
services:
rustdesk-server:
container_name: rustdesk-server
ports:
- 21115:21115
- 21116:21116
- 21116:21116/udp
- 21117:21117
- 21118:21118
- 21119:21119
image: rustdesk/rustdesk-server-s6:latest
environment:
- "RELAY=rustdesk.example.com:21117"
- "ENCRYPTED_ONLY=1"
- "DB_URL=/db/db_v2.sqlite3"
volumes:
- ./db:/db
restart: unless-stopped
secrets:
- key_pub
- key_priv
secrets:
key_pub:
file: secrets/id_ed25519.pub
key_priv:
file: secrets/id_ed25519
```
## How to create a keypair
A keypair is needed for encryption; you can provide it, as explained before, but you need a way to create one.
You can use this command to generate a keypair:
```bash
/usr/bin/rustdesk-utils genkeypair
```
If you don't have (or don't want) the `rustdesk-utils` package installed on your system, you can invoke the same command with docker:
```bash
docker run --rm --entrypoint /usr/bin/rustdesk-utils rustdesk/rustdesk-server-s6:latest genkeypair
```
The output will be something like this:
```text
Public Key: 8BLLhtzUBU/XKAH4mep3p+IX4DSApe7qbAwNH9nv4yA=
Secret Key: egAVd44u33ZEUIDTtksGcHeVeAwywarEdHmf99KM5ajwEsuG3NQFT9coAfiZ6nen4hfgNICl7upsDA0f2e/jIA==
```
## .deb packages
Separate .deb packages are available for each binary, you can find them in the [Releases](https://github.com/rustdesk/rustdesk-server/releases).
These packages are meant for the following distributions:
- Ubuntu 24.04 LTS
- Ubuntu 22.04 LTS
- Ubuntu 20.04 LTS
- Ubuntu 18.04 LTS
- Debian 12 bookworm
- Debian 11 bullseye
- Debian 10 buster
## ENV variables
`hbbs` and `hbbr` can be configured using these ENV variables.
You can specify the variables as usual or use an `.env` file.
| variable | binary | description |
| --- | --- | --- |
| ALWAYS_USE_RELAY | hbbs | if set to **"Y"** disallows direct peer connection |
| DB_URL | hbbs | path for database file |
| DOWNGRADE_START_CHECK | hbbr | delay (in seconds) before downgrade check |
| DOWNGRADE_THRESHOLD | hbbr | threshold of downgrade check (bit/ms) |
| KEY | hbbs/hbbr | if set force the use of a specific key, if set to **"_"** force the use of any key |
| LIMIT_SPEED | hbbr | speed limit (in Mb/s) |
| PORT | hbbs/hbbr | listening port (21116 for hbbs - 21117 for hbbr) |
| RELAY | hbbs | IP address/DNS name of the machines running hbbr (separated by comma) |
| RUST_LOG | all | set debug level (error\|warn\|info\|debug\|trace) |
| SINGLE_BANDWIDTH | hbbr | max bandwidth for a single connection (in Mb/s) |
| TOTAL_BANDWIDTH | hbbr | max total bandwidth (in Mb/s) |
-348
View File
@@ -1,348 +0,0 @@
<p align="center">
<a href="#如何自行构建">自行构建</a> •
<a href="#Docker-镜像">Docker</a> •
<a href="#基于-S6-overlay-的镜像">S6-overlay</a> •
<a href="#如何创建密钥">密钥</a> •
<a href="#deb-套件">Debian</a> •
<a href="#ENV-环境参数">环境参数</a><br>
[<a href="README.md">English</a>] | [<a href="README-DE.md">Deutsch</a>] | [<a href="README-NL.md">Nederlands</a>] | [<a href="README-TW.md">繁体中文</a>]<br>
</p>
# RustDesk Server Program
[![build](https://github.com/rustdesk/rustdesk-server/actions/workflows/build.yaml/badge.svg)](https://github.com/rustdesk/rustdesk-server/actions/workflows/build.yaml)
[**下载**](https://github.com/rustdesk/rustdesk-server/releases)
[**说明文件**](https://rustdesk.com/docs/zh-cn/self-host/)
[**FAQ**](https://github.com/rustdesk/rustdesk/wiki/FAQ)
自行搭建属于你的RustDesk服务器,所有的一切都是免费且开源的
## 如何自行构建
```bash
cargo build --release
```
执行后会在target/release目录下生成三个对应平台的可执行程序
- hbbs - RustDesk ID/会和服务器
- hbbr - RustDesk 中继服务器
- rustdesk-utils - RustDesk 命令行工具
您可以在 [releases](https://github.com/rustdesk/rustdesk-server/releases) 页面中找到最新的服务端软件。
如果您需要额外的功能支持,[RustDesk 专业版服务器](https://rustdesk.com/pricing.html) 获取更适合您。
如果您想开发自己的服务器,[rustdesk-server-demo](https://github.com/rustdesk/rustdesk-server-demo) 应该会比直接使用这个仓库更简单快捷。
## Docker 镜像
Docker镜像会在每次 GitHub 发布新的release版本时自动构建。我们提供两种类型的镜像。
### Classic 传统镜像
这个类型的镜像是基于 `ubuntu-20.04` 进行构建,镜像仅包含两个主要的可执行程序(`hbbr` 和 `hbbs`)。它们可以通过以下tag在 [Docker Hub](https://hub.docker.com/r/rustdesk/rustdesk-server/) 上获得:
| 架构 | image:tag |
|---------| ----------------------------------------- |
| amd64 | `rustdesk/rustdesk-server:latest` |
| arm64v8 | `rustdesk/rustdesk-server:latest-arm64v8` |
您可以使用以下命令,直接通过 ``docker run`` 來启动这些镜像:
```bash
docker run --name hbbs --net=host -v "$PWD/data:/root" -d rustdesk/rustdesk-server:latest hbbs -r <relay-server-ip[:port]>
docker run --name hbbr --net=host -v "$PWD/data:/root" -d rustdesk/rustdesk-server:latest hbbr
```
或不使用 `--net=host` 参数启动, 但这样 P2P 直连功能将无法工作。
对于使用了 SELinux 的系统,您需要将 ``/root`` 替换为 ``/root:z``,以保证容器的正常运行。或者,也可以通过添加参数 ``--security-opt label=disable`` 来完全禁用 SELinux 容器隔离。
```bash
docker run --name hbbs -p 21115:21115 -p 21116:21116 -p 21116:21116/udp -p 21118:21118 -v "$PWD/data:/root" -d rustdesk/rustdesk-server:latest hbbs -r <relay-server-ip[:port]>
docker run --name hbbr -p 21117:21117 -p 21119:21119 -v "$PWD/data:/root" -d rustdesk/rustdesk-server:latest hbbr
```
`relay-server-ip` 参数是运行这些容器的服务器的 IP 地址(或 DNS 名称)。如果你不想使用 **21117** 作为 `hbbr` 的服务端口,可使用可选参数 `port` 进行指定。
您也可以使用 docker-compose 进行构建,以下为配置示例:
```yaml
version: '3'
networks:
rustdesk-net:
external: false
services:
hbbs:
container_name: hbbs
ports:
- 21115:21115
- 21116:21116
- 21116:21116/udp
- 21118:21118
image: rustdesk/rustdesk-server:latest
command: hbbs -r rustdesk.example.com:21117
volumes:
- ./data:/root
networks:
- rustdesk-net
depends_on:
- hbbr
restart: unless-stopped
hbbr:
container_name: hbbr
ports:
- 21117:21117
- 21119:21119
image: rustdesk/rustdesk-server:latest
command: hbbr
volumes:
- ./data:/root
networks:
- rustdesk-net
restart: unless-stopped
```
编辑第16行来指定你的中继服务器 (默认端口监听在 21117 的那一个)。 如果需要的话,您也可以编辑 volume 信息 (第 18 和 33 行)。
(感谢 @lukebarone 和 @QuiGonLeong 协助提供的 docker-compose 配置示例)
## 基于 S6-overlay 的镜像
> 这些镜像是针对 `busybox:stable` 构建的,并添加了可执行程序(hbbr 和 hbbs)以及 [S6-overlay](https://github.com/just-containers/s6-overlay)。 它们可以使用以下tag在 [Docker hub](https://hub.docker.com/r/rustdesk/rustdesk-server-s6/) 上获取:
| 架構 | version | image:tag |
| --------- | ------- | -------------------------------------------- |
| multiarch | latest | `rustdesk/rustdesk-server-s6:latest` |
| amd64 | latest | `rustdesk/rustdesk-server-s6:latest-amd64` |
| i386 | latest | `rustdesk/rustdesk-server-s6:latest-i386` |
| arm64v8 | latest | `rustdesk/rustdesk-server-s6:latest-arm64v8` |
| armv7 | latest | `rustdesk/rustdesk-server-s6:latest-armv7` |
| multiarch | 2 | `rustdesk/rustdesk-server-s6:2` |
| amd64 | 2 | `rustdesk/rustdesk-server-s6:2-amd64` |
| i386 | 2 | `rustdesk/rustdesk-server-s6:2-i386` |
| arm64v8 | 2 | `rustdesk/rustdesk-server-s6:2-arm64v8` |
| armv7 | 2 | `rustdesk/rustdesk-server-s6:2-armv7` |
| multiarch | 2.0.0 | `rustdesk/rustdesk-server-s6:2.0.0` |
| amd64 | 2.0.0 | `rustdesk/rustdesk-server-s6:2.0.0-amd64` |
| i386 | 2.0.0 | `rustdesk/rustdesk-server-s6:2.0.0-i386` |
| arm64v8 | 2.0.0 | `rustdesk/rustdesk-server-s6:2.0.0-arm64v8` |
| armv7 | 2.0.0 | `rustdesk/rustdesk-server-s6:2.0.0-armv7` |
强烈建议您使用`major version` 或 `latest` tag 的 `multiarch` 架构的镜像。
S6-overlay 在此处作为监控程序,用以保证两个进程的运行,因此使用此镜像,您无需运行两个容器。
您可以使用 `docker run` 命令直接启动镜像,如下:
```bash
docker run --name rustdesk-server \
--net=host \
-e "RELAY=rustdeskrelay.example.com" \
-e "ENCRYPTED_ONLY=1" \
-v "$PWD/data:/data" -d rustdesk/rustdesk-server-s6:latest
```
或刪去 `--net=host` 参数, 但 P2P 直连功能将无法工作。
```bash
docker run --name rustdesk-server \
-p 21115:21115 -p 21116:21116 -p 21116:21116/udp \
-p 21117:21117 -p 21118:21118 -p 21119:21119 \
-e "RELAY=rustdeskrelay.example.com" \
-e "ENCRYPTED_ONLY=1" \
-v "$PWD/data:/data" -d rustdesk/rustdesk-server-s6:latest
```
或着您也可以使用 docker-compose 文件:
```yaml
version: '3'
services:
rustdesk-server:
container_name: rustdesk-server
ports:
- 21115:21115
- 21116:21116
- 21116:21116/udp
- 21117:21117
- 21118:21118
- 21119:21119
image: rustdesk/rustdesk-server-s6:latest
environment:
- "RELAY=rustdesk.example.com:21117"
- "ENCRYPTED_ONLY=1"
volumes:
- ./data:/data
restart: unless-stopped
```
对于此容器镜像,除了在下面的环境变量部分指定的变量之外,您还可以使用以下`环境变量`
| 环境变量 | 是否可选 | 描述 |
|----------------|------|--------------------------|
| RELAY | 否 | 运行此容器的宿主机的 IP 地址/ DNS 名称 |
| ENCRYPTED_ONLY | 是 | 如果设置为 **"1"**,将不接受未加密的连接。 |
| KEY_PUB | 是 | 密钥对中的公钥(Public Key) |
| KEY_PRIV | 是 | 密钥对中的私钥(Private Key) |
### 基于 S6-overlay 镜像的密钥管理
您可以将密钥对保存在 Docker volume 中,但我们建议不要将密钥写入文件系統中;因此,我们提供了一些方案。
在容器启动时,会检查密钥对是否存在(`/data/id_ed25519.pub` 和 `/data/id_ed25519`),如果其中一個密钥不存在,则会从环境变量或 Docker Secret 中重新生成它。
然后检查密钥对的可用性:如果公钥和私钥不匹配,容器将停止运行。
如果您未提供密钥,`hbbs` 将会在默认位置生成一个。
#### 使用 ENV 存储密钥对
您可以使用 Docker 环境变量來存储密钥。如下:
```bash
docker run --name rustdesk-server \
--net=host \
-e "RELAY=rustdeskrelay.example.com" \
-e "ENCRYPTED_ONLY=1" \
-e "DB_URL=/db/db_v2.sqlite3" \
-e "KEY_PRIV=FR2j78IxfwJNR+HjLluQ2Nh7eEryEeIZCwiQDPVe+PaITKyShphHAsPLn7So0OqRs92nGvSRdFJnE2MSyrKTIQ==" \
-e "KEY_PUB=iEyskoaYRwLDy5+0qNDqkbPdpxr0kXRSZxNjEsqykyE=" \
-v "$PWD/db:/db" -d rustdesk/rustdesk-server-s6:latest
```
```yaml
version: '3'
services:
rustdesk-server:
container_name: rustdesk-server
ports:
- 21115:21115
- 21116:21116
- 21116:21116/udp
- 21117:21117
- 21118:21118
- 21119:21119
image: rustdesk/rustdesk-server-s6:latest
environment:
- "RELAY=rustdesk.example.com:21117"
- "ENCRYPTED_ONLY=1"
- "DB_URL=/db/db_v2.sqlite3"
- "KEY_PRIV=FR2j78IxfwJNR+HjLluQ2Nh7eEryEeIZCwiQDPVe+PaITKyShphHAsPLn7So0OqRs92nGvSRdFJnE2MSyrKTIQ=="
- "KEY_PUB=iEyskoaYRwLDy5+0qNDqkbPdpxr0kXRSZxNjEsqykyE="
volumes:
- ./db:/db
restart: unless-stopped
```
#### 使用 Docker Secret 來保存密钥对
您还可以使用 Docker Secret 來保存密钥。
如果您使用 **docker-compose** 或 **docker swarm**,推荐您使用。
只需按照以下示例操作:
```bash
cat secrets/id_ed25519.pub | docker secret create key_pub -
cat secrets/id_ed25519 | docker secret create key_priv -
docker service create --name rustdesk-server \
--secret key_priv --secret key_pub \
--net=host \
-e "RELAY=rustdeskrelay.example.com" \
-e "ENCRYPTED_ONLY=1" \
-e "DB_URL=/db/db_v2.sqlite3" \
--mount "type=bind,source=$PWD/db,destination=/db" \
rustdesk/rustdesk-server-s6:latest
```
```yaml
version: '3'
services:
rustdesk-server:
container_name: rustdesk-server
ports:
- 21115:21115
- 21116:21116
- 21116:21116/udp
- 21117:21117
- 21118:21118
- 21119:21119
image: rustdesk/rustdesk-server-s6:latest
environment:
- "RELAY=rustdesk.example.com:21117"
- "ENCRYPTED_ONLY=1"
- "DB_URL=/db/db_v2.sqlite3"
volumes:
- ./db:/db
restart: unless-stopped
secrets:
- key_pub
- key_priv
secrets:
key_pub:
file: secrets/id_ed25519.pub
key_priv:
file: secrets/id_ed25519
```
## 如何生成密钥对
加密需要一对密钥;您可以按照前面所述提供它,但需要一个工具去生成密钥对。
您可以使用以下命令生成一对密钥:
```bash
/usr/bin/rustdesk-utils genkeypair
```
如果您沒有(或不想)在系统上安装 `rustdesk-utils` 套件,您可以使用 Docker 执行相同的命令:
```bash
docker run --rm --entrypoint /usr/bin/rustdesk-utils rustdesk/rustdesk-server-s6:latest genkeypair
```
运行后的输出内容如下:
```text
Public Key: 8BLLhtzUBU/XKAH4mep3p+IX4DSApe7qbAwNH9nv4yA=
Secret Key: egAVd44u33ZEUIDTtksGcHeVeAwywarEdHmf99KM5ajwEsuG3NQFT9coAfiZ6nen4hfgNICl7upsDA0f2e/jIA==
```
## .deb 套件
每个可执行文件都有单独的 .deb 套件可供使用,您可以在 [releases](https://github.com/rustdesk/rustdesk-server/releases) 页面中找到它們。
這些套件适用于以下发行版:
- Ubuntu 22.04 LTS
- Ubuntu 20.04 LTS
- Ubuntu 18.04 LTS
- Debian 11 bullseye
- Debian 10 buster
## ENV 环境变量
可以使用这些`环境变量`参数來配置 hbbs 和 hbbr。
您可以像往常一样指定参数,或者使用 .env 文件。
| 参数 | 可执行文件 | 描述 |
|-----------------------|---------------|--------------------------------------------------|
| ALWAYS_USE_RELAY | hbbs | 如果设定为 **"Y"**,将关闭直接点对点连接功能 |
| DB_URL | hbbs | 数据库配置 |
| DOWNGRADE_START_CHECK | hbbr | 降级检查之前的延迟是啊尽(以秒为单位) |
| DOWNGRADE_THRESHOLD | hbbr | 降级检查的阈值(bit/ms) |
| KEY | hbbs/hbbr | 如果设置了此参数,将强制使用指定密钥对,如果设为 **"_"**,则强制使用任意密钥 |
| LIMIT_SPEED | hbbr | 速度限制(以Mb/s为单位) |
| PORT | hbbs/hbbr | 监听端口(hbbs为21116,hbbr为21117) |
| RELAY_SERVERS | hbbs | 运行hbbr的机器的IP地址/DNS名称(用逗号分隔) |
| RUST_LOG | all | 设置 debug level (error\|warn\|info\|debug\|trace) |
| SINGLE_BANDWIDTH | hbbr | 单个连接的最大带宽(以Mb/s为单位) |
| TOTAL_BANDWIDTH | hbbr | 最大总带宽(以Mb/s为单位) |
+180 -121
View File
@@ -1,82 +1,137 @@
# 关于此分支
[![build](https://github.com/lejianwen/rustdesk-server/actions/workflows/build.yaml/badge.svg)](https://github.com/lejianwen/rustdesk-server/actions/workflows/build.yaml)
- 解决当客户端登录了`Api`账号时链接超时的问题
- s6镜像添加了`Api`支持,`Api`开源地址 https://github.com/lejianwen/rustdesk-api
- 是否必须登录才能链接, `MUST_LOGIN` 默认为 `N`,设置为 `Y` 则必须登录才能链接
- `RUSTDESK_API_JWT_KEY`,设置后会通过`JWT`校验token的合法性
## docker镜像地址
- s6 镜像 [lejianwen/rustdesk-server-s6](https://hub.docker.com/r/lejianwen/rustdesk-server-s6)
```yaml
networks:
rustdesk-net:
external: false
services:
rustdesk:
ports:
- 21114:21114
- 21115:21115
- 21116:21116
- 21116:21116/udp
- 21117:21117
- 21118:21118
- 21119:21119
image: lejianwen/rustdesk-server-s6:latest
environment:
- RELAY=<relay_server[:port]>
- ENCRYPTED_ONLY=1
- MUST_LOGIN=N
- TZ=Asia/Shanghai
- RUSTDESK_API_RUSTDESK_ID_SERVER=<id_server[:21116]>
- RUSTDESK_API_RUSTDESK_RELAY_SERVER=<relay_server[:21117]>
- RUSTDESK_API_RUSTDESK_API_SERVER=http://<api_server[:21114]>
- RUSTDESK_API_KEY_FILE=/data/id_ed25519.pub
- RUSTDESK_API_JWT_KEY=xxxxxx # jwt key
volumes:
- /data/rustdesk/server:/data
- /data/rustdesk/api:/app/data #将数据库挂载
networks:
- rustdesk-net
restart: unless-stopped
```
- 普通镜像 [lejianwen/rustdesk-server](https://hub.docker.com/r/lejianwen/rustdesk-server)
# API功能截图
![Api.png](./readme/api.png)
![commnd.png](./readme/command_simple.png)
更多查看 [RustDesk Api](https://github.com/lejianwen/rustdesk-api)
---
<p align="center">
<a href="#how-to-build-manually">Manually</a> •
<a href="#docker-images">Docker</a> •
<a href="#s6-overlay-based-images">S6-overlay</a> •
<a href="#how-to-create-a-keypair">Keypair</a> •
<a href="#deb-packages">Debian</a> •
<a href="#env-variables">Variables</a><br>
[<a href="README-DE.md">Deutsch</a>] | [<a href="README-NL.md">Nederlands</a>] | [<a href="README-TW.md">繁體中文</a>] | [<a href="README-ZH.md">简体中文</a>]<br>
<a href="#如何自行构建">自行构建</a> •
<a href="#Docker-镜像">Docker</a> •
<a href="#基于-S6-overlay-的镜像">S6-overlay</a> •
<a href="#如何创建密钥">密钥</a> •
<a href="#deb-套件">Debian</a> •
<a href="#ENV-环境参数">环境参数</a><br>
[<a href="README-EN.md">English</a>] | [<a href="README-DE.md">Deutsch</a>] | [<a href="README-NL.md">Nederlands</a>] | [<a href="README-TW.md">繁体中文</a>]<br>
</p>
# RustDesk Server Program
[![build](https://github.com/rustdesk/rustdesk-server/actions/workflows/build.yaml/badge.svg)](https://github.com/rustdesk/rustdesk-server/actions/workflows/build.yaml)
[**Download**](https://github.com/rustdesk/rustdesk-server/releases)
[**Manual**](https://rustdesk.com/docs/en/self-host/)
[**下载**](https://github.com/lejianwen/rustdesk-server/releases)
[**FAQ**](https://github.com/rustdesk/rustdesk/wiki/FAQ)
[**说明文件**](https://rustdesk.com/docs/zh-cn/self-host/)
Self-host your own RustDesk server, it is free and open source.
自行搭建属于你的RustDesk服务器,所有的一切都是免费且开源的
## How to build manually
## 如何自行构建
```bash
cargo build --release
```
Three executables will be generated in target/release.
执行后会在target/release目录下生成三个对应平台的可执行程序
- hbbs - RustDesk ID/Rendezvous server
- hbbr - RustDesk relay server
- rustdesk-utils - RustDesk CLI utilities
- hbbs - RustDesk ID/会和服务器
- hbbr - RustDesk 中继服务器
- rustdesk-utils - RustDesk 命令行工具
You can find updated binaries on the [Releases](https://github.com/rustdesk/rustdesk-server/releases) page.
您可以在 [releases](https://github.com/lejianwen/rustdesk-server/releases) 页面中找到最新的服务端软件。
If you want extra features, [RustDesk Server Pro](https://rustdesk.com/pricing.html) might suit you better.
如果您需要额外的功能支持,[RustDesk 专业版服务器](https://rustdesk.com/pricing.html) 获取更适合您。
If you want to develop your own server, [rustdesk-server-demo](https://github.com/rustdesk/rustdesk-server-demo) might be a better and simpler start for you than this repo.
如果您想开发自己的服务器,[rustdesk-server-demo](https://github.com/rustdesk/rustdesk-server-demo) 应该会比直接使用这个仓库更简单快捷。
## Docker images
## Docker 镜像
Docker images are automatically generated and published to [Docker Hub](https://hub.docker.com/r/rustdesk) and [GitHub Container Registry](https://github.com/rustdesk?tab=packages&repo_name=rustdesk-server) on every GitHub release. We have 2 kind of images.
Docker镜像会在每次 GitHub 发布新的release版本时自动构建。我们提供两种类型的镜像。
### Classic image
### Classic 传统镜像
These images are built from scratch with two main binaries (`hbbs` and `hbbr`). They're available on [Docker Hub](https://hub.docker.com/r/rustdesk/rustdesk-server/) and [GitHub Container Registry](https://github.com/rustdesk/rustdesk-server/pkgs/container/rustdesk-server) with these architectures:
这个类型的镜像是基于 `ubuntu-20.04` 进行构建,镜像仅包含两个主要的可执行程序(`hbbr` 和 `hbbs`)。它们可以通过以下tag在 [Docker Hub](https://hub.docker.com/r/lejianwen/rustdesk-server/) 上获得:
* amd64
* arm64v8
* armv7
| 架构 | image:tag |
|---------| ----------------------------------------- |
| amd64 | `lejianwen/rustdesk-server:latest` |
| arm64v8 | `lejianwen/rustdesk-server:latest-arm64v8` |
You could use `latest` tag or major version tag `1` with supported architectures:
| Version | image:tag |
| ------------- | --------------------------------- |
| latest | `rustdesk/rustdesk-server:latest` |
| Major version | `rustdesk/rustdesk-server:1` |
You can start these images directly with `docker run` with these commands:
您可以使用以下命令,直接通过 ``docker run`` 來启动这些镜像:
```bash
docker run --name hbbs --net=host -v "$PWD/data:/root" -d rustdesk/rustdesk-server:latest hbbs -r <relay-server-ip[:port]>
docker run --name hbbr --net=host -v "$PWD/data:/root" -d rustdesk/rustdesk-server:latest hbbr
docker run --name hbbs --net=host -v "$PWD/data:/root" -d lejianwen/rustdesk-server:latest hbbs -r <relay-server-ip[:port]>
docker run --name hbbr --net=host -v "$PWD/data:/root" -d lejianwen/rustdesk-server:latest hbbr
```
or without `--net=host`, but P2P direct connection can not work.
或不使用 `--net=host` 参数启动, 但这样 P2P 直连功能将无法工作。
For systems using SELinux, replacing `/root` by `/root:z` is required for the containers to run correctly. Alternatively, SELinux container separation can be disabled completely adding the option `--security-opt label=disable`.
对于使用了 SELinux 的系统,您需要将 ``/root`` 替换为 ``/root:z``,以保证容器的正常运行。或者,也可以通过添加参数 ``--security-opt label=disable`` 来完全禁用 SELinux 容器隔离。
```bash
docker run --name hbbs -p 21115:21115 -p 21116:21116 -p 21116:21116/udp -p 21118:21118 -v "$PWD/data:/root" -d rustdesk/rustdesk-server:latest hbbs -r <relay-server-ip[:port]>
docker run --name hbbr -p 21117:21117 -p 21119:21119 -v "$PWD/data:/root" -d rustdesk/rustdesk-server:latest hbbr
docker run --name hbbs -p 21115:21115 -p 21116:21116 -p 21116:21116/udp -p 21118:21118 -v "$PWD/data:/root" -d lejianwen/rustdesk-server:latest hbbs -r <relay-server-ip[:port]>
docker run --name hbbr -p 21117:21117 -p 21119:21119 -v "$PWD/data:/root" -d lejianwen/rustdesk-server:latest hbbr
```
The `relay-server-ip` parameter is the IP address (or dns name) of the server running these containers. The **optional** `port` parameter has to be used if you use a port different than **21117** for `hbbr`.
`relay-server-ip` 参数是运行这些容器的服务器的 IP 地址(或 DNS 名称)。如果你不想使用 **21117** 作为 `hbbr` 的服务端口,可使用可选参数 `port` 进行指定。
You can also use docker-compose, using this configuration as a template:
您也可以使用 docker-compose 进行构建,以下为配置示例:
```yaml
version: '3'
@@ -93,7 +148,7 @@ services:
- 21116:21116
- 21116:21116/udp
- 21118:21118
image: rustdesk/rustdesk-server:latest
image: lejianwen/rustdesk-server:latest
command: hbbs -r rustdesk.example.com:21117
volumes:
- ./data:/root
@@ -108,7 +163,7 @@ services:
ports:
- 21117:21117
- 21119:21119
image: rustdesk/rustdesk-server:latest
image: lejianwen/rustdesk-server:latest
command: hbbr
volumes:
- ./data:/root
@@ -117,45 +172,48 @@ services:
restart: unless-stopped
```
Edit line 16 to point to your relay server (the one listening on port 21117). You can also edit the volume lines (line 18 and line 33) if you need.
编辑第16行来指定你的中继服务器 (默认端口监听在 21117 的那一个)。 如果需要的话,您也可以编辑 volume 信息 (第 18 和 33 行)。
(docker-compose credit goes to @lukebarone and @QuiGonLeong)
(感谢 @lukebarone 和 @QuiGonLeong 协助提供的 docker-compose 配置示例)
> [!NOTE]
> The rustdesk/rustdesk-server:latest in China may be replaced with the latest version number on Docker Hub, such as `rustdesk-server:1.1.10-3`. Otherwise, the old version may be pulled due to image acceleration.
## 基于 S6-overlay 的镜像
> [!NOTE]
> If you are experiencing issues pulling from Docker Hub, try pulling from the [GitHub Container Registry](https://github.com/rustdesk/rustdesk-server/pkgs/container/rustdesk-server) instead.
> 这些镜像是针对 `busybox:stable` 构建的,并添加了可执行程序(hbbr 和 hbbs)以及 [S6-overlay](https://github.com/just-containers/s6-overlay)。 它们可以使用以下tag在 [Docker hub](https://hub.docker.com/r/lejianwen/rustdesk-server-s6/) 上获取:
## S6-overlay based images
These images are build against `busybox:stable` with the addition of the binaries (both `hbbs` and `hbbr`) and [S6-overlay](https://github.com/just-containers/s6-overlay). They're available on [Docker hub](https://hub.docker.com/r/rustdesk/rustdesk-server-s6/) and [GitHub Container Registry](https://github.com/rustdesk/rustdesk-server/pkgs/container/rustdesk-server) with these architectures:
| 架構 | version | image:tag |
| --------- | ------- | -------------------------------------------- |
| multiarch | latest | `lejianwen/rustdesk-server-s6:latest` |
| amd64 | latest | `lejianwen/rustdesk-server-s6:latest-amd64` |
| i386 | latest | `lejianwen/rustdesk-server-s6:latest-i386` |
| arm64v8 | latest | `lejianwen/rustdesk-server-s6:latest-arm64v8` |
| armv7 | latest | `lejianwen/rustdesk-server-s6:latest-armv7` |
| multiarch | 2 | `lejianwen/rustdesk-server-s6:2` |
| amd64 | 2 | `lejianwen/rustdesk-server-s6:2-amd64` |
| i386 | 2 | `lejianwen/rustdesk-server-s6:2-i386` |
| arm64v8 | 2 | `lejianwen/rustdesk-server-s6:2-arm64v8` |
| armv7 | 2 | `lejianwen/rustdesk-server-s6:2-armv7` |
| multiarch | 2.0.0 | `lejianwen/rustdesk-server-s6:2.0.0` |
| amd64 | 2.0.0 | `lejianwen/rustdesk-server-s6:2.0.0-amd64` |
| i386 | 2.0.0 | `lejianwen/rustdesk-server-s6:2.0.0-i386` |
| arm64v8 | 2.0.0 | `lejianwen/rustdesk-server-s6:2.0.0-arm64v8` |
| armv7 | 2.0.0 | `lejianwen/rustdesk-server-s6:2.0.0-armv7` |
* amd64
* i386
* arm64v8
* armv7
强烈建议您使用`major version` 或 `latest` tag 的 `multiarch` 架构的镜像。
You could use `latest` tag or major version tag `1` with supported architectures:
S6-overlay 在此处作为监控程序,用以保证两个进程的运行,因此使用此镜像,您无需运行两个容器。
| Version | image:tag |
| ------------- | ------------------------------------ |
| latest | `rustdesk/rustdesk-server-s6:latest` |
| Major version | `rustdesk/rustdesk-server-s6:1` |
The S6-overlay acts as a supervisor and keeps both process running, so with this image, there's no need to have two separate running containers.
You can start these images directly with `docker run` with this command:
您可以使用 `docker run` 命令直接启动镜像,如下:
```bash
docker run --name rustdesk-server \
--net=host \
-e "RELAY=rustdeskrelay.example.com" \
-e "ENCRYPTED_ONLY=1" \
-v "$PWD/data:/data" -d rustdesk/rustdesk-server-s6:latest
-v "$PWD/data:/data" -d lejianwen/rustdesk-server-s6:latest
```
or without `--net=host`, but P2P direct connection cannot work.
或刪去 `--net=host` 参数, 但 P2P 直连功能将无法工作。
```bash
docker run --name rustdesk-server \
@@ -163,10 +221,10 @@ docker run --name rustdesk-server \
-p 21117:21117 -p 21118:21118 -p 21119:21119 \
-e "RELAY=rustdeskrelay.example.com" \
-e "ENCRYPTED_ONLY=1" \
-v "$PWD/data:/data" -d rustdesk/rustdesk-server-s6:latest
-v "$PWD/data:/data" -d lejianwen/rustdesk-server-s6:latest
```
Or you can use a docker-compose file:
或着您也可以使用 docker-compose 文件:
```yaml
version: '3'
@@ -175,13 +233,14 @@ services:
rustdesk-server:
container_name: rustdesk-server
ports:
- 21114:21114
- 21115:21115
- 21116:21116
- 21116:21116/udp
- 21117:21117
- 21118:21118
- 21119:21119
image: rustdesk/rustdesk-server-s6:latest
image: lejianwen/rustdesk-server-s6:latest
environment:
- "RELAY=rustdesk.example.com:21117"
- "ENCRYPTED_ONLY=1"
@@ -190,26 +249,26 @@ services:
restart: unless-stopped
```
For this container image, you can use these environment variables, **in addition** to the ones specified in the following **ENV variables** section:
对于此容器镜像,除了在下面的环境变量部分指定的变量之外,您还可以使用以下`环境变量`
| variable | optional | description |
| --- | --- | --- |
| RELAY | no | the IP address/DNS name of the machine running this container |
| ENCRYPTED_ONLY | yes | if set to **"1"** unencrypted connection will not be accepted |
| KEY_PUB | yes | public part of the key pair |
| KEY_PRIV | yes | private part of the key pair |
| 环境变量 | 是否可选 | 描述 |
|----------------|------|--------------------------|
| RELAY | 否 | 运行此容器的宿主机的 IP 地址/ DNS 名称 |
| ENCRYPTED_ONLY | 是 | 如果设置为 **"1"**,将不接受未加密的连接。 |
| KEY_PUB | 是 | 密钥对中的公钥(Public Key) |
| KEY_PRIV | 是 | 密钥对中的私钥(Private Key) |
### Secret management in S6-overlay based images
### 基于 S6-overlay 镜像的密钥管理
You can obviously keep the key pair in a docker volume, but the best practices tells you to not write the keys on the filesystem; so we provide a couple of options.
您可以将密钥对保存在 Docker volume 中,但我们建议不要将密钥写入文件系統中;因此,我们提供了一些方案。
On container startup, the presence of the keypair is checked (`/data/id_ed25519.pub` and `/data/id_ed25519`) and if one of these keys doesn't exist, it's recreated from ENV variables or docker secrets.
Then the validity of the keypair is checked: if public and private keys doesn't match, the container will stop.
If you provide no keys, `hbbs` will generate one for you, and it'll place it in the default location.
在容器启动时,会检查密钥对是否存在(`/data/id_ed25519.pub` 和 `/data/id_ed25519`),如果其中一個密钥不存在,则会从环境变量或 Docker Secret 中重新生成它。
然后检查密钥对的可用性:如果公钥和私钥不匹配,容器将停止运行。
如果您未提供密钥,`hbbs` 将会在默认位置生成一个。
#### Use ENV to store the key pair
#### 使用 ENV 存储密钥对
You can use docker environment variables to store the keys. Just follow this examples:
您可以使用 Docker 环境变量來存储密钥。如下:
```bash
docker run --name rustdesk-server \
@@ -219,7 +278,7 @@ docker run --name rustdesk-server \
-e "DB_URL=/db/db_v2.sqlite3" \
-e "KEY_PRIV=FR2j78IxfwJNR+HjLluQ2Nh7eEryEeIZCwiQDPVe+PaITKyShphHAsPLn7So0OqRs92nGvSRdFJnE2MSyrKTIQ==" \
-e "KEY_PUB=iEyskoaYRwLDy5+0qNDqkbPdpxr0kXRSZxNjEsqykyE=" \
-v "$PWD/db:/db" -d rustdesk/rustdesk-server-s6:latest
-v "$PWD/db:/db" -d lejianwen/rustdesk-server-s6:latest
```
```yaml
@@ -229,13 +288,14 @@ services:
rustdesk-server:
container_name: rustdesk-server
ports:
- 21114:21114
- 21115:21115
- 21116:21116
- 21116:21116/udp
- 21117:21117
- 21118:21118
- 21119:21119
image: rustdesk/rustdesk-server-s6:latest
image: lejianwen/rustdesk-server-s6:latest
environment:
- "RELAY=rustdesk.example.com:21117"
- "ENCRYPTED_ONLY=1"
@@ -247,11 +307,11 @@ services:
restart: unless-stopped
```
#### Use Docker secrets to store the key pair
#### 使用 Docker Secret 來保存密钥对
You can alternatively use docker secrets to store the keys.
This is useful if you're using **docker-compose** or **Docker Swarm**.
Just follow this examples:
您还可以使用 Docker Secret 來保存密钥。
如果您使用 **docker-compose** 或 **docker swarm**,推荐您使用。
只需按照以下示例操作:
```bash
cat secrets/id_ed25519.pub | docker secret create key_pub -
@@ -263,7 +323,7 @@ docker service create --name rustdesk-server \
-e "ENCRYPTED_ONLY=1" \
-e "DB_URL=/db/db_v2.sqlite3" \
--mount "type=bind,source=$PWD/db,destination=/db" \
rustdesk/rustdesk-server-s6:latest
lejianwen/rustdesk-server-s6:latest
```
```yaml
@@ -273,13 +333,14 @@ services:
rustdesk-server:
container_name: rustdesk-server
ports:
- 21114:21114
- 21115:21115
- 21116:21116
- 21116:21116/udp
- 21117:21117
- 21118:21118
- 21119:21119
image: rustdesk/rustdesk-server-s6:latest
image: lejianwen/rustdesk-server-s6:latest
environment:
- "RELAY=rustdesk.example.com:21117"
- "ENCRYPTED_ONLY=1"
@@ -298,57 +359,55 @@ secrets:
file: secrets/id_ed25519
```
## How to create a keypair
## 如何生成密钥对
A keypair is needed for encryption; you can provide it, as explained before, but you need a way to create one.
加密需要一对密钥;您可以按照前面所述提供它,但需要一个工具去生成密钥对。
You can use this command to generate a keypair:
您可以使用以下命令生成一对密钥:
```bash
/usr/bin/rustdesk-utils genkeypair
```
If you don't have (or don't want) the `rustdesk-utils` package installed on your system, you can invoke the same command with docker:
如果您沒有(或不想)在系统上安装 `rustdesk-utils` 套件,您可以使用 Docker 执行相同的命令:
```bash
docker run --rm --entrypoint /usr/bin/rustdesk-utils rustdesk/rustdesk-server-s6:latest genkeypair
docker run --rm --entrypoint /usr/bin/rustdesk-utils lejianwen/rustdesk-server-s6:latest genkeypair
```
The output will be something like this:
运行后的输出内容如下:
```text
Public Key: 8BLLhtzUBU/XKAH4mep3p+IX4DSApe7qbAwNH9nv4yA=
Secret Key: egAVd44u33ZEUIDTtksGcHeVeAwywarEdHmf99KM5ajwEsuG3NQFT9coAfiZ6nen4hfgNICl7upsDA0f2e/jIA==
```
## .deb packages
## .deb 套件
Separate .deb packages are available for each binary, you can find them in the [Releases](https://github.com/rustdesk/rustdesk-server/releases).
These packages are meant for the following distributions:
每个可执行文件都有单独的 .deb 套件可供使用,您可以在 [releases](https://github.com/lejianwen/rustdesk-server/releases) 页面中找到它們。
這些套件适用于以下发行版:
- Ubuntu 24.04 LTS
- Ubuntu 22.04 LTS
- Ubuntu 20.04 LTS
- Ubuntu 18.04 LTS
- Debian 12 bookworm
- Debian 11 bullseye
- Debian 10 buster
## ENV variables
## ENV 环境变量
`hbbs` and `hbbr` can be configured using these ENV variables.
You can specify the variables as usual or use an `.env` file.
可以使用这些`环境变量`参数來配置 hbbs 和 hbbr。
您可以像往常一样指定参数,或者使用 .env 文件。
| variable | binary | description |
| --- | --- | --- |
| ALWAYS_USE_RELAY | hbbs | if set to **"Y"** disallows direct peer connection |
| DB_URL | hbbs | path for database file |
| DOWNGRADE_START_CHECK | hbbr | delay (in seconds) before downgrade check |
| DOWNGRADE_THRESHOLD | hbbr | threshold of downgrade check (bit/ms) |
| KEY | hbbs/hbbr | if set force the use of a specific key, if set to **"_"** force the use of any key |
| LIMIT_SPEED | hbbr | speed limit (in Mb/s) |
| PORT | hbbs/hbbr | listening port (21116 for hbbs - 21117 for hbbr) |
| RELAY | hbbs | IP address/DNS name of the machines running hbbr (separated by comma) |
| RUST_LOG | all | set debug level (error\|warn\|info\|debug\|trace) |
| SINGLE_BANDWIDTH | hbbr | max bandwidth for a single connection (in Mb/s) |
| TOTAL_BANDWIDTH | hbbr | max total bandwidth (in Mb/s) |
| 参数 | 可执行文件 | 描述 |
|-----------------------|---------------|--------------------------------------------------|
| ALWAYS_USE_RELAY | hbbs | 如果设定为 **"Y"**,将关闭直接点对点连接功能 |
| DB_URL | hbbs | 数据库配置 |
| DOWNGRADE_START_CHECK | hbbr | 降级检查之前的延迟是啊尽(以秒为单位) |
| DOWNGRADE_THRESHOLD | hbbr | 降级检查的阈值(bit/ms) |
| KEY | hbbs/hbbr | 如果设置了此参数,将强制使用指定密钥对,如果设为 **"_"**,则强制使用任意密钥 |
| LIMIT_SPEED | hbbr | 速度限制(以Mb/s为单位) |
| PORT | hbbs/hbbr | 监听端口(hbbs为21116,hbbr为21117) |
| RELAY_SERVERS | hbbs | 运行hbbr的机器的IP地址/DNS名称(用逗号分隔) |
| RUST_LOG | all | 设置 debug level (error\|warn\|info\|debug\|trace) |
| SINGLE_BANDWIDTH | hbbr | 单个连接的最大带宽(以Mb/s为单位) |
| TOTAL_BANDWIDTH | hbbr | 最大总带宽(以Mb/s为单位) |
+5
View File
@@ -1,3 +1,8 @@
rustdesk-server (1.1.14) UNRELEASED; urgency=medium
* add KeyExchange
* fix ws query online
* add Must Login
rustdesk-server (1.1.13) UNRELEASED; urgency=medium
* Version check and refactor hbb_common to share with rustdesk client
+16 -23
View File
@@ -1,36 +1,29 @@
version: '3'
networks:
rustdesk-net:
external: false
services:
hbbs:
container_name: hbbs
rustdesk:
ports:
- 21114:21114
- 21115:21115
- 21116:21116
- 21116:21116/udp
- 21118:21118
image: rustdesk/rustdesk-server:latest
command: hbbs -r rustdesk.example.com:21117
volumes:
- ./data:/root
networks:
- rustdesk-net
depends_on:
- hbbr
restart: unless-stopped
hbbr:
container_name: hbbr
ports:
- 21117:21117
- 21118:21118
- 21119:21119
image: rustdesk/rustdesk-server:latest
command: hbbr
image: lejianwen/rustdesk-server-s6:latest
environment:
- RELAY=<relay_server[:port]>
- ENCRYPTED_ONLY=1
- MUST_LOGIN=N
- TZ=Asia/Shanghai
- RUSTDESK_API_RUSTDESK_ID_SERVER=<id_server[:21116]>
- RUSTDESK_API_RUSTDESK_RELAY_SERVER=<relay_server[:21117]>
- RUSTDESK_API_RUSTDESK_API_SERVER=http://<api_server[:21114]>
volumes:
- ./data:/root
- /data/rustdesk/server:/data
- /data/rustdesk/api:/app/data #将数据库挂载
- /data/rustdesk/server:/app/conf/data #挂载key文件到api容器,可以不用使用 RUSTDESK_API_RUSTDESK_KEY
networks:
- rustdesk-net
restart: unless-stopped
restart: unless-stopped
+3 -2
View File
@@ -1,4 +1,4 @@
FROM busybox:stable
FROM lejianwen/rustdesk-api:latest
ARG S6_OVERLAY_VERSION=3.2.0.0
ARG S6_ARCH=x86_64
@@ -15,11 +15,12 @@ COPY rootfs /
ENV RELAY=relay.example.com
ENV ENCRYPTED_ONLY=0
EXPOSE 21115 21116 21116/udp 21117 21118 21119
EXPOSE 21114 21115 21116 21116/udp 21117 21118 21119
HEALTHCHECK --interval=10s --timeout=5s CMD /usr/bin/healthcheck.sh
WORKDIR /data
VOLUME /app/data
VOLUME /data
@@ -0,0 +1,2 @@
key-secret
hbbs
@@ -0,0 +1,4 @@
#!/command/with-contenv sh
sleep 3
cd /app
./apimain
@@ -0,0 +1 @@
longrun
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

+54
View File
@@ -0,0 +1,54 @@
use jsonwebtoken::{decode, encode, Algorithm, DecodingKey, EncodingKey, Header, Validation};
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
use std::env;
pub static SECRET: Lazy<String> =
Lazy::new(|| env::var("RUSTDESK_API_JWT_KEY").unwrap_or_else(|_| "".to_string()));
// 定义一个结构体来表示 JWT 的 payload
#[derive(Debug, Serialize, Deserialize)]
pub struct Claims {
user_id: u32,
exp: usize,
}
pub fn generate_token(user_id: u32, exp: i64) -> Result<String, String> {
println!("secret: {:}", SECRET.to_string());
let claims = Claims {
user_id,
exp: (chrono::Utc::now() + chrono::Duration::seconds(exp)).timestamp() as usize,
};
let token = encode(
&Header::default(),
&claims,
&EncodingKey::from_secret(SECRET.as_ref()),
);
match token {
Ok(t) => Ok(t),
Err(e) => Err(e.to_string()),
}
}
// 验证 JWT 的函数
pub fn verify_token(token: &str) -> Result<Claims, String> {
// 解码 JWT
let validation = Validation::new(Algorithm::HS256);
let decoded = decode::<Claims>(
&token,
&DecodingKey::from_secret(SECRET.as_ref()),
&validation,
);
match decoded {
Ok(token_data) => {
let now = chrono::Utc::now().timestamp() as usize;
if token_data.claims.exp > now {
Ok(token_data.claims)
} else {
Err("Token status invalid or expired".to_string())
}
}
Err(_) => Err("Invalid token".to_string()),
}
}
+1
View File
@@ -4,3 +4,4 @@ pub mod common;
mod database;
mod peer;
mod version;
pub mod jwt;
+2 -1
View File
@@ -22,7 +22,8 @@ fn main() -> ResultType<()> {
-r, --relay-servers=[HOST] 'Sets the default relay servers, separated by comma'
-M, --rmem=[NUMBER(default={RMEM})] 'Sets UDP recv buffer size, set system rmem_max first, e.g., sudo sysctl -w net.core.rmem_max=52428800. vi /etc/sysctl.conf, net.core.rmem_max=52428800, sudo sysctl –p'
, --mask=[MASK] 'Determine if the connection comes from LAN, e.g. 192.168.0.0/16'
-k, --key=[KEY] 'Only allow the client with the same key'",
-k, --key=[KEY] 'Only allow the client with the same key'
, --must-login=[Y|N] 'Only allow the client with login'",
);
init_args(&args, "hbbs", "RustDesk ID/Rendezvous Server");
let port = get_arg_or("port", RENDEZVOUS_PORT.to_string()).parse::<i32>()?;
+207 -13
View File
@@ -1,5 +1,6 @@
use crate::common::*;
use crate::peer::*;
use hbb_common::bytes::BufMut;
use hbb_common::{
allow_err, bail,
bytes::{Bytes, BytesMut},
@@ -13,9 +14,15 @@ use hbb_common::{
log,
protobuf::{Message as _, MessageField},
rendezvous_proto::{
register_pk_response::Result::{TOO_FREQUENT, UUID_MISMATCH},
register_pk_response::Result::{INVALID_ID_FORMAT, TOO_FREQUENT, UUID_MISMATCH},
*,
},
sodiumoxide::crypto::{
box_, box_::PublicKey, box_::SecretKey, secretbox, secretbox::Key, secretbox::Nonce, sign,
},
sodiumoxide::hex,
tcp,
tcp::Encrypt,
tcp::{listen_any, FramedStream},
timeout,
tokio::{
@@ -31,7 +38,7 @@ use hbb_common::{
AddrMangle, ResultType,
};
use ipnetwork::Ipv4Network;
use sodiumoxide::crypto::sign;
use std::{
collections::HashMap,
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr},
@@ -39,6 +46,7 @@ use std::{
sync::Arc,
time::Instant,
};
use crate::jwt;
#[derive(Clone, Debug)]
enum Data {
@@ -50,16 +58,21 @@ enum Data {
const REG_TIMEOUT: i32 = 30_000;
type TcpStreamSink = SplitSink<Framed<TcpStream, BytesCodec>, Bytes>;
type WsSink = SplitSink<tokio_tungstenite::WebSocketStream<TcpStream>, tungstenite::Message>;
enum Sink {
enum SinkType {
TcpStream(TcpStreamSink),
Ws(WsSink),
}
struct Sink {
tx: SinkType,
key: Arc<Mutex<Option<Encrypt>>>,
}
type Sender = mpsc::UnboundedSender<Data>;
type Receiver = mpsc::UnboundedReceiver<Data>;
static ROTATION_RELAY_SERVER: AtomicUsize = AtomicUsize::new(0);
type RelayServers = Vec<String>;
const CHECK_RELAY_TIMEOUT: u64 = 3_000;
static ALWAYS_USE_RELAY: AtomicBool = AtomicBool::new(false);
static MUST_LOGIN: AtomicBool = AtomicBool::new(false);
#[derive(Clone)]
struct Inner {
@@ -69,6 +82,8 @@ struct Inner {
mask: Option<Ipv4Network>,
local_ip: String,
sk: Option<sign::SecretKey>,
secure_tcp_pk_b: PublicKey,
secure_tcp_sk_b: SecretKey,
}
#[derive(Clone)]
@@ -119,6 +134,8 @@ impl RendezvousServer {
.unwrap_or_default(),
)
};
// For privacy use per connection key pair
let (secure_tcp_pk_b, secure_tcp_sk_b) = box_::gen_keypair();
let mut rs = Self {
tcp_punch: Arc::new(Mutex::new(HashMap::new())),
pm,
@@ -133,6 +150,8 @@ impl RendezvousServer {
sk,
mask,
local_ip,
secure_tcp_pk_b,
secure_tcp_sk_b,
}),
};
log::info!("mask: {:?}", rs.inner.mask);
@@ -158,6 +177,25 @@ impl RendezvousServer {
"N"
}
);
let must_login = get_arg("must-login");
log::debug!("must_login={}", must_login);
if must_login.to_uppercase() == "Y" ||
(must_login == "" && std::env::var("MUST_LOGIN")
.unwrap_or_default()
.to_uppercase()
== "Y") {
MUST_LOGIN.store(true, Ordering::SeqCst);
}
log::info!(
"MUST_LOGIN={}",
if MUST_LOGIN.load(Ordering::SeqCst) {
"Y"
} else {
"N"
}
);
if test_addr.to_lowercase() != "no" {
let test_addr = if test_addr.is_empty() {
listener.local_addr()?
@@ -554,6 +592,58 @@ impl RendezvousServer {
});
Self::send_to_sink(sink, msg_out).await;
}
Some(rendezvous_message::Union::KeyExchange(ex)) => {
log::trace!("KeyExchange {:?} <- bytes: {:?}", addr, hex::encode(&bytes));
if ex.keys.len() != 2 {
log::error!("Handshake failed: invalid phase 2 key exchange message");
return false;
}
log::trace!("KeyExchange their_pk: {:?}", hex::encode(&ex.keys[0]));
log::trace!("KeyExchange box: {:?}", hex::encode(&ex.keys[1]));
let their_pk: [u8; 32] = ex.keys[0].to_vec().try_into().unwrap();
let cryptobox: [u8; 48] = ex.keys[1].to_vec().try_into().unwrap();
let symetric_key = get_symetric_key_from_msg(
self.inner.secure_tcp_sk_b.0,
their_pk,
&cryptobox,
);
log::debug!("KeyExchange symetric key: {:?}", hex::encode(&symetric_key));
let key = secretbox::Key::from_slice(&symetric_key);
match key {
Some(key) => {
if let Some(sink) = sink.as_mut() {
sink.key.lock().await.replace(Encrypt::new(key));
}
log::debug!("KeyExchange symetric key set");
return true;
}
None => {
log::error!("KeyExchange symetric key NOT set");
return false;
}
}
}
Some(rendezvous_message::Union::OnlineRequest(or)) => {
let mut states = BytesMut::zeroed((or.peers.len() + 7) / 8);
for (i, peer_id) in or.peers.iter().enumerate() {
if let Some(peer) = self.pm.get_in_memory(peer_id).await {
let elapsed = peer.read().await.last_reg_time.elapsed().as_millis() as i32;
// bytes index from left to right
let states_idx = i / 8;
let bit_idx = 7 - i % 8;
if elapsed < REG_TIMEOUT {
states[states_idx] |= 0x01 << bit_idx;
}
}
}
let mut msg_out = RendezvousMessage::new();
msg_out.set_online_response(OnlineResponse {
states: states.into(),
..Default::default()
});
Self::send_to_sink(sink, msg_out).await;
}
_ => {}
}
}
@@ -687,6 +777,29 @@ impl RendezvousServer {
});
return Ok((msg_out, None));
}
// if secret is not empty check token by jwt
if MUST_LOGIN.load(Ordering::SeqCst) {
if ph.token.is_empty() {
let mut msg_out = RendezvousMessage::new();
msg_out.set_punch_hole_response(PunchHoleResponse {
other_failure: String::from("Connection failed, please login!"),
..Default::default()
});
return Ok((msg_out, None));
} else if !jwt::SECRET.is_empty() {
let token = ph.token;
let token = jwt::verify_token(token.as_str());
if token.is_err() {
let mut msg_out = RendezvousMessage::new();
msg_out.set_punch_hole_response(PunchHoleResponse {
//提示重新登录
other_failure: String::from("Token error, please log out and log back in!"),
..Default::default()
});
return Ok((msg_out, None));
}
}
}
let id = ph.id;
// punch hole request from A, relay to B,
// check if in same intranet first,
@@ -803,12 +916,15 @@ impl RendezvousServer {
#[inline]
async fn send_to_sink(sink: &mut Option<Sink>, msg: RendezvousMessage) {
if let Some(sink) = sink.as_mut() {
if let Ok(bytes) = msg.write_to_bytes() {
match sink {
Sink::TcpStream(s) => {
if let Ok(mut bytes) = msg.write_to_bytes() {
if let Some(enc) = &mut sink.key.lock().await.as_mut() {
bytes = enc.enc(&bytes);
}
match &mut sink.tx {
SinkType::TcpStream(s) => {
allow_err!(s.send(Bytes::from(bytes)).await);
}
Sink::Ws(ws) => {
SinkType::Ws(ws) => {
allow_err!(ws.send(tungstenite::Message::Binary(bytes)).await);
}
}
@@ -916,13 +1032,14 @@ impl RendezvousServer {
match fds.next() {
Some("h") => {
res = format!(
"{}\n{}\n{}\n{}\n{}\n{}\n",
"{}\n{}\n{}\n{}\n{}\n{}\n{}\n",
"relay-servers(rs) <separated by ,>",
"reload-geo(rg)",
"ip-blocker(ib) [<ip>|<number>] [-]",
"ip-changes(ic) [<id>|<number>] [-]",
"always-use-relay(aur)",
"test-geo(tg) <ip1> <ip2>"
"always-use-relay(aur) [Y|N]",
"test-geo(tg) <ip1> <ip2>",
"must-login(ml) [Y|N]",
)
}
Some("relay-servers" | "rs") => {
@@ -1049,6 +1166,21 @@ impl RendezvousServer {
}
}
}
Some("must-login" | "ml") => {
if let Some(rs) = fds.next() {
if rs.to_uppercase() == "Y" {
MUST_LOGIN.store(true, Ordering::SeqCst);
} else {
MUST_LOGIN.store(false, Ordering::SeqCst);
}
} else {
let _ = writeln!(
res,
"MUST_LOGIN: {:?}",
MUST_LOGIN.load(Ordering::SeqCst)
);
}
}
_ => {}
}
res
@@ -1130,7 +1262,10 @@ impl RendezvousServer {
};
let ws_stream = tokio_tungstenite::accept_hdr_async(stream, callback).await?;
let (a, mut b) = ws_stream.split();
sink = Some(Sink::Ws(a));
sink = Some(Sink {
tx: SinkType::Ws(a),
key: Arc::new(Mutex::new(None)),
});
while let Ok(Some(Ok(msg))) = timeout(30_000, b.next()).await {
if let tungstenite::Message::Binary(bytes) = msg {
if !self.handle_tcp(&bytes, &mut sink, addr, key, ws).await {
@@ -1140,8 +1275,23 @@ impl RendezvousServer {
}
} else {
let (a, mut b) = Framed::new(stream, BytesCodec::new()).split();
sink = Some(Sink::TcpStream(a));
while let Ok(Some(Ok(bytes))) = timeout(30_000, b.next()).await {
let enc = Arc::new(Mutex::new(None));
sink = Some(Sink {
tx: SinkType::TcpStream(a),
key: enc.clone(),
});
// Avoid key exchange if answering on nat helper port
if !key.is_empty() {
self.key_exchange_phase1(addr, &mut sink).await;
}
while let Ok(Some(Ok(mut bytes))) = timeout(30_000, b.next()).await {
let mut enc_lock = enc.lock().await;
if enc_lock.is_some() {
if let Err(err) = enc_lock.as_mut().unwrap().dec(&mut bytes) {
return Err(err.into());
}
}
drop(enc_lock);
if !self.handle_tcp(&bytes, &mut sink, addr, key, ws).await {
break;
}
@@ -1224,6 +1374,31 @@ impl RendezvousServer {
}
false
}
async fn key_exchange_phase1(&mut self, addr: SocketAddr, sink: &mut Option<Sink>) {
let mut msg_out = RendezvousMessage::new();
log::debug!("KeyExchange phase 1: send our pk for this tcp connection in a message signed with our server key");
let sk = &self.inner.sk;
match sk {
Some(sk) => {
let our_pk_b = self.inner.secure_tcp_pk_b.clone();
let sm = sign::sign(&our_pk_b.0, &sk);
let bytes_sm = Bytes::from(sm);
msg_out.set_key_exchange(KeyExchange {
keys: vec![bytes_sm],
..Default::default()
});
log::trace!(
"KeyExchange {:?} -> bytes: {:?}",
addr,
hex::encode(Bytes::from(msg_out.write_to_bytes().unwrap()))
);
Self::send_to_sink(sink, msg_out).await;
}
None => {}
}
}
}
async fn check_relay_servers(rs0: Arc<RelayServers>, tx: Sender) {
@@ -1323,3 +1498,22 @@ async fn create_tcp_listener(port: i32) -> ResultType<TcpListener> {
log::debug!("listen on tcp {:?}", s.local_addr());
Ok(s)
}
fn get_symetric_key_from_msg(
our_sk_b: [u8; 32],
their_pk_b: [u8; 32],
sealed_value: &[u8; 48],
) -> [u8; 32] {
let their_pk_b = box_::PublicKey(their_pk_b);
let nonce = box_::Nonce([0u8; box_::NONCEBYTES]);
let sk = box_::SecretKey(our_sk_b);
let key = box_::open(sealed_value, &nonce, &their_pk_b, &sk);
match key {
Ok(key) => {
let mut key_array = [0u8; 32];
key_array.copy_from_slice(&key);
key_array
}
Err(e) => panic!("Error while opening the seal key{:?}", e),
}
}
+24
View File
@@ -0,0 +1,24 @@
use hbb_common::tokio;
use hbbs::jwt;
#[test]
fn test_generate_token() {
std::env::set_var("RUSTDESK_API_JWT_KEY", "testjwt");
let token = jwt::generate_token(1, 3600).unwrap();
println!("Generated Token: {}", token);
assert!(!token.is_empty(), "Generated token should not be empty");
}
#[tokio::test]
async fn test_verify_token() {
std::env::set_var("RUSTDESK_API_JWT_KEY", "testjwt");
let token = jwt::generate_token(1, 2).unwrap();
// let token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJleHAiOjE3MzY4NzA4NjF9.u5pxmwNMrYUwtkspF1FuZj-R5ANAR9WT9_dMHuQhV0Y";
println!("Token : {:?}, now: {:?}", token, chrono::Utc::now().timestamp());
// hbb_common::sleep(3f32).await;
// println!("Token : {:?}, now: {:?}", token, chrono::Utc::now().timestamp());
let result = jwt::verify_token(&token);
println!("Token Verification Result: {:?}", result);
assert!(result.is_ok(), "Token should be valid");
}
+1 -1
View File
@@ -15,7 +15,7 @@
!define PRODUCT_NAME "rustdesk_server"
!define PRODUCT_DESCRIPTION "Installer for ${PRODUCT_NAME}"
!define COPYRIGHT "Copyright © 2021"
!define VERSION "1.1.13"
!define VERSION "1.1.14"
VIProductVersion "${VERSION}.0"
VIAddVersionKey "ProductName" "${PRODUCT_NAME}"