89078

Java SSLSocket handshake failure

Question:

I'm trying to find a way to establish a connection beetwen a Java client and a C server using SSL.

This is the java client:

import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocketFactory; public class Main { public static void main(String[] args) throws IOException { SSLSocketFactory sslsockfact = (SSLSocketFactory) SSLSocketFactory.getDefault(); SSLSocket sslsocket = (SSLSocket) sslsockfact.createSocket( args[0], Integer.parseInt(args[1])); sslsocket.startHandshake(); System.in.read(); } }

It's only a few functions to establish connection and perform handshake, but I'm getting this error:

Exception in thread "main" javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174) at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:136) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.recvAlert( SSLSocketImpl.java:1657) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord( SSLSocketImpl.java:932) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake( SSLSocketImpl.java:1096) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake( SSLSocketImpl.java:1123) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake( SSLSocketImpl.java:1107) at posslu.Main.main(Main.java:22) Java Result: 1

Unfortunately I don't have any sources of the server program - I only know the protocol. Is it even possible to connect java and C++ using ssl? AFAIK server is written using openssl.

Any help?

EDIT:

I'm connecting from Windows to Linux and server's using posix sockets.

Answer1:

Yes, it's definitely possible to communicate via SSL between Java and C.

The Java client code may be failing because it doesn't recognise the server certificate being sent.

You need to make sure that the server's certificate is present in the Java client's trust store.

Answer2:

Try setting this system property:

System.setProperty("javax.net.debug", "all");

This will give you much debugging information on what is happening during the handshake.

Recommend

  • java.rmi.ConnectException: Connection refused to host: 10.0.0.57 [duplicate]
  • javax.net.ssl.SSLHandshakeException: Connection closed by peer at com.android.org.conscrypt.NativeCr
  • Disabling Python 3.2 ResourceWarning
  • php mcrypt equivalent for sagepay on a windows server
  • How to enforce TLS1.2 to Rest client using Rest Template
  • Excel VBA: search a string to find the first non-text character
  • Geocoder works in 1.6 but not in 2.2 emulator
  • LocateRegistry.createRegistry
  • Eventbus onMessageEvent not getting called
  • problem with classes not found during PlayPlugin.enhance
  • Authentication failed with Azure Active Directory in Windows Phone
  • Creating Java object from class name with constructor, which contains parameters [duplicate]
  • how to find common suffix in java by using method
  • Display java JPanel in a JFrame
  • onBackPressed() not being executed
  • How to use RequestBodyAdvice
  • How to test if a URL from an Eclipse bundle is a directory?
  • iOS: Detect app start via notification press
  • how to adjust image in a panel in Java swing?
  • How to access EntityManager inside Entity class in EJB3
  • how to do an event when i swipe from fragment to the other
  • Spring Data JPA custom method causing PropertyReferenceException
  • JFileChooser in front of fullscreen Swing application
  • Array.prototype.includes - not transformed with babel
  • HTML download movie download link
  • How to draw moving and Running sine wave chart using JFree chart in java?
  • Possible to stop flickering java tooltip in heavyweight mode?
  • output of program is not same as passed argument
  • sending/ receiving email in Java
  • Eraser for UIBezierPath
  • Akka Routing: Reply's send to router ends up as dead letters
  • How to delete a row from a dynamic generate table using jquery?
  • Proper way to use connect-multiparty with express.js?
  • Suggestions to manage Login/Logout transitions
  • Exception on Android 4.0 `android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode)`
  • unknown Exception android
  • EntityFramework adding new object to nested object collection
  • Checking variable from a different class in C#
  • failed to connect to specific WiFi in android programmatically
  • How can I use threading to 'tick' a timer to be accessed by other threads?