Help us understand the problem. What is going on with this article?

OpenSSLでcertificate verify failedが出た場合

More than 5 years have passed since last update.

ハマったのでメモ

環境

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
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした