-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rest-assurance client is not working with BCFIPS certificates
Swapp to Vertx http client
- Loading branch information
pablo gonzalez granados
committed
May 6, 2022
1 parent
e8d171e
commit 45c72a4
Showing
8 changed files
with
92 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+2.07 KB
(180%)
security/bouncycastle-fips/src/main/resources/server-keystore.jks
Binary file not shown.
Binary file modified
BIN
-1.36 KB
(52%)
security/bouncycastle-fips/src/main/resources/server-truststore.jks
Binary file not shown.
84 changes: 73 additions & 11 deletions
84
...e-fips/src/test/java/io/quarkus/ts/security/bouncycastle/fips/BouncyCastleFipsJsseIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,98 @@ | ||
package io.quarkus.ts.security.bouncycastle.fips; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.CoreMatchers.containsString; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.security.Security; | ||
|
||
import org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.runtime.util.ClassPathUtils; | ||
import io.quarkus.test.bootstrap.Protocol; | ||
import io.quarkus.test.bootstrap.RestService; | ||
import io.quarkus.test.scenarios.QuarkusScenario; | ||
import io.quarkus.test.services.Dependency; | ||
import io.quarkus.test.services.QuarkusApplication; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.core.buffer.Buffer; | ||
import io.vertx.core.net.KeyStoreOptions; | ||
import io.vertx.ext.web.client.WebClientOptions; | ||
import io.vertx.mutiny.ext.web.client.WebClient; | ||
|
||
@QuarkusScenario | ||
public class BouncyCastleFipsJsseIT { | ||
|
||
private static final String PASSWORD = "password"; | ||
|
||
@QuarkusApplication(dependencies = { | ||
@QuarkusApplication(ssl = true, dependencies = { | ||
@Dependency(groupId = "org.bouncycastle", artifactId = "bctls-fips", version = "${bouncycastle.bctls-fips.version}") | ||
}) | ||
private static final RestService app = new RestService().withProperties("jsse.properties"); | ||
|
||
@Test | ||
public void verifyBouncyCastleFipsAndJsseProviderAvailability() { | ||
given() | ||
.keyStore(Paths.get("client-keystore.jks").toFile(), PASSWORD) | ||
.trustStore(Paths.get("client-truststore.jks").toFile(), PASSWORD) | ||
.when() | ||
.get("/api/listProviders") | ||
.then() | ||
.statusCode(200) | ||
.body(containsString("BCFIPS,BCJSSE")); | ||
public void verifyBouncyCastleFipsAndJsseProviderAvailability() throws Exception { | ||
Security.insertProviderAt(new BouncyCastleFipsProvider(), 1); | ||
WebClient webClient = WebClient.create(new io.vertx.mutiny.core.Vertx(Vertx.vertx()), createWebClientOptions()); | ||
String endpoint = app.getHost(Protocol.HTTPS) + ":" + app.getPort(Protocol.HTTPS) + "/api/listProviders"; | ||
String body = webClient | ||
.getAbs(endpoint) | ||
.sendAndAwait().bodyAsString(); | ||
|
||
assertThat(body, containsString("BCFIPS,BCJSSE")); | ||
} | ||
|
||
private WebClientOptions createWebClientOptions() throws Exception { | ||
WebClientOptions webClientOptions = new WebClientOptions(); | ||
|
||
byte[] keyStoreData = getFileContent(Paths.get("src", "test", "resources", "client-keystore.jks")); | ||
KeyStoreOptions keyStoreOptions = new KeyStoreOptions() | ||
.setPassword(PASSWORD) | ||
.setValue(Buffer.buffer(keyStoreData)) | ||
.setType("BCFKS") | ||
.setProvider("BCFIPS"); | ||
webClientOptions.setKeyCertOptions(keyStoreOptions); | ||
|
||
byte[] trustStoreData = getFileContent(Paths.get("src", "test", "resources", "client-truststore.jks")); | ||
KeyStoreOptions trustStoreOptions = new KeyStoreOptions() | ||
.setPassword(PASSWORD) | ||
.setValue(Buffer.buffer(trustStoreData)) | ||
.setType("BCFKS") | ||
.setProvider("BCFIPS"); | ||
webClientOptions.setVerifyHost(false).setTrustAll(true).setTrustOptions(trustStoreOptions); | ||
|
||
return webClientOptions; | ||
} | ||
|
||
private static byte[] getFileContent(Path path) throws IOException { | ||
byte[] data; | ||
final InputStream resource = Thread.currentThread().getContextClassLoader() | ||
.getResourceAsStream(ClassPathUtils.toResourceName(path)); | ||
if (resource != null) { | ||
try (InputStream is = resource) { | ||
data = doRead(is); | ||
} | ||
} else { | ||
try (InputStream is = Files.newInputStream(path)) { | ||
data = doRead(is); | ||
} | ||
} | ||
return data; | ||
} | ||
|
||
private static byte[] doRead(InputStream is) throws IOException { | ||
ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||
byte[] buf = new byte[1024]; | ||
int r; | ||
while ((r = is.read(buf)) > 0) { | ||
out.write(buf, 0, r); | ||
} | ||
return out.toByteArray(); | ||
} | ||
} |
Binary file modified
BIN
+2.07 KB
(180%)
security/bouncycastle-fips/src/test/resources/client-keystore.jks
Binary file not shown.
Binary file modified
BIN
-1.36 KB
(52%)
security/bouncycastle-fips/src/test/resources/client-truststore.jks
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters