使用科尔多瓦文件传输在SSL环境上传文件时出错 [英] Error uploading file using Cordova filetransfer in SSL environment

查看:193
本文介绍了使用科尔多瓦文件传输在SSL环境上传文件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在面临的一个问题,而试图用科尔多瓦文件传输的API,而工作灯开发服务器在运行HTTPS上载文件。

我创建了一个有效的CA证书,并把它放在服务器上,以及它导入到Android模拟器。

我能够登录到使用文件传输API的应用和下载数据,但是当我尝试用它来上传数据,我在LogCat中得到下面的消息。

在code呼吁我们的WL应用程序执行的下载和上传实现的servlet。

  9月11日至26日:20:27.854:E /文件传输(2362): {\"target\":\"https:\\/\\/my-ip-address\\/APP\\/appServlet\",\"source\":\"file:\\/\\/\\/storage\\/sdcard\\/anywhere\\/wilson\\/app2\\/it_1305\\/1416946570255.jpg\",\"http_status\":0,\"$c$c\":3}
9月11日至26日:20:27.854:E /文件传输(2362):java.io.IOException异常:主机名我的IP地址的未经过验证
9月11日至26日:20:27.854:E /文件传输(2362):在com.squareup.okhttp.Connection.upgradeToTls(Connection.java:146)
9月11日至26日:20:27.854:E /文件传输(2362):在com.squareup.okhttp.Connection.connect(Connection.java:106)
9月11日至26日:20:27.854:E /文件传输(2362):在com.squareup.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:287)
9月11日至26日:20:27.854:E /文件传输(2362):在com.squareup.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:248)
9月11日至26日:20:27.854:E /文件传输(2362):在com.squareup.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:197)
9月11日至26日:20:27.854:E /文件传输(2362):在com.squareup.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:383)
9月11日至26日:20:27.854:E /文件传输(2362):在com.squareup.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:127)
9月11日至26日:20:27.854:E /文件传输(2362):在com.squareup.okhttp.internal.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:179)
9月11日至26日:20:27.854:E /文件传输(2362):在org.apache.cordova.filetransfer.FileTransfer $ 1.run(FileTransfer.java:388)
9月11日至26日:20:27.854:E /文件传输(2362):在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
9月11日至26日:20:27.854:E /文件传输(2362):在java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:587)
9月11日至26日:20:27.854:E /文件传输(2362):在java.lang.Thread.run(Thread.java:841)
9月11日至26日:20:27.854:E /文件传输(2362):上传0 18725字节后失败。


解决方案

这是错误意味着你没有使用你的服务器的主机名作为CN证书。 Android的验证CN(通用名)的主机名匹配,否则该证书是无效的,因为它可以用你的证书,以pretend,他们是你的(这个位置的详细信息)

如果您的服务器没有一个主机名(如hostname.com),只需一个IP地址,你必须在主题备用名称(SAN)作为证书extenstions的一部分指定IP。参阅如何将其添加为一个扩展这个答案。中的具体步骤将取决于工具,您用来生成证书。

有关更详细的信息,请看看这里就如何应对Android文档HTTPS和SSL 。特别是,他们有一个部分解释如何处理你遇到的问题,题为常见问题与主机名验证。

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.

I created a certificate with a valid CA and put it in the server, as well as imported it to the the Android Emulator.

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.

The code is calling a servlet implemented with our WL application to execute the download and upload.

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. 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).

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. 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. Particularly, they have a section explaining how to deal with the problem that you are having, titled 'Common Problems with Hostname Verification'.

这篇关于使用科尔多瓦文件传输在SSL环境上传文件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆