Pkcs11Interop icon indicating copy to clipboard operation
Pkcs11Interop copied to clipboard

MacCatalyst - Pkcs11Interop is not supported on this platform

Open angelru opened this issue 2 years ago • 25 comments

I am using NET MAUI in with mac catalyst and I get this exception

   at Net.Pkcs11Interop.Common.Platform.DetectPlatform()
   at Net.Pkcs11Interop.Common.Platform.get_IsLinux()
   at Net.Pkcs11Interop.Common.Platform.get_NativeULongSize()
   at Net.Pkcs11Interop.HighLevelAPI.Factories.Pkcs11LibraryFactory..ctor()
   at Net.Pkcs11Interop.HighLevelAPI.Pkcs11InteropFactories..ctor()

angelru avatar Nov 17 '22 12:11 angelru

Hi @jariq, do you know anything about it?

angelru avatar Nov 21 '22 07:11 angelru

Nope. I am not currently working on anything maccatalyst related.

jariq avatar Nov 21 '22 09:11 jariq

@jariq

I don't know why your library doesn't detect an application that runs with MacCatalyst, I downloaded the project and returned _isMacOsX = true

but it returns an exception: {System.DllNotFoundException: libdl at Net.Pkcs11Interop.Common.UnmanagedLibrary.Load(String fileName) in /Users/development/Desktop/src/Pkcs11Interop/Common/UnmanagedLibrary.cs:line 74 at Net.Pkcs11Interop.LowLevelAPI80.Pkcs.11 ctor

and load library: "/usr/local/lib/libeTPkcs11.dylib"

I think I remember it used to work.


MMP : warning MM2006: Native library 'libdl' was referenced but could not be found.
MMP : warning MM2009: Referenced by Net.Pkcs11Interop.Common.NativeMethods.dlopen
MMP : warning MM2009: Referenced by Net.Pkcs11Interop.Common.NativeMethods.dlerror
MMP : warning MM2009: Referenced by Net.Pkcs11Interop.Common.NativeMethods.dlclose
MMP : warning MM2009: Referenced by Net.Pkcs11Interop.Common.NativeMethods.dlerror
MMP : warning MM2009: Referenced by Net.Pkcs11Interop.Common.NativeMethods.dlsym
MMP : warning MM2009: Referenced by Net.Pkcs11Interop.Common.NativeMethods.dlerror

how can i add https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem.ismaccatalyst?view=net-7.0

angelru avatar Nov 24 '22 07:11 angelru

@angelru it's really hard for me to understand what your problem is and help you because you're describing it in a multiple comments in a quite chaotic way. Please be as detailed as you can be and provide:

  • the version of Pkcs11Interop you are using
  • the version of .NET you are using
  • the version of operating system you are using
  • the description of the actual result (what is actually happening) and the expected result (what would you expect to happen instead)
  • the exception you are getting along with a full stack trace
  • snippet of the problematic code

jariq avatar Nov 24 '22 11:11 jariq

I am using the latest version of Pkcs11Interop and .NET 7 with MAUI.

I got it to compile the application for MacCatalyst with the https://github.com/Pkcs11Interop/empty-pkcs11/pull/3

But when using:

factories = new Pkcs11InteropFactories(); 

get exception:

   at Net.Pkcs11Interop.Common.Platform.DetectPlatform()
   at Net.Pkcs11Interop.Common.Platform.get_IsLinux()
   at Net.Pkcs11Interop.Common.Platform.get_NativeULongSize()
   at Net.Pkcs11Interop.HighLevelAPI.Factories.Pkcs11LibraryFactory..ctor()
   at Net.Pkcs11Interop.HighLevelAPI.Pkcs11InteropFactories..ctor()

angelru avatar Nov 24 '22 13:11 angelru

Information you provided:

  • the version of Pkcs11Interop you are using: 5.1.2
  • the version of .NET you are using: .NET 7
  • the description of the actual result (what is actually happening) and the expected result (what would you expect to happen instead): Gets exception while calling factories = new Pkcs11InteropFactories();
  • snippet of the problematic code: factories = new Pkcs11InteropFactories();

Information you still need to provide:

  • the version of operating system you are using
  • the exception you are getting along with a full stack trace

jariq avatar Nov 24 '22 13:11 jariq

NET 7 MAUI with maccatalyst

macOS Monterey 12.6.1

Pkcs11Interop is not supported on this platform

   at Net.Pkcs11Interop.Common.Platform.DetectPlatform() in /Users/desarrollo/Desktop/src/Pkcs11Interop/Common/Platform.cs:line 217
   at Net.Pkcs11Interop.Common.Platform.get_IsLinux() in /Users/desarrollo/Desktop/src/Pkcs11Interop/Common/Platform.cs:line 88
   at Net.Pkcs11Interop.Common.Platform.get_NativeULongSize() in /Users/desarrollo/Desktop/src/Pkcs11Interop/Common/Platform.cs:line 127
   at Net.Pkcs11Interop.HighLevelAPI.Factories.Pkcs11LibraryFactory..ctor() in /Users/desarrollo/Desktop/src/Pkcs11Interop/HighLevelAPI/Factories/Pkcs11LibraryFactory.cs:line 43
   at Net.Pkcs11Interop.HighLevelAPI.Pkcs11InteropFactories..ctor() in /Users/desarrollo/Desktop/src/Pkcs11Interop/HighLevelAPI/Pkcs11InteropFactories.cs:line 150

angelru avatar Nov 24 '22 15:11 angelru

OK so let's sum it up once again:

  • the version of Pkcs11Interop you are using:

    Pkcs11Interop 5.1.2

  • the version of .NET you are using:

    .NET 7 MAUI with maccatalyst

  • the version of operating system you are using:

    macOS Monterey 12.6.1

  • the description of the actual result (what is actually happening) and the expected result (what would you expect to happen instead):

    Gets exception while calling factories = new Pkcs11InteropFactories();

  • snippet of the problematic code:

    factories = new Pkcs11InteropFactories();

  • the exception you are getting:

    Net.Pkcs11Interop.Common.UnsupportedPlatformException thrown at https://github.com/Pkcs11Interop/Pkcs11Interop/blob/5.1.2/src/Pkcs11Interop/Common/Platform.cs#L217

jariq avatar Nov 24 '22 16:11 jariq

Could you please add following code to your application and let me know what it prints to STDOUT?

Console.WriteLine($"Is Windows: {System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Windows)}");
Console.WriteLine($"Is Windows: {System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Linux)}");
Console.WriteLine($"Is Windows: {System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.OSX)}");

jariq avatar Nov 24 '22 16:11 jariq

Console.WriteLine($"Is Windows: {System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Windows)}");
Console.WriteLine($"Is Windows: {System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Linux)}");
Console.WriteLine($"Is Windows: {System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.OSX)}");
2022-11-24 20:18:59.281 RADesktop[693:6870] Is Windows: False
2022-11-24 20:18:59.281 RADesktop[693:6870] Is Windows: False
2022-11-24 20:18:59.281 RADesktop[693:6870] Is Windows: False

I saw this: https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem.ismaccatalyst?view=net-7.0

OperatingSystem.IsMacCatalyst()

angelru avatar Nov 24 '22 19:11 angelru

Welp, System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.OSX) returning false in .NET 7 MAUI app running on macOS 12.6.1 is an issue that should be fixed in https://github.com/dotnet/runtime/.

jariq avatar Nov 24 '22 19:11 jariq

I understand it's a NET problem, but one thing, I unload your project and return _isMacOsX = true where the exception is thrown.

and then it tells me this: {System.DllNotFoundException: libdl at Net.Pkcs11Interop.Common.UnmanagedLibrary.Load(String fileName) in /Users/development/Desktop/src/Pkcs11Interop/Common/UnmanagedLibrary.cs:line 74 at Net.Pkcs11Interop.LowLevelAPI80.Pkcs.11 ctor

angelru avatar Nov 24 '22 20:11 angelru

@jariq

I don't know why your library doesn't detect an application that runs with MacCatalyst, I downloaded the project and returned _isMacOsX = true

but it returns an exception: {System.DllNotFoundException: libdl at Net.Pkcs11Interop.Common.UnmanagedLibrary.Load(String fileName) in /Users/development/Desktop/src/Pkcs11Interop/Common/UnmanagedLibrary.cs:line 74 at Net.Pkcs11Interop.LowLevelAPI80.Pkcs.11 ctor

and load library: "/usr/local/lib/libeTPkcs11.dylib"

I think I remember it used to work.


MMP : warning MM2006: Native library 'libdl' was referenced but could not be found.
MMP : warning MM2009: Referenced by Net.Pkcs11Interop.Common.NativeMethods.dlopen
MMP : warning MM2009: Referenced by Net.Pkcs11Interop.Common.NativeMethods.dlerror
MMP : warning MM2009: Referenced by Net.Pkcs11Interop.Common.NativeMethods.dlclose
MMP : warning MM2009: Referenced by Net.Pkcs11Interop.Common.NativeMethods.dlerror
MMP : warning MM2009: Referenced by Net.Pkcs11Interop.Common.NativeMethods.dlsym
MMP : warning MM2009: Referenced by Net.Pkcs11Interop.Common.NativeMethods.dlerror

how can i add https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem.ismaccatalyst?view=net-7.0

Hi, I encounter the same issue. By running step by step debug, I also have an exception stating that libdl is missing :

NativeMethods.cs this method :

/// <summary>
/// Loads the dynamic library
/// </summary>
/// <param name='filename'>Library filename.</param>
/// <param name='flag'>RTLD_LAZY for lazy function call binding or RTLD_NOW immediate function call binding.</param>
/// <returns>Handle for the dynamic library if successful, IntPtr.Zero otherwise.</returns>
[DllImport("libdl", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
internal static extern IntPtr dlopen(string filename, int flag);

Exception :

DllNotFoundException : libdl

StackTrace :

at Net.Pkcs11Interop.Common.UnmanagedLibrary.Load(String fileName) in /Users/yr/Projects/turbosignv3/Pkcs11Interop-master/src/Pkcs11Interop/Common/UnmanagedLibrary.cs:line 74 at Net.Pkcs11Interop.LowLevelAPI80.Pkcs11Library..ctor(String libraryPath) in /Users/yr/Projects/turbosignv3/Pkcs11Interop-master/src/Pkcs11Interop/LowLevelAPI80/Pkcs11Library.cs:line 66 at Net.Pkcs11Interop.HighLevelAPI80.Pkcs11Library..ctor(Pkcs11InteropFactories factories, String libraryPath, AppType appType) in /Users/yr/Projects/turbosignv3/Pkcs11Interop-master/src/Pkcs11Interop/HighLevelAPI80/Pkcs11Library.cs:line 120 at Net.Pkcs11Interop.HighLevelAPI80.Factories.Pkcs11LibraryFactory.LoadPkcs11Library(Pkcs11InteropFactories factories, String libraryPath, AppType appType) in /Users/yr/Projects/turbosignv3/Pkcs11Interop-master/src/Pkcs11Interop/HighLevelAPI80/Factories/Pkcs11LibraryFactory.cs:line 44 at Net.Pkcs11Interop.HighLevelAPI.Factories.Pkcs11LibraryFactory.LoadPkcs11Library(Pkcs11InteropFactories factories, String libraryPath, AppType appType) in /Users/yr/Projects/turbosignv3/Pkcs11Interop-master/src/Pkcs11Interop/HighLevelAPI/Factories/Pkcs11LibraryFactory.cs:line 68 at turbosignv3.MainPage.TestPkcs11() in /Users/yr/Projects/turbosignv3/turbosignv3/MainPage.xaml.cs:line 50

Thordax avatar Nov 24 '22 20:11 Thordax

Could any of you please share with me a minimal MAUI app that replicates the problem? So I can easily run Minimal, Reproducible Example.

jariq avatar Nov 24 '22 20:11 jariq

Is this project Ok for you ? You just have to click the first button after launching the project

https://we.tl/t-7UGrF2CS4c

Thordax avatar Nov 24 '22 20:11 Thordax

@Thordax @jariq

Something must have changed in .NET MAUI & MacCatalyst or macOS in some update, a few months ago it worked fine.

angelru avatar Nov 25 '22 05:11 angelru

@Thordax the project you provided does not build on my mac. I had to disable Android and iOS platforms in turbosingv3 project in order to get rid of some errors but now with only maccatalyst left it still does not build with the following error:

/usr/local/share/dotnet/packs/Microsoft.MacCatalyst.Sdk/15.4.2372/targets/Xamarin.Shared.Sdk.targets(3,3): Error: clang++ exited with code 1:
Undefined symbols for architecture x86_64:
    "_C_CancelFunction", referenced from:
          -u command line option
    "_C_CloseAllSessions", referenced from:
          -u command line option

I'd say it's missing empty-pkcs11 library during the linking phase. Any hint how to fix this?

jariq avatar Nov 25 '22 09:11 jariq

@Thordax the project you provided does not build on my mac. I had to disable Android and iOS platforms in turbosingv3 project in order to get rid of some errors but now with only maccatalyst left it still does not build with the following error:

/usr/local/share/dotnet/packs/Microsoft.MacCatalyst.Sdk/15.4.2372/targets/Xamarin.Shared.Sdk.targets(3,3): Error: clang++ exited with code 1:
Undefined symbols for architecture x86_64:
    "_C_CancelFunction", referenced from:
          -u command line option
    "_C_CloseAllSessions", referenced from:
          -u command line option

I'd say it's missing empty-pkcs11 library during the linking phase. Any hint how to fix this?

<ItemGroup>
		<NativeReference Include="Libs/libempty-pkcs11-catalyst.dylib">
			<Kind>Dynamic</Kind>
			<SmartLink>False</SmartLink>
		</NativeReference>
	</ItemGroup>

Will it be solved by changing the linker?

angelru avatar Nov 25 '22 10:11 angelru

Hi @angelru I tried to add that reference in the csproj file, but I suppose the file "libempty-pkcs11-catalyst.dylib" is missing.

How could I get that file ? Should I compile it somehow ?

Thordax avatar Nov 25 '22 12:11 Thordax

Hi @angelru I tried to add that reference in the csproj file, but I suppose the file "libempty-pkcs11-catalyst.dylib" is missing.

How could I get that file ? Should I compile it somehow ?

Accept pull https://github.com/Pkcs11Interop/empty-pkcs11/pull/3/files

angelru avatar Nov 25 '22 12:11 angelru

Thanks @angelru I got the same error unfortunately (missing file "libdl", and I don't know how to get it).

Without it, I can't call the native method "dlopen" in the NativeMethod.cs file :

[DllImport("libdl", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
internal static extern IntPtr dlopen(string filename, int flag);

Thordax avatar Nov 25 '22 13:11 Thordax

Thanks @angelru I got the same error unfortunately (missing file "libdl", and I don't know how to get it).

Without it, I can't call the native method "dlopen" in the NativeMethod.cs file :

[DllImport("libdl", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
internal static extern IntPtr dlopen(string filename, int flag);

yes, same issue...

angelru avatar Nov 25 '22 13:11 angelru

@jariq @Thordax something new?

angelru avatar Jan 20 '23 10:01 angelru

is there news?

angelru avatar Mar 23 '24 06:03 angelru

Nope. I am not currently working on anything MAUI or maccatalyst related.

jariq avatar Mar 23 '24 10:03 jariq