Skip to content
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

Fix disabling verifying server certificate #449

Merged
merged 2 commits into from
Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html
### Fixed

- Fix support for older versions of Http.rb ([#438](https://github.com/elastic/apm-agent-ruby/pull/434))
- Fix disabling SSL verification ([#449](https://github.com/elastic/apm-agent-ruby/pull/449))

## 2.8.1 (2019-05-29)

Expand Down
15 changes: 12 additions & 3 deletions lib/elastic_apm/transport/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,20 @@ def build_user_agent(metadata)
].join(' ')
end

def build_ssl_context
return unless @config.use_ssl? && @config.server_ca_cert
def build_ssl_context # rubocop:disable Metrics/MethodLength
return unless @config.use_ssl?

OpenSSL::SSL::SSLContext.new.tap do |context|
context.ca_file = @config.server_ca_cert
if @config.server_ca_cert
context.ca_file = @config.server_ca_cert
end

context.verify_mode =
if @config.verify_server_cert
OpenSSL::SSL::VERIFY_PEER
else
OpenSSL::SSL::VERIFY_NONE
mikker marked this conversation as resolved.
Show resolved Hide resolved
end
end
end
end
Expand Down
37 changes: 37 additions & 0 deletions spec/elastic_apm/transport/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,43 @@ module Transport
end
end

describe 'verify_server_cert' do
let(:config) do
Config.new(server_url: 'https://self-signed.badssl.com')
end

it 'is enabled by default' do
expect(config.logger)
.to receive(:error)
.with(/OpenSSL::SSL::SSLError/)

WebMock.disable!
subject.write('')
subject.flush
WebMock.enable!
end

context 'when disabled' do
let(:config) do
Config.new(
server_url: 'https://self-signed.badssl.com',
verify_server_cert: false
)
end

it "doesn't complain" do
expect(config.logger)
.to_not receive(:error)
.with(/OpenSSL::SSL::SSLError/)

WebMock.disable!
subject.write('')
subject.flush
WebMock.enable!
end
end
end

# rubocop:disable Metrics/MethodLength
def build_stub(body: nil, headers: {}, to_return: {}, status: 202, &block)
opts = {
Expand Down