samuel-lucas6 / Geralt

A modern cryptographic library for .NET 8+ based on libsodium and inspired by Monocypher.
https://www.geralt.xyz/
MIT License
48 stars 3 forks source link

MAUI/Android/iOS support #7

Open stevehansen opened 1 year ago

stevehansen commented 1 year ago

Love that this targets .NET 6/7 but it seems when trying to use this on Android it just fails to load:

Loaded assembly: /data/data/test/files/.__override__/Geralt.dll [External]
[monodroid-assembly] Shared library 'libsodium' not loaded, p/invoke 'randombytes_buf' may fail
[monodroid-assembly] Shared library 'libsodium' not loaded, p/invoke 'sodium_library_version_major' may fail
[monodroid-assembly] Shared library 'libsodium' not loaded, p/invoke 'sodium_library_version_minor' may fail
[monodroid-assembly] Shared library 'libsodium' not loaded, p/invoke 'sodium_version_string' may fail
[monodroid-assembly] Shared library 'libsodium' not loaded, p/invoke 'sodium_set_misuse_handler' may fail
[monodroid-assembly] Shared library 'libsodium' not loaded, p/invoke 'sodium_init' may fail
[monodroid-assembly] Shared library 'libsodium' not loaded, p/invoke 'sodium_library_version_major' may fail
**System.PlatformNotSupportedException:** 'Unable to access the libsodium DLL. Geralt may not be supported on this platform, or this machine may be missing the Visual C++ Redistributable on Windows.'

What do I need to do to get this working on Android?

samuel-lucas6 commented 1 year ago

Glad you like the library. Support for Android/iOS would be very nice, but I unfortunately don't have any experience with either, and the libsodium NuGet doesn't provide pre-compiled binaries for them. You should be able to use a build script from here, but I'm not sure if anything else needs to be done.

samuel-lucas6 commented 1 year ago

@stevehansen Have you had any luck?

stevehansen commented 1 year ago

@samuel-lucas6 https://stackoverflow.com/a/56297065/295296 found some instructions here, about building the libsodium.so in and embedding them, I tried some of it last week but didn't succeed yet (instruction for Xamarin, not completely compatible with MAUI). I'll see if I can make another attempt this week.

Jack-Edwards commented 1 year ago

Looking at the swift-sodium repo, it looks like the right way to do this would be to include a pre-compiled instance of libsodium in the project.

swift-sodium Clibsodium.xcframework

Or perhaps there is a way to link repos and include a compilation pre-build step in the .csproj. Though this seems prone to failure in case a backwards-incompatible change is introduced in libsodium.

samuel-lucas6 commented 1 year ago

Ok it seems I need to implement a change NSec did for iOS support.

shipitfaster commented 7 months ago

Bumping this thread as I, too, would like to run on Android. Were @Jack-Edwards or @stevehansen able to find an alternate solution?

samuel-lucas6 commented 7 months ago

I've opened a discussion in the libsodium repo. Assuming progress is made there, the issue becomes how to implement support here if any changes are required and how to test that it works.

samuel-lucas6 commented 6 months ago

Seems like the new NuGet package supports win-arm64 and ios-arm64 but still not Android.