From 422f0cc31521745bbf13dffb1ffa2d68aef9eedf Mon Sep 17 00:00:00 2001 From: Julio Capote Date: Fri, 6 Jan 2023 13:19:04 -0500 Subject: move signer to registry --- registry/registry.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'registry/registry.go') 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( -- cgit v1.2.3