android https 证书过期

有的时候 我们android https 证书过期 ,或者使用明文等方式去访问服务器 可能会碰到类似的 问题 :

javax.net.ssl.SSLHandshakeException: Chain validation failed

java.security.cert.CertPathValidatorException: Response is unreliable: its validity interval is out-of-date

java.security.cert.CertPathValidatorException: Could not determine revocation status

所以我们 尝试使用一下方式解决 :

1) 忽略证书验证

TrustManager\[\] trustAllCerts = new TrustManager\[\] {

new X509TrustManager() {

public void checkClientTrusted(X509Certificate\[\] chain, String authType) {}

public void checkServerTrusted(X509Certificate\[\] chain, String authType) {}

public X509Certificate\[\] getAcceptedIssuers() {

return new X509Certificate0;

}

}

};

try {

SSLContext sslContext = SSLContext.getInstance("TLS");

sslContext.init(null, trustAllCerts, new java.security.SecureRandom());

HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());

// 进行网络请求...

} catch (Exception e) {

e.printStackTrace();

}

如果您希望允许整个应用程序使用不安全的 HTTP 连接,可以在应用程序的清单文件(AndroidManifest.xml)中添加以下标记:

复制代码

<application

android:usesCleartextTraffic="true" ...>

...

</application>

更详细的可以去问 gpt

相关推荐
福大大架构师每日一题1 小时前
mediamtx v1.21.2发布:UDP、JWT、RTSP、RTMP、HLS、WebRTC全面修复,稳定性与安全性再提升
网络协议·udp·webrtc
曹小强wxx2 小时前
Flutter 局域网设备发现:UDP 广播 + mDNS 双路合并,以及靠谱的在线判定与断线重连
物联网·网络协议·flutter
花间相见2 小时前
【计算基础|网络09】TCP(上):三次握手与四次挥手
网络·网络协议·tcp/ip
wdfk_prog2 小时前
LWIP教程 08:从 `tcp_write()` 到 ACK 清队列——TCP 数据发送、窗口与回调
网络·网络协议·tcp/ip
anew___2 小时前
《从零手写操作系统 (37):网络协议栈基础——Socket接口与TCP状态机》
网络·网络协议·tcp/ip
Lsetea3 小时前
OpenSSL读取加密私钥报bad decrypt:passin与口令来源排查
linux·https·ssl证书·openssl·私钥
花间相见4 小时前
【计算基础|网络10】TCP(中):可靠传输
网络·网络协议·tcp/ip
Lsetea5 小时前
OpenSSL报CA signature digest algorithm too weak:error 68与签名摘要排查
https·ssl证书·openssl·签名算法·证书链
wdfk_prog14 小时前
LWIP教程 09:从 `tcp_slowtmr()` 到 Fast Retransmit——TCP 超时重传与重复 ACK
服务器·网络·数据库·网络协议·tcp/ip