TLSv1.2、および.NET Framework 4.5.2または4.6.2でLDAPを使用してActiveDirectoryを照会したいですが(両方とも問題があります)。問題は、「ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12」を使用していても、TLSv1.0を使用しようとし続けていることです。c#とTLSv1.2を使用してLDAPに接続
「System.DirectoryServices.Protocols」はTLSv1.2上でLDAPを照会するために使用できるパッケージですか?もしそうなら、そのTLSバージョンを有効にする適切な方法は何ですか?
は最終的に、私は、Web API 2コントローラからこれを実行したいのですが、問題を再現する簡単なテストとして、私は次のコンソールアプリケーションを持っている:
using System;
using System.Diagnostics;
using System.DirectoryServices.Protocols;
using System.Net;
namespace Ldap
{
class Program
{
private const string ldapHost = "169.254.212.120";
private const int ldapPort = 30389; // normally just 389
private const int ldapSslPort = 30636; // normally just 636
private const bool sslEnabled = true;
private const string userBaseDistinguishedName = "dc=example,dc=org";
private const string bindUserCommonName = "admin";
private const string bindUserDistinguishedName = "cn=admin,dc=example,dc=org";
private const string bindUserPassword = "admin";
static void Main(string[] args)
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
using (LdapConnection connection = CreateConnection())
{
try
{
connection.Bind();
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
}
}
}
private static LdapConnection CreateConnection()
{
var directoryIdentifier = new LdapDirectoryIdentifier(ldapHost,
sslEnabled ? ldapSslPort : ldapPort, true, false);
var credential = new NetworkCredential(bindUserDistinguishedName, bindUserPassword);
var conn = new LdapConnection(directoryIdentifier, credential, AuthType.Basic);
conn.SessionOptions.SecureSocketLayer = sslEnabled;
conn.SessionOptions.ProtocolVersion = 3; // Use LDAPv3 (otherwise it appears to default to LDAPv2)
return conn;
}
}
}
サーバーでは、私がテストですこれはOpenLdapドッカーコンテナ(標準ポートではなくポート30389と30636が公開されています)を使用しますが、最終的にはこのコードを使用して& query ActiveDirectoryを接続します。
テストLDAPサーバーを立って、私は(ドッカー17.06 CE)を使用することが起こる:
docker run --name test_ldap -p 0.0.0.0:30636:636 -p 0.0.0.0:30389:389 --env LDAP_TLS_CIPHER_SUITE="SECURE256:+SECURE128:-VERS-TLS-ALL:+VERS-TLS1.2:-RSA:-DHE-DSS:-CAMELLIA-128-CBC:-CAMELLIA-256-CBC" --env LDAP_TLS_VERIFY_CLIENT="allow" --hostname example.org --detach osixia/openldap:1.1.7
はまた、Wiresharkの実行:Wiresharkの中で見られるトラフィックこんにちは「クライアント内の「バージョン」ことを示していパケットは「TLS 1.0(0x0301)」です。
オープンLDAPサーバーのショー内のログ:
59810624 conn=1002 fd=16 ACCEPT from IP=172.17.0.1:44606 (IP=0.0.0.0:636)
TLS: can't accept: An unknown public key algorithm was encountered..
59810624 conn=1002 fd=16 closed (TLS negotiation failure)
私はあなたがすでにこの1を見ている可能性が推測をhttp://blogs.perficient.com/microsoft/2016/04/ tsl-1-2-and-net-support /あなたがそうでなかった場合のために –
ねえ、私はそれを好きな人と見てきました。私はTLS1.2が動作するバージョン(.NET 4.6.2)を試しましたが、4.5回避策 "ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12"も試しました。どちらのアプローチもLDAPでは使えないようです。 –