From 66364410a9962d0370f1a8e78bda47a017bda298 Mon Sep 17 00:00:00 2001 From: tanya732 Date: Wed, 8 Jan 2025 17:20:45 +0530 Subject: [PATCH 1/3] added groovy version compatible with java 8 --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index 9f9ad2ade..a14704a18 100644 --- a/build.gradle +++ b/build.gradle @@ -4,6 +4,7 @@ buildscript { } dependencies { + classpath 'org.codehaus.groovy:groovy-all:2.5.14' // Ensure Groovy version compatible with Java 8 // https://github.com/melix/japicmp-gradle-plugin/issues/36 classpath 'com.google.guava:guava:31.1-jre' } From 9d027b8b04de2a2e0975db176bd924729faee08f Mon Sep 17 00:00:00 2001 From: tanya732 Date: Wed, 8 Jan 2025 18:19:43 +0530 Subject: [PATCH 2/3] reverted back to jdk15 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index a14704a18..5cf40dfff 100644 --- a/build.gradle +++ b/build.gradle @@ -135,7 +135,7 @@ dependencies { implementation "com.auth0:java-jwt:4.4.0" implementation "net.jodah:failsafe:2.4.4" - testImplementation "org.bouncycastle:bcprov-jdk18on:1.78" + testImplementation "org.bouncycastle:bcprov-jdk15on:1.70" testImplementation "org.mockito:mockito-core:4.8.1" testImplementation "com.squareup.okhttp3:mockwebserver:${okhttpVersion}" testImplementation "org.hamcrest:hamcrest:${hamcrestVersion}" From 687306c15ae38a9164f13f4604189a9b90dfc7a7 Mon Sep 17 00:00:00 2001 From: tanya732 Date: Wed, 8 Jan 2025 18:39:00 +0530 Subject: [PATCH 3/3] updating test implementations --- build.gradle | 1 - .../utils/tokens/SignatureVerifierTest.java | 20 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index 5cf40dfff..a4c31b28f 100644 --- a/build.gradle +++ b/build.gradle @@ -135,7 +135,6 @@ dependencies { implementation "com.auth0:java-jwt:4.4.0" implementation "net.jodah:failsafe:2.4.4" - testImplementation "org.bouncycastle:bcprov-jdk15on:1.70" testImplementation "org.mockito:mockito-core:4.8.1" testImplementation "com.squareup.okhttp3:mockwebserver:${okhttpVersion}" testImplementation "org.hamcrest:hamcrest:${hamcrestVersion}" diff --git a/src/test/java/com/auth0/utils/tokens/SignatureVerifierTest.java b/src/test/java/com/auth0/utils/tokens/SignatureVerifierTest.java index 151378efa..443a99ddd 100644 --- a/src/test/java/com/auth0/utils/tokens/SignatureVerifierTest.java +++ b/src/test/java/com/auth0/utils/tokens/SignatureVerifierTest.java @@ -4,9 +4,9 @@ import com.auth0.exception.PublicKeyProviderException; import com.auth0.jwt.exceptions.AlgorithmMismatchException; import com.auth0.jwt.interfaces.DecodedJWT; -import org.bouncycastle.util.io.pem.PemReader; import org.junit.jupiter.api.Test; +import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileReader; import java.io.IOException; @@ -18,6 +18,7 @@ import java.security.interfaces.RSAPublicKey; import java.security.spec.EncodedKeySpec; import java.security.spec.X509EncodedKeySpec; +import java.util.Base64; import java.util.Scanner; import static com.auth0.AssertsUtil.verifyThrows; @@ -144,7 +145,7 @@ public RSAPublicKey getPublicKeyById(String keyId) throws PublicKeyProviderExcep private static RSAPublicKey readPublicKeyFromFile(final String path) throws IOException { Scanner scanner = null; - PemReader pemReader = null; + BufferedReader reader = null; try { scanner = new Scanner(Paths.get(path)); if (scanner.hasNextLine() && scanner.nextLine().startsWith("-----BEGIN CERTIFICATE-----")) { @@ -155,8 +156,15 @@ private static RSAPublicKey readPublicKeyFromFile(final String path) throws IOEx fs.close(); return (RSAPublicKey) key; } else { - pemReader = new PemReader(new FileReader(path)); - byte[] keyBytes = pemReader.readPemObject().getContent(); + reader = new BufferedReader(new FileReader(path)); + StringBuilder pemContent = new StringBuilder(); + String line; + while ((line = reader.readLine()) != null) { + if (!line.startsWith("-----BEGIN") && !line.startsWith("-----END")) { + pemContent.append(line); + } + } + byte[] keyBytes = Base64.getDecoder().decode(pemContent.toString()); KeyFactory kf = KeyFactory.getInstance("RSA"); EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes); return (RSAPublicKey) kf.generatePublic(keySpec); @@ -167,8 +175,8 @@ private static RSAPublicKey readPublicKeyFromFile(final String path) throws IOEx if (scanner != null) { scanner.close(); } - if (pemReader != null) { - pemReader.close(); + if (reader != null) { + reader.close(); } } }