nativescript-community/https

Android error when do request to webservice

Closed this issue · 15 comments

Hi! when I do request to my webservice, Android side throws this exception:
javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

What I'm doing wrong? same code works on iOS. please help me.

var dir = fileSystem.knownFolders.currentApp().getFolder('certs');
console.log("Dir: "+JSON.stringify(dir));
var certificate = dir.getFile('APISICAR.cer').path;
console.log("Certificado path: "+certificate);
Https.enableSSLPinning({ host: "192.168.0.130", certificate, allowInvalidCertificates:true});

can you print the console logs?

Thank you for reply. Here are app logs.

D/AndroidRuntime(12685): >>>>>> START com.android.internal.os.RuntimeInit uid 2000 <<<<<<
D/AndroidRuntime(12685): CheckJNI is OFF
D/AndroidRuntime(12685): readGMSProperty: start
D/AndroidRuntime(12685): readGMSProperty: already setted!!
D/AndroidRuntime(12685): readGMSProperty: end
D/phoneserver( 177): Receive thread's TID [198] CHNMNG:readline pread= 0xb6f536e0,count=50
D/phoneserver( 177): Receive thread's TID [198] CHMNG: receive data thread :mux=/dev/stty_w0
D/phoneserver( 177): Receive thread's TID [198] MUX :/dev/stty_w0 Waiting for resp
D/phoneserver( 177): Receive thread's TID [198] CHMNG: receive data thread :mux=/dev/stty_w0
D/phoneserver( 177): Receive thread's TID [198] MUX :/dev/stty_w0 Waiting for resp
D/phoneserver( 177): Receive thread's TID [198] CHMNG: receive data thread :mux=/dev/stty_w0
D/phoneserver( 177): Receive thread's TID [198] MUX :/dev/stty_w0 Waiting for resp
D/StatusBar.NetworkController( 832): refreshViews connected={ wifi } level=4 combinedSignalIconId=0x7f0202d8/com.android.systemui:drawable/stat_sys_wifi_signal_3 mobileLabel=weex wifiLabel="DevSICAR" emergencyOnly=false combinedLabel="DevSICAR" mAirplaneMode=false mDataActivity=0 mPhoneSignalIconId=0x7f02029a/com.android.systemui:drawable/stat_sys_signal_4_auto_rotate mQSPhoneSignalIconId=0x7f020098/com.android.systemui:drawable/ic_qs_signal_4 mDataDirectionIconId=0x0/(null) mDataSignalIconId=0x7f02029a/com.android.systemui:drawable/stat_sys_signal_4_auto_rotate mDataTypeIconId=0x7f0201fc/com.android.systemui:drawable/stat_sys_data_connected_h mQSDataTypeIconId=0x7f0200a1/com.android.systemui:drawable/ic_qs_signal_h mNoSimIconId=0x0/(null) mWifiIconId=0x7f0202d8/com.android.systemui:drawable/stat_sys_wifi_signal_3 mQSWifiIconId=0x7f0200ab/com.android.systemui:drawable/ic_qs_wifi_3 mWifiActivityIconId=0x7f0202ac/com.android.systemui:drawable/stat_sys_signal_inout mBluetoothTetherIconId=0x7f0202b9/com.android.systemui:drawable/stat_sys_tether_bluetooth
D/STATUSBAR-WifiQuickSettingButton( 832): onWifiSignalChanged enabled=true enabledDesc:"DevSICAR"
D/AndroidRuntime(12685): addProductProperty: start
D/StatusBar.NetworkController( 832): updateTelephonySignalStrength: hasService=true ss=SignalStrength: 14 99 -120 -160 -120 -1 -1 99 2147483647 2147483647 2147483647 2147483647 2147483647 0x0 gsm|lte
D/StatusBar.NetworkController( 832): updateTelephonySignalStrength: iconLevel=4
D/StatusBar.NetworkController( 832): updateTelephonySignalStrength, No signal level. mPhoneSignalIconId = com.android.systemui:drawable/stat_sys_signal_4_auto_rotate mDataSignalIconId = com.android.systemui:drawable/stat_sys_signal_4_auto_rotate mQSPhoneSignalIconId = com.android.systemui:drawable/ic_qs_signal_4 mContentDescriptionPhoneSignal = Cobertura total
D/StatusBar.NetworkController( 832): refreshViews connected={ wifi } level=4 combinedSignalIconId=0x7f0202d8/com.android.systemui:drawable/stat_sys_wifi_signal_3 mobileLabel=weex wifiLabel="DevSICAR" emergencyOnly=false combinedLabel="DevSICAR" mAirplaneMode=false mDataActivity=0 mPhoneSignalIconId=0x7f02029a/com.android.systemui:drawable/stat_sys_signal_4_auto_rotate mQSPhoneSignalIconId=0x7f020098/com.android.systemui:drawable/ic_qs_signal_4 mDataDirectionIconId=0x0/(null) mDataSignalIconId=0x7f02029a/com.android.systemui:drawable/stat_sys_signal_4_auto_rotate mDataTypeIconId=0x7f0201fc/com.android.systemui:drawable/stat_sys_data_connected_h mQSDataTypeIconId=0x7f0200a1/com.android.systemui:drawable/ic_qs_signal_h mNoSimIconId=0x0/(null) mWifiIconId=0x7f0202d8/com.android.systemui:drawable/stat_sys_wifi_signal_3 mQSWifiIconId=0x7f0200ab/com.android.systemui:drawable/ic_qs_wifi_3 mWifiActivityIconId=0x7f0202ac/com.android.systemui:drawable/stat_sys_signal_inout mBluetoothTetherIconId=0x7f0202b9/com.android.systemui:drawable/stat_sys_tether_bluetooth
D/STATUSBAR-WifiQuickSettingButton( 832): onWifiSignalChanged enabled=true enabledDesc:"DevSICAR"
E/memtrack(12685): Couldn't load memtrack module (No such file or directory)
E/android.os.Debug(12685): failed to load memtrack module: -2
D/ClClient( 7617): Not sending keepalive. Current connection state=STOPPED
D/AndroidRuntime(12685): Calling main entry com.android.commands.pm.Pm
E/JS (12403): Https.request error javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
W/System.err(12403): javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
W/System.err(12403): at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:322)
W/System.err(12403): at com.android.okhttp.Connection.upgradeToTls(Connection.java:1257)
W/System.err(12403): at com.android.okhttp.Connection.connect(Connection.java:1188)
W/System.err(12403): at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:395)
W/System.err(12403): at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:298)
W/System.err(12403): at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:399)
W/System.err(12403): at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:110)
W/System.err(12403): at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.connect(DelegatingHttpsURLConnection.java:89)
W/System.err(12403): at com.android.okhttp.internal.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:25)
W/System.err(12403): at org.nativescript.widgets.Async$Http$HttpRequestTask.doInBackground(Async.java:541)
W/System.err(12403): at org.nativescript.widgets.Async$Http$1.run(Async.java:480)
W/System.err(12403): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
W/System.err(12403): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
W/System.err(12403): at org.nativescript.widgets.Async$PriorityThreadFactory$1.run(Async.java:52)
W/System.err(12403): at java.lang.Thread.run(Thread.java:818)
W/System.err(12403): Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
W/System.err(12403): at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:324)
W/System.err(12403): at com.android.org.conscrypt.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:225)
W/System.err(12403): at com.android.org.conscrypt.Platform.checkServerTrusted(Platform.java:114)
W/System.err(12403): at com.android.org.conscrypt.OpenSSLSocketImpl.verifyCertificateChain(OpenSSLSocketImpl.java:550)
W/System.err(12403): at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
W/System.err(12403): at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:318)
W/System.err(12403): ... 14 more
W/System.err(12403): Caused by: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
W/System.err(12403): ... 20 more
V/JS (12403): en ErrorError: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
I/art (12685): System.exit called, status: 0

Eh, sorry man, I have no idea what could be causing this. It sounds like you're not setting the path correctly to your cert file.

@dgma I encountered this error message "Trust anchor for certification path not found." Are you using subdomain and wildcard SSL Cert in your Web Server? Try use exactly domain name.

the same problem, i'm using NativeScript-https module with exactly domaine name (in localhost)

@almorabet
Make sure your cert must not wildcard cert.

@kentplaza thanks for reply, no the cert is self signed for testing purpose and doesn't contain wildcard
CN=10.0.3.2

zenz commented

@almorabet Self signed Cert is not supported.

@zenz thanks for reply, i'll try with trusted Cert

@zenz you're right, Self signed Cert was the problem.

Hi, I have the same error, is there any workaround to accept self signed cert?

inane commented

same scenario, any work around?

Hi, I have this problem with a wildcard certificate. Any available workaround?
I can paste my environment information if necessary.
Thanks.

Same problem here.