Android 4.4 及更低版本上的 SSLHandshakeException [英] SSLHandshakeException on Android 4.4 and lower

查看:26
本文介绍了Android 4.4 及更低版本上的 SSLHandshakeException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我想使用 POST 方法连接 Paypal Rest API 时遇到问题.当我不使用现代httpclient时,我收到错误

I have a problem when I want to connect with Paypal Rest API with POST method. When I am not using modernhttpclient I got error

The authentication or decryption has failed. 

但是当我使用 modernhttpclient 时,它可以在 Android API 23 (Marshmallow) 中运行,当我在 Android API 19(设备)和 Android API 16(模拟器)中测试时,我遇到了错误

But when I am using modernhttpclient it work in Android API 23 (Marshmallow) and when I test in Android API 19 (device) and Android API 16 (emulator) I got error

ex {Javax.Net.Ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=…} Javax.Net.Ssl.SSLHandshakeException

根据ssl握手异常android 我需要使用自定义套接字工厂.但是如何在 HttpClient 或 modernHttpClient 中实现呢?

According to ssl handshake exception android I need to use custom socket factory. But how can I implement it in HttpClient or modernHttpClient?

推荐答案

不确定我是否能完全回答你的问题,但我会试一试:

Not sure if I can fully answer your question, but I'll give it a try:

如果您分析 Paypal REST API 端点,例如使用像这样的 SSL 实验室 https://www.ssllabs.com/ssltest/analyze.html?d=api.sandbox.paypal.com&hideResults=on,你看他们只支持TLS 1.2 协议.

If you analyze the Paypal REST API endpoint, for example with SSL Labs like so https://www.ssllabs.com/ssltest/analyze.html?d=api.sandbox.paypal.com&hideResults=on, you see they only support the TLS 1.2 protocol.

现在 Android 从 API Level 16 开始支持这个,你可以在这里看到 https://developer.android.com/reference/javax/net/ssl/SSLSocket.html,但默认情况下它是禁用的,并且仅在 API 级别 20+ 中才启用.

Now Android does support this since API Level 16, as you can see here https://developer.android.com/reference/javax/net/ssl/SSLSocket.html, but it is disabled by default and only in API Levels 20+ they enabled it.

在 Xamarin 论坛中,有人发布了一个解决方案,通过派生 ModernHttpClient 并添加改进的 SSL 套接字工厂,为 API 级别为 16 到 19 的 Android 启用 TLS 1.2:https://forums.xamarin.com/discussion/63005/modernhttpclient-tls-1-2-android-api-19

In the Xamarin forums someone posted a solution for enabling TLS 1.2 for Android with API Levels 16 to 19 by forking ModernHttpClient and adding an improved SSL socket factory: https://forums.xamarin.com/discussion/63005/modernhttpclient-tls-1-2-android-api-19

这应该可以解决您在这些 Android 版本上的问题,但对 Android 4.1 之前的版本没有帮助.

This should fix your issue with those Android versions, but it will not help you with versions before Android 4.1.

这篇关于Android 4.4 及更低版本上的 SSLHandshakeException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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