Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "The certificate authority is invalid or incorrect" when connecting to SignalR (Core) hub in UWP

I'm trying to connect to a SignalR Core hub from my UWP application.

In a .NET Core application (2.1) it works perfectly, whereas in UWP it throws an exception when hub.StartAsync() is called.

The certificate authority is invalid or incorrect

This is my code:

hub = new HubConnectionBuilder()
    .WithUrl("http://localhost:49791/hubs/status")
    .Build();

await hub.StartAsync();

What's going on?

I set guess I have to configure something in the Package Manifest, but what?

like image 341
SuperJMN Avatar asked Sep 26 '18 17:09

SuperJMN


3 Answers

In My case, I added below capabilities from Package.appxmanifest

enter image description here

like image 102
Ankit Avatar answered Nov 02 '22 10:11

Ankit


OK, I got into SignalR's Gitter Chat and one kind user has pointed me out the fix. Kudos to him. Here is the excerpt of the conversation.

Andrew Stanton-Nurse (@anurse): Is your application using SSL? The URL seems to be http but this error should only occur when using a self-signed SSL certificate

José Manuel Nieto @SuperJMN I'm not sure! I'm using the default ASP. NET Core template for Wep API. How can I check it? Thank you for the quick response! 😃

Andrew Stanton-Nurse @anurse try just navigating to the URL in a browser, does it redirect you to https://localhost:...?

José Manuel Nieto @SuperJMN OK, I discovered the problem here 👇

Snapshop

For it to work, this has to be unchecked 😃

like image 41
SuperJMN Avatar answered Nov 02 '22 10:11

SuperJMN


I know this was posted some time ago. I had same issue and unchecked Enable SSL as you did. And yes it works, but if you want to still keep the SSL enable and debug against https, you can add the below code. (For Debugging only, do not push this into any production). I also enabled Private Networks in the Package.appxmanifest of UWP

    Connection = new HubConnectionBuilder().WithUrl("https://localhost:44333/clienthub", options =>
                    {
                        options.HttpMessageHandlerFactory = (handler) =>
                        {
                            if (handler is HttpClientHandler clientHandler)
                            {
                                clientHandler.ServerCertificateCustomValidationCallback = ValidateCertificate;
                            }
                            return handler;
                        };
                    }).Build();

bool ValidateCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
            // TODO: You can do custom validation here, or just return true to always accept the certificate.
            // DO NOT use custom validation logic in a production application as it is insecure.
            return true;
        }
like image 3
Laurent Greyling Avatar answered Nov 02 '22 09:11

Laurent Greyling