Pkcs11Interop
Pkcs11Interop copied to clipboard
MacCatalyst - Pkcs11Interop is not supported on this platform
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()
Hi @jariq, do you know anything about it?
Nope. I am not currently working on anything maccatalyst related.
@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 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
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()
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
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
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
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)}");
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()
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/.
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
@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
Could any of you please share with me a minimal MAUI app that replicates the problem? So I can easily run Minimal, Reproducible Example.
Is this project Ok for you ? You just have to click the first button after launching the project
https://we.tl/t-7UGrF2CS4c
@Thordax @jariq
Something must have changed in .NET MAUI & MacCatalyst or macOS in some update, a few months ago it worked fine.
@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?
@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?
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 ?
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
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);
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...
@jariq @Thordax something new?
is there news?
Nope. I am not currently working on anything MAUI or maccatalyst related.