File tree Expand file tree Collapse file tree 3 files changed +63
-1
lines changed
Expand file tree Collapse file tree 3 files changed +63
-1
lines changed Original file line number Diff line number Diff line change 11# go-openpgp-wks
2- A Go library for OpenPGP Web Key Service
2+
3+ A Go library for [ OpenPGP Web Key Service] ( https://tools.ietf.org/html/draft-koch-openpgp-webkey-service-04 ) .
4+
5+ ## License
6+
7+ MIT
Original file line number Diff line number Diff line change 1+ package wks
2+
3+ import (
4+ "crypto/sha1"
5+ "errors"
6+ "io"
7+ "net/http"
8+ "strings"
9+
10+ "github.com/tv42/zbase32"
11+ "golang.org/x/crypto/openpgp"
12+ "golang.org/x/crypto/openpgp/packet"
13+ )
14+
15+ func splitAddress (addr string ) (local , domain string , err error ) {
16+ parts := strings .Split (addr , "@" )
17+ if len (parts ) != 2 {
18+ return "" , "" , errors .New ("wks: invalid email address" )
19+ }
20+ return parts [0 ], parts [1 ], nil
21+ }
22+
23+ // Discover retrieves keys associated to an email address.
24+ func Discover (addr string ) ([]* openpgp.Entity , error ) {
25+ local , domain , err := splitAddress (strings .ToLower (addr ))
26+ if err != nil {
27+ return nil , err
28+ }
29+
30+ // TODO: SRV record
31+
32+ hashedLocal := sha1 .Sum ([]byte (local ))
33+ url := "https://" + domain + "/.well-known/openpgpkey/hu/" + zbase32 .EncodeToString (hashedLocal [:])
34+ resp , err := http .Get (url )
35+ if err != nil {
36+ return nil , err
37+ }
38+ defer resp .Body .Close ()
39+
40+ r := packet .NewReader (resp .Body )
41+ var entities []* openpgp.Entity
42+ for {
43+ e , err := openpgp .ReadEntity (r )
44+ if err == io .EOF {
45+ break
46+ } else if err != nil {
47+ return entities , err
48+ }
49+
50+ entities = append (entities , e )
51+ }
52+
53+ return entities , nil
54+ }
Original file line number Diff line number Diff line change 1+ // wks implements OpenPGP Web Key Service, defined in
2+ // https://tools.ietf.org/html/draft-koch-openpgp-webkey-service-04
3+ package wks
You can’t perform that action at this time.
0 commit comments