Ubuntu curl: (60) ssl certificate problem: self signed certificate in certificate chain

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 파일이 어디에 있는지 위치를 확인한다.

Ubuntu curl: (60) ssl certificate problem: self signed certificate in certificate chain

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 문제 해결 을 참고

같이 보기

  • java keytool 사용법 - Keystore 생성, 키쌍 생성, 인증서 등록 및 관리
  • Guzzle - cURL error 60: SSL certificate problem: unable to get local issuer certificate 문제 해결
  • git 에서 https repository 연결시 SSL 인증서 오류 해결법
  • Java 에서 ValidatorException 등 인증서 관련 에러 해결 - keystore에 SSL/TLS 인증서를 import 하기
  • SSL Intermediate 인증서 모음(github gist)



Edit: I had updated my root CA certificates from curl.haxx.se .


When I try curl -Iv https://yahoo.com I get an error as unable to get local issuer certificate in the result. However if I try curl -Iv --cacert /etc/ssl/certs/ca-certificates.crt https://yahoo.com I get a result without any error.

Weirdly curl -Iv https://google.com works properly. But curl -Iv https://deb.nodesource.com doesn't.

Is there any chance to overcome this issue? (by changing curl configuration etc.)

root@ip-172-31-40-176:/var# curl -Iv https://yahoo.com * Rebuilt URL to: https://yahoo.com/ * Hostname was NOT found in DNS cache * Trying 206.190.36.45... * Connected to yahoo.com (206.190.36.45) port 443 (#0) * successfully set certificate verify locations: * CAfile: none CApath: /etc/ssl/certs * SSLv3, TLS handshake, Client hello (1): * SSLv3, TLS handshake, Server hello (2): * SSLv3, TLS handshake, CERT (11): * SSLv3, TLS alert, Server hello (2): * SSL certificate problem: unable to get local issuer certificate * Closing connection 0 curl: (60) SSL certificate problem: unable to get local issuer certificate 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.

How do you fix self

To solve this, you'll need to install it as a trusted server. If it's signed by a non-trusted CA, you'll have to install that CA's certificate as well..
i would consider this a work around or an option for testing. ... .
This seems to be specific to Node. ... .
It is NodeJS-specific and just disables all certificate checks..

How do I fix curl 60 SSL certificate problem certificate has expired?

The only solution to this problem is to get your host to update the root certificate on your server. So, you need to contact your server host and ask them to insert a new cacert. pem file into their servers, and configure it within their php.

How do you curl with a self

How use a self-signed certificate with Curl?.
Download and save the self-signed certificate..
Tell the Curl client about it with --cacert [file] command-line switch. This parameter tells the Curl to use the specified certificate file to verify the peer..

How do you fix a curl Error 60?

Solution:.
Save the cacert. pem file anywhere on your system. Example: Since you're modifying both php. ... .
Open your php.ini file. If your php.ini file doesn't have the curl.cainfo line, just add it to the end of the file, then add the file path where you saved your cacert.pem file: ... .
Restart your server..