Guest User

Untitled

a guest
Mar 23rd, 2013
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. private void OnServiceConfigurationCreated( object sender, ServiceConfigurationCreatedEventArgs e )
  2. {
  3. List<CookieTransform> sessionTransforms = new List<CookieTransform>( new CookieTransform[]
  4. {
  5. new DeflateCookieTransform(),
  6. new RsaEncryptionCookieTransform( e.ServiceConfiguration.ServiceCertificate ),
  7. new RsaSignatureCookieTransform( e.ServiceConfiguration.ServiceCertificate )
  8. } );
  9.  
  10. SessionSecurityTokenHandler sessionHandler =
  11. new SessionSecurityTokenHandler( sessionTransforms.AsReadOnly() );
  12.  
  13. e.ServiceConfiguration.SecurityTokenHandlers.AddOrReplace( sessionHandler );
  14. }
  15.  
  16. <microsoft.identityModel>
  17. <service>
  18. <serviceCertificate>
  19. <certificateReference x509FindType="FindByThumbprint" findValue="C7FD338059CCB374798923A915BC91B718814A8E" storeLocation="LocalMachine" storeName="TrustedPeople" />
  20. </serviceCertificate>
  21. </service>
  22. </microsoft.identityModel>
  23.  
  24. System.Security.Cryptography.CryptographicException: ID1014: The signature is not valid. The data may have been tampered with.
  25. at Microsoft.IdentityModel.Web.RsaSignatureCookieTransform.Decode(Byte[] encoded)
  26. at Microsoft.IdentityModel.Tokens.SessionSecurityTokenHandler.ApplyTransforms(Byte[] cookie, Boolean outbound)
  27. at Microsoft.IdentityModel.Tokens.SessionSecurityTokenHandler.ReadToken(XmlReader reader, SecurityTokenResolver tokenResolver)
  28. at Microsoft.IdentityModel.Tokens.SessionSecurityTokenHandler.ReadToken(Byte[] token, SecurityTokenResolver tokenResolver)
  29. at Microsoft.IdentityModel.Web.SessionAuthenticationModule.ReadSessionTokenFromCookie(Byte[] sessionCookie)
  30. at Microsoft.IdentityModel.Web.SessionAuthenticationModule.TryReadSessionTokenFromCookie(SessionSecurityToken& sessionToken)
  31. at Microsoft.IdentityModel.Web.SessionAuthenticationModule.OnAuthenticateRequest(Object sender, EventArgs eventArgs)
  32. at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
  33. at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
  34.  
  35. void CustomSessionAuthenticationModule_SessionSecurityTokenReceived( object sender, SessionSecurityTokenReceivedEventArgs e )
  36. {
  37. DateTime now = DateTime.UtcNow;
  38. DateTime validFrom = e.SessionToken.ValidFrom;
  39. DateTime validTo = e.SessionToken.ValidTo;
  40.  
  41. double tokenLifetime = (validTo - validFrom).TotalMinutes;
  42.  
  43. SessionAuthenticationModule sam = sender as SessionAuthenticationModule;
  44.  
  45. if( now < validTo && now > validFrom.AddMinutes( tokenLifetime / 2 ) )
  46. {
  47. e.SessionToken = sam.CreateSessionSecurityToken(
  48. e.SessionToken.ClaimsPrincipal, e.SessionToken.Context,
  49. now, now.AddMinutes( tokenLifetime ), e.SessionToken.IsPersistent );
  50. e.ReissueCookie = true;
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment