Android 4.4及更低版本上的SSLHandshakeException [英] SSLHandshakeException on Android 4.4 and lower
问题描述
我想通过POST方法连接Paypal Rest API时遇到问题。当我不使用modernhttpclient时,出现错误
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(棉花糖)中使用,而当我在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 Labs这样的 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级别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论坛中有人发布了解决方案通过分叉Mo为API级别16至19启用Android的TLS 1.2 dernHttpClient并添加改进的SSL套接字工厂: 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屋!