Wrote the GnuPG WKD fetcher

This commit is contained in:
the-djmaze 2026-11-01 22:13:09 +01:00
parent 7ebd70418c
commit ef49cc142e

View file

@ -199,27 +199,33 @@ abstract class Keyservers
/**
* https://wiki.gnupg.org/WKD
* An example: https://snappymail.eu/.well-known/openpgpkey/hu/i4cdqgcarfjdjnba6y4jnf498asg8c6p
* is the direct method URL for "releases@snappymail.eu"
* gpg --with-wkd-hash --fingerprint releases@snappymail.eu
* gpg --no-armor --export releases@snappymail.eu > i4cdqgcarfjdjnba6y4jnf498asg8c6p
*/
public static function wkd(string $host, string $emailAddress)
public static function wkd(string $emailAddress): string|false
{
/*
$localPart = \explode('@', $emailAddress)[0];
$parts = \explode('@', $emailAddress);
$host = \array_pop($parts);
$localPart = \implode('@', $parts);
$b32 = new \SnappyMail\Base32('ybndrfg8ejkmcpqxot1uwisza345h769');
$keyid = $b32->encode(\sha1($localPart, true));
"https://{$host}/.well-known/openpgpkey/hu/{$keyid}";
/** https://wiki.gnupg.org/WKD
DNS:
openpgpkey.example.org. 300 IN CNAME wkd.keys.openpgp.org.
$oResponse = static::HTTP()->doRequest('GET', "https://openpgpkey.{$host}/.well-known/openpgpkey/{$host}/hu/{$keyid}");
if (!$oResponse || 200 !== $oResponse->status) {
$oResponse = static::HTTP()->doRequest('GET', "https://{$host}/.well-known/openpgpkey/hu/{$keyid}");
}
if (!$oResponse) {
\SnappyMail\Log::info('PGP', "No response for WKD key {$keyId} on {$host}");
return false;
}
if (200 !== $oResponse->status) {
\SnappyMail\Log::debug('PGP', "{$oResponse->status} for WKD key {$keyId} on {$host}");
return false;
}
https://openpgpkey.example.com/.well-known/openpgpkey/example.com/hu/
else https://example.com/.well-known/openpgpkey/hu/
An example: https://snappymail.eu/.well-known/openpgpkey/hu/i4cdqgcarfjdjnba6y4jnf498asg8c6p
is the direct method URL for "releases@snappymail.eu"
*/
return $oResponse->body;
}
public static function dns(string $host, string $keyid)