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