Ошибка сервера LDAP при использовании аутентификации LDAPS - PullRequest
0 голосов
/ 19 февраля 2020
string username = "username";
var con = new LdapConnection(new LdapDirectoryIdentifier(ADUtilities.LDAPServer, Convert.ToInt32(ADUtilities.LDAPPort), false, false));
con.SessionOptions.SecureSocketLayer = true;
con.SessionOptions.ProtocolVersion = 3;
var clientCertificateFile = new X509Certificate();
clientCertificateFile.Import(ADUtilities.LDAPSSLCertificatePath);
con.ClientCertificates.Add(clientCertificateFile);
con.SessionOptions.VerifyServerCertificate = new VerifyServerCertificateCallback(VerifyServerCertificate); }

con.Credential = new NetworkCredential(username, ADPassword);
con.AuthType = AuthType.Negotiate;
con.Timeout = new TimeSpan(0, 1, 0);
con.Bind();
private bool VerifyServerCertificate(LdapConnection ldapConnection, X509Certificate certificate) {
    X509Certificate2 certificate2 = new X509Certificate2(certificate);
    return certificate2.Verify();
}

Ошибка в строке con.bind (), что сервер LDAP недоступен. Тот же код работает нормально с портом 389, но не с 636, т.е. LDAPS

...