curl 은 기본적으로 https 사이트의 SSL 인증서를 검증한다. 인증 기관의 인증서 목록이 없거나 모르는 기관에서 발급한 인증서일 경우 다음과 같은 인증서 검증 에러를 발생시키고 동작을 중지하게 된다.

cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
BASH


해결방법은 3가지가 있다.

1. 인증서 검증 안 함

검증을 하지 않는 옵션인 -k(--insecure) 옵션을 주고 curl 을 구동하면 된다.

curl -k -L google.com
BASH
curl --insecure -L google.com
BASH


2. 인증기관 목록 추가하기

2번째 방법은 curl 의 신뢰하는 인증 기관 목록(CA List; Certificate Authority List)에 접속하려는 사이트의 인증서를 발급한 기관을 추가하는 방법이다.


1.  먼저 curl 을 -v 옵션을 주고 실행해서 CA List 파일이 어디에 있는지 위치를 확인한다.

RHEL/CentOS 는 아래와 같이 /etc/pki/tls/certs/ca-bundle.crt 에서 CA 목록을 로딩함

lesstif@localhost:~> curl -v  https://google.com
 
* About to connect() to google.com port 443 (#0)
*   Trying 74.125.128.139... connected
* Connected to google.com (74.125.128.139) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
BASH

Ubuntu 는 /etc/ssl/certs/ca-certificates.crt 또는  /etc/ssl/certs 디렉터리에서 CA 목록 로딩

Windows 에서 curl.exe 를 사용시 다음 순서대로 ca-bundle.crt 를 찾음

  1. application's directory
  2. current working directory
  3. Windows System directory (e.g. C:\windows\system32)
  4. Windows Directory (e.g. C:\windows)
  5. all directories along %PATH%


2. 서버 인증서 및 CA List 를  BASE64 로 저장한 내용을 위에서 확인한 ca-bundle.crt 파일에 추가해 준다. 자세한 방법은 https 연결시 서버의 SSL 인증서 추출하기 (curl 또는 web browser 사용) 를 참고한다.


3. 런타임에 옵션으로 CA List 파일을 지정하려면 curl 실행시 --cacert  옵션으로 CA  List를 지정할 수 있다.

curl -v --cacert myca-bundle.crt https://google.com
BASH


3. CA 인증서 파일 갱신

새로운 인증 기관이 생겼는데 OS 에 포함된 curl 에는 반영이 안 되서 발생할 수 있다. curl 홈페이지에서는 주기적으로 최신 인증 기관 목록을 갱신햇 배포하므로 CA 인증서 목록을 다운받아서 기존 파일에 덮어써도 된다.

1. wget 또는 curl  명령을 사용해서 https://curl.haxx.se/ca/cacert.pem 에서 인증서를 다운받는다. 

wget 사용

wget --no-check-certificate https://curl.haxx.se/ca/cacert.pem
BASH

curl 사용

curl -k -O https://curl.haxx.se/ca/cacert.pem
CODE


2. curl -v 옵션으로 CA 인증서 목록 파일의 위치를 확인한 후에 예전 파일은 백업하고 다운받은 인증서 파일을 덮어쓴다.

curl 사용

sudo cp cacert.pem  /etc/ssl/certs/ca-certificates.crt 
CODE

PHP 에서 curl 사용시

Guzzle - cURL error 60: SSL certificate problem: unable to get local issuer certificate 문제 해결 을 참고

같이 보기