【问题标题】:Mutual authentication using a USB token slot with a X.509 certificate使用带有 X.509 证书的 USB 令牌插槽进行相互身份验证
【发布时间】:2014-12-11 13:08:39
【问题描述】:

我正在尝试在 C# 中实现一个客户端库以与 tomcat 服务器进行通信。身份验证应通过在 Windows 客户端的相互 SSL 身份验证中使用带有 X.509 证书的飞天 epass2003 令牌来完成。

但是,我每次运行客户端窗口时都会请求令牌密码以继续操作,这对用户来说是一种过度杀伤力并且不可接受的操作。

我想知道是否可以取消此请求并以某种方式将其添加到代码中。或者,如果有其他方法可以在不使用 windows 证书管理器的情况下使用令牌。

这就是我扩展连接器的方式:

 class WebClientEx : WebClient
 { 
     public int Timeout { get; set; }

     public X509Certificate certificate { get; set; }

     protected override WebRequest GetWebRequest(Uri address)
     {
         ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
         ServicePointManager.Expect100Continue = true;
         ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
         HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address);
         request.Credentials = CredentialCache.DefaultCredentials;
         request.AuthenticationLevel = AuthenticationLevel.MutualAuthRequested;
         request.ClientCertificates.Add(this.certificate);
         request.Timeout = this.Timeout;
         return request;
     }
...
}   

这是我如何连接到服务器的示例:

byte[] certificate = getCertificate("autenticacao"); // Get certificate from token

 X509Certificate cert = new X509Certificate(certificate);

 var post = new NameValueCollection();
 post["test"] = "1";

 using (var wb = new WebClientEx(cert))
 {
     try
     {
         wb.Timeout = 30000;
         var response = wb.UploadValues("https://localhost:8443", "POST", post);
         Console.WriteLine("Done.");
     }
     catch (WebException e)
     {
         // Handle WebException
     }
 }

这是 Windows 请求屏幕:

最好的问候,

【问题讨论】:

    标签: c# client-certificates mutual-authentication


    【解决方案1】:

    TLS 允许使用会话票证重用会话。见RFC5077 Transport Layer Security (TLS) Session Resumption without Server-Side State,读Speeding up SSL: enabling session reuse。服务器支持各不相同。 Afaik .Net Framework 客户端支持基本上没有。见TLS/SSL and .NET Framework 4.0

    硬件模块不允许私钥离开模块,每次访问都需要 PIN。因此,如果 TLS 握手需要密钥,那么 PIN 对话是不可避免的,您唯一的机会是尝试避免私钥要求,而这只能通过可重复使用的 TLS 会话票证来实现,afaik。

    您可以重新考虑对每个 访问的双向 TLS 要求。访问一个资源(即登录页面),获取访问票据(cookie),然后使用它来验证访问其余资源。

    PS。 SSL 是一个没有选择的选项,已经过时多年了,现在每个人都在谈论 TLS。

    【讨论】:

    • 在https连接器中不能使用pkcs11接口吗?我已经使用 pcks11 实现了一种无需 pin 对话框即可初始化令牌的方法,因为我在代码本身中启动了令牌。
    猜你喜欢
    • 2017-12-26
    • 2011-09-15
    • 2021-03-13
    • 2019-07-17
    • 1970-01-01
    • 2011-01-28
    • 1970-01-01
    • 2016-06-14
    • 2022-06-10
    相关资源
    最近更新 更多