Skip to content

Commit c06f69a

Browse files
committed
Upgrade to JJWT 0.10.6
* Update to version 0.10.6 * Use -api, -impl, and -jackson modules * Drop the use of deprecated JJWT APIs * Fix a misuse of the key material (testing only)
1 parent 46f1a30 commit c06f69a

File tree

6 files changed

+36
-23
lines changed

6 files changed

+36
-23
lines changed

bom/pom.xml

+12-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<java-base-image.name>openjdk:11-jre-slim</java-base-image.name>
4141
<jaxb.api.version>2.2.12</jaxb.api.version>
4242
<javax.annotation.api.version>1.3.2</javax.annotation.api.version>
43-
<jjwt.version>0.7.0</jjwt.version>
43+
<jjwt.version>0.10.6</jjwt.version>
4444
<jmeter.version>3.3</jmeter.version>
4545
<junit.version>4.12</junit.version>
4646
<logback.version>1.2.3</logback.version>
@@ -280,7 +280,17 @@
280280
</dependency>
281281
<dependency>
282282
<groupId>io.jsonwebtoken</groupId>
283-
<artifactId>jjwt</artifactId>
283+
<artifactId>jjwt-api</artifactId>
284+
<version>${jjwt.version}</version>
285+
</dependency>
286+
<dependency>
287+
<groupId>io.jsonwebtoken</groupId>
288+
<artifactId>jjwt-impl</artifactId>
289+
<version>${jjwt.version}</version>
290+
</dependency>
291+
<dependency>
292+
<groupId>io.jsonwebtoken</groupId>
293+
<artifactId>jjwt-jackson</artifactId>
284294
<version>${jjwt.version}</version>
285295
</dependency>
286296
<dependency>

client/src/test/java/org/eclipse/hono/client/impl/RegistrationClientImplTest.java

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016, 2018 Contributors to the Eclipse Foundation
2+
* Copyright (c) 2016, 2019 Contributors to the Eclipse Foundation
33
*
44
* See the NOTICE file(s) distributed with this work for additional
55
* information regarding copyright ownership.
@@ -26,6 +26,9 @@
2626
import java.sql.Date;
2727
import java.time.Duration;
2828
import java.time.Instant;
29+
import java.util.Random;
30+
31+
import javax.crypto.SecretKey;
2932

3033
import org.apache.qpid.proton.message.Message;
3134
import org.eclipse.hono.cache.ExpiringValueCache;
@@ -45,6 +48,7 @@
4548

4649
import io.jsonwebtoken.Jwts;
4750
import io.jsonwebtoken.SignatureAlgorithm;
51+
import io.jsonwebtoken.security.Keys;
4852
import io.vertx.core.Handler;
4953
import io.vertx.core.Vertx;
5054
import io.vertx.core.json.JsonObject;
@@ -214,11 +218,15 @@ private static JsonObject newRegistrationAssertionResult() {
214218

215219
private static JsonObject newRegistrationAssertionResult(final String defaultContentType) {
216220

221+
final byte[] bits = new byte[32];
222+
new Random().nextBytes(bits);
223+
final SecretKey key = Keys.hmacShaKeyFor(bits);
224+
217225
final String token = Jwts.builder()
218-
.signWith(SignatureAlgorithm.HS256, "asecretkeywithatleastthirtytwobytes")
219-
.setExpiration(Date.from(Instant.now().plusSeconds(10)))
220-
.setIssuer("test")
221-
.compact();
226+
.signWith(key, SignatureAlgorithm.HS256)
227+
.setExpiration(Date.from(Instant.now().plusSeconds(10)))
228+
.setIssuer("test")
229+
.compact();
222230
final JsonObject result = new JsonObject().put(RegistrationConstants.FIELD_ASSERTION, token);
223231
if (defaultContentType != null) {
224232
result.put(RegistrationConstants.FIELD_DEFAULTS, new JsonObject()

core/pom.xml

+5-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@
6161
</dependency>
6262
<dependency>
6363
<groupId>io.jsonwebtoken</groupId>
64-
<artifactId>jjwt</artifactId>
64+
<artifactId>jjwt-impl</artifactId>
65+
</dependency>
66+
<dependency>
67+
<groupId>io.jsonwebtoken</groupId>
68+
<artifactId>jjwt-jackson</artifactId>
6569
</dependency>
6670
<dependency>
6771
<!-- required as a (missing) transient dependency for JJWT -->

service-base/pom.xml

-10
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,6 @@
6464
<artifactId>logback-classic</artifactId>
6565
<scope>test</scope>
6666
</dependency>
67-
<dependency>
68-
<groupId>io.jsonwebtoken</groupId>
69-
<artifactId>jjwt</artifactId>
70-
<exclusions>
71-
<exclusion>
72-
<groupId>com.fasterxml.jackson.core</groupId>
73-
<artifactId>jackson-databind</artifactId>
74-
</exclusion>
75-
</exclusions>
76-
</dependency>
7767
<dependency>
7868
<groupId>org.eclipse.hono</groupId>
7969
<artifactId>hono-client</artifactId>

service-base/src/main/java/org/eclipse/hono/service/auth/AuthTokenHelperImpl.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016, 2018 Contributors to the Eclipse Foundation
2+
* Copyright (c) 2016, 2019 Contributors to the Eclipse Foundation
33
*
44
* See the NOTICE file(s) distributed with this work for additional
55
* information regarding copyright ownership.
@@ -89,7 +89,7 @@ public static AuthTokenHelper forSharedSecret(final String sharedSecret, final l
8989
public String createToken(final String authorizationId, final Authorities authorities) {
9090

9191
final JwtBuilder builder = Jwts.builder()
92-
.signWith(algorithm, key)
92+
.signWith(key, algorithm)
9393
.setIssuer("Hono")
9494
.setSubject(Objects.requireNonNull(authorizationId))
9595
.setExpiration(Date.from(Instant.now().plus(tokenLifetime)));

service-base/src/main/java/org/eclipse/hono/service/registration/RegistrationAssertionHelperImpl.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016, 2018 Contributors to the Eclipse Foundation
2+
* Copyright (c) 2016, 2019 Contributors to the Eclipse Foundation
33
*
44
* See the NOTICE file(s) distributed with this work for additional
55
* information regarding copyright ownership.
@@ -94,7 +94,8 @@ public String getAssertion(final String tenantId, final String deviceId) {
9494
throw new IllegalStateException("no algorithm set");
9595
}
9696

97-
return Jwts.builder().signWith(algorithm, key)
97+
return Jwts.builder()
98+
.signWith(key, algorithm)
9899
.setSubject(deviceId)
99100
.claim("ten", tenantId)
100101
.setExpiration(Date.from(Instant.now().plus(tokenLifetime)))
@@ -112,7 +113,7 @@ public boolean isValid(final String token, final String tenantId, final String d
112113
.setAllowedClockSkewSeconds(10)
113114
.parse(token);
114115
return true;
115-
} catch (JwtException e) {
116+
} catch (final JwtException e) {
116117
// token is invalid for some reason
117118
LOG.debug("failed to validate token", e);
118119
return false;

0 commit comments

Comments
 (0)