2017-04-12 47 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對話框。我將不得不多看看它。

相關問題