简体   繁体   English

“无法为 SSL/TLS 安全通道建立信任关系。” signalr2.2、https、.net 客户端、自定义证书的异常

[英]“Could not establish trust relationship for the SSL/TLS secure channel.” Exception on signalr2.2, https, .net client, custom certificate

I got some exception in testing signalr .net client with custom self-signed certificate.我在使用自定义自签名证书测试 signalr .net 客户端时遇到了一些异常。
There was no exception on http. http 也不例外。
Is there any problem in setting up the self-signed certificate in my code?在我的代码中设置自签名证书有什么问题吗?
Note that, there is no problem in my certificate file because it runs my https mvc sites well.请注意,我的证书文件没有问题,因为它可以很好地运行我的 https mvc 站点。

server side code : asp.net, azure local fabric服务器端代码:asp.net,azure 本地结构

[assembly: OwinStartup(typeof(BookohWebRole.Startup))]
namespace BookohWebRole
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            var hubConfiguration = new HubConfiguration();
            hubConfiguration.EnableDetailedErrors = true;
            hubConfiguration.EnableJavaScriptProxies = false;
            //GlobalHost.HubPipeline.AddModule(new ErrorHandlingPipelineModule());
            app.MapSignalR(hubConfiguration);
        }
    }
}

public class ChatHub : Hub
{
    public override Task OnConnected()
    {
        Trace.TraceInformation("OnConnected");
        var authToken = Context.QueryString.Get("AuthToken");
        Trace.TraceInformation("authToken : " + authToken);
        return base.OnConnected();
    }

    public override Task OnDisconnected(bool stopCalled)
    {
        Trace.TraceInformation("OnDisconnected");
        return base.OnDisconnected(stopCalled);
    }

    public override Task OnReconnected()
    {
        Trace.TraceInformation("OnReconnected");
        var authToken = Context.QueryString.Get("AuthToken");
        Trace.TraceInformation("authToken : " + authToken);
        return base.OnReconnected();
    }

    public void Send(string name, string message)
    {
        Trace.TraceInformation("Context.ConnectionId : " + Context.ConnectionId);
        Clients.All.onSend(name, message);
    }
}

client side code : .net client, unit test method客户端代码:.net 客户端,单元测试方法

[TestMethod]
public void chat()
{
    var ev = new AutoResetEvent(false);

    Task.Run(async () =>
    {
        try
        {
            ServicePointManager.DefaultConnectionLimit = 10;
            var queryString = new Dictionary<string, string>();
            queryString.Add("AuthToken", Guid.NewGuid().ToString());

            //https://localhost:44302/
            //http://localhost:22792/

            var hubConnection = new HubConnection("https://localhost:44302/");
            hubConnection.Credentials = CredentialCache.DefaultCredentials;
            hubConnection.AddClientCertificate(X509Certificate.CreateFromCertFile("bookoh.cer"));
            hubConnection.TraceLevel = TraceLevels.All;
            hubConnection.TraceWriter = Console.Out;
            IHubProxy chatHubProxy = hubConnection.CreateHubProxy("ChatHub");
            await hubConnection.Start();

            chatHubProxy.On<string, string>("onSend", (name, message) =>
            {
                Trace.TraceInformation("onSend name : " + name);
                Trace.TraceInformation("onSend message : " + message);
                ev.Set();
            });

            Trace.TraceInformation("chatHubProxy.Invoke");
            await chatHubProxy.Invoke("Send", "hhd2002", "hello");
        }
        catch (Exception ex)
        {
            Trace.TraceInformation("ex : " + ex);
        }
    });

    ev.WaitOne();
}

full exception message on client program客户端程序上的完整异常消息

 vstest.executionengine.x86.exe Information: 0 : ex : System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
 at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)
 at System.Net.PooledStream.EndWrite(IAsyncResult asyncResult)
 at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)

It looks like your actual exception message is看起来您的实际异常消息是

The remote certificate is invalid according to the validation procedure.根据验证程序,远程证书无效。

This is most likely due to it being self-signed and not signed by a trusted certificate authority.这很可能是因为它是自签名的,而不是由受信任的证书颁发机构签名。 It looks like this has already been answered here:看起来这已经在这里得到了回答:

C# Ignore certificate errors? C# 忽略证书错误?

I had this issue and it was due to an expired/missing Digi Cert Global Root G2 certificate.我遇到了这个问题,这是由于 Digi Cert Global Root G2 证书过期/丢失所致。

I believe if you raise it with Microsoft they provide you a new certificate, however I just applied it from another machine.我相信如果你向微软提出它,他们会为你提供一个新证书,但我只是从另一台机器上应用它。

The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel 底层连接已关闭:无法为 SSL/TLS 安全通道建立信任关系

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WebException无法为SSL / TLS安全通道建立信任关系 - WebException Could not establish trust relationship for the SSL/TLS secure channel asp.net core 2.0 中的 WCF - 无法为具有权限的 SSL/TLS 安全通道建立信任关系 - WCF in asp.net core 2.0 - Could not establish trust relationship for the SSL/TLS secure channel with authority Asp.net webform c# 代码生成错误无法为 SSL/TLS 安全通道建立信任关系 - Asp.net webform c# code generates error Could not establish trust relationship for the SSL/TLS secure channel 无法创建SSL / TLS安全通道。客户端和服务器无法通信,因为它们没有通用算法 - Could not create SSL/TLS secure channel. The client and server cannot communicate, because they do not possess a common algorithm 无法创建SSL / TLS安全通道。 -Cdyne回传 - Could not create SSL/TLS secure channel. - Cdyne Postback Windows 7 无法创建 SSL/TLS 安全通道。"} System.Net.WebException - Windows 7 Could not create SSL/TLS secure channel."} System.Net.WebException 调用第三方Web服务和证书时无法使用授权建立SSL / TLS的安全通道 - Could not establish secure channel for SSL/TLS with authority when calling third party web service along with certificate WCF SSL无法通过授权为SSL / TLS建立安全通道 - WCF SSL Could not establish secure channel for SSL/TLS with authority 无法使用权​​限“ site.com”为SSL / TLS建立安全通道 - Could not establish secure channel for SSL/TLS with authority 'site.com' 该请求已中止:无法创建SSL / TLS安全通道。 调用PostAsJsonAsync时 - The request was aborted: Could not create SSL/TLS secure channel. when calling PostAsJsonAsync
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM