1

Je tente de sécuriser l'API Web asp.net à l'aide de la bibliothèque IdentityServer3.IdentityServer3 Type de fournisseur non valide spécifié lors de l'utilisation du certificat auto-signé

J'ai créé un certificat auto-signé pour la signature de la sécurité tokes comme suit:

My Self-Sign Certificate

Puis je me suis l'exception suivante quand je l'appelle mon serveur d'autorisation

http://localhost:53180/connect/token

"InnerException": { 
    "Message": "An error has occurred.", 
    "ExceptionMessage": "Invalid provider type specified.\r\n", 
    "ExceptionType": "System.Security.Cryptography.CryptographicException", 
    "StackTrace": " at System.Security.Cryptography.Utils.CreateProvHandle(CspParameters parameters, Boolean randomKeyContainer)\r\n at System.Security.Cryptography.Utils.GetKeyPairHelper(CspAlgorithmType keyType, CspParameters parameters, Boolean randomKeyContainer, Int32 dwKeySize, SafeProvHandle& safeProvHandle, SafeKeyHandle& safeKeyHandle)\r\n at System.Security.Cryptography.RSACryptoServiceProvider.GetKeyPair()\r\n at System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 dwKeySize, CspParameters parameters, Boolean useDefaultKeySize)\r\n at System.Security.Cryptography.X509Certificates.X509Certificate2.get_PrivateKey()\r\n at System.IdentityModel.Tokens.X509AsymmetricSecurityKey.get_PrivateKey()\r\n at System.IdentityModel.Tokens.X509AsymmetricSecurityKey.GetSignatureFormatter(String algorithm)\r\n at System.IdentityModel.Tokens.AsymmetricSignatureProvider..ctor(AsymmetricSecurityKey key, String algorithm, Boolean willCreateSignatures) in c:\\workspace\\WilsonForDotNet45Release\\src\\System.IdentityModel.Tokens.Jwt\\AsymmetricSignatureProvider.cs:line 147" 

Il semble y avoir un problème avec la clé privée du certificat:

Private Key Problem Aidez-nous!

+0

J'ai rencontré le même problème avec IdentityServer4. –

Répondre

0

Voir: https://github.com/IdentityServer/IdentityServer3/issues/2859

Vous avez besoin d'un certificat avec une clé privée gérée par un CSP héritage, pas CNG.

Si vous utilisez Windows Server 2016 ou Windows 10, le commandlet New-SelfSignedCertificate a été considérablement étendu et inclut désormais toutes les options dont vous avez besoin. La commande suivante génère un certificat approprié pour la signature symbolique, avec la clé privée gérée par un CSP héritage:

New-SelfSignedCertificate -CertStoreLocation cert:\localmachine\my ` 
-FriendlyName "Token Signing" -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.3") ` 
-KeyUsage DigitalSignature -KeyAlgorithm RSA -KeyLength 2048 -KeySpec Signature ` 
-DnsName ([System.Net.Dns]::GetHostByName($env:computerName).HostName) 

La partie clé est le -KeySpec Signature qui force l'utilisation d'un CSP héritage pour le secteur privé clé.