当前位置:网站首页>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.
边栏推荐
- DVWA installation tutorial (understand what you don't understand · in detail)
- npm run serve starts error npm ERR Missing script "serve"
- 在线sql编辑查询工具sql-editor
- Briefly describe SSRF
- 第一个WebAssembly程序
- Detailed MySQL-Explain
- 【调优】一个 Spark 任务某天突然变慢怎么解决
- 学生成绩管理系统(C语言版)
- Servlet basic principles and application of common API methods
- 【SQL】first_value 应用场景 - 首单 or 复购
猜你喜欢
![[HCTF 2018]admin](/img/4e/58234ca163c22fc334334eb89a5b00.png)
[HCTF 2018]admin

3 minutes to tell you how to become a hacker | Zero foundation to hacker introductory guide, you only need to master these five skills

oracle row to column, column to row summary
phpok website vulnerability exploitation analysis

Jdbc & Mysql timeout分析

使用PyQt5为YoloV5添加界面(一)

Remember a Mailpress plugin RCE vulnerability recurrence

Mycat2.0 build tutorial

Detailed introduction to the usage of Nacos configuration center

The first WebAssembly program
随机推荐
【Spark】Spark 高频面试题英语版(1)
Jackson serialization failure problem - oracle data return type can't find the corresponding Serializer
MySQL 数据类型及占用空间
Arthas 命令解析(watch/tt/sc)
Reasons and solutions for Invalid bound statement (not found)
sql concat() function
c#下Web3合约空投、转账调用代码
Jdbc & Mysql timeout分析
GraphQL (1) Basic introduction and application examples
[Mozhe Academy] Identity Authentication Failure Vulnerability Actual Combat
misc-log analysis of CTF
GraphQL(一)基础介绍及应用示例
vulnhub-XXE ctf security question
批量自动归集
FastAPI Quick Start
MySQL开窗函数
kali is an essential artifact for information security
Operators and Interaction Basics
Jackson 序列化失败问题-oracle数据返回类型找不到对应的Serializer
MySQL 5.7 安装教程(全步骤、保姆级教程)