|
36 | 36 | import java.io.InputStream;
|
37 | 37 | import java.net.InetAddress;
|
38 | 38 | import java.net.InetSocketAddress;
|
| 39 | +import java.nio.file.Files; |
| 40 | +import java.nio.file.Paths; |
| 41 | +import java.security.KeyFactory; |
39 | 42 | import java.security.KeyStore;
|
| 43 | +import java.security.cert.Certificate; |
| 44 | +import java.security.cert.CertificateFactory; |
| 45 | +import java.security.spec.PKCS8EncodedKeySpec; |
40 | 46 |
|
41 | 47 | import static org.hamcrest.Matchers.instanceOf;
|
42 | 48 | import static org.junit.Assert.assertEquals;
|
@@ -101,12 +107,20 @@ private RestClient buildRestClient() {
|
101 | 107 |
|
102 | 108 | private static SSLContext getSslContext() throws Exception {
|
103 | 109 | SSLContext sslContext = SSLContext.getInstance("TLS");
|
104 |
| - try (InputStream in = RestClientBuilderIntegTests.class.getResourceAsStream("/testks.jks")) { |
105 |
| - KeyStore keyStore = KeyStore.getInstance("JKS"); |
106 |
| - keyStore.load(in, "password".toCharArray()); |
107 |
| - KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); |
| 110 | + try (InputStream certFile = RestClientBuilderIntegTests.class.getResourceAsStream("/test.crt")) { |
| 111 | + // Build a keystore of default type programmatically since we can't use JKS keystores to |
| 112 | + // init a KeyManagerFactory in FIPS 140 JVMs. |
| 113 | + KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); |
| 114 | + keyStore.load(null, "password".toCharArray()); |
| 115 | + CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); |
| 116 | + PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(Files.readAllBytes(Paths.get(RestClientBuilderIntegTests.class |
| 117 | + .getResource("/test.der").toURI()))); |
| 118 | + KeyFactory keyFactory = KeyFactory.getInstance("RSA"); |
| 119 | + keyStore.setKeyEntry("mykey", keyFactory.generatePrivate(privateKeySpec), "password".toCharArray(), |
| 120 | + new Certificate[]{certFactory.generateCertificate(certFile)}); |
| 121 | + KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); |
108 | 122 | kmf.init(keyStore, "password".toCharArray());
|
109 |
| - TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509"); |
| 123 | + TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); |
110 | 124 | tmf.init(keyStore);
|
111 | 125 | sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
|
112 | 126 | }
|
|
0 commit comments