【问题记录】Java服务发起HTTPS请求报错:PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException
问题报错
今天上线了我开发的一个OAuth2单点登录客户端的实现,在测试系统验证没问题,到生产环境由于单点登录服务端HTTPS协议,报错如下:
I/O error on POST request for "xxx.xxx.xxx.xxx:8080": sun.security.validator.ValidatorException:
PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is 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
导致报错的原因是 HTTPS 域名的公钥证书不在 JDK/JRE 的证书库中,被Java认为是不可信的。
解决方案
1、导出证书
首先需要获取 HTTPS 域名的公钥证书,可以通过浏览器导出,如下是 Chrome 浏览器导出百度的公钥证书。

2、上传证书到服务器
如果是本地 JDK 则不需要此步骤。我把CA.cer上传到了 Linux 服务器的 /root 下
3、为 keytool 授予执行权限
防止 keytool 没有操作权限。
sudo chmod +x ${JDK目录}/bin/keytool
4、导入证书
Java 证书库文件的路径为 ${JDK目录}/jre/lib/security/cacerts,以下命令公钥证书放在 /root/CA.cer
${JDK目录}/bin/keytool -import \
-alias cacerts -keystore ${JDK目录}/jre/lib/security/cacerts \
-file /root/CA.cer
顺序输入 yes + 回车 与 changeit +回车,完成证书导入。
yes表示允许信任此证书,changeit是 Java 证书库默认的密码。
5、重启 Java 服务
这我就不多说了,懂得都懂 :happy:
最后
希望对您能有所启发,如果您有更优雅的实现方式 或者 文中有错误,希望您能不吝赐教评论指出,感谢。
本文同步发布于博客园(东北小狐狸 https://www.cnblogs.com/hellxz/)与CSDN(东北小狐狸-Hellxz https://blog.csdn.net/u012586326)禁止转载。
【问题记录】Java服务发起HTTPS请求报错:PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException的更多相关文章
- Flutter配置环境报错“PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target”
背景:最近看了很多Flutter漂亮的项目,想要尝试一下.所有环境都搭建好之后,按照文档一步一步配置(抄袭),但始终报如下图错误. PKIX path building failed: sun.sec ...
- 报错PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target"
今天在调用第三方HTTPS接口的时候,一直显示这个报错,然后百度很久,有2种解决方法,一个是说自己手动去导入,第二种用代码忽略证书验证.我用二种方式, 复制即用, public void test2( ...
- java程序中访问https时,报 PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
在java中使用https访问数据时报异常: Caused by: sun.security.validator.ValidatorException: PKIX path building fail ...
- 解决 java 使用ssl过程中出现"PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target"
今天,封装HttpClient使用ssl时报一下错误: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorExc ...
- mvn 编译报错mavn sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested targ
mavn 编译报错: mavn sun.security.validator.ValidatorException: PKIX path building failed: sun.security.p ...
- PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilder,阿里MAVEN仓库地址更新为了https问题
http://maven.aliyun.com/nexus/content/groups/public/,仓库地址更新为了https,所以下载时需要ssl认证,我们可以忽略ssl检查导致的问题,我们可 ...
- http 使用curl发起https请求报错的解决办法
使用curl发起https请求的时候报错:“SSL certificate problem, verify that the CA cert is OK. Details: error:1409008 ...
- java 使用https协议,cas认证PKIX path building failed错误解决方法
如果遇到的是 上图的异常,请继续往下看. linux 下 添加 证书 (1) 获取网站安全证书 xx.cer ( 详情见随笔 获取网站安全证书 ) (2) 将上面导出的证书导入java中的cacert ...
- 解决java使用https协议请求出现证书不信任问题(PKIX path building failed)
解决https请求时出现pkix path building fail错误 方法 将submail.cer 安全证书导入到java中的cacerts证书库 (sumail是我从https://api. ...
随机推荐
- C++ CLI简介(什么是C++ CLI)
要知道C++/CLI是什么,首先知道什么是CLI. 一.CLI简介 CLI:(Common Language Infrastructure,通用语言框架)提供了一套可执行代码和它所运行需要的虚拟执行环 ...
- 【权限管理】Apache Shiro和Spring Security的对比
一.Shiro简介 Apache Shiro是Java的一个安全框架.目前,使用Apache Shiro的人越来越多,因为它相当简单,对比Spring Security,可能没有Spring Secu ...
- C语言定义常量
/* #define 标识符 #define day main中day=10;仅一次赋值*/ 错误 #define 标识符 常量值 #define day 10;
- PE文件结构(32/64差异)
1 基本概念 下表描述了贯穿于本文中的一些概念: 名称 描述 地址 是"虚拟地址"而不是"物理地址".为什么不是"物理地址"呢?因为数据在内 ...
- TiDB基本简介
一.TiDB整体架构 与传统的单机数据库相比,TiDB具有以下优势: 纯分布式架构,拥有良好的扩展性,支持弹性的扩缩容 支持SQL,对外暴露MySQL的网络协议,并兼容大多数MySQL的语法,在大多数 ...
- Gradient checking
所需文件:本地下载 Gradient Checking Welcome to the final assignment for this week! In this assignment you wi ...
- 三大操作系统对比使用之·Windows10
时间:2018-10-29 记录:byzqy 本篇是一篇个人对Windows系统使用习惯.技巧和应用推荐的文档,在此记录.分享和后续查询备忘. 打开终端: Win+R,调出"运行" ...
- Pytest系列(19)- 我们需要掌握的allure特性
如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 前面我们介绍了allure的 ...
- Sentry Web 性能监控 - Metrics
系列 1 分钟快速使用 Docker 上手最新版 Sentry-CLI - 创建版本 快速使用 Docker 上手 Sentry-CLI - 30 秒上手 Source Maps Sentry For ...
- 作业帮-PHP技术一面整理
项目经验介绍 RPC 调用的协议 用amf 和 base64编码 我想问的是通信协议:调用rpc接口时的过程是什么样?比如业务调用PHP接口的时候,用的是什么协议? (没理解)(https://www ...