问题报错

今天上线了我开发的一个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的更多相关文章

  1. 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 ...

  2. 报错PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target"

    今天在调用第三方HTTPS接口的时候,一直显示这个报错,然后百度很久,有2种解决方法,一个是说自己手动去导入,第二种用代码忽略证书验证.我用二种方式, 复制即用, public void test2( ...

  3. 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 ...

  4. 解决 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 ...

  5. 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 ...

  6. PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilder,阿里MAVEN仓库地址更新为了https问题

    http://maven.aliyun.com/nexus/content/groups/public/,仓库地址更新为了https,所以下载时需要ssl认证,我们可以忽略ssl检查导致的问题,我们可 ...

  7. http 使用curl发起https请求报错的解决办法

    使用curl发起https请求的时候报错:“SSL certificate problem, verify that the CA cert is OK. Details: error:1409008 ...

  8. java 使用https协议,cas认证PKIX path building failed错误解决方法

    如果遇到的是 上图的异常,请继续往下看. linux 下 添加 证书 (1) 获取网站安全证书 xx.cer ( 详情见随笔 获取网站安全证书 ) (2) 将上面导出的证书导入java中的cacert ...

  9. 解决java使用https协议请求出现证书不信任问题(PKIX path building failed)

    解决https请求时出现pkix path building fail错误 方法 将submail.cer 安全证书导入到java中的cacerts证书库 (sumail是我从https://api. ...

随机推荐

  1. prism 中的 自定义region

    参考网址: https://blog.csdn.net/weixin_30872499/article/details/98673059 并不是所有控件都可以被用作Region了吗?我们将Gird块的 ...

  2. 关于int和Integer缓存(二):修改缓存大小

    续上文: java中的基础数据类型长度是否取决于操作系统? 在一些语言中,数据类型的长度是和操作系统有关系的,比如c和c++: 但是在java中,java的基础类型长度都是固定的,都是4个字节.因为j ...

  3. 刷题-力扣-337. 打家劫舍 III

    337. 打家劫舍 III 题目链接 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/house-robber-iii 著作权归领扣网络所有.商 ...

  4. 面试必问题:JS防抖与节流

    摘要:防抖与节流可谓是面试常见,其实很好理解,下面带你分分钟了解防抖与节流的基本思想与写法~ 本文分享自华为云社区<JS防抖与节流快速了解与应用>,作者:北极光之夜. . 一.速识防抖: ...

  5. Linux下修改mysql默认最大连接数

    liunx下修改mysql最大连接数(Centos下测试通过)1.查看当前系统下mysql设置的最大连接数方式一.mysqladmin -uroot -p variables |grep max_co ...

  6. Ubuntu 16.04 Install NVidia Driver (download from nvidia official site)

    sudo apt-get update sudo apt-mark hold libreoffice sudo apt-get update && sudo apt-get upgra ...

  7. k8s笔记0528-基于KUBERNETES构建企业容器云手动部署集群记录-5

    1.为Flannel生成证书 [root@linux-node1 ~]# vim flanneld-csr.json { "CN": "flanneld", & ...

  8. SQL查询语句执行流程

    msyql执行流程 你有个最简单的表,表里只有一个 ID 字段,在执行下面这个查询语句时:: select * from T where ID=10: 我们看到的只是输入一条语句,返回一个结果,却不知 ...

  9. vue ele 日期时间格式限制不能早于当天,时间转换成时间戳 进行比较

    <el-date-picker             value-format="yyyy-MM-dd HH:mm:ss"             v-model=&quo ...

  10. HashSet的存储原理

    HashSet的底层用哈希散列表来存储对象(默认长度为16的数组),假如: Set set=new HashSet(); set.add(obj); 内部存储过程为:定义h=obj.hashCode, ...