Skip to content

Commit d3b9843

Browse files
authored
Merge pull request #214 from c960657/ssl-ciphers
Implement HTTPI::Auth::SSL#ciphers configuration
2 parents 8cb7189 + 03f1293 commit d3b9843

File tree

21 files changed

+178
-77
lines changed

21 files changed

+178
-77
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
### Unreleased
2+
* Feature: [#214](https://github.com/savonrb/httpi/pull/214) Add SSL ciphers configuration
3+
14
### 2.4.5
25

36
* Improvement: [#209](https://github.com/savonrb/httpi/pull/209) Drop Travis CI support for Ruby < 2.3.0 and jruby.

httpi.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
2020

2121
s.add_development_dependency 'rubyntlm', '~> 0.3.2'
2222
s.add_development_dependency 'rake', '~> 10.0'
23-
s.add_development_dependency 'rspec', '~> 2.14'
23+
s.add_development_dependency 'rspec', '~> 3.5'
2424
s.add_development_dependency 'mocha', '~> 0.13'
2525
s.add_development_dependency 'puma', '~> 2.3.2'
2626
s.add_development_dependency 'webmock'

lib/httpi/adapter/curb.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ def setup_ssl_auth
116116
@client.cert_key = ssl.cert_key_file
117117
@client.cert = ssl.cert_file
118118
@client.certpassword = ssl.cert_key_password
119+
@client.set(:ssl_cipher_list, ssl.ciphers.join(':')) if ssl.ciphers
119120

120121
@client.ssl_verify_peer = ssl.verify_mode == :peer
121122
end

lib/httpi/adapter/excon.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def client_opts
7373
opts[:ssl_verify_peer] = false
7474
end
7575

76+
opts[:ciphers] = ssl.ciphers if ssl.ciphers
7677
opts[:ssl_version] = ssl.ssl_version if ssl.ssl_version
7778
opts[:ssl_min_version] = ssl.min_version if ssl.min_version
7879
opts[:ssl_max_version] = ssl.max_version if ssl.max_version

lib/httpi/adapter/http.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def create_client
6161
context.min_version = @request.auth.ssl.min_version if @request.auth.ssl.min_version != nil
6262
context.max_version = @request.auth.ssl.max_version if @request.auth.ssl.max_version != nil
6363
context.verify_mode = @request.auth.ssl.openssl_verify_mode
64+
context.ciphers = @request.auth.ssl.ciphers if @request.auth.ssl.ciphers
6465

6566
client = ::HTTP::Client.new(:ssl_context => context)
6667
else

lib/httpi/adapter/httpclient.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def setup_ssl_auth
7373
# Send client-side certificate regardless of state of SSL verify mode
7474
@client.ssl_config.client_cert = ssl.cert
7575
@client.ssl_config.client_key = ssl.cert_key
76+
@client.ssl_config.ciphers = ssl.ciphers if ssl.ciphers
7677

7778
@client.ssl_config.verify_mode = ssl.openssl_verify_mode
7879
end

lib/httpi/adapter/net_http.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ def setup_ssl_auth
177177
# Send client-side certificate regardless of state of SSL verify mode
178178
@client.key = ssl.cert_key
179179
@client.cert = ssl.cert
180+
@client.ciphers = ssl.ciphers if ssl.ciphers
180181

181182
@client.verify_mode = ssl.openssl_verify_mode
182183
end

lib/httpi/auth/ssl.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class SSL
2525

2626
# Returns whether SSL configuration is present.
2727
def present?
28-
(verify_mode == :none) || (cert && cert_key) || ca_cert_file
28+
(verify_mode == :none) || (cert && cert_key) || ca_cert_file || ciphers
2929
rescue TypeError, Errno::ENOENT
3030
false
3131
end
@@ -48,6 +48,24 @@ def present?
4848
# Certificate store holds trusted CA certificates used to verify peer certificates.
4949
attr_accessor :cert_store
5050

51+
# Accessor for the SSL ciphers list.
52+
attr_reader :ciphers
53+
54+
# Sets the available symmetric algorithms for encryption and decryption.
55+
# @see OpenSSL::SSL::SSLContext#ciphers
56+
# @example
57+
# ssl.ciphers = "cipher1:cipher2:..."
58+
# ssl.ciphers = [name, ...]
59+
# ssl.ciphers = [[name, version, bits, alg_bits], ...]
60+
def ciphers=(ciphers)
61+
@ciphers =
62+
if ciphers
63+
context = OpenSSL::SSL::SSLContext.new
64+
context.ciphers = ciphers
65+
context.ciphers.map(&:first)
66+
end
67+
end
68+
5169
# Returns the cert type to validate SSL certificates PEM|DER.
5270
def cert_type
5371
@cert_type ||= :pem

spec/httpi/adapter/curb_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,13 @@
250250
request
251251
end
252252

253+
it 'sets ssl_cipher_list' do
254+
request.auth.ssl.ciphers = ["AES128"]
255+
curb.expects(:set).with(any_parameters).at_least(1)
256+
curb.expects(:set).with(:ssl_cipher_list, anything)
257+
adapter.request(:get)
258+
end
259+
253260
context 'sets ssl_version' do
254261
it 'defaults to nil when no ssl_version is specified' do
255262
curb.expects(:ssl_version=).with(nil)

spec/httpi/adapter/em_http_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150

151151
it "raises an error for HTTP digest auth" do
152152
request.auth.digest "username", "password"
153-
expect { adapter.request(:get) }.to raise_error
153+
expect { adapter.request(:get) }.to raise_error HTTPI::NotSupportedError
154154
end
155155
end
156156

0 commit comments

Comments
 (0)