-
Notifications
You must be signed in to change notification settings - Fork 251
SSL hostname verification support #262
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ def prepare_socket(server) | |
encryption = server[:encryption] | ||
|
||
@conn = socket | ||
setup_encryption encryption if encryption | ||
setup_encryption({ verify_host: server[:connected_host] }.merge(encryption)) if encryption | ||
end | ||
|
||
def open_connection(server) | ||
|
@@ -50,7 +50,7 @@ def open_connection(server) | |
errors = [] | ||
hosts.each do |host, port| | ||
begin | ||
prepare_socket(server.merge(socket: @socket_class.new(host, port, socket_opts))) | ||
prepare_socket(server.merge(socket: @socket_class.new(host, port, socket_opts), connected_host: host)) | ||
return | ||
rescue Net::LDAP::Error, SocketError, SystemCallError, | ||
OpenSSL::SSL::SSLError => e | ||
|
@@ -88,6 +88,13 @@ def self.wrap_with_ssl(io, tls_options = {}) | |
conn = OpenSSL::SSL::SSLSocket.new(io, ctx) | ||
conn.connect | ||
|
||
if tls_options[:verify_host] | ||
# This raises OpenSSL::SSL::SSLError if hostname verification fails | ||
conn.post_connection_check(tls_options[:verify_host]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A previously undocumented (until I documented it) method it is very important to call if you want your SSL connections to be secure! |
||
else | ||
warn "not verifying SSL hostname of LDAP server" | ||
end | ||
|
||
# Doesn't work: | ||
# conn.sync_close = true | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this does verification by default unless explicitly disabled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tarcieri, sorry I'm not really much of a ruby dev, so I may misunderstand a bit. I assume any non nil value in a conditional returns false... so users must explicitly enable verification in config with
:encryption = { :method => :simple_tls, :tls_options => { :verify_host => true } }
?If I understand correctly,
:encryption => { :method => :simple_tls, :tls_options => { :verify_mode => OpenSSL::SSL::VERIFY_PEER, :tls_options[:verify_host] => false} }
should imply checking that the cert is at least signed by a trusted CA, but allowing for a mismatch?What happens if the user has simply put
{ :method => :simple_tls, :tls_options => { :verify_mode => OpenSSL::SSL::VERIFY_PEER }
?The match function will not run if tls_options[:verify_host] is nil? Hence I thought that your pull doesn't do hostname validation unless the user explicitly configures it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is passing the hostname through as
verify_host
, unless the user has setverify_host
to something else.It's a bit convoluted, but it's on by default, and enables the user to opt-out.
I would agree having a separate user targeted flag would make sense, but you don't seem to be understanding how this code is working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tarcieri, thanks, got it now. I cloned your fork and tested
:verify_host => false
(with valid variables set for my env). It bumps into an error.Can you provide some config examples?
Also, testing my own pull, I noticed that the CI build will fail if it actually checks the hostname by default because the CI test suite has a cert mismatched resulting in
So that implies your pull doesn't match the hostname by default because the CI build succeeded. I had the same confusing issue with my attempted fix.