मैंने एमएसडीएन मंचों, डोमिनिक बायर के ब्लॉग में पढ़ा है, और अन्य स्रोतों में कि डीपीएपीआई एज़ूर में बॉक्स के बाहर काम नहीं करेगा, और किसी भी प्रकार के वेब फार्म परिदृश्य में संघीय प्रमाणीकरण को संभालने का एक दृष्टिकोण है डीपीएपीआई एक ऐसे व्यक्ति के साथ बदलता है जो खेत में उपलब्ध एक निजी कुंजी का उपयोग करता है, जैसे X509 प्रमाणपत्र का उपयोग कर आरएसए एन्क्रिप्शन। मैं अपने Azure MVC आवेदन में इस दृष्टिकोण ले लिया है और SessionSecurityTokenHandler
इस तरह कॉन्फ़िगर किया गया:सत्र सुरक्षा सुरक्षा टोकनहैंडर डीपीएपीआई का उपयोग कर आरएसए-एन्क्रिप्टेड कुकी में सत्र सुरक्षा सुरक्षा को डिक्रिप्ट करने का प्रयास कर रहा है; क्यूं कर?
FederatedAuthentication.ServiceConfigurationCreated += (sender, args) =>
{
var sessionTransforms = new List<CookieTransform>(new CookieTransform[]
{
new DeflateCookieTransform(),
new RsaEncryptionCookieTransform(args.ServiceConfiguration.ServiceCertificate),
new RsaSignatureCookieTransform(args.ServiceConfiguration.ServiceCertificate)
});
var sessionHandler = new SessionSecurityTokenHandler(sessionTransforms.AsReadOnly());
args.ServiceConfiguration.SecurityTokenHandlers.AddOrReplace(sessionHandler);
};
इस विन्यास का उपयोग करना, हम कोई पहचान प्रदाता से टोकन प्राप्त करते हैं और सुरक्षित कुकीज़ इन रूपांतरण का उपयोग करके एन्क्रिप्ट जारी करने के लिए सक्षम हैं। Azure एमुलेटर में चल रहा है, सब कुछ उम्मीद के रूप में काम करता है। हालांकि, Azure वातावरण में, हम रुक-रुक कर निम्न त्रुटि ब्राउज़र में देखें:
Key not valid for use in specified state.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Security.Cryptography.CryptographicException: Key not valid for use in specified state.
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:
[CryptographicException: Key not valid for use in specified state.
]
System.Security.Cryptography.ProtectedData.Unprotect(Byte[] encryptedData, Byte[] optionalEntropy, DataProtectionScope scope) +577
Microsoft.IdentityModel.Web.ProtectedDataCookieTransform.Decode(Byte[] encoded) +80
[InvalidOperationException: ID1073: A CryptographicException occurred when attempting to decrypt the cookie using the ProtectedData API (see inner exception for details). If you are using IIS 7.5, this could be due to the loadUserProfile setting on the Application Pool being set to false. ]
Microsoft.IdentityModel.Web.ProtectedDataCookieTransform.Decode(Byte[] encoded) +433
Microsoft.IdentityModel.Tokens.SessionSecurityTokenHandler.ApplyTransforms(Byte[] cookie, Boolean outbound) +189
Microsoft.IdentityModel.Tokens.SessionSecurityTokenHandler.ReadToken(XmlReader reader, SecurityTokenResolver tokenResolver) +862
Microsoft.IdentityModel.Tokens.SessionSecurityTokenHandler.ReadToken(Byte[] token, SecurityTokenResolver tokenResolver) +109
Microsoft.IdentityModel.Web.SessionAuthenticationModule.ReadSessionTokenFromCookie(Byte[] sessionCookie) +356
Microsoft.IdentityModel.Web.SessionAuthenticationModule.TryReadSessionTokenFromCookie(SessionSecurityToken& sessionToken) +123
Microsoft.IdentityModel.Web.SessionAuthenticationModule.OnAuthenticateRequest(Object sender, EventArgs eventArgs) +61
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +270
यह पता चलता है कि SessionSecurityTokenHandler
कुकी DPAPI का उपयोग कर डिक्रिप्ट करने के लिए कोशिश कर रहा है, लेकिन क्यों लगता है? क्या मैंने ऊपर आरएसए का उपयोग करने के लिए इसे कॉन्फ़िगर नहीं किया?
वाह पर इस सवाल मिलते हैं! अच्छी पकड़! तुम उस पर मेरा हो! – astaykov
अच्छा !!! लेकिन आपने कॉन्फ़िगरेशन फ़ाइल के माध्यम से क्यों नहीं किया? http://blogs.msdn.com/b/distributedservices/archive/2012/10/29/wif-1-0-id1073-a-cryptographicexception-occurred-when-attempting-to-decrypt-the-cookie-using- the-protecteddedd-api.aspx – antwoord
@antwoord जो इसे स्थापित करने के लिए अधिक तार्किक तरीका होगा। मुझे लगता है कि यह 'Application_Start' हैंडलर में किया गया कारण था क्योंकि जिस व्यक्ति ने इसे नहीं किया था, उसे यह नहीं पता था कि यह' web.config' में किया जा सकता है, और यह कोई मुद्दा नहीं था जिसे मैं बदलना चाहता था (हालांकि यह सब के बाद कम समय ले सकता है)। –