Class: HTTParty::ConnectionAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/occi/api/client/http/httparty_fix.rb

Instance Method Summary collapse

Instance Method Details

#attach_ssl_certificates(http, options) ⇒ Object (private)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/occi/api/client/http/httparty_fix.rb', line 6

def attach_ssl_certificates(http, options)
  if http.use_ssl?
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE

    # Client certificate authentication
    if options[:pem]
      http.cert = OpenSSL::X509::Certificate.new(options[:pem])
      http.key = OpenSSL::PKey::RSA.new(options[:pem], options[:pem_password])
      http.verify_mode = OpenSSL::SSL::VERIFY_PEER
    end

    # Set chain of client certificates
    if options[:ssl_extra_chain_cert]
      http.extra_chain_cert = []

      options[:ssl_extra_chain_cert].each do |p_ca|
        http.extra_chain_cert << OpenSSL::X509::Certificate.new(p_ca)
      end
    end

    # SSL certificate authority file and/or directory
    if options[:ssl_ca_file]
      http.ca_file = options[:ssl_ca_file]
      http.verify_mode = OpenSSL::SSL::VERIFY_PEER
    end

    if options[:ssl_ca_path]
      http.ca_path = options[:ssl_ca_path]
      http.verify_mode = OpenSSL::SSL::VERIFY_PEER
    end

    # This is only Ruby 1.9+
    if options[:ssl_version] && http.respond_to?(:ssl_version=)
      http.ssl_version = options[:ssl_version]
    end
  end
end