FormsAuthentication에는 인증 티켓을 밀고 당기는 암호화 및 암호 해독 방법이 있습니다. 역할에는 많은 방법이 있지만 사용되는 암호화 유형이나 해독 방법을 알려주지는 않습니다. 누구든지 올바른 방향으로 나를 가리킬 수 있습니까? 나는 테스트를 위해 역할 쿠키를 조롱 할 수 있어야한다.역할 쿠키는 어떻게 암호화됩니까?
편집 1 : 여기
난 아직도 데 문제의 예입니다. 여기
SetLoggedInUserInHttpContext(User, Roles.GetRolesForUser(User.UserID.ToString()));
RQUserMembership member = new RQUserMembership();
QUserMembership mem = member.GetByUserAndPass(User.Username, User.Password);
FormsAuthentication.SetAuthCookie(mem.UserId.ToString(), true);
QGlobals.expireLoginProxyID();
RQLoginAttempt.LogSuccessfulAttempt(User.Username);
는 사용자의 설정입니다
public static bool SetLoggedInUserInHttpContext(QUser User, string[] roles = null) {
if (HttpContext.Current != null) {
if (roles == null) {
roles = Roles.GetRolesForUser(User.UserID.ToString());
}
GenericIdentity genericIdentity = new GenericIdentity(User.UserID.ToString());
RolePrincipal genericUser = new RolePrincipal(genericIdentity); //rolesToSet
HttpContext.Current.User = genericUser;
return (User.UserID == QGlobals.GetLoggedInUserID());
} else {
return false;
}
}
바이트 [] 얻기 위해 내 시도 :
HttpContext blah = HttpContext.Current;
string blah2 = HttpContext.Current.Request.Cookies[".ASPXROLES"].Value;
byte[] bytes = new byte[blah2.Length * sizeof(char)];
System.Buffer.BlockCopy(blah2.ToCharArray(), 0, bytes, 0, bytes.Length);
byte[] blah3 = MachineKey.Unprotect(bytes);
var str = System.Text.Encoding.Default.GetString(blah3);
지금 blah3 = MachineKey.Unprotect(bytes);
Error occurred during a cryptographic operation.
at System.Web.Security.Cryptography.HomogenizingCryptoServiceWrapper.HomogenizeErrors(Func`2 func, Byte[] input)
at System.Web.Security.Cryptography.HomogenizingCryptoServiceWrapper.Unprotect(Byte[] protectedData)
at System.Web.Security.MachineKey.Unprotect(ICryptoServiceProvider cryptoServiceProvider, Byte[] protectedData, String[] purposes)
at System.Web.Security.MachineKey.Unprotect(Byte[] protectedData, String[] purposes)
at Quorra.Repositories.RQUser.GetUserHomePageStats(Int32 UserID, Int32 HourInterval) in e:\Code\quorra\Quorra.Domain\Repositories\RQUser.cs:line 133
at Quorra.Admin.Controllers.HomeController.Home(Nullable`1 refreshBasketCount) in e:\Code\quorra\Quorra.Admin\Controllers\HomeController.cs:line 31
at lambda_method(Closure , ControllerBase , Object[])
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.ActionInvocation.InvokeSynchronousActionMethod()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult](IAsyncResult asyncResult, Object tag)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass48.<InvokeActionMethodFilterAsynchronouslyRecursive>b__41()
에 오류가납니다을
모든 방향이 app이됩니다. recited.
편집 2 :
내가 명확히하려면 사용자 그래서 Roles.IsUserInRole();
작품에 대한 역할 쿠키를 설정 할 수 있어야합니다. 지금은 userId를 전달하면 역할 공급자에게 가서 해당 메서드를 실행하지만 로그온 한 사용자를 확인하기 때문에 쿠키가 테스트됩니다. 실제로 암호를 해독 할 필요가 없습니다. 암호화 할 수 있으면 충분합니다.
"테스트를 위해 역할 쿠키를 조롱하는 것"이 무슨 뜻인지 분명히 할 수 있습니까? MachineKey.Unprotect API는 의도적으로 .ASPXAUTH 또는 .ASPXROLES 쿠키를 해독하는 데 사용할 수 없습니다. – Levi
몇 가지 설명을 추가했습니다. 다른 것이 필요한지 알려주세요. – Recursor