Skip to content

Commit 54ce056

Browse files
committed
tolerate absense of certificate when enabling ssl
1 parent 6c12f38 commit 54ce056

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 5.0.4
2+
- Removed requirement to have a certificate/key pair when enabling ssl
3+
14
## 5.0.3
25
- Docs: Set the default_codec doc attribute.
36

lib/logstash/outputs/tcp.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,12 @@ def setup_ssl
8585
require "openssl"
8686

8787
@ssl_context = OpenSSL::SSL::SSLContext.new
88-
@ssl_context.cert = OpenSSL::X509::Certificate.new(File.read(@ssl_cert))
89-
@ssl_context.key = OpenSSL::PKey::RSA.new(File.read(@ssl_key),@ssl_key_passphrase)
88+
if @ssl_cert
89+
@ssl_context.cert = OpenSSL::X509::Certificate.new(File.read(@ssl_cert))
90+
if @ssl_key
91+
@ssl_context.key = OpenSSL::PKey::RSA.new(File.read(@ssl_key),@ssl_key_passphrase)
92+
end
93+
end
9094
if @ssl_verify
9195
@cert_store = OpenSSL::X509::Store.new
9296
# Load the system default certificate path to the store

logstash-output-tcp.gemspec

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Gem::Specification.new do |s|
22

33
s.name = 'logstash-output-tcp'
4-
s.version = '5.0.3'
4+
s.version = '5.0.4'
55
s.licenses = ['Apache License (2.0)']
66
s.summary = "Writes events over a TCP socket"
77
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"
@@ -26,5 +26,6 @@ Gem::Specification.new do |s|
2626
s.add_runtime_dependency 'stud'
2727

2828
s.add_development_dependency 'logstash-devutils'
29+
s.add_development_dependency 'flores'
2930
end
3031

spec/outputs/tcp_spec.rb

+32
Original file line numberDiff line numberDiff line change
@@ -1 +1,33 @@
11
require "logstash/devutils/rspec/spec_helper"
2+
require "logstash/outputs/tcp"
3+
require "flores/pki"
4+
5+
describe LogStash::Outputs::Tcp do
6+
subject { described_class.new(config) }
7+
let(:config) { {
8+
"host" => "localhost",
9+
"port" => 2000 + rand(3000),
10+
} }
11+
12+
context "when enabling SSL" do
13+
let(:config) { super.merge("ssl_enable" => true) }
14+
context "and not providing a certificate/key pair" do
15+
it "registers without error" do
16+
expect { subject.register }.to_not raise_error
17+
end
18+
end
19+
context "and providing a certificate/key pair" do
20+
let(:cert_key_pair) { Flores::PKI.generate }
21+
let(:certificate) { cert_key_pair.first }
22+
let(:cert_file) do
23+
path = Tempfile.new('foo').path
24+
IO.write(path, certificate.to_s)
25+
path
26+
end
27+
let(:config) { super.merge("ssl_cert" => true, "ssl_cert" => cert_file) }
28+
it "registers without error" do
29+
expect { subject.register }.to_not raise_error
30+
end
31+
end
32+
end
33+
end

0 commit comments

Comments
 (0)