Код: Выделить всё
LDAPModel message = new LDAPModel();
string ldapServer = ConfigurationManager.AppSettings["LDAP_host"];
string adminUsername = ConfigurationManager.AppSettings["LDAP_admin_username"];
string adminPassword = ConfigurationManager.AppSettings["LDAP_admin_password"];
int ldapPort = 636; //389
string UsersDN = "ou=users,o=data";
LdapConnection ldapConnection = null;
errorMessage = string.Empty;
try
{
// Log: Attempting to create connection
Log("Creating LDAP connection to server: " + ldapServer + " on port: " + ldapPort);
if (CreateConnection(ref ldapConnection, ldapServer, ldapPort, adminUsername, adminPassword))
{
Log("LDAP connection created successfully. Attempting to bind with admin credentials.");
try
{
ldapConnection.Bind();
Log("Admin bind successful.");
}
catch (LdapException ex)
{
message.STATUS = false;
message.VALUE = "Admin bind failed: " + ex.Message +
"\nError Code: " + ex.ErrorCode +
"\nServer Message: " + ex.ServerErrorMessage;
if (ldapConnection != null)
{
ldapConnection.Dispose();
}
return message;
}
}
}
private bool CreateConnection(ref LdapConnection con, string server, int port, string username, string password) //this is for port 636
{
try
{
//System.Net.ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
con = new LdapConnection(new LdapDirectoryIdentifier(server, port));
con.SessionOptions.SecureSocketLayer = true;
con.SessionOptions.VerifyServerCertificate = (connection, certificate) => true;
// con.SessionOptions.VerifyServerCertificate = new VerifyServerCertificateCallback(ServerCallBack);
con.SessionOptions.ProtocolVersion = 3;
con.AuthType = AuthType.Basic;
con.Credential = new NetworkCredential(username, password);
return true;
}
catch (LdapException)
{
return false;
}
catch (Exception)
{
return false;
}
}
private bool CreateConnectionWithoutCert(ref LdapConnection con, string server, int port, string username, string password)//this is test for port 389
{
try
{
con = new LdapConnection(new LdapDirectoryIdentifier(server, port));
// ⚠️ Do not use SSL or StartTLS
con.SessionOptions.SecureSocketLayer = false;
// ⚠️ Do not use StartTLS — leave this out
// con.SessionOptions.StartTransportLayerSecurity(null);
con.SessionOptions.ProtocolVersion = 3;
con.AuthType = AuthType.Basic;
con.Credential = new NetworkCredential(username, password);
return true;
}
catch (LdapException)
{
return false;
}
catch (Exception)
{
return false;
}
}
private bool ServerCallBack(LdapConnection connection, X509Certificate certificate)
{
return true;
}
< /code>
Я показал вам соответствующие части кода. Принципал, пароль и имя хоста поступают из файла web.config
con.SessionOptions.StartTransportLayerSecurity(null);
< /code>
Bind Fake, и я получаю эту ошибку: < /p>
Проверьте учетные данные LDAP < /p>
< /blockquote>
Проблема - порт 636, привязка сохраняет неудачу, и я продолжает получать: < /p>
add ward ind wath wath wath wath: < /p>
недоступно. < /p>
< /blockquote>
Вещи, которые я пробовал: < /p>
[*] telnet в порт 636, и порт показывает, что его открытый < /p>
< /li>
У меня есть сертификат, который был сертификат, а другой - сертификат, а другой - сертификат, а другой - сертификат, а другой - сертификат, а другой - сертификат, и другой - сертификат. CERTLM и CERTMGR как надежного корня, так и личного
[*] Приложение использует только TLS 1.2, потому что это старый
Каталог Apache был использован для подключения к серверу к порту. /> < /li>
Я использовал Wireshark на сервере, и показывает, что клиент Hello был отправлен из приложения, и он показал, что это был TLS 1.2 < /p>
< /li>
< /ul>
Я хочу найти корень проблемы, это из -за сертификатов? Я попросил команду LDAP дать мне полную цепочку сертификатов, но они сказали, что сертификат, подписанный, уже достаточно. Это из -за TLS 1.2? Есть ли код, который мне не хватает? Я не могу понять, как подключиться к порту 636.
Подробнее здесь: https://stackoverflow.com/questions/797 ... n-port-636