Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

SSLHandshakeException: Received fatal alert :handshake_failure

843811Aug 23 2006 — edited Sep 6 2006
Hola forum,
I'm having a bit of a problem with ssl sockets currently. Please bear with me as this is my first run at using ssl sockets for anything and I've done a fair bit of searching on google already.

Here's the code I'm using:
(kindly ignore any typos as they are the result of having to manually type the code in - the code resides on a seperate system).
int port = 443;
String hostname = "hostname";

TrustManager[] trustAllCerts = new TrustManager[]{
   new X509TrustManager(){
      public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateExcpetion{}
      
      public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException{}

      public X509Certificate[] getAcceptedIssuers(){
          return new X509Certificate[0];
      }

SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new SecureRandom());
SSLSocketFactory factory = sslContext.getSocketFactory();

SSLSocket socket  = (SSLSocket)factory.getSocketFactory(hostname, port);
socket.setUseClientMode9true);

socket.startHandshake();
...
this throws the following exception from startHandshake():
javax.net.ssl.SSLHandhakeException: Received fatal alert: handshake_failure
      at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Unknown Source)
      at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Unknown Source)
      at com.sun.net.ssl.internal.ssl.SSLSocketImpl.recvAlert(Unknown Source)
      at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Uknown Source)
      at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
      at testcode.main(testcode.java 62)
Any insight? I would be most appreciative. Thanks!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 4 2006
Added on Aug 23 2006
8 comments
6,728 views