Skip to content

DangerousAcceptAnyServerCertificateValidator for RemoteCertificateValidationCallback #42482

@JamesNK

Description

@JamesNK

Today with HttpClientHandler.ServerCertificateCustomValidationCallback you can do this to accept self-signed certificates:

var httpHandler = new HttpClientHandler();
// Return `true` to allow certificates that are untrusted/invalid
httpHandler.ServerCertificateCustomValidationCallback = 
    HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;

This is good, but the predefined delegate is limited to HttpClientHandler. There are options specific to SocketsHttpHandler so devs sometimes must use it instead. When they use SocketsHttpHandler there isn't an equivalent for quickly accepting self-signed certificates. They must specify a delegate that returns true:

var httpHandler = new SocketsHttpHandler();
httpHandler.SslOptions.RemoteCertificateValidationCallback =
    (object sender, X509Certificate? certificate, X509Chain? chain, SslPolicyErrors sslPolicyErrors) => true;

It would be nice if there was a helper delegate for SocketsHttpHandler like DangerousAcceptAnyServerCertificateValidator:

var httpHandler = new SocketsHttpHandler();
httpHandler.SslOptions.RemoteCertificateValidationCallback =
    SocketsHttpHandler.DangerousAcceptAnyServerCertificateValidator;

The property could either go on SocketsHttpHandler, or SslClientAuthenticationOptions (which is where RemoteCertificateValidationCallback is defined)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions