Hi @S Abijith , Welcome to Microsoft Q&A,
System.DirectoryServices.Protocols.LdapConnection
in .NET does not allow to directly check if the server has mTLS enabled.
If you have access to the LDAP server, you can check if mTLS is enabled by checking the server's configuration. Usually the server configuration file explicitly sets whether client certificate verification is enabled.
The only convenient way may be to use exception detection and send a test without a certificate before you send it. You can send the certificate after getting the target error.
If the server has mTLS enabled and the client does not provide a certificate, an exception will usually be thrown. You can infer whether mTLS is enabled by handling the exception. For example, when a client connects to an mTLS-enabled server and does not provide a certificate, an AuthenticationException
or similar SSL error will usually be thrown.
try
{
ldapConnection.Bind(nc);
}
catch (AuthenticationException authEx)
{
// Catch TLS handshake failure, possibly because client certificate not provided
if (authEx.Message.Contains("required client certificate"))
{
// Server requires client certificate, mTLS may be enabled
Console.WriteLine("Server requires client certificate. mTLS may be enabled.");
}
else
{
// Other authentication issues
Console.WriteLine("Authentication failed: " + authEx.Message);
}
}
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.