3939
4040import org .apache .hc .core5 .http .HttpHost ;
4141import org .apache .hc .core5 .ssl .SSLContextBuilder ;
42- import org .bouncycastle .crypto .CryptoServicesRegistrar ;
43- import org .bouncycastle .jcajce .provider .BouncyCastleFipsProvider ;
44- import org .bouncycastle .jsse .provider .BouncyCastleJsseProvider ;
4542import org .junit .AfterClass ;
4643import org .junit .BeforeClass ;
4744
5855import java .security .KeyStore ;
5956import java .security .PrivilegedAction ;
6057import java .security .SecureRandom ;
61- import java .security .Security ;
6258
6359import static org .hamcrest .MatcherAssert .assertThat ;
6460import static org .hamcrest .Matchers .instanceOf ;
7066 */
7167public class RestClientBuilderIntegTests extends RestClientTestCase implements RestClientFipsAwareTestCase {
7268
73- static {
74- if (inFipsJvm ()) {
75- int highestPriority = 1 ;
76- if (Security .getProvider (BouncyCastleFipsProvider .PROVIDER_NAME ) == null ) {
77- Security .insertProviderAt (new BouncyCastleFipsProvider (), highestPriority ++);
78- }
79- if (Security .getProvider (BouncyCastleJsseProvider .PROVIDER_NAME ) == null ) {
80- Security .insertProviderAt (new BouncyCastleJsseProvider (), highestPriority );
81- }
82- }
83- }
84-
8569 private static HttpsServer httpsServer ;
8670
8771 @ BeforeClass
8872 public static void startHttpServer () throws Exception {
8973 httpsServer = HttpsServer .create (new InetSocketAddress (InetAddress .getLoopbackAddress (), 0 ), 0 );
90- String keyStoreType = CryptoServicesRegistrar .isInApprovedOnlyMode () ? "BCFKS" : "JKS" ;
91- httpsServer .setHttpsConfigurator (new HttpsConfigurator (getSslContext (true , keyStoreType )));
74+ httpsServer .setHttpsConfigurator (new HttpsConfigurator (new RestClientBuilderIntegTests ().getSslContext (true )));
9275 httpsServer .createContext ("/" , new ResponseHandler ());
9376 httpsServer .start ();
9477 }
@@ -108,11 +91,6 @@ public static void stopHttpServers() throws IOException {
10891 }
10992
11093 public void testBuilderUsesDefaultSSLContext () throws Exception {
111- makeRequest ();
112- }
113-
114- @ Override
115- public void makeRequest (String keyStoreType ) throws Exception {
11694 final SSLContext defaultSSLContext = SSLContext .getDefault ();
11795 try {
11896 try (RestClient client = buildRestClient ()) {
@@ -124,7 +102,7 @@ public void makeRequest(String keyStoreType) throws Exception {
124102 }
125103 }
126104
127- SSLContext .setDefault (getSslContext (false , keyStoreType ));
105+ SSLContext .setDefault (getSslContext (false ));
128106 try (RestClient client = buildRestClient ()) {
129107 Response response = client .performRequest (new Request ("GET" , "/" ));
130108 assertEquals (200 , response .getStatusLine ().getStatusCode ());
@@ -139,19 +117,10 @@ private RestClient buildRestClient() {
139117 return RestClient .builder (new HttpHost ("https" , address .getHostString (), address .getPort ())).build ();
140118 }
141119
142- private static SSLContext getSslContext (boolean server , String keyStoreType ) throws Exception {
120+ @ Override
121+ public SSLContext getSslContext (boolean server , String keyStoreType , SecureRandom secureRandom , String fileExtension ) throws Exception {
143122 SSLContext sslContext ;
144123 char [] password = "password" .toCharArray ();
145- SecureRandom secureRandom ;
146- String fileExtension ;
147-
148- if (CryptoServicesRegistrar .isInApprovedOnlyMode ()) {
149- secureRandom = SecureRandom .getInstance ("DEFAULT" , "BCFIPS" );
150- fileExtension = ".bcfks" ;
151- } else {
152- secureRandom = SecureRandom .getInstanceStrong ();
153- fileExtension = ".jks" ;
154- }
155124
156125 try (
157126 InputStream trustStoreFile = RestClientBuilderIntegTests .class .getResourceAsStream ("/test_truststore" + fileExtension );
0 commit comments