alexrainman / ModernHttpClient

ModernHttpClient
MIT License
126 stars 28 forks source link

SSL error thrown even with EnableUntrustedCertificates = true #10

Closed vaindil closed 6 years ago

vaindil commented 6 years ago

I'm connecting to a local server that uses a self-signed SSL cert, so EnableUntrustedCertificates is set to true. I'm still getting the below error, however. Am I misunderstanding what EnableUntrustedCertificates is intended to do?

The exception:

Unhandled Exception:

System.Net.Http.HttpRequestException: Hostname my.hostname.local not verified:
    certificate: sha256/fake/hashstringhere=
    DN: CN=hostname.local
    subjectAltNames: [hostname.local, *.hostname.local, *.*.hostname.local] occurred

I'm declaring HttpClient like this:

_client = new HttpClient(new NativeMessageHandler
{
    AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
    EnableUntrustedCertificates = true,
    Timeout = TimeSpan.FromSeconds(6)
})
{
    BaseAddress = new Uri("https://my.hostname.local/")
};
alexrainman commented 6 years ago

Which platform?

vaindil commented 6 years ago

Sorry, this is on Android 7.1.1.

Package versions:

alexrainman commented 6 years ago

OK, i will run some tests.

alexrainman commented 6 years ago

Cannot reproduce this. Can you provide a demo project?

vaindil commented 6 years ago

This is really odd, apparently it has to do with the certificate itself. When I test with https://self-signed.badssl.com the code works, but testing with https://my.hostname.local throws the error. I'll see if I can recreate the cert for a repro.

vaindil commented 6 years ago

This is the exception that I get. I can't figure out why I get it. I can't repro either. Does that help at all?

vaindil commented 6 years ago

Today I learned that you can't have a two-level wildcard cert (like *.*.example.com). That was the issue. I fixed the cert and now all is good. Sorry about this!

alexrainman commented 6 years ago

No problem.