-
Notifications
You must be signed in to change notification settings - Fork 29
Add EnclaveConfig to confidentialrelay request params (PRIV-458) #2063
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nadahalli
wants to merge
6
commits into
main
Choose a base branch
from
tejaswi/priv-458-relay-enclave-config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+222
−9
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
291b651
Add EnclaveConfig to confidentialrelay request params (PRIV-458)
nadahalli ae64545
Mark EnclavePublicKey on SecretsRequestParams as Deprecated
nadahalli 40a8e4c
Revert EnclavePublicKey Deprecated annotation
nadahalli 4f5ce0d
Merge remote-tracking branch 'origin/main' into tejaswi/priv-458-rela…
nadahalli 131baa9
Merge branch 'main' into tejaswi/priv-458-relay-enclave-config
nadahalli 69656ee
Merge branch 'main' into tejaswi/priv-458-relay-enclave-config
nadahalli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,13 +29,28 @@ func mustCapabilityHash(t *testing.T, r CapabilityResponseResult, p CapabilityRe | |
| return h | ||
| } | ||
|
|
||
| func validEnclaveConfig() EnclaveConfig { | ||
| return EnclaveConfig{ | ||
| Signers: [][]byte{ | ||
| {0x01, 0x02, 0x03}, | ||
| {0x04, 0x05, 0x06}, | ||
| {0x07, 0x08, 0x09}, | ||
| {0x0a, 0x0b, 0x0c}, | ||
| }, | ||
| MasterPublicKey: []byte("master-public-key"), | ||
| T: 2, | ||
| F: 1, | ||
| } | ||
| } | ||
|
|
||
| func validSecretsParams() SecretsRequestParams { | ||
| return SecretsRequestParams{ | ||
| WorkflowID: "wf-1", | ||
| Owner: validOwnerA, | ||
| ExecutionID: validExecutionID, | ||
| OrgID: "org-1", | ||
| EnclavePublicKey: validEnclavePubKey, | ||
| EnclaveConfig: validEnclaveConfig(), | ||
| Attestation: "att-a", | ||
| Secrets: []SecretIdentifier{ | ||
| {Key: "alpha", Namespace: "ns-a"}, | ||
|
|
@@ -45,13 +60,14 @@ func validSecretsParams() SecretsRequestParams { | |
|
|
||
| func validCapabilityParams() CapabilityRequestParams { | ||
| return CapabilityRequestParams{ | ||
| WorkflowID: "wf-1", | ||
| Owner: validOwnerA, | ||
| ExecutionID: validExecutionID, | ||
| ReferenceID: "42", | ||
| CapabilityID: "[email protected]", | ||
| Payload: "request-payload", | ||
| Attestation: "att-a", | ||
| WorkflowID: "wf-1", | ||
| Owner: validOwnerA, | ||
| ExecutionID: validExecutionID, | ||
| ReferenceID: "42", | ||
| CapabilityID: "[email protected]", | ||
| Payload: "request-payload", | ||
| EnclaveConfig: validEnclaveConfig(), | ||
| Attestation: "att-a", | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -297,3 +313,122 @@ func TestRelayResponseSignaturePayload_UsesExpectedPrefix(t *testing.T) { | |
| require.Equal(t, expected, RelayResponseSignaturePayload(hash)) | ||
| require.NotEqual(t, hash[:], RelayResponseSignaturePayload(hash)) | ||
| } | ||
|
|
||
| // TestValidateEnclaveConfig covers the EnclaveConfig validation added for | ||
| // PRIV-458 / CL112-01. The relay needs each request to carry a non-empty | ||
| // signers list, non-zero F, and a non-empty MasterPublicKey so it can | ||
| // meaningfully compare against onchain DON state. | ||
| func TestValidateEnclaveConfig(t *testing.T) { | ||
| t.Run("valid config accepted", func(t *testing.T) { | ||
| require.NoError(t, validateEnclaveConfig(validEnclaveConfig())) | ||
| }) | ||
| t.Run("missing signers rejected", func(t *testing.T) { | ||
| c := validEnclaveConfig() | ||
| c.Signers = nil | ||
| require.Error(t, validateEnclaveConfig(c)) | ||
| }) | ||
| t.Run("empty signer rejected", func(t *testing.T) { | ||
| c := validEnclaveConfig() | ||
| c.Signers = append(c.Signers, []byte{}) | ||
| err := validateEnclaveConfig(c) | ||
| require.Error(t, err) | ||
| require.Contains(t, err.Error(), "signers[") | ||
| }) | ||
| t.Run("F=0 rejected", func(t *testing.T) { | ||
| c := validEnclaveConfig() | ||
| c.F = 0 | ||
| require.Error(t, validateEnclaveConfig(c)) | ||
| }) | ||
| t.Run("empty master_public_key rejected", func(t *testing.T) { | ||
| c := validEnclaveConfig() | ||
| c.MasterPublicKey = nil | ||
| require.Error(t, validateEnclaveConfig(c)) | ||
| }) | ||
| } | ||
|
|
||
| // TestSecretsRequestParams_Validate_RequiresEnclaveConfig covers that the | ||
| // Validate gate rejects requests missing the EnclaveConfig. | ||
| func TestSecretsRequestParams_Validate_RequiresEnclaveConfig(t *testing.T) { | ||
| p := validSecretsParams() | ||
| p.EnclaveConfig = EnclaveConfig{} | ||
| require.Error(t, p.Validate()) | ||
| } | ||
|
|
||
| // TestCapabilityRequestParams_Validate_RequiresEnclaveConfig same as above | ||
| // for the capability execute path. | ||
| func TestCapabilityRequestParams_Validate_RequiresEnclaveConfig(t *testing.T) { | ||
| p := validCapabilityParams() | ||
| p.EnclaveConfig = EnclaveConfig{} | ||
| require.Error(t, p.Validate()) | ||
| } | ||
|
|
||
| // TestSecretsResponseHash_BindsEnclaveConfig proves the response signature | ||
| // hash differs when EnclaveConfig differs. If the hash did not bind | ||
| // EnclaveConfig, two responses signed over the same secrets but with | ||
| // different enclave configs would have indistinguishable signatures. | ||
| func TestSecretsResponseHash_BindsEnclaveConfig(t *testing.T) { | ||
| params := validSecretsParams() | ||
| result := SecretsResponseResult{ | ||
| Secrets: []SecretEntry{ | ||
| { | ||
| ID: SecretIdentifier{Key: "alpha", Namespace: "ns-a"}, | ||
| Ciphertext: "cipher-a", | ||
| EncryptedShares: []string{"share-a1"}, | ||
| }, | ||
| }, | ||
| } | ||
| base := mustSecretsHash(t, result, params) | ||
|
|
||
| changed := params | ||
| changed.EnclaveConfig.F = params.EnclaveConfig.F + 1 | ||
| require.NotEqual(t, base, mustSecretsHash(t, result, changed)) | ||
|
|
||
| changed2 := params | ||
| changed2.EnclaveConfig.T = params.EnclaveConfig.T + 1 | ||
| require.NotEqual(t, base, mustSecretsHash(t, result, changed2)) | ||
|
|
||
| changed3 := params | ||
| changed3.EnclaveConfig.MasterPublicKey = append([]byte(nil), params.EnclaveConfig.MasterPublicKey...) | ||
| changed3.EnclaveConfig.MasterPublicKey[0] ^= 0xff | ||
| require.NotEqual(t, base, mustSecretsHash(t, result, changed3)) | ||
|
|
||
| changed4 := params | ||
| changed4.EnclaveConfig.Signers = append([][]byte(nil), params.EnclaveConfig.Signers...) | ||
| changed4.EnclaveConfig.Signers = append(changed4.EnclaveConfig.Signers, []byte{0xff}) | ||
| require.NotEqual(t, base, mustSecretsHash(t, result, changed4)) | ||
| } | ||
|
|
||
| // TestCapabilityResponseHash_BindsEnclaveConfig same as above for the | ||
| // capability execute path. | ||
| func TestCapabilityResponseHash_BindsEnclaveConfig(t *testing.T) { | ||
| params := validCapabilityParams() | ||
| result := CapabilityResponseResult{Payload: "out"} | ||
| base := mustCapabilityHash(t, result, params) | ||
|
|
||
| changed := params | ||
| changed.EnclaveConfig.F = params.EnclaveConfig.F + 1 | ||
| require.NotEqual(t, base, mustCapabilityHash(t, result, changed)) | ||
| } | ||
|
|
||
| // TestSecretsResponseHash_StableUnderSignerReordering proves that the | ||
| // EnclaveConfig.Signers ordering does not affect the hash. The relay-side | ||
| // comparison against onchain state is order-independent so the hash must be | ||
| // too, otherwise an enclave permuting Signers (or a different ordering | ||
| // emitted across reboots) would invalidate signatures over identical | ||
| // logical state. | ||
| func TestSecretsResponseHash_StableUnderSignerReordering(t *testing.T) { | ||
| params := validSecretsParams() | ||
| result := SecretsResponseResult{ | ||
| Secrets: []SecretEntry{ | ||
| {ID: SecretIdentifier{Key: "alpha", Namespace: "ns-a"}, Ciphertext: "c", EncryptedShares: []string{"s"}}, | ||
| }, | ||
| } | ||
| base := mustSecretsHash(t, result, params) | ||
|
|
||
| reversed := params | ||
| reversed.EnclaveConfig.Signers = make([][]byte, len(params.EnclaveConfig.Signers)) | ||
| for i, s := range params.EnclaveConfig.Signers { | ||
| reversed.EnclaveConfig.Signers[len(params.EnclaveConfig.Signers)-1-i] = s | ||
| } | ||
| require.Equal(t, base, mustSecretsHash(t, result, reversed)) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note I'm pretty sure we shouldn't be putting in audit tags in our code; I'm not entirely sure why that is, but the recommendation is to link to JIRA and add the audit ref there