[英]“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:看起来这已经在这里得到了回答:
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.