记录 openssl 证书验证失败的诡异问题
项目使用了第三方包 tecnickcom/TCPDF
生成 PDF 文件,需要插入图片到文件中。
然后发生了以下报错:
[ error ] [2]getimagesize(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed
[ error ] [2]getimagesize(): Failed to enable crypto
[ error ] [2]getimagesize(https://www.xxx.com/static/upload/default-avatar.jpg): failed to open stream: operation failed
[ error ] [2]file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed
解决方案:
PHP 在发起 HTTPS 请求的时候,需要本地证书自验,也可以跳过不验证,我这里使用了验证证书。
先下载一个 CA
证书
wget http://curl.haxx.se/ca/cacert.pem
配置一下 php.ini
[openssl]
; The location of a Certificate Authority (CA) file on the local filesystem
; to use when verifying the identity of SSL/TLS peers. Most users should
; not specify a value for this directive as PHP will attempt to use the
; OS-managed cert stores in its absence. If specified, this value may still
; be overridden on a per-stream basis via the "cafile" SSL stream context
; option.
openssl.cafile= SSL证书绝对路径
问题解决。
一般情况是不需要理会这个证书的,就是不明白为什么 cafile 证书突然就失效了,但是
curl
是能发出https
请求的,所以感到很诡异,换了 cafile 证书之后就正常了。
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: