This is the main dovel repository, it has the Go code to run dovel SMTP server.
Author: blmayer (bleemayer@gmail.com)
Date: Thu Jun 22 20:38:06 2023 -0300
Parent: cf724e0
Added wkd support
commit d301a8d47986b3b5f360636fb6e56b7d0d356925 Author: blmayer <bleemayer@gmail.com> Date: Thu Jun 22 20:38:06 2023 -0300 Added wkd support diff --git a/util/wkd/wkd.go b/util/wkd/wkd.go new file mode 100644 index 0000000..1a86698 --- /dev/null +++ b/util/wkd/wkd.go @@ -0,0 +1,33 @@ +package wkd + +import ( + "crypto/sha1" + "fmt" + "net/http" + + pgp "github.com/ProtonMail/gopenpgp/v2/crypto" + "github.com/tv42/zbase32" +) + +const suffix = "/.well-known/openpgpkey/hu/" + +func FetchPGPKey(local, domain string) (string, error) { + s := sha1.Sum([]byte(local)) + slug := zbase32.EncodeToString(s[:]) + res, err := http.Get("https://" + domain + suffix + slug) + if err != nil { + return "", err + } + + if res.StatusCode > 399 { + return "", fmt.Errorf("key not found") + } + defer res.Body.Close() + + key, err := pgp.NewKeyFromReader(res.Body) + if err != nil { + return "", err + } + + return key.GetArmoredPublicKey() +}