diff options
Diffstat (limited to 'registry/registry.go')
-rw-r--r-- | registry/registry.go | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/registry/registry.go b/registry/registry.go index dc83328..50986c9 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -2,9 +2,12 @@ package registry import ( "bytes" + "context" "crypto/x509" "encoding/gob" + "encoding/json" "encoding/pem" + "io" "net/http" "net/url" "strings" @@ -13,6 +16,10 @@ import ( "git.capotej.com/capotej/communique/models" "git.capotej.com/capotej/communique/urls" "git.capotej.com/capotej/communique/views" + "github.com/go-fed/activity/streams" + "github.com/go-fed/activity/streams/vocab" + "github.com/go-fed/httpsig" + "go.uber.org/zap" ) type Handler struct { @@ -24,9 +31,10 @@ type Registry struct { cfg config.Config persister *models.Persister handlerMap map[string]Handler + log *zap.SugaredLogger } -func NewRegistry(cfg config.Config, persister *models.Persister) (*Registry, error) { +func NewRegistry(cfg config.Config, persister *models.Persister, log *zap.SugaredLogger) (*Registry, error) { reg := Registry{cfg: cfg, persister: persister} reg.handlerMap = make(map[string]Handler) for _, v := range cfg.Handlers { @@ -153,10 +161,36 @@ func (r *Registry) Inbox(name string, req *http.Request) error { if handler == nil { return nil } - // verifier, err := httpsig.NewVerifier(req) - // if err != nil { - // return err - // } + logger := r.log.With("type", "inbox") + + verifier, err := httpsig.NewVerifier(req) + if err != nil { + return err + } + + keyId := verifier.KeyId() + logger.With("keyId", keyId).Debugf("fetching") + resp, err := http.Get(keyId) + if err != nil { + return err + } + defer resp.Body.Close() + keyPage, err := io.ReadAll(resp.Body) + logger.With("keyId", keyId).With("response", string(keyPage)).Debugf("received response") + var keyPageData map[string]interface{} + err = json.Unmarshal(keyPage, &keyPageData) + if err != nil { + return err + } + var t vocab.ActivityStreamsPerson + streams.ToType(context.Background(), keyPageData) + pubKeyProp := t.GetW3IDSecurityV1PublicKey() + iter := pubKeyProp.At(0) + pubKey := iter.Get() + pemProp := pubKey.GetW3IDSecurityV1PublicKeyPem() + pem := pemProp.Get() + logger.With("keyId", keyId).With("pem", pem).Debugf("extracted pem") + return nil } |