2017-06-29 83 views
1

我設立這是由我們的生產服務器的虛擬機克隆的測試環境。我擁有一個IP(位於管理程序)後面的所有克隆,並使用NAT(Linux)訪問測試環境中的服務。如何讓Ruby Net/Ldap忽略服務器證書主機名不匹配?

我有我的測試實例中的IP名爲「test.internal.com」 DNS記錄。當我想聯繫「測試」 LDAP服務器,我可以在命令行發出ldapsearch檢索信息(此成功OK)。

現在我想連接到測試實例時,我連接到測試不過我的Ruby應用程序,林心如說:hostname "test.internal.com" does not match the server certificate (Net::LDAP::Error)。顯然這是真的,因爲我的LDAP服務器上的證書未配置爲test.internal.com

我是否需要爲我的LDAP服務器獲得一個新的證書,並使用替代名稱test.internal.com或者有什麼方法可以讓Ruby忽略該問題?我發現OpenSSL::SSL::VERIFY_NONEtls_options,但它似乎並不奏效。

#!/usr/bin/ruby 

require 'net/ldap' 
require 'io/console' 
require 'highline/import' 

ldapHost = 'test.internal.com' 
ldapPort = '8389' 
baseDn = "dc=internal,dc=com" 

user = gets 
username = "uid=" + user + ',ou=users,dc=internal,dc=com' 
password = ask("Password: ") { |q| q.echo = "*" } 

ldap_con = Net::LDAP.new ({ :host => ldapHost, 
           :port => ldapPort, 
           :base => baseDn, 
           :encryption => :start_tls, tls_options: { verify_mode: OpenSSL::SSL::VERIFY_NONE }, 
           :auth => { :method => :simple, :username => username, :password => password } 
          }) 

op_filter = Net::LDAP::Filter.eq("objectClass", "posixGroup") 

ldap_con.search(:base => baseDn, :filter => op_filter, :attributes=> 'dn') do |entry| 
    puts "DN: #{entry.dn}" 
end 

回答

0

而不是使用:

verify_mode: OpenSSL::SSL::VERIFY_NONE 

使用:

verify_mode: "VERIFY_NONE" 

,你會被設定。

相關問題