【问题标题】:Retrofit not working with maps api of sha256 test url改造不适用于 sha256 测试 url 的 maps api
【发布时间】:2015-09-29 06:49:39
【问题描述】:

我已将改造用于 google Places and Direction API 集成。最近我从 Google Maps for Work 支持团队获得了更新,为了确保您的应用程序不受影响,您需要验证您使用的 HTTPS 客户端是否支持 SHA -256.

他们提供了一个测试 url(https://cert-test.sandbox.google.com) 来验证 http-client 是否兼容

我已使用 https://cert-test.sandbox.google.com 进行了 Retrofit 验证,但它失败了,并给了我异常,如下所述:

javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL 握手中止: ssl=0x1027ce0: SSL 库失败,通常是协议错误

为了清楚起见,我在这个集成中使用了普通的 okhttpclient。

如果有人有修复它,请做需要。

【问题讨论】:

  • 您使用的是哪个 okhttp 库版本?
  • 我用的是okhttp:2.4.0
  • 请尝试将其更新到 2.5.0 然后再次检查
  • 有什么具体原因吗?

标签: android google-maps ssl retrofit


【解决方案1】:

看起来服务器正在使用TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 密码。 API 20(L 预览版)才开始支持它。您可以在 SSLSocket docs 上查看 API 级别支持的密码列表。

尝试在 5.0 或更高版本的设备上运行您的测试。例如下面的代码在运行 5.0 的设备上是成功的,但是在 4.4.4 上得到了 SSL 异常 --

OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().get().url("https://cert-test.sandbox.google.com/")
  .build();

response = client.newCall(request).execute();
Log.d(TAG, "code = " + response.code());

但同样的URLConnection代码也是如此——

HttpsURLConnection con = (HttpsURLConnection) new URL("https://cert-test.sandbox.google.com/").openConnection();
con.connect();
Log.d(TAG, "code = " + con.getResponseCode());

问题不在于改造或 okhttp,而是旧手机上提供的默认安全提供程序的限制。

您可以通过安装新的提供程序来解决它。谷歌通过 google play 服务提供了一个,并且易于安装。一行(加上异常处理等)。

try {
    ProviderInstaller.installIfNeeded(this);
} catch (GooglePlayServicesRepairableException e) {
     // Fix it
} catch (GooglePlayServicesNotAvailableException e) {
     // Skip it
}

有关完整示例,请参阅来自 Google 的 "Updating Your Security Provider to Protect Against SSL Exploits"

如果手机安装了 Google Play,这样做将允许上述两个代码块在较低的 API 版本上运行。

【讨论】:

    猜你喜欢
    • 2014-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-09
    • 1970-01-01
    • 2016-03-21
    • 2011-09-04
    相关资源
    最近更新 更多