我試圖連接到需要StartTLS但沒有運氣的LDAP服務器 - 每當我使用SessionOptions.StartTransportLayerSecurity(..)或將SessionOptions.SecureSocketLayer設置爲true時,我得到例外。從System.DirectoryServices使用StartTLS與LDAP
下面是我使用的代碼:
using (var connection = new LdapConnection(new LdapDirectoryIdentifier(config.LdapServer, config.Port, false, false)))
{
connection.SessionOptions.ProtocolVersion = 3;
connection.Credential = new NetworkCredential(config.BindDN, config.BindPassword);
connection.SessionOptions.VerifyServerCertificate += (conn, cert) => {return true;};
connection.AuthType = AuthType.Basic;
//connection.SessionOptions.SecureSocketLayer = true;
connection.SessionOptions.StartTransportLayerSecurity(null); // throws here, same if done after bind.
connection.Bind();
... do stuff with connection
}
產生的例外是「TlsOperationException:出現未知錯誤」,調用StartTransportLayerSecurity方法時發生。
我已經測試了針對OpenLDAP服務器和Active Directory的代碼,但都不起作用。
有誰知道如何讓StartTLS使用System.DirectoryServices?
可否請你指定的OpenLDAP針對特定版本,Active Directory和特別是操作系統*雙向*客戶端和服務器這裏涉及到縮小範圍有多大?過去有相當多的微妙的LDAP堆棧不兼容,這仍然適用於您的客戶可能使用的潛在遺留場景。 – 2012-01-23 11:46:10
斯特芬嗨,信息是OpenLDAP的2.4.18,FreeBSD的服務器和客戶端是在Windows Server 2008 R2的計算機(客戶端代碼中的ASP.Net應用程序託管,.Net框架3.5 SP1)。 在LDAP的版本上進一步搜索,讓我有關於該主題的一些博客文章,包括: http://pongo15.wordpress.com/2009/12/18/on-getting-openldap-and-windows- ldap-to-interop/- 幫助我深入瞭解問題的底部。 我要去嘗試,並鼓勵用戶向上移動到最新的OpenLDAP,因爲我認爲這個問題可能是固定在以後的版本(他們的版本是真的老了,太陽公佈,2009年6月) – Bittercoder 2012-01-26 10:26:16
感謝跟進信息,這將有助於後來的讀者對這樣的問題(+1)!我[更新我的答案](http://stackoverflow.com/posts/9020311/revisions#)相應... – 2012-01-26 15:40:50