LocalCertificateSelectionCallback Delegasikan
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Memilih sertifikat Secure Sockets Layer (SSL) lokal yang digunakan untuk autentikasi.
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
Parameter
- sender
- Object
Objek yang berisi informasi status untuk validasi ini.
- targetHost
- String
Server host yang ditentukan oleh klien.
- localCertificates
- X509CertificateCollection
Yang X509CertificateCollection berisi sertifikat lokal.
- remoteCertificate
- X509Certificate
Sertifikat yang digunakan untuk mengautentikasi pihak jarak jauh.
Tampilkan Nilai
Digunakan X509Certificate untuk membuat koneksi SSL.
Contoh
Contoh kode berikut menunjukkan implementasi metode untuk delegasi ini.
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;
}
Contoh kode berikut menunjukkan pembuatan instans delegasi ini.
// 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)
);
Keterangan
Delegasi ini digunakan untuk membuat instans SslStream kelas. Kelas SslStream ini digunakan untuk membantu mengamankan informasi yang dipertukarkan antara klien dan server. Klien dan server menggunakan delegasi ini untuk memilih sertifikat yang akan digunakan untuk autentikasi.
Metode Ekstensi
GetMethodInfo(Delegate) |
Mendapatkan objek yang mewakili metode yang diwakili oleh delegasi yang ditentukan. |