Class: HTTPClient::SSLSocketWrap

Inherits:
Object
  • Object
show all
Defined in:
lib/httpclient/session.rb

Overview

Wraps up OpenSSL::SSL::SSLSocket and offers debugging features.

Instance Method Summary collapse

Constructor Details

#initialize(socket, context, debug_dev = nil) ⇒ SSLSocketWrap

Returns a new instance of SSLSocketWrap.



296
297
298
299
300
301
302
303
304
# File 'lib/httpclient/session.rb', line 296

def initialize(socket, context, debug_dev = nil)
  unless SSLEnabled
    raise ConfigurationError.new('Ruby/OpenSSL module is required')
  end
  @context = context
  @socket = socket
  @ssl_socket = create_openssl_socket(@socket)
  @debug_dev = debug_dev
end

Instance Method Details

#<<(str) ⇒ Object



376
377
378
379
380
# File 'lib/httpclient/session.rb', line 376

def <<(str)
  rv = @ssl_socket.write(str)
  debug(str)
  rv
end

#closeObject



345
346
347
348
# File 'lib/httpclient/session.rb', line 345

def close
  @ssl_socket.close
  @socket.close
end

#closed?Boolean

Returns:

  • (Boolean)


350
351
352
# File 'lib/httpclient/session.rb', line 350

def closed?
  @socket.closed?
end

#eof?Boolean

Returns:

  • (Boolean)


354
355
356
# File 'lib/httpclient/session.rb', line 354

def eof?
  @ssl_socket.eof?
end

#flushObject



382
383
384
# File 'lib/httpclient/session.rb', line 382

def flush
  @ssl_socket.flush
end

#gets(*args) ⇒ Object



358
359
360
361
362
# File 'lib/httpclient/session.rb', line 358

def gets(*args)
  str = @ssl_socket.gets(*args)
  debug(str)
  str
end

#peer_certObject



341
342
343
# File 'lib/httpclient/session.rb', line 341

def peer_cert
  @ssl_socket.peer_cert
end

#post_connection_check(host) ⇒ Object



313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# File 'lib/httpclient/session.rb', line 313

def post_connection_check(host)
  verify_mode = @context.verify_mode || OpenSSL::SSL::VERIFY_NONE
  if verify_mode == OpenSSL::SSL::VERIFY_NONE
    return
  elsif @ssl_socket.peer_cert.nil? and
    check_mask(verify_mode, OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT)
    raise OpenSSL::SSL::SSLError.new('no peer cert')
  end
  hostname = host.host
  if @ssl_socket.respond_to?(:post_connection_check) and RUBY_VERSION > "1.8.4"
    @ssl_socket.post_connection_check(hostname)
  else
    @context.post_connection_check(@ssl_socket.peer_cert, hostname)
  end
end

#read(*args) ⇒ Object



364
365
366
367
368
# File 'lib/httpclient/session.rb', line 364

def read(*args)
  str = @ssl_socket.read(*args)
  debug(str)
  str
end

#readpartial(*args) ⇒ Object



370
371
372
373
374
# File 'lib/httpclient/session.rb', line 370

def readpartial(*args)
  str = @ssl_socket.readpartial(*args)
  debug(str)
  str
end

#ssl_cipherObject



333
334
335
# File 'lib/httpclient/session.rb', line 333

def ssl_cipher
  @ssl_socket.cipher
end

#ssl_connect(hostname = nil) ⇒ Object



306
307
308
309
310
311
# File 'lib/httpclient/session.rb', line 306

def ssl_connect(hostname = nil)
  if hostname && @ssl_socket.respond_to?(:hostname=)
    @ssl_socket.hostname = hostname
  end
  @ssl_socket.connect
end

#ssl_stateObject



337
338
339
# File 'lib/httpclient/session.rb', line 337

def ssl_state
  @ssl_socket.state
end

#ssl_versionObject



329
330
331
# File 'lib/httpclient/session.rb', line 329

def ssl_version
  @ssl_socket.ssl_version if @ssl_socket.respond_to?(:ssl_version)
end

#syncObject



386
387
388
# File 'lib/httpclient/session.rb', line 386

def sync
  @ssl_socket.sync
end

#sync=(sync) ⇒ Object



390
391
392
# File 'lib/httpclient/session.rb', line 390

def sync=(sync)
  @ssl_socket.sync = sync
end