-
Notifications
You must be signed in to change notification settings - Fork 83
Feat: added ssl_supported_protocols option
#131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ae22fcb
Feat: added `ssl_supported_protocols` option
kares f8c703c
test feature
kares eca011b
cleanup
kares b0e1144
Docs + changelog
kares ae37701
Docs: cleanup legacy protocol versions
kares 9462b6f
Docs: document Java 8 behavior
kares 564cc19
Test: refactor support code to spec_helper
kares 8710fba
Test: TLSv1.3 only spec
kares faa6b7e
Docs: more details on potentially using TLSv1.1
kares e0ac258
Test: make sure we can actually test this ...
kares 6043003
Docs: suggestions from code review
kares 3f6b1b8
Test: drop the lambda callback
kares 297f482
Docs: format
kares File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,109 +1,4 @@ | ||
| require "logstash/devutils/rspec/spec_helper" | ||
| require "logstash/outputs/http" | ||
| require "logstash/codecs/plain" | ||
| require "thread" | ||
| require "sinatra" | ||
| require "webrick" | ||
| require "webrick/https" | ||
| require 'openssl' | ||
| require_relative "../supports/compressed_requests" | ||
|
|
||
| PORT = rand(65535-1024) + 1025 | ||
|
|
||
| class LogStash::Outputs::Http | ||
| attr_writer :agent | ||
| attr_reader :request_tokens | ||
| end | ||
|
|
||
| # note that Sinatra startup and shutdown messages are directly logged to stderr so | ||
| # it is not really possible to disable them without reopening stderr which is not advisable. | ||
| # | ||
| # == Sinatra (v1.4.6) has taken the stage on 51572 for development with backup from WEBrick | ||
| # == Sinatra has ended his set (crowd applauds) | ||
| # | ||
| class TestApp < Sinatra::Base | ||
| # on the fly uncompress gzip content | ||
| use CompressedRequests | ||
|
|
||
| set :environment, :production | ||
| set :sessions, false | ||
|
|
||
| @@server_settings = { | ||
| :AccessLog => [], # disable WEBrick logging | ||
| :Logger => WEBrick::BasicLog::new(nil, WEBrick::BasicLog::FATAL) | ||
| } | ||
|
|
||
| def self.server_settings | ||
| @@server_settings | ||
| end | ||
|
|
||
| def self.server_settings=(settings) | ||
| @@server_settings = settings | ||
| end | ||
|
|
||
| def self.multiroute(methods, path, &block) | ||
| methods.each do |method| | ||
| method.to_sym | ||
| self.send method, path, &block | ||
| end | ||
| end | ||
|
|
||
| def self.last_request=(request) | ||
| @last_request = request | ||
| end | ||
|
|
||
| def self.last_request | ||
| @last_request | ||
| end | ||
|
|
||
| def self.retry_fail_count=(count) | ||
| @retry_fail_count = count | ||
| end | ||
|
|
||
| def self.retry_fail_count() | ||
| @retry_fail_count || 2 | ||
| end | ||
|
|
||
| multiroute(%w(get post put patch delete), "/good") do | ||
| self.class.last_request = request | ||
| [200, "YUP"] | ||
| end | ||
|
|
||
| multiroute(%w(get post put patch delete), "/bad") do | ||
| self.class.last_request = request | ||
| [400, "YUP"] | ||
| end | ||
|
|
||
| multiroute(%w(get post put patch delete), "/retry") do | ||
| self.class.last_request = request | ||
|
|
||
| if self.class.retry_fail_count > 0 | ||
| self.class.retry_fail_count -= 1 | ||
| [429, "Will succeed in #{self.class.retry_fail_count}"] | ||
| else | ||
| [200, "Done Retrying"] | ||
| end | ||
| end | ||
| end | ||
|
|
||
| RSpec.configure do | ||
| #http://stackoverflow.com/questions/6557079/start-and-call-ruby-http-server-in-the-same-script | ||
| def start_app_and_wait(app, opts = {}) | ||
| queue = Queue.new | ||
|
|
||
| Thread.start do | ||
| begin | ||
| app.start!({ server: 'WEBrick', port: PORT }.merge opts) do |server| | ||
| queue.push(server) | ||
| end | ||
| rescue => e | ||
| warn "Error starting app: #{e.inspect}" # ignore | ||
| end | ||
| end | ||
|
|
||
| queue.pop # blocks until the start! callback runs | ||
| end | ||
| end | ||
| require File.expand_path('../spec_helper.rb', File.dirname(__FILE__)) | ||
|
|
||
| describe LogStash::Outputs::Http do | ||
| # Wait for the async request to finish in this spinlock | ||
|
|
@@ -520,22 +415,28 @@ def start_app_and_wait(app, opts = {}) | |
| end | ||
| end | ||
|
|
||
| describe LogStash::Outputs::Http do # different block as we're starting web server with TLS | ||
| RSpec.describe LogStash::Outputs::Http do # different block as we're starting web server with TLS | ||
|
|
||
| @@default_server_settings = TestApp.server_settings.dup | ||
|
|
||
| before do | ||
| cert, key = WEBrick::Utils.create_self_signed_cert 2048, [["CN", ssl_cert_host]], "Logstash testing" | ||
| TestApp.server_settings = @@default_server_settings.merge({ | ||
| :SSLEnable => true, | ||
| :SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE, | ||
| :SSLCertificate => cert, | ||
| :SSLPrivateKey => key | ||
| }) | ||
| TestApp.server_settings = @@default_server_settings.merge(webrick_config) | ||
|
|
||
| TestApp.last_request = nil | ||
|
|
||
| @server = start_app_and_wait(TestApp) | ||
| @server = start_app_and_wait(TestApp, &server_setup) | ||
| end | ||
|
|
||
| let(:server_setup) { lambda { |_| } } | ||
kares marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| let(:webrick_config) do | ||
| cert, key = WEBrick::Utils.create_self_signed_cert 2048, [["CN", ssl_cert_host]], "Logstash testing" | ||
| { | ||
| SSLEnable: true, | ||
| SSLVerifyClient: OpenSSL::SSL::VERIFY_NONE, | ||
| SSLCertificate: cert, | ||
| SSLPrivateKey: key | ||
| } | ||
| end | ||
|
|
||
| after do | ||
|
|
@@ -590,4 +491,44 @@ def start_app_and_wait(app, opts = {}) | |
|
|
||
| end | ||
|
|
||
| context 'with supported_protocols set to (disabled) 1.1' do | ||
|
|
||
| let(:config) { super().merge 'ssl_supported_protocols' => ['TLSv1.1'], 'ssl_verification_mode' => 'none' } | ||
|
|
||
| it "keeps retrying due a protocol exception" do # TLSv1.1 not enabled by default | ||
| expect(subject).to receive(:log_failure). | ||
| with('Could not fetch URL', hash_including(message: 'No appropriate protocol (protocol is disabled or cipher suites are inappropriate)')). | ||
| at_least(:once) | ||
| Thread.start { subject.multi_receive [ event ] } | ||
| sleep 1.0 | ||
| end | ||
|
|
||
| end unless tls_version_enabled_by_default?('TLSv1.1') | ||
|
|
||
| context 'with supported_protocols set to 1.2/1.3' do | ||
|
|
||
| let(:config) { super().merge 'ssl_supported_protocols' => ['TLSv1.2', 'TLSv1.3'], 'ssl_verification_mode' => 'none' } | ||
|
|
||
| let(:webrick_config) { super().merge SSLVersion: 'TLSv1.2' } | ||
|
|
||
| it "should process the request" do | ||
| subject.multi_receive [ event ] | ||
| expect(last_request_body).to include '"message":"hello!"' | ||
| end | ||
|
|
||
| end | ||
|
|
||
| context 'with supported_protocols set to 1.3' do | ||
|
|
||
| let(:config) { super().merge 'ssl_supported_protocols' => ['TLSv1.3'], 'ssl_verification_mode' => 'none' } | ||
|
|
||
| let(:webrick_config) { super().merge SSLVersion: 'TLSv1.3' } | ||
|
|
||
| it "should process the request" do | ||
| subject.multi_receive [ event ] | ||
| expect(last_request_body).to include '"message":"hello!"' | ||
| end | ||
|
|
||
| end if tls_version_enabled_by_default?('TLSv1.3') && JOpenSSL::VERSION > '0.12' # due WEBrick uses OpenSSL | ||
|
|
||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| require "logstash/devutils/rspec/spec_helper" | ||
| require "logstash/outputs/http" | ||
| require "logstash/codecs/plain" | ||
|
|
||
| require "thread" | ||
| require "sinatra" | ||
| require "webrick" | ||
| require "webrick/https" | ||
| require 'openssl' | ||
|
|
||
| require "supports/compressed_requests" | ||
|
|
||
| PORT = rand(65535-1024) + 1025 | ||
|
|
||
| class LogStash::Outputs::Http | ||
| attr_writer :agent | ||
| attr_reader :request_tokens | ||
| end | ||
|
|
||
| # NOTE: extend WEBrick with support for config[:SSLVersion] | ||
| WEBrick::GenericServer.class_eval do | ||
| alias_method :__setup_ssl_context, :setup_ssl_context | ||
|
|
||
| def setup_ssl_context(config) | ||
| ctx = __setup_ssl_context(config) | ||
| ctx.ssl_version = config[:SSLVersion] if config[:SSLVersion] | ||
| ctx | ||
| end | ||
|
|
||
| end | ||
|
|
||
| # note that Sinatra startup and shutdown messages are directly logged to stderr so | ||
| # it is not really possible to disable them without reopening stderr which is not advisable. | ||
| # | ||
| # == Sinatra (v1.4.6) has taken the stage on 51572 for development with backup from WEBrick | ||
| # == Sinatra has ended his set (crowd applauds) | ||
| # | ||
| class TestApp < Sinatra::Base | ||
| # on the fly uncompress gzip content | ||
| use CompressedRequests | ||
|
|
||
| set :environment, :production | ||
| set :sessions, false | ||
|
|
||
| @@server_settings = { | ||
| :AccessLog => [], # disable WEBrick logging | ||
| :Logger => WEBrick::BasicLog::new(nil, WEBrick::BasicLog::FATAL) | ||
| } | ||
|
|
||
| def self.server_settings | ||
| @@server_settings | ||
| end | ||
|
|
||
| def self.server_settings=(settings) | ||
| @@server_settings = settings | ||
| end | ||
|
|
||
| def self.multiroute(methods, path, &block) | ||
| methods.each do |method| | ||
| method.to_sym | ||
| self.send method, path, &block | ||
| end | ||
| end | ||
|
|
||
| def self.last_request=(request) | ||
| @last_request = request | ||
| end | ||
|
|
||
| def self.last_request | ||
| @last_request | ||
| end | ||
|
|
||
| def self.retry_fail_count=(count) | ||
| @retry_fail_count = count | ||
| end | ||
|
|
||
| def self.retry_fail_count() | ||
| @retry_fail_count || 2 | ||
| end | ||
|
|
||
| multiroute(%w(get post put patch delete), "/good") do | ||
| self.class.last_request = request | ||
| [200, "YUP"] | ||
| end | ||
|
|
||
| multiroute(%w(get post put patch delete), "/bad") do | ||
| self.class.last_request = request | ||
| [400, "YUP"] | ||
| end | ||
|
|
||
| multiroute(%w(get post put patch delete), "/retry") do | ||
| self.class.last_request = request | ||
|
|
||
| if self.class.retry_fail_count > 0 | ||
| self.class.retry_fail_count -= 1 | ||
| [429, "Will succeed in #{self.class.retry_fail_count}"] | ||
| else | ||
| [200, "Done Retrying"] | ||
| end | ||
| end | ||
| end | ||
|
|
||
| RSpec.configure do |config| | ||
| #http://stackoverflow.com/questions/6557079/start-and-call-ruby-http-server-in-the-same-script | ||
| def start_app_and_wait(app, opts = {}) | ||
| queue = Queue.new | ||
|
|
||
| Thread.start do | ||
| begin | ||
| app.start!({ server: 'WEBrick', port: PORT }.merge opts) do |server| | ||
| yield(server) if block_given? | ||
| queue.push(server) | ||
| end | ||
| rescue => e | ||
| warn "Error starting app: #{e.inspect}" # ignore | ||
| end | ||
| end | ||
|
|
||
| queue.pop # blocks until the start! callback runs | ||
| end | ||
|
|
||
| config.extend(Module.new do | ||
|
|
||
| def tls_version_enabled_by_default?(tls_version) | ||
| begin | ||
| context = javax.net.ssl.SSLContext.getInstance('TLS') | ||
| context.init nil, nil, nil | ||
| context.getDefaultSSLParameters.getProtocols.include? tls_version.to_s | ||
| rescue => e | ||
| warn "#{__method__} failed : #{e.inspect}" | ||
| nil | ||
| end | ||
| end | ||
|
|
||
| end) | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.