简体   繁体   English

在SSL环境中使用Cordova filetransfer上传文件时出错

[英]Error uploading file using Cordova filetransfer in SSL environment

I'm facing an issue while trying to use the Cordova File Transfer API to upload a file while the Worklight Development Server is running in HTTPS. 在Worklight Development Server在HTTPS中运行时,尝试使用Cordova File Transfer API上载文件时遇到问题。

I created a certificate with a valid CA and put it in the server, as well as imported it to the the Android Emulator. 我创建了具有有效CA的证书,并将其放入服务器中,并将其导入到Android仿真器中。

I'm able to login to the application and download data using the File Transfer API, but when I try to use it for uploading data I'm getting the below message in LogCat. 我可以使用File Transfer API登录到应用程序并下载数据,但是当我尝试使用它来上传数据时,我在LogCat中收到以下消息。

The code is calling a servlet implemented with our WL application to execute the download and upload. 该代码正在调用用我们的WL应用程序实现的servlet,以执行下载和上传。

11-26 09:20:27.854: E/FileTransfer(2362): {"target":"https:\/\/my-ip-address\/APP\/appServlet","source":"file:\/\/\/storage\/sdcard\/anywhere\/wilson\/app2\/it_1305\/1416946570255.jpg","http_status":0,"code":3}
11-26 09:20:27.854: E/FileTransfer(2362): java.io.IOException: Hostname 'my-ip-address' was not verified
11-26 09:20:27.854: E/FileTransfer(2362):   at com.squareup.okhttp.Connection.upgradeToTls(Connection.java:146)
11-26 09:20:27.854: E/FileTransfer(2362):   at com.squareup.okhttp.Connection.connect(Connection.java:106)
11-26 09:20:27.854: E/FileTransfer(2362):   at com.squareup.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:287)
11-26 09:20:27.854: E/FileTransfer(2362):   at com.squareup.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:248)
11-26 09:20:27.854: E/FileTransfer(2362):   at com.squareup.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:197)
11-26 09:20:27.854: E/FileTransfer(2362):   at com.squareup.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:383)
11-26 09:20:27.854: E/FileTransfer(2362):   at com.squareup.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:127)
11-26 09:20:27.854: E/FileTransfer(2362):   at com.squareup.okhttp.internal.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:179)
11-26 09:20:27.854: E/FileTransfer(2362):   at org.apache.cordova.filetransfer.FileTransfer$1.run(FileTransfer.java:388)
11-26 09:20:27.854: E/FileTransfer(2362):   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
11-26 09:20:27.854: E/FileTransfer(2362):   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
11-26 09:20:27.854: E/FileTransfer(2362):   at java.lang.Thread.run(Thread.java:841)
11-26 09:20:27.854: E/FileTransfer(2362): Failed after uploading 0 of 18725 bytes.

That error means that you did not use your server's host name as the CN for the certificate. 该错误意味着您没有将服务器的主机名用作证书的CN。 Android verifies that the CN (common name) matches the host name, otherwise the certificate is not valid, as it could be any other server using your certificate to pretend that they are you (more information about this here) . Android会验证CN(公用名)是否与主机名匹配,否则证书无效,因为它可能是使用您的证书假装自己的其他任何服务器(有关此信息,请参见此处)

If your server does not have a host name (as in hostname.com), just an IP address, you have to specify the IP in the Subject Alternative Name (SAN) as part of the certificate extenstions. 如果您的服务器没有主机名(例如hostname.com中的IP地址),则必须在“使用者备用名称”(SAN)中指定IP作为证书扩展的一部分。 Refer to this answer on how to add it as an extension. 请参阅此答案,以了解如何将其添加为扩展。 The exact procedure will depend on the tool you used to generate the certificate. 确切的过程将取决于您用来生成证书的工具。

For more detailed information, look here at the android documentation on how to deal with HTTPS and SSL. 有关更多详细信息, 参阅此处的android文档,了解如何处理HTTPS和SSL。 Particularly, they have a section explaining how to deal with the problem that you are having, titled 'Common Problems with Hostname Verification'. 特别是,他们有一节说明如何处理您遇到的问题,标题为“主机名验证的常见问题”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM