我想知道是否可以使用智能卡的私钥对数据进行签名而不求助于 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.
正如您所看到的,一个关键方面是将安全关键操作与系统的其余部分隔离。使用用户私钥执行加密的唯一方法是使用智能卡读卡器(硬件本身)。由于无法从服务器端 ASP.NET 网页访问客户端的硬件,因此您尝试执行的操作是不可能的。
实现此目的的唯一方法是使用客户端组件。
关于asp.net - 通过 ASP.NET、Windows 身份验证和模拟,使用智能卡的私钥对数据进行签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16152210/