Skip to content

Commit 93602bc

Browse files
authored
Merge pull request #168 from galois17/fix-ssl-noverify
Avoid using ssl no verify
2 parents 200b109 + 87064ce commit 93602bc

File tree

4 files changed

+75
-11
lines changed

4 files changed

+75
-11
lines changed

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ language: ruby
22

33
rvm:
44
- "ruby-head"
5+
- "2.7"
56
- "2.4.0"
67
- "2.3"
78
- "2.2"
8-
9+
matrix:
10+
allow_failures:
11+
- rvm: "ruby-head"
912
addons:
1013
code_climate:
1114
repo_token: 8f697ca756250f0c2c54170ae27e8a9c459d18a0236903b11291c88291b3aac9

lib/oauth/consumer.rb

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,21 @@
88
module OAuth
99
class Consumer
1010
# determine the certificate authority path to verify SSL certs
11-
CA_FILES = %W(#{ENV['SSL_CERT_FILE']} /etc/ssl/certs/ca-certificates.crt /etc/pki/tls/certs/ca-bundle.crt /usr/share/curl/curl-ca-bundle.crt)
12-
CA_FILES.each do |ca_file|
13-
if File.exist?(ca_file)
14-
CA_FILE = ca_file
15-
break
11+
if ENV['SSL_CERT_FILE']
12+
if File.exist?(ENV['SSL_CERT_FILE'])
13+
CA_FILE = ENV['SSL_CERT_FILE']
14+
else
15+
raise "The SSL CERT provided does not exist."
16+
end
17+
end
18+
19+
if !defined?(CA_FILE)
20+
CA_FILES = %W(/etc/ssl/certs/ca-certificates.crt /etc/pki/tls/certs/ca-bundle.crt /usr/share/curl/curl-ca-bundle.crt)
21+
CA_FILES.each do |ca_file|
22+
if File.exist?(ca_file)
23+
CA_FILE = ca_file
24+
break
25+
end
1626
end
1727
end
1828
CA_FILE = nil unless defined?(CA_FILE)
@@ -343,12 +353,15 @@ def create_http(_url = nil)
343353

344354
http_object.use_ssl = (our_uri.scheme == 'https')
345355

346-
if @options[:ca_file] || CA_FILE
347-
http_object.ca_file = @options[:ca_file] || CA_FILE
356+
if @options[:no_verify]
357+
http_object.verify_mode = OpenSSL::SSL::VERIFY_NONE
358+
else
359+
ca_file = @options[:ca_file] || CA_FILE
360+
if ca_file
361+
http_object.ca_file = ca_file
362+
end
348363
http_object.verify_mode = OpenSSL::SSL::VERIFY_PEER
349364
http_object.verify_depth = 5
350-
else
351-
http_object.verify_mode = OpenSSL::SSL::VERIFY_NONE
352365
end
353366

354367
http_object.read_timeout = http_object.open_timeout = @options[:timeout] || 30

oauth.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
3232
spec.add_development_dependency("iconv")
3333
spec.add_development_dependency("rack", "~> 2.0")
3434
spec.add_development_dependency("rack-test")
35-
spec.add_development_dependency("mocha", ">= 0.9.12")
35+
spec.add_development_dependency("mocha", ">= 0.9.12", "<=1.1.0")
3636
spec.add_development_dependency("typhoeus", ">= 0.1.13")
3737
spec.add_development_dependency("em-http-request", "0.2.11")
3838
spec.add_development_dependency("curb")

test/units/test_consumer.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,54 @@ def test_getting_tokens_doesnt_add_paths_if_full_url_is_specified
165165
@consumer.get_request_token
166166
end
167167

168+
def test_noverify_true
169+
@consumer = OAuth::Consumer.new(
170+
"key",
171+
"secret",
172+
{
173+
:site => "https://api.mysite.co.nz/v1",
174+
:request_token_url => "https://authentication.mysite.co.nz/Oauth/RequestToken",
175+
:no_verify => true
176+
})
177+
178+
stub_request(:post, "https://authentication.mysite.co.nz/Oauth/RequestToken").to_return(:body => "success", :status => 200)
179+
180+
Net::HTTP.any_instance.expects(:'verify_mode=').with(OpenSSL::SSL::VERIFY_NONE)
181+
182+
@consumer.get_request_token
183+
end
184+
185+
def test_noverify_false
186+
@consumer = OAuth::Consumer.new(
187+
"key",
188+
"secret",
189+
{
190+
:site => "https://api.mysite.co.nz/v1",
191+
:request_token_url => "https://authentication.mysite.co.nz/Oauth/RequestToken",
192+
:no_verify => false
193+
})
194+
195+
stub_request(:post, "https://authentication.mysite.co.nz/Oauth/RequestToken").to_return(:body => "success", :status => 200)
196+
197+
Net::HTTP.any_instance.expects(:'verify_mode=').with(OpenSSL::SSL::VERIFY_PEER)
198+
@consumer.get_request_token
199+
end
200+
201+
def test_noverify_empty
202+
@consumer = OAuth::Consumer.new(
203+
"key",
204+
"secret",
205+
{
206+
:site => "https://api.mysite.co.nz/v1",
207+
:request_token_url => "https://authentication.mysite.co.nz/Oauth/RequestToken"
208+
})
209+
210+
stub_request(:post, "https://authentication.mysite.co.nz/Oauth/RequestToken").to_return(:body => "success", :status => 200)
211+
212+
Net::HTTP.any_instance.expects(:'verify_mode=').with(OpenSSL::SSL::VERIFY_PEER)
213+
@consumer.get_request_token
214+
end
215+
168216
def test_token_request_identifies_itself_as_a_token_request
169217
request_options = {}
170218
@consumer.stubs(:request).returns(create_stub_http_response)

0 commit comments

Comments
 (0)