Commit 05cf3588 authored by ale's avatar ale
Browse files

Use hash@domain syntax for the openPGPKeyHash attribute

This allows quick lookups regardless of the domain (the WKD hash only
represents the local part of the uid).
parent a8d46fc1
Pipeline #30485 passed with stages
in 3 minutes and 35 seconds
......@@ -401,19 +401,22 @@ func splitAddress(addr string) (local, domain string, err error) {
return parts[0], parts[1], nil
}
// hashLocal returns the WKD hash for the local part of a given email address.
func hashLocal(local string) string {
local = strings.ToLower(local)
hashedLocal := sha1.Sum([]byte(local))
return zbase32.EncodeToString(hashedLocal[:])
}
// wkdHashAddress returns the WKD hash for the local part of a given email address.
// wkdHashAddress combines the WKD hash for the local part of a given
// email address, with the domain, to generate a site-wide unique
// identifier for quick WKD lookup.
func wkdHashAddress(addr string) (string, error) {
local, _, err := splitAddress(addr)
local, domain, err := splitAddress(addr)
if err != nil {
return "", err
}
return hashLocal(local), nil
return fmt.Sprintf("%s@%s", hashLocal(local), domain), nil
}
func parseOpenPGPKey(data []byte, email string) (key *crypto.Key, err error) {
......
......@@ -56,7 +56,7 @@ func TestIntegration_SetNewPGPKey(t *testing.T) {
if email.Email.OpenPGPKey.ID != testKey.GetHexKeyID() {
t.Fatalf("email.OpenPGPKey.ID mismatch: %s, expected %s", email.Email.OpenPGPKey.ID, testKey.GetHexKeyID())
}
if email.Email.OpenPGPKey.Hash != "og5xkb3w4f6n39ysbu6yx5btzg6pfke6" {
if email.Email.OpenPGPKey.Hash != "og5xkb3w4f6n39ysbu6yx5btzg6pfke6@investici.org" {
t.Fatalf("email.OpenPGPKey.Hash unexpected: %s", email.Email.OpenPGPKey.Hash)
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment