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

Identification algorithm #208

Closed
wants to merge 2 commits into from
Closed
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 @@
## 6.3.2
- Fix: provide SSL engine with advisory peer and algorithm information [207](https://github.com/logstash-plugins/logstash-input-tcp/issues/207)

## 6.3.1
- Fixes a regression in which the ssl_subject was missing for SSL-secured connections in server mode [#199](https://github.com/logstash-plugins/logstash-input-tcp/pull/199)

Expand Down
5 changes: 3 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ end

task :vendor => :install_jars

Rake::Task["test"].clear
task :test do
require 'rspec'
require 'rspec/core/runner'
Rake::Task[:install_jars].invoke
sh './gradlew test'
exit(RSpec::Core::Runner.run(Rake::FileList['spec/**/*_spec.rb']))
sh(%{./gradlew test}) { |ok,res| exit(res) unless ok }
exit(RSpec::Core::Runner.run(%w(--format documentation).concat(Rake::FileList['spec/**/*_spec.rb'])))
end
16 changes: 10 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ repositories {
dependencies {
testImplementation 'org.apache.logging.log4j:log4j-core:2.17.1'

implementation 'io.netty:netty-all:4.1.65.Final'
implementation 'io.netty:netty-all:4.1.68.Final'
implementation group: 'commons-io', name: 'commons-io', version: '2.8.0' // used from Netty
compileOnly 'org.apache.logging.log4j:log4j-api:2.17.1' // provided by Logstash
compileOnly group: 'org.jruby', name: 'jruby-complete', version: "9.1.13.0" // provided by Logstash
Expand All @@ -57,9 +57,12 @@ task generateGemJarRequiresFile {
jars_file.newWriter().withWriter { w ->
w << "# AUTOGENERATED BY THE GRADLE SCRIPT. DO NOT EDIT.\n\n"
w << "require \'jar_dependencies\'\n"
configurations.runtimeClasspath.allDependencies.each {
w << "require_jar(\'${it.group}\', \'${it.name}\', \'${it.version}\')\n"
}
configurations.runtimeClasspath.resolvedConfiguration.resolvedArtifacts
.collect {it.owner}
.sort { it.group }
.each {
w << "require_jar(\'${it.group}\', \'${it.name}\', \'${it.version}\')\n"
}
w << "\nrequire_jar(\'${project.group}\', \'${project.name}\', \'${project.version}\')\n"
}
}
Expand All @@ -68,8 +71,9 @@ task generateGemJarRequiresFile {
task vendor {
doLast {
String vendorPathPrefix = "vendor/jar-dependencies"
configurations.runtimeClasspath.allDependencies.each { dep ->
File f = configurations.runtimeClasspath.filter { it.absolutePath.contains("${dep.group}/${dep.name}/${dep.version}") }.singleFile
configurations.runtimeClasspath.resolvedConfiguration.resolvedArtifacts.each { artifact ->
ModuleVersionIdentifier dep = artifact.owner
File f = artifact.file
String groupPath = dep.group.replaceAll('\\.', '/')
File newJarFile = file("${vendorPathPrefix}/${groupPath}/${dep.name}/${dep.version}/${dep.name}-${dep.version}.jar")
newJarFile.mkdirs()
Expand Down
2 changes: 1 addition & 1 deletion spec/inputs/tcp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def get_port
aggregate_failures("event #{i}") do
expect(event.get("message")).to eq("#{i} ☹")
expect(event.get(ecs_select[disabled: "host", v1: "[@metadata][input][tcp][source][name]"])).to eq("localhost").or eq("ip6-localhost")
expect(event.get(ecs_select[disabled: "[@metadata][ip_address]", v1: "[@metadata][input][tcp][source][ip]"])).to eq('127.0.0.1')
expect(event.get(ecs_select[disabled: "[@metadata][ip_address]", v1: "[@metadata][input][tcp][source][ip]"])).to eq('127.0.0.1').or eq("0:0:0:0:0:0:0:1")
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def build_certificate(root_ca, root_key, name, password=nil)
key = ( root_key.nil? ? OpenSSL::PKey::RSA.new(2048) : root_key )
options = { :serial => 2, :subject => "/DC=org/DC=ruby-lang/CN=Ruby#{name}", :key => key, :issuer => root_ca.subject}
cert = new_certificate(options)
add_ca_extensions(cert, nil, root_ca)
add_ca_extensions(cert, nil, root_ca, %w(IP:127.0.0.1 IP:0:0:0:0:0:0:0:1))
if password
key_text = key.to_pem(OpenSSL::Cipher::AES256.new(:CFB), password)
[ cert.sign(key, OpenSSL::Digest::SHA256.new), key, key_text ]
Expand Down Expand Up @@ -120,7 +120,7 @@ def new_certificate(options)
cert
end

def add_ca_extensions(certificate, subject=nil, issuer=nil)
def add_ca_extensions(certificate, subject=nil, issuer=nil, san_list=[])
factory = OpenSSL::X509::ExtensionFactory.new
factory.subject_certificate = (subject.nil? ? certificate : subject)
factory.issuer_certificate = (issuer.nil? ? certificate : issuer)
Expand All @@ -129,6 +129,7 @@ def add_ca_extensions(certificate, subject=nil, issuer=nil)
certificate.add_extension(factory.create_extension("keyUsage","keyCertSign, cRLSign, digitalSignature", true))
certificate.add_extension(factory.create_extension("subjectKeyIdentifier","hash",false))
certificate.add_extension(factory.create_extension("authorityKeyIdentifier","keyid:always",false))
certificate.add_extension(factory.create_extension('subjectAltName', san_list.join(','))) unless san_list.empty?
end

end
21 changes: 20 additions & 1 deletion src/main/java/org/logstash/tcp/InputLoop.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.SslHandler;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLParameters;
import java.io.Closeable;
import java.io.IOException;
import java.net.InetSocketAddress;
Expand Down Expand Up @@ -134,7 +137,7 @@ protected void initChannel(final SocketChannel channel) throws Exception {

// if SSL is enabled, the SSL handler must be added to the pipeline first
if (sslContext != null) {
channel.pipeline().addLast(SSL_HANDLER, sslContext.newHandler(channel.alloc()));
channel.pipeline().addLast(SSL_HANDLER, newSslHandler(channel));
}

channel.pipeline().addLast(new DecoderAdapter(localCopy, logger));
Expand All @@ -145,6 +148,22 @@ protected void initChannel(final SocketChannel channel) throws Exception {
}
}

private SslHandler newSslHandler(final SocketChannel socketChannel) {
final InetSocketAddress remoteAddress = socketChannel.remoteAddress();
final String peerHost = remoteAddress.getHostString();
final int peerPort = remoteAddress.getPort();
final SslHandler sslHandler = sslContext.newHandler(socketChannel.alloc(), peerHost, peerPort);

final SSLEngine engine = sslHandler.engine();
engine.setUseClientMode(false);

final SSLParameters sslParameters = engine.getSSLParameters();
sslParameters.setEndpointIdentificationAlgorithm("HTTPS");
engine.setSSLParameters(sslParameters);

return sslHandler;
}

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
logger.error("Error in Netty input handler: " + cause);
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.3.1
6.3.2