Class: SumologicCloudSyslog::SSLTransport

Inherits:
Object
  • Object
show all
Defined in:
lib/sumologic_cloud_syslog/ssl_transport.rb

Overview

Supports SSL connection to remote host

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port, cert: nil, key: nil, ssl_version: :TLSv1_2) ⇒ SSLTransport

Returns a new instance of SSLTransport.



25
26
27
28
29
30
31
32
# File 'lib/sumologic_cloud_syslog/ssl_transport.rb', line 25

def initialize(host, port, cert: nil, key: nil, ssl_version: :TLSv1_2)
  @host = host
  @port = port
  @cert = cert
  @key = key
  @ssl_version = ssl_version
  connect
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_sym, *arguments, &block) ⇒ Object

Forward any methods directly to SSLSocket



49
50
51
# File 'lib/sumologic_cloud_syslog/ssl_transport.rb', line 49

def method_missing(method_sym, *arguments, &block)
  @socket.send(method_sym, *arguments, &block)
end

Instance Attribute Details

#certObject (readonly)

Returns the value of attribute cert.



23
24
25
# File 'lib/sumologic_cloud_syslog/ssl_transport.rb', line 23

def cert
  @cert
end

#hostObject (readonly)

Returns the value of attribute host.



23
24
25
# File 'lib/sumologic_cloud_syslog/ssl_transport.rb', line 23

def host
  @host
end

#keyObject (readonly)

Returns the value of attribute key.



23
24
25
# File 'lib/sumologic_cloud_syslog/ssl_transport.rb', line 23

def key
  @key
end

#portObject (readonly)

Returns the value of attribute port.



23
24
25
# File 'lib/sumologic_cloud_syslog/ssl_transport.rb', line 23

def port
  @port
end

#socketObject

Returns the value of attribute socket.



21
22
23
# File 'lib/sumologic_cloud_syslog/ssl_transport.rb', line 21

def socket
  @socket
end

#ssl_versionObject (readonly)

Returns the value of attribute ssl_version.



23
24
25
# File 'lib/sumologic_cloud_syslog/ssl_transport.rb', line 23

def ssl_version
  @ssl_version
end

Instance Method Details

#connectObject



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sumologic_cloud_syslog/ssl_transport.rb', line 34

def connect
  tcp = TCPSocket.new(host, port)

  ctx = OpenSSL::SSL::SSLContext.new
  ctx.set_params(verify_mode: OpenSSL::SSL::VERIFY_PEER)
  ctx.ssl_version = ssl_version

  ctx.cert = OpenSSL::X509::Certificate.new(File.open(cert)) if cert
  ctx.key = OpenSSL::PKey::RSA.new(File.open(key)) if key

  @socket = OpenSSL::SSL::SSLSocket.new(tcp, ctx)
  @socket.connect
end