LocalCertificateSelectionCallback Delegat

Definition

Wählt das für die Authentifizierung verwendete SSL (Secure Sockets Layer)-Remotezertifikat aus.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 

Parameter

sender
Object

Ein Objekt mit Zustandsinformationen für diese Validierung.An object that contains state information for this validation.

targetHost
String

Der vom Client angegebene Hostserver.The host server specified by the client.

localCertificates
X509CertificateCollection

Eine X509CertificateCollection mit lokalen Zertifikaten.An X509CertificateCollection containing local certificates.

remoteCertificate
X509Certificate

Das zum Authentifizieren der Remoteseite verwendete Zertifikat.The certificate used to authenticate the remote party.

acceptableIssuers
String[]

Ein String-Array der Zertifikatsaussteller, die von der Remoteseite akzeptiert werden können.A String array of certificate issuers acceptable to the remote party.

Rückgabewert

X509Certificate

Ein X509Certificate, das zum Herstellen einer SSL-Verbindung verwendet wird.An X509Certificate used for establishing an SSL connection.

Vererbung
LocalCertificateSelectionCallback

Beispiele

Im folgenden Codebeispiel wird eine Methoden Implementierung für diesen Delegaten veranschaulicht.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;
}

Im folgenden Codebeispiel wird das Erstellen einer Instanz dieses Delegaten veranschaulicht.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)
    );

Hinweise

Dieser Delegat wird verwendet, um Instanzen der SslStream -Klasse zu erstellen.This delegate is used to construct instances of the SslStream class. Die SslStream -Klasse wird verwendet, um die zwischen einem Client und einem Server ausgetauschten Informationen zu sichern.The SslStream class is used to help secure information exchanged between a client and server. Der Client und der Server verwenden diesen Delegaten, um ein Zertifikat auszuwählen, das für die Authentifizierung verwendet werden soll.The client and server use this delegate to select a certificate to be used for authentication.

Erweiterungsmethoden

GetMethodInfo(Delegate)

Ruft ein Objekt ab, das die Methode darstellt, die vom angegebenen Delegaten dargestellt wird.Gets an object that represents the method represented by the specified delegate.

Gilt für:

Siehe auch