0

I am getting

"javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:361) at com.android.okhttp.Connection.connectTls(Connection.java:235) at com.android.okhttp.Connection.connectSocket(Connection.java:199) at com.android.okhttp.Connection.connect(Connection.java:172) at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:367) at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:130) at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:329) at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:246) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:457) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:126) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:257) at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218) at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java)"

Exception while executing urlConnection.getOutputStream() line in android N. Please anyone help

Ichigo Kurosaki
  • 3,765
  • 8
  • 41
  • 56
svn
  • 61
  • 5
  • Your server has some sort of an SSL issue, such as using a self-signed certificate, or using a certificate from a certificate authority that is not recognized. You need to start by talking to the server maintainers and determining what sort of SSL certificate they are using. – CommonsWare Jun 19 '17 at 13:13
  • Hi... as we are in testing phase... using self signed .ca certificate – svn Jun 19 '17 at 13:33
  • And I also used network security configuration concept... no use still getting same error – svn Jun 19 '17 at 13:34
  • Network security configuration only works on Android 7.0+ (though [I have a backport](https://github.com/commonsguy/cwac-netsecurity)). Perhaps there is a bug in how you set up the network security configuration (without an [mcve], we cannot tell), or perhaps your test device is running Android 6.0 or older. – CommonsWare Jun 19 '17 at 14:06
  • Yes.. Its working very fine with Android 6.0 or older version. I am facing Problem in Android N. How can I Proceed? – svn Jun 19 '17 at 15:32
  • I have no idea, as you have not provided a [mcve]. In this case, it would include your network security configuration XML resource, the manifest entry showing your reference to that resource, and the URL that you are requesting that is generating the above stack trace. – CommonsWare Jun 19 '17 at 15:34
  • I testing in emulator with android N configuration.. also tested in Android N Device same exception I am getting. – svn Jun 19 '17 at 15:41
  • I ve added android:networkSecurityConfig="@xml/network_security_config" in Manifest. – svn Jun 19 '17 at 15:45
  •                                     is my network security config – svn Jun 19 '17 at 15:45
  • and I kept ca.cer and .p12 file under raw folder. – svn Jun 19 '17 at 15:47
  • did I missed anything ? in this configuration – svn Jun 19 '17 at 15:47
  • "and I kept ca.cer and .p12 file under raw folder" -- if you mean `ca.cer` and `ca.p12`, ideally, that would be a build error, as now there are two files known as `@raw/ca`. Make sure that one of those is in PEM or DER format, and get rid of the other one, and see if that helps. – CommonsWare Jun 19 '17 at 16:07
  • No. one is ca.cert and one more is admin.p12. – svn Jun 19 '17 at 16:19
  • I am not able to paste my connection part code as its in comment section.. – svn Jun 19 '17 at 16:46
  • I also referred https://stackoverflow.com/questions/43788568/android-7-trust-anchor-for-certification-path-not-found link. here you mentioned to remove some part of code what it is? – svn Jun 19 '17 at 16:53
  • I was referring to the custom `SSLContext` that this person was creating. – CommonsWare Jun 19 '17 at 16:57
  • Hi.. As code is lengthy m nt able to paste it here..and m not able to move to chat option also.. I want to discuss on the code.. my code part also includes SSLContext in connection method. – svn Jun 19 '17 at 17:47
  • I am sorry, but there is little more that I can suggest to you. [Here is a sample app](https://github.com/commonsguy/cw-omnibus/tree/master/Internet/CA) that demonstrates the use of network security configuration, in this case with Retrofit and Picasso (by way of OkHttp). Perhaps it will give you some further ideas. – CommonsWare Jun 19 '17 at 17:54

0 Answers0