Skip to content

Commit 84591a3

Browse files
committed
Add ComplianceRegion to PrivateKey, NewRemoteSignerWithCertID, NewRemoteSigner
1 parent 091c159 commit 84591a3

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

client/client.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func (c *Client) getRemote(server string) (Remote, error) {
193193
// ski, sni, serverIP, and certID are used to identify the key by the remote
194194
// keyserver.
195195
func NewRemoteSignerWithCertID(ctx context.Context, c *Client, keyserver string, ski protocol.SKI,
196-
pub crypto.PublicKey, sni string, certID string, serverIP net.IP) (crypto.Signer, error) {
196+
pub crypto.PublicKey, sni string, certID string, serverIP net.IP, complianceRegion ...protocol.ComplianceRegion) (crypto.Signer, error) {
197197
span, _ := opentracing.StartSpanFromContext(ctx, "client.NewRemoteSignerWithCertID")
198198
defer span.Finish()
199199
priv := PrivateKey{
@@ -205,6 +205,9 @@ func NewRemoteSignerWithCertID(ctx context.Context, c *Client, keyserver string,
205205
keyserver: keyserver,
206206
certID: certID,
207207
}
208+
if len(complianceRegion) > 0 {
209+
priv.complianceRegion = complianceRegion[0]
210+
}
208211
var err error
209212
priv.JaegerSpan, err = tracing.SpanContextToBinary(span.Context())
210213
if err != nil {
@@ -223,7 +226,7 @@ func NewRemoteSignerWithCertID(ctx context.Context, c *Client, keyserver string,
223226
// ski, sni, and serverIP are used to identified the key by the remote
224227
// keyserver.
225228
func NewRemoteSigner(ctx context.Context, c *Client, keyserver string, ski protocol.SKI,
226-
pub crypto.PublicKey, sni string, serverIP net.IP) (crypto.Signer, error) {
229+
pub crypto.PublicKey, sni string, serverIP net.IP, complianceRegion ...protocol.ComplianceRegion) (crypto.Signer, error) {
227230

228231
span, _ := opentracing.StartSpanFromContext(ctx, "client.NewRemoteSignerWithCertID")
229232
defer span.Finish()
@@ -235,6 +238,10 @@ func NewRemoteSigner(ctx context.Context, c *Client, keyserver string, ski proto
235238
serverIP: serverIP,
236239
keyserver: keyserver,
237240
}
241+
242+
if len(complianceRegion) > 0 {
243+
priv.complianceRegion = complianceRegion[0]
244+
}
238245
var err error
239246
priv.JaegerSpan, err = tracing.SpanContextToBinary(span.Context())
240247
if err != nil {
@@ -254,24 +261,24 @@ func NewRemoteSigner(ctx context.Context, c *Client, keyserver string, ski proto
254261
// SKI is computed from the public key and along with sni and serverIP,
255262
// the remote Signer uses those key identification info to contact the
256263
// remote keyserver for keyless operations.
257-
func (c *Client) NewRemoteSignerTemplate(ctx context.Context, keyserver string, pub crypto.PublicKey, sni string, serverIP net.IP) (crypto.Signer, error) {
264+
func (c *Client) NewRemoteSignerTemplate(ctx context.Context, keyserver string, pub crypto.PublicKey, sni string, serverIP net.IP, complianceRegion ...protocol.ComplianceRegion) (crypto.Signer, error) {
258265
ski, err := protocol.GetSKI(pub)
259266
if err != nil {
260267
return nil, err
261268
}
262-
return NewRemoteSigner(ctx, c, keyserver, ski, pub, sni, serverIP)
269+
return NewRemoteSigner(ctx, c, keyserver, ski, pub, sni, serverIP, complianceRegion...)
263270
}
264271

265272
// NewRemoteSignerTemplateWithCertID returns a remote keyserver
266273
// based crypto.Signer with the public key.
267274
// SKI is computed from public key, and along with sni, serverIP, and
268275
// certID the remote signer uses these to contact the remote keyserver.
269-
func (c *Client) NewRemoteSignerTemplateWithCertID(ctx context.Context, keyserver string, pub crypto.PublicKey, sni string, serverIP net.IP, certID string) (crypto.Signer, error) {
276+
func (c *Client) NewRemoteSignerTemplateWithCertID(ctx context.Context, keyserver string, pub crypto.PublicKey, sni string, serverIP net.IP, certID string, complianceRegion ...protocol.ComplianceRegion) (crypto.Signer, error) {
270277
ski, err := protocol.GetSKI(pub)
271278
if err != nil {
272279
return nil, err
273280
}
274-
return NewRemoteSignerWithCertID(ctx, c, keyserver, ski, pub, sni, certID, serverIP)
281+
return NewRemoteSignerWithCertID(ctx, c, keyserver, ski, pub, sni, certID, serverIP, complianceRegion...)
275282
}
276283

277284
// NewRemoteSignerByPublicKey returns a remote keyserver based signer

client/keys.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ type PrivateKey struct {
9393

9494
// We have shove the span context inside PrivateKey because
9595
// it's used by calling functions on the `crypto.Signer` interface, which don't take ctx as a parameter.
96-
JaegerSpan []byte
96+
JaegerSpan []byte
97+
complianceRegion protocol.ComplianceRegion
9798
}
9899

99100
// Public returns the public key corresponding to the opaque private key.
@@ -124,13 +125,14 @@ func (key *PrivateKey) execute(ctx context.Context, op protocol.Op, msg []byte)
124125
// https://github.com/cloudflare/gokeyless/pull/276 makes it safe to fill it in,
125126
// but there's no way to know the version of the remote keyserver
126127
result, err = conn.Conn.DoOperation(ctx, protocol.Operation{
127-
Opcode: op,
128-
Payload: msg,
129-
SKI: key.ski,
130-
ClientIP: key.clientIP,
131-
ServerIP: key.serverIP,
132-
SNI: key.sni,
133-
CertID: key.certID,
128+
Opcode: op,
129+
Payload: msg,
130+
SKI: key.ski,
131+
ClientIP: key.clientIP,
132+
ServerIP: key.serverIP,
133+
SNI: key.sni,
134+
CertID: key.certID,
135+
ComplianceRegion: key.complianceRegion,
134136
})
135137
if err != nil {
136138
conn.Close()

0 commit comments

Comments
 (0)