Isopoh.Cryptography.Argon2 icon indicating copy to clipboard operation
Isopoh.Cryptography.Argon2 copied to clipboard

Running on Hololens UWP

Open Xan2063 opened this issue 4 years ago • 3 comments

Hi everyone, I tried using Argon2 on Hololens, but there seem to be problems accessing the windows api from a UWP project. Sometimes Hololens is a bit special...so not sure, if it is a general UWP Problem.

Here is the stack trace I got. I think UWP is restricted on accessing native APIs, but I did not dig into this. Do you have any experience on this?

Thanks Alex

System.TypeInitializationException: The type initializer for 'Isopoh.Cryptography.SecureArray.SecureArray' threw an exception. ---> System.NotSupportedException: No SecureArray.DefaultCall support for current operating system (whatever that is, maybe "Microsoft Windows NT 10.0.19041.0", I think I know Windows, Linux, OSX, and web - and maybe iOS...). You  don't have to use the default SecureArrayCall - you can pass in a version of the calls that work for your operating system.
  at Isopoh.Cryptography.SecureArray.SecureArray.get_DefaultCall () [0x00000] in <00000000000000000000000000000000>:0 
  at Isopoh.Cryptography.SecureArray.SecureArray..cctor () [0x00000] in <00000000000000000000000000000000>:0 
  at Isopoh.Cryptography.SecureArray.SecureArray`1[T]..ctor (System.Int32 size, Isopoh.Cryptography.SecureArray.SecureArrayType type, Isopoh.Cryptography.SecureArray.SecureArrayCall call) [0x00000] in <00000000000000000000000000000000>:0 
  at Isopoh.Cryptography.SecureArray.SecureArray`1[T].Best (System.Int32 size, Isopoh.Cryptography.SecureArray.SecureArrayCall secureArrayCall) [0x00000] in <00000000000000000000000000000000>:0 
  at Isopoh.Cryptography.Argon2.Argon2.Hash (System.String password, System.String secret, System.Int32 timeCost, System.Int32 memoryCost, System.Int32 parallelism, Isopoh.Cryptography.Argon2.Argon2Type type, System.Int32 hashLength, Isopoh.Cryptography.SecureArray.SecureArrayCall secureArrayCall) [0x00000] in <00000000000000000000000000000000>:0 
  at Isopoh.Cryptography.Argon2.Argon2.Hash (System.String password, System.Int32 timeCost, System.Int32 memoryCost, System.Int32 parallelism, Isopoh.Cryptography.Argon2.Argon2Type type, System.Int32 hashLength, Isopoh.Cryptography.SecureArray.SecureArrayCall secureArrayCall) [0x00000] in <00000000000000000000000000000000>:0 
  at StoredCreds.PrepareCredentialsForStorage (Credentials credentials) [0x00000] in <00000000000000000000000000000000>:0 
  at UserSelectionMode.Activate (NavigationParameters navigationParameters) [0x00000] in <00000000000000000000000000000000>:0 

Xan2063 avatar Nov 11 '20 09:11 Xan2063

You know, I coded very early on the Hololens and didn't think to try this library on it...

The issue is with trying to be fancy in assuring memory gets locked and zeroed with SecureArray by calling into the OS.

I'll work on getting that working in the Hololens.

mheyman avatar Nov 13 '20 16:11 mheyman

Maybe the issue is with Hololens2 which is ARM-based. Is there a way to help you with that issue. I think the file system of the hololens is not open, so I cannot check dlls easily.

Xan2063 avatar Nov 16 '20 08:11 Xan2063

I don't think it is an ARM vs Intel issue because P/Invoke works on both (according to interwebs and my initial fiddling).

And, I've found contradictory documentation about calling these things. I did find https://docs.microsoft.com/en-us/previous-versions/mt186421(v=vs.85) which, I think, lists some of the things I can P/Invoke. I’m pretty sure that isn’t all the things because the stackoverflow tells me to detect if the code is running on UWP is to P/Invoke GetCurrentPackageFullName(). That isn’t in the list.

As a workaround for now, you can create your own Argon2Config and set the SecureArrayCall field to an instance of DefaultWebSecureArrayCall. Then use that Argon2Config in calls to hash and verify. That uses the version of SecureArray that runs in webassembly. That version doesn't attempt to lock memory in RAM and only hopes to zero the memory. It is hard to zero memory when you are done with it in light of optimizers and such that notice "you are trying to zero the memory but you don't use it afterwards so I'm going to help you by not eating CPU performing that action" :-)

mheyman avatar Nov 17 '20 11:11 mheyman