Hosting your own SMP Server#
| Updated 12.10.2024 | Languages: EN, FR, CZ, PL |
Table of Contents#
- Overview
- Quick start with systemd service
- Installation options
- Verifying server binaries
- Configuration
- Further configuration
- Server security
- Tor: installation and configuration
- Server information page
- Documentation
- Reproduce builds
- Updating your SMP server
- Configuring the app to use the server
Overview#
SMP server is the relay server used to pass messages in SimpleX network. SimpleX Chat apps have preset servers (for mobile apps these are smp11, smp12 and smp14.simplex.im), but you can easily change app configuration to use other servers.
SimpleX clients only determine which server is used to receive the messages, separately for each contact (or group connection with a group member), and these servers are only temporary, as the delivery address can change.
To create SMP server, you'll need:
- VPS or any other server.
- Your own domain, pointed at the server (
smp.example.com
) - A basic Linux knowledge.
Please note: when you change the servers in the app configuration, it only affects which servers will be used for the new contacts, the existing contacts will not automatically move to the new servers, but you can move them manually using "Change receiving address" button in contact/member information pages – it will be automated in the future.
Quick start#
To create SMP server as a systemd service, you'll need:
- VPS or any other server.
- Your server domain, with A and AAAA records specifying server IPv4 and IPv6 addresses (
smp1.example.com
) - A basic Linux knowledge.
Please note: while you can run an SMP server without a domain name, in the near future client applications will start using server domain name in the invitation links (instead of simplex.chat
domain they use now). In case a server does not have domain name and server pages (see below), the clients will be generaing the links with simplex:
scheme that cannot be opened in the browsers.
-
Install server with Installation script.
-
Adjust firewall:
-
Init server:
Replace
smp1.example.com
with your actual server domain. -
Install tor:
-
Configure tor:
Paste the following:
Paste the following:
-
Start tor:
-
Install Caddy:
-
Configure Caddy:
Replace
smp1.example.com
with your actual server domain. Paste the following:http://smp1.example.com { redir https://smp1.example.com{uri} permanent } smp1.example.com:8443 { tls { key_type rsa4096 } }
Replace
smp1.example.com
with your actual server domain. Paste the following:Paste the following:
-
Enable and start Caddy service:
Wait until "good to go" has been printed.
-
Enable and start smp-server:
-
Print your address:
Installation options#
You can install SMP server in one of the following ways:
- systemd service
- using installation script - recommended
- or manually
- Docker container from DockerHub
- Linode marketplace
systemd service
Installation script
This installation script will automatically install binaries, systemd services and additional scripts that will manage backups, updates and uninstallation. This is the recommended option due to its flexibility, easy updating, and being battle tested on our servers.
Please note that currently only Ubuntu distribution is supported.
Run the following script on the server:
Type 1
and hit enter to install smp-server
.
Manual deployment
Manual installation is the most advanced deployment that provides the most flexibility. Generally recommended only for advanced users.
-
Install binary:
-
Using pre-compiled binaries:
-
Compiling from source:
Please refer to Build from source: Using your distribution
-
-
Create user and group for
smp-server
: -
Create necessary directories and assign permissions:
-
Allow
smp-server
port in firewall: -
Optional — If you're using distribution with
systemd
, create/etc/systemd/system/smp-server.service
file with the following content:And execute
sudo systemctl daemon-reload
.
Docker container
You can deploy smp-server using Docker Compose. This is second recommended option due to its popularity and relatively easy deployment.
This deployment provides two Docker Compose files: the automatic one and manual. If you're not sure, choose automatic.
This will download images from Docker Hub.
Docker: Automatic setup
This configuration provides quick and easy way to setup your SMP server: Caddy will automatically manage Let's Encrypt certificates and redirect HTTP to HTTPS, while smp-server will serve both server information page and SMP Protocol by 443 port. 5223 port is used as fallback.
Please note that you must have 80
and 443
ports unallocated by other servers.
- Create
smp-server
directory and switch to it:
- Create
docker-compose.yml
file with the following content:
You can also grab it from here - docker-compose-smp-complete.yml. Don't forget to rename it to docker-compose.yml
.
- In the same directory, create
.env
file with the following content:
You can also grab it from here - docker-compose-smp-complete.env. Don't forget to rename it to .env
.
Change variables according to your preferences.
- Start your containers:
Docker: Manual setup
If you know what you are doing, this configuration provides bare SMP server setup without automatically managed Let's Encrypt certificates by Caddy to serve server information page with 5223 port set as primary.
This configuration allows you to retain the ability to manage 80 and 443 ports yourself. As a downside, SMP server *can not be served to 443 port.
- Create
smp-server
directory and switch to it:
- Create
docker-compose.yml
file with the following content:
You can also grab it from here - docker-compose-smp-manual.yml. Don't forget to rename it to docker-compose.yml
.
- In the same directory, create
.env
file with the following content:
You can also grab it from here - docker-compose-smp-manual.env. Don't forget to rename it to .env
.
Change variables according to your preferences.
- Start your containers:
Linode marketplace
You can deploy smp-server upon creating new Linode VM. Please refer to: Linode Marketplace
Verifying server binaries#
Starting from v6.3 server builds are reproducible.
That also allows us to sign server releases, confirming the integrity of GitHub builds.
To verify server binaries after you downloaded them:
-
Download
_sha256sums
(hashes of all server binaries) and_sha256sums.asc
(signature). -
Download our key FB44AF81A45BDE327319797C85107E357D4A17FC from openpgp.org
-
Import the key with
gpg --import FB44AF81A45BDE327319797C85107E357D4A17FC
. Key filename should be the same as its fingerprint, but please change it if necessary. -
Run
gpg --verify --trusted-key _sha256sums.asc _sha256sums
. It should print:
Good signature from "SimpleX Chat chat@simplex.chat"
- Compute the hashes of the binaries you plan to use with
shu256sum <file>
or withopenssl sha256 <file>
and compare them with the hashes in the file_sha256sums
- they must be the same.
That is it - you now verified authenticity of our GitHub server binaries.
Configuration#
To see which options are available, execute smp-server
without flags:
You can get further help by executing sudo su smp -c "smp-server <command> -h"
After that, we need to configure smp-server
:
Interactively
Execute the following command:
There are several options to consider:
-
Enable store log to restore queues and messages on server restart (Yn):
Enter
y
to enable saving and restoring connections and messages when the server is restarted.Please note: it is important to use SIGINT to restart the server, as otherwise the undelivered messages will not be restored. The connections will be restored irrespective of how the server is restarted, as unlike messages they are added to append-only log on every change.
-
Enable logging daily statistics (yN):
Enter
y
to enable logging statistics in CSV format, e.g. they can be used to show aggregate usage charts inGrafana
.
These statistics include daily counts of created, secured and deleted queues, sent and received messages, and also daily, weekly, and monthly counts of active queues (that is, the queues that were used for any messages). We believe that this information does not include anything that would allow correlating different queues as belonging to the same users, but please let us know, confidentially, if you believe that this can be exploited in any way.
-
Require a password to create new messaging queues?
Press
Enter
or enter your arbitrary password to password-protectsmp-server
, orn
to disable password protection. -
Enter server FQDN or IP address for certificate (127.0.0.1):
Enter your domain or ip address that your smp-server is running on - it will be included in server certificates and also printed as part of server address.
Via command line options
Execute the following command:
You should determine which flags are needed for your use-case and then execute smp-server init
with -y
flag for non-interactive initialization:
For example, run:
to initialize your smp-server
configuration with:
- restoring connections and messages when the server is restarted (
-l
flag), - IP address
192.168.1.5
, - protect
smp-server
with a passwordtest
.
After that, your installation is complete and you should see in your teminal output something like this:
The server address above should be used in your client configuration, and if you added server password it should only be shared with the other people who you want to allow using your server to receive the messages (all your contacts will be able to send messages - it does not require a password). If you passed IP address or hostnames during the initialisation, they will be printed as part of server address, otherwise replace <hostnames>
with the actual server hostnames.
Further configuration#
All generated configuration, along with a description for each parameter, is available inside configuration file in /etc/opt/simplex/smp-server.ini
for further customization. Depending on the smp-server version, the configuration file looks something like this:
Server security#
Initialization
Although it's convenient to initialize smp-server configuration directly on the server, operators ARE ADVISED to initialize smp-server fully offline to protect your SMP server CA private key.
Follow the steps to quickly initialize the server offline:
-
Install Docker on your system.
-
Deploy smp-server locally.
-
Destroy the container. All relevant configuration files and keys will be available at
$HOME/simplex/smp/config
. -
Move your
CA
private key (ca.key
) to the safe place. For further explanation, see the next section: Server security: Private keys. -
Copy all other configuration files except the CA key to the server:
Private keys
Connection to the smp server occurs via a TLS connection. During the TLS handshake, the client verifies smp-server CA and server certificates by comparing its fingerprint with the one included in server address. If server TLS credential is compromised, this key can be used to sign a new one, keeping the same server identity and established connections. In order to protect your smp-server from bad actors, operators ARE ADVISED to move CA private key to a safe place. That could be:
- Tails live usb drive with persistent and encrypted storage.
- Offline Linux laptop.
- Bitwarden.
- Any other safe storage that satisfy your security requirements.
Follow the steps to secure your CA keys:
-
Login to your server via SSH.
-
Copy the CA key to a safe place from this file:
-
Delete the CA key from the server. Please make sure you've saved you CA key somewhere safe. Otherwise, you would lose the ability to rotate the online certificate:
Online certificate rotation
Operators of smp servers ARE ADVISED to rotate online certificate regularly (e.g., every 3 months). In order to do this, follow the steps:
-
Create relevant folders:
-
Copy the configuration files from the server to the local machine (if not yet):
-
Copy your CA private key from a safe place to the local machine and name it
ca.key
. -
Download latest
smp-server
binary from Github releases: -
Put the
smp-server
binary to your$PATH
and make it executable: -
Export a variable to configure your path to smp-server configuration:
-
Execute the following command:
This command should print:
-
Remove the CA key from the config folder (make sure you have a backup!):
-
Upload new certificates to the server:
-
Connect to the server via SSH and restart the service:
-
Done!
Tor: installation and configuration#
Installation for onion address
SMP-server can also be deployed to be available via Tor network. Run the following commands as root
user.
-
Install tor:
We're assuming you're using Ubuntu/Debian based distributions. If not, please refer to offical tor documentation or your distribution guide.
-
Configure offical Tor PPA repository:
-
Import repository key:
-
Update repository index:
-
Install
tor
package:
-
-
Configure tor:
-
File configuration:
Open tor configuration with your editor of choice (
nano
,vim
,emacs
,etc.):And insert the following lines to the bottom of configuration. Please note lines starting with
#
: this is comments about each individual options. -
Create directories:
-
-
Start tor:
Enable
systemd
service and start tor. Officaltor
is a bit flaky on the first start and may not create onion host address, so we're restarting it just in case. -
Display onion host:
Execute the following command to display your onion host address:
SOCKS port for SMP PROXY
SMP-server versions starting from v5.8.0-beta.0
can be configured to PROXY smp servers available exclusively through Tor network to be accessible to the clients that do not use Tor. Run the following commands as root
user.
-
Install tor as described in the previous section.
-
Execute the following command to creatae a new Tor daemon instance:
-
Open the
tor2
configuration and replace its content with the following lines: -
Enable service at startup and start the daemon:
You can check
tor2
logs with the following command: -
After server initialization, configure the
PROXY
section like so:
Server information page#
SMP server SHOULD be configured to serve Web page with server information that can include admin info, server info, provider info, etc. It will also serve connection links, generated using the mobile/desktop apps. Run the following commands as root
user.
Please note: this configuration is supported since v6.1.0-beta.2
.
-
Add the following to your smp-server configuration (please modify fields in [INFORMATION] section to include relevant information):
-
Install the webserver. For easy deployment we'll describe the installtion process of Caddy webserver on Ubuntu server:
-
Install the packages:
-
Install caddy gpg key for repository:
-
Install Caddy repository:
-
Install Caddy:
-
-
Replace Caddy configuration with the following:
Please replace
YOUR_DOMAIN
with your actual domain (smp.example.com).http://YOUR_DOMAIN { redir https://YOUR_DOMAIN{uri} permanent } YOUR_DOMAIN:8443 { tls { key_type rsa4096 } }
-
Enable and start Caddy service:
-
Create script to copy certificates to your smp directory:
Please replace
YOUR_DOMAIN
with your actual domain (smp.example.com). -
Make the script executable and execute it:
-
Check if certificates were copied:
-
Create cronjob to copy certificates to smp directory in timely manner:
-
Then:
- If you're running at least
v6.1.0-beta.2
, restart the server. - If you're running below
v6.1.0-beta.2
, upgrade the server.
- If you're running at least
-
Access the webpage you've deployed from your browser (
https://smp.example.org
). You should see the smp-server information that you've provided in your ini file.
Documentation#
All necessary files for smp-server
are located in /etc/opt/simplex/
folder.
Stored messages, connections, statistics and server log are located in /var/opt/simplex/
folder.
SMP server address
SMP server address has the following format:
smp://<fingerprint>[:<password>]@<public_hostname>[,<onion_hostname>]
-
<fingerprint>
Your
smp-server
fingerprint of certificate. You can check your certificate fingerprint in/etc/opt/simplex/fingerprint
. -
optional
<password>
Your configured password of
smp-server
. You can check your configured pasword in/etc/opt/simplex/smp-server.ini
, under[AUTH]
section increate_password:
field. -
<public_hostname>
, optional<onion_hostname>
Your configured hostname(s) of
smp-server
. You can check your configured hosts in/etc/opt/simplex/smp-server.ini
, under[TRANSPORT]
section inhost:
field.
Systemd commands
To start smp-server
on host boot, run:
To start smp-server
, run:
To check status of smp-server
, run:
To stop smp-server
, run:
To check tail of smp-server
log, run:
Control port
Enabling control port in the configuration allows administrator to see information about the smp-server in real-time. Additionally, it allows to delete queues for content moderation and see the debug info about the clients, sockets, etc. Enabling the control port requires setting the admin
and user
passwords.
-
Generate two passwords for each user:
-
Open the configuration file:
-
Configure the control port and replace the passwords:
-
Restart the server:
To access the control port, use:
or:
Upon connecting, the control port should print:
To authenticate, type the following and hit enter. Change the my_generated_password
with the user
or admin
password from the configuration:
Here's the full list of commands, their descriptions and who can access them.
Command | Description | Requires admin role |
---|---|---|
stats |
Real-time statistics. Fields described in Daily statistics | - |
stats-rts |
GHC/Haskell statistics. Can be enabled with +RTS -T -RTS option |
- |
clients |
Clients information. Useful for debugging. | yes |
sockets |
General sockets information. | - |
socket-threads |
Thread infomation per socket. Useful for debugging. | yes |
threads |
Threads information. Useful for debugging. | yes |
server-info |
Aggregated server infomation. | - |
delete |
Delete known queue. Useful for content moderation. | - |
save |
Save queues/messages from memory. | yes |
help |
Help menu. | - |
quit |
Exit the control port. | - |
Daily statistics
You can enable smp-server
statistics for Grafana
dashboard by setting value on
in /etc/opt/simplex/smp-server.ini
, under [STORE_LOG]
section in log_stats:
field.
Logs will be stored as csv
file in /var/opt/simplex/smp-server-stats.daily.log
. Fields for the csv
file are:
Fields description
Field number | Field name | Field Description |
---|---|---|
1 | fromTime |
Date of statistics |
Messaging queue: | ||
2 | qCreated |
Created |
3 | qSecured |
Established |
4 | qDeleted |
Deleted |
Messages: | ||
5 | msgSent |
Sent |
6 | msgRecv |
Received |
7 | dayMsgQueues |
Active queues in a day |
8 | weekMsgQueues |
Active queues in a week |
9 | monthMsgQueues |
Active queues in a month |
Messages with "notification" flag | ||
10 | msgSentNtf |
Sent |
11 | msgRecvNtf |
Received |
12 | dayCountNtf |
Active queues in a day |
13 | weekCountNtf |
Active queues in a week |
14 | monthCountNtf |
Active queues in a month |
Additional statistics: | ||
15 | qCount |
Stored queues |
16 | msgCount |
Stored messages |
17 | msgExpired |
Expired messages |
18 | qDeletedNew |
New deleted queues |
19 | qDeletedSecured |
Secured deleted queues |
Requested sessions with all relays: | ||
20 | pRelays_pRequests |
- requests |
21 | pRelays_pSuccesses |
- successes |
22 | pRelays_pErrorsConnect |
- connection errors |
23 | pRelays_pErrorsCompat |
- compatability errors |
24 | pRelays_pErrorsOther |
- other errors |
Requested sessions with own relays: | ||
25 | pRelaysOwn_pRequests |
- requests |
26 | pRelaysOwn_pSuccesses |
- successes |
27 | pRelaysOwn_pErrorsConnect |
- connection errors |
28 | pRelaysOwn_pErrorsCompat |
- compatability errors |
29 | pRelaysOwn_pErrorsOther |
- other errors |
Message forwards to all relays: | ||
30 | pMsgFwds_pRequests |
- requests |
31 | pMsgFwds_pSuccesses |
- successes |
32 | pMsgFwds_pErrorsConnect |
- connection errors |
33 | pMsgFwds_pErrorsCompat |
- compatability errors |
34 | pMsgFwds_pErrorsOther |
- other errors |
Message forward to own relays: | ||
35 | pMsgFwdsOwn_pRequests |
- requests |
36 | pMsgFwdsOwn_pSuccesses |
- successes |
37 | pMsgFwdsOwn_pErrorsConnect |
- connection errors |
38 | pMsgFwdsOwn_pErrorsCompat |
- compatability errors |
39 | pMsgFwdsOwn_pErrorsOther |
- other errors |
Received message forwards: | ||
40 | pMsgFwdsRecv |
|
Message queue subscribtion errors: | ||
41 | qSub |
All |
42 | qSubAuth |
Authentication erorrs |
43 | qSubDuplicate |
Duplicate SUB errors |
44 | qSubProhibited |
Prohibited SUB errors |
Message errors: | ||
45 | msgSentAuth |
Authentication errors |
46 | msgSentQuota |
Quota errors |
47 | msgSentLarge |
Large message errors |
48 | msgNtfs |
XXXXXXXXXXXXXXXXXXXX |
49 | msgNtfNoSub |
XXXXXXXXXXXXXXXXXXXX |
50 | msgNtfLost |
XXXXXXXXXXXXXXXXXXXX |
51 | qSubNoMsg |
Removed, always 0 |
52 | msgRecvGet |
XXXXXXXXXXXXXXXXX |
53 | msgGet |
XXXXXXXXXXXXXXXXX |
54 | msgGetNoMsg |
XXXXXXXXXXXXXXXXX |
55 | msgGetAuth |
XXXXXXXXXXXXXXXXX |
56 | msgGetDuplicate |
XXXXXXXXXXXXXXXXX |
57 | msgGetProhibited |
XXXXXXXXXXXXXXXXX |
58 | psSub_dayCount |
Removed, always 0 |
59 | psSub_weekCount |
Removed, always 0 |
60 | psSub_monthCount |
Removed, always 0 |
61 | qCount |
XXXXXXXXXXXXXXXXX |
62 | ntfCreated |
XXXXXXXXXXXXXXXXX |
63 | ntfDeleted |
XXXXXXXXXXXXXXXXX |
64 | ntfSub |
XXXXXXXXXXXXXXXXX |
65 | ntfSubAuth |
XXXXXXXXXXXXXXXXX |
66 | ntfSubDuplicate |
XXXXXXXXXXXXXXXXX |
67 | ntfCount |
XXXXXXXXXXXXXXXXX |
68 | qDeletedAllB |
XXXXXXXXXXXXXXXXX |
69 | qSubAllB |
XXXXXXXXXXXXXXXXX |
70 | qSubEnd |
XXXXXXXXXXXXXXXXX |
71 | qSubEndB |
XXXXXXXXXXXXXXXXX |
72 | ntfDeletedB |
XXXXXXXXXXXXXXXXX |
73 | ntfSubB |
XXXXXXXXXXXXXXXXX |
74 | msgNtfsB |
XXXXXXXXXXXXXXXXX |
75 | msgNtfExpired |
XXXXXXXXXXXXXXXXX |
To import csv
to Grafana
one should:
-
Install Grafana plugin: Grafana - CSV datasource
-
Allow local mode by appending following:
... to
/etc/grafana/grafana.ini
-
Add a CSV data source:
- In the side menu, click the Configuration tab (cog icon)
- Click Add data source in the top-right corner of the Data Sources tab
- Enter "CSV" in the search box to find the CSV data source
- Click the search result that says "CSV"
- In URL, enter a file that points to CSV content
-
You're done! You should be able to create your own dashboard with statistics.
For further documentation, see: CSV Data Source for Grafana - Documentation
Updating your SMP server#
To update your smp-server to latest version, choose your installation method and follow the steps:
-
Manual deployment
-
Stop the server:
-
Update the binary:
-
Start the server:
-
-
-
Execute the followin command:
To install specific version, run:
-
Done!
-
-
-
Stop and remove the container:
-
Pull latest image:
-
Start new container:
-
-
-
Pull latest images:
-
Restart the containers:
-
Remove obsolete images:
-
Reproduce builds#
You can locally reproduce server binaries, following these instructions.
If you are a security expert or researcher, you can help SimpleX network and users community by signing the release checksums – we will publish your signature. Please reach out to us!
To reproduce the build you must have:
- Linux machine
x86-64
architecture- Installed
docker
,curl
andgit
-
Download script:
-
Make it executable:
-
Execute the script with the required tag:
The script executes these steps (please review the script to confirm):
- builds all server binaries for the release in docker container.
- downloads binaries from the same GitHub release and compares them with the built binaries.
- if they all match, generates _sha256sums file with their checksums.
This will take a while.
-
After compilation, you should see the folder named as the tag (e.g.,
v6.3.1
) with two subfolders:The file _sha256sums contains the hashes of all builds - you can compare it with the same file in GitHub release.
Configuring the app to use the server#
To configure the app to use your messaging server copy it's full address, including password, and add it to the app. You have an option to use your server together with preset servers or without them - you can remove or disable them.
It is also possible to share the address of your server with your friends by letting them scan QR code from server settings - it will include server password, so they will be able to receive messages via your server as well.
Please note: you need SMP server version 4.0 to have password support. If you already have a deployed server, you can add password by adding it to server INI file.