github.com/prebid/prebid-server/v2@v2.18.0/experiment/adscert/inprocesssigner.go (about) 1 package adscert 2 3 import ( 4 "crypto/rand" 5 "time" 6 7 "github.com/IABTechLab/adscert/pkg/adscert/api" 8 "github.com/IABTechLab/adscert/pkg/adscert/discovery" 9 "github.com/IABTechLab/adscert/pkg/adscert/signatory" 10 "github.com/benbjohnson/clock" 11 "github.com/prebid/prebid-server/v2/config" 12 ) 13 14 // inProcessSigner holds the signatory to add adsCert header to requests using in process go library 15 type inProcessSigner struct { 16 signatory signatory.AuthenticatedConnectionsSignatory 17 } 18 19 // Sign adds adsCert header to requests using in process go library 20 func (ips *inProcessSigner) Sign(destinationURL string, body []byte) (string, error) { 21 req := &api.AuthenticatedConnectionSignatureRequest{ 22 RequestInfo: createRequestInfo(destinationURL, body), 23 } 24 signatureResponse, err := ips.signatory.SignAuthenticatedConnection(req) 25 if err != nil { 26 return "", err 27 } 28 return getSignatureMessage(signatureResponse) 29 } 30 31 func newInProcessSigner(inProcessSignerConfig config.AdsCertInProcess) (*inProcessSigner, error) { 32 return &inProcessSigner{ 33 signatory: signatory.NewLocalAuthenticatedConnectionsSignatory( 34 inProcessSignerConfig.Origin, 35 rand.Reader, 36 clock.New(), 37 discovery.NewDefaultDnsResolver(), 38 discovery.NewDefaultDomainStore(), 39 time.Duration(inProcessSignerConfig.DNSCheckIntervalInSeconds)*time.Second, 40 time.Duration(inProcessSignerConfig.DNSRenewalIntervalInSeconds)*time.Second, 41 []string{inProcessSignerConfig.PrivateKey}), 42 }, nil 43 }