Skip to content

tolerate absence of certificate when enabling ssl #36

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 1 commit into from
Jan 2, 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 5.0.4
- Removed requirement to have a certificate/key pair when enabling ssl

## 5.0.3
- Docs: Set the default_codec doc attribute.

Expand Down
8 changes: 6 additions & 2 deletions lib/logstash/outputs/tcp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,12 @@ def setup_ssl
require "openssl"

@ssl_context = OpenSSL::SSL::SSLContext.new
@ssl_context.cert = OpenSSL::X509::Certificate.new(File.read(@ssl_cert))
@ssl_context.key = OpenSSL::PKey::RSA.new(File.read(@ssl_key),@ssl_key_passphrase)
if @ssl_cert
@ssl_context.cert = OpenSSL::X509::Certificate.new(File.read(@ssl_cert))
if @ssl_key
@ssl_context.key = OpenSSL::PKey::RSA.new(File.read(@ssl_key),@ssl_key_passphrase)
end
end
if @ssl_verify
@cert_store = OpenSSL::X509::Store.new
# Load the system default certificate path to the store
Expand Down
3 changes: 2 additions & 1 deletion logstash-output-tcp.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|

s.name = 'logstash-output-tcp'
s.version = '5.0.3'
s.version = '5.0.4'
s.licenses = ['Apache License (2.0)']
s.summary = "Writes events over a TCP socket"
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
Expand All @@ -26,5 +26,6 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'stud'

s.add_development_dependency 'logstash-devutils'
s.add_development_dependency 'flores'
end

32 changes: 32 additions & 0 deletions spec/outputs/tcp_spec.rb
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
require "logstash/devutils/rspec/spec_helper"
require "logstash/outputs/tcp"
require "flores/pki"

describe LogStash::Outputs::Tcp do
subject { described_class.new(config) }
let(:config) { {
"host" => "localhost",
"port" => 2000 + rand(3000),
} }

context "when enabling SSL" do
let(:config) { super.merge("ssl_enable" => true) }
context "and not providing a certificate/key pair" do
it "registers without error" do
expect { subject.register }.to_not raise_error
end
end
context "and providing a certificate/key pair" do
let(:cert_key_pair) { Flores::PKI.generate }
let(:certificate) { cert_key_pair.first }
let(:cert_file) do
path = Tempfile.new('foo').path
IO.write(path, certificate.to_s)
path
end
let(:config) { super.merge("ssl_cert" => true, "ssl_cert" => cert_file) }
it "registers without error" do
expect { subject.register }.to_not raise_error
end
end
end
end