Skip to content

Commit 5d85961

Browse files
authored
Replace CredentialsService with SignerService (#602)
1 parent 4012615 commit 5d85961

22 files changed

+244
-183
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
88

99
- Add `iexec-core-library` dependency and use it. (#595)
1010
- Create `ConfigServerClient` instance and use it instead of `BlockchainAdapterApiClient`. (#596)
11+
- Replace `CredentialsService` with `SignerService`. (#602)
1112

1213
### Bug fixes
1314

build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ group = 'com.iexec.worker'
1313
ext {
1414
springCloudVersion = '2021.0.8'
1515
commonsMathsVersion = '3.6.1'
16+
testContainersVersion = '1.19.3'
1617
}
1718

1819
if (!project.hasProperty('gitBranch')) {
@@ -115,6 +116,9 @@ testing {
115116

116117
// awaitility
117118
implementation "org.awaitility:awaitility"
119+
120+
// testcontainers
121+
implementation "org.testcontainers:junit-jupiter:$testContainersVersion"
118122
}
119123
}
120124
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version=8.4.0
22
iexecCommonVersion=8.4.0-NEXT-SNAPSHOT
33
iexecCommonsContainersVersion=1.2.1
4-
iexecCommonsPocoVersion=3.2.0
4+
iexecCommonsPocoVersion=4.0.0-NEXT-SNAPSHOT
55
iexecResultVersion=8.4.0
66
iexecSmsVersion=8.5.1-NEXT-SNAPSHOT
77
iexecCoreVersion=8.4.1-NEXT-SNAPSHOT

src/main/java/com/iexec/worker/chain/CredentialsService.java

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/main/java/com/iexec/worker/chain/EnclaveAuthorizationService.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 IEXEC BLOCKCHAIN TECH
2+
* Copyright 2020-2024 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.
@@ -16,10 +16,10 @@
1616

1717
package com.iexec.worker.chain;
1818

19-
import com.iexec.common.utils.EthAddress;
2019
import com.iexec.commons.poco.security.Signature;
2120
import com.iexec.commons.poco.tee.TeeEnclaveChallengeSignature;
2221
import com.iexec.commons.poco.utils.BytesUtils;
22+
import com.iexec.commons.poco.utils.EthAddress;
2323
import com.iexec.commons.poco.utils.SignatureUtils;
2424
import lombok.extern.slf4j.Slf4j;
2525
import org.springframework.stereotype.Service;
@@ -39,23 +39,23 @@ public boolean isVerifiedEnclaveSignature(String chainTaskId,
3939
String baseErrorMessage =
4040
"Cannot verify enclave signature with invalid ";
4141
if (!BytesUtils.isNonZeroedBytes32(resultHash)) {
42-
log.error(baseErrorMessage + "result hash [chainTaskId:{}, " +
43-
"resultHash:{}]", chainTaskId, resultHash);
42+
log.error(baseErrorMessage + "result hash [chainTaskId:{}, resultHash:{}]",
43+
chainTaskId, resultHash);
4444
return false;
4545
}
4646
if (!BytesUtils.isNonZeroedBytes32(resultSeal)) {
47-
log.error(baseErrorMessage + "result seal [chainTaskId:{}, " +
48-
"resultSeal:{}]", chainTaskId, resultSeal);
47+
log.error(baseErrorMessage + "result seal [chainTaskId:{}, resultSeal:{}]",
48+
chainTaskId, resultSeal);
4949
return false;
5050
}
5151
if (!SignatureUtils.isSignature(enclaveSignature)) {
52-
log.error(baseErrorMessage + "enclave signature [chainTaskId:{}, " +
53-
"enclaveSignature:{}]", chainTaskId, enclaveSignature);
52+
log.error(baseErrorMessage + "enclave signature [chainTaskId:{}, enclaveSignature:{}]",
53+
chainTaskId, enclaveSignature);
5454
return false;
5555
}
5656
if (!EthAddress.validate(enclaveChallenge)) {
57-
log.error(baseErrorMessage + "enclave challenge [chainTaskId:{}, " +
58-
"enclaveChallenge:{}]", chainTaskId, enclaveChallenge);
57+
log.error(baseErrorMessage + "enclave challenge [chainTaskId:{}, enclaveChallenge:{}]",
58+
chainTaskId, enclaveChallenge);
5959
return false;
6060
}
6161

src/main/java/com/iexec/worker/chain/IexecHubService.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,20 @@
4848
public class IexecHubService extends IexecHubAbstractService implements Purgeable {
4949

5050
private static final String PENDING_RECEIPT_STATUS = "pending";
51-
private final CredentialsService credentialsService;
51+
private final SignerService signerService;
5252
private final ThreadPoolExecutor executor;
5353
private final Web3jService web3jService;
5454

5555
@Autowired
56-
public IexecHubService(CredentialsService credentialsService,
56+
public IexecHubService(SignerService signerService,
5757
Web3jService web3jService,
5858
ConfigServerConfigurationService configServerConfigurationService) {
59-
super(credentialsService.getCredentials(),
59+
super(signerService.getCredentials(),
6060
web3jService,
6161
configServerConfigurationService.getIexecHubContractAddress(),
6262
1,
6363
5);
64-
this.credentialsService = credentialsService;
64+
this.signerService = signerService;
6565
this.web3jService = web3jService;
6666
this.executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(1);
6767
}
@@ -89,7 +89,7 @@ private IexecHubContract.TaskContributeEventResponse sendContributeTransaction(C
8989
List<IexecHubContract.TaskContributeEventResponse> contributeEvents =
9090
IexecHubContract.getTaskContributeEvents(contributeReceipt).stream()
9191
.filter(event -> Objects.equals(bytesToString(event.taskid), chainTaskId)
92-
&& Objects.equals(event.worker, credentialsService.getCredentials().getAddress()))
92+
&& Objects.equals(event.worker, signerService.getAddress()))
9393
.collect(Collectors.toList());
9494
log.debug("contributeEvents count {} [chainTaskId: {}]", contributeEvents.size(), chainTaskId);
9595

@@ -124,7 +124,7 @@ private IexecHubContract.TaskRevealEventResponse sendRevealTransaction(String ch
124124
List<IexecHubContract.TaskRevealEventResponse> revealEvents =
125125
IexecHubContract.getTaskRevealEvents(revealReceipt).stream()
126126
.filter(event -> Objects.equals(bytesToString(event.taskid), chainTaskId)
127-
&& Objects.equals(event.worker, credentialsService.getCredentials().getAddress()))
127+
&& Objects.equals(event.worker, signerService.getAddress()))
128128
.collect(Collectors.toList());
129129
log.debug("revealEvents count {} [chainTaskId:{}]", revealEvents.size(), chainTaskId);
130130

@@ -239,15 +239,15 @@ private boolean isStatusValidOnChainAfterPendingReceipt(String chainTaskId, Chai
239239
// endregion
240240

241241
Optional<ChainContribution> getChainContribution(String chainTaskId) {
242-
return getChainContribution(chainTaskId, credentialsService.getCredentials().getAddress());
242+
return getChainContribution(chainTaskId, signerService.getAddress());
243243
}
244244

245245
Optional<ChainAccount> getChainAccount() {
246-
return getChainAccount(credentialsService.getCredentials().getAddress());
246+
return getChainAccount(signerService.getAddress());
247247
}
248248

249249
public boolean hasEnoughGas() {
250-
return web3jService.hasEnoughGas(credentialsService.getCredentials().getAddress());
250+
return web3jService.hasEnoughGas(signerService.getAddress());
251251
}
252252

253253
public long getLatestBlockNumber() {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2024 IEXEC BLOCKCHAIN TECH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.iexec.worker.chain;
18+
19+
import com.iexec.commons.poco.chain.SignerService;
20+
import lombok.Value;
21+
import org.springframework.boot.context.properties.ConfigurationProperties;
22+
import org.springframework.boot.context.properties.ConstructorBinding;
23+
import org.springframework.context.annotation.Bean;
24+
25+
@Value
26+
@ConstructorBinding
27+
@ConfigurationProperties(prefix = "wallet")
28+
public class WalletConfiguration {
29+
String encryptedFilePath;
30+
String password;
31+
32+
@Bean
33+
SignerService signerService(Web3jService web3jService) throws Exception {
34+
return new SignerService(web3jService.getWeb3j(), web3jService.getChainId(), password, encryptedFilePath);
35+
}
36+
37+
@Bean
38+
public String workerWalletAddress(SignerService signerService) {
39+
return signerService.getAddress();
40+
}
41+
}

src/main/java/com/iexec/worker/config/PublicConfigurationService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818

1919
import com.iexec.common.config.ConfigServerClient;
2020
import com.iexec.common.config.ConfigServerClientBuilder;
21+
import com.iexec.core.api.SchedulerClient;
2122
import com.iexec.core.config.PublicConfiguration;
2223
import com.iexec.resultproxy.api.ResultProxyClient;
2324
import com.iexec.resultproxy.api.ResultProxyClientBuilder;
24-
import com.iexec.worker.feign.CustomCoreFeignClient;
2525
import feign.Logger;
2626
import lombok.Getter;
2727
import org.apache.commons.lang3.StringUtils;
@@ -34,8 +34,8 @@ public class PublicConfigurationService {
3434

3535
private final PublicConfiguration publicConfiguration;
3636

37-
public PublicConfigurationService(CustomCoreFeignClient customCoreFeignClient) {
38-
this.publicConfiguration = customCoreFeignClient.getPublicConfiguration();
37+
public PublicConfigurationService(SchedulerClient schedulerClient) {
38+
this.publicConfiguration = schedulerClient.getPublicConfiguration();
3939
}
4040

4141
public String getSchedulerPublicAddress() {

src/main/java/com/iexec/worker/feign/CustomCoreFeignClient.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.iexec.common.config.WorkerModel;
2020
import com.iexec.common.replicate.ReplicateStatusUpdate;
2121
import com.iexec.core.api.SchedulerClient;
22-
import com.iexec.core.config.PublicConfiguration;
2322
import com.iexec.core.notification.TaskNotification;
2423
import com.iexec.core.notification.TaskNotificationType;
2524
import com.iexec.core.replicate.ReplicateTaskSummary;
@@ -75,12 +74,6 @@ public String getCoreVersion() {
7574
"getCoreVersion", null, null);
7675
}
7776

78-
public PublicConfiguration getPublicConfiguration() {
79-
return makeHttpCall(
80-
jwtToken -> coreClient.getPublicConfiguration(),
81-
"getPublicConfiguration", null, null);
82-
}
83-
8477
//TODO: Make registerWorker return Worker
8578
public void registerWorker(WorkerModel model) {
8679
makeHttpCall(

src/main/java/com/iexec/worker/feign/LoginService.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717
package com.iexec.worker.feign;
1818

19+
import com.iexec.commons.poco.chain.SignerService;
1920
import com.iexec.commons.poco.security.Signature;
2021
import com.iexec.commons.poco.utils.SignatureUtils;
2122
import com.iexec.core.api.SchedulerClient;
22-
import com.iexec.worker.chain.CredentialsService;
2323
import feign.FeignException;
2424
import lombok.extern.slf4j.Slf4j;
2525
import org.apache.commons.lang3.StringUtils;
@@ -36,12 +36,12 @@ public class LoginService {
3636
static final String TOKEN_PREFIX = "Bearer ";
3737
private String jwtToken;
3838

39-
private final CredentialsService credentialsService;
39+
private final SignerService signerService;
4040
private final SchedulerClient coreClient;
4141
private final ReentrantLock lock = new ReentrantLock();
4242

43-
LoginService(CredentialsService credentialsService, SchedulerClient coreClient) {
44-
this.credentialsService = credentialsService;
43+
LoginService(SignerService signerService, SchedulerClient coreClient) {
44+
this.signerService = signerService;
4545
this.coreClient = coreClient;
4646
}
4747

@@ -68,8 +68,8 @@ public String login() {
6868
final String oldToken = jwtToken;
6969
expireToken();
7070

71-
String workerAddress = credentialsService.getCredentials().getAddress();
72-
ECKeyPair ecKeyPair = credentialsService.getCredentials().getEcKeyPair();
71+
final String workerAddress = signerService.getCredentials().getAddress();
72+
final ECKeyPair ecKeyPair = signerService.getCredentials().getEcKeyPair();
7373

7474
final String challenge;
7575
try {
@@ -83,7 +83,7 @@ public String login() {
8383
return "";
8484
}
8585

86-
Signature signature = SignatureUtils.hashAndSign(challenge, workerAddress, ecKeyPair);
86+
final Signature signature = SignatureUtils.hashAndSign(challenge, ecKeyPair);
8787
final String token;
8888
try {
8989
token = coreClient.login(workerAddress, signature);

0 commit comments

Comments
 (0)