curl の openssl版でSSLサイトにアクセスすると "SSL certificate problem: unable to get local issuer certificate" エラーが表示される

curl の openssl版でSSLサイトにアクセスすると "SSL certificate problem: unable to get local issuer certificate" エラーが表示される現象について紹介します。

現象

curl の openssl版でSSLのサイトにアクセスすると、下記のエラーが発生します。
curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: https://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.


なお、winssl版のcurlでは同じコマンドを実行した場合でもエラーは発生しません。

原因

コマンドを実行したPCのクライアント証明書が無いことが原因です。

対処法1:クライアント証明書のチェックをしない

curl に -k オプションを指定することで、クライアント証明書のチェックをしないようにできます。

対処法2:クライアント証明書を用意する

クライアント証明書を用意します。curlコマンドに
--cacert (証明書(*.pem)ファイル) --capath (証明書ファイルのパス)
オプションを指定することで、指定した証明書を利用してアクセスします。
クライアント証明書はgit,phpなど他のソフトウェアの証明書でも動作します。証明書が無い場合は、curlのサイトからダウンロードできます。

cacert.pem のダウンロード手順

https://curl.haxx.se/docs/caextract.html にアクセスします。
下図のページが表示されます。ページ上部に[cacert.pem] ファイルへのリンクがありますので、こちらをクリックする、または、リンク先をファイルに保存するなどして、pemファイルをダウンロードします。



著者
iPentecのプログラマー、最近はAIの積極的な活用にも取り組み中。
とっても恥ずかしがり。
作成日: 2016-10-09
Copyright © iPentec all rights reserverd.