Skip to content

Bypass the certificate security check for localhost makes calls to valid https host throw exception #102106

@bpsc-wkubis

Description

@bpsc-wkubis

Description

I've implemented the steps from the guide Bypass the certificate security check. My understanding is that this custom message handler should function for both localhost (where it bypasses the check) and for valid HTTPS hosts.

The handler works perfectly when making API calls to localhost. However, when I attempt to make a call to a valid HTTPS host, an exception is thrown: Java.Security.Cert.CertificateException. The message associated with this exception is 'The remote certificate was rejected by the provided RemoteCertificateValidationCallback.'

When I set up the HttpClient without this message handler, simply using new HttpClient(), the call works fine.

During debug the expression return errors == System.Net.Security.SslPolicyErrors.None returns false because the errors are of type RemoteCertificateChainErrors."

Steps to Reproduce

Follow guide on https://learn.microsoft.com/en-us/dotnet/maui/data-cloud/local-web-services?view=net-maui-8.0 and then create 2 http requests. One for https localhost which should work fine, and second to some valid https host e.x. https://google.com which should throw described exception.

Both https client should use described in article Custom message handler.

Link to public reproduction project repository

No response

Version with bug

8.0.7 SR2

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

Instead of return errors == System.Net.Security.SslPolicyErrors.None; return just "true", althouh it's not really great solution

Relevant log output

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions