Skip to content

Commit 7563cd5

Browse files
authored
Add Authorization header on /tee/challenges/{chainTaskId} endpoint (#255)
1 parent fb98094 commit 7563cd5

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44

55
## [[NEXT]](https://github.com/iExecBlockchainComputing/iexec-sms/releases/tag/vNEXT) 2024
66

7+
### New Features
8+
9+
- Add `Authorization` header on `/tee/challenges/{chainTaskId}` endpoint. (#255)
10+
711
### Quality
812

913
- Use only two SQL statements to read `TeeTaskComputeSecret` and `Web2Secret` during TEE session creation. (#254)

iexec-sms-library/src/main/java/com/iexec/sms/api/SmsClient.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,18 @@ String setWeb3Secret(
118118
// endregion
119119

120120
// region TEE
121+
122+
/**
123+
* @deprecated use {@link SmsClient#generateTeeChallenge(String, String)}
124+
*/
125+
@Deprecated(forRemoval = true)
121126
@RequestLine("POST /tee/challenges/{chainTaskId}")
122127
String generateTeeChallenge(@Param("chainTaskId") String chainTaskId);
123128

129+
@Headers("Authorization: {authorization}")
130+
@RequestLine("POST /tee/challenges/{chainTaskId}")
131+
String generateTeeChallenge(@Param("authorization") String authorization, @Param("chainTaskId") String chainTaskId);
132+
124133
@RequestLine("POST /tee/sessions")
125134
@Headers("Authorization: {authorization}")
126135
ApiResponseBody<TeeSessionGenerationResponse, TeeSessionGenerationError> generateTeeSession(

src/main/java/com/iexec/sms/tee/TeeController.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public TeeController(
7373

7474
/**
7575
* Return which TEE framework this SMS is configured to use.
76+
*
7677
* @return TEE framework this SMS is configured to use.
7778
*/
7879
@GetMapping("/framework")
@@ -100,10 +101,16 @@ public ResponseEntity<TeeServicesProperties> getTeeServicesProperties(
100101
}
101102

102103
/**
103-
* Called by the core, not the worker
104+
* Generates an enclave challenge for a PoCo task.
105+
* <p>
106+
* This method is called by the scheduler.
107+
*
108+
* @param authorization Authorization to check the query legitimacy
109+
* @param chainTaskId ID of the task the challenge will be produced for
110+
* @return The Ethereum address enclave challenge for the provided
104111
*/
105112
@PostMapping("/challenges/{chainTaskId}")
106-
public ResponseEntity<String> generateTeeChallenge(@PathVariable String chainTaskId) {
113+
public ResponseEntity<String> generateTeeChallenge(@RequestHeader String authorization, @PathVariable String chainTaskId) {
107114
Optional<TeeChallenge> executionChallenge =
108115
teeChallengeService.getOrCreate(chainTaskId, false);
109116
return executionChallenge
@@ -118,10 +125,12 @@ public ResponseEntity<String> generateTeeChallenge(@PathVariable String chainTas
118125
* to the enclave so the latter can talk to the CAS and get
119126
* the needed secrets.
120127
*
121-
* @return
122-
* 200 OK with the session id if success,
123-
* 404 NOT_FOUND if the task is not found,
124-
* 500 INTERNAL_SERVER_ERROR otherwise.
128+
* @return result
129+
* <ul>
130+
* <li>200 OK with the session id if success.
131+
* <li>404 NOT_FOUND if the task is not found.
132+
* <li>500 INTERNAL_SERVER_ERROR otherwise.
133+
* </ul>
125134
*/
126135
@PostMapping("/sessions")
127136
public ResponseEntity<ApiResponseBody<TeeSessionGenerationResponse, TeeSessionGenerationError>> generateTeeSession(
@@ -170,7 +179,7 @@ public ResponseEntity<ApiResponseBody<TeeSessionGenerationResponse, TeeSessionGe
170179
return ResponseEntity.ok(ApiResponseBody.<TeeSessionGenerationResponse, TeeSessionGenerationError>builder()
171180
.data(teeSessionGenerationResponse)
172181
.build());
173-
} catch(TeeSessionGenerationException e) {
182+
} catch (TeeSessionGenerationException e) {
174183
log.error("Failed to generate secure session [taskId:{}, workerAddress:{}]",
175184
taskId, workerAddress, e);
176185
final ApiResponseBody<TeeSessionGenerationResponse, TeeSessionGenerationError> body =

0 commit comments

Comments
 (0)