File tree Expand file tree Collapse file tree 3 files changed +57
-20
lines changed Expand file tree Collapse file tree 3 files changed +57
-20
lines changed Original file line number Diff line number Diff line change 2929puts "Ruby: %s" % ruby_version
3030puts "RubyGems: %s" % Gem ::VERSION if defined? ( Gem ::VERSION )
3131puts "Bundler: %s" % Bundler ::VERSION if defined? ( Bundler ::VERSION )
32-
33- def tls12_supported?
34- ctx = OpenSSL ::SSL ::SSLContext . new
35- if ctx . methods . include? ( :min_version= )
36- ctx . min_version = ctx . max_version = OpenSSL ::SSL ::TLS1_2_VERSION
37- true
38- else
39- OpenSSL ::SSL ::SSLContext ::METHODS . include? ( :TLSv1_2 )
40- end
41- rescue
42- end
43-
44- # We were able to connect, but perhaps this Ruby will have trouble when we require TLSv1.2
45- unless tls12_supported?
46- puts "\n WARNING: Although your Ruby can connect to #{ host } today, your OpenSSL is very old! 👴" ,
47- "WARNING: You will need to upgrade OpenSSL to use #{ host } ."
48- exit 1
49- end
50-
51- exit 0
Original file line number Diff line number Diff line change @@ -105,6 +105,7 @@ def net_http_connection_successful?
105105 end . start
106106
107107 Bundler . ui . info ( "Ruby net/http: success" )
108+ warn_on_unsupported_tls12
108109
109110 true
110111 rescue StandardError => error
@@ -119,6 +120,28 @@ def net_http_connection_successful?
119120 false
120121 end
121122
123+ def warn_on_unsupported_tls12
124+ ctx = OpenSSL ::SSL ::SSLContext . new
125+ supported = true
126+
127+ if ctx . respond_to? ( :min_version= )
128+ begin
129+ ctx . min_version = ctx . max_version = OpenSSL ::SSL ::TLS1_2_VERSION
130+ rescue OpenSSL ::SSL ::SSLError , NameError
131+ supported = false
132+ end
133+ else
134+ supported = OpenSSL ::SSL ::SSLContext ::METHODS . include? ( :TLSv1_2 ) # rubocop:disable Naming/VariableNumber
135+ end
136+
137+ Bundler . ui . warn ( <<~EOM ) unless supported
138+
139+ WARNING: Although your Ruby can connect to #{ host } today, your OpenSSL is very old!
140+ WARNING: You will need to upgrade OpenSSL to use #{ host } .
141+
142+ EOM
143+ end
144+
122145 module Explanation
123146 extend self
124147
Original file line number Diff line number Diff line change @@ -334,5 +334,39 @@ def connect
334334 expect ( net_http . min_version . to_s ) . to eq ( "TLS1_3" )
335335 expect ( net_http . max_version . to_s ) . to eq ( "TLS1_3" )
336336 end
337+
338+ it "warns when TLS1.2 is not supported" do
339+ expected_out = <<~MSG
340+ Here's your OpenSSL environment:
341+
342+ OpenSSL: #{ OpenSSL ::VERSION }
343+ Compiled with: #{ OpenSSL ::OPENSSL_VERSION }
344+ Loaded with: #{ OpenSSL ::OPENSSL_LIBRARY_VERSION }
345+
346+ Trying connections to https://rubygems.org:
347+ Bundler: success
348+ RubyGems: success
349+ Ruby net/http: success
350+
351+ Hooray! This Ruby can connect to rubygems.org.
352+ You are all set to use Bundler and RubyGems.
353+
354+ MSG
355+
356+ expected_err = <<~MSG
357+
358+ WARNING: Although your Ruby can connect to rubygems.org today, your OpenSSL is very old!
359+ WARNING: You will need to upgrade OpenSSL to use rubygems.org.
360+
361+ MSG
362+
363+ previous_version = OpenSSL ::SSL ::TLS1_2_VERSION
364+ OpenSSL ::SSL . send ( :remove_const , :TLS1_2_VERSION )
365+
366+ subject = Bundler ::CLI ::Doctor ::SSL . new ( { } )
367+ expect { subject . run } . to output ( expected_out ) . to_stdout . and output ( expected_err ) . to_stderr
368+ ensure
369+ OpenSSL ::SSL . const_set ( :TLS1_2_VERSION , previous_version )
370+ end
337371 end
338372end
You can’t perform that action at this time.
0 commit comments