And*_*rew 5 ssl directoryservices ldap active-directory edirectory
我有一个应用程序使用典型的System.DirectoryServices.DirectoryEntry代码从目录服务复制数据.我现在需要使用带有自签名证书的SSL从Novell eDirectory复制.我怀疑现有代码可以使用可以验证的有效证书,或者可能是将自签名证书添加到本地计算机密钥库.但是为了确保使用自签名证书,我能找到的唯一解决方案是使用System.DirectoryServices.Protocols命名空间和LdapConnection类,从而可以连接VerifyServerCertificate回调.我找不到任何方法将相同的概念应用于DirectoryEntry实例,或连接到LdapConnection实例并以某种方式"转换"到DirectoryEntry实例.也许这是不可能的,我只想确认一下.欢迎任何其他想法.
我发现的唯一相关链接是:http://www.codeproject.com/Articles/19097/eDirectory-Authentication-using-LdapConnection-and
这是一个非凡的问题.
我几天来一直在与同一个问题作斗争,我终于得到了一些明确的证据,说明为什么DirectoryEntry对象在这种情况下不起作用.
此特定Ldap服务器(在LDAPS 636上运行)也会发出自己的自签名证书.使用LdapConnection(并通过Wireshark监控流量),我注意到在使用DirectoryEntry时不会发生握手:
第一个序列来自安全的ldap服务器,第二个序列来自我的机器.提示第二个序列的代码是:
ldapConnection.SessionOptions.VerifyServerCertificate += delegate { return true; };
Run Code Online (Sandbox Code Playgroud)
还有其他方法来"假装"回调,但这是我一直在使用的.
遗憾的是,DirectoryEntry没有用于验证自签名证书的选项或方法,因此永远不会接受证书(第二个序列),并且连接无法初始化.
实现此目的的唯一可行方法是使用LdapConnection,结合SearchRequest和SearchResponse.这是我到目前为止所得到的:
LdapConnection ldapConnection = new LdapConnection("xxx.xxx.xxx:636");
var networkCredential = new NetworkCredential("Hey", "There", "Guy");
ldapConnection.SessionOptions.SecureSocketLayer = true;
ldapConnection.SessionOptions.VerifyServerCertificate += delegate { return true; };
ldapConnection.AuthType = AuthType.Negotiate;
ldapConnection.Bind(networkCredential);
SearchRequest request = new SearchRequest("DC=xxx,DC=xxx,DC=xxx", "(sAMAccountName=3074861)", SearchScope.Subtree);
SearchResponse response = (SearchResponse)ldapConnection.SendRequest(request);
if(response.Entries.Count == 1)
{SearchResultEntry entry = response.Entries[0];
string DN = entry.DistinguishedName;}
Run Code Online (Sandbox Code Playgroud)
从那里,您可以从SearchResponse收集AD属性,并进行相应处理.尽管如此,这是一个完全无赖,因为SearchRequest似乎比使用DirectoryEntry要慢得多.
希望这可以帮助!
归档时间: |
|
查看次数: |
4917 次 |
最近记录: |