diff options
| author | salmonik <salmonik@tuta.io> | 2026-10-28 22:55:51 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-10-28 22:55:51 +0100 |
| commit | 87440d5a23f0fd894d949295a7c1ff85043550fc (patch) | |
| tree | 53b2bada6872b6e565bb79982213616a50419b1c /docs/SERVER_SETUP.md | |
| parent | v0.3.1: clean up dependencies, stale tests and document verification (diff) | |
| download | zagan-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.md | 100 |
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 | |||
| 3 | The server speaks TLS and needs a PKCS#12 identity (`identity.p12`) plus the | ||
| 4 | PEM key/certificate used to build it. The files are read from the current | ||
| 5 | working directory. | ||
| 6 | |||
| 7 | ## Quick start | ||
| 8 | |||
| 9 | From the project root: | ||
| 10 | |||
| 11 | ```sh | ||
| 12 | cargo run --bin server -- --init | ||
| 13 | cargo run --bin server | ||
| 14 | ``` | ||
| 15 | |||
| 16 | `--init` creates a self-signed development identity and exits. The next | ||
| 17 | command starts the server on `127.0.0.1:11525`. | ||
| 18 | |||
| 19 | If `identity.p12` is missing at startup, the server now prints these same | ||
| 20 | instructions 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 | |||
| 30 | On Unix, `identity.p12` and `key.pem` are set to mode `0600`. All three are | ||
| 31 | ignored by git (`*.p12`, `*.pem`, `*.key`). | ||
| 32 | |||
| 33 | ## Manual setup | ||
| 34 | |||
| 35 | If `openssl` is not installed or you want to control the certificate: | ||
| 36 | |||
| 37 | ```sh | ||
| 38 | openssl req -x509 -newkey rsa:2048 \ | ||
| 39 | -keyout key.pem -out cert.pem \ | ||
| 40 | -days 3650 -nodes -subj "/CN=localhost" | ||
| 41 | |||
| 42 | openssl pkcs12 -export -out identity.p12 \ | ||
| 43 | -inkey key.pem -in cert.pem -passout pass: | ||
| 44 | ``` | ||
| 45 | |||
| 46 | The 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 | ||
| 53 | cargo run --bin server | ||
| 54 | |||
| 55 | # listen on all interfaces | ||
| 56 | cargo run --bin server -- -i 0.0.0.0 -p 11525 | ||
| 57 | |||
| 58 | # show options | ||
| 59 | cargo run --bin server -- --help | ||
| 60 | ``` | ||
| 61 | |||
| 62 | Then start the client in another terminal: | ||
| 63 | |||
| 64 | ```sh | ||
| 65 | cargo run --bin client | ||
| 66 | ``` | ||
| 67 | |||
| 68 | On first contact the client prints the SPKI fingerprint and pins it. If you | ||
| 69 | regenerate 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 | ||
| 76 | the same way. `--init` uses SChannel-friendly PKCS#12 algorithms; if you build | ||
| 77 | the identity by hand on Windows, use: | ||
| 78 | |||
| 79 | ```sh | ||
| 80 | openssl 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. | | ||
