Preparing the system
Create a system user named signal
to run the gateway with :
$ sudo useradd -r -s /usr/bin/nologin -d /var/lib/signal -c "Signal Web Gateway User" signal
Installation
Build from source Code
Install the dependencies to download and compile the program :
$ sudo pacman -S go git
Downlod and compile the source code :
$ go get github.com/signal-golang/textsecure
$ cd go/src/github.com/signal-golang/textsecure/cmd/textsecure/
$ go build
$ ./textsecure -h
Install the binary into the appropriate folder :
$ sudo install -g signal -Dm 0750 -t /opt/signal-golang/bin/ textsecure
Optional : If you want to add the program to your path
$ sudo ln -sv /opt/signal-golang/bin/textsecure /usr/local/bin/
Download binaries
Warning !! This version crashes when receiving a signal message with the following error :
level=fatal msg="Cannot read line from console: EOF"
But if you inisist :
$ curl -L -o signal-web-gateway https://gitlab.com/morph027/signal-web-gateway/-/jobs/artifacts/master/raw/signal-amd64?job=binary-amd64
$ sudo mkdir -p /opt/signal-web-gateway/bin
$ sudo install -g signal -m 0750 signal-web-gateway /opt/signal-web-gateway/bin/
Configuration
Create the systemd unit
Create the systemd unit that will be used to launch our gateway. Create the unit file /etc/systemd/system/signal-web-gateway.service
with the following content :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
The service will fail to start because there is no config file. However, we are going to use systemd to create the required directories for us and arrange their permissions.
$ sudo systemctl start signal-web-gateway.service
Check if log files are present, otherwise create them with :
$ sudo touch /var/log/signal-web-gateway/{output,error}.log
Arrange the file permissions :
$ sudo chgrp signal /var/log/signal-web-gateway/{output,error}.log
$ sudo chmod 664 /var/log/signal-web-gateway/{output,error}.log
Create the config file
Create the config file config.yml
under /etc/webapps/signal-web-gateway/
with following content.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
Create a folder .config
inside the Working Directory /var/lib/signal-web-gateway/
and a symlink to the config file :
$ sudo rm -r /var/lib/signal-web-gateway/.config
$ sudo ln -sv /etc/webapps/signal-web-gateway /var/lib/signal-web-gateway/.config
Verify your number by starting the application with -config
parameter :
$ sudo -H -u signal /opt/signal-golang/bin/textsecure -config /etc/webapps/signal-web-gateway
Input the code received in the verification call and Ctrl+C
to Exit.
Now you can start the systemd service
$ sudo systemctl enable --now signal-web-gateway.service
Optional : Create a Contact list
In order to send messages using names instead of numbers, you can create a contacts.yml
in /etc/webapps/signal-web-gateway
:
1 2 3 |
|
Configuring Nextcloud To use Signal 2FA
Now you need to install The TwoFactor Gateway app in nextcloud and configure it to use your signal-web-gateway
.
$ sudo -u nextcloud php /usr/share/webapps/nextcloud/occ app:install twofactor_gateway
$ sudo -u nextcloud php /usr/share/webapps/nextcloud/occ twofactorauth:gateway:configure signal
Enter Your Signal gateway address
signal.lan:5000
Now in Nextcloud user settings, under Security enable Signal two factor authentification and verify your number.
Test using Nextcloud's occ
command
You can test the gateway by sending a signal msg to your number, change nc_username
to your nextcloud user name :
$ sudo -u nextcloud php /usr/share/webapps/nextcloud/occ twofactorauth:gateway:test nc_username signal +212XXXXXXXXX
Sending Messages via the gateway
Using curl
$ curl -X POST -F "to=+212XXXXXXXXX" -F "message=Hi!" http://signal:5000
$ curl -X POST -d '{"message":"From desktop using VM Arch gateway"}' http://signal:5000/json/+212XXXXXXXXX
Using netcat
The content length should be calculated and sent otherwise a wrong header error will occur.
$ netcat signal.lan 5000
POST / HTTP/1.1
Host: signal.lan:5000
Content-Type: application/x-www-form-urlencoded
Content-Length: 53
to=%2b212XXXXXXXXX&message=Salut de la part du Netcat