Skip to content

Commit c86cc00

Browse files
authored
Merge pull request #78 from iExecBlockchainComputing/feature/upgrade-jjwt-dependency
Feature/upgrade jjwt dependency
2 parents 1866761 + a4a461d commit c86cc00

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ All notable changes to this project will be documented in this file.
1818
* Upgrade to Spring Boot 2.6.14.
1919
* Upgrade to Gradle 7.6.
2020
* Upgrade OkHttp to 4.9.0.
21-
* Upgrade java-http-ipfs-client to 1.4.0 for latest IPFS Kubo support (v0.18.1).
21+
* Upgrade `java-http-ipfs-client` to 1.4.0 for latest IPFS Kubo support (v0.18.1).
22+
* Upgrade `jjwt` to `jjwt-api` 0.11.5.
2223

2324
## [[7.3.0]](https://github.com/iExecBlockchainComputing/iexec-result-proxy/releases/tag/v7.3.0) 2023-01-18
2425

build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ plugins {
1010

1111
ext {
1212
springCloudVersion = '2021.0.5'
13+
jjwtVersion = '0.11.5'
1314
}
1415

1516
if (!project.hasProperty('gitBranch')) {
@@ -76,7 +77,9 @@ dependencies {
7677
implementation 'com.github.ipfs:java-ipfs-http-client:1.4.0'
7778

7879
// json web token
79-
implementation 'io.jsonwebtoken:jjwt:0.7.0'
80+
implementation "io.jsonwebtoken:jjwt-api:$jjwtVersion"
81+
runtimeOnly "io.jsonwebtoken:jjwt-impl:$jjwtVersion"
82+
runtimeOnly "io.jsonwebtoken:jjwt-jackson:$jjwtVersion"
8083

8184
// expiring map
8285
implementation 'net.jodah:expiringmap:0.5.8'

src/main/java/com/iexec/resultproxy/jwt/JwtService.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import io.jsonwebtoken.JwtException;
2323
import io.jsonwebtoken.Jwts;
2424
import io.jsonwebtoken.SignatureAlgorithm;
25+
import io.jsonwebtoken.security.Keys;
2526
import lombok.extern.slf4j.Slf4j;
2627
import org.springframework.stereotype.Service;
2728

@@ -112,7 +113,7 @@ String createJwt(String walletAddress) {
112113
.setAudience(walletAddress)
113114
.setIssuedAt(new Date())
114115
.setSubject(UUID.randomUUID().toString())
115-
.signWith(SignatureAlgorithm.HS256, jwtKey)
116+
.signWith(Keys.hmacShaKeyFor(jwtKey), SignatureAlgorithm.HS256)
116117
.compact();
117118
}
118119

@@ -138,8 +139,9 @@ public boolean isValidJwt(String jwtString) {
138139
* @return Wallet address extracted from the 'audience' claim
139140
*/
140141
public String getWalletAddressFromJwtString(String jwtString) {
141-
return Jwts.parser()
142+
return Jwts.parserBuilder()
142143
.setSigningKey(jwtKey)
144+
.build()
143145
.parseClaimsJws(jwtString)
144146
.getBody()
145147
.getAudience();

src/test/java/com/iexec/resultproxy/jwt/JwtServiceTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import com.iexec.common.utils.FileHelper;
2121
import io.jsonwebtoken.Jwts;
2222
import io.jsonwebtoken.SignatureAlgorithm;
23-
import io.jsonwebtoken.SignatureException;
2423
import io.jsonwebtoken.UnsupportedJwtException;
24+
import io.jsonwebtoken.security.SignatureException;
2525
import lombok.SneakyThrows;
2626
import org.junit.jupiter.api.BeforeEach;
2727
import org.junit.jupiter.api.Test;
@@ -42,6 +42,7 @@
4242
import java.util.UUID;
4343

4444
import static com.iexec.resultproxy.jwt.JwtService.KEY_SIZE;
45+
import static io.jsonwebtoken.security.Keys.hmacShaKeyFor;
4546
import static org.junit.jupiter.api.Assertions.*;
4647
import static org.mockito.ArgumentMatchers.any;
4748
import static org.mockito.Mockito.*;
@@ -122,7 +123,7 @@ void failToReadWalletAddressOnWronglySignedToken() {
122123
.setAudience(walletAddress)
123124
.setIssuedAt(new Date())
124125
.setSubject(UUID.randomUUID().toString())
125-
.signWith(SignatureAlgorithm.HS256, badJwtKey)
126+
.signWith(hmacShaKeyFor(badJwtKey), SignatureAlgorithm.HS256)
126127
.compact();
127128
assertAll(
128129
() -> verifyNoInteractions(jwtRepository),
@@ -223,7 +224,7 @@ void wronglySignedTokenIsNotValid() {
223224
.setAudience(walletAddress)
224225
.setIssuedAt(new Date())
225226
.setSubject(UUID.randomUUID().toString())
226-
.signWith(SignatureAlgorithm.HS256, badJwtKey)
227+
.signWith(hmacShaKeyFor(badJwtKey), SignatureAlgorithm.HS256)
227228
.compact();
228229
boolean isValid = jwtService.isValidJwt(badToken);
229230
assertAll (

0 commit comments

Comments
 (0)