La chiave privata non supporta la tasti di scambio durante la risposta ADFS2.0
-
29-10-2019 - |
Domanda
Hai un problema simile
Abbiamo dichiarato di aver riconosciuto il sito asp.net e il server adfs configurato per questo sito
Quindi, abbiamo - lanciamo la nostra applicazione web - spostati per l'autenticazione sul server adfs e torniamo al sito web - di conseguenza abbiamo una pagina del server di errore con l'URL del nostro sito
**System.NotSupportedException: The private key does not support the exchange KeySpec.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NotSupportedException: The private key does not support the exchange KeySpec.]
System.IdentityModel.Tokens.X509AsymmetricSecurityKey.DecryptKey(String algorithm, Byte[] keyData) +237615
System.IdentityModel.Selectors.SimpleTokenResolver.TryResolveSecurityKeyCore(SecurityKeyIdentifierClause keyIdentifierClause, SecurityKey& key) +378
Microsoft.IdentityModel.Tokens.EncryptedSecurityTokenHandler.ReadToken(XmlReader reader) +253
Microsoft.IdentityModel.Tokens.SecurityTokenHandlerCollection.ReadToken(XmlReader reader) +105
Microsoft.IdentityModel.Web.TokenReceiver.ReadToken(String tokenXml, XmlDictionaryReaderQuotas readerQuotas) +282
Microsoft.IdentityModel.Web.WSFederationAuthenticationModule.SignInWithResponseMessage(HttpRequest request) +312
Microsoft.IdentityModel.Web.WSFederationAuthenticationModule.OnAuthenticateRequest(Object sender, EventArgs args) +1099462
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +171**
I log di Windows mostrano che in questo lasso di tempo riceviamo tale avviso, come ho suggerito completamente correlato all'errore dalla pagina di errore del server
Log Name: Application
Source: ASP.NET 2.0.50727.0
Date: 3/23/2011 2:05:50 PM
Event ID: 1309
Task Category: Web Event
Level: Warning
Keywords: Classic
User: N/A
Computer: machine-name
Description:
Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 3/23/2011 2:05:50 PM
Event time (UTC): 3/23/2011 2:05:50 PM
Event ID: 356af0be20744d15bba97111f6bbd475
Event sequence: 7
Event occurrence: 6
Event detail code: 0
Application information:
Application domain: /appl-domain/ClaimsAwareWebAppWithManagedSTS-1-129453622903756000
Trust level: Full
Application Virtual Path: /ClaimsAwareWebAppWithManagedSTS
Application Path: C:\tools\AdvantageSso\Using Managed STS\ClaimsAwareWebAppWithManagedSTS\
Machine name: machine-name
Process information:
Process ID: 3840
Process name: w3wp.exe
Account name: NT AUTHORITY\NETWORK SERVICE
Exception information:
Exception type: NotSupportedException
Exception message: The private key does not support the exchange KeySpec.
Request information:
Request URL: https://app-url/ClaimsAwareWebAppWithManagedSTS/default.aspx
Request path: /ClaimsAwareWebAppWithManagedSTS/default.aspx
User host address: host-name
User:
Is authenticated: False
Authentication Type:
Thread account name: NT AUTHORITY\NETWORK SERVICE
Thread information:
Thread ID: 10
Thread account name: NT AUTHORITY\NETWORK SERVICE
Is impersonating: False
Stack trace: at System.IdentityModel.Tokens.X509AsymmetricSecurityKey.DecryptKey(String algorithm, Byte[] keyData)
at System.IdentityModel.Selectors.SecurityTokenResolver.SimpleTokenResolver.TryResolveSecurityKeyCore(SecurityKeyIdentifierClause keyIdentifierClause, SecurityKey& key)
at Microsoft.IdentityModel.Tokens.EncryptedSecurityTokenHandler.ReadToken(XmlReader reader)
at Microsoft.IdentityModel.Tokens.SecurityTokenHandlerCollection.ReadToken(XmlReader reader)
at Microsoft.IdentityModel.Web.TokenReceiver.ReadToken(String tokenXml, XmlDictionaryReaderQuotas readerQuotas)
at Microsoft.IdentityModel.Web.WSFederationAuthenticationModule.SignInWithResponseMessage(HttpRequest request)
at Microsoft.IdentityModel.Web.WSFederationAuthenticationModule.OnAuthenticateRequest(Object sender, EventArgs args)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
La parte con utente vuoto e IsAuthenticated= false è molto confusa ... Quindi significa che non passiamo l'autenticazione ob ADFS o mostra i risultati correnti del sito richiesto
Quindi, sfortunatamente non sono un grande esperto in questo settore e combatto con esso durante la settimana
Qualcuno potrebbe aiutarmi a risolvere il problema?
Grazie mille
Soluzione
Quello che sembra accadere qui è che il tuo trust di terze parti in AD FS è configurato per crittografare i suoi token utilizzando (la parte pubblica di) alcuni certificati. Lo fa e la tua applicazione web cerca di decrittografarli utilizzando la chiave privata dello stesso certificato.
Tuttavia, il certificato deve supportare lo "scambio di chiavi" e dal tuo messaggio di errore sembra che il tuo non lo sia. Non ho idea da dove hai preso il tuo certificato, ma se lo stai creando a livello di programmazione tramite Windows COM utilizzando IX509Enrollment , quindi devi impostare KeySpec per IX509PrivateKey a XCN_AT_KEYEXCHANGE .
Una cosa diversa che devi fare bene, è assicurarti che il certificato supporti la "firma del documento". Per questo assicurati che IX509ExtensionEnhancedKeyUsage contenga XCN_OID_KP_DOCUMENT_SIGNING o 1.3.6.1.4.1.311.10.3.12.
Inoltre, i nomi delle classi COM dietro le interfacce COM precedenti sono documentati in Pagina IX509EnrollmentWebClassFactory :: CreateObject .
Altri suggerimenti
Dovresti anche controllare se l'utente (servizio) che indirizza il certificato ha diritti sufficienti sulla macchina locale per accedere ai certificati.Questo era il mio problema.