2017-04-12 91 views
1

这似乎是这样一个简单的事情,但我一直试图弄清楚这一个多星期了,现在似乎无法弄清楚。我们正在使用WinJS创建Windows UWP应用程序,并希望用户使用PIV(智能卡)/ PIN组合登录到应用程序。实质上,当应用程序启动时,它将验证是否有智能卡插入到设备中,然后提示用户输入PIN。如果PIN码是针对智能卡进行验证的,那么应用程序会将用户登录。用户使用智能卡登录Windows UWP应用程序

我们确实有Windows 7应用程序,目前正在这样做,但我试图转换该代码,但看起来我们使用的API对Windows无效UWP应用程序。我确实发布了关于这些API的问题,但没有收到任何回复(https://stackoverflow.com/questions/43344679/x509certificate2ui-class-equivalent-with-windows-uwp-and-winjs)。在Windows 7中,我们使用X509Certificate2UI(https://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.x509certificate2ui(v=vs.110).aspx)类来选择一个提示用户输入PIN的证书。

经过大量的研究,我相信(可能是错误的)与Windows UWP我需要使用智能卡API(https://docs.microsoft.com/en-us/uwp/api/windows.devices.smartcards)。过去几天我一直在阅读并在智能卡上看到几个Microsoft文档,如:https://docs.microsoft.com/en-us/windows/uwp/security/smart-cards,但无法找到一种方法来验证用户输入的PIN与智能卡上的PIN码。

从SmartCardProvisioning类(https://docs.microsoft.com/en-us/uwp/api/windows.devices.smartcards.smartcardprovisioning),我们可以调用它会提示当前PIN和新的PIN用户requestPinChangeAsync()方法。我正在寻找类似的功能,只是它只会询问当前的PIN码,然后返回一个值,让应用知道PIN码是否正确。

我也读过微软的Hello(https://docs.microsoft.com/en-us/windows/uwp/security/microsoft-passport)API,但没有看到将其用于智能卡的方法。

任何人都可以在正确的方向指出我如何使用智能卡/ PIN组合在我的应用程序中使用双因素身份验证。看起来好像我过去几天一直在Google泡沫中一遍又一遍,需要帮助才能走出去。

感谢

编辑解释为什么它不是一个重复: 不是一个真正的副本,这两个问题都由我问,我提的问题的BOD其他职位。在另一篇文章中,我正在寻找与WinJS的Windows UWP相同的X509Certificate2UI类。随着进一步的研究,我认为这可能不是正确的方式,因此通过这篇文章,我期待着看看是否有人能指出我正确的方向,使用PIV(智能卡)进行双因素身份验证,PIN与卡相关联。

编辑:工作的共享代码: 这是WinJS代码似乎工作。不知道有没有更好的方式:

if (certToUse != null) { 
    Windows.Security.Cryptography.Core.PersistedKeyProvider.openKeyPairFromCertificateAsync(certToUse, Windows.Security.Cryptography.Core.HashAlgorithmNames.sha256, Windows.Security.Cryptography.Core.CryptographicPadding.rsaPkcs1V15).then(function (keyPair) { 
     var buffer = 'data to sign' 
     var data = Windows.Security.Cryptography.CryptographicBuffer.convertStringToBinary(buffer, Windows.Security.Cryptography.BinaryStringEncoding.utf16BE) 
     Windows.Security.Cryptography.Core.CryptographicEngine.signAsync(keyPair, data).then(function (signed) { 
     var results = Windows.Security.Cryptography.Core.CryptographicEngine.verifySignature(keyPair, data, signed) 
      completeValidatePin = true 
      successCallback(true) 
     }, function (reason) { 
      completeValidatePin = true 
      errorCallback('User cancelled login') 
     }) 
    }, function (reason) { 
     completeValidatePin = true 
     errorCallback('Error using certificate') 
    }) 
    } else { 
    errorCallback('Certificate not found') 
    } 
+0

可能有[X509Certificate2UI类与Windows UWP和WinJS相当]的重复(http:// stackoverflow。com/questions/43344679/x509certificate2ui-class-equivalent-with-windows-uwp-and-winjs) –

+0

这不是一个重复的问题,两个问题都是由我提出的,我提到了问题的其他帖子。在另一篇文章中,我正在寻找与WinJS的Windows UWP相同的X509Certificate2UI类。随着进一步的研究,我认为这可能不是正确的方式,因此通过这篇文章,我期待着看看是否有人能指出我正确的方向,使用PIV(智能卡)进行双因素身份验证,PIN与卡相关联。 –

+0

不,我经历过该示例,但没有具体的方式请求证书并验证用户输入的PIN。该示例向您显示如何更改和重置PIN码,但不验证它。 –

回答

0

我目前正在调查你的问题,并试图确定是否有一个很好的解决方案。

我的确写了下面的代码,我认为应该工作:

IReadOnlyList<Certificate> Certs; 
CertificateQuery CertQuery = new CertificateQuery(); 
CertQuery.HardwareOnly = true; 

Certs = await CertificateStores.FindAllAsync(CertQuery); 
string strEncrypt = "test"; 
IBuffer BufferToEncrypt = CryptographicBuffer.ConvertStringToBinary(strEncrypt, BinaryStringEncoding.Utf8); 

foreach (Certificate Cert in Certs) 
{ 
    if (Cert.HasPrivateKey && ((Cert.KeyStorageProviderName == "Microsoft Base Smart Card Crypto Provider") || Cert.KeyStorageProviderName == "Microsoft Smart Card Key Storage Provider")) 
    { 
     CryptographicKey Key = null; 

     try 
     {       
      Key = await PersistedKeyProvider.OpenKeyPairFromCertificateAsync(Cert, HashAlgorithmNames.Sha1, CryptographicPadding.RsaPkcs1V15);       

     } 
     catch (Exception ex) 
     { 
      // Could not open Smart Card Key Pair 
     } 

     if (Key != null) 
     { 
      try 
      {       
       // Try to Sign with Cert Private key 
       IBuffer EncryptedBuffer = CryptographicEngine.Sign(Key, BufferToEncrypt); 
      } 
      catch (Exception ex) 
      { 
       // Could not sign        
      } 
     } 
    } 
} 

不幸的是,OpenKeyPairFromCertificateAsync创建了一个无声的背景下,供应商等等CryptographicEngine.Sign无法显示PIN对话框。我将不得不多看看它。

相关问题