Skip to content

Publish a Web Key Directory

WKD distributes public OpenPGP keys over HTTPS. It supplies a domain source, not confirmation of personal identity.

Setup

Prepare your values and Debian packages. Use publicly trusted certificates; the laboratory test uses an explicitly local test CA.

Prepare OpenPGP. For direct WKD, the mailbox domain DOMAIN must be reachable over HTTPS with a certificate for that name. On existing webservers, merge only the WKD location into the relevant virtual host.

Select the same webserver as during installation. These examples create a dedicated HTTPS virtual host; for existing virtual hosts, merge the path configuration there instead of creating a duplicate host for the same name.

set -euo pipefail
. /root/mailserver.env
export GNUPGHOME=/root/mail-pgp
FPR=$(gpg --with-colons --fingerprint "$MAILBOX" | awk -F: '$1=="fpr" {print $10; exit}')
HASH=$(gpg-wks-client --print-wkd-hash "$MAILBOX" | awk '{print $1}')
test -n "$HASH"
install -d -m 0755 /var/www/wkd/.well-known/openpgpkey/hu
gpg --export-options export-minimal --export "$FPR" > "/var/www/wkd/.well-known/openpgpkey/hu/$HASH"
chmod 0644 "/var/www/wkd/.well-known/openpgpkey/hu/$HASH"
touch /var/www/wkd/.well-known/openpgpkey/policy
cat > /etc/nginx/sites-available/mail-wkd <<EOF
server {
    listen 443 ssl;
    server_name $DOMAIN;
    ssl_certificate /etc/letsencrypt/live/$DOMAIN/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/$DOMAIN/privkey.pem;
    location /.well-known/openpgpkey/ {
        root /var/www/wkd;
        default_type application/octet-stream;
        add_header Access-Control-Allow-Origin "*" always;
    }
    location / { return 404; }
}
EOF
ln -sfn /etc/nginx/sites-available/mail-wkd /etc/nginx/sites-enabled/mail-wkd
nginx -t
systemctl reload nginx
set -euo pipefail
. /root/mailserver.env
export GNUPGHOME=/root/mail-pgp
FPR=$(gpg --with-colons --fingerprint "$MAILBOX" | awk -F: '$1=="fpr" {print $10; exit}')
HASH=$(gpg-wks-client --print-wkd-hash "$MAILBOX" | awk '{print $1}')
test -n "$HASH"
install -d -m 0755 /var/www/wkd/.well-known/openpgpkey/hu
gpg --export-options export-minimal --export "$FPR" > "/var/www/wkd/.well-known/openpgpkey/hu/$HASH"
chmod 0644 "/var/www/wkd/.well-known/openpgpkey/hu/$HASH"
touch /var/www/wkd/.well-known/openpgpkey/policy
a2enmod ssl headers
cat > /etc/apache2/sites-available/mail-wkd.conf <<EOF
<VirtualHost *:443>
    ServerName $DOMAIN
    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/$DOMAIN/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/$DOMAIN/privkey.pem
    Alias "/.well-known/openpgpkey/" "/var/www/wkd/.well-known/openpgpkey/"
    <Directory "/var/www/wkd/.well-known">
        Options None
        AllowOverride None
        Require all granted
    </Directory>
    <Location "/.well-known/openpgpkey/">
        ForceType application/octet-stream
        Header always set Access-Control-Allow-Origin "*"
    </Location>
    RedirectMatch 404 "^/(?!\\.well-known/openpgpkey/).*"
</VirtualHost>
EOF
a2ensite mail-wkd.conf
apache2ctl configtest
systemctl enable --now apache2
systemctl reload apache2

Test

set -euo pipefail
. /root/mailserver.env
HASH=$(gpg-wks-client --print-wkd-hash "$MAILBOX" | awk '{print $1}')
curl --fail --silent --show-error --resolve "$DOMAIN:443:127.0.0.1" \
  "https://$DOMAIN/.well-known/openpgpkey/hu/$HASH" > /root/mail-tests/wkd-public.gpg
export GNUPGHOME=/root/mail-pgp
expected=$(gpg --with-colons --fingerprint "$MAILBOX" | awk -F: '$1=="fpr" {print $10; exit}')
actual=$(gpg --batch --show-keys --with-colons /root/mail-tests/wkd-public.gpg | awk -F: '$1=="fpr" {print $10; exit}')
test "$actual" = "$expected"
echo 'PASS: HTTPS returns your expected public key.'

Also check discovery externally with curl without --resolve and gpg --auto-key-locate clear,wkd --locate-keys MAILBOX in an empty user keyring. An existing openpgpkey host can influence the advanced method. Update the actually published snapshot on key changes or revocation. GnuPG WKD guide.

RateMyMail can check WKD for supported PGP/MIME signatures with wkd: true and an isolated openpgp_socket. It defaults to disabled. Each check fetches fresh candidates without a cross-message key cache. The request reveals the From mailbox to the domain operator and must be covered by the privacy notice. The report separates discovery method, domain/UID finding, signature validity and revocation snapshot. A positive WKD finding neither confirms personal identity nor authorizes a reply.