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

3

10

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?

Nicky answered 26/9, 2018 at 17:3 Comment(2)
What exception then? Usually the network related permissions must be granted, learn.microsoft.com/en-us/windows/uwp/packaging/…Faus
We all overlook the error message in the title.Boeotian
N
6

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 😃

Nicky answered 27/9, 2018 at 9:5 Comment(0)
I
14

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

enter image description here

Iasis answered 14/9, 2020 at 5:54 Comment(2)
Correct answer if this error occurs in http connection (no ssl)Martinmas
@Ankit, Thanks, it was the case with my project as well. This might be the best answer as the problem is with Certificate of the Webservice in most of the cases.Usher
N
6

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 😃

Nicky answered 27/9, 2018 at 9:5 Comment(0)
C
4

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;
        }
Chancechancel answered 13/3, 2019 at 10:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.