Skip to content

Commit 865475c

Browse files
committed
Implement HTTPI::Auth::SSL#ciphers configuration
1 parent e671b7a commit 865475c

File tree

15 files changed

+63
-4
lines changed

15 files changed

+63
-4
lines changed

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
source 'https://rubygems.org'
2+
ruby RUBY_VERSION
23
gemspec
34

45
gem 'jruby-openssl', :platforms => :jruby
@@ -9,7 +10,7 @@ gem 'curb', '~> 0.8', :require => false, :platforms => :ruby
910
gem 'em-http-request', :require => false, :platforms => [:ruby, :jruby]
1011
gem 'em-synchrony', :require => false, :platforms => [:ruby, :jruby]
1112
gem 'excon', '~> 0.21', :require => false, :platforms => [:ruby, :jruby]
12-
gem 'net-http-persistent', '~> 2.8', :require => false
13+
gem 'net-http-persistent', :require => false
1314
gem 'http', :require => false
1415

1516
# coverage

httpi.gemspec

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

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

lib/httpi/adapter/curb.rb

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

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

lib/httpi/adapter/excon.rb

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

74+
opts[:ciphers] = ssl.ciphers if ssl.ciphers
7475
opts[:ssl_version] = ssl.ssl_version if ssl.ssl_version
7576

7677
opts

lib/httpi/adapter/http.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def create_client
5959
context.key = @request.auth.ssl.cert_key
6060
context.ssl_version = @request.auth.ssl.ssl_version if @request.auth.ssl.ssl_version != nil
6161
context.verify_mode = @request.auth.ssl.openssl_verify_mode
62+
context.ciphers = @request.auth.ssl.ciphers if @request.auth.ssl.ciphers
6263

6364
client = ::HTTP::Client.new(:ssl_context => context)
6465
else

lib/httpi/adapter/httpclient.rb

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

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

lib/httpi/adapter/net_http.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ def setup_ssl_auth
166166
# Send client-side certificate regardless of state of SSL verify mode
167167
@client.key = ssl.cert_key
168168
@client.cert = ssl.cert
169+
@client.ciphers = ssl.ciphers if ssl.ciphers
169170

170171
@client.verify_mode = ssl.openssl_verify_mode
171172
end

lib/httpi/adapter/net_http_persistent.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ class NetHTTPPersistent < NetHTTP
1212
private
1313

1414
def create_client
15-
Net::HTTP::Persistent.new thread_key
15+
if Gem::Version.new(Net::HTTP::Persistent::VERSION) < Gem::Version.new('3.0.0')
16+
Net::HTTP::Persistent.new thread_key
17+
else
18+
Net::HTTP::Persistent.new name: thread_key
19+
end
1620
end
1721

1822
def perform(http, http_request, &on_body)

lib/httpi/auth/ssl.rb

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,29 @@ def present?
3434
# Accessor for the ca_path to validate SSL certificates.
3535
attr_accessor :ca_cert_path
3636

37-
# ertificate store holds trusted CA certificates used to verify peer certificates.
37+
# Certificate store holds trusted CA certificates used to verify peer certificates.
3838
attr_accessor :cert_store
3939

40+
# Returns the available symmetric algorithms for encryption and decryption.
41+
# @!attribute ciphers
42+
# @return [<String>, nil]
43+
attr_reader :ciphers
44+
45+
# Sets the available symmetric algorithms for encryption and decryption.
46+
# @see OpenSSL::SSL::SSLContext#ciphers
47+
# @example
48+
# ssl.ciphers = "cipher1:cipher2:..."
49+
# ssl.ciphers = [name, ...]
50+
# ssl.ciphers = [[name, version, bits, alg_bits], ...]
51+
def ciphers=(ciphers)
52+
@ciphers =
53+
if ciphers
54+
context = OpenSSL::SSL::SSLContext.new
55+
context.ciphers = ciphers
56+
context.ciphers.map(&:first)
57+
end
58+
end
59+
4060
# Returns the cert type to validate SSL certificates PEM|DER.
4161
def cert_type
4262
@cert_type ||= :pem

spec/httpi/adapter/curb_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@
280280
request.auth.ssl.cert_key_file = "spec/fixtures/client_key.pem"
281281
request.auth.ssl.cert_file = "spec/fixtures/client_cert.pem"
282282
request.auth.ssl.cert_key_password = 'example'
283+
request.auth.ssl.ciphers = OpenSSL::Cipher.ciphers
283284
request
284285
end
285286

0 commit comments

Comments
 (0)