サーバのSSL CA(認証局)証明書が古くてcurl がエラーになる件

古いサーバにrvmをgithub から取ってこようとしたらエラーになったよ。

  • 新しいサーバ

https://raw.github.com へのRedirectも問題なくアクセスできてる。

$ curl -L -I get.rvm.io
HTTP/1.1 301 Moved Permanently
Server: nginx/1.0.14
Date: Thu, 21 Jun 2012 01:22:39 GMT
Content-Type: text/html
Content-Length: 185
Connection: keep-alive
Location: https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer

HTTP/1.1 200 OK
Server: nginx/1.0.13
Date: Thu, 21 Jun 2012 01:22:40 GMT
Content-Type: text/plain; charset=utf-8
Connection: keep-alive
Status: 200 OK
Content-Length: 1
X-RateLimit-Remaining: 100
Cache-Control: no-cache
X-Frame-Options: deny
X-Runtime: 16
X-RateLimit-Limit: 100
  • 古いサーバ
$ curl -L -I get.rvm.io
HTTP/1.1 301 Moved Permanently
Server: nginx/1.0.14
Date: Thu, 21 Jun 2012 01:22:45 GMT
Content-Type: text/html
Content-Length: 185
Connection: keep-alive
Location: https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer

curl: (60) SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
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). The default
 bundle is named curl-ca-bundle.crt; 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.

解決

新しい証明書とってくる。

$ wget http://curl.haxx.se/ca/cacert.pem
CAを入れ替える

取ってきたcacert.pem で入れ替える。ただ、これをしたときに既存のものにどういう影響が出るかよくわかってないので、心配なら一時的に新しいものを指定しといたほうが安心かな。

# cd /etc/pki/tls/certs/
# mv ca-bundle.crt ca-bundle.crt.org
# mv ~/cacert.pem ca-bundle.crt
一時的に新しいCAを指定する場合
  • optionで指定
$ curl --cacert cacert.pem https://ssl.example.com/
$ export CURL_CA_BUNDLE=cacert.pem
$ curl https://ssl.example.com/

追記 (たぶんこっちが正解)

↑のやってから気付いたけど、RHEL系の場合は /etc/pki/tls/certs/ca-bundle.crt はopensslパッケージに含まれているので、
手動でごちゃごちゃ頑張らなくても、yum update openssl をすればca-bundle.crtも更新されるはず。