Skip to content

Commit be2bda9

Browse files
Merge pull request #325 from iExecBlockchainComputing/release/5.0.0
Release/5.0.0
2 parents 435b54a + a255a60 commit be2bda9

File tree

64 files changed

+1774
-2554
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1774
-2554
lines changed

Dockerfile

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
FROM azul/zulu-openjdk-alpine:11.0.3-jre
1+
FROM openjdk:11.0.7-jre-slim
22

3-
RUN apk add --no-cache bash coreutils openssl zip
3+
RUN apt-get update && apt-get install -y --no-install-recommends bash coreutils openssl zip
44

55
ENV IEXEC_DECRYPT_FILE_PATH "/decrypt-dataset.sh"
66
ENV IEXEC_ENCRYPT_FILE_PATH "/encrypt-result.sh"
@@ -9,10 +9,6 @@ COPY build/resources/main/decrypt-dataset.sh /decrypt-dataset.sh
99
COPY build/resources/main/encrypt-result.sh /encrypt-result.sh
1010
COPY build/resources/main/entrypoint.sh entrypoint.sh
1111

12-
# Default certificate will only be valid at 'https://localhost:[...]' (and not at 'https://core:[...]' for e.g.)
13-
COPY build/resources/main/ssl-keystore-dev.p12 /ssl/ssl-truststore.p12
14-
ENV IEXEC_WORKER_SSL_TRUSTSTORE /ssl/ssl-truststore.p12
15-
1612
RUN chmod +x /decrypt-dataset.sh && \
1713
chmod +x /encrypt-result.sh && \
1814
chmod +x entrypoint.sh

build.gradle

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ dependencyManagement {
5858
dependencies {
5959
// iexec
6060
compile "com.iexec.common:iexec-common:$iexecCommonVersion"
61-
// compile files("../iexec-common/build/libs/iexec-common-${iexecCommonVersion}.jar")
61+
//compile files("../iexec-common/build/libs/iexec-common-${iexecCommonVersion}.jar")
6262

6363
// spring
6464
compile("org.springframework.boot:spring-boot-starter") {
@@ -72,6 +72,10 @@ dependencies {
7272
compile "org.springframework.retry:spring-retry"
7373
testCompile "org.springframework.boot:spring-boot-starter-test"
7474

75+
// Web3j issues, see core build.gradle
76+
implementation 'com.squareup.okhttp3:okhttp:4.3.1'
77+
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.3.50'
78+
7579
// docker-client
7680
compile 'com.spotify:docker-client:8.13.1'
7781
compile 'org.glassfish.jersey.inject:jersey-hk2:2.26'
@@ -143,7 +147,7 @@ uploadArchives.enabled = canUploadArchives
143147

144148
test {
145149
if (System.properties['test.profile'] == 'skipDocker') {
146-
exclude '**/docker/**'
150+
exclude '**/compute/DockerServiceTests*'
147151
}
148152
}
149153

@@ -177,7 +181,7 @@ task buildImage(type: Exec) {
177181
}
178182

179183
buildImage.dependsOn prepareDockerFile
180-
buildImage.enabled = isMasterBranch || project.hasProperty("forceDockerBuild")
184+
buildImage.enabled = (isMasterBranch || isDevelopBranch ) || project.hasProperty("forceDockerBuild")
181185

182186
task pushImage(type: Exec) {
183187
if (project.hasProperty("nexusUser") && project.hasProperty("nexusPassword")) {
@@ -192,7 +196,7 @@ task pushImage(type: Exec) {
192196
}
193197

194198
pushImage.dependsOn buildImage
195-
pushImage.enabled = isMasterBranch && project.hasProperty("nexusUser") && project.hasProperty("nexusPassword")
199+
pushImage.enabled = (isMasterBranch || isDevelopBranch ) && project.hasProperty("nexusUser") && project.hasProperty("nexusPassword")
196200

197201
//gradle bootRun -PproxyHost=192.168.XX.XXX -PproxyPort=3128
198202
project.ext.getJvmArgs = {

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
iexecCommonVersion=4.0.1
1+
iexecCommonVersion=5.0.0
22
nexusUser=fake
33
nexusPassword=fake
4-
version=4.0.2
4+
version=5.0.0

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

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

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

Lines changed: 66 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package com.iexec.worker.chain;
22

33
import com.iexec.common.chain.*;
4-
import com.iexec.common.contract.generated.IexecHubABILegacy;
4+
import com.iexec.common.contract.generated.IexecHubContract;
5+
import com.iexec.common.contribution.Contribution;
56
import com.iexec.common.replicate.ReplicateStatusCause;
6-
import com.iexec.common.security.Signature;
7+
import com.iexec.common.result.ComputedFile;
78
import com.iexec.common.utils.BytesUtils;
8-
import com.iexec.common.utils.HashUtils;
9-
import com.iexec.common.utils.SignatureUtils;
10-
9+
import com.iexec.common.worker.result.ResultUtils;
1110
import lombok.extern.slf4j.Slf4j;
1211
import org.springframework.stereotype.Service;
1312

@@ -22,20 +21,18 @@
2221
public class ContributionService {
2322

2423
private IexecHubService iexecHubService;
25-
private ContributionAuthorizationService contributionAuthorizationService;
24+
private WorkerpoolAuthorizationService workerpoolAuthorizationService;
25+
private EnclaveAuthorizationService enclaveAuthorizationService;
26+
private CredentialsService credentialsService;
2627

2728
public ContributionService(IexecHubService iexecHubService,
28-
ContributionAuthorizationService contributionAuthorizationService) {
29+
WorkerpoolAuthorizationService workerpoolAuthorizationService,
30+
EnclaveAuthorizationService enclaveAuthorizationService,
31+
CredentialsService credentialsService) {
2932
this.iexecHubService = iexecHubService;
30-
this.contributionAuthorizationService = contributionAuthorizationService;
31-
}
32-
33-
public static String computeResultSeal(String walletAddress, String chainTaskId, String deterministHash) {
34-
return HashUtils.concatenateAndHash(walletAddress, chainTaskId, deterministHash);
35-
}
36-
37-
public static String computeResultHash(String chainTaskId, String deterministHash) {
38-
return HashUtils.concatenateAndHash(chainTaskId, deterministHash);
33+
this.workerpoolAuthorizationService = workerpoolAuthorizationService;
34+
this.enclaveAuthorizationService = enclaveAuthorizationService;
35+
this.credentialsService = credentialsService;
3936
}
4037

4138
public boolean isChainTaskInitialized(String chainTaskId) {
@@ -66,20 +63,20 @@ public Optional<ReplicateStatusCause> getCannotContributeStatusCause(String chai
6663
return Optional.of(CONTRIBUTION_ALREADY_SET);
6764
}
6865

69-
if (!isContributionAuthorizationPresent(chainTaskId)) {
70-
return Optional.of(CONTRIBUTION_AUTHORIZATION_NOT_FOUND);
66+
if (!isWorkerpoolAuthorizationPresent(chainTaskId)) {
67+
return Optional.of(CONTRIBUTION_AUTHORIZATION_NOT_FOUND);//TODO Rename status to WORKERPOOL_AUTHORIZATION_NOT_FOUND
7168
}
7269

7370
return Optional.empty();
7471
}
7572

76-
private boolean isContributionAuthorizationPresent(String chainTaskId) {
77-
ContributionAuthorization contributionAuthorization =
78-
contributionAuthorizationService.getContributionAuthorization(chainTaskId);
79-
if (contributionAuthorization != null){
73+
private boolean isWorkerpoolAuthorizationPresent(String chainTaskId) {
74+
WorkerpoolAuthorization workerpoolAuthorization =
75+
workerpoolAuthorizationService.getWorkerpoolAuthorization(chainTaskId);
76+
if (workerpoolAuthorization != null) {
8077
return true;
8178
}
82-
log.error("ContributionAuthorization missing [chainTaskId:{}]", chainTaskId);
79+
log.error("WorkerpoolAuthorization missing [chainTaskId:{}]", chainTaskId);
8380
return false;
8481
}
8582

@@ -108,14 +105,6 @@ private boolean isContributionUnsetToContribute(ChainTask chainTask) {
108105
return chainContribution.getStatus().equals(ChainContributionStatus.UNSET);
109106
}
110107

111-
public boolean isContributionAuthorizationValid(ContributionAuthorization auth, String signerAddress) {
112-
// create the hash that was used in the signature in the core
113-
byte[] message = BytesUtils.stringToBytes(
114-
HashUtils.concatenateAndHash(auth.getWorkerWallet(), auth.getChainTaskId(), auth.getEnclaveChallenge()));
115-
116-
return SignatureUtils.isSignatureValid(message, auth.getSignature(), signerAddress);
117-
}
118-
119108
public boolean isContributionDeadlineReached(String chainTaskId) {
120109
Optional<ChainTask> oTask = iexecHubService.getChainTask(chainTaskId);
121110
if (!oTask.isPresent()) return true;
@@ -124,30 +113,64 @@ public boolean isContributionDeadlineReached(String chainTaskId) {
124113
}
125114

126115
// returns ChainReceipt of the contribution if successful, null otherwise
127-
public Optional<ChainReceipt> contribute(ContributionAuthorization contribAuth, String deterministHash, Signature enclaveSignature) {
128-
String resultSeal = computeResultSeal(contribAuth.getWorkerWallet(), contribAuth.getChainTaskId(), deterministHash);
129-
String resultHash = computeResultHash(contribAuth.getChainTaskId(), deterministHash);
130-
IexecHubABILegacy.TaskContributeEventResponse contributeResponse = iexecHubService.contribute(contribAuth, resultHash, resultSeal, enclaveSignature);
116+
public Optional<ChainReceipt> contribute(Contribution contribution) {
117+
118+
IexecHubContract.TaskContributeEventResponse contributeResponse = iexecHubService.contribute(contribution);
131119

132120
if (contributeResponse == null) {
133-
log.error("ContributeTransactionReceipt received but was null [chainTaskId:{}]", contribAuth.getChainTaskId());
121+
log.error("ContributeTransactionReceipt received but was null [chainTaskId:{}]", contribution.getChainTaskId());
134122
return Optional.empty();
135123
}
136124

137-
ChainReceipt chainReceipt = ChainUtils.buildChainReceipt(contributeResponse.log, contribAuth.getChainTaskId(),
125+
ChainReceipt chainReceipt = ChainUtils.buildChainReceipt(contributeResponse.log, contribution.getChainTaskId(),
138126
iexecHubService.getLatestBlockNumber());
139127

140-
141-
142128
return Optional.of(chainReceipt);
143129
}
144130

145-
public boolean putContributionAuthorization(ContributionAuthorization contributionAuthorization) {
146-
return contributionAuthorizationService.putContributionAuthorization(contributionAuthorization);
131+
public boolean putWorkerpoolAuthorization(WorkerpoolAuthorization workerpoolAuthorization) {
132+
return workerpoolAuthorizationService.putWorkerpoolAuthorization(workerpoolAuthorization);
133+
}
134+
135+
public WorkerpoolAuthorization getWorkerpoolAuthorization(String chainTaskId) {
136+
return workerpoolAuthorizationService.getWorkerpoolAuthorization(chainTaskId);
147137
}
148138

149-
public ContributionAuthorization getContributionAuthorization(String chainTaskId) {
150-
return contributionAuthorizationService.getContributionAuthorization(chainTaskId);
139+
public Contribution getContribution(ComputedFile computedFile) {
140+
String chainTaskId = computedFile.getTaskId();
141+
WorkerpoolAuthorization workerpoolAuthorization = workerpoolAuthorizationService.getWorkerpoolAuthorization(chainTaskId);
142+
if (workerpoolAuthorization == null) {
143+
log.error("Cant getContribution (cant getWorkerpoolAuthorization) [chainTaskId:{}]", chainTaskId);
144+
return null;
145+
}
146+
147+
String resultDigest = computedFile.getResultDigest();
148+
String resultHash = ResultUtils.computeResultHash(chainTaskId, resultDigest);
149+
String resultSeal = ResultUtils.computeResultSeal(credentialsService.getCredentials().getAddress(), chainTaskId, resultDigest);
150+
String workerpoolSignature = workerpoolAuthorization.getSignature().getValue();
151+
String enclaveChallenge = workerpoolAuthorization.getEnclaveChallenge();
152+
String enclaveSignature = computedFile.getEnclaveSignature();
153+
154+
boolean isTeeTask = iexecHubService.isTeeTask(chainTaskId);
155+
if (isTeeTask) {
156+
if (!enclaveAuthorizationService.isVerifiedEnclaveSignature(chainTaskId,
157+
resultHash, resultSeal, enclaveSignature, enclaveChallenge)){
158+
log.error("Cant getContribution (isVerifiedEnclaveSignature false) [chainTaskId:{}]", chainTaskId);
159+
return null;
160+
}
161+
} else {
162+
enclaveSignature = BytesUtils.EMPTY_HEXASTRING_64;
163+
}
164+
165+
return Contribution.builder()
166+
.chainTaskId(chainTaskId)
167+
.resultDigest(resultDigest)
168+
.resultHash(resultHash)
169+
.resultSeal(resultSeal)
170+
.enclaveChallenge(enclaveChallenge)
171+
.enclaveSignature(enclaveSignature)
172+
.workerPoolSignature(workerpoolSignature)
173+
.build();
151174
}
152175

153176
}
Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,17 @@
11
package com.iexec.worker.chain;
22

3-
import lombok.extern.slf4j.Slf4j;
4-
import org.springframework.stereotype.Service;
5-
import org.web3j.crypto.CipherException;
6-
import org.web3j.crypto.Credentials;
7-
import org.web3j.crypto.WalletUtils;
3+
import com.iexec.common.chain.CredentialsAbstractService;
84

9-
import java.io.IOException;
5+
import org.springframework.beans.factory.annotation.Value;
6+
import org.springframework.stereotype.Service;
107

11-
@Slf4j
128
@Service
13-
public class CredentialsService {
14-
15-
private Credentials credentials;
16-
17-
public CredentialsService(WalletDetails walletDetails) throws IOException, CipherException {
18-
try {
19-
credentials = WalletUtils.loadCredentials(walletDetails.getPassword(), walletDetails.getPath());
20-
log.info("Load wallet credentials [address:{}] ", credentials.getAddress());
21-
} catch (IOException | CipherException e) {
22-
log.error("Credentials cannot be loaded [exception:{}] ", e);
23-
throw e;
24-
}
25-
}
9+
public class CredentialsService extends CredentialsAbstractService {
2610

27-
public Credentials getCredentials() {
28-
return credentials;
11+
public CredentialsService(
12+
@Value("${wallet.password}") String walletPassword,
13+
@Value("${wallet.encryptedFilePath}") String walletPath
14+
) throws Exception {
15+
super(walletPassword, walletPath);
2916
}
30-
}
17+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.iexec.worker.chain;
2+
3+
import com.iexec.common.security.Signature;
4+
import com.iexec.common.tee.TeeEnclaveChallengeSignature;
5+
import lombok.extern.slf4j.Slf4j;
6+
import org.springframework.stereotype.Service;
7+
8+
import static com.iexec.common.utils.SignatureUtils.isExpectedSignerOnSignedMessageHash;
9+
10+
11+
@Slf4j
12+
@Service
13+
public class EnclaveAuthorizationService {
14+
15+
public boolean isVerifiedEnclaveSignature(String chainTaskId, String resultHash, String resultSeal,
16+
String enclaveSignature, String enclaveChallenge) {
17+
if (enclaveChallenge == null || enclaveChallenge.isEmpty()) {
18+
log.error("Cant verify enclave signature (enclave challenge not found) [chainTaskId:{}]", chainTaskId);
19+
return false;
20+
}
21+
22+
if (enclaveSignature == null || enclaveSignature.isEmpty()) {
23+
log.error("Cant verify enclave signature (enclave signature not found) [chainTaskId:{}]", chainTaskId);
24+
return false;
25+
}
26+
27+
String messageHash = TeeEnclaveChallengeSignature.getMessageHash(resultHash, resultSeal);
28+
29+
return isExpectedSignerOnSignedMessageHash(messageHash,
30+
new Signature(enclaveSignature), enclaveChallenge);
31+
}
32+
}

0 commit comments

Comments
 (0)