Last active
May 10, 2019 20:29
-
-
Save andymc12/25e7a4e445a1bc7e284717b3c1bf6f9a to your computer and use it in GitHub Desktop.
When running this against the HttpServer in the MP Rest Client 1.3 TCK, I get the following exception:
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
import java.io.*; | |
import java.net.*; | |
import java.security.*; | |
import javax.net.ssl.*; | |
public class TestSSLwithStores { | |
private static String TEST_URL = "https://localhost:8948"; | |
private static String SSL_DIR = "/path/to/microprofile-rest-client/tck/src/main/resources/ssl/"; | |
public static void main(String[] args) throws Throwable { | |
InputStream keyStream = new FileInputStream(SSL_DIR + "client.keystore"); | |
InputStream trustStream = new FileInputStream(SSL_DIR + "client.truststore"); | |
char[] password = "password".toCharArray(); | |
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); | |
keyStore.load(keyStream, password); | |
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); | |
trustStore.load(trustStream, password); | |
KeyManagerFactory keyFactory = | |
KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); | |
keyFactory.init(keyStore, password); | |
KeyManager[] keyManagers = keyFactory.getKeyManagers(); | |
TrustManagerFactory trustFactory = | |
TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); | |
trustFactory.init(trustStore); | |
TrustManager[] trustManagers = trustFactory.getTrustManagers(); | |
SSLContext sslContext = SSLContext.getInstance("SSL"); | |
sslContext.init(keyManagers, trustManagers, null); | |
SSLContext.setDefault(sslContext); | |
URL url = new URL(TEST_URL); | |
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); | |
connection.connect(); | |
System.out.println(connection.getResponseCode()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I built the TestSSLWithStores class using guidance from: https://stackoverflow.com/questions/8339200/how-can-i-use-certificate-authentication-with-httpsurlconnection
Here is the exception I see when running this agains the HttpsServer in the MP Rest Client 1.3 TCK:
When I test this with Apache CXF, I see these tests fail with essentially the same stack trace:
Note that the line number may be off somewhat, as I added the following code to the tests to allow me time to try running the standalone test case above: