diff --git a/build.gradle b/build.gradle index a14704a1..a4c31b28 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-jdk18on:1.78" 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 151378ef..443a99dd 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(); } } }