Search code examples
rubyldapopenldapnetldap

Binding to LDAP with multiple certs. in ruby


I'm using https://github.com/ruby-ldap/ruby-net-ldap gem to connect/bind to LDAP

treebase = "ou=xxxxxx,dc=xxxxx,dc=xx"
credentials = {             
                :username => "myusername,ou=xxxxxx,dc=xxxxx,dc=xx",
                :password => "password"
}
encryption = {
                :method => :simple_tls,
                :tls_options => { :ca_path => "folder/Chain/pem_folder"}
}
# pem_folder = folder that contains multiple pem files

ldap = Net::LDAP.new :host => "hostname.example.com",
     :port => 636,
     :encryption => encryption,
     :base => treebase,
     :auth => credentials

ldap.bind

The above code results in ruby-2.2.2/gems/net-ldap-0.12.1/lib/net/ldap/connection.rb:47:in open_connection': SSL_connect returned=1 errno=0 state=error: certificate verify failed (Net::LDAP::Error)

I have a feeling it has something to do with the multiple certs but not sure.


Solution

  • What worked for me was

    1. Make sure you are connected to VPN if needed to be on the network
    2. follow the instruction here specially the part about rehashing with c_rehash

    3. my username was also missing uid= before which was causing failed binding

    4. Stackoverflow also helped but I used Figaro Gem instead