当前位置:网站首页>解决 『SunCertPathBuilderException:unable to find valid certification path to requested target』 问题
解决 『SunCertPathBuilderException:unable to find valid certification path to requested target』 问题
2022-04-23 11:02:00 【爱博客大伯】
解决 『SunCertPathBuilderException:unable to find valid certification path to requested target』 问题
* 问题
在 maven 编译的时候,出现证书校验错误,部分log如下:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
此问题通常是在访问maven依赖库的网站(https的)时,证书被替换了,然后导致的。
为什么证书会被替换?可能的原因是,代理服务器作为中间人,在https传输过程中,将服务器的证书替换了,然后就可以监听https的流量了。通常,公司里会这么干。这里代理服务器利用了https协议的密钥交换过程,可以参考这篇文章:扫盲 HTTPS 和 SSL/TLS 协议
解决此问题,有两种方法。
* 方法1:为maven添加属性maven.wagon.http.ssl.insecure=true
在mvn命令后面加上-Dmaven.wagon.http.ssl.insecure=true
。此属性是让maven忽略安全性,不再校验服务器的证书(此时服务器的证书可能是被替换的)。
mvn -Dmaven.wagon.http.ssl.insecure=true package
* 方法2:将证书添加到 cacerts 中
环境:Windows。
cacerts包含了很多CA证书,位置在Java的安装目录: 『Java\jdk1.8.0_65\jre\lib\security\cacerts』。
执行如下命令,将证书加到cacerts中:
keytool.exe -importcert -file <新证书> -keystore Java\jdk1.8.0_65\jre\lib\security\cacerts -storepass changeit
<新证书>
可以是cer格式的,例如,xxx.cer。
执行此命令会提示你是否信任此证书,输入yes,回车。然后证书就加入cacerts中了。部分log如下:
Trust this certificate? [no]: yes
Certificate was added to keystore
◇ 关于cacerts的说明
A certificates file named “cacerts” resides in the security properties directory, java.home\lib\security, where java.home is the runtime environment directory (the jre directory in the SDK or the top-level directory of the Java 2 Runtime Environment).
The “cacerts” file represents a system-wide keystore with CA certificates. System administrators can configure and manage that file using keytool, specifying “jks” as the keystore type. The “cacerts” keystore file ships with several root CA certificates. The initial password of the “cacerts” keystore file is “changeit”. System administrators should change that password and the default access permission of that file when installing the SDK.
* 参考
版权声明
本文为[爱博客大伯]所创,转载请带上原文链接,感谢
https://blog.csdn.net/u013553529/article/details/82895226
边栏推荐
- Precautions for latex formula
- Detailed explanation of typora Grammar (I)
- The courses bought at a high price are open! PHPer data sharing
- 高价买来的课程,公开了!phper资料分享
- JVM - common parameters
- Ueditor -- limitation of 4m size of image upload component
- Alarm scene recognition
- Resolution and size of mainstream mobile phones
- Special members and magic methods
- 26. 删除有序数组中的重复项
猜你喜欢
Excel·VBA数组冒泡排序函数
【leetcode】102. Sequence traversal of binary tree
Google Earth Engine(GEE)——将原始影像进行升尺度计算(以海南市为例)
About the three commonly used auxiliary classes of JUC
vm设置静态虚拟机
Diary of dishes | Blue Bridge Cup - hexadecimal to octal (hand torn version) with hexadecimal conversion notes
Visualized common drawing (II) line chart
CUMCM 2021-B:乙醇偶合制備C4烯烴(2)
Mysql8.0安装指南
Solution architect's small bag - 5 types of architecture diagrams
随机推荐
The difference between restful and soap
Visualization Road (11) detailed explanation of Matplotlib color
HuggingFace
Problems of class in C # and database connection
我的创作纪念日
MBA-day5数学-应用题-工程问题
After the MySQL router is reinstalled, it reconnects to the cluster for boot - a problem that has been configured in this host before
Mysql8.0安装指南
学习 Go 语言 0x01:从官网开始
《Neo4j权威指南》简介,求伯君、周鸿袆、胡晓峰、周涛等大咖隆重推荐
Full stack cross compilation x86 completion process experience sharing
学习 Go 语言 0x08:《Go 语言之旅》中 练习使用 error
Solution architect's small bag - 5 types of architecture diagrams
第六站神京门户-------手机号码的转换
Database management software sqlpro for SQLite for Mac 2022.30
remote: Support for password authentication was removed on August 13, 2021.
最强日期正则表达式
Data analysis learning (I) data analysis and numpy Foundation
Software testers, how to mention bugs?
Excel·VBA自定义函数获取单元格多数值