Skip to content

Commit 434857f

Browse files
authored
feat: add TDX SMS support and load cache in SmsService at startup (#762)
1 parent 2358967 commit 434857f

File tree

10 files changed

+184
-114
lines changed

10 files changed

+184
-114
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# x-release-please-start-version
22
version=9.0.0
33
# x-release-please-end
4-
iexecCommonsPocoVersion=5.1.0
4+
iexecCommonsPocoVersion=5.2.0
55
iexecCommonVersion=9.1.0
66
iexecBlockchainAdapterVersion=9.0.0
77
iexecResultVersion=9.0.0
Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,51 @@
1+
/*
2+
* Copyright 2022-2025 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+
117
package com.iexec.core.registry;
218

3-
import lombok.Getter;
19+
import jakarta.validation.constraints.NotNull;
20+
import lombok.Value;
421
import org.hibernate.validator.constraints.URL;
5-
import org.springframework.beans.factory.annotation.Value;
6-
import org.springframework.context.annotation.Configuration;
22+
import org.springframework.boot.context.properties.ConfigurationProperties;
23+
import org.springframework.boot.context.properties.bind.DefaultValue;
24+
import org.springframework.validation.annotation.Validated;
725

8-
@Getter
9-
@Configuration
26+
@Value
27+
@Validated
28+
@ConfigurationProperties(prefix = "sms")
1029
public class PlatformRegistryConfiguration {
30+
@URL
31+
@NotNull
32+
String scone;
1133

1234
@URL
13-
@Value("${sms.scone}")
14-
private String sconeSms;
35+
@NotNull
36+
String gramine;
1537

1638
@URL
17-
@Value("${sms.gramine}")
18-
private String gramineSms;
19-
39+
@NotNull
40+
String tdx;
41+
42+
public PlatformRegistryConfiguration(
43+
@DefaultValue("") final String scone,
44+
@DefaultValue("") final String gramine,
45+
@DefaultValue("") final String tdx
46+
) {
47+
this.scone = scone;
48+
this.gramine = gramine;
49+
this.tdx = tdx;
50+
}
2051
}

src/main/java/com/iexec/core/sms/SmsService.java

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@
2929
import com.iexec.sms.api.SmsClient;
3030
import com.iexec.sms.api.SmsClientProvider;
3131
import feign.FeignException;
32+
import jakarta.annotation.PostConstruct;
3233
import lombok.extern.slf4j.Slf4j;
3334
import org.apache.commons.lang3.StringUtils;
3435
import org.springframework.context.event.EventListener;
3536
import org.springframework.stereotype.Service;
3637
import org.web3j.crypto.Hash;
3738

39+
import java.util.Arrays;
3840
import java.util.Optional;
41+
import java.util.function.Predicate;
3942

4043
import static com.iexec.sms.secret.ReservedSecretKeyName.IEXEC_RESULT_IEXEC_RESULT_PROXY_URL;
4144

@@ -60,6 +63,16 @@ public SmsService(final IexecHubService iexecHubService,
6063
this.smsClientProvider = smsClientProvider;
6164
}
6265

66+
@PostConstruct
67+
void initSmsClients() {
68+
Arrays.stream(TeeFramework.values())
69+
.map(this::retrieveSmsUrl)
70+
.filter(Optional::isPresent)
71+
.map(Optional::get)
72+
.filter(Predicate.not(String::isBlank))
73+
.forEach(smsClientProvider::getSmsClient);
74+
}
75+
6376
private Optional<String> getVerifiedSmsUrl(final String chainTaskId) {
6477
final TaskDescription taskDescription = iexecHubService.getTaskDescription(chainTaskId);
6578
return getVerifiedSmsUrl(chainTaskId, taskDescription.getTeeFramework());
@@ -86,35 +99,31 @@ public Optional<String> getVerifiedSmsUrl(final String chainTaskId, final String
8699
Optional<String> getVerifiedSmsUrl(final String chainTaskId, final TeeFramework teeFrameworkForDeal) {
87100
log.debug("getVerifiedSmsUrl [chainTaskId:{}, teeFrameworkForDeal:{}]", chainTaskId, teeFrameworkForDeal);
88101
if (teeFrameworkForDeal == null) {
89-
log.error("Can't get verified SMS url with invalid TEE framework " +
90-
"from tag [chainTaskId:{}]", chainTaskId);
102+
log.error("Can't get verified SMS url with invalid TEE framework from tag [chainTaskId:{}]", chainTaskId);
91103
return Optional.empty();
92104
}
93-
Optional<String> smsUrl = retrieveSmsUrl(teeFrameworkForDeal);
105+
final Optional<String> smsUrl = retrieveSmsUrl(teeFrameworkForDeal);
94106
if (smsUrl.isEmpty()) {
95-
log.error("Can't get verified SMS url since type of tag is not " +
96-
"supported [chainTaskId:{},teeFrameworkForDeal:{}]",
107+
log.error("Can't get verified SMS url since type of tag is not supported [chainTaskId:{}, teeFrameworkForDeal:{}]",
97108
chainTaskId, teeFrameworkForDeal);
98109
return Optional.empty();
99110
}
100111
final SmsClient smsClient = smsClientProvider.getSmsClient(smsUrl.get());
101112
if (!checkSmsTeeFramework(smsClient, teeFrameworkForDeal, chainTaskId)) {
102-
log.error("Can't get verified SMS url since tag TEE type " +
103-
"does not match SMS TEE type [chainTaskId:{},teeFrameworkForDeal:{}]",
113+
log.error("Can't get verified SMS url since tag TEE type does not match SMS TEE type [chainTaskId:{}, teeFrameworkForDeal:{}]",
104114
chainTaskId, teeFrameworkForDeal);
105115
return Optional.empty();
106116
}
107117
return smsUrl;
108118
}
109119

110-
private Optional<String> retrieveSmsUrl(TeeFramework teeFramework) {
111-
Optional<String> smsUrl = Optional.empty();
112-
if (teeFramework == TeeFramework.SCONE) {
113-
smsUrl = Optional.of(registryConfiguration.getSconeSms());
114-
} else if (teeFramework == TeeFramework.GRAMINE) {
115-
smsUrl = Optional.of(registryConfiguration.getGramineSms());
116-
}
117-
return smsUrl;
120+
private Optional<String> retrieveSmsUrl(final TeeFramework teeFramework) {
121+
return switch (teeFramework) {
122+
case SCONE -> Optional.of(registryConfiguration.getScone());
123+
case GRAMINE -> Optional.of(registryConfiguration.getGramine());
124+
case TDX -> Optional.of(registryConfiguration.getTdx());
125+
default -> Optional.empty();
126+
};
118127
}
119128

120129
private boolean checkSmsTeeFramework(SmsClient smsClient,
@@ -130,8 +139,7 @@ private boolean checkSmsTeeFramework(SmsClient smsClient,
130139
}
131140

132141
if (smsTeeFramework != teeFrameworkForDeal) {
133-
log.error("SMS is configured for another TEE framework " +
134-
"[chainTaskId:{}, teeFrameworkForDeal:{}, smsTeeFramework:{}]",
142+
log.error("SMS is configured for another TEE framework [chainTaskId:{}, teeFrameworkForDeal:{}, smsTeeFramework:{}]",
135143
chainTaskId, teeFrameworkForDeal, smsTeeFramework);
136144
return false;
137145
}

src/test/java/com/iexec/core/chain/WebSocketBlockchainListenerTests.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ class WebSocketBlockchainListenerTests {
5656

5757
@DynamicPropertySource
5858
static void registerProperties(DynamicPropertyRegistry registry) {
59-
registry.add("sms.scone", () -> "");
60-
registry.add("sms.gramine", () -> "");
6159
registry.add("chain.node-address", () -> getServiceUrl(
6260
environment.getServiceHost(CHAIN_SVC_NAME, CHAIN_SVC_PORT),
6361
environment.getServicePort(CHAIN_SVC_NAME, CHAIN_SVC_PORT))

src/test/java/com/iexec/core/detector/replicate/ContributionAndFinalizationUnnotifiedDetectorTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.iexec.common.replicate.ReplicateStatus;
2020
import com.iexec.common.replicate.ReplicateStatusUpdate;
2121
import com.iexec.commons.poco.task.TaskDescription;
22+
import com.iexec.commons.poco.tee.TeeFramework;
2223
import com.iexec.core.chain.IexecHubService;
2324
import com.iexec.core.configuration.CronConfiguration;
2425
import com.iexec.core.replicate.Replicate;
@@ -94,6 +95,7 @@ private void mockTaskAndTaskDecription(final String callback) {
9495
TaskDescription.builder()
9596
.trust(BigInteger.ONE)
9697
.isTeeTask(true)
98+
.teeFramework(TeeFramework.SCONE)
9799
.callback(callback)
98100
.build()
99101
);

0 commit comments

Comments
 (0)