Ionic v1 - $cordovaFileTransfer failing only on Android 7


#1

I am using $cordovaFileTransfer (ngCordova wrapper around cordova-plugin-file-transfer 1.7.1 "File Transfer" & cordova-plugin-file 6.0.1 "File")

This code works fine on iOS (11.x) but has stopped working on Android 7.0 (was working on 6.x)

The error is:

May 3, 2018 03:26:47 PM INFO Error 
{"code":3,"source":"https://server/zm/index.php?
    view=view_video&eid=218648","target":
    "file:///data/user/0/com.pliablepixels.zmninja_pro/files/temp-video.mp4","http_status":null,"body":null,
    "exception":"java.security.cert.CertPathValidatorException: 
Trust anchor for certification path not found."}

The code in question:

$cordovaFileTransfer.download(path, tp, opt, th)

where:

path: url to mp4 file
tp: target path on device
opt = {}
th = true (I used self signed certificates)

Given this code worked well in Android 6, are you aware on any changes to 7 that I need to consider?

Detailed adb logs, if it helps:

05-03 15:26:47.156  5410  5410 D SystemWebChromeClient: file:///android_asset/www/lib/filelogger/dist/filelogger.min.js: Line 6 : May 3, 2018 03:26:47 PM DEBUG Saving temporary video to: file:///data/user/0/com.pliablepixels.zmninja_pro/files/temp-video.mp4
05-03 15:26:47.156  5410  5410 I chromium: [INFO:CONSOLE(6)] "May 3, 2018 03:26:47 PM DEBUG Saving temporary video to: file:///data/user/0/com.pliablepixels.zmninja_pro/files/temp-video.mp4", source: file:///android_asset/www/lib/filelogger/dist/filelogger.min.js (6)
05-03 15:26:47.160  5410  5644 D FileTransfer: download https://myserver/zm/index.php?view=view_video&eid=218648 to file:///data/user/0/com.pliablepixels.zmninja_pro/files/temp-video.mp4
05-03 15:26:47.161  5410 13546 D FileTransfer: Download file:https://myserver/zm/index.php?view=view_video&eid=218648
05-03 15:26:47.270  5410 13548 D TEST    : cdvfile://localhost/files/zmNinjaLog.txt: 128
05-03 15:26:47.308  5410 13546 W FileTransfer: Error getting HTTP status code from connection.
05-03 15:26:47.308  5410 13546 W FileTransfer: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
05-03 15:26:47.308  5410 13546 W FileTransfer:  at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:361)
05-03 15:26:47.308  5410 13546 W FileTransfer:  at com.android.okhttp.Connection.connectTls(Connection.java:235)
05-03 15:26:47.308  5410 13546 W FileTransfer:  at com.android.okhttp.Connection.connectSocket(Connection.java:199)
05-03 15:26:47.308  5410 13546 W FileTransfer:  at com.android.okhttp.Connection.connect(Connection.java:172)
05-03 15:26:47.308  5410 13546 W FileTransfer:  at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:367)
05-03 15:26:47.308  5410 13546 W FileTransfer:  at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:130)
05-03 15:26:47.308  5410 13546 W FileTransfer:  at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:329)
05-03 15:26:47.308  5410 13546 W FileTransfer:  at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:246)
05-03 15:26:47.308  5410 13546 W FileTransfer:  at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:457)
05-03 15:26:47.308  5410 13546 W FileTransfer:  at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:126)
05-03 15:26:47.308  5410 13546 W FileTransfer:  at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.connect(DelegatingHttpsURLConnection.java:89)
05-03 15:26:47.308  5410 13546 W FileTransfer:  at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java)
05-03 15:26:47.308  5410 13546 W FileTransfer:  at org.apache.cordova.filetransfer.FileTransfer$2.run(FileTransfer.java:779)
05-03 15:26:47.308  5410 13546 W FileTransfer:  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
05-03 15:26:47.308  5410 13546 W FileTransfer:  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
05-03 15:26:47.308  5410 13546 W FileTransfer:  at java.lang.Thread.run(Thread.java:761)
05-03 15:26:47.308  5410 13546 W FileTransfer: Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
05-03 15:26:47.308  5410 13546 W FileTransfer:  at com.android.org.conscrypt.TrustManagerImpl.verifyChain(TrustManagerImpl.java:563)
05-03 15:26:47.308  5410 13546 W FileTransfer:  at com.android.org.conscrypt.TrustManagerImpl.checkTrustedRecursive(TrustManagerImpl.java:444)
05-03 15:26:47.308  5410 13546 W FileTransfer:  at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:401)
05-03 15:26:47.308  5410 13546 W FileTransfer:  at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:375)
05-03 15:26:47.308  5410 13546 W FileTransfer:  at com.android.org.conscrypt.TrustManagerImpl.getTrustedChainForServer(TrustManagerImpl.java:304)
05-03 15:26:47.308  5410 13546 W FileTransfer:  at android.security.net.config.NetworkSecurityTrustManager.checkServerTrusted(NetworkSecurityTrustManager.java:94)
05-03 15:26:47.308  5410 13546 W FileTransfer:  at android.security.net.config.RootTrustManager.checkServerTrusted(RootTrustManager.java:88)
05-03 15:26:47.308  5410 13546 W FileTransfer:  at com.android.org.conscrypt.Platform.checkServerTrusted(Platform.java:178)
05-03 15:26:47.308  5410 13546 W FileTransfer:  at com.android.org.conscrypt.OpenSSLSocketImpl.verifyCertificateChain(OpenSSLSocketImpl.java:596)
05-03 15:26:47.308  5410 13546 W FileTransfer:  at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
05-03 15:26:47.308  5410 13546 W FileTransfer:  at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:357)
05-03 15:26:47.308  5410 13546 W FileTransfer:  ... 15 more
05-03 15:26:47.308  5410 13546 W FileTransfer: Caused by: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
05-03 15:26:47.308  5410 13546 W FileTransfer:  ... 26 more
05-03 15:26:47.309  5410 13546 E FileTransfer: {"code":3,"source":"https:\/\/myserver\/zm\/index.php?view=view_video&eid=218648","target":"file:\/\/\/data\/user\/0\/com.pliablepixels.zmninja_pro\/files\/temp-video.mp4","http_status":0,"exception":"java.security.cert.CertPathValidatorException: Trust anchor for certification path not found."}
05-03 15:26:47.309  5410 13546 E FileTransfer: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
05-03 15:26:47.309  5410 13546 E FileTransfer:  at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:361)
05-03 15:26:47.309  5410 13546 E FileTransfer:  at com.android.okhttp.Connection.connectTls(Connection.java:235)
05-03 15:26:47.309  5410 13546 E FileTransfer:  at com.android.okhttp.Connection.connectSocket(Connection.java:199)
05-03 15:26:47.309  5410 13546 E FileTransfer:  at com.android.okhttp.Connection.connect(Connection.java:172)
05-03 15:26:47.309  5410 13546 E FileTransfer:  at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:367)
05-03 15:26:47.309  5410 13546 E FileTransfer:  at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:130)
05-03 15:26:47.309  5410 13546 E FileTransfer:  at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:329)
05-03 15:26:47.309  5410 13546 E FileTransfer:  at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:246)
05-03 15:26:47.309  5410 13546 E FileTransfer:  at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:457)
05-03 15:26:47.309  5410 13546 E FileTransfer:  at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:126)
05-03 15:26:47.309  5410 13546 E FileTransfer:  at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.connect(DelegatingHttpsURLConnection.java:89)
05-03 15:26:47.309  5410 13546 E FileTransfer:  at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java)
05-03 15:26:47.309  5410 13546 E FileTransfer:  at org.apache.cordova.filetransfer.FileTransfer$2.run(FileTransfer.java:779)
05-03 15:26:47.309  5410 13546 E FileTransfer:  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
05-03 15:26:47.309  5410 13546 E FileTransfer:  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
05-03 15:26:47.309  5410 13546 E FileTransfer:  at java.lang.Thread.run(Thread.java:761)
05-03 15:26:47.309  5410 13546 E FileTransfer: Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
05-03 15:26:47.309  5410 13546 E FileTransfer:  at com.android.org.conscrypt.TrustManagerImpl.verifyChain(TrustManagerImpl.java:563)
05-03 15:26:47.309  5410 13546 E FileTransfer:  at com.android.org.conscrypt.TrustManagerImpl.checkTrustedRecursive(TrustManagerImpl.java:444)
05-03 15:26:47.309  5410 13546 E FileTransfer:  at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:401)
05-03 15:26:47.309  5410 13546 E FileTransfer:  at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:375)
05-03 15:26:47.309  5410 13546 E FileTransfer:  at com.android.org.conscrypt.TrustManagerImpl.getTrustedChainForServer(TrustManagerImpl.java:304)
05-03 15:26:47.309  5410 13546 E FileTransfer:  at android.security.net.config.NetworkSecurityTrustManager.checkServerTrusted(NetworkSecurityTrustManager.java:94)
05-03 15:26:47.309  5410 13546 E FileTransfer:  at android.security.net.config.RootTrustManager.checkServerTrusted(RootTrustManager.java:88)
05-03 15:26:47.309  5410 13546 E FileTransfer:  at com.android.org.conscrypt.Platform.checkServerTrusted(Platform.java:178)
05-03 15:26:47.309  5410 13546 E FileTransfer:  at com.android.org.conscrypt.OpenSSLSocketImpl.verifyCertificateChain(OpenSSLSocketImpl.java:596)
05-03 15:26:47.309  5410 13546 E FileTransfer:  at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
05-03 15:26:47.309  5410 13546 E FileTransfer:  at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:357)
05-03 15:26:47.309  5410 13546 E FileTransfer:  ... 15 more
05-03 15:26:47.309  5410 13546 E FileTransfer: Caused by: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
05-03 15:26:47.309  5410 13546 E FileTransfer:  ... 26 more

#2

Problem solved. It was necessary to install the self signed certificate on the device too. I don’t recall if it was previously installed whilst on Android 6 or not, so not 100% sure if its an Android 7 only issue.