Skip to content

Commit 1084d9a

Browse files
committed
capabilities/v2/actions/confidentialrelay: Add applicationRequestID to ComputeRequest and hashing
Introduce the `ApplicationRequestID` field to the `ComputeRequest` struct. For non-legacy versions, this field is included in the computed hash to bind the application-specific request identity. For legacy versions, the field is excluded from the hash, maintaining compatibility with existing behavior.
1 parent 5fe4f9b commit 1084d9a

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

pkg/capabilities/v2/actions/confidentialrelay/computerequest.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func SignedComputeRequestSignaturePayload(computeRequestHash [32]byte) []byte {
4848
// authorized identity.
4949
type ComputeRequest struct {
5050
RequestID [32]byte `json:"requestID"`
51+
ApplicationRequestID string `json:"applicationRequestID"`
5152
PublicData []byte `json:"publicData"`
5253
Ciphertexts [][]byte `json:"ciphertexts"`
5354
CiphertextNames []string `json:"CiphertextNames"`
@@ -62,7 +63,8 @@ type ComputeRequest struct {
6263
// reuses this package's length-prefix helpers (writeBytes/writeString/
6364
// writeLengthPrefix), which are identical to the source's writeWithLength/
6465
// writeLengthPrefix. EncryptedDecryptionKeyShares is intentionally excluded, and
65-
// Version is included only for the legacy version, both matching the source.
66+
// Version is included only for the legacy version, and ApplicationRequestID is
67+
// included only for non-legacy versions, both matching the source.
6668
func (cr ComputeRequest) Hash() [32]byte {
6769
h := sha256.New()
6870

@@ -88,9 +90,12 @@ func (cr ComputeRequest) Hash() [32]byte {
8890

8991
writeString(h, cr.AppID)
9092
// Version is included in the hash only for the legacy version, matching
91-
// confidential-compute (which is migrating Version out of the hash).
93+
// confidential-compute (which is migrating Version out of the hash). Newer
94+
// versions bind the application-specific request ID instead.
9295
if cr.Version == computeRequestLegacyVersion {
9396
writeString(h, cr.Version)
97+
} else {
98+
writeString(h, cr.ApplicationRequestID)
9499
}
95100

96101
var result [32]byte

pkg/capabilities/v2/actions/confidentialrelay/computerequest_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ func sampleComputeRequest() ComputeRequest {
1313
}
1414
return ComputeRequest{
1515
RequestID: rid,
16+
ApplicationRequestID: "application-request-id",
1617
PublicData: []byte("public-data"),
1718
Ciphertexts: [][]byte{[]byte("ct-a"), []byte("ct-b")},
1819
CiphertextNames: []string{"name-a", "name-b"},
@@ -74,3 +75,21 @@ func TestComputeRequestHash_VersionOnlyHashedForLegacy(t *testing.T) {
7475
legacy.Version = computeRequestLegacyVersion
7576
require.NotEqual(t, legacy.Hash(), nonLegacyA.Hash(), "legacy Version must be bound into the hash")
7677
}
78+
79+
// ApplicationRequestID is the post-legacy replacement for binding application-level
80+
// request identity without constraining RequestID's 32-byte protocol shape.
81+
func TestComputeRequestHash_ApplicationRequestIDOnlyHashedForNonLegacy(t *testing.T) {
82+
legacyA := sampleComputeRequest()
83+
legacyA.ApplicationRequestID = "exec-a"
84+
legacyB := sampleComputeRequest()
85+
legacyB.ApplicationRequestID = "exec-b"
86+
require.Equal(t, legacyA.Hash(), legacyB.Hash(), "legacy ApplicationRequestID must not affect the hash")
87+
88+
nonLegacyA := sampleComputeRequest()
89+
nonLegacyA.Version = "0.0.7"
90+
nonLegacyA.ApplicationRequestID = "exec-a"
91+
nonLegacyB := sampleComputeRequest()
92+
nonLegacyB.Version = "0.0.7"
93+
nonLegacyB.ApplicationRequestID = "exec-b"
94+
require.NotEqual(t, nonLegacyA.Hash(), nonLegacyB.Hash(), "non-legacy ApplicationRequestID must be bound into the hash")
95+
}

0 commit comments

Comments
 (0)