Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Federated Authentication and "Error occurred during a cryptographic operation"

I got this exception when I try get my home page on ASP.NET MVC application.

[CryptographicException: Error occurred during a cryptographic operation.]
System.Web.Security.Cryptography.HomogenizingCryptoServiceWrapper.HomogenizeErrors(Func`2 func, Byte[] input) +246
System.IdentityModel.Services.MachineKeyTransform.Decode(Byte[] encoded) +191
System.IdentityModel.Tokens.SessionSecurityTokenHandler.ApplyTransforms(Byte[] cookie, Boolean outbound) +173
System.IdentityModel.Tokens.SessionSecurityTokenHandler.ReadToken(XmlReader reader, SecurityTokenResolver tokenResolver) +756
System.IdentityModel.Tokens.SessionSecurityTokenHandler.ReadToken(Byte[] token, SecurityTokenResolver tokenResolver) +100
System.IdentityModel.Services.SessionAuthenticationModule.ReadSessionTokenFromCookie(Byte[] sessionCookie) +1164
System.IdentityModel.Services.SessionAuthenticationModule.TryReadSessionTokenFromCookie(SessionSecurityToken& sessionToken) +287
System.IdentityModel.Services.SessionAuthenticationModule.OnAuthenticateRequest(Object sender, EventArgs eventArgs) +231
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +165

From what I understand something get wrong in the cookie for SessionAuthenticationModule. If you clear the cookies (as stated already here Federated Authentication on Azure) it works. What I would like is to understand what is going on, how to catche the exceptions and fix the issue.

like image 990
Dave Avatar asked Apr 05 '13 16:04

Dave


2 Answers

The cookie, when issued, contains security token encrypted using the current machineKey. When the cookie from the previous build is sent back to server, SAM (more precisely the token handler) tries to decrypt it using the new value of machineKey which causes the error. Check my answer in the related post (Federated Authentication on Azure) to mitigate the error. HTH

like image 158
eXavier Avatar answered Oct 19 '22 09:10

eXavier


I faced the same problem. I just cleared all of browser's cookies and cache data and it got fixed.

like image 30
Baqer Naqvi Avatar answered Oct 19 '22 09:10

Baqer Naqvi