Android问题记录03_javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handsh...

  • 问题记录

在Android 4.4的机器上https网络请求失败,但是测试时用Android4.4以上的手机一直没有发现这个问题,特此记录下这个问题

  • 现象

网络请求失败报错:
javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x78317148: Failure in SSL library, usually a protocol error error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure (external/openssl/ssl/s23_clnt.c:744 0x74017f64:0x00000000)

Glide加载图片也出错:


image.png
  • 问题原因
    https单向认证问题
    android 4.4没有启用TLSv1.1 和 TLSv1.2 传输层安全协议
    https://developer.android.com/reference/javax/net/ssl/SSLSocket
Protocol Supported (API Levels) Enabled by default (API Levels)
SSLv3 1–25 1–22
TLSv1 1+ 1+
TLSv1.1 16+ 20+
TLSv1.2 16+ 20+

可以看出虽然Android 16就虽然已经支持了TLS1.1和TLS1.,但是默认并没有开启,API 20才默认开启

  • 解决方案
    https://stackoverflow.com/questions/29916962/javax-net-ssl-sslhandshakeexception-javax-net-ssl-sslprotocolexception-ssl-han
    https://stackoverflow.com/questions/24357863/making-sslengine-use-tlsv1-2-on-android-4-4-2/26586324#26586324

因为项目是放谷歌playStore的 所以采取的解决办法是:
项目build.gradle文件中添加
dependencies {
....
implementation 'com.google.android.gms:play-services-auth:16.0.1'
}

Application中添加
try{
ProviderInstaller.installIfNeeded(this);
} catch (GooglePlayServicesRepairableException e) {

} catch (GooglePlayServicesNotAvailableException e) {
}

一定要try catch

你可能感兴趣的:(Android问题记录03_javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handsh...)