Add hkp and vks support

This commit is contained in:
2026-10-11 10:52:13 +03:00
parent 9ef912049a
commit ab6fbc5e16
6 changed files with 134 additions and 108 deletions
+83 -80
View File
@@ -1,123 +1,126 @@
# GPG Public Key Server with Web Key Directory (WKD)
# OpenPGP Key Distribution: WKD + HKP + VKS
A small Docker/Nginx service that publishes OpenPGP public keys as static files. It supports the **WKD direct method** as well as optional human-downloadable armored keys. WKD lets compatible OpenPGP clients discover a public key from an email address and its domain.
This project combines an Nginx frontend with a Hagrid backend.
> This is a static WKD publisher, not a full HKP/HKPS keyserver or a key-submission service. It does not automatically verify ownership of email addresses or update/revoke published keys.
- **WKD:** static files under `/.well-known/openpgpkey/`.
- **HKP:** `/pks/lookup` and `/pks/add`, handled by Hagrid.
- **VKS:** `/vks/v1/` API, handled by Hagrid.
- **Static downloads:** optional public-key files under `/keys/`.
## Files
Hagrid supports a subset of HKP and its native VKS API. It is not full SKS/HKP feature parity. See https://keys.openpgp.org/about/api/
```text
gpg-keyserver-wkd/
├── Dockerfile
├── docker-compose.yml
├── nginx.conf
├── publish-wkd-key.sh
├── README.md
├── keys/ # Optional ASCII-armored downloads
└── wkd/
├── policy # WKD policy marker (created by script)
└── hu/ # Binary public keys named by WKD hash
```
## Important deployment caveat
## Requirements
The Compose file uses the community-maintained `jumper78/hagrid-openpgp` image as an example, not an official production image published by keys.openpgp.org. Confirm its current image tag, internal listen port, persistent-data path, and configuration requirements before deploying. The sample assumes port `8000` and `/data`; change these to match the selected image. The scaffold does not configure TLS, DNS, or SMTP automatically.
- Docker Engine and Docker Compose v2
- GnuPG installed on the host for key export
- A domain you control and HTTPS for production
## Start
## Start the container
From this directory:
1. Copy `.env.example` to `.env`.
2. Review the Hagrid image's documentation and verify port and volume settings.
3. Run:
```bash
docker compose up -d --build
docker compose ps
curl -f http://localhost:8088/healthz
docker compose logs -f
```
Expected health response: `OK`. The service is available locally on port `8088`.
Frontend: `http://localhost:8088`. `/healthz` returns `OK`. Use HTTPS in production by placing this behind a trusted TLS reverse proxy.
## Publish a WKD key
## HKP
First ensure the public key for the target email address is in your local GPG keyring. Export **public keys only**; never export secret/private keys to this service.
On Linux, macOS, or WSL, run from this project directory:
Lookup a key:
```bash
./publish-wkd-key.sh user@example.com
curl -i 'http://localhost:8088/pks/lookup?op=get&search=user%40example.com'
```
The script uses `gpg-wks-client --print-wkd-hash` to compute the WKD filename, exports a binary public key into `wkd/hu/<hash>`, creates the `wkd/policy` marker, and exports an optional ASCII-armored copy into `keys/user@example.com.asc`.
The Docker container mounts `wkd/` and `keys/` read-only. Files added or updated on the host are served without rebuilding the image.
### Manual export (if you prefer)
GnuPG lookup:
```bash
HASH="$(gpg-wks-client --print-wkd-hash user@example.com | awk 'NR==1 {print $1}')"
mkdir -p wkd/hu
: > wkd/policy
gpg --batch --export user@example.com > "wkd/hu/$HASH"
gpg --keyserver hkp://localhost:8088 --search-keys FINGERPRINT
```
The WKD object should be a binary OpenPGP export. The public key must contain the intended email address in a user ID, and you should verify its fingerprint independently before publishing.
Submit an ASCII-armored public key:
## URL layout and DNS/HTTPS
```bash
gpg --armor --export user@example.com > publickey.asc
curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode keytext@publickey.asc http://localhost:8088/pks/add
```
This configuration implements the **direct method**. For `user@example.com`, the path is:
HKP upload does not verify email ownership. Use VKS for the verification workflow.
## VKS
Fetch by uppercase fingerprint (without `0x`):
```bash
curl -i 'http://localhost:8088/vks/v1/by-fingerprint/UPPERCASE_FINGERPRINT'
```
Fetch by key ID:
```bash
curl -i 'http://localhost:8088/vks/v1/by-keyid/UPPERCASE_KEY_ID'
```
Fetch by URL-encoded email (only published/verified addresses are discoverable):
```bash
curl -i 'http://localhost:8088/vks/v1/by-email/user%40example.com'
```
Upload a public key:
```bash
gpg --armor --export user@example.com > publickey.asc
python3 -c 'import json,pathlib; print(json.dumps({"keytext":pathlib.Path("publickey.asc").read_text()}))' > upload.json
curl -i -H 'Content-Type: application/json' --data-binary @upload.json http://localhost:8088/vks/v1/upload
```
The owner may need to complete an email-verification step before email lookup works. Configure SMTP as documented by the selected Hagrid image if using verification emails.
## WKD
The direct-method URL usually has this form:
```text
https://example.com/.well-known/openpgpkey/hu/<WKD_HASH>?l=user
https://example.com/.well-known/openpgpkey/hu/<z-base-32-hash>
```
The policy marker must be available at:
```text
https://example.com/.well-known/openpgpkey/policy
```
Replace `example.com` with your actual email domain. The Nginx container itself only speaks HTTP on port 80; put it behind your existing HTTPS reverse proxy and route the domain's requests to this service. The certificate must be valid for the email domain. WKD requires HTTPS; do not treat plain HTTP testing as production validation.
For the direct method, the email domain itself must serve `/.well-known/openpgpkey/`. If your main website already owns that domain, configure its reverse proxy to route that path to this service, or merge the WKD files and Nginx location into the existing web server. Do not simply point the whole domain at this container if that would replace your existing website.
The alternative **advanced method** uses `https://openpgpkey.example.com/.well-known/openpgpkey/example.com/...` and requires a dedicated `openpgpkey` subdomain with HTTPS. This sample is configured for the direct method only.
## Test WKD
After configuring DNS and HTTPS, use GnuPG from a client machine:
Use GnuPG to display the correct WKD hash:
```bash
gpg --locate-keys --auto-key-locate clear,nodefault,wkd user@example.com
gpg --with-wkd-hash --list-keys user@example.com
```
You can also check the raw key URL locally after publishing. Substitute the hash printed by the script:
Place the **binary public-key export** at the matching path beneath `wkd/`, for example `wkd/example.com/hu/<hash>`. WKD must be served from the correct email domain over HTTPS; a `keys.example.com` hostname does not automatically enable WKD for `example.com`.
Static downloadable key example:
```bash
curl -f http://localhost:8088/.well-known/openpgpkey/hu/<WKD_HASH>
gpg --armor --export user@example.com > keys/user@example.com.asc
curl -f http://localhost:8088/keys/user@example.com.asc
```
A successful local HTTP request verifies file serving only; final validation must use the public HTTPS URL and your real email domain.
## Security
## Security and maintenance
- Never publish private/secret keys.
- Use HTTPS in production and verify fingerprints via a separate trusted channel.
- Review and pin the Hagrid image rather than blindly using `latest`.
- Back up Hagrid's persistent data and `keys/` / `wkd/`.
- Monitor logs, rate limits and email verification; configure SMTP if required.
- This sample has not been tested against your actual image, reverse proxy, DNS or mail setup.
- Never put private keys, secret-key exports, passwords, or private key backups in `keys/` or `wkd/`.
- Public keys are public, but their association with an email address should be verified before publication.
- Directory listing is disabled; only GET and HEAD are allowed for key paths.
- WKD does not itself prove a key is safe or current. Publish updates and revocations when appropriate, and verify fingerprints through a separate trusted channel.
- The sample grants `Access-Control-Allow-Origin: *` only for WKD paths because browser-based clients may need cross-origin reads.
- Keep the reverse proxy and TLS certificates correctly configured and renewed.
## Troubleshooting
## Useful commands
```bash
docker compose logs -f gpg-keyserver
docker compose restart
docker compose down
docker compose up -d --build
```
- **502:** Hagrid may not be running or may use a different port; update `nginx.conf`.
- **404 VKS email lookup:** the key may be absent or the address not verified/published.
- **WKD failure:** check the HTTPS origin, hash, domain-specific path and binary key format.
## References
- [GnuPG Wiki: WKD](https://wiki.gnupg.org/WKD)
- [GnuPG Wiki: WKD hosting](https://wiki.gnupg.org/WKDHosting)
- [OpenPGP Web Key Directory specification draft](https://datatracker.ietf.org/doc/draft-koch-openpgp-webkey-service/)
- Hagrid API (HKP/VKS): https://keys.openpgp.org/about/api/
- WKD: https://wiki.gnupg.org/WKD
- Example community Docker image: https://hub.docker.com/r/jumper78/hagrid-openpgp