使用自签名证书时建立SignalR连接

问题描述 投票:3回答:1

我有一个使用自签名证书的自托管Web API Web服务。我成功地使用URL与其他应用程序的Web服务控制器操作进行通信:

https://localhost:5150/...

请注意,我已成功将自签名证书绑定到端口5150,并使用相应的netsh命令为我的应用程序保留了所有IP的端口。

我正在尝试将SignalR集线器集成到此Web服务中。我在启动代码中使用以下内容配置了支持CORS的集线器:

// Configure the SignalR hub that will talk to the browser
        appBuilder.Map("/signalr", map =>
        {
            map.UseCors(CorsOptions.AllowAll);

            HubConfiguration hubConfig = new HubConfiguration();
            hubConfig.EnableDetailedErrors = true;
            hubConfig.EnableJavaScriptProxies = false;

            map.RunSignalR(hubConfig);
        });

我正在启动我的HTTP侦听器,这个/也用于Web API:

_webApp = WebApp.Start<Startup>(baseUrl);

哪里是的baseUrl

https://+:5150/.

我的SignalR初始化代码,在我的Angular控制器中是:

var initialize = function () {

    //Getting the connection object
    connection = $.hubConnection("/signalr", { useDefaultPath: false });

    // Url signalr scripts should hit back on the server
    connection.url = ENV.SIGNALR.protocol + '://' + ENV.SIGNALR.server + ':' + ENV.SIGNALR.port + '/' + ENV.SIGNALR.url;

    // Turn on client-side logging
    connection.logging = ENV.SIGNALR.logging;

    // Get proxy based on Hub name (must be camel-case)
    proxy = connection.createHubProxy('dashboardHub');

    // Setup event handlers for messages we get from the server.
    proxy.on('rxDiagnosticMessage', function (msg) {
        //console.log('Received rxDiagnosticMessage');
        $rootScope.$broadcast("rx-diagnostic-message", msg);
    });

    //Starting connection
    connection.start()
        .done(function () { console.log('SignalR connection started'); })
        .fail(function (err) { console.log('SignalR connection failed - ' + err); });

    // Display errors to console
    connection.error(function (err) {
        console.log('SignalR error - ' + err);
    });
};

尝试连接到集线器时,出现以下错误:

15:04:43 GMT-0400 (Eastern Daylight Time)] SignalR: Auto detected cross domain url. jquery.signalR-2.1.0.js:81
[15:04:43 GMT-0400 (Eastern Daylight Time)] SignalR: Client subscribed to hub 'dashboardhub'. jquery.signalR-2.1.0.js:81
[15:04:43 GMT-0400 (Eastern Daylight Time)] SignalR: Negotiating with 'https://localhost:5150/signalr/negotiate?clientProtocol=1.4&connectionData=%5B%7B%22name%22%3A%22dashboardhub%22%7D%5D'. jquery.signalR-2.1.0.js:81
GET https://localhost:5150/signalr/negotiate?clientProtocol=1.4&connectionData=%5B%7B%22name%22%3A%22dashboardhub%22%7D%5D&_=1407524683014 net::ERR_INSECURE_RESPONSE jquery-2.1.1.js:8623
SignalR error - Error: Error during negotiation request. AppSignalR.js:43
SignalR connection failed - Error: Error during negotiation request. AppSignalR.js:39
[15:04:43 GMT-0400 (Eastern Daylight Time)] SignalR: Stopping connection.

注意SignalR连接协商期间的net :: ERR_INSECURE_RESPONSE。

奇怪的是......如果我运行Fiddler2,那么连接就可以了! (Fiddler是否为我的网络应用/ SignalR提供了一个很好的证书?)

我怀疑这是由于证书是自签名的(个人证书,可信证书中的证书)。在WCF和WebAPI客户端中,我总是拦截权限错误并绕过错误:

ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);

我的Angular应用程序中的SignalR客户端是否需要进行类似的操作?或者这应该工作吗?

请注意,我已经看过这个帖子 - SignalR with Self-Signed SSL and Self-Host仍然不适合我。

ssl signalr self-signed
1个回答
-2
投票

您不能将localhost与SSL一起使用,您需要URL中的绝对HostName。

查看您创建的证书中的ISSUED BY和ISSUED TO字段,ISSUED BY需要成为您机器上“Trusted Publisher”列表的一部分(使用浏览器访问网页的机器),并且ISSUED TO需要成为你的网址.ie证书已经发给你,只有你。因此,如果您的ISSUED TO字段的值为“HOSTNAME.DOMAINNAME”,其中HOSTNAMe是机器的hostName,而DomainName是托管网站的机器的域,那么您需要使用相同的名称访问您的SITE,即。

希望这可以帮助。

© www.soinside.com 2019 - 2024. All rights reserved.