The blog.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

107 lines
4.2 KiB

  1. ---
  2. title: Using Signal on a server
  3. description: >
  4. Using Signal on a server
  5. created: !!timestamp '2019-04-08'
  6. time: 1:54 PM
  7. tags:
  8. - signal
  9. ---
  10. For a long while, I'd been using an email to SMS gateway to push
  11. important notifications from my server, such as SMART error messages,
  12. to my phone. After all the
  13. [NSA warrantless surveillance](https://en.wikipedia.org/wiki/NSA_warrantless_surveillance_(2001%E2%80%932007)),
  14. I made a commitment to encrypt as much of my communications as possible.
  15. When Signal came out, I adopted it because of it's strong encryption and
  16. privacy. Ever since I've been wanting to use it for notifications from
  17. my server. I finally got around to trying out the CLI version, and got
  18. it to work.
  19. The installation of the command line utility for Signal was more straight
  20. forward than I was expecting. I decided to use
  21. [signal-cli](https://github.com/AsamK/signal-cli) and I was a bit worried,
  22. as it uses Java. Java has historically been difficult to run on FreeBSD
  23. due to lack of support and draconian licensing terms. I was surprised
  24. that the packages for OpenJDK 8 were both present and just worked on my
  25. server. A simple `pkg install openjdk8` got Java up and running.
  26. One thing to note is that the package said that fdesc and proc needed to
  27. be mounted for Java to work, but I did not, and things still worked.
  28. There are likely other parts of Java that may not work w/o those mounted,
  29. but not for Signal.
  30. As I have been using OSS for a long time, I like to build things from
  31. source, so I followed the instructions at
  32. [Building signal-cli](https://github.com/AsamK/signal-cli#building) and
  33. got the command built with out any trouble.
  34. Once the command was built, the
  35. [Usage guide](https://github.com/AsamK/signal-cli#usage) provided the
  36. basics, but didn't include instructions on how to verify the safety
  37. numbers to ensure that the initial exchange was not MitM'd. There is a
  38. [man page](https://github.com/AsamK/signal-cli/blob/master/man/signal-cli.1.adoc),
  39. but it requires a2x and separate steps to build, but a little bit of
  40. digging got me the necessary steps (also, it turns out that the adoc
  41. format is a simple text format).
  42. With a bit of searching, I found the `listIdentities` and `verify`
  43. commands. There may have been another way, but because I had sent a
  44. test message, my phone was listed:
  45. ```
  46. $ signal-cli -u +XXXXXXXXXXX listIdentities
  47. +YYYYYYYYYYY: TRUSTED_UNVERIFIED Added: Sat Apr 06 18:43:15 PDT 2019 Fingerprint: ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ Safety Number: WWWWW WWWWW WWWWW WWWWW WWWWW WWWWW WWWWW WWWWW WWWWW WWWWW WWWWW WWWWW
  48. ```
  49. And then I needed to use the `trust` subcommand:
  50. ```
  51. $ signal-cli -u +XXXXXXXXXXX trust -v 'WWWWW WWWWW WWWWW WWWWW WWWWW WWWWW WWWWW WWWWW WWWWW WWWWW WWWWW WWWWW' +YYYYYYYYYYY
  52. ```
  53. The hardest part of this was figuring out how to invoke the command upon
  54. reception of an email. I used an alias listed in `/etc/aliases` to forward
  55. the email to both the SMS gateway and myself. The issue with trying to
  56. invoke the command from here was that the command was run as the `mailnull`
  57. user, which of course didn't have access to my user's home directory to
  58. read the private key. After a bit of debating, I remembered I use
  59. `procmail`, and realized this was the best way to send the message.
  60. I created a symlink for the command into my user's bin directory, created
  61. a short script called `sendcell`:
  62. ```
  63. $ cat ~/bin/sendcell
  64. #!/bin/sh -
  65. ~user/bin/signal-cli -u +XXXXXXXXXXX send +YYYYYYYYYYY
  66. ```
  67. and then added a filter to my `.procmailrc` file. The filter at first
  68. looked like this:
  69. ```
  70. :0Wf
  71. * ^TO_celluser@([^@\.]*\.)*example.com
  72. | sendcell
  73. ```
  74. But after the first test, it included all the headers, including all the
  75. `Received` headers, so I updated it to use `formail` to remove all but the
  76. `From`, `Subject` and `Date` (in case the message gets significantly delayed,
  77. I can see by how much) headers:
  78. ```
  79. :0c
  80. * ^TO_celluser@([^@\.]*\.)*example.com
  81. {
  82. :0Wf
  83. | formail -k -X From: -X Subject: -X Date:
  84. :0
  85. | sendcell
  86. }
  87. ```
  88. and now I get the messages delivered to my phone securely!
  89. It is tempting to use this to be able to invoke commands on my server
  90. remotely, but there isn't much I need to do when I don't have my laptop
  91. with me.