【发布时间】:2017-06-27 12:42:11
【问题描述】:
我试图在这里为我寻找一些答案,但我找不到任何可以解决我问题的方法。
在我正在进行的项目中,我们将更改我们的域。更改有点棘手 - 我们还必须将连接从 HTTP 更改为 HTTPS。我已收到 .crt 密钥(例如,example.tech.crt - 会将所有公司名称更改为“example”)。经过几个小时的不断失败,我决定在这里写。
首先,我尝试使用本教程http://ogrelab.ikratko.com/using-android-volley-with-self-signed-certificate/ - 但它不起作用(我什至不是说因为 API23 我不得不使用已弃用的 Apache 库)。如果需要,这就是我创建 BKS 文件的方式:
keytool -importcert -v -trustcacerts -file "example.tech.crt" -alias example_tech
-keystore "example_tech.bks" -provider org.bouncycastle.jce.provider.BouncyCastleProvider
-providerpath "bcprov-jdk16-146.jar" -storetype BKS
然后,我尝试了这种方法Does Android Volley support SSL? - 最佳答案中的一种(忽略域名检查)。我仍然尝试使用 BKS 文件 - 我有一些关于转换错误的例外情况,所以我更改了行:
CertificateFactory cf = CertificateFactory.getInstance("X.509");
到
CertificateFactory cf = CertificateFactory.getInstance("X.509", "BC");
正如某处所建议的那样 - 错误仍然存在。我尝试使用 .crt 文件而不是 BKS - 我仍然失败。
每次我都会遇到同样的错误:
javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException:
SSL handshake aborted: ssl=0x650f83a0: Failure in SSL library, usually a protocol error
error:14077102:SSL routines:SSL23_GET_SERVER_HELLO:unsupported protocol
(external/openssl/ssl/s23_clnt.c:714 0x5fda0d74:0x00000000)
我尝试使用 Postman 执行几乎相同的请求,并且它们在同一个地址上工作没有任何问题,所以这不是服务器问题。我尝试使用各种域 - example.tech、www.example.tech、example.tech:80 等等(当然总是使用 https)。
以下是类似 curl 的请求示例(当然经过审查):
curl request: curl -X "POST"
-D "grant_type=password&password=[passwordHere]&username=[emailHere]&"
-H 'Authorization: Basic [tokenHere]
"https://example.tech/oauth/token"
我看不到我的代码有什么问题,我很高兴看到我在这里做错了什么。如果需要更多代码,请随时提出要求(但其中 99% 与第二个链接一样,只有非常小的改动)。
【问题讨论】:
-
.crt 不是键。它是一个证书。您在某处启用了 SSLv2 或至少 SSLv2ClientHello。
标签: android ssl https android-volley