github.com/prebid/prebid-server/v2@v2.18.0/experiment/adscert/remotesigner.go (about) 1 package adscert 2 3 import ( 4 "fmt" 5 "time" 6 7 "github.com/IABTechLab/adscert/pkg/adscert/api" 8 "github.com/IABTechLab/adscert/pkg/adscert/signatory" 9 "github.com/prebid/prebid-server/v2/config" 10 "google.golang.org/grpc" 11 "google.golang.org/grpc/credentials/insecure" 12 ) 13 14 // remoteSigner holds the signatory to add adsCert header to requests using remote signing server 15 type remoteSigner struct { 16 signatory signatory.AuthenticatedConnectionsSignatory 17 } 18 19 // Sign adds adsCert header to requests using remote signing server 20 func (rs *remoteSigner) Sign(destinationURL string, body []byte) (string, error) { 21 signatureResponse, err := rs.signatory.SignAuthenticatedConnection( 22 &api.AuthenticatedConnectionSignatureRequest{ 23 RequestInfo: createRequestInfo(destinationURL, []byte(body)), 24 }) 25 if err != nil { 26 return "", err 27 } 28 return getSignatureMessage(signatureResponse) 29 } 30 31 func newRemoteSigner(remoteSignerConfig config.AdsCertRemote) (*remoteSigner, error) { 32 // Establish the gRPC connection that the client will use to connect to the 33 // signatory server. Secure connections are not implemented at this time. 34 opts := []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())} 35 conn, err := grpc.Dial(remoteSignerConfig.Url, opts...) 36 if err != nil { 37 return nil, fmt.Errorf("failed to dial remote signer: %v", err) 38 } 39 40 clientOpts := &signatory.AuthenticatedConnectionsSignatoryClientOptions{ 41 Timeout: time.Duration(remoteSignerConfig.SigningTimeoutMs) * time.Millisecond} 42 signatoryClient := signatory.NewAuthenticatedConnectionsSignatoryClient(conn, clientOpts) 43 return &remoteSigner{signatory: signatoryClient}, nil 44 45 }