当前位置:网站首页>解决 『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
边栏推荐
- Mba-day6 logic - hypothetical reasoning exercises
- Excel·VBA数组冒泡排序函数
- Solutions to common problems in visualization (IX) background color
- MBA-day6 逻辑学-假言推理练习题
- Excel · VBA custom function to obtain multiple cell values
- [Niuke challenge 47] C. conditions (BitSet acceleration Floyd)
- Idea - indexing or scanning files to index every time you start
- The songbird document editor will be open source: starting with but not limited to markdown
- SWAT—Samba WEB管理工具介绍
- Difference between pregnancy box and delivery box
猜你喜欢
Cve-2019-0708 vulnerability exploitation of secondary vocational network security 2022 national competition
【leetcode】199. Right view of binary tree
Visual common drawing (IV) histogram
Mysql8. 0 installation guide
Visual Road (XII) detailed explanation of collection class
解决方案架构师的小锦囊 - 架构图的 5 种类型
Learning note 5 - gradient explosion and gradient disappearance (k-fold cross verification)
Manjaro installation and configuration (vscode, wechat, beautification, input method)
ConstraintLayout布局
【leetcode】102. Sequence traversal of binary tree
随机推荐
Constraintlayout layout
Kaggle - real battle of house price prediction
Solutions to common problems in visualization (VIII) solutions to problems in shared drawing area
Database management software sqlpro for SQLite for Mac 2022.30
Excel · VBA custom function to obtain multiple cell values
Software testers, how to mention bugs?
Jupyter lab top ten high productivity plug-ins
Use of SVN:
@valid,@Validated 的学习笔记
ConstraintLayout布局
Analysis on the characteristics of the official game economic model launched by platoffarm
Mba-day5 Mathematics - application problems - engineering problems
Problems of class in C # and database connection
Learning Notes 6 - Summary of several deep learning convolutional neural networks
最强日期正则表达式
比深度学习更值得信赖的模型ART
Cve-2019-0708 vulnerability exploitation of secondary vocational network security 2022 national competition
Derivation and regularization
Pytorch implementation of transformer
MBA-day5數學-應用題-工程問題