Ruby 1.9.0 > Home > All Libraries > library net/https

library net/https

Abstract

net/http に SSL/TLS 拡張を実装するライブラリです。

[注意] net/https は RFC2818 の 3.1 に定められた 「サーバーの証明書に記載された身元のチェック」を自動では実行しません。 接続しているはずのサーバのホスト名と証明書に記載されているホスト名が 一致するかをライブラリの使用者が各自実装する必要があります。

http://www.ipa.go.jp/security/rfc/RFC2818JA.html#31

[ruby-dev:25254]

Example

簡単な例を挙げます。 verify_mode に指定する定数に関しては OpenSSL::SSL を参照してください。 必ず use_ssl = true を呼ばなければいけないところに注意してください。

require 'net/https'
https = Net::HTTP.new('www.example.com',443)
https.use_ssl = true
https.ca_file = '/usr/share/ssl/cert.pem'
https.verify_mode = OpenSSL::SSL::VERIFY_PEER
https.verify_depth = 5
https.start {
  response = https.get('/')
  puts response.body
}

以下は HTTPS プロクシ経由でアクセスする例です。 プロクシ経由でも通信路は暗号化されます。 [[unknown:WWWプロキシにおけるSSLトンネリング|URL:http://www21.ocn.ne.jp/~k-west/SSLandTLS/draft-luotonen-ssl-tunneling-03-Ja.txt]] を参照してください。

require 'net/https'
proxy_addr = 'proxy.example.com'
proxy_port = 3128
https = Net::HTTP::Proxy(proxy_addr, proxy_port).new('www.example.com',443)
https.use_ssl = true
https.ca_file = '/usr/share/ssl/cert.pem'
https.verify_mode = OpenSSL::SSL::VERIFY_PEER
https.verify_depth = 5
https.start {
  response = https.get('/')
  puts response.body
}

Added/Redefined Methods

Net::HTTP#ca_file Net::HTTP#ca_path Net::HTTP#cert Net::HTTP#cert_store Net::HTTP#key Net::HTTP#peer_cert Net::HTTP#ssl_timeout Net::HTTP#ssl_timeout= Net::HTTP#use_ssl= Net::HTTP#use_ssl? Net::HTTP#verify_callback Net::HTTP#verify_depth Net::HTTP#verify_mode