Skip to content

Commit abdcefb

Browse files
committed
Adds ComplianceRegion to Op protocol
1 parent 6aa62fb commit abdcefb

File tree

4 files changed

+75
-31
lines changed

4 files changed

+75
-31
lines changed

protocol/protocol.go

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"github.com/cloudflare/cfssl/helpers/derhelpers"
2222
)
2323

24-
//go:generate stringer -type=Tag,Op -output=protocol_string.go
24+
//go:generate stringer -type=Tag,Op,ComplianceRegion -output=protocol_string.go
2525

2626
// Tag marks the type of an Item.
2727
type Tag byte
@@ -51,6 +51,8 @@ const (
5151
TagJaegerSpan Tag = 0x15
5252
// TagReqContext contains request metadata
5353
TagReqContext Tag = 0x16
54+
// TagComplianceRegion implies the compliance region of the operation which can impact behavior
55+
TagComplianceRegion Tag = 0x17
5456
// TagPadding implies an item with a meaningless payload added for padding.
5557
TagPadding Tag = 0x20
5658
)
@@ -202,6 +204,16 @@ func (e Error) String() string {
202204
}
203205
}
204206

207+
// ComplianceRegion describes any guardrails that gokeyless should follow when accessing data from
208+
// external applications
209+
type ComplianceRegion byte
210+
211+
const (
212+
// ComplianceRegionFedRAMPHigh signals that this operation should only interact
213+
// with the FedRAMP High QS instance
214+
ComplianceRegionFedRAMPHigh ComplianceRegion = 0x01
215+
)
216+
205217
const (
206218
paddedLength = 1024
207219
headerSize = 8
@@ -405,30 +417,32 @@ func (p *Packet) ReadFrom(r io.Reader) (n int64, err error) {
405417

406418
// Operation defines a single (repeatable) keyless operation.
407419
type Operation struct {
408-
Opcode Op
409-
Payload []byte
410-
Extra []byte
411-
SKI SKI
412-
Digest Digest
413-
ClientIP net.IP
414-
ServerIP net.IP
415-
SNI string
416-
CertID string
417-
ForwardingSvc int64
418-
CustomFuncName string
419-
JaegerSpan []byte
420-
ReqContext []byte
420+
Opcode Op
421+
Payload []byte
422+
Extra []byte
423+
SKI SKI
424+
Digest Digest
425+
ClientIP net.IP
426+
ServerIP net.IP
427+
SNI string
428+
CertID string
429+
ForwardingSvc int64
430+
CustomFuncName string
431+
JaegerSpan []byte
432+
ReqContext []byte
433+
ComplianceRegion ComplianceRegion
421434
}
422435

423436
func (o *Operation) String() string {
424-
return fmt.Sprintf("[Opcode: %v, SKI: %v, Digest: %02x, Client IP: %s, Server IP: %s, SNI: %s, Forwarding Service: %v]",
437+
return fmt.Sprintf("[Opcode: %v, SKI: %v, Digest: %02x, Client IP: %s, Server IP: %s, SNI: %s, Forwarding Service: %v, ComplianceRegion %v]",
425438
o.Opcode,
426439
o.SKI,
427440
o.Digest,
428441
o.ClientIP,
429442
o.ServerIP,
430443
o.SNI,
431444
o.ForwardingSvc,
445+
o.ComplianceRegion,
432446
)
433447
}
434448

@@ -512,6 +526,8 @@ func (o *Operation) Bytes() uint16 {
512526
if o.ReqContext != nil {
513527
add(tlvLen(len(o.ReqContext)))
514528
}
529+
// compliance region
530+
add(tlvLen(1))
515531
if int(length)+headerSize < paddedLength {
516532
// TODO: Are we sure that's the right behavior?
517533

@@ -586,6 +602,8 @@ func (o *Operation) MarshalBinary() ([]byte, error) {
586602
b = append(b, tlvBytes(TagReqContext, o.ReqContext)...)
587603
}
588604

605+
b = append(b, tlvBytes(TagComplianceRegion, []byte{byte(o.ComplianceRegion)})...)
606+
589607
if len(b)+headerSize < paddedLength {
590608
// TODO: Are we sure that's the right behavior?
591609

@@ -673,6 +691,11 @@ func (o *Operation) UnmarshalBinary(body []byte) error {
673691
o.JaegerSpan = data
674692
case TagReqContext:
675693
o.ReqContext = data
694+
case TagComplianceRegion:
695+
if len(data) != 1 {
696+
return fmt.Errorf("invalid ComplianceRegion: %s", data)
697+
}
698+
o.ComplianceRegion = ComplianceRegion(data[0])
676699
default:
677700
// Silently ignore any unknown tags (to allow for new tags to be gradually added to the protocol).
678701
continue

protocol/protocol.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ The following tag values are possible for items:
3939
0x13 - CustomFuncName, (for use with opcode 0x24)
4040
0x14 - Supplemental payload, whose meaning is not specified and must be predetermined between the server and client,
4141
0x15 - Binary encoded Jaeger span (https://www.jaegertracing.io/docs/1.19/client-libraries/#value)
42+
0x17 - ComplianceRegion,
4243

4344
A requests contains a header and the following items:
4445

protocol/protocol_string.go

Lines changed: 23 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protocol/protocol_test.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,19 @@ func TestMarshalBinary(t *testing.T) {
2323
rand.Read(payload)
2424
rand.Read(reqCtx)
2525
op := Operation{
26-
Opcode: OpECDSASignSHA256,
27-
Payload: payload,
28-
Extra: extra,
29-
Digest: sha256.Sum256([]byte("Digest")),
30-
SKI: sha1.Sum([]byte("SKI")),
31-
ClientIP: net.ParseIP("1.1.1.1").To4(),
32-
ServerIP: net.ParseIP("2.2.2.2").To4(),
33-
SNI: "SNI",
34-
CertID: "SNI",
35-
CustomFuncName: "CustomFuncName",
36-
JaegerSpan: []byte("615f730ad5fe896f:615f730ad5fe896f:1"),
37-
ReqContext: reqCtx,
26+
Opcode: OpECDSASignSHA256,
27+
Payload: payload,
28+
Extra: extra,
29+
Digest: sha256.Sum256([]byte("Digest")),
30+
SKI: sha1.Sum([]byte("SKI")),
31+
ClientIP: net.ParseIP("1.1.1.1").To4(),
32+
ServerIP: net.ParseIP("2.2.2.2").To4(),
33+
SNI: "SNI",
34+
CertID: "SNI",
35+
CustomFuncName: "CustomFuncName",
36+
JaegerSpan: []byte("615f730ad5fe896f:615f730ad5fe896f:1"),
37+
ReqContext: reqCtx,
38+
ComplianceRegion: ComplianceRegionFedRAMPHigh,
3839
}
3940
pkt := NewPacket(42, op)
4041
b, err := pkt.MarshalBinary()

0 commit comments

Comments
 (0)