Skip to content

Add SNI support for Google Secure LDAP #405

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
jpdasma opened this issue Jun 7, 2022 · 0 comments
Closed

Add SNI support for Google Secure LDAP #405

jpdasma opened this issue Jun 7, 2022 · 0 comments

Comments

@jpdasma
Copy link
Contributor

jpdasma commented Jun 7, 2022

Using net/ldap with ldap.google.com:636:

require 'net/ldap'

ldap = Net::LDAP.new  :host => 'ldap.google.com',
                      :port => 636,
                      :encryption => :simple_tls,
                      :auth => {
                        :method => :simple,
                        :username => 'test',
                        :password => 'test',
                      }

will result in this error:

`open_connection': hostname "ldap.google.com" does not match the server certificate (Net::LDAP::Error)

This is because of Google Secure LDAP's behavior: https://support.google.com/a/answer/9190869?hl=en

The Secure LDAP service requires a TLS client that supports and initiates a TLS session using SNI (Server Name Indication). If the TLS client does not support SNI, then the TLS server (ldap.google.com) returns a self-signed certificate that will not pass CA validation checks, to indicate that SNI is required.

To use SNI we have to add a call to conn.hostname in this part of the code (before calling conn.connect): https://github.com/ruby-ldap/ruby-net-ldap/blob/master/lib/net/ldap/connection.rb#L98

I tested this by hard coding conn.hostname to ldap.google.com:

@@ -95,6 +95,7 @@
     ctx.set_params(tls_options) unless tls_options.empty?

     conn = OpenSSL::SSL::SSLSocket.new(io, ctx)
+    conn.hostname = "ldap.google.com"

     begin
       if timeout

This fixed the error with regards to the certificate.

I'm planning on submitting a PR for this, but I figured I might open an issue first to see if I didn't miss anything.

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

No branches or pull requests

1 participant