事象
Cygwinでcurlを使って、httpsで通信しようとした場合にエラーとなる。
$ curl https://google.co.jp
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 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.
実施したこと
サーバ証明書をダウンロードする
http://curl.haxx.se/docs/caextract.html からca-bundle.crtをホームディレクトリにコピーする。
ファイル名を「curl-ca-bundle.crt 」に変更する。
ただし、カレントディレクトリを移動するとうまくいかない。
$ ls
ca-bundle.crt
$ mv ca-bundle.crt curl-ca-bundle.crt
$ curl https://google.co.jp
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 222 100 222 0 0 395 0 --:--:-- --:--:-- --:--:-- 395<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://www.google.co.jp/">here</A>.
</BODY></HTML>
$ cd /
$ curl https://google.co.jp
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 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.
curlの日本語マニュアルに以下の記述を発見。とりあえずcurl-ca-bundle.crtをPATH内に配置する。
curl の windows 版は、自動的に, curl.exe と同じディレクトリ内, カレントディレクトリ内, あるいはユーザの PATH 以下のフォルダから、 curl-ca-bundle.crt というファイル名の CA 証明書を探し出します。
http://www.hcn.zaq.ne.jp/___/unix/curl_manpage.html