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 SSL Subject regression in server mode #199

Merged
merged 3 commits into from
Oct 12, 2022

Conversation

yaauie
Copy link
Contributor

@yaauie yaauie commented Mar 29, 2022

Alters the TCP#decode_buffer signature to accept the ssl subject instead of
expecting a ruby socket, so that it can be interoperable between the ruby-based
client mode and the netty-powered server mode.

In server mode, the SSL subject is extracted once when initializing the
connection IFF SSL is enabled and verification is turned on.

Co-authored-by: Will Weber [email protected]
Closes: #159

Alters the TCP#decode_buffer signature to accept the _ssl subject_ instead of
expecting a ruby socket, so that it can be interoperable between the ruby-based
client mode and the netty-powered server mode.

In server mode, the SSL subject is extracted _once_ when initializing the
connection IFF SSL is enabled and verification is turned on.

Co-authored-by: Will Weber <[email protected]>
Closes: logstash-plugins#159
@yaauie yaauie force-pushed the restore-missing-ssl-subject branch from 77c63f8 to 9c643c8 Compare April 4, 2022 15:19
@yaauie yaauie requested a review from kares May 3, 2022 18:13
Copy link
Contributor

@kares kares left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what the old format was but it would be nice to use the same (RFC) format.
otherwise the formats are different (the RFC format is cleaner IMHO) :

  • Ruby "/OU=foo bar; please fix your client./CN=sample.name"
  • Java "CN=sample.name,OU=foo bar\\; please fix your client."

def extract_sslsubject(channel)
return nil unless @tcp.ssl_enable && @tcp.ssl_verify

channel.pipeline().get("ssl-handler").engine().getSession().getPeerPrincipal().getName()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
channel.pipeline().get("ssl-handler").engine().getSession().getPeerPrincipal().getName()
channel.pipeline().get("ssl-handler").engine.getSession.getPeerCertificates[0].getSubjectX500Principal.getName

return nil unless @tcp.ssl_enable && @tcp.ssl_verify

channel.pipeline().get("ssl-handler").engine().getSession().getPeerPrincipal().getName()
rescue Exception => e
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not use the anti-pattern or rescuing everything

Suggested change
rescue Exception => e
rescue java.lang.Exception

also might be worth logging the exception at least on the debug level

def handle_socket(socket)
client_address = socket.peeraddr[3]
client_ip_address = socket.peeraddr[2]
client_port = socket.peeraddr[1]

# Client mode sslsubject extraction, server mode happens in DecoderImpl#decode
ssl_subject = socket.peer_cert.subject.to_s if @ssl_enable && @ssl_verify
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ssl_subject = socket.peer_cert.subject.to_s if @ssl_enable && @ssl_verify
ssl_subject = socket.peer_cert.subject.to_s(OpenSSL::X509::Name::RFC2253) if @ssl_enable && @ssl_verify

@yaauie yaauie merged commit 3663173 into logstash-plugins:main Oct 12, 2022
@yaauie yaauie deleted the restore-missing-ssl-subject branch October 12, 2022 05:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants