Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
65
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

@kengos@github

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
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
65
Help us understand the problem. What are the problem?