Method: Aerospike::Socket::SSL.create_context

Defined in:
lib/aerospike/socket/ssl.rb

.create_context(tls_options) ⇒ Object


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/aerospike/socket/ssl.rb', line 48

def create_context(tls_options)
  OpenSSL::SSL::SSLContext.new.tap do |ctx|
    if tls_options[:cert_file] && tls_options[:pkey_file]
      cert = OpenSSL::X509::Certificate.new(File.read(tls_options[:cert_file]))
      pkey = OpenSSL::PKey.read(File.read(tls_options[:pkey_file]), tls_options[:pkey_pass])
      if ctx.respond_to?(:add_certificate)
        ctx.add_certificate(cert, pkey)
      else
        ctx.cert = cert
        ctx.key = pkey
      end
    end

    params = DEFAULT_TLS_PARAMS.merge(filter_params(tls_options))
    ctx.set_params(params) unless params.empty?
  end
end