*. 에러현상
file_get_contents() 에서 https 호출시 아래와 같은 에러가 발생될 겨우
[root@xxxx tmp]# php test2.php
PHP Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /tmp/test2.php on line 10
PHP Warning: file_get_contents(): Failed to enable crypto in /tmp/test2.php on line 10
PHP Warning: file_get_contents(https://xxxx.yyyy.com/abc): failed to open stream: operation failed in /tmp/test2.php on line 10
bool(false)
*. 원인
CA인증서 만료날짜가 지나서 생기는 이슈
*. 임시 해결법
$arrContextOptions=array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);
$response = file_get_contents("https://xxxx.yyyy.com/abc", false,$arrContextOptions);
*. OS에서 CA 인증서 새로 받아 적용
centos 7 기준
*. 인증서 위치 : /etc/pki/tls/certs
[root@xxxx certs]# ll
total 16
lrwxrwxrwx 1 root root 49 Feb 25 2021 ca-bundle.crt -> /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem <-- 이파일 교체
lrwxrwxrwx 1 root root 55 Feb 25 2021 ca-bundle.trust.crt -> /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt
-rw-------. 1 root root 1403 Mar 12 2019 localhost.crt
-rwxr-xr-x 1 root root 610 Dec 17 2020 make-dummy-cert
-rw-r--r-- 1 root root 2516 Dec 17 2020 Makefile
-rwxr-xr-x 1 root root 829 Dec 17 2020 renew-dummy-cert
*. 인증서 갱신 ( https://curl.se/docs/caextract.html 에서 확인)
[root@xxxx tmp]# curl https://curl.se/ca/cacert.pem -o /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
*. update-ca-trust
이 명령어 사용하지 말라! 오래된 인증서로 다시 내려 받더라.