16
16
begin
17
17
require 'openssl'
18
18
rescue LoadError
19
- abort "Oh no! Your Ruby doesn't have OpenSSL, so it can't connect to #{ host } . " \
20
- "You'll need to recompile or reinstall Ruby with OpenSSL support and try again."
19
+ puts "Oh no! Your Ruby doesn't have OpenSSL, so it can't connect to #{ host } ." ,
20
+ "You'll need to recompile or reinstall Ruby with OpenSSL support and try again."
21
+ exit 1
21
22
end
22
23
23
24
begin
32
33
end
33
34
34
35
uri = URI ( "https://#{ host } " )
35
- ssl_version = ARGV . shift
36
+ tls_version = ARGV . shift
36
37
verify_mode = ARGV . any? ? OpenSSL ::SSL . const_get ( ARGV . shift ) : OpenSSL ::SSL ::VERIFY_PEER
37
38
38
39
if defined? ( RUBY_DESCRIPTION )
46
47
47
48
puts "" , "Here's your Ruby and OpenSSL environment:"
48
49
puts
49
- puts "Ruby: %s" % ruby_version
50
- puts "RubyGems: %s" % Gem ::VERSION if defined? ( Gem ::VERSION )
51
- puts "Bundler: %s" % Bundler ::VERSION if defined? ( Bundler ::VERSION )
52
- puts "Compiled with: %s" % OpenSSL ::OPENSSL_VERSION
53
- puts "Loaded version: %s" % OpenSSL ::OPENSSL_LIBRARY_VERSION if defined? ( OpenSSL ::OPENSSL_LIBRARY_VERSION )
54
- puts "SSL_CERT_FILE: %s" % OpenSSL ::X509 ::DEFAULT_CERT_FILE
55
- puts "SSL_CERT_DIR: %s" % OpenSSL ::X509 ::DEFAULT_CERT_DIR
56
- puts
57
- puts "With that out of the way, let's see if you can connect to #{ host } ..."
50
+ puts "Ruby: %s" % ruby_version
51
+ puts "RubyGems: %s" % Gem ::VERSION if defined? ( Gem ::VERSION )
52
+ puts "Bundler: %s" % Bundler ::VERSION if defined? ( Bundler ::VERSION )
53
+ puts "OpenSSL: %s" % OpenSSL ::VERSION if defined? ( OpenSSL ::VERSION )
54
+ puts "Compiled with: %s" % OpenSSL ::OPENSSL_VERSION
55
+ puts "Loaded with: %s" % OpenSSL ::OPENSSL_LIBRARY_VERSION if defined? ( OpenSSL ::OPENSSL_LIBRARY_VERSION )
58
56
puts
59
57
58
+ def show_ssl_certs
59
+ puts "" , "Below affect only Ruby net/http connections:"
60
+ puts
61
+ t = ENV [ 'SSL_CERT_FILE' ] || OpenSSL ::X509 ::DEFAULT_CERT_FILE
62
+ ssl_file = if Dir . exist? t
63
+ "✅ exists #{ t } "
64
+ elsif RUBY_PLATFORM . end_with? 'linux'
65
+ t = '/etc/ssl/certs/ca-certificates.crt'
66
+ Dir . exist? ( t ) ? "✅ exists #{ t } " : "❌ is missing #{ t } "
67
+ else
68
+ "❌ is missing #{ t } "
69
+ end
70
+ puts "SSL_CERT_FILE: %s" % ssl_file
71
+
72
+ t = ENV [ 'SSL_CERT_DIR' ] || OpenSSL ::X509 ::DEFAULT_CERT_DIR
73
+ ssl_dir = Dir . exist? ( t ) ? "✅ exists #{ t } " : "❌ is missing #{ t } "
74
+ puts "SSL_CERT_DIR: %s" % ssl_dir
75
+ puts
76
+ end
77
+
60
78
def error_reason ( error )
61
79
case error . message
62
80
when /certificate verify failed/
@@ -70,80 +88,86 @@ def error_reason(error)
70
88
end
71
89
end
72
90
91
+ puts "Trying connections to #{ uri . to_s } :"
92
+ puts
73
93
begin
74
94
b_uri = defined? ( Bundler ::URI ) ? Bundler ::URI ( uri . to_s ) : uri
75
95
Bundler ::Fetcher . new ( Bundler ::Source ::Rubygems ::Remote . new ( b_uri ) ) . send ( :connection ) . request ( b_uri )
76
- bundler_status = "success ✅ "
96
+ bundler_status = "✅ success "
77
97
rescue => error
78
- bundler_status = "failed ❌ (#{ error_reason ( error ) } )"
98
+ bundler_status = "❌ failed (#{ error_reason ( error ) } )"
79
99
end
80
- puts "Bundler connection to #{ host } : #{ bundler_status } "
100
+ puts "Bundler: #{ bundler_status } "
81
101
82
102
begin
83
103
require 'rubygems/remote_fetcher'
84
104
Gem ::RemoteFetcher . fetcher . fetch_path ( uri )
85
- rubygems_status = "success ✅ "
105
+ rubygems_status = "✅ success "
86
106
rescue => error
87
- rubygems_status = "failed ❌ (#{ error_reason ( error ) } )"
107
+ rubygems_status = "❌ failed (#{ error_reason ( error ) } )"
88
108
end
89
- puts "RubyGems connection to #{ host } : #{ rubygems_status } "
109
+ puts "RubyGems: #{ rubygems_status } "
90
110
91
111
begin
92
112
# Try to connect using HTTPS
93
113
Net ::HTTP . new ( uri . host , uri . port ) . tap do |http |
94
114
http . use_ssl = true
95
- if ssl_version
115
+ if tls_version
96
116
if http . respond_to? :min_version=
97
- vers = ssl_version . sub ( "v" , "" ) . to_sym
117
+ vers = tls_version . sub ( "v" , "" ) . to_sym
98
118
http . min_version = vers
99
119
http . max_version = vers
100
120
else
101
- http . ssl_version = ssl_version . to_sym
121
+ http . ssl_version = tls_version . to_sym
102
122
end
103
123
end
104
124
http . verify_mode = verify_mode
105
125
end . start
106
126
107
- puts "Ruby net/http connection to #{ host } : success ✅ "
127
+ puts "Ruby net/http: ✅ success "
108
128
puts
109
129
rescue => error
110
- puts "Ruby net/http connection to #{ host } : failed ❌ "
130
+ puts "Ruby net/http: ❌ failed "
111
131
puts
112
132
puts "Unfortunately, this Ruby can't connect to #{ host } . 😡"
113
133
114
134
case error . message
115
135
# Check for certificate errors
116
136
when /certificate verify failed/
117
- abort "Your Ruby can't connect to #{ host } because you are missing the certificate\n " \
118
- "files OpenSSL needs to verify you are connecting to the genuine #{ host } servers."
137
+ show_ssl_certs
138
+ puts "\n Your Ruby can't connect to #{ host } because you are missing the certificate" ,
139
+ "files OpenSSL needs to verify you are connecting to the genuine #{ host } servers." , ""
119
140
# Check for TLS version errors
120
141
when /read server hello A/ , /tlsv1 alert protocol version/
121
- if ssl_version == "TLSv1_3"
122
- abort "Your Ruby can't connect to #{ host } because #{ ssl_version } isn't supported yet."
142
+ if tls_version == "TLSv1_3"
143
+ puts " \n Your Ruby can't connect to #{ host } because #{ tls_version } isn't supported yet.\n \n "
123
144
else
124
- abort "Your Ruby can't connect to #{ host } because your version of OpenSSL is too old.\n " \
125
- "You'll need to upgrade your OpenSSL install and/or recompile Ruby to use a newer OpenSSL."
145
+ puts " \n Your Ruby can't connect to #{ host } because your version of OpenSSL is too old." ,
146
+ "You'll need to upgrade your OpenSSL install and/or recompile Ruby to use a newer OpenSSL." , " "
126
147
end
148
+ # OpenSSL doesn't support TLS version specified by argument
149
+ when /unknown SSL method/
150
+ puts "\n Your Ruby can't connect because #{ tls_version } isn't supported by your version of OpenSSL.\n \n "
127
151
else
128
- puts "Even worse, we're not sure why. 😕"
152
+ puts "\n Even worse, we're not sure why. 😕"
129
153
puts
130
- puts "Here's the full error information:"
131
- puts "#{ error . class } : #{ error . message } "
132
- puts " " << error . backtrace . join ( "\n " )
154
+ puts "Here's the full error information:" ,
155
+ "#{ error . class } : #{ error . message } " ,
156
+ " #{ error . backtrace . join ( "\n " ) } "
133
157
puts
134
- puts "You might have more luck using Mislav's SSL doctor.rb script. You can get it here:"
135
- puts "https://github.com/mislav/ssl-tools/blob/8b3dec4/doctor.rb"
136
- puts "Read more about the script and how to use it in this blog post:"
137
- puts "https://mislav.net/2013/07/ruby-openssl/"
138
- abort
158
+ puts "You might have more luck using Mislav's SSL doctor.rb script. You can get it here:" ,
159
+ "https://github.com/mislav/ssl-tools/blob/8b3dec4/doctor.rb" ,
160
+ "Read more about the script and how to use it in this blog post:" ,
161
+ "https://mislav.net/2013/07/ruby-openssl/" , ""
139
162
end
163
+ exit 1
140
164
end
141
165
142
166
guide_url = "http://ruby.to/ssl-check-failed"
143
167
if bundler_status =~ /success/ && rubygems_status =~ /success/
144
168
# Whoa, it seems like it's working!
145
169
puts "Hooray! This Ruby can connect to #{ host } ." ,
146
- "You are all set to use Bundler and RubyGems. 👌" , ""
170
+ "You are all set to use Bundler and RubyGems. 👌" , ""
147
171
elsif rubygems_status !~ /success/
148
172
puts "It looks like Ruby and Bundler can connect to #{ host } , but RubyGems itself" ,
149
173
"cannot. You can likely solve this by manually downloading and installing a" ,
@@ -156,9 +180,9 @@ def error_reason(error)
156
180
"check out the troubleshooting guide at #{ guide_url } 📦"
157
181
else
158
182
puts "For some reason, your Ruby installation can connect to #{ host } , but neither" ,
159
- "RubyGems nor Bundler can. The most likely fix is to manually upgrade RubyGems by" ,
160
- "following the instructions at #{ guide_url } . After you've done that, run `gem install" ,
161
- "bundler` to upgrade Bundler, and then run this script again to make sure everything worked. ❣️"
183
+ "RubyGems nor Bundler can. The most likely fix is to manually upgrade RubyGems by" ,
184
+ "following the instructions at #{ guide_url } . After you've done that, run `gem install" ,
185
+ "bundler` to upgrade Bundler, and then run this script again to make sure everything worked. ❣️"
162
186
end
163
187
164
188
def tls12_supported?
@@ -174,10 +198,9 @@ def tls12_supported?
174
198
175
199
# We were able to connect, but perhaps this Ruby will have trouble when we require TLSv1.2
176
200
unless tls12_supported?
177
- puts
178
- puts "WARNING: Although your Ruby can connect to #{ host } today, your OpenSSL is very old! 👴"
179
- puts "WARNING: You will need to upgrade OpenSSL to use #{ host } ."
180
- abort
201
+ puts "\n WARNING: Although your Ruby can connect to #{ host } today, your OpenSSL is very old! 👴" ,
202
+ "WARNING: You will need to upgrade OpenSSL to use #{ host } ."
203
+ exit 1
181
204
end
182
205
183
206
exit 0
0 commit comments