英語で読む

次の方法で共有


LocalCertificateSelectionCallback 代理人

定義

認証に使用するローカルの SSL (Secure Sockets Layer) 証明書を選択します。

C#
public delegate System.Security.Cryptography.X509Certificates.X509Certificate? LocalCertificateSelectionCallback(object sender, string targetHost, X509CertificateCollection localCertificates, X509Certificate? remoteCertificate, string[] acceptableIssuers);
C#
public delegate System.Security.Cryptography.X509Certificates.X509Certificate LocalCertificateSelectionCallback(object sender, string targetHost, X509CertificateCollection localCertificates, X509Certificate? remoteCertificate, string[] acceptableIssuers);
C#
public delegate System.Security.Cryptography.X509Certificates.X509Certificate LocalCertificateSelectionCallback(object sender, string targetHost, X509CertificateCollection localCertificates, X509Certificate remoteCertificate, string[] acceptableIssuers);

パラメーター

sender
Object

この検証のステータス情報を格納するオブジェクト。

targetHost
String

クライアントが指定したホスト サーバー。

localCertificates
X509CertificateCollection

ローカルの証明書を格納している X509CertificateCollection

remoteCertificate
X509Certificate

リモート側の認証に使用される証明書。

acceptableIssuers
String[]

リモート側が受け入れることのできる証明書発行者の String 配列。

戻り値

SSL 接続の確立に使用する X509Certificate

次のコード例は、このデリゲートのメソッド実装を示しています。

C#
public static X509Certificate SelectLocalCertificate(
    object sender,
    string targetHost,
    X509CertificateCollection localCertificates,
    X509Certificate remoteCertificate,
    string[] acceptableIssuers)
{	
    Console.WriteLine("Client is selecting a local certificate.");
    if (acceptableIssuers != null &&
        acceptableIssuers.Length > 0 &&
        localCertificates != null &&
        localCertificates.Count > 0)
    {
        // Use the first certificate that is from an acceptable issuer.
        foreach (X509Certificate certificate in localCertificates)
        {
            string issuer = certificate.Issuer;
            if (Array.IndexOf(acceptableIssuers, issuer) != -1)
                return certificate;
        }
    }
    if (localCertificates != null &&
        localCertificates.Count > 0)
        return localCertificates[0];

    return null;
}

次のコード例では、このデリゲートのインスタンスを作成する方法を示します。

C#
// Server name must match the host name and the name on the host's certificate.
serverName = args[0];
// Create a TCP/IP client socket.
TcpClient client = new TcpClient(serverName,5000);
Console.WriteLine("Client connected.");
// Create an SSL stream that will close the client's stream.
SslStream sslStream = new SslStream(
    client.GetStream(),
    false,
    new RemoteCertificateValidationCallback (ValidateServerCertificate),
    new LocalCertificateSelectionCallback(SelectLocalCertificate)
    );

注釈

このデリゲートは、 クラスのインスタンスを構築するために使用されます SslStream 。 クラスは SslStream 、クライアントとサーバーの間で交換される情報をセキュリティで保護するために使用されます。 クライアントとサーバーは、このデリゲートを使用して、認証に使用する証明書を選択します。

拡張メソッド

GetMethodInfo(Delegate)

指定したデリゲートによって表されるメソッドを表すオブジェクトを取得します。

適用対象

製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

こちらもご覧ください