A small TLS 1.3 reverse proxy for the most common nginx setup: a few HTTPS sites, each forwarded to one HTTP service on the same host or network. One static binary, one configuration file with six keys per site, no dependencies at run time.
- Terminates TLS 1.3 and picks the certificate by SNI.
- Forwards each hostname to its upstream over HTTP/1.1, with
Hostas the client sent it,X-Real-IP,X-Forwarded-For,X-Forwarded-ProtoandVia. - Passes WebSocket upgrades through.
- Streams request bodies, with a size cap per site.
- Allows a site only from given address ranges (a CDN's, a private network's), refusing everyone else during the handshake.
- On port 80, redirects to HTTPS and serves ACME tokens for
certbot --webroot, so certificates renew without an nginx plugin. - Logs a line per request to journald.
It is written in Rust without unsafe, but for the function that wipes
secrets and the two Linux system calls that wait for SIGTERM, on top of
libcrux, a formally verified crypto library. The TLS and HTTP state
machines and the threading are specified in TLA+ and model-checked, and
the code is tested against those specs (see "Checking it"); the real
threads also run under thousands of schedules (shuttle). The models are
checked within bounds (small ones in CI, larger ones locally) and cover
the designs only: parsing, the cryptography and the operating system
(file descriptors, blocking I/O) are checked by tests, proofs of small
inputs and coverage-guided fuzzing instead, as SPEC.md section 10 sets
out.
Status: version 0.1, new. It is tested as described below, but has not yet had much use. There is no warranty (see the licenses).
shioko fits if each server block of your nginx configuration does no more
than this:
server {
listen 443 ssl;
server_name app.example.org;
ssl_certificate /etc/letsencrypt/live/app.example.org/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/app.example.org/privkey.pem;
client_max_body_size 100M;
allow 10.0.0.0/8;
deny all;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}That block, plus the usual port 80 server for the redirect and certbot, is in shioko:
[app.example.org]
upstream = 127.0.0.1:8080
cert = /etc/letsencrypt/live/app.example.org/fullchain.pem
key = /etc/letsencrypt/live/app.example.org/privkey.pem
websocket = yes
allow = 10.0.0.0/8
max-body = 100M
It does not fit if you need any of these, which shioko does not do:
- static files, PHP or FastCGI, gzip;
rewrite,return,try_files, or severallocationblocks going to different places;- wildcard or regular-expression
server_names, or redirects from one name to another (wwwto the bare domain); several plain names are fine, one section each; add_header, includingStrict-Transport-Security(the application has to send it), andauth_basic;- HTTPS or Unix-socket upstreams, or several upstreams per site;
- ports other than 80 and 443, or HTTP/2 (clients fall back to HTTP/1.1);
- configuration reload without a restart (renewed certificates are taken up by themselves, within a minute, and a restart lets the requests being served finish);
- clients that cannot do TLS 1.3 with ChaCha20-Poly1305 (next section).
shioko offers one choice at each layer of TLS: TLS 1.3, the cipher
TLS_CHACHA20_POLY1305_SHA256, key exchange X25519MLKEM768 (post-quantum
hybrid) or X25519, and ECDSA P-256 certificates.
- Works: current Chrome, Edge, Firefox and Safari, curl and anything else using OpenSSL 1.1.1 or later, Go, Python, Node.js, Java 12 and later, and Cloudflare in front of your site.
- Does not work: clients that only speak TLS 1.2 or older, such as apps
on Android 9 and older that use the system's TLS; Java before 12; and
programs that use Windows' own TLS (Schannel), such as Windows' built-in
curl.exe, PowerShell and many .NET applications, because Windows supports ChaCha20-Poly1305 but leaves it off by default. Browsers on Windows bring their own TLS and are fine. Older smart TVs, set-top boxes and other embedded clients may also fail. - Certificates must be ECDSA P-256. certbot 2.0 and later issues those by default; an RSA certificate has to be replaced first (the deployment guide shows how).
The deployment guide shows how to find out from your nginx logs whether any of your clients would be refused, before you switch.
About as fast as nginx for what such a setup does, a little slower at
bulk downloads. Every end-to-end run (tools/e2e.sh, also in CI) measures
both, serving the same site from the same upstream, and fails if shioko
falls too far behind. On an Apple M5, everything in Docker on the same
machine, with the final code of this version:
| shioko | nginx | |
|---|---|---|
| TLS handshake, median / 99th percentile | 0.58 / 0.71 ms | 0.53 / 0.70 ms |
| request on a kept connection, median / 99th percentile | 0.15 / 0.20 ms | 0.14 / 0.19 ms |
| 32 connections at once: requests per second | 8,663 | 9,606 |
| one 50 MB download | 220 MB/s | 460 MB/s |
The download gap is the cipher: nginx uses AES-GCM with the CPU's AES
instructions, shioko ChaCha20-Poly1305 in portable code. At 220 MB/s that
is still more than a 1 Gbit/s link carries. shioko uses a thread per
connection, so it is made for hundreds of connections, not hundreds of
thousands (see the limits in SPEC.md).
You need Rust (rustup) and access to crates.io: the
build downloads libcrux and the few crates it needs, at the exact versions
and checksums recorded in Cargo.lock. Build on Linux or macOS, for the
architecture of the server (uname -m there says x86_64 or aarch64):
git clone https://github.com/oToToT/Shioko.git shioko
cd shioko
rustup toolchain install # the version pinned in rust-toolchain.toml
cargo build --locked --release --target x86_64-unknown-linux-musl
The binary, target/x86_64-unknown-linux-musl/release/shioko, is static and
runs on any Linux distribution. Then follow
deploy/README.md: it translates your nginx
configuration, installs shioko with its systemd unit and the certbot hook,
switches over with a few seconds of downtime, and says how to go back.
One file, /etc/shioko/shioko.conf, with one section per site, named by its
hostname:
| Key | Meaning | If omitted |
|---|---|---|
upstream |
host:port of the HTTP/1.1 server the site is forwarded to. A name is looked up again for each request, with the system's resolver (/etc/hosts, then DNS) and without a cache; the lookup has the resolver's own timeouts (/etc/resolv.conf), and the 5 s connect timeout starts after it, for each address the name gives. An address, or a name in /etc/hosts, avoids waiting on DNS. |
required |
cert |
PEM certificate chain; the site is served over HTTPS and port 80 redirects to it | the site is plain HTTP |
key |
PEM private key (ECDSA P-256), required with cert |
|
websocket |
yes lets WebSocket upgrades through |
upgrade headers are removed |
allow |
address ranges, and files with one range per line, that may connect. An IPv4 range lets in IPv4 clients and an IPv6 range IPv6 clients, as in nginx: ::/0 is every IPv6 client and no IPv4 one, and a range of IPv4-mapped addresses (::ffff:…) lets nobody in |
everyone |
max-body |
largest request body, in bytes or with K, M or G, such as 525M; unlike nginx's, 0 allows no body |
1M, as in nginx |
# starts a comment, to the end of its line. shioko check validates the
file without starting the server, and reports the first mistake with its
line number.
Fixed, not configurable: ports 80 and 443 on all IPv4 and IPv6 addresses
(through one dual-stack socket, so IPv6 must be enabled on the host, as it
is by default); ACME tokens from
/var/lib/shioko/acme/.well-known/acme-challenge (where
certbot --webroot -w /var/lib/shioko/acme puts them), for any hostname; at
most 512 connections from addresses inside some site's allowlist and 512
from everyone else, at most 64 of these from one address (an IPv6 /64),
the rest closed at once, so a flood from outside cannot take the slots of
allowlisted sites (fewer than 512, with a warning at startup, if the
open-file limit is below 3088); 5 s to connect to an upstream (nginx waits
60 s); as
in nginx, 60 s of silence from an upstream or on a WebSocket, and 75 s for
an idle keep-alive connection; a request body must keep up 64 KiB a
minute, and a client must take each piece we write (at most 16 KB) within
60 s, so slow clients cannot hold connections for free. Responses and
WebSockets keep no pace, so that server-sent events and quiet WebSockets
work. A name that only needs a
certificate, a mail server's for instance, needs no section. An unknown
hostname gets a 404 or, over TLS, an unrecognized_name alert.
Keep the ACME directory writable by root only. shioko serves any file
of up to 4 KB in /var/lib/shioko/acme/.well-known/acme-challenge/ whose
name looks like a token, and it follows symbolic links. With certbot
running as root, as the deployment guide sets it up, only root can write
there, and root can read the keys anyway, so this changes nothing. It
matters if you run the ACME client as another user (acme.sh, lego, a
container) and let it write to that directory: that user could put there
a link to any site's private key, which shioko can read, and fetch the key
over plain HTTP.
More examples, and every detail of the behaviour, are in
SPEC.md: section 3 for the configuration, 5 for TLS, 6 for
HTTP.
These are deliberate. Each is recorded as a deviation against the sentence
it departs from in spec/rfc/.
TLS (RFC 8446)
- Only one cipher suite, two key exchange groups, one signature scheme.
RFC 8446 section 9.1 makes
TLS_AES_128_GCM_SHA256, key exchange over secp256r1 and RSA signatures mandatory to implement. shioko implementsTLS_CHACHA20_POLY1305_SHA256, X25519MLKEM768 (the post-quantum hybrid of RFC 10024, preferred when offered), X25519 andecdsa_secp256r1_sha256only. - TLS 1.3 only; no session resumption, no early data, no client certificates.
- After 32 records in a row that carry nothing (dummy ChangeCipherSpecs, KeyUpdates, empty records), the next is refused, as OpenSSL and BoringSSL refuse it, although the RFC has them all accepted.
- The certificate chain is sent as it is in the file and never parsed, so nothing the RFC asks of a chain is checked.
HTTP (RFC 9110, RFC 9112)
- Absolute-form request targets are refused. RFC 9112 section 3.2.2
says a server must accept
GET http://host/path HTTP/1.1. shioko answers 400 to anything but an origin-form target (/path). Browsers and CDNs send origin-form to an origin; accepting the other form means choosing between two host names in one request. CONNECT is refused for the same reason. - Request targets may hold characters the URI grammar forbids (
|,^,[,{, ...), because browsers send them unencoded; they are forwarded as received. Max-Forwardsis not processed for OPTIONS.- TRACE is refused with 405 (without the
Allowfield RFC 9110 asks for) andOPTIONS *with 400, as nginx refuses them. OPTIONS for a path, the CORS preflight, is forwarded. - Header lists with empty elements (
Transfer-Encoding: chunked,) are refused. - The upstream hop is plain HTTP/1.1, with a new connection per request.
- ACME tokens are served without validators and without evaluating conditional requests.
The complete lists are at the end of sections 5 and 6 of SPEC.md.
nix develop # TLC, OpenSSL, curl
tools/check.sh # lint, tests, the threads under thousands of
# schedules (shuttle/), release builds for both targets
tools/spec.sh # model-check the specs, check the RFC lists
tools/spec-big.sh # the same models within larger bounds (slow; not CI)
tools/prove.sh [big] # Kani proofs (big: longer inputs, about an hour)
tools/interop.sh # a real shioko against OpenSSL and curl
tools/ci.sh # all of the above in Linux containers, tlsfuzzer,
# and a short run of every fuzz target
tools/ci.sh STAGE... # some of it: specs proofs interop unit tlsfuzzer fuzz
# linux/amd64 linux/arm64
tools/fuzz.sh [SECONDS] [TARGET...]
# coverage-guided fuzzing (needs nightly and cargo-fuzz)
GitHub Actions (.github/workflows/ci.yml) verifies every push to main and
every pull request. Each stage of tools/ci.sh is a job of its own, with
arm64 on an arm64 runner, and the end-to-end environment below runs twice:
tools/e2e.sh and tools/e2e.sh record. Their results are kept as artifacts
of the run.
tools/e2e.sh [soak MINUTES] runs the end-to-end environment of ci/e2e/
(needs Docker and network to pull images): shioko as deployed, nginx for
comparison, Vaultwarden, Jellyfin, a test upstream, and Pebble issuing a
certificate to certbot through shioko. It also measures latency and
throughput next to nginx, and fails if shioko falls too far behind. Results
go to target/e2e/.
tools/e2e.sh record does the same with a development build that logs the
steps of its threads, and TLC checks the whole run against spec/Server.tla
(tools/servertrace.py).
tools/ci.sh also runs every TLS 1.3 script of tlsfuzzer against shioko
(ci/tlsfuzzer.Dockerfile, tools/tlsfuzzer.sh). The probes expected to
fail are listed in tests/tlsfuzzer.txt, each with the reason: mostly
features shioko leaves out on purpose, such as AES, other groups, RSA
certificates, tickets and TLS 1.2. Every connection of that run is recorded,
decrypted by an independent decoder, and checked by TLC against the TLS
spec as a whole behaviour (tools/tlstrace.py, spec/HandshakeTrace.tla).
SPEC.md section 8 describes every check in detail.
shioko is licensed under either of the Apache License, Version
2.0 or the MIT license, at your option.
shioko is built with libcrux (Apache-2.0) and a few other crates, and the
repository holds RFC texts and test vectors; THIRD-PARTY.md lists them
with their terms.