Skip to content

Commit 801b54c

Browse files
authored
Remove bounycastle test implementations (#688)
1 parent e5b5c3d commit 801b54c

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ dependencies {
135135
implementation "com.auth0:java-jwt:4.4.0"
136136
implementation "net.jodah:failsafe:2.4.4"
137137

138-
testImplementation "org.bouncycastle:bcprov-jdk18on:1.78"
139138
testImplementation "org.mockito:mockito-core:4.8.1"
140139
testImplementation "com.squareup.okhttp3:mockwebserver:${okhttpVersion}"
141140
testImplementation "org.hamcrest:hamcrest:${hamcrestVersion}"

src/test/java/com/auth0/utils/tokens/SignatureVerifierTest.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import com.auth0.exception.PublicKeyProviderException;
55
import com.auth0.jwt.exceptions.AlgorithmMismatchException;
66
import com.auth0.jwt.interfaces.DecodedJWT;
7-
import org.bouncycastle.util.io.pem.PemReader;
87
import org.junit.jupiter.api.Test;
98

9+
import java.io.BufferedReader;
1010
import java.io.FileInputStream;
1111
import java.io.FileReader;
1212
import java.io.IOException;
@@ -18,6 +18,7 @@
1818
import java.security.interfaces.RSAPublicKey;
1919
import java.security.spec.EncodedKeySpec;
2020
import java.security.spec.X509EncodedKeySpec;
21+
import java.util.Base64;
2122
import java.util.Scanner;
2223

2324
import static com.auth0.AssertsUtil.verifyThrows;
@@ -144,7 +145,7 @@ public RSAPublicKey getPublicKeyById(String keyId) throws PublicKeyProviderExcep
144145

145146
private static RSAPublicKey readPublicKeyFromFile(final String path) throws IOException {
146147
Scanner scanner = null;
147-
PemReader pemReader = null;
148+
BufferedReader reader = null;
148149
try {
149150
scanner = new Scanner(Paths.get(path));
150151
if (scanner.hasNextLine() && scanner.nextLine().startsWith("-----BEGIN CERTIFICATE-----")) {
@@ -155,8 +156,15 @@ private static RSAPublicKey readPublicKeyFromFile(final String path) throws IOEx
155156
fs.close();
156157
return (RSAPublicKey) key;
157158
} else {
158-
pemReader = new PemReader(new FileReader(path));
159-
byte[] keyBytes = pemReader.readPemObject().getContent();
159+
reader = new BufferedReader(new FileReader(path));
160+
StringBuilder pemContent = new StringBuilder();
161+
String line;
162+
while ((line = reader.readLine()) != null) {
163+
if (!line.startsWith("-----BEGIN") && !line.startsWith("-----END")) {
164+
pemContent.append(line);
165+
}
166+
}
167+
byte[] keyBytes = Base64.getDecoder().decode(pemContent.toString());
160168
KeyFactory kf = KeyFactory.getInstance("RSA");
161169
EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
162170
return (RSAPublicKey) kf.generatePublic(keySpec);
@@ -167,8 +175,8 @@ private static RSAPublicKey readPublicKeyFromFile(final String path) throws IOEx
167175
if (scanner != null) {
168176
scanner.close();
169177
}
170-
if (pemReader != null) {
171-
pemReader.close();
178+
if (reader != null) {
179+
reader.close();
172180
}
173181
}
174182
}

0 commit comments

Comments
 (0)