diff options
author | Julio Capote <jcapote@gmail.com> | 2023-01-06 18:19:04 +0000 |
---|---|---|
committer | Julio Capote <jcapote@gmail.com> | 2023-01-06 18:19:04 +0000 |
commit | 422f0cc31521745bbf13dffb1ffa2d68aef9eedf (patch) | |
tree | 3008a6d9f911cfcb1ff1a628be6b8129038f4479 /registry/registry.go | |
parent | 54bb7670eaff9218f3e67e39abab8902674842c6 (diff) | |
download | communique-422f0cc31521745bbf13dffb1ffa2d68aef9eedf.tar.gz |
move signer to registry
Diffstat (limited to 'registry/registry.go')
-rw-r--r-- | registry/registry.go | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/registry/registry.go b/registry/registry.go index c6c317c..dc5dff2 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -43,13 +43,21 @@ type Registry struct { func NewRegistry(cfg config.Config, persister *models.Persister, log *zap.SugaredLogger) (*Registry, error) { reg := Registry{cfg: cfg, persister: persister, log: log} reg.handlerMap = make(map[string]Handler) + var err error for _, v := range cfg.Handlers { reg.handlerMap[v.Name] = Handler{handlerCfg: v} - err := generateKeypairIfNeeded(v, persister) + err = generateKeypairIfNeeded(v, persister) if err != nil { 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) + if err != nil { + return nil, err + } return ®, nil } @@ -263,14 +271,7 @@ func (r *Registry) deliverAcceptToInbox(url, actorUrl, actorKeyUrl *url.URL, fol request.Header.Set("Host", url.Host) r.mu.Lock() - prefs := []httpsig.Algorithm{} - digestAlgorithm := httpsig.DigestSha256 - headersToSign := []string{httpsig.RequestTarget, "host", "date", "digest"} - signer, _, err := httpsig.NewSigner(prefs, digestAlgorithm, headersToSign, httpsig.Signature, 0) - if err != nil { - return err - } - err = signer.SignRequest(privKey, actorKeyUrl.String(), request, jsonData) + err = r.signer.SignRequest(privKey, actorKeyUrl.String(), request, jsonData) r.mu.Unlock() r.log.With( |