LocalCertificateSelectionCallback LocalCertificateSelectionCallback LocalCertificateSelectionCallback LocalCertificateSelectionCallback Delegate

Definizione

Seleziona il certificato SSL (Secure Sockets Layer) locale utilizzato per l'autenticazione.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 

Parametri

sender
Object Object Object Object

Oggetto contenente le informazioni di stato per la convalida.An object that contains state information for this validation.

targetHost
String String String String

Server host specificato dal client.The host server specified by the client.

remoteCertificate
X509Certificate X509Certificate X509Certificate X509Certificate

Certificato utilizzato per autenticare la parte remota.The certificate used to authenticate the remote party.

acceptableIssuers
String[]

Matrice String di autorità emittenti di certificati accettabili per la parte remota.A String array of certificate issuers acceptable to the remote party.

Valore restituito

System.Security.Cryptography.X509Certificates.X509Certificate

Classe X509Certificate utilizzata per stabilire una connessione SSL.An X509Certificate used for establishing an SSL connection.

Ereditarietà
LocalCertificateSelectionCallbackLocalCertificateSelectionCallbackLocalCertificateSelectionCallbackLocalCertificateSelectionCallback

Esempi

Nell'esempio di codice seguente viene illustrata l'implementazione di un metodo per questo delegato.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;
}

Nell'esempio di codice riportato di seguito viene illustrata la creazione di un'istanza di questo delegato.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)
    );

Commenti

Questo delegato viene utilizzato per costruire istanze della SslStream classe.This delegate is used to construct instances of the SslStream class. La SslStream classe viene usata per proteggere le informazioni scambiate tra un client e un server.The SslStream class is used to help secure information exchanged between a client and server. Il client e il server utilizzano questo delegato per selezionare un certificato da utilizzare per l'autenticazione.The client and server use this delegate to select a certificate to be used for authentication.

Metodi di estensione

GetMethodInfo(Delegate) GetMethodInfo(Delegate) GetMethodInfo(Delegate) GetMethodInfo(Delegate)

Ottiene un oggetto che rappresenta il metodo rappresentato dal delegato specificato.Gets an object that represents the method represented by the specified delegate.

Si applica a

Vedi anche