【问题标题】:SignalR with Client Certificate Authentication具有客户端证书身份验证的 SignalR
【发布时间】:2015-10-07 22:35:23
【问题描述】:

我在 IIS 上托管了使用 SignalR 与客户端建立持久连接的服务。

我正在尝试实现客户端证书身份验证,以便服务器可以根据他们发送的证书验证客户端是否为有效客户端。我正在使用 Signalr 的 PersistentConnection。

客户: 我创建了一个 Connection 对象,并创建了一个 X.509 证书,我通过以下方式将其添加到连接中:

var connection = new Connection("localhost:8060/TheService/connect");
connection.AddClientCertificate(certificate); 
connection.Start().Wait();

当客户端尝试连接时,我想验证它提供的证书是否为有效证书。所以在服务器端我重写了 SignalR 的 PersistentConnection 中的 AuthorizeRequest() 方法:

    public class MyConnection : PersistentConnection
    {
        protected override Task OnReceived(IRequest request, string connectionId, string data)
        {
            return Connection.Broadcast("Server Received: " + data);
        }

        protected override bool AuthorizeRequest(IRequest request)
        {
            INameValueCollection headers = request.Headers;

            foreach (KeyValuePair<string, string> entry in headers)
            {
                Console.WriteLine("Key: {0}, Value: {1}", entry.Key, entry.Value);
                Console.WriteLine("");
            }

            return true; 
        }
}

我的问题是:如何在 AuthorizeRequest 方法中检索客户端证书?我需要 SignalR 以某种方式获得对证书的访问权限,以便我可以验证它 AuthorizeRequest,然后返回 false(错误证书)或返回 true(有效证书)。

谢谢!

【问题讨论】:

    标签: c# asp.net signalr client-certificates


    【解决方案1】:

    您应该能够从作为参数的请求中获取证书。 HttpClientCertificate cert = request.GetHttpContext().Request.ClientCertificate;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-01-03
      • 2011-04-09
      • 2013-10-07
      • 1970-01-01
      • 2022-06-23
      • 1970-01-01
      • 2018-02-12
      相关资源
      最近更新 更多