Hello im trying to handshake with SSL on android and im getting this error:
10-21 15:39:33.279: W/System.err(500): javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
10-21 15:39:33.279: W/System.err(500): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:381)
10-21 15:39:33.279: W/System.err(500): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLOutputStream.<init>(OpenSSLSocketImpl.java:681)
10-21 15:39:33.279: W/System.err(500): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.getOutputStream(OpenSSLSocketImpl.java:618)
10-21 15:39:33.279: W/System.err(500): at com.example.workoutlog.TestSSL.<init>(TestSSL.java:43)
10-21 15:39:33.279: W/System.err(500): at com.example.workoutlog.HomePage$GetHandShake.doInBackground(HomePage.java:1816)
10-21 15:39:33.279: W/System.err(500): at com.example.workoutlog.HomePage$GetHandShake.doInBackground(HomePage.java:1)
10-21 15:39:33.289: W/System.err(500): at android.os.AsyncTask$2.call(AsyncTask.java:287)
10-21 15:39:33.289: W/System.err(500): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
10-21 15:39:33.289: W/System.err(500): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
10-21 15:39:33.289: W/System.err(500): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
10-21 15:39:33.289: W/System.err(500): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
10-21 15:39:33.289: W/System.err(500): at java.lang.Thread.run(Thread.java:856)
10-21 15:39:33.289: W/System.err(500): Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
10-21 15:39:33.289: W/System.err(500): at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:276)
10-21 15:39:33.289: W/System.err(500): at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:197)
10-21 15:39:33.289: W/System.err(500): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.verifyCertificateChain(OpenSSLSocketImpl.java:584)
10-21 15:39:33.299: W/System.err(500): at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_do_handshake(Native Method)
10-21 15:39:33.299: W/System.err(500): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:378)
10-21 15:39:33.299: W/System.err(500): ... 11 more
10-21 15:39:33.299: W/System.err(500): Caused by: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
10-21 15:39:33.299: W/System.err(500): ... 16 more
10-21 15:39:33.299: W/dalvikvm(500): threadid=17: thread exiting with uncaught exception (group=0x40cf7930)
10-21 15:39:33.310: W/GAV2(500): Thread[AsyncTask #4,5,main]: dispatch call queued. Need to call GAServiceManager.getInstance().initialize().
This is my code:
public class TestSSL {
SSLSocket sslsocket;
Context context;
public TestSSL(Context context)
{
SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
try {
sslsocket = (SSLSocket) sslsocketfactory.createSocket("server", port);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
InputStream inputstream = null;
try {
inputstream = sslsocket.getInputStream();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
BufferedReader bufferedreader = new BufferedReader(inputstreamreader);
OutputStream outputstream = null;
try {
outputstream = sslsocket.getOutputStream();
} catch (IOException e) {
e.printStackTrace();
}
OutputStreamWriter outputstreamwriter = new OutputStreamWriter(outputstream);
BufferedWriter bufferedwriter = new BufferedWriter(outputstreamwriter);
sslsocket.addHandshakeCompletedListener(new HandshakeCompletedListener() {
@Override
public void handshakeCompleted(HandshakeCompletedEvent event) {
// TODO Auto-generated method stub
Log.i("test", event.toString());
}
});
try {
sslsocket.startHandshake();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Why im getting this error? Thanks.
I suppose you are trying to connect on dev server with self-signed certificate. Read the following article.
http://developer.android.com/training/articles/security-ssl.html#HttpsExample
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With