La clave privada no es compatible con el intercambio KeySpec durante la respuesta ADFS2.0
-
29-10-2019 - |
Pregunta
Tienes ese problema
Hemos reclamado el sitio asp.net y el servidor adfs configurado para este sitio
Entonces, tenemos - lanzamos nuestra aplicación web - movida para la autenticación al servidor adfs y regresamos al sitio web - como resultado, tenemos una página de servidor de error con la URL de nuestro sitio
**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**
Los registros de Windows muestran que en este momento recibimos dicha advertencia, como sugerí completamente correlacionada con el error de la página de error del servidor
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 usuario vacío e IsAuthenticated= false es muy confusa ... Entonces, ¿significa que no pasamos la autenticación ob ADFS o muestra los resultados actuales del sitio solicitado?
Por lo tanto, desafortunadamente no soy un gran experto en esta área y lucho con ella cada semana
¿Alguien podría ayudarme a solucionar el problema?
Muchas gracias
Solución
Lo que parece suceder aquí es que su Confianza para la parte que confía en AD FS está configurada para cifrar sus tokens usando (la parte pública de) algún certificado. Lo hace y su aplicación web intenta descifrarlos utilizando la clave privada de ese mismo certificado.
Sin embargo, el certificado debe admitir el "intercambio de claves" y, según su mensaje de error, parece que el suyo no lo hace. No tengo idea de dónde obtuvo su certificado, pero si lo está creando mediante programación a través de Windows COM usando IX509Enrollment , luego debe configurar el KeySpec para IX509PrivateKey a XCN_AT_KEYEXCHANGE .
Algo diferente que debe hacer bien es asegurarse de que el certificado admita la 'firma de documentos'. Para ello, asegúrese de que IX509ExtensionEnhancedKeyUsage contenga XCN_OID_KP_DOCUMENT_SIGNING o 1.3.6.1.4.1.311.10.3.12.
Además, los nombres de las clases COM detrás de las interfaces COM anteriores están documentados en IX509EnrollmentWebClassFactory :: CreateObject página.
Otros consejos
También debe verificar si el usuario (de servicio) que se dirige al certificado tiene suficientes derechos en la máquina local para acceder a los certificados.Ese era mi problema.