LocalCertificateSelectionCallback Делегат

Определение

Выбирает локальный сертификат SSL, используемый для проверки подлинности.Selects the local Secure Sockets Layer (SSL) certificate used for authentication.

public delegate System::Security::Cryptography::X509Certificates::X509Certificate ^ LocalCertificateSelectionCallback(System::Object ^ sender, System::String ^ targetHost, X509CertificateCollection ^ localCertificates, X509Certificate ^ remoteCertificate, cli::array <System::String ^> ^ acceptableIssuers);
public delegate System.Security.Cryptography.X509Certificates.X509Certificate LocalCertificateSelectionCallback(object sender, string targetHost, X509CertificateCollection localCertificates, X509Certificate remoteCertificate, string[] acceptableIssuers);
type LocalCertificateSelectionCallback = delegate of obj * string * X509CertificateCollection * X509Certificate * string[] -> X509Certificate
Public Delegate Function LocalCertificateSelectionCallback(sender As Object, targetHost As String, localCertificates As X509CertificateCollection, remoteCertificate As X509Certificate, acceptableIssuers As String()) As X509Certificate 

Параметры

sender
Object

Объект, содержащий сведения о состоянии этой проверки.An object that contains state information for this validation.

targetHost
String

Сервер, указанный клиентом.The host server specified by the client.

localCertificates
X509CertificateCollection

Коллекция X509CertificateCollection, содержащая локальные сертификаты.An X509CertificateCollection containing local certificates.

remoteCertificate
X509Certificate

Сертификат для проверки подлинности удаленной стороны.The certificate used to authenticate the remote party.

acceptableIssuers
String[]

Массив элементов String, определяющий поставщиков сертификатов, приемлемых для удаленной стороны.A String array of certificate issuers acceptable to the remote party.

Возвращаемое значение

X509Certificate

Сертификат X509Certificate, используемый для установки SSL-соединения.An X509Certificate used for establishing an SSL connection.

Наследование
LocalCertificateSelectionCallback

Примеры

В следующем примере кода демонстрируется реализация метода для этого делегата.The following code example demonstrates a method implementation for this delegate.

static X509Certificate^ SelectLocalCertificate(
        Object^ sender, 
        String^ targetHost, 
        X509CertificateCollection^ localCertificates, 
        X509Certificate^ remoteCertificate, 
        array<String^>^ acceptableIssuers
)
{	
    Console::WriteLine("Client is selecting a local certificate.");
    if (acceptableIssuers != nullptr && 
            acceptableIssuers->Length > 0 &&
            localCertificates != nullptr &&
            localCertificates->Count > 0)
    {
        // Use the first certificate that is from an acceptable issuer.
        IEnumerator^ myEnum1 = localCertificates->GetEnumerator();
        while ( myEnum1->MoveNext() )
        {
            X509Certificate^ certificate = safe_cast<X509Certificate^>(myEnum1->Current);
            String^ issuer = certificate->Issuer;
            if ( Array::IndexOf( acceptableIssuers, issuer ) != -1 )
                return certificate;
        }
    }
    if (localCertificates != nullptr &&
            localCertificates->Count > 0)
        return localCertificates[0];
            
    return nullptr;
 }

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;
}

В следующем примере кода демонстрируется создание экземпляра этого делегата.The following code example demonstrates creating an instance of this delegate.

// Server name must match the host name and the name on the host's certificate. 
serverName = args[ 1 ];

// Create a TCP/IP client socket.
TcpClient^ client = gcnew TcpClient( serverName,80 );
Console::WriteLine( L"Client connected." );

// Create an SSL stream that will close the client's stream.
SslStream^ sslStream = gcnew SslStream( 
    client->GetStream(),
    false,
    gcnew RemoteCertificateValidationCallback( ValidateServerCertificate ),
    gcnew LocalCertificateSelectionCallback( SelectLocalCertificate ) );

// 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,80);
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.This delegate is used to construct instances of the SslStream class. Класс SslStream используется для защиты обмена данными между клиентом и сервером.The SslStream class is used to help secure information exchanged between a client and server. Клиент и сервер используют этот делегат для выбора сертификата, который будет использоваться для проверки подлинности.The client and server use this delegate to select a certificate to be used for authentication.

Методы расширения

GetMethodInfo(Delegate)

Получает объект, представляющий метод, представленный указанным делегатом.Gets an object that represents the method represented by the specified delegate.

Применяется к

Дополнительно