CertificatePolicy Class

Namespace: System.Net.Security
Assembly: System (in System.dll)

Represents a policy that defines how certificate validation is performed for secure network connections. This class is typically used to customize the behavior of SSL/TLS connections when specific certificate validation requirements need to be enforced or bypassed.

Syntax

[System.Security.SecurityCritical]
public sealed class CertificatePolicy

Remarks

The CertificatePolicy class provides a mechanism to control the validation of X.509 certificates used in secure network communications, such as those established using SSL/TLS. In .NET Framework versions prior to 4.5, developers could implement custom certificate validation logic by providing a delegate to the System.Net.Security.SslPolicyErrors.RemoteCertificateChainErrors event or by setting a custom System.Net.Security.ICertificatePolicy.

Starting with .NET Framework 4.5, the CertificatePolicy class is considered obsolete for new development. It is recommended to use the more modern and flexible approaches provided by System.Net.Security.SslClientAuthenticationOptions.RemoteCertificateValidationCallback for client-side SSL/TLS connections. This callback allows for fine-grained control over certificate validation on a per-connection basis.

Note: This class is primarily for backward compatibility. For new applications, use SslClientAuthenticationOptions.RemoteCertificateValidationCallback.

Constructors

Name Description
CertificatePolicy() Initializes a new instance of the CertificatePolicy class.

Methods

Name Description
SatisfyModulusEquality(X509Certificate, X509Certificate) Determines whether the modulus of two certificates is equal. This method is used internally for certificate comparison.
SatisfyRemoteCertChainPolicy(string, X509Certificate, X509Chain, System.Net.Security.SslPolicyErrors) Evaluates the validity of a remote certificate based on the specified criteria. This method is called by the .NET Framework to validate server certificates.

Methods

SatisfyModulusEquality

public static bool SatisfyModulusEquality(X509Certificate cert1, X509Certificate cert2)

Parameters:

Returns: true if the modulus of cert1 is equal to the modulus of cert2; otherwise, false.

SatisfyRemoteCertChainPolicy

public static bool SatisfyRemoteCertChainPolicy(string hostName, X509Certificate certificate, X509Chain chain, System.Net.Security.SslPolicyErrors errors)

Parameters:

Returns: true if the certificate validation policy is satisfied; otherwise, false.