LocalCertificateSelectionCallback Delegate
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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);
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
Parameters
- sender
- Object
An object that contains state information for this validation.
- targetHost
- String
The host server specified by the client.
- localCertificates
- X509CertificateCollection
An X509CertificateCollection containing local certificates.
- remoteCertificate
- X509Certificate
The certificate used to authenticate the remote party.
Return Value
An X509Certificate used for establishing an SSL connection.
Examples
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,5000 );
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,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)
);
Remarks
This delegate is used to construct instances of the SslStream class. 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.
Extension Methods
GetMethodInfo(Delegate) |
Gets an object that represents the method represented by the specified delegate. |
Applies to
See also
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기