Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The issue of RemoteCertificateNameMismatch in .Net 6 when calling AWS GetObjectAsync can be resolved by either ignoring the certificate validation or by updating the root certificates.

  1. Ignoring the certificate validation: You can use the following code to ignore the certificate validation:
System.Net.ServicePointManager.ServerCertificateValidationCallback +=
    (sender, cert, chain, sslPolicyErrors) => true;

var client = new AmazonS3Client();
  1. Updating the root certificates: You can update the root certificates by downloading the latest set of trusted root certificates from the Microsoft website and installing them on your server or local machine.

You can use the following code to update the root certificates:

// initialize HttpClientHandler instance with the default .NET implementation of SSL/TLS
var httpClientHandler = new HttpClientHandler();

// Enable automatic updates of root CA certificates
httpClientHandler.UseDefaultCredentials = true;
httpClientHandler.CheckCertificateRevocationList = true;
httpClientHandler.ServerCertificateCustomValidationCallback = (request, cert, chain, errors) =>
{
    // validate cert with your own logic
    return cert.Subject.Contains("domain.com");
};

var httpClient = new HttpClient(httpClientHandler);
var s3Client = new AmazonS3Client(httpClient);

Once the root certificates are updated, you should not face the RemoteCertificateNameMismatch issue when calling AWS GetObjectAsync.