Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provid
1,导出浏览器的证书(以百度为例)
保存在本地,然后上传到服务器
2,查看服务器安装的证书
# 查看服务器安装的证书
keytool -list -keystore /usr/local/jdk1.8.0_201/jre/lib/security/cacerts
# 密码:
changeit
# 安装证书 LL2刚刚客户端上传的证书
keytool -import -alias LL2 -keystore /usr/local/jdk1.8.0_201/jre/lib/security/cacerts -file /usr/local/jar**/**/LL2.cer
# 输入 y
# 安装完成之后执行第一步,看看数量是否增加
3,生成证书
新建InstallCert.java文件
/* * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * - Neither the name of Sun Microsystems nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.security.KeyStore;
import java.security.MessageDigest;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate; import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager; public class InstallCert { public static void main(String[] args) throws Exception { String host; int port; char[] passphrase; if ((args.length == 1) || (args.length == 2)) { String[] c = args[0].split(":"); host = c[0]; port = (c.length == 1) ? 443 : Integer.parseInt(c[1]); String p = (args.length == 1) ? "changeit" : args[1]; passphrase = p.toCharArray(); } else { System.out .println("Usage: java InstallCert <host>[:port] [passphrase]"); return; } File file = new File("jssecacerts"); if (file.isFile() == false) { char SEP = File.separatorChar; File dir = new File(System.getProperty("java.home") + SEP + "lib" + SEP + "security"); file = new File(dir, "jssecacerts"); if (file.isFile() == false) { file = new File(dir, "cacerts"); } } System.out.println("Loading KeyStore " + file + "..."); InputStream in = new FileInputStream(file); KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); ks.load(in, passphrase); in.close(); SSLContext context = SSLContext.getInstance("TLS"); TrustManagerFactory tmf = TrustManagerFactory .getInstance(TrustManagerFactory.getDefaultAlgorithm()); tmf.init(ks); X509TrustManager defaultTrustManager = (X509TrustManager) tmf .getTrustManagers()[0]; SavingTrustManager tm = new SavingTrustManager(defaultTrustManager); context.init(null, new TrustManager[] { tm }, null); SSLSocketFactory factory = context.getSocketFactory(); System.out .println("Opening connection to " + host + ":" + port + "..."); SSLSocket socket = (SSLSocket) factory.createSocket(host, port); socket.setSoTimeout(10000); try { System.out.println("Starting SSL handshake..."); socket.startHandshake(); socket.close(); System.out.println(); System.out.println("No errors, certificate is already trusted"); } catch (SSLException e) { System.out.println(); e.printStackTrace(System.out); } X509Certificate[] chain = tm.chain; if (chain == null) { System.out.println("Could not obtain server certificate chain"); return; } BufferedReader reader = new BufferedReader(new InputStreamReader( System.in)); System.out.println(); System.out.println("Server sent " + chain.length + " certificate(s):"); System.out.println(); MessageDigest sha1 = MessageDigest.getInstance("SHA1"); MessageDigest md5 = MessageDigest.getInstance("MD5"); for (int i = 0; i < chain.length; i++) { X509Certificate cert = chain[i]; System.out.println(" " + (i + 1) + " Subject " + cert.getSubjectDN()); System.out.println(" Issuer " + cert.getIssuerDN()); sha1.update(cert.getEncoded()); System.out.println(" sha1 " + toHexString(sha1.digest())); md5.update(cert.getEncoded()); System.out.println(" md5 " + toHexString(md5.digest())); System.out.println(); } System.out .println("Enter certificate to add to trusted keystore or 'q' to quit: [1]"); String line = reader.readLine().trim(); int k; try { k = (line.length() == 0) ? 0 : Integer.parseInt(line) - 1; } catch (NumberFormatException e) { System.out.println("KeyStore not changed"); return; } X509Certificate cert = chain[k]; String alias = host + "-" + (k + 1); ks.setCertificateEntry(alias, cert); OutputStream out = new FileOutputStream("jssecacerts"); ks.store(out, passphrase); out.close(); System.out.println(); System.out.println(cert); System.out.println(); System.out .println("Added certificate to keystore 'jssecacerts' using alias '" + alias + "'"); } private static final char[] HEXDIGITS = "0123456789abcdef".toCharArray(); private static String toHexString(byte[] bytes) { StringBuilder sb = new StringBuilder(bytes.length * 3); for (int b : bytes) { b &= 0xff; sb.append(HEXDIGITS[b >> 4]); sb.append(HEXDIGITS[b & 15]); sb.append(' '); } return sb.toString(); } private static class SavingTrustManager implements X509TrustManager { private final X509TrustManager tm; private X509Certificate[] chain; SavingTrustManager(X509TrustManager tm) { this.tm = tm; } public X509Certificate[] getAcceptedIssuers() { throw new UnsupportedOperationException(); } public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { throw new UnsupportedOperationException(); } public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { this.chain = chain; tm.checkServerTrusted(chain, authType); } } }
编译运行
javac InstallCert.java
java InstallCert www.baidu.com
输入1,回车
在当前的目下生成 jssecacerts 文件
导入证书
复制证书文件jssecacerts到Java安装路径\jre\lib\security下,我的路径是/usr/java/jdk1.8.0_31/jre/lib/security/
3,重启项目
最后重启项目。
参考链接:https://www.cnblogs.com/dreasky/p/13497161.html
https://blog.csdn.net/yshxjoy/article/details/78893101
https://blog.csdn.net/chaishen10000/article/details/82992291
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provid相关推荐
- 解决调用第三方API报sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provid
1.最近在调用第三方API遇到证书验证问题 postman调用和用RestTemplate分别报错如下: 2.经过查询资料 是https,需要安装证书,但是自定义的证书貌似得不到信任,所以报PK ...
- PKIX问题:sun.security.validator.ValidatorException: PKIX path building failed
对新项目clean install 的时候,报错了,提示没有合法的证书,报错信息如下 [ERROR] Failed to execute goal on project springbootactiv ...
- 报错:sun.security.validator.ValidatorException: PKIX path building failed
背景 本人使用itext导出pdf时,会报这个错误:sun.security.validator.ValidatorException: PKIX path building failed. 报错代码 ...
- 最全解决 PKIX问题方案:sun.security.validator.ValidatorException: PKIX path building failed:
这个问题的根本原因是你安装JDK时,Java\jar 1.8.0_141\lib\ext\里面缺少了一个安全凭证jssecacerts证书文件,通过运行下面类可以生成证书,将生成的证书放在Java\j ...
- 对接服务,对方服务器更新SSL证书,服务https的get和post报错。 sun.security.validator.ValidatorException: PKIX path building
错误信息 javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path build ...
- BUG处理:javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path buil
分享目的: 如果别人已经讲述了,这里只会给出相关链接 只补充解决思路. 每个人在寻找解决答案过程中,遇到的痛点难点都是不同的. 这里仅阐述我实际项目遇到问题的解决方案. BUG描述: tomcat配置 ...
- maven PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable
本例使用maven进行sonar代码扫描的时候,url 指定的是 https 地址,出现了异常: Unable to execute SonarScanner analysis: Fail to ge ...
- PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilder
一.问题描述:pom.xml导入依赖时报错 PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilder 二 ...
- PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilder...
Elasticsearch 8.4.3 spring-boot-starter-data-elasticsearch https连接es [PKIX path building failed, una ...
最新文章
- mysql 启动安全模式_“ Word上次启动时失败,以安全模式启动Word ....”解决办法...
- malloc原理和内存碎片
- java递归分苹果_递归较难题——分苹果问题
- Eclipse 的常见报错、警告和原因分析、解决方式以及相关操作快捷键小结(持续更新)
- Kafka万亿级消息实战干货~持续更新中
- 利用微信实现自动发送监控告警
- CVE-2017-8046(Spring Data Rest RCE)
- 软件测试面试-在工作中功能,接口,性能,自动化的占比是多少?
- 共226款Html5小游戏源码分享
- 用计算机录制声音让音质更好,电脑有什么好用的录音软件吗
- 使用函数式编程优化代码
- 用php编写室友通讯录_使用 XML 和 PHP 创建一个更具适应性的电话簿和通讯录
- 【dubbo异常处理】Fail to decode request due to: RpcInvocation
- 依存分析:中文依存句法分析简介
- MFC快速创建bmp图片
- Value ‘0000-00-00 00:00:00‘ can not be represented as java.sql.Timestamp
- 机械之美——机械时期的计算设备
- 使用Python进行自动化测试
- 九万字图文讲透彻 Linux 电源管理及实例分析
- 零、一些常用的英文名称