ClientCertificateResource Class
Assembly: System.Net.Security.dll
Represents a resource that is accessible only by a specific client certificate.
Syntax
Namespace: System.Net.Security
Assembly: System.Net.Security.dll
Remarks
The ClientCertificateResource class is used in conjunction with the SslStream class to enforce client certificate authentication for accessing specific resources. When a client attempts to access a resource protected by a ClientCertificateResource, the server validates the client's certificate against a predefined policy. If the certificate is valid and trusted, the client is granted access.
This class is particularly useful in scenarios where fine-grained access control based on client identity is required, such as in secure web services or internal APIs.
Examples
Basic Usage
The following example demonstrates how to create a ClientCertificateResource and associate it with an SSL stream. This is a conceptual example; actual implementation involves server-side certificate validation logic.
// Assume 'serverCertificate' is a valid X509Certificate2
// Assume 'clientCertificate' is the certificate presented by the client
// In a server-side scenario, you might use this conceptually like:
// SslStream sslStream = new SslStream(innerStream, false);
// await sslStream.AuthenticateAsServerAsync(serverCertificate, requireClientCertificate: true, clientCertificateValidationCallback: (sender, certificate, chain, sslPolicyErrors) =>
// {
// // Custom validation logic here
// // If the client certificate is valid and matches expected criteria, return true.
// // You would typically check the certificate's subject, issuer, or custom extensions.
// if (certificate != null && certificate.Subject.Contains("CN=TrustedClient"))
// {
// return true;
// }
// return false;
// });
// This class itself might not be directly instantiated in common use cases.
// Its properties and behavior are often managed by the SslStream authentication process.
Console.WriteLine("ClientCertificateResource concept applied during SSL authentication.");
Methods
This class does not expose any public methods.
Properties
This class does not expose any public properties.
Requirements
| Assembly | Supported in |
|---|---|
| System.Net.Security.dll | .NET Framework 4.5, .NET Core 1.0, .NET Standard 1.3, .NET 5+ |