LocalCertificateSelectionCallback Delegate
Selects the local Secure Sockets Layer (SSL) certificate used for authentication.
Assembly: System (in System.dll)
'Declaration Public Delegate Function LocalCertificateSelectionCallback ( _ sender As Object, _ targetHost As String, _ localCertificates As X509CertificateCollection, _ remoteCertificate As X509Certificate, _ acceptableIssuers As String() _ ) As X509Certificate 'Usage Dim instance As New LocalCertificateSelectionCallback(AddressOf HandlerMethod)
Parameters
- sender
- Type: System.Object
An object that contains state information for this validation.
- targetHost
- Type: System.String
The host server specified by the client.
- localCertificates
- Type: System.Security.Cryptography.X509Certificates.X509CertificateCollection
An X509CertificateCollection containing local certificates.
- remoteCertificate
- Type: System.Security.Cryptography.X509Certificates.X509Certificate
The certificate used to authenticate the remote party.
- acceptableIssuers
- Type: System.String()
A String array of certificate issuers acceptable to the remote party.
Return Value
Type: System.Security.Cryptography.X509Certificates.X509CertificateAn X509Certificate used for establishing an SSL connection.
The following code example demonstrates a method implementation for this delegate.
public:
static X509Certificate* SelectLocalCertificate(
String* /*targetHost*/,
X509CertificateCollection* localCertificates,
X509Certificate* /*remoteCertificate*/,
String* acceptableIssuers[])
{
Console::WriteLine(S"Client is selecting a local certificate.");
if (acceptableIssuers != 0 &&
acceptableIssuers->Length > 0 &&
localCertificates != 0 &&
localCertificates->Count > 0)
{
// Use the first certificate that is from an acceptable issuer.
IEnumerator* myEnum1 = localCertificates->GetEnumerator();
while (myEnum1->MoveNext())
{
X509Certificate* certificate = __try_cast<X509Certificate*>(myEnum1->Current);
String* issuer = certificate->GetIssuerName();
if (Array::IndexOf(acceptableIssuers, issuer) != -1)
return certificate;
}
}
if (localCertificates != 0 &&
localCertificates->Count > 0)
return localCertificates->Item[0];
return 0;
}
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 = new TcpClient(serverName,8080);
Console::WriteLine(S"Client connected.");
// Create an SSL stream that will close the client's stream.
SslStream* sslStream = new SslStream(
client->GetStream(),
false,
new RemoteCertValidationCallback (ValidateServerCertificate),
new LocalCertSelectionCallback(SelectLocalCertificate)
);
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.