Skip to content

Commit 44b089b

Browse files
committed
fix some verify_mode edge cases
1 parent 143abf6 commit 44b089b

File tree

3 files changed

+66
-12
lines changed

3 files changed

+66
-12
lines changed

lib/logstash/inputs/http.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,14 @@ def validate_ssl_settings!
191191
raise LogStash::ConfigurationError, "Certificate or JKS must be configured"
192192
end
193193

194-
if @ssl && original_params.key?("verify_mode")
195-
if original_params.key?("ssl_verify_mode")
194+
if @ssl && (original_params.key?("verify_mode") && original_params.key?("ssl_verify_mode"))
196195
raise LogStash::ConfigurationError, "Both 'ssl_verify_mode' and 'verify_mode' were set. Use only 'ssl_verify_mode'."
197-
end
196+
elsif original_params.key?("verify_mode")
197+
@ssl_verify_mode_final = @verify_mode
198+
elsif original_params.key?("ssl_verify_mode")
199+
@ssl_verify_mode_final = @ssl_verify_mode
200+
else
201+
@ssl_verify_mode_final = @ssl_verify_mode
198202
end
199203

200204
if @ssl && require_certificate_authorities? && !client_authentication?
@@ -213,11 +217,9 @@ def build_ssl_params
213217
return nil unless @ssl
214218

215219
ssl_builder = nil
216-
verify_mode_string = nil
217220

218221
if @keystore && @keystore_password
219222
ssl_builder = org.logstash.plugins.inputs.http.util.JksSslBuilder.new(@keystore, @keystore_password.value)
220-
verify_mode_string = @verify_mode.upcase if original_params.key?("verify_mode")
221223
else
222224
begin
223225
ssl_builder = org.logstash.plugins.inputs.http.util.SslSimpleBuilder.new(@ssl_certificate, @ssl_key, @ssl_key_passphrase.nil? ? nil : @ssl_key_passphrase.value)
@@ -227,14 +229,13 @@ def build_ssl_params
227229
end
228230

229231
if client_authentication?
230-
verify_mode_string = @ssl_verify_mode.upcase
231232
ssl_builder.setCertificateAuthorities(@ssl_certificate_authorities)
232233
end
233234
end
234235

235236
ssl_context = ssl_builder.build()
236237
ssl_handler_provider = org.logstash.plugins.inputs.http.util.SslHandlerProvider.new(ssl_context)
237-
ssl_handler_provider.setVerifyMode(verify_mode_string)
238+
ssl_handler_provider.setVerifyMode(@ssl_verify_mode_final.upcase)
238239
ssl_handler_provider.setProtocols(convert_protocols)
239240
ssl_handler_provider.setHandshakeTimeoutMilliseconds(@ssl_handshake_timeout)
240241

@@ -254,7 +255,7 @@ def client_authentication?
254255
end
255256

256257
def require_certificate_authorities?
257-
@ssl_verify_mode == "force_peer" || @ssl_verify_mode == "peer"
258+
@ssl_verify_mode_final == "force_peer" || @ssl_verify_mode_final == "peer"
258259
end
259260

260261
def normalized_ciphers

spec/inputs/http_spec.rb

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
require "zlib"
77
require "stringio"
88

9+
java_import "io.netty.handler.ssl.util.SelfSignedCertificate"
10+
911
describe LogStash::Inputs::Http do
1012

1113
before do
@@ -355,15 +357,65 @@
355357
end
356358
end
357359
context "with :ssl_certificate" do
358-
let(:ssl_certificate) { Stud::Temporary.file }
359-
let(:ssl_key) { Stud::Temporary.file }
360+
let(:ssc) { SelfSignedCertificate.new }
361+
let(:ssl_certificate) { ssc.certificate }
362+
let(:ssl_key) { ssc.private_key }
363+
364+
after(:each) { ssc.delete }
365+
360366
subject { LogStash::Inputs::Http.new("port" => port, "ssl" => true,
361367
"ssl_certificate" => ssl_certificate.path,
362368
"ssl_key" => ssl_key.path) }
363369
it "should not raise exception" do
364-
expect(subject).to receive(:build_ssl_params)
365370
expect { subject.register }.to_not raise_exception
366371
end
372+
373+
context "with ssl_verify_mode = none" do
374+
subject { LogStash::Inputs::Http.new("port" => port, "ssl" => true,
375+
"ssl_certificate" => ssl_certificate.path,
376+
"ssl_key" => ssl_key.path,
377+
"ssl_verify_mode" => "none"
378+
) }
379+
it "should not raise exception" do
380+
expect { subject.register }.to_not raise_exception
381+
end
382+
end
383+
["peer", "force_peer"].each do |verify_mode|
384+
context "with ssl_verify_mode = #{verify_mode}" do
385+
subject { LogStash::Inputs::Http.new("port" => port, "ssl" => true,
386+
"ssl_certificate" => ssl_certificate.path,
387+
"ssl_certificate_authorities" => ssl_certificate.path,
388+
"ssl_key" => ssl_key.path,
389+
"ssl_verify_mode" => verify_mode
390+
) }
391+
it "should not raise exception" do
392+
expect { subject.register }.to_not raise_exception
393+
end
394+
end
395+
end
396+
context "with verify_mode = none" do
397+
subject { LogStash::Inputs::Http.new("port" => port, "ssl" => true,
398+
"ssl_certificate" => ssl_certificate.path,
399+
"ssl_key" => ssl_key.path,
400+
"verify_mode" => "none"
401+
) }
402+
it "should not raise exception" do
403+
expect { subject.register }.to_not raise_exception
404+
end
405+
end
406+
["peer", "force_peer"].each do |verify_mode|
407+
context "with verify_mode = #{verify_mode}" do
408+
subject { LogStash::Inputs::Http.new("port" => port, "ssl" => true,
409+
"ssl_certificate" => ssl_certificate.path,
410+
"ssl_certificate_authorities" => ssl_certificate.path,
411+
"ssl_key" => ssl_key.path,
412+
"verify_mode" => verify_mode
413+
) }
414+
it "should not raise exception" do
415+
expect { subject.register }.to_not raise_exception
416+
end
417+
end
418+
end
367419
end
368420
end
369421
end

src/main/java/org/logstash/plugins/inputs/http/util/SslHandlerProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ public class SslHandlerProvider {
1313

1414
private final static Logger logger = LogManager.getLogger(SslSimpleBuilder.class);
1515
private final SslContext sslContext;
16-
private SslClientVerifyMode verifyMode = SslClientVerifyMode.FORCE_PEER;
16+
private SslClientVerifyMode verifyMode = SslClientVerifyMode.NONE;
1717
private long handshakeTimeoutMilliseconds = 10000;
1818

1919
enum SslClientVerifyMode {
2020
VERIFY_PEER,
2121
FORCE_PEER,
22+
NONE
2223
}
2324

2425
private String[] protocols = new String[] { "TLSv1.2" };

0 commit comments

Comments
 (0)