当前位置:网站首页>Trust anchor for certification path not found. Exception solution.
Trust anchor for certification path not found. Exception solution.
2022-07-30 06:55:00 【¥Yiren alone drunk】
1. Exception details:
When doing OkHttp to access the network, the following error always occurs.
java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
Second, the cause of the problem:
Because the https.bks certificate of the project is not a certificate issued by a formal CA, but a certificate issued by a secondary agent, etc., the verification fails!!!
Third, the solution:
Ignore https certificate verification
Specific method: When obtaining sslParams, modify and customize TrustManager to trustAllCerts
Then add this method to the main class
1, JAVA version:
public static void handleSSLHandshake() {try {TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {public X509Certificate[] getAcceptedIssuers() {return new X509Certificate[0];}@Overridepublic void checkClientTrusted(X509Certificate[] certs, String authType) {}@Overridepublic void checkServerTrusted(X509Certificate[] certs, String authType) {}}};SSLContext sc = SSLContext.getInstance("TLS");// trustAllCerts trust all certificatessc.init(null, trustAllCerts, new SecureRandom());HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {@Overridepublic boolean verify(String hostname, SSLSession session) {return true;}});} catch (Exception ignored) {}}2, Kotlin version:
fun handleSSLHandshake() {try {var trustAllCerts:Array = arrayOf(object: X509TrustManager{override fun checkClientTrusted(p0: Array?, p1: String?) {}override fun checkServerTrusted(p0: Array?, p1: String?) {}override fun getAcceptedIssuers(): Array {val arrayOfNulls = arrayOfNulls(0)return arrayOfNulls}})val sc: SSLContext = SSLContext.getInstance("TLS")// trustAllCerts trust all certificatessc.init(null, trustAllCerts, SecureRandom())HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory())HttpsURLConnection.setDefaultHostnameVerifier(object : HostnameVerifier{override fun verify(p0: String?, p1: SSLSession?): Boolean {return true}})}catch(e:Exception){}} 3, and then call it in the oncreate() method
handleSSLHandshake()
This pit has been encountered a lot of times. After checking a lot of blogs, I found a good solution. I reprinted it and shared it with everyone, hoping to help everyone.
边栏推荐
- [Mozhe Academy] Identity Authentication Failure Vulnerability Actual Combat
- Servlet basic principles and application of common API methods
- The most powerful and most commonly used SQL statements in history
- DVWA installation tutorial (understand what you don't understand · in detail)
- 根据ip地址获取地理位置及坐标(离线方式)
- 第一个WebAssembly程序
- Using PyQt5 to add an interface to YoloV5 (1)
- 【Spark】Spark 高频面试题英语版(1)
- Request请求体重新封装,解决请求体只能获取一次的问题
- Oracle数据库SQL优化详解
猜你喜欢

【数仓】数据仓库高频面试题题英文版(1)

mysql不是内部或外部命令,也不是可运行的程序或批处理文件解决

TDengine集群搭建
![[MATLAB] Image Processing - Recognition of Traffic Signs](/img/45/1a5797a17ebf6db965a64c85e0f037.png)
[MATLAB] Image Processing - Recognition of Traffic Signs

FastAPI 快速入门

"MySQL Advanced Chapter" four, the storage structure of the index

Jackson 序列化失败问题-oracle数据返回类型找不到对应的Serializer

互联网商城盲盒app为何如此火爆

MySQL开窗函数

Reasons and solutions for Invalid bound statement (not found)
随机推荐
mysql is not an internal or external command, nor is it a runnable program or batch file to resolve
Obtain geographic location and coordinates according to ip address (offline method)
Go简单实现协程池
DVWA installation tutorial (understand what you don't understand · in detail)
SQL Server Installation Tutorial
在线sql编辑查询工具sql-editor
[MATLAB]图像处理——交通标志的识别
JVM Learning (2) Garbage Collector
Mysql client common exception analysis
C#下大批量一键空投实现
Awd summary
Servlet basic principles and application of common API methods
MySQL 5.7 安装教程(全步骤、保姆级教程)
【OS】操作系统高频面试题英文版(1)
学生成绩管理系统(C语言版)
Operators and Interaction Basics
国内数字藏品交易平台开发市场会开放二级市场吗
2022CISCNmisc
Usage of exists in sql
Detailed explanation of ClickHouse query statement