summaryrefslogtreecommitdiffstats
path: root/docs/SERVER_SETUP.md
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-10-28 22:55:51 +0100
committersalmonik <salmonik@tuta.io>2026-10-28 22:55:51 +0100
commit87440d5a23f0fd894d949295a7c1ff85043550fc (patch)
tree53b2bada6872b6e565bb79982213616a50419b1c /docs/SERVER_SETUP.md
parentv0.3.1: clean up dependencies, stale tests and document verification (diff)
downloadzagan-bet-87440d5a23f0fd894d949295a7c1ff85043550fc.tar.gz
zagan-bet-87440d5a23f0fd894d949295a7c1ff85043550fc.zip
v0.4.0: add first-time TLS setup and server help
Diffstat (limited to 'docs/SERVER_SETUP.md')
-rw-r--r--docs/SERVER_SETUP.md100
1 files changed, 100 insertions, 0 deletions
diff --git a/docs/SERVER_SETUP.md b/docs/SERVER_SETUP.md
new file mode 100644
index 0000000..e2f3177
--- /dev/null
+++ b/docs/SERVER_SETUP.md
@@ -0,0 +1,100 @@
1# Server setup
2
3The server speaks TLS and needs a PKCS#12 identity (`identity.p12`) plus the
4PEM key/certificate used to build it. The files are read from the current
5working directory.
6
7## Quick start
8
9From the project root:
10
11```sh
12cargo run --bin server -- --init
13cargo run --bin server
14```
15
16`--init` creates a self-signed development identity and exits. The next
17command starts the server on `127.0.0.1:11525`.
18
19If `identity.p12` is missing at startup, the server now prints these same
20instructions instead of only the raw OS error.
21
22## What `--init` creates
23
24| File | Purpose |
25| --- | --- |
26| `identity.p12` | PKCS#12 identity loaded by `native-tls`. Empty password. Uses PBE-SHA1-3DES and a SHA-1 MAC so the Windows SChannel backend can load it. |
27| `key.pem` | RSA private key used to build the identity. Not read at runtime. |
28| `cert.pem` | Public certificate, useful for inspection. |
29
30On Unix, `identity.p12` and `key.pem` are set to mode `0600`. All three are
31ignored by git (`*.p12`, `*.pem`, `*.key`).
32
33## Manual setup
34
35If `openssl` is not installed or you want to control the certificate:
36
37```sh
38openssl req -x509 -newkey rsa:2048 \
39 -keyout key.pem -out cert.pem \
40 -days 3650 -nodes -subj "/CN=localhost"
41
42openssl pkcs12 -export -out identity.p12 \
43 -inkey key.pem -in cert.pem -passout pass:
44```
45
46The password must be empty because the server calls
47`Identity::from_pkcs12(&data, "")`.
48
49## Running
50
51```sh
52# default: 127.0.0.1:11525
53cargo run --bin server
54
55# listen on all interfaces
56cargo run --bin server -- -i 0.0.0.0 -p 11525
57
58# show options
59cargo run --bin server -- --help
60```
61
62Then start the client in another terminal:
63
64```sh
65cargo run --bin client
66```
67
68On first contact the client prints the SPKI fingerprint and pins it. If you
69regenerate the server identity, the client will reject the new key; run
70`forget-host` in the client if the change is intentional.
71
72## Windows
73
74`--init` shells out to `openssl`, so OpenSSL must be installed and on `PATH`
75(Git for Windows, WSL, or a standalone OpenSSL build). The generated files work
76the same way. `--init` uses SChannel-friendly PKCS#12 algorithms; if you build
77the identity by hand on Windows, use:
78
79```sh
80openssl pkcs12 -export -out identity.p12 -inkey key.pem -in cert.pem \
81 -passout pass: -keypbe PBE-SHA1-3DES -certpbe PBE-SHA1-3DES -macalg sha1
82```
83
84## Security notes
85
86- This is a self-signed development identity with an empty PKCS#12 password.
87 Treat `key.pem` and `identity.p12` as secrets and do not commit them.
88- The trust model is TOFU: clients pin the SPKI fingerprint on first contact.
89 A changed key is a loud error, not an automatic re-trust.
90- For a public deployment, use a CA-issued certificate and protect the
91 PKCS#12 with a password; the current server code expects an empty password.
92
93## Troubleshooting
94
95| Symptom | Fix |
96| --- | --- |
97| `Failed to initialize TLS: Could not read TLS identity` | Run `cargo run --bin server -- --init`. |
98| `Address already in use` | Stop the other server or pass `-p <port>`. |
99| Client says `HOST KEY CHANGED` | The server certificate changed. If intentional, run `forget-host` in the client. |
100| `openssl` not found | Install OpenSSL or use the manual commands on a machine that has it. |