Class: WWW::Mechanize::Chain::SSLResolver

Inherits:
Object
  • Object
show all
Includes:
Handler
Defined in:
lib/www/mechanize/chain/ssl_resolver.rb

Instance Attribute Summary

Attributes included from Handler

#chain

Instance Method Summary collapse

Constructor Details

#initialize(ca_file, verify_callback, cert, key, pass) ⇒ SSLResolver

Returns a new instance of SSLResolver.



7
8
9
10
11
12
13
# File 'lib/www/mechanize/chain/ssl_resolver.rb', line 7

def initialize(ca_file, verify_callback, cert, key, pass)
  @ca_file = ca_file
  @verify_callback = verify_callback
  @cert = cert
  @key = key
  @pass = pass
end

Instance Method Details

#handle(ctx, params) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/www/mechanize/chain/ssl_resolver.rb', line 15

def handle(ctx, params)
  uri       = params[:uri]
  http_obj  = params[:connection]
  if uri.scheme == 'https' && ! http_obj.started? && ! http_obj.frozen?
    http_obj.use_ssl = true
    http_obj.verify_mode = OpenSSL::SSL::VERIFY_NONE
    if @ca_file
      http_obj.ca_file = @ca_file
      http_obj.verify_mode = OpenSSL::SSL::VERIFY_PEER
      http_obj.verify_callback = @verify_callback if @verify_callback
    end
    if @cert && @key
      http_obj.cert = OpenSSL::X509::Certificate.new(::File.read(@cert))
      http_obj.key  = OpenSSL::PKey::RSA.new(::File.read(@key), @pass)
    end
  end
  super
end