1. 说明:

以下:例子的域名因为工作环境的问题,被我拿自己的博客域名替代了,所以无法进行模拟测试,请珍重,哈哈!

2. 环境:

centos:7.5

java jdk:1.8.0_74

3. curl 请求报错

[root@test01 tmp]# curl "https://www.zhaouncle.com/api/v2/app/getBopomofo?source=%e8%b5%b5%e8%b6%99"
curl: (60) Peer's Certificate issuer is not recognized.
More details here: http://curl.haxx.se/docs/sslcerts.html curl performs SSL certificate verification by default, using a "bundle"
of Certificate Authority (CA) public keys (CA certs). If the default
bundle file isn't adequate, you can specify an alternate file
using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
the bundle, the certificate verification probably failed due to a
problem with the certificate (it might be expired, or the name might
not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
the -k (or --insecure) option.

3.1 解决办法一,治本之法

3.1.1 Firefox 火狐浏览器

打开 https://www.zhaouncle.com,然后依次点击以下操作

“安全锁图标”——》“向右箭头”——》“更多信息”——》“查看证书”——》“中间那个证书”,下载为 pem 文件




3.1.2 进入 centos 系统

将下载的 pem 文件放入/etc/pki/ca-trust/source/anchors 目录,然后执行 update-ca-trust extract 命令

3.2 解决办法二,治标

curl -k 或者 curl --insecure,在命令行上直接避免证书校验

curl -k "https://www.zhaouncle.com/api/v2/app/getBopomofo?source=%e8%b5%b5%e8%b6%99"
curl --insecure "https://www.zhaouncle.com/api/v2/app/getBopomofo?source=%e8%b5%b5%e8%b6%99"

3.3 解决办法三,治标

3.3.1 wget 解决方法:

echo "check_certificate = off" >> ~/.wgetrc

3.3.2 curl 解决方法:

echo "insecure" >> ~/.curlrc

4. Java 和 curl 都请求证书错误

4.1 以下是 curl 报错:

[centos@test01 ~]$ curl "https://www.zhaouncle.com/api/v2/app/getBopomofo?source=%e8%b5%b5%e8%b6%99"
curl: (60) Peer's Certificate issuer is not recognized.
More details here: http://curl.haxx.se/docs/sslcerts.html curl performs SSL certificate verification by default, using a "bundle"
of Certificate Authority (CA) public keys (CA certs). If the default
bundle file isn't adequate, you can specify an alternate file
using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
the bundle, the certificate verification probably failed due to a
problem with the certificate (it might be expired, or the name might
not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
the -k (or --insecure) option.
[centos@test01 ~]$ ping www.zhaouncle.com
PING www.zhaouncle.com (10.0.0.100) 56(84) bytes of data.
64 bytes from test01 (10.0.0.100): icmp_seq=1 ttl=64 time=262 ms
64 bytes from test01 (10.0.0.100): icmp_seq=2 ttl=64 time=262 ms
64 bytes from test01 (10.0.0.100): icmp_seq=3 ttl=64 time=262 ms
^C
--- www.zhaouncle.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 262.636/262.636/262.637/0.418 ms

4.2 以下是 java 请求 www 证书报错

org.springframework.web.client.ResourceAccessException: I/O error on GET request for "https://www.mitrade.com/api/v2/app/getBopomofo": 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

4.3 说明

4.3.1 疑问:大家肯定很好奇我为啥会 ping 域名,然后还是内网 ip?

解答:因为绑定了 hosts,然后请求的是内网 ip,于是走的是本地的 nginx,nginx 配置了证书,而不是外部的 cdn,如果是走外部请求走 cdn,curl 和 java 都不会报错,因为 cdn 已经绑定了证书,这个证书上传了证书链。哎,没错了,证书链。

4.3.2 何谓证书链

加速 https 需要上传 SSL 证书,打开公钥 domain.com.crt ,发现里面有 3 个证书:

证书链。一般是一个用户证书,一个中间证书,和一个根证书。

一般只需要 用户证书+中间证书 就可以了, 根证书不用传, 除非你这个证书链不是三级,而是有两个中间证书.

一般来讲,只有传 用户证书 才能正常工作,可以同时传 用户证书和中间证书 或者 用户证书和中间证书和根证书

注意这些证书必须在同一个文件里面

格式如下:

-----BEGIN CERTIFICATE-----
MIIFSzCCBDOgAwIBAgIQHV3ex3xRLXOHkz2GjVAKrjANBgkqhkiG9w0BAQsFADCB
......后面省略,第一个是用户证书
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
MIIGCDCCA/CgAwIBAgIQKy5u6tl1NmwUim7bo3yMBzANBgkqhkiG9w0BAQwFADCB
......后面省略,第二个是中间证书
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
MIIFdDCCBFygAwIBAgIQJ2buVutJ846r13Ci/ITeIjANBgkqhkiG9w0BAQwFADBv
......后面省略,第三个是根证书
-----END CERTIFICATE-----

4.3.3 解决:

解决方法:在哪 nginx 那里把 www 的 crt 证书添加进中间证书,ok,就解决了所以问题,而且还不需要 步骤 3 但对对系统和命令行进行从处理,就可以解决问题。

参考:https://ep.gnt.md/index.php/curl-60-peers-certificate-issuer-is-not-recognized/

【证书】curl 和 java 请求报证书错误的更多相关文章

  1. SpringMVC的AJAX请求报406错误

    SpringMVC的AJAX请求报406错误原因有两种:1.jackson包没有引入 2.如果已经引入jackson包了还报406的错误,那么就有可能是请求的url路径是.html结尾,但是返回的数据 ...

  2. TP5 ajax请求报500错误

    场景:几个站点从阿里云迁移到腾讯云,然后 TP5项目 ajax请求报500错误 数据返回成功,但是http状态码是500,不走success,一直走error 如下图: 原因分析: 服务器centos ...

  3. springMVC配置时,静态资源和jsp文件路径没错但是访问时controller的请求报404错误。

    springMVC配置时,静态资源和jsp文件路径没错但是访问时controller的请求报404错误. 1.场景 如果在web.xml中servlet-mapping的url-pattern设置的是 ...

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

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

  5. 用curl获取https请求时出现错误的处理

    今天一个同事反映,使用curl发起https请求的时候报错:“SSL certificate problem, verify that the CA cert is OK. Details: erro ...

  6. Yii 1.1 请求报400错误

    Yii的action可以带参数,比如: class PostController extends CController { public function actionCreate($categor ...

  7. ajax请求报语法错误

    今天改代码修正完一个ajax请求后,调试发现出错进error方法,查看错误信息报语法错误,具体是调用parseJSON方法时出错,因为我是用json方式传递的参数,所以第一时间查看data参数是否正确 ...

  8. 解决微信小程序用 SpringMVC 处理http post时请求报415错误

    解决微信小程序用 SpringMVC 处理http post时请求返回415错误 写微信小程序时遇到的问题,这个坑硬是让我整了半天 wx.request请求跟ajax类似处理方法一致 小程序端请求代码 ...

  9. http请求报400错误的原因分析

     在ajax请求后台数据时有时会报 HTTP 400 错误 - 请求无效 (Bad request);出现这个请求无效报错说明请求没有进入到后台服务里: 原因:1)前端提交数据的字段名称或者是字段类型 ...

随机推荐

  1. Learn day9 粘包\struct用法\hashlib校验\socketserver并发\模块引入\进程\join\守护进程

    1.粘包现象 总结 : 导致黏包现象的两种情况 hello,worl d (1) 在发送端,发送数据太快,频繁发送 (2) 在接收端,接收数据太慢,延迟截取 # ### 服务端 import sock ...

  2. 洛谷 P2391 白雪皑皑 线段树+优化

    题目描述: 现在有 \(N\) 片雪花排成一列. Pty 要对雪花进行$ M $次染色操作,第 \(i\)次染色操作中,把\((i*p+q)%N+1\) 片雪花和第\((i*q+p)%N+1\)片雪花 ...

  3. java 动态增加应用服务器,出现的消息队列的消费者提报错问题

    java 动态增加应用服务器,出现的消息队列的消费者提报错问题 在项目中,有这样的业务场景,在某一个时间段,客户流量瞬间增大,服务器瞬间很大,出现高并发问题.有一种解决方案就是脚本动态增加业务服务器, ...

  4. mysql 两主一从环境搭建(5.7.24)

    搭建说明 两主一从,从本质上说,只不过是机器 master-a 和 master-b 互为主从机(热备),然后通过 keepalived 进行高可用配置,使得在同一时间内只会有一台对外提供服务,实现单 ...

  5. Luogu P1856 [USACO5.5]矩形周长Picture

    线段树+扫描线 经典的扫描线问题 首先将一个矩形看作由竖着的两条边和横着的两条边构成 那分成两次考虑,一次考虑竖边,一次考虑横边 首先考虑横边 如图两个矩形,现将横边擦去,留下竖边,将平面划分成3个区 ...

  6. [POJ 2821]TN's Kindom III(任意长度循环卷积的Bluestein算法)

    [POJ 2821]TN's Kindom III(任意长度循环卷积的Bluestein算法) 题面 给出两个长度为\(n\)的序列\(B,C\),已知\(A\)和\(B\)的循环卷积为\(C\),求 ...

  7. Python 3.9就要来了......,令人兴奋的时刻

    本文主要介绍Python3.9的一些新特性,如:更快速的进程释放,性能的提升,简便的新字符串函数,字典并集运算符以及更兼容稳定的内部API,详细如下: 字典并集和可迭代更新 字符串方法 类型提示 新的 ...

  8. 内网渗透 day14-empire基础命令的使用

    empire的基础操作 目录 1. 建立监听器 2. 设置stagers 3. 用户交互 4. 提权 1. 建立监听器 help    查看帮助命令 listeners     查看监听器 useli ...

  9. <摘自>飞:jxl简析[ http://www.emlog.net/fei ]

    <摘自>飞:jxl简析:http://www.emlog.net/fei 最近,完成了一个网上报表系统,刚巧用到了一个 JAVA 操作 excel 表格的 API .闲来无事,就将其大概的 ...

  10. JS模拟百度分享侧边栏效果

    模拟百度分享侧边栏的弹出与滑入效果.当鼠标移入#div1分享侧边栏,#div1分享侧边栏区块匀速滑出直至其全部露出.当鼠标移除#div1分享侧边栏,#div1分享侧边栏区块匀速滑入隐藏,直至恢复初始位 ...