@@ -127,19 +127,26 @@ func TestSecretsEndpoint_ECDSAAttestation(t *testing.T) {
127127
128128 n , mockCC := createTestNodeWithManager (t , manager )
129129
130- // Add test release
130+ // Generate ECDSA key pair for attestation. ECDSA /secrets binds the signer
131+ // to the app's on-chain creator, so the app ID must be a contract address
132+ // and its creator must equal the signer's address.
133+ appPrivateKey , err := crypto .GenerateKey ()
134+ require .NoError (t , err )
135+ appPublicKey := crypto .FromECDSAPub (& appPrivateKey .PublicKey )
136+ creatorAddr := crypto .PubkeyToAddress (appPrivateKey .PublicKey )
137+
138+ appAddr := common .HexToAddress ("0x00000000000000000000000000000000000ECD5A" )
139+ appID := appAddr .Hex ()
140+ mockCC .SetAppCreator (appAddr , creatorAddr )
141+
142+ // Add test release keyed on the app contract address
131143 testRelease := & kmsTypes.Release {
132144 ImageDigest : "ecdsa:unverified" , // ECDSA uses this default
133145 EncryptedEnv : "encrypted-env-data" ,
134146 PublicEnv : "PUBLIC_VAR=test-value" ,
135147 Timestamp : time .Now ().Unix (),
136148 }
137- mockCC .AddTestRelease ("ecdsa-test-app" , testRelease )
138-
139- // Generate ECDSA key pair for attestation
140- appPrivateKey , err := crypto .GenerateKey ()
141- require .NoError (t , err )
142- appPublicKey := crypto .FromECDSAPub (& appPrivateKey .PublicKey )
149+ mockCC .AddTestRelease (appID , testRelease )
143150
144151 // Generate challenge
145152 nonce := make ([]byte , attestation .NonceLength )
@@ -150,7 +157,7 @@ func TestSecretsEndpoint_ECDSAAttestation(t *testing.T) {
150157 require .NoError (t , err )
151158
152159 // Sign challenge
153- signature , err := attestation .SignChallenge (appPrivateKey , "ecdsa-test-app" , challenge )
160+ signature , err := attestation .SignChallenge (appPrivateKey , appID , challenge )
154161 require .NoError (t , err )
155162
156163 // Generate RSA key pair for response encryption
@@ -160,7 +167,7 @@ func TestSecretsEndpoint_ECDSAAttestation(t *testing.T) {
160167
161168 // Create ECDSA attestation request
162169 req := kmsTypes.SecretsRequestV1 {
163- AppID : "ecdsa-test-app" ,
170+ AppID : appID ,
164171 AttestationMethod : "ecdsa" ,
165172 Attestation : signature ,
166173 Challenge : []byte (challenge ),
@@ -211,24 +218,29 @@ func TestSecretsEndpoint_ECDSAWithExtraData(t *testing.T) {
211218
212219 n , mockCC := createTestNodeWithManager (t , manager )
213220
221+ appPrivateKey , err := crypto .GenerateKey ()
222+ require .NoError (t , err )
223+ appPublicKey := crypto .FromECDSAPub (& appPrivateKey .PublicKey )
224+ creatorAddr := crypto .PubkeyToAddress (appPrivateKey .PublicKey )
225+
226+ appAddr := common .HexToAddress ("0x00000000000000000000000000000000e57Ada7a" )
227+ appID := appAddr .Hex ()
228+ mockCC .SetAppCreator (appAddr , creatorAddr )
229+
214230 testRelease := & kmsTypes.Release {
215231 ImageDigest : "ecdsa:unverified" ,
216232 EncryptedEnv : "encrypted-env-data" ,
217233 PublicEnv : "PUBLIC_VAR=test-value" ,
218234 Timestamp : time .Now ().Unix (),
219235 }
220- mockCC .AddTestRelease ("extra-data-app" , testRelease )
221-
222- appPrivateKey , err := crypto .GenerateKey ()
223- require .NoError (t , err )
224- appPublicKey := crypto .FromECDSAPub (& appPrivateKey .PublicKey )
236+ mockCC .AddTestRelease (appID , testRelease )
225237
226238 nonce := make ([]byte , attestation .NonceLength )
227239 _ , err = rand .Read (nonce )
228240 require .NoError (t , err )
229241 challenge , err := attestation .GenerateChallenge (nonce )
230242 require .NoError (t , err )
231- signature , err := attestation .SignChallenge (appPrivateKey , "extra-data-app" , challenge )
243+ signature , err := attestation .SignChallenge (appPrivateKey , appID , challenge )
232244 require .NoError (t , err )
233245
234246 rsaEncrypt := encryption .NewRSAEncryption ()
@@ -238,7 +250,7 @@ func TestSecretsEndpoint_ECDSAWithExtraData(t *testing.T) {
238250 extraData := []byte (`{"action":"transfer","amount":"100","to":"0xdead"}` )
239251
240252 req := kmsTypes.SecretsRequestV1 {
241- AppID : "extra-data-app" ,
253+ AppID : appID ,
242254 AttestationMethod : "ecdsa" ,
243255 Attestation : signature ,
244256 Challenge : []byte (challenge ),
@@ -549,15 +561,6 @@ func TestSecretsEndpoint_BothMethodsEnabled(t *testing.T) {
549561 }
550562 mockCC .AddTestRelease ("test-app-gcp" , releaseGCP )
551563
552- // Add release for ECDSA
553- releaseECDSA := & kmsTypes.Release {
554- ImageDigest : "ecdsa:unverified" ,
555- EncryptedEnv : "ecdsa-env" ,
556- PublicEnv : "PUBLIC=ecdsa" ,
557- Timestamp : time .Now ().Unix (),
558- }
559- mockCC .AddTestRelease ("test-app-ecdsa" , releaseECDSA )
560-
561564 // Test 1: Use GCP method
562565 gcpClaims := kmsTypes.AttestationClaims {
563566 AppID : "test-app-gcp" ,
@@ -583,16 +586,27 @@ func TestSecretsEndpoint_BothMethodsEnabled(t *testing.T) {
583586
584587 assert .Equal (t , http .StatusOK , w .Code , "GCP method should succeed" )
585588
586- // Test 2: Use ECDSA method
589+ // Test 2: Use ECDSA method. ECDSA binds the signer to the app's on-chain
590+ // creator, so use a contract-address app ID whose creator is the signer.
587591 appPrivKey , _ := crypto .GenerateKey ()
588592 appPubKey := crypto .FromECDSAPub (& appPrivKey .PublicKey )
593+ ecdsaAppAddr := common .HexToAddress ("0x00000000000000000000000000000000b074ECDb" )
594+ ecdsaAppID := ecdsaAppAddr .Hex ()
595+ mockCC .SetAppCreator (ecdsaAppAddr , crypto .PubkeyToAddress (appPrivKey .PublicKey ))
596+ mockCC .AddTestRelease (ecdsaAppID , & kmsTypes.Release {
597+ ImageDigest : "ecdsa:unverified" ,
598+ EncryptedEnv : "ecdsa-env" ,
599+ PublicEnv : "PUBLIC=ecdsa" ,
600+ Timestamp : time .Now ().Unix (),
601+ })
602+
589603 nonce := make ([]byte , attestation .NonceLength )
590604 _ , _ = rand .Read (nonce )
591605 challenge , _ := attestation .GenerateChallenge (nonce )
592- signature , _ := attestation .SignChallenge (appPrivKey , "test-app-ecdsa" , challenge )
606+ signature , _ := attestation .SignChallenge (appPrivKey , ecdsaAppID , challenge )
593607
594608 reqECDSA := kmsTypes.SecretsRequestV1 {
595- AppID : "test-app-ecdsa" ,
609+ AppID : ecdsaAppID ,
596610 AttestationMethod : "ecdsa" ,
597611 Attestation : signature ,
598612 Challenge : []byte (challenge ),
0 commit comments