aboutsummaryrefslogtreecommitdiff
path: root/registry/registry.go
diff options
context:
space:
mode:
Diffstat (limited to 'registry/registry.go')
-rw-r--r--registry/registry.go32
1 files changed, 5 insertions, 27 deletions
diff --git a/registry/registry.go b/registry/registry.go
index e15d861..aa61d58 100644
--- a/registry/registry.go
+++ b/registry/registry.go
@@ -12,17 +12,15 @@ import (
"net/http"
"net/url"
"strings"
- "sync"
- "time"
"git.capotej.com/capotej/communique/config"
+ "git.capotej.com/capotej/communique/delivery"
"git.capotej.com/capotej/communique/models"
"git.capotej.com/capotej/communique/tools"
"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"
)
@@ -36,8 +34,7 @@ type Registry struct {
persister *models.Persister
handlerMap map[string]Handler
log *zap.SugaredLogger
- signer httpsig.Signer
- mu sync.Mutex
+ delivery *delivery.Signed
}
func NewRegistry(cfg config.Config, persister *models.Persister, log *zap.SugaredLogger) (*Registry, error) {
@@ -51,10 +48,7 @@ func NewRegistry(cfg config.Config, persister *models.Persister, log *zap.Sugare
return nil, err
}
}
- prefs := []httpsig.Algorithm{}
- digestAlgorithm := httpsig.DigestSha256
- headersToSign := []string{httpsig.RequestTarget, "host", "date", "digest"}
- reg.signer, _, err = httpsig.NewSigner(prefs, digestAlgorithm, headersToSign, httpsig.Signature, 0)
+ reg.delivery, err = delivery.NewSigned(persister)
if err != nil {
return nil, err
}
@@ -261,30 +255,14 @@ func (r *Registry) deliverAcceptToInbox(url, actorUrl, actorKeyUrl *url.URL, fol
return err
}
jsonData, err := json.Marshal(payload)
-
- aso := models.NewKeypair(handler)
- result, err := r.persister.Find(aso)
if err != nil {
return err
}
- buf := bytes.NewBuffer(result)
- dec := gob.NewDecoder(buf)
- var keypair models.Keypair
- err = dec.Decode(&keypair)
+
+ request, err := r.delivery.SignedRequest(handler, jsonData, url, actorKeyUrl)
if err != nil {
return err
}
- privKey := &keypair.PrivateKey
-
- request, err := http.NewRequest("POST", url.String(), bytes.NewBuffer(jsonData))
- date := time.Now().UTC().Format(http.TimeFormat)
- request.Header.Set("Date", date)
- request.Header.Set("Content-Type", "application/activity+json")
- request.Header.Set("Host", url.Host)
-
- r.mu.Lock()
- err = r.signer.SignRequest(privKey, actorKeyUrl.String(), request, jsonData)
- r.mu.Unlock()
r.log.With(
"type",