Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Won't Fix
-
None
-
None
-
None
Description
FileTransfer's download function fails when trying to download a file from a site using TLS 1.2. This works fine in Android 5 or higher, but it fails in Android 4.x.
I searched a bit and I found that Android 4.4 should support TLS1.2 but it is disabled by default. I applied the solution proposed in this post and it worked for me:
http://stackoverflow.com/a/33567745
That is, I created the MySSLSocketFactory class in the FileTransfer project, and I used it in the trustAllHosts function (line 636 of FileTransfer.java):
SSLSocketFactory newFactory = new MySSLSocketFactory(sc.getSocketFactory());
I'm not sure if this can cause problems with other certificates, I don't know much about this. It would be nice if the Cordova team could take a look at this and check if it can be solved.
This is the stacktrace:
Error getting HTTP status code from connection. javax.net.ssl.SSLException: Connection closed by peer at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method) at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:405) at com.android.okhttp.Connection.upgradeToTls(Connection.java:146) at com.android.okhttp.Connection.connect(Connection.java:107) at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:294) at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255) at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206) at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345) at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:89) at com.android.okhttp.internal.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:161) at org.apache.cordova.filetransfer.FileTransfer$4.run(FileTransfer.java:869) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at java.lang.Thread.run(Thread.java:841)
It can be tested with this code:
var ft = new FileTransfer(), path = 'squirrel.jpg', uri = 'https://prototype.moodle.net/mobile/moodle32/webservice/pluginfile.php/314/mod_resource/content/3/squirrel.jpg?forcedownload=1&token=616455be9f363cc9631cab89cfcfa1cd'; ft.download(uri, path, success, error, true); function success() { console.log('Success'); } function error(data) { console.log('Error', data); }
Attachments
Issue Links
- links to