Module: PahoMqtt::SSLHelper

Extended by:
SSLHelper
Included in:
SSLHelper
Defined in:
lib/paho_mqtt/ssl_helper.rb

Instance Method Summary collapse

Instance Method Details

#config_ssl_context(cert_path, key_path, ca_path = nil) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/paho_mqtt/ssl_helper.rb', line 21

def config_ssl_context(cert_path, key_path, ca_path=nil)
  ssl_context = OpenSSL::SSL::SSLContext.new
  set_cert(cert_path, ssl_context)
  set_key(key_path, ssl_context)
  set_root_ca(ca_path, ssl_context)
  #ssl_context.verify_mode = OpenSSL::SSL::VERIFY_PEER unless ca_path.nil?
  ssl_context
end

#set_cert(cert_path, ssl_context) ⇒ Object



30
31
32
# File 'lib/paho_mqtt/ssl_helper.rb', line 30

def set_cert(cert_path, ssl_context)
  ssl_context.cert = OpenSSL::X509::Certificate.new(File.read(cert_path))
end

#set_key(key_path, ssl_context) ⇒ Object



34
35
36
# File 'lib/paho_mqtt/ssl_helper.rb', line 34

def set_key(key_path, ssl_context)
  ssl_context.key = OpenSSL::PKey::RSA.new(File.read(key_path))
end

#set_root_ca(ca_path, ssl_context) ⇒ Object



38
39
40
# File 'lib/paho_mqtt/ssl_helper.rb', line 38

def set_root_ca(ca_path, ssl_context)
  ssl_context.ca_file = ca_path
end