2

I have search for a day on internet but I don't have any clue to resolve my problem.

please help me.

I have register a web service on a bank, the bank send me 2 file .crt file and .key file.

And after my customer a transaction, the bank will send me a post request message to notify my server(my server receive this message), but the bank require me to send back that message to confirm via their web service url(their url use https).

when I use code java to send message back, I receive this exception

javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure

this this is my code

URL url = new URL("https://bankurlservice"); 
HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection(); 
KeyStore ksCACert = KeyStore.getInstance(KeyStore.getDefaultType()); 
ksCACert.load(new FileInputStream("keystore path"), "keystorepass".toCharArray()); 
TrustManagerFactory tmf = TrustManagerFactory.getInstance("X509"); 
tmf.init(ksCACert);
SSLContext context = SSLContext.getInstance("TLS"); 
context.init(null, tmf.getTrustManagers(), null);
SSLSocketFactory sslSocketFactory = context.getSocketFactory();
urlConnection.setSSLSocketFactory(sslSocketFactory); 
BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); 
String res = "";
String inputLine; while ((inputLine = in.readLine()) != null) { res += inputLine; } in.close(); 
bkit07
  • 41
  • 2
  • 9
  • You have to import the public key and certificate into your key store: http://stackoverflow.com/questions/17695297/importing-the-private-key-public-certificate-pair-in-the-java-keystore – hotzst Oct 05 '15 at 08:59
  • public key is .key file that the bank send me, and certificate is .crt file, is it right? – bkit07 Oct 05 '15 at 09:24

0 Answers0