SPHINX Password Storage – Server Installation Guide
1. Overview
The SPHINX server is also known as the oracle. The server is responsible for handling password requests, managing user accounts, and providing secure access to stored passwords.
SPHINX offers two server implementations:
- Python Reference Implementation: Ideal for development, testing, and CI/CD.
- zphinx-zerver (Zig): Production-grade, recommended for real-world deployments.
If you have a Zig compiler, we recommend using the zphinx-zerver. See zphinx-zerver: Production Server Installation for details.
2. Quick Install Recipes
2.1. On Devuan/Debian/Ubuntu/Kali/Raspbian/etc
Currently only in debian testing/unstable, and equivalents in debian derivates.
apt install pwdsphinx
This installs the Python reference implementation, which you can run with the instructions below.
2.2. On NixOS
Use the recipe from opaque-sphinx.
2.3. Using Docker
Follow the instructions at the zphinx-zerver-docker.
3. Building from Source
3.1. Python Reference Server (Unix-like Systems)
Recommended for development and testing only. For production, see zphinx-zerver below.
3.1.1. Install regular dependencies
You need to adjust the package names according to your distribution's naming conventions. To install on Debian-based systems:
apt install python libsodium libsodium-dev gcc g++
3.1.2. Install liboprf
liboprf is a library for Oblivious Pseudorandom Functions (OPRFs), including support for Threshold OPRFs. To install,
git clone https://github.com/stef/liboprf.git cd liboprf/src make sudo PREFIX=/usr make install cd ../..
3.1.3. Install libequihash
The libequihash library provides memory-hard proof-of-work with fast verification. To install, run:
PREFIX=/usr sudo make clean install
git clone https://github.com/stef/equihash.git cd equihash make sudo PREFIX=/usr make install cd ..
3.1.4. Install pwdsphinx
With the dependencies in place, install the Python SPHINX client, pwdsphinx:
python3 -m virtualenv --copies --system-site-packages env
source env/bin/activate
pip install pwdsphinx
Done! After configuring, you can run the server with oracle.
3.2. zphinx-zerver: Production Server Installation
Recommended for production deployments.
3.2.1. Prerequisites
- Install
libequihashas shown above. - Install Zig v0.14.x. You can install from the package manager of your distro if it has Zig or from https://ziglang.org/download/#release-0.14.1.
- Ensure that
libequihash.pcandsodium.pcare in/usr/share/pkgconfig/. This is done because Zig does not seem to be able to find other distro-specific directories like/usr/lib/x86_64-linux-gnu/pkgconfig/
3.2.2. Clone the Repository
git clone --recursive https://github.com/stef/zphinx-zerver
3.2.3. Build
cd zphinx-zerver
zig build install -Doptimize=ReleaseSafe -Dpie=true -Drelro=true --prefix .
For cross-compiling or generic CPUs, where you are building the
server on a different CPU than what you are going deploy it on,
you might want to add a -Dcpu=baseline parameter:
zig build -Dcpu=baseline -Doptimize=ReleaseSafe -Dpie=true -Drelro=true install --prefix .
3.2.4. Allow Binding to Port 443 (Optional but Recommended)
We recommend running a production server on port 443, which is where TLS-enabled web servers are usually running. Also, it is the most widely allowed port on firewalls. Using this port prevents issues like being locked out from your passwords because a hotel's firewall does not allow you to connect to a more esoteric port like 2355.
To avoid running the server as root, you can use the following command to allow the server to bind to port 443 without root privileges:
sudo setcap 'cap_net_bind_service=+ep' ./bin/oracle
3.3. Configuring the Server
Both server implementations (Python reference and zphinx-zerver) use identical configuration files. This section walks you through the essential setup steps.
3.3.1. Get a proper TLS cert
The server needs a TLSv1.2 certificate and the only supported algorithm for the key is Elliptic Curve Digital Signature Algorithm (ECDSA). To generate a key, run:
openssl ecparam -genkey -out ssl_key.pem -name secp384r1
You also need to create a TLS certificate for this key.
Option A: Production Certificate (Recommended)
For production deployments, you can obtain a certificate from Let's Encrypt using your preferred ACME client (certbot, acme.sh, etc.).
Option B: Self-Signed Certificate (Testing Only)
⚠️ Warning: Only use self-signed certificates for testing and development.
openssl req -new -nodes -x509 -sha256 -key ssl_key.pem -out ssl_cert.pem -days 365 -subj '/CN=your-hostname'
Replace your-hostname with your server's actual hostname or IP address.
For self-signed certificates, you must:
- Copy
ssl_cert.pemto each client machine - Set the
ssl_certvariable in client config to point to this file
3.3.2. Configuration
3.3.2.1. Configuration File Locations
First you need a configuration for your oracle. SPHINX reads configuration files in this specific order, with later files overriding earlier settings:
/etc/sphinx/config- System-wide configuration~/.sphinxrc- User-specific configuration~/.config/sphinx/config- XDG-compliant user configuration./sphinx.cfg- Project or directory-specific configuration
This hierarchy allows global defaults while letting users customize their personal settings.
3.3.2.2. Basic Configuration Template
The content of the configuration files should be according to the following example (showing all default values):
[server] address="::" port=2355 ssl_key="key.pem" ssl_cert="cert.pem" timeout=3 max_kids=5 datadir= "/var/lib/sphinx" verbose=false rl_decay= 1800 rl_threshold= 1 #rl_gracetime=10 ltsigkey="ltsig.key"
3.3.2.3. Configuration Parameter Guide
address: Determines on what address your oracle is listening. Set to"::"to listen on all IPv4 and IPv6 interfaces, or specific IP for restricted accessport: Sets the port your oracle is listening on. We recommend using port 443 if available, since it is usually used for web servers and would help when the oracle is being accessed from behind tight firewallsssl_key&ssl_cert: Required. Have no defaults, and must be set to paths to your TLS credentials. Without them, the oracle will not runtimeout: Sets the TCP connection timeout. Increase for slow networks, with the caveat that this might lead to easier resource exhaustion, by blocking all workersmax_kids: Configures the number of worker processes serving requests.datadir: Points at the root directory where all data is stored. Backup this directory regularly and securely, since the loss of this directory means users lose access to their passwordsverbose: Makes the oracle print information to standard output. This can be helpful for debuggingrl_decay: Sets the number of seconds for the attack difficulty to decrease. Together withrl_thresholdandrl_gracetime, these params are used to configure rate limitingrl_threshold: Configures the number of failed attempts before increasing the difficulty levelrl_gracetime: Sets the number of additional seconds allowed - beyond the max solution time fixed for a certain difficulty - before a rate-limiting puzzle expiresltsigkey: The path pointing to the long-term signing private key. You can create one by runningoracle init. This will also create a public key and its base64 encoded variant, which should be published to all potential users so that they can use your oracle in a threshold setup. If running a public server, establish an online presence (static webpage, social media, etc.) to publish your public key
The production Zig server, zphinx-zerver, supports overriding any
of these config variables by setting environment variables. The name
of the environment variable is the all-capital variant of the name,
prefixed by ORACLE_. For example, you can set the verbosity of the
server, controlled with the verbose parameter using
ORACLE_VERBOSE like this:
ORACLE_VERBOSE=true oracle
3.4. Running the Server
Once you have configured your TLS certificates and server settings, you can start your SPHINX server. The command differs slightly depending on which implementation you're using.
For the production zphinx-zerver, run:
./bin/oracle 2>&1 | /usr/bin/ts
For pwdsphinx, use:
oracle 2>&1 | /usr/bin/ts
The command pipes both standard output and error streams through
/usr/bin/ts, a utility from the moreutils package that adds
timestamps to each log line. This basic logging setup helps
with debugging and monitoring, though you may want to implement
a more sophisticated logging solution for production environments.
3.5. Sandboxing zphinx-zerver
zphinx-zerver includes a simple script for sandboxing the server with further sandboxing using seccomp (secure computing mode), a Linux kernel feature that restricts the system calls (syscalls) a process can make. This script creates an isolated environment that limits the server's access to system resources, reducing the potential impact of security vulnerabilities.
To run the oracle in a sandboxed environment:
./sbox.sh bin/oracle sphinx.cfg seccomp/debian-sid-zig-0.9.0-5.bpf 2>&1 | /usr/bin/ts
3.5.1. Important Sandboxing Considerations
The sandboxed environment has several limitations you should be aware of:
- Shell expansion features like tilde (
) for home directory and variable expansion ($FOO) will not work inside the sandboxed environment. This happens because musl libc actually executes ~/bin/shto handle these expansions, which is restricted in the sandbox. You must use full absolute paths in your configuration. - Your configuration file format becomes more strict in the sandboxed environment. The config file must not contain spaces around the equals signs (=), as the sandbox script sources the file directly and spaces will cause parsing failures.
- During the configuration loading process, you may see one harmless error or warning message about the `[server]` section header, which can be safely ignored.
3.5.2. Creating Custom Seccomp Profiles
If the provided .bpf seccomp profiles don't work for your system
architecture or distribution, you can create your own.
The simplest approach is to start with an existing profile
like x86_64-musl.seccomp or debian-sid-zig-0.9.0.seccomp and compile it.
These profiles are located in the seccomp directory of the zphinx-zerver repository.:
tools/compile_seccomp_policy.py target.seccomp target.bpf
Test your new profile using the sandbox script, sbox.sh, while
monitoring system messages with dmesg. If the kernel blocks a
syscall, dmesg will report which syscall caused the violation.
Add the missing syscall to your .seccomp file, recompile, and
test again until the server runs without violations.
For a completely custom profile, you can generate one for your architecture and libc like this:
3.5.2.1. Generate constants.json
For zphinx-zerver, you can use the constants.json file from the zphinx-zerver
/seccomp directory. If you prefer, you can generate a new one by following
the instructions below:
git clone https://android.googlesource.com/platform/external/minijail/ /tmp/minijail cd /tmp/minijail make constants.json cd - cp /tmp/minijail/constants.json .
3.5.2.2. Generate a comprehensive strace log
You need to start the oracle without a sandbox/jail, and run the full
Python unit test suite (present in the pwdsphinx/tests folder) from
the Python reference implementation
against the server, while stracing it. Alternatively, you could just
run pwdsphinx/tests/test.sh, but that is less comprehensive and mostly
tests the positive branches
To create a comprehensive trace of the server's system calls while running the full test suite:
strace -fo target.strace bin/oracle
3.5.2.3. Extract a seccomp configuration from the strace log
Run this script to generate a list of all system calls from your trace log to create a new seccomp policy:
tools/generate_seccomp_policy.py target.strace >target.seccomp
3.5.2.4. Compile seccomp into bpf
Finally, compile the .seccomp file into a proper .bpf
tools/compile_seccomp_policy.py target.seccomp target.bpf
This process ensures your seccomp profile includes the system calls
your server needs while blocking everything else. This custom config
can now be used with the above-mentioned sbox.sh script.
3.6. Running in Production
Normally you want to run the zPHINX server on a dedicated machine, with nothing else (except maybe an ssh), to minimize your attack surface.
However… sometimes you don't have this luxury of minimized attack surface, and you want to run zPHINX on a server with other (probably) HTTP services.
You (might/should) also want to run a separate webserver for public
announcements related to your server, like public keys, sample configs
and updates and news. Our recommendation is to run the zPHINX server
on pwd.yourdomain.tld and the related webserver on
sphinx.yourdomain.tld.
You might be tempted to run nginx as a reverse proxy in front of
zPHINX. DON'T. SPHINX as a protocol cannot be TLS terminated
upstream. Also if you look into plaintext SPHINX traffic you will see
it is all binary. You will have only lot's of HTTP/1.1 400 Bad
Request and unhappy users.
What you can do in these cases is to run a SNI-based routing proxy, like snifer or HAPROXY. This also allows you to run a dedicated website for your SPHINX server, so that you can inform your users about the configuration, keys and maintenance related updates and news. The following is an example HAPROXY config:
defaults
timeout client 30s
timeout server 30s
timeout connect 5s
# HAPROXY listens here
frontend ft_ssl_vip
bind 10.0.0.10:443
mode tcp
tcp-request inspect-delay 5s
tcp-request content accept if { req_ssl_hello_type 1 }
default_backend bk_ssl_default
# Using SNI to take routing decision
backend bk_ssl_default
mode tcp
acl sphinx req_ssl_sni -i sphinx.domain.com
use-server sphinx_server if sphinx
use-server other if !sphinx_server
option ssl-hello-chk
server sphinx_server 127.0.0.1:2523 check
server other 127.0.0.1:443 check
In this setup you should adjust 10.0.0.10 to your public IP address where you want to run all your services. In the example above the zPHINX server runs on localhost:2523 and the other stuff on a webserver listening on localhost:443.
In case you want your webserver to have access to IP addresses of connecting clients, you need transparent proxying which also involves some firewall configuration, an example is available in the HAPROXY repo.
3.6.1. Running a SPHINX hidden-service
This is useful, so your users can be sure, they cannot be tracked by you based on IP addresses. It shows you mean business and respect them.
HiddenServiceDir /var/lib/tor/sphinx/ HiddenServicePort 443 127.0.0.1:4443
the hostname is in /var/lib/tor/sphinx/hostname.