asp.net - 通过 ASP.NET、Windows 身份验证和模拟,使用智能卡的私钥对数据进行签名

标签 asp.net .net-4.0 x509certificate smartcard

我想知道是否可以使用智能卡的私钥对数据进行签名而不求助于 java applet 或 activex 控件。

我已经非常接近了!

我们的环境是:

  • AD 域
  • PKI 基础设施/智能卡 (PIV)

我用以下方法构建了一个简单的 ASP.NET (.net 4.0) Web 表单应用程序:

  • Windows 身份验证开启,匿名关闭
  • 身份模拟

通过读卡器中的智能卡,我可以轻松枚举登录用户的智能卡上的证书 (StoreLocation.CurrentUser)。但是,当我尝试访问私钥(通过 CSP)时,收到“访问被拒绝”错误。

在我的本地计算机上的 Debug模式下,一切正常。我知道 - 这是陈词滥调。

        protected void Page_Load(object sender, EventArgs e)
        {

            //always populate the cert store
            store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
            store.Open(OpenFlags.MaxAllowed);

            RSACryptoServiceProvider csp = new RSACryptoServiceProvider();

            //hardcoded to get the first cert in the store - it's legit and had a private key
            cert = store.Certificates[0];

            //throws error when not local
            csp = (RSACryptoServiceProvider)cert.PrivateKey;

        }

我尝试授予应用程序池身份访问证书存储的权限,但没有成功。

最佳答案

无法在服务器上使用用户的私钥。这将有效抵消使用智能卡的好处。事实上,安全操作将在智能卡上执行。

Strategy for Supporting Smart Cards

Microsoft views smart cards as a key component of its Public Key Infrastructure (PKI) support. Smart cards enhance software-only solutions, such as client authentication, interactive logon, and secure e-mail. Smart cards are a point of convergence for public-key certificates and associated keys because they:

  • Provide tamper-resistant storage for protecting private keys and other forms of personal information.
  • Isolate security-critical computations involving authentication, digital signatures, and key exchanges from other parts of the system.
  • Enable portability of credentials and other private information between computers at work, at home, or for mobile users.

来源:Smart Card Concepts

正如您所看到的,一个关键方面是将安全关键操作与系统的其余部分隔离。使用用户私钥执行加密的唯一方法是使用智能卡读卡器(硬件本身)。由于无法从服务器端 ASP.NET 网页访问客户端的硬件,因此您尝试执行的操作是不可能的。

实现此目的的唯一方法是使用客户端组件。

关于asp.net - 通过 ASP.NET、Windows 身份验证和模拟,使用智能卡的私钥对数据进行签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16152210/

相关文章:

asp.net - 当 StatusCode 不为 200 时,自定义 404 页面不显示

c# - 本地化 resx 文件中资源字符串的参数

java - key 工具错误 : Failed to establish chain from reply

c# - 给定两个证书,我如何验证一个是用另一个的私钥签名的?

c# - 我们还应该使用服务器端网格还是 Javascript 网格?

java - 从 X509 证书中获取签名值

javascript - Jquery 在加载 CSS ddsmoothmenu 之前显示 UL 列表结构

c# - 如何使用 RazorEngine 引用 <img src/> 中的图像文件来生成 HTML 电子邮件

sql - 如何最好地在后台执行查询以不卡住应用程序 (.NET)

assemblies - CLR 4.0 内联策略? (可能是 MethodImplOptions.NoInlining 的错误)