Ruby 2.3.0 リファレンスマニュアル > ライブラリ一覧 > opensslライブラリ > OpenSSL::OCSPモジュール
クラス・モジュールの継承リスト: OpenSSL::OCSP
OCSP(Online Certificate Status Protocol)を取り扱うためのモジュールです。OCSP は [RFC2560] で定義されています。
このモジュールは OCSP のリクエストとレスポンスを取り扱う機能を持っています。
OCSP レスポンダと通信する機能はありません。ユーザが例えば OCSP over http などを実装する必要があります。
OCSP レスポンダにリクエストを送ってその返答を表示する
require 'openssl' require 'net/http' # ... subject # 問い合わせ対象の証明書(Certificate オブジェクト) issuer # subject の発行者の証明書(Certificate オブジェクト) store # 信頼している証明書ストア cid = OpenSSL::OCSP::CertificateId.new(subject, issuer) req = OpenSSL::OCSP::Request.new req.add_certid(cid) req.add_nonce http = Net::HTTP.new('ocsp.example.com', 80) httpres = http.post("/", req.to_der, 'content-type' => 'application/ocsp-request') raise "HTTP error" if !httpres.kind_of?(Net::HTTPOK) res = OpenSSL::OCSP::Response.new(httpres.body) puts "Response status: #{res.status_string}" exit if res.status != OpenSSL::OCSP::RESPONSE_STATUS_SUCCESSFUL basic_resp = res.basic raise "nonce error" unless [-1, 1].include?(req.check_nonce(basic_resp)) unless basic_resp.verify([], store) puts "verify response fail" end rescid, status, reason, revtime, thisupd, nextupd, exts = basic_resp.status.first STATUS2MESSAGE = { OpenSSL::OCSP::V_CERTSTATUS_GOOD => "OK", OpenSSL::OCSP::V_CERTSTATUS_REVOKED => "REVOKED", OpenSSL::OCSP::V_CERTSTATUS_UNKNOWN => "UNKNOWN", } puts "status: #{STATUS2MESSAGE[status]}" puts "reason: #{reason}" if status == OpenSSL::OCSP::V_CERTSTATUS_REVOKED puts "revoked time: #{revtime}" if status == OpenSSL::OCSP::V_CERTSTATUS_REVOKED puts "response update: #{thisupd}" puts "response next update: #{nextupd}" puts "extensions: " exts.each{|ext| p ext}