Skip to content

Commit 2985431

Browse files
committed
cmd/age-keyserver: add transparency log of stored keys
1 parent ae8ad5e commit 2985431

9 files changed

Lines changed: 452 additions & 55 deletions

File tree

cmd/age-keylookup/main.go

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import (
77
"net/http"
88
"net/url"
99
"os"
10+
"strings"
1011
"time"
12+
13+
"filippo.io/torchwood"
14+
"golang.org/x/mod/sumdb/note"
15+
"golang.org/x/mod/sumdb/tlog"
1116
)
1217

1318
func main() {
@@ -22,6 +27,7 @@ func main() {
2227
fmt.Fprintf(os.Stderr, "\n")
2328
fmt.Fprintf(os.Stderr, "Environment:\n")
2429
fmt.Fprintf(os.Stderr, " AGE_KEYSERVER_URL Default keyserver URL\n")
30+
fmt.Fprintf(os.Stderr, " AGE_KEYSERVER_PUBKEY Default keyserver transparency log vkey\n")
2531
os.Exit(2)
2632
}
2733

@@ -33,7 +39,17 @@ func main() {
3339
server = "https://keyserver.geomys.org"
3440
}
3541

36-
pubkey, err := lookupKey(server, email)
42+
vkey := os.Getenv("AGE_KEYSERVER_PUBKEY")
43+
if vkey == "" {
44+
vkey = "keyserver.geomys.org+be45b77c+Ae58So8awYbwaF+V98htpY0xXlRcjhNuL5Ucrq9en2yp"
45+
}
46+
v, err := note.NewVerifier(vkey)
47+
if err != nil {
48+
fmt.Fprintf(os.Stderr, "Error: invalid keyserver public key: %v\n", err)
49+
os.Exit(1)
50+
}
51+
52+
pubkey, err := lookupKey(server, v, email)
3753
if err != nil {
3854
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
3955
os.Exit(1)
@@ -42,7 +58,10 @@ func main() {
4258
fmt.Println(pubkey)
4359
}
4460

45-
func lookupKey(serverURL, email string) (string, error) {
61+
func lookupKey(serverURL string, v note.Verifier, email string) (string, error) {
62+
// Normalize email
63+
email = strings.TrimSpace(strings.ToLower(email))
64+
4665
// Build the lookup URL
4766
lookupURL := serverURL + "/api/lookup?email=" + url.QueryEscape(email)
4867

@@ -72,6 +91,7 @@ func lookupKey(serverURL, email string) (string, error) {
7291
var result struct {
7392
Email string `json:"email"`
7493
Pubkey string `json:"pubkey"`
94+
Proof string `json:"proof"`
7595
}
7696

7797
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
@@ -85,5 +105,13 @@ func lookupKey(serverURL, email string) (string, error) {
85105
return "", fmt.Errorf("empty public key returned")
86106
}
87107

108+
// Verify spicy signature
109+
entry := fmt.Appendf(nil, "%s\n%s\n", result.Email, result.Pubkey)
110+
if err := torchwood.VerifyProof(v.Name(), func(b []byte) (*note.Note, error) {
111+
return note.Open(b, note.VerifierList(v))
112+
}, tlog.RecordHash(entry), []byte(result.Proof)); err != nil {
113+
return "", fmt.Errorf("failed to verify key proof: %w", err)
114+
}
115+
88116
return result.Pubkey, nil
89117
}

0 commit comments

Comments
 (0)