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!