I generated a CSR using OpenSSL:
openssl req -out MyCompanyCsr.csr -new -newkey rsa:2048 -nodes -keyout MyCompanyPrivateKey.key
So starting out, we have:
- MyCompanyPrivateKey.key
- MyCompanyCsr.csr
Then I sent it to our integration partner, who responded with 3 files:
- PartnerIntermediateCa.crt
- PartnerRootCa.crt
- MyCompanyCsr.crt
Now I need to connect to their web service using mutual SSL. To do this, I know I need to set the truststore and keystore in my SSLSocketFactory for JAXB.
I'm instantiating the keystore and truststore in Java using:
KeyStore trustStore = KeyStore.getInstance("JKS");
InputStream tsis = ClassLoader.getSystemResourceAsStream(trustStorePath);
trustStore.load(tsis, "mypassword".toCharArray());
tsis.close();
KeyStore keyStore = KeyStore.getInstance("JKS");
InputStream ksis = ClassLoader.getSystemResourceAsStream(keyStorePath);
keyStore.load(ksis, "mypassword".toCharArray());
if (ksis != null) {
ksis.close();
}
TrustManagerFactory tmf =
TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(trustStore);
KeyManagerFactory kmf =
KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(keyStore, "mypassword".toCharArray());
However, attempting to use this code in connecting to the server throws a SSLHandshakeException
with the message http.client.failed
:
com.sun.xml.ws.client.ClientTransportException: HTTP transport error:
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
The keystore
and truststore
I'm using were exported from my browser, with the Client private key as a PKCS
and the Server cert as a x509 Cert PKCS#7 w/ Chain'. Then opened them up in Portecle and exported them both as
JKS` files.
Assuming the Java code is legit, how can I be sure I have correctly created the keystore
and truststore
?
Thanks very much.