Class: X509Sleuth::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/x509_sleuth/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, options = {}) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
15
16
17
18
# File 'lib/x509_sleuth/client.rb', line 9

def initialize(host, options = {})
  options = {
    port:           443,
    timeout_secs:   15
  }.merge(options)

  @host         = host
  @port         = options[:port]
  @timeout_secs = options[:timeout_secs]
end

Instance Attribute Details

#connect_errorObject (readonly)

Returns the value of attribute connect_error.



7
8
9
# File 'lib/x509_sleuth/client.rb', line 7

def connect_error
  @connect_error
end

#hostObject (readonly)

Returns the value of attribute host.



7
8
9
# File 'lib/x509_sleuth/client.rb', line 7

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



7
8
9
# File 'lib/x509_sleuth/client.rb', line 7

def port
  @port
end

#timeout_secsObject (readonly)

Returns the value of attribute timeout_secs.



7
8
9
# File 'lib/x509_sleuth/client.rb', line 7

def timeout_secs
  @timeout_secs
end

Instance Method Details

#connectObject



30
31
32
33
34
# File 'lib/x509_sleuth/client.rb', line 30

def connect
  Timeout::timeout(@timeout_secs) { ssl_socket.connect }
rescue SystemCallError, SocketError, OpenSSL::SSL::SSLError, Timeout::Error => e
  @connect_error = e
end

#connect_failed?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/x509_sleuth/client.rb', line 36

def connect_failed?
  connect_error ? true : false
end

#peer_certificateObject



40
41
42
# File 'lib/x509_sleuth/client.rb', line 40

def peer_certificate
  @peer_certficate ||= ssl_socket.peer_cert
end

#ssl_socketObject



24
25
26
27
28
# File 'lib/x509_sleuth/client.rb', line 24

def ssl_socket
  @ssl_socket ||= OpenSSL::SSL::SSLSocket.new(tcp_socket)
  @ssl_socket.hostname = @host
  @ssl_socket
end

#tcp_socketObject



20
21
22
# File 'lib/x509_sleuth/client.rb', line 20

def tcp_socket
  @tcp_socket ||= TCPSocket.new(@host, @port)
end