search
LoginSignup
64

More than 5 years have passed since last update.

posted at

updated at

OpenSSLでcertificate verify failedが出た場合

ハマったのでメモ

環境

OS X 10.8.2
rbenv + ruby-build
openssl 1.0.1e(brew)

rubyインストールの仕方は http://qiita.com/items/e7c4374d25ba2056a7b7 と同じ

エラー

require 'net/https'
https = Net::HTTP.new('github.com', 443)
https.use_ssl = true
https.verify_mode = OpenSSL::SSL::VERIFY_PEER
https.request_get('/')
# => OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
# ... 略 ...

CA_FILEの場所の確認

> require 'openssl'
=> true
> p OpenSSL::X509::DEFAULT_CERT_FILE
"/usr/local/etc/openssl/cert.pem"

指定されたディレクトリへ移動すると、cert.pemがない

$ cd /usr/local/etc/openssl
$ ll
total 24
drwxr-xr-x   4 kengos  admin    136  2 17 16:32 ./
drwxr-xr-x  14 kengos  admin    476  2 17 16:11 ../
drwxr-xr-x   9 kengos  admin    306  2 17 16:22 misc/
-rw-r--r--   1 kengos  admin  10835  2 17 16:22 openssl.cnf

適当にダウンロードして、設置したら解決

curl -o cert.pem http://curl.haxx.se/ca/cacert.pem
mv cert.pem /usr/local/etc/openssl

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
64