Files
ep-docker-gpg-keyserver/publish-wkd-key.sh
T
2026-10-10 22:30:42 +03:00

34 lines
1.2 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
if [[ $# -ne 1 ]]; then
echo "Usage: $0 user@example.com" >&2
exit 2
fi
email="$1"
command -v gpg >/dev/null || { echo "gpg is required" >&2; exit 1; }
command -v gpg-wks-client >/dev/null || { echo "gpg-wks-client is required (usually included with GnuPG)" >&2; exit 1; }
# GnuPG computes the standardized SHA-1 + z-base-32 WKD local-part hash.
hash="$(gpg-wks-client --print-wkd-hash "$email" | awk 'NR==1 {print $1}')"
if [[ ! "$hash" =~ ^[a-z0-9]{32}$ ]]; then
echo "Could not determine a valid WKD hash for: $email" >&2
exit 1
fi
mkdir -p "wkd/hu" "keys"
# WKD serves the binary OpenPGP public-key export, not an ASCII-armored file.
gpg --batch --export "$email" > "wkd/hu/$hash"
if [[ ! -s "wkd/hu/$hash" ]]; then
rm -f "wkd/hu/$hash"
echo "No public key exported for $email. Check that the key is in your GPG keyring." >&2
exit 1
fi
: > wkd/policy
# Also retain an optional human-downloadable armored copy.
gpg --armor --batch --export "$email" > "keys/$email.asc"
echo "Published WKD key for $email"
echo "WKD hash: $hash"
echo "Direct-method URL path: /.well-known/openpgpkey/hu/$hash?l=${email%@*}"
echo "Local test: curl -f http://localhost:8088/.well-known/openpgpkey/hu/$hash"