Skip to content

Commit

Permalink
feat(chenso): adds support for client SSL certificates
Browse files Browse the repository at this point in the history
  • Loading branch information
iobaixas committed Nov 18, 2016
1 parent 49124e0 commit 0b6bada
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,15 @@ Pincers.for_chenso do |pincers|
end
```

Chenso also supports **client SSL certificate**, to use a client certificate use the `ssl_cert` and `ssl_key` options:

```ruby
Pincers.for_chenso(
ssl_cert: OpenSSL::X509::Certificate.new(File.read('./client.cert.pem')),
ssl_key: OpenSSL::PKey::RSA.new(File.read('./client.key.pem'))
)
```

#### Navigating frames

Pincers operations can only target one frame at a time. By default, the top frame is selected when location is changed. To switch to a diferent frame use the `goto` method with the `frame:` option:
Expand Down
5 changes: 5 additions & 0 deletions lib/pincers/http/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ def self.build_from_options(_options = {})
session.headers.merge! _options[:headers] if _options.key? :headers
session.redirect_limit = _options[:redirect_limit] if _options.key? :redirect_limit

if _options.key? :ssl_cert
session.ssl_cert = _options[:ssl_cert]
session.ssl_key = _options[:ssl_key]
end

client = self.new session, _options[:document]
client.freeze if _options[:freeze]
client
Expand Down
11 changes: 10 additions & 1 deletion lib/pincers/http/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class Session
}

attr_reader :cookie_jar, :headers
attr_accessor :proxy_addr, :proxy_port, :proxy_user, :proxy_password, :redirect_limit
attr_accessor :proxy_addr, :proxy_port, :proxy_user, :proxy_password, :redirect_limit,
:ssl_cert, :ssl_key

def initialize(_other = nil)
if _other
Expand All @@ -20,6 +21,8 @@ def initialize(_other = nil)
@proxy_addr = _other.proxy_addr
@proxy_port = _other.proxy_port
@redirect_limit = _other.redirect_limit
@ssl_cert = _other.ssl_cert
@ssl_key = _other.ssl_key
else
@headers = DEFAULT_HEADERS
@cookie_jar = CookieJar.new
Expand Down Expand Up @@ -102,6 +105,12 @@ def connect(_uri)
)

conn.use_ssl = true if _uri.scheme == 'https'

if ssl_cert
conn.cert = ssl_cert
conn.key = ssl_key
end

conn.verify_mode = OpenSSL::SSL::VERIFY_NONE
conn
end
Expand Down

0 comments on commit 0b6bada

Please sign in to comment.