Skip to content

Commit bdd30a7

Browse files
committed
(PUP-10889) Handle ruby < 2.5
Ruby didn't define the OpenSSL::SSL::TLS1_VERSION constant until 2.5 and the `SSLContext#min_version=` wasn't supported.
1 parent 5d039ed commit bdd30a7

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

lib/puppet/network/http/factory.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def create_connection(site)
2828
http = Puppet::Util::HttpProxy.proxy(URI(site.addr))
2929
http.use_ssl = site.use_ssl?
3030
if site.use_ssl?
31-
http.min_version = OpenSSL::SSL::TLS1_VERSION
31+
http.min_version = OpenSSL::SSL::TLS1_VERSION if http.respond_to?(:min_version)
3232
http.ciphers = Puppet[:ciphers]
3333
end
3434
http.read_timeout = Puppet[:http_read_timeout]

lib/puppet/util/monkey_patches.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ def daemonize
3232
# (#19151) Reject all SSLv2 ciphers and handshakes
3333
require 'puppet/ssl/openssl_loader'
3434
unless Puppet::Util::Platform.jruby_fips?
35+
unless defined?(OpenSSL::SSL::TLS1_VERSION)
36+
module OpenSSL::SSL
37+
# see https://github.com/ruby/ruby/commit/609103dbb5fb182eec12f052226c43e39b907682#diff-09f822c26289f5347111795ca22ed7ed1cfadd6ebd28f987991d1d414eef565aR2755-R2759
38+
OpenSSL::SSL::TLS1_VERSION = 0x301
39+
end
40+
end
41+
3542
class OpenSSL::SSL::SSLContext
3643
if DEFAULT_PARAMS[:options]
3744
DEFAULT_PARAMS[:options] |= OpenSSL::SSL::OP_NO_SSLv2 | OpenSSL::SSL::OP_NO_SSLv3

spec/integration/http/client_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@
159159
https_server.start_server do |port|
160160
expect {
161161
client.get(URI("https://127.0.0.1:#{port}"), options: {ssl_context: root_context})
162-
}.to raise_error(Puppet::HTTP::ConnectionError, /no cipher match/)
162+
}.to raise_error(Puppet::HTTP::ConnectionError, /no cipher match|sslv3 alert handshake failure/)
163163
end
164164
end
165165
end

spec/unit/network/http/factory_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def create_connection(site)
146146
end
147147

148148
context 'tls' do
149-
it "sets the minimum version to TLS 1.0" do
149+
it "sets the minimum version to TLS 1.0", if: RUBY_VERSION.to_f >= 2.5 do
150150
conn = create_connection(site)
151151
expect(conn.min_version).to eq(OpenSSL::SSL::TLS1_VERSION)
152152
end

0 commit comments

Comments
 (0)