Ruby 2.1.0 リファレンスマニュアル > ライブラリ一覧 > opensslライブラリ > OpenSSL::SSL::SSLSocketクラス

class OpenSSL::SSL::SSLSocket

クラス・モジュールの継承リスト: OpenSSL::SSL::SSLSocket < Enumerable < OpenSSL::SSL::SocketForwarder < OpenSSL::Buffering < Object < Kernel < BasicObject

要約

ソケットをラップして SSL での認証と暗号通信を実現するためのクラスです。

SSL/TLS サーバに接続して write します。

require 'socket'
require 'openssl'
include OpenSSL

soc = TCPSocket.new('www.example.com', 443)
ssl = SSL::SSLSocket.new(soc)
ssl.connect
ssl.post_connection_check('www.example.com')
raise "verification error" if ssl.verify_result != OpenSSL::X509::V_OK
ssl.write('hoge')
print ssl.peer_cert.to_text
ssl.close
soc.close

特異メソッド

定義 説明
new(socket) -> OpenSSL::SSL::SSLSocket
new(socket, context) -> OpenSSL::SSL::SSLSocket

socket をラップして SSLSocket オブジェクトを生成します。

インスタンスメソッド

定義 説明
accept -> self

TLS/SSL 通信をサーバモードとして開始し、クライアントからのハンドシェイク開始を待ち、クライアントとのハンドシェイクを実行します。

accept_nonblock -> self

ノンブロッキング方式で TLS/SSL 通信をサーバモードとして開始し、クライアントとのハンドシェイクを実行します。

cert -> OpenSSL::X509::Certificate | nil

自分自身を証明する証明書を返します。

cipher -> [String, String, Integer, Integer]

現在実際に使われている暗号の情報を配列で返します。

connect -> self

TLS/SSl 通信をクライアントモードとして開始し、サーバとのハンドシェイクを実行します。

connect_nonblock -> self

ノンブロッキング方式で TLS/SSL 通信をクライアントモードとして開始し、サーバとのハンドシェイクを実行します。

context -> OpenSSL::SSL::SSLContext

SSLSocket オブジェクトを生成する時に渡されたコンテクストを返します。

hostname -> String | nil

TLS の Server Name Indication 拡張で利用するサーバのホスト名を返します。

hostname=(hostname)

TLS の Server Name Indication(SNI) 拡張で利用するサーバのホスト名を設定します。

io -> IO
to_io -> IO

SSLSocket オブジェクトを生成する時に渡されたソケットを返します。

peer_cert -> OpenSSL::X509::Certificate | nil

接続相手の証明書オブジェクトを返します。

peer_cert_chain -> [OpenSSL::X509::Certificate] | nil

接続相手の証明書チェインを OpenSSL::X509::Certificate オブジェクトの配列で返します。

pending -> Integer | nil

OpenSSL内部のバッファが保持している、直ちに読み取り可能なデータのバイト数を返します。

post_connection_check(hostname) -> true

接続後検証を行います。

session -> OpenSSL::SSL::Session

利用している SSL セッションを OpenSSL::SSL::Session オブジェクトで返します。

session=(sess)

ハンドシェイクで再利用する SSL セッションを設定します。

session_reused? -> bool

利用している SSL セッションが再利用されたものである場合に真を返します。

state -> String

現在の状態をアルファベット 6 文字の文字列で返します。

sync_close -> bool

SSLSocket を close するときにラップしているソケットも close するかどうかを返します。

sync_close=(bool)

SSLSocket を close するときにラップしているソケットも close するかどうかを設定します。

sysclose -> nil

接続を閉じます。相手に'close notify'を送ります。

sysread(length, buf=nil) -> String

データをバッファを経由せずに暗号化通信路から読み込み、読み込んだデータを文字列で返します。

syswrite(string) -> Integer

データをバッファを経由せずに暗号化通信路に書き込みます。

verify_result -> Integer

検証結果のエラーコードを整数値で返します。

継承したメソッド

! != __id__ __send__ instance_eval instance_exec method_missing singleton_method_added singleton_method_removed singleton_method_undefined all? any? chunk chunk_while collect collect_concat count cycle detect drop drop_while each_cons each_entry each_slice each_with_index each_with_object entries find_all find_index first grep grep_v group_by include? inject lazy max max_by min min_by minmax minmax_by none? one? partition reject reverse_each slice_after slice_before slice_when sort sort_by sum take take_while to_h to_set uniq zip !~ <=> == === =~ _dump class clone define_singleton_method display enum_for eql? equal? extend freeze frozen? hash initialize initialize_copy inspect instance_of? instance_variable_defined? instance_variable_get instance_variable_set instance_variables is_a? itself marshal_dump marshal_load method methods must_be must_be_close_to must_be_empty must_be_instance_of must_be_kind_of must_be_nil must_be_same_as must_be_within_epsilon must_equal must_include must_match must_raise must_respond_to must_send must_throw nil? object_id pretty_inspect pretty_print pretty_print_cycle pretty_print_inspect pretty_print_instance_variables private_methods protected_methods psych_to_yaml public_method public_methods public_send remove_instance_variable respond_to? respond_to_missing? send singleton_class singleton_method singleton_methods taint tainted? tap to_ary to_hash to_int to_proc to_regexp to_s to_str trust untaint untrust untrusted? .yaml_tag ::ARGF ::ARGV ::DATA ::ENV ::FALSE ::NIL ::RUBY_COPYRIGHT ::RUBY_DESCRIPTION ::RUBY_ENGINE ::RUBY_PATCHLEVEL ::RUBY_PLATFORM ::RUBY_RELEASE_DATE ::RUBY_REVISION ::RUBY_VERSION ::SCRIPT_LINES__ ::STDERR ::STDIN ::STDOUT ::TOPLEVEL_BINDING ::TRUE << close each each_byte eof flush getc gets print printf puts read read_nonblock readchar readline readlines readpartial sync sync= ungetc write write_nonblock ::BLOCK_SIZE addr closed? do_not_reverse_lookup= fcntl getsockopt peeraddr setsockopt