Skip to content

Commit 30a291f

Browse files
committed
Backport JJWT and dependencies update from main
WE2-1132 Signed-off-by: Mart Somermaa <[email protected]>
1 parent c519cac commit 30a291f

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

pom.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
<maven.version>3.3.9</maven.version>
1515
<maven-surefire-plugin.version>3.5.4</maven-surefire-plugin.version>
1616
<java.version>1.8</java.version>
17-
<jjwt.version>0.11.5</jjwt.version>
17+
<jjwt.version>0.13.0</jjwt.version>
1818
<jackson.version>2.18.5</jackson.version>
19-
<slf4j.version>1.7.36</slf4j.version>
20-
<bouncycastle.version>1.70</bouncycastle.version>
21-
<okhttp.version>4.10.0</okhttp.version>
19+
<slf4j.version>2.0.17</slf4j.version>
20+
<bouncycastle.version>1.82</bouncycastle.version>
21+
<okhttp.version>5.3.0</okhttp.version>
2222
<junit-jupiter.version>5.12.0</junit-jupiter.version>
2323
<assertj.version>3.27.3</assertj.version>
2424
<mockito.version>4.11.0</mockito.version>
@@ -56,17 +56,17 @@
5656
</dependency>
5757
<dependency>
5858
<groupId>org.bouncycastle</groupId>
59-
<artifactId>bcprov-jdk15on</artifactId>
59+
<artifactId>bcprov-jdk18on</artifactId>
6060
<version>${bouncycastle.version}</version>
6161
</dependency>
6262
<dependency>
6363
<groupId>org.bouncycastle</groupId>
64-
<artifactId>bcpkix-jdk15on</artifactId>
64+
<artifactId>bcpkix-jdk18on</artifactId>
6565
<version>${bouncycastle.version}</version>
6666
</dependency>
6767
<dependency>
6868
<groupId>com.squareup.okhttp3</groupId>
69-
<artifactId>okhttp</artifactId>
69+
<artifactId>okhttp-jvm</artifactId>
7070
<version>${okhttp.version}</version>
7171
</dependency>
7272

src/main/java/eu/webeid/security/validator/AuthTokenSignatureValidator.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@
2525
import eu.webeid.security.exceptions.AuthTokenParseException;
2626
import eu.webeid.security.exceptions.AuthTokenSignatureValidationException;
2727
import eu.webeid.security.exceptions.ChallengeNullOrEmptyException;
28-
import io.jsonwebtoken.SignatureAlgorithm;
29-
import io.jsonwebtoken.impl.crypto.DefaultSignatureValidatorFactory;
30-
import io.jsonwebtoken.impl.crypto.SignatureValidator;
31-
import io.jsonwebtoken.security.SignatureException;
28+
import io.jsonwebtoken.Jwts;
29+
import io.jsonwebtoken.impl.security.DefaultVerifySecureDigestRequest;
30+
import io.jsonwebtoken.security.SignatureAlgorithm;
31+
import io.jsonwebtoken.security.VerifySecureDigestRequest;
3232

33+
import java.io.ByteArrayInputStream;
3334
import java.net.URI;
3435
import java.nio.charset.StandardCharsets;
3536
import java.security.MessageDigest;
@@ -73,25 +74,20 @@ public void validate(String algorithm, String signature, PublicKey publicKey, St
7374
throw new AuthTokenParseException("Unsupported signature algorithm");
7475
}
7576

76-
SignatureAlgorithm signatureAlgorithm;
77+
final SignatureAlgorithm signatureAlgorithm = (SignatureAlgorithm) Jwts.SIG.get().forKey(algorithm);
78+
if (signatureAlgorithm == null) {
79+
// Should not happen, see ALLOWED_SIGNATURE_ALGORITHMS check above.
80+
throw new AuthTokenParseException("JJWT does not support signature algorithm: " + algorithm);
81+
}
7782
MessageDigest hashAlgorithm;
7883
try {
79-
signatureAlgorithm = SignatureAlgorithm.forName(algorithm);
8084
hashAlgorithm = hashAlgorithmForName(algorithm);
81-
} catch (SignatureException e) {
82-
// Should not happen, see ALLOWED_SIGNATURE_ALGORITHMS check above.
83-
throw new AuthTokenParseException("Invalid signature algorithm", e);
8485
} catch (NoSuchAlgorithmException e) {
85-
throw new AuthTokenParseException("Invalid hash algorithm", e);
86-
}
87-
if (signatureAlgorithm == null || signatureAlgorithm == SignatureAlgorithm.NONE) {
8886
// Should not happen, see ALLOWED_SIGNATURE_ALGORITHMS check above.
89-
throw new AuthTokenParseException("Invalid signature algorithm");
87+
throw new AuthTokenParseException("Invalid hash algorithm", e);
9088
}
9189
Objects.requireNonNull(hashAlgorithm, "hashAlgorithm");
92-
signatureAlgorithm.assertValidVerificationKey(publicKey);
93-
final SignatureValidator signatureValidator = DefaultSignatureValidatorFactory.INSTANCE
94-
.createSignatureValidator(signatureAlgorithm, publicKey);
90+
9591
final byte[] decodedSignature = decodeBase64(signature);
9692

9793
final byte[] originHash = hashAlgorithm.digest(originBytes);
@@ -100,9 +96,13 @@ public void validate(String algorithm, String signature, PublicKey publicKey, St
10096

10197
// Note that in case of ECDSA, the eID card outputs raw R||S, but JCA's SHA384withECDSA signature
10298
// validation implementation requires the signature in DER encoding.
103-
// JJWT's EllipticCurveProvider.transcodeSignatureToDER() internally takes care of transcoding
104-
// raw R||S to DER as needed inside EllipticCurveProvider.isValid().
105-
if (!signatureValidator.isValid(concatSignedFields, decodedSignature)) {
99+
// JJWT internally takes care of transcoding raw R||S to DER as needed.
100+
final VerifySecureDigestRequest<PublicKey> verificationRequest =
101+
new DefaultVerifySecureDigestRequest<>(
102+
new ByteArrayInputStream(concatSignedFields),
103+
null, null,
104+
publicKey, decodedSignature);
105+
if (!signatureAlgorithm.verify(verificationRequest)) {
106106
throw new AuthTokenSignatureValidationException();
107107
}
108108
}

0 commit comments

Comments
 (0)