11/*
2- * Copyright 2020-2024 IEXEC BLOCKCHAIN TECH
2+ * Copyright 2020-2025 IEXEC BLOCKCHAIN TECH
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1717package com .iexec .worker .chain ;
1818
1919import com .iexec .commons .poco .security .Signature ;
20- import com .iexec .commons .poco .tee . TeeEnclaveChallengeSignature ;
20+ import com .iexec .commons .poco .utils . HashUtils ;
2121import com .iexec .commons .poco .utils .SignatureUtils ;
2222import org .junit .jupiter .api .Test ;
2323import org .junit .jupiter .api .extension .ExtendWith ;
@@ -41,77 +41,77 @@ class EnclaveAuthorizationServiceTests {
4141
4242 @ Test
4343 void isVerifiedEnclaveSignature () throws InvalidAlgorithmParameterException , NoSuchAlgorithmException , NoSuchProviderException {
44- String chainTaskId = "0x0000000000000000000000000000000000000000000000000000000000000001" ;
45- String resultHash = "0x0000000000000000000000000000000000000000000000000000000000000002" ;
46- String resultSeal = "0x0000000000000000000000000000000000000000000000000000000000000003" ;
44+ final String chainTaskId = "0x0000000000000000000000000000000000000000000000000000000000000001" ;
45+ final String resultHash = "0x0000000000000000000000000000000000000000000000000000000000000002" ;
46+ final String resultSeal = "0x0000000000000000000000000000000000000000000000000000000000000003" ;
4747
48- String messageHash = TeeEnclaveChallengeSignature . getMessageHash (resultHash , resultSeal );
49- Credentials credentials = Credentials .create (Keys .createEcKeyPair ());
48+ final String messageHash = HashUtils . concatenateAndHash (resultHash , resultSeal );
49+ final Credentials credentials = Credentials .create (Keys .createEcKeyPair ());
5050
51- String hexPrivateKey = Numeric .toHexStringWithPrefix (credentials .getEcKeyPair ().getPrivateKey ());
52- Signature signature = SignatureUtils .signMessageHashAndGetSignature (messageHash , hexPrivateKey );
51+ final String hexPrivateKey = Numeric .toHexStringWithPrefix (credentials .getEcKeyPair ().getPrivateKey ());
52+ final Signature signature = SignatureUtils .signMessageHashAndGetSignature (messageHash , hexPrivateKey );
5353
54- boolean isVerifiedEnclaveSignature = enclaveAuthorizationService .isVerifiedEnclaveSignature (chainTaskId , resultHash , resultSeal , signature .getValue (), credentials .getAddress ());
54+ final boolean isVerifiedEnclaveSignature = enclaveAuthorizationService .isVerifiedEnclaveSignature (chainTaskId , resultHash , resultSeal , signature .getValue (), credentials .getAddress ());
5555 assertThat (isVerifiedEnclaveSignature ).isTrue ();
5656 }
5757
5858 @ Test
5959 void isNotVerifiedEnclaveSignatureSinceWrongResultHash () throws InvalidAlgorithmParameterException , NoSuchAlgorithmException , NoSuchProviderException {
60- String chainTaskId = "0x0000000000000000000000000000000000000000000000000000000000000001" ;
61- String resultHash = "0x1" ;
62- String resultSeal = "0x0000000000000000000000000000000000000000000000000000000000000003" ;
60+ final String chainTaskId = "0x0000000000000000000000000000000000000000000000000000000000000001" ;
61+ final String resultHash = "0x1" ;
62+ final String resultSeal = "0x0000000000000000000000000000000000000000000000000000000000000003" ;
6363
64- String messageHash = TeeEnclaveChallengeSignature . getMessageHash (resultHash , resultSeal );
65- Credentials credentials = Credentials .create (Keys .createEcKeyPair ());
64+ final String messageHash = HashUtils . concatenateAndHash (resultHash , resultSeal );
65+ final Credentials credentials = Credentials .create (Keys .createEcKeyPair ());
6666
67- String hexPrivateKey = Numeric .toHexStringWithPrefix (credentials .getEcKeyPair ().getPrivateKey ());
68- Signature signature = SignatureUtils .signMessageHashAndGetSignature (messageHash , hexPrivateKey );
67+ final String hexPrivateKey = Numeric .toHexStringWithPrefix (credentials .getEcKeyPair ().getPrivateKey ());
68+ final Signature signature = SignatureUtils .signMessageHashAndGetSignature (messageHash , hexPrivateKey );
6969
70- boolean isVerifiedEnclaveSignature = enclaveAuthorizationService .isVerifiedEnclaveSignature (chainTaskId , resultHash , resultSeal , signature .getValue (), credentials .getAddress ());
70+ final boolean isVerifiedEnclaveSignature = enclaveAuthorizationService .isVerifiedEnclaveSignature (chainTaskId , resultHash , resultSeal , signature .getValue (), credentials .getAddress ());
7171 assertThat (isVerifiedEnclaveSignature ).isFalse ();
7272 }
7373
7474 @ Test
7575 void isNotVerifiedEnclaveSignatureSinceWrongResultSeal () throws InvalidAlgorithmParameterException , NoSuchAlgorithmException , NoSuchProviderException {
76- String chainTaskId = "0x0000000000000000000000000000000000000000000000000000000000000001" ;
77- String resultHash = "0x0000000000000000000000000000000000000000000000000000000000000002" ;
78- String resultSeal = "0x3" ;
76+ final String chainTaskId = "0x0000000000000000000000000000000000000000000000000000000000000001" ;
77+ final String resultHash = "0x0000000000000000000000000000000000000000000000000000000000000002" ;
78+ final String resultSeal = "0x3" ;
7979
80- String messageHash = TeeEnclaveChallengeSignature . getMessageHash (resultHash , resultSeal );
81- Credentials credentials = Credentials .create (Keys .createEcKeyPair ());
80+ final String messageHash = HashUtils . concatenateAndHash (resultHash , resultSeal );
81+ final Credentials credentials = Credentials .create (Keys .createEcKeyPair ());
8282
83- String hexPrivateKey = Numeric .toHexStringWithPrefix (credentials .getEcKeyPair ().getPrivateKey ());
84- Signature signature = SignatureUtils .signMessageHashAndGetSignature (messageHash , hexPrivateKey );
83+ final String hexPrivateKey = Numeric .toHexStringWithPrefix (credentials .getEcKeyPair ().getPrivateKey ());
84+ final Signature signature = SignatureUtils .signMessageHashAndGetSignature (messageHash , hexPrivateKey );
8585
86- boolean isVerifiedEnclaveSignature = enclaveAuthorizationService .isVerifiedEnclaveSignature (chainTaskId , resultHash , resultSeal , signature .getValue (), credentials .getAddress ());
86+ final boolean isVerifiedEnclaveSignature = enclaveAuthorizationService .isVerifiedEnclaveSignature (chainTaskId , resultHash , resultSeal , signature .getValue (), credentials .getAddress ());
8787 assertThat (isVerifiedEnclaveSignature ).isFalse ();
8888 }
8989
9090 @ Test
9191 void isNotVerifiedEnclaveSignatureSinceWrongEnclaveChallenge () throws InvalidAlgorithmParameterException , NoSuchAlgorithmException , NoSuchProviderException {
92- String chainTaskId = "0x0000000000000000000000000000000000000000000000000000000000000001" ;
93- String resultHash = "0x0000000000000000000000000000000000000000000000000000000000000002" ;
94- String resultSeal = "0x0000000000000000000000000000000000000000000000000000000000000003" ;
92+ final String chainTaskId = "0x0000000000000000000000000000000000000000000000000000000000000001" ;
93+ final String resultHash = "0x0000000000000000000000000000000000000000000000000000000000000002" ;
94+ final String resultSeal = "0x0000000000000000000000000000000000000000000000000000000000000003" ;
9595
96- String messageHash = TeeEnclaveChallengeSignature . getMessageHash (resultHash , resultSeal );
97- Credentials credentials = Credentials .create (Keys .createEcKeyPair ());
96+ final String messageHash = HashUtils . concatenateAndHash (resultHash , resultSeal );
97+ final Credentials credentials = Credentials .create (Keys .createEcKeyPair ());
9898
99- String hexPrivateKey = Numeric .toHexStringWithPrefix (credentials .getEcKeyPair ().getPrivateKey ());
100- Signature signature = SignatureUtils .signMessageHashAndGetSignature (messageHash , hexPrivateKey );
99+ final String hexPrivateKey = Numeric .toHexStringWithPrefix (credentials .getEcKeyPair ().getPrivateKey ());
100+ final Signature signature = SignatureUtils .signMessageHashAndGetSignature (messageHash , hexPrivateKey );
101101
102- boolean isVerifiedEnclaveSignature = enclaveAuthorizationService .isVerifiedEnclaveSignature (chainTaskId , resultHash , resultSeal , signature .getValue (), "0x1" );
102+ final boolean isVerifiedEnclaveSignature = enclaveAuthorizationService .isVerifiedEnclaveSignature (chainTaskId , resultHash , resultSeal , signature .getValue (), "0x1" );
103103 assertThat (isVerifiedEnclaveSignature ).isFalse ();
104104 }
105105
106106 @ Test
107107 void isNotVerifiedEnclaveSignatureSinceWrongEnclaveSignature () throws InvalidAlgorithmParameterException , NoSuchAlgorithmException , NoSuchProviderException {
108- String chainTaskId = "0x0000000000000000000000000000000000000000000000000000000000000001" ;
109- String resultHash = "0x0000000000000000000000000000000000000000000000000000000000000002" ;
110- String resultSeal = "0x0000000000000000000000000000000000000000000000000000000000000003" ;
108+ final String chainTaskId = "0x0000000000000000000000000000000000000000000000000000000000000001" ;
109+ final String resultHash = "0x0000000000000000000000000000000000000000000000000000000000000002" ;
110+ final String resultSeal = "0x0000000000000000000000000000000000000000000000000000000000000003" ;
111111
112- Credentials credentials = Credentials .create (Keys .createEcKeyPair ());
112+ final Credentials credentials = Credentials .create (Keys .createEcKeyPair ());
113113
114- boolean isVerifiedEnclaveSignature = enclaveAuthorizationService .isVerifiedEnclaveSignature (chainTaskId , resultHash , resultSeal , "0x1" , credentials .getAddress ());
114+ final boolean isVerifiedEnclaveSignature = enclaveAuthorizationService .isVerifiedEnclaveSignature (chainTaskId , resultHash , resultSeal , "0x1" , credentials .getAddress ());
115115 assertThat (isVerifiedEnclaveSignature ).isFalse ();
116116 }
117117}
0 commit comments