Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Html.AntiForgeryToken helper throws exception on Mono #847

@Praburaj

Description

@Praburaj

https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNet.Mvc.Core/AntiForgery/BinaryBlob.cs#L96

private static byte[] GenerateNewToken(int bitLength)
        {
            var data = new byte[bitLength / 8];
            CryptRand.FillBuffer(new ArraySegment<byte>(data));
            return data;
        }
System.DllNotFoundException: bcrypt.dll
  at (wrapper managed-to-native) Microsoft.AspNet.Security.DataProtection.UnsafeNativeMethods:BCryptGenRandom (intptr,byte*,uint,Microsoft.AspNet.Security.DataProtection.BCryptGenRandomFlags)
  at Microsoft.AspNet.Security.DataProtection.BCryptUtil.GenRandom (System.Byte* buffer, Int32 bufferBytes) [0x00000] in <filename unknown>:0 
  at Microsoft.AspNet.Security.DataProtection.CryptRand.FillBuffer (ArraySegment`1 buffer) [0x00000] in <filename unknown>:0 
  at Microsoft.AspNet.Mvc.BinaryBlob.GenerateNewToken (Int32 bitLength) [0x00000] in <filename unknown>:0 
  at Microsoft.AspNet.Mvc.BinaryBlob..ctor (Int32 bitLength) [0x00000] in <filename unknown>:0 
  at Microsoft.AspNet.Mvc.AntiForgeryToken.get_SecurityToken () [0x00000] in <filename unknown>:0 
  at Microsoft.AspNet.Mvc.TokenProvider.GenerateFormToken (Microsoft.AspNet.Http.HttpContext httpContext, System.Security.Claims.ClaimsIdentity identity, Microsoft.AspNet.Mvc.AntiForgeryToken cookieToken) [0x00000] in <filename unknown>:0 
  at Microsoft.AspNet.Mvc.AntiForgeryWorker.GetTokens (Microsoft.AspNet.Http.HttpContext httpContext, Microsoft.AspNet.Mvc.AntiForgeryToken oldCookieToken) [0x00000] in <filename unknown>:0 
  at Microsoft.AspNet.Mvc.AntiForgeryWorker.GetFormInputElement (Microsoft.AspNet.Http.HttpContext httpContext) [0x00000] in <filename unknown>:0 
  at Microsoft.AspNet.Mvc.AntiForgery.GetHtml (Microsoft.AspNet.Http.HttpContext context) [0x00000] in <filename unknown>:0 
  at Microsoft.AspNet.Mvc.Rendering.HtmlHelper.AntiForgeryToken () [0x00000] in <filename unknown>:0 
  at ASP.Views_StoreManager_Edit_cshtml+<ExecuteAsync>d__1.MoveNext () [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <filename unknown>:0 
  at Microsoft.AspNet.Mvc.Razor.RazorView+<RenderPageCoreAsync>d__1.MoveNext () [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <filename unknown>:0 
  at Microsoft.AspNet.Mvc.Razor.RazorView+<RenderPageAsync>d__1.MoveNext () [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in <filename unknown>:0 
  at Microsoft.AspNet.Mvc.Razor.RazorView+<RenderAsync>d__1.MoveNext () [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <filename unknown>:0 
  at Microsoft.AspNet.Mvc.ViewResult+<ExecuteResultAsync>d__1.MoveNext () [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <filename unknown>:0 
  at Microsoft.AspNet.Mvc.ReflectedActionInvoker+<InvokeActionResult>d__1.MoveNext () [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <filename unknown>:0 
  at Microsoft.AspNet.Mvc.ReflectedActionInvoker+<InvokeActionResultFilter>d__1.MoveNext () [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 
  at Microsoft.AspNet.Mvc.ReflectedActionInvoker+<InvokeActionResultWithFilters>d__1.MoveNext () [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <filename unknown>:0 
  at Microsoft.AspNet.Mvc.ReflectedActionInvoker+<InvokeActionAsync>d__1.MoveNext () [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <filename unknown>:0 
  at Microsoft.AspNet.Mvc.MvcRouteHandler+<RouteAsync>d__1.MoveNext () [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <filename unknown>:0 
  at Microsoft.AspNet.Routing.Template.TemplateRoute+<RouteAsync>d__1.MoveNext () [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <filename unknown>:0 
  at Microsoft.AspNet.Routing.RouteCollection+<RouteAsync>d__1.MoveNext () [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <filename unknown>:0 
  at Microsoft.AspNet.Builder.RouterMiddleware+<Invoke>d__1.MoveNext () [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <filename unknown>:0 
  at MusicStore.Startup+<<Configure>b__6>d__0.MoveNext () [0x00000] in <filename unknown>:0 

Recommendation from Levi:
MVC should instead be using the RandomNumberGenerator class. CryptRand was just a temporary workaround because the CLR team didn’t have the crypto libraries ported over.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions