Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pkcs11Interop is not supported on this platform #215

Open
angelru opened this issue Nov 17, 2022 · 25 comments
Open

Pkcs11Interop is not supported on this platform #215

angelru opened this issue Nov 17, 2022 · 25 comments

Comments

@angelru
Copy link

angelru commented Nov 17, 2022

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
Copy link
Author

angelru commented Nov 21, 2022

Hi @jariq, do you know anything about it?

@jariq
Copy link
Member

jariq commented Nov 21, 2022

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

@angelru
Copy link
Author

angelru commented Nov 24, 2022

@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

@jariq
Copy link
Member

jariq commented Nov 24, 2022

@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

@angelru
Copy link
Author

angelru commented Nov 24, 2022

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

I got it to compile the application for MacCatalyst with the
Pkcs11Interop/empty-pkcs11#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()

@jariq
Copy link
Member

jariq commented Nov 24, 2022

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

@angelru
Copy link
Author

angelru commented Nov 24, 2022

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

@jariq
Copy link
Member

jariq commented Nov 24, 2022

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
Copy link
Member

jariq commented Nov 24, 2022

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)}");

@angelru
Copy link
Author

angelru commented Nov 24, 2022

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()

@jariq
Copy link
Member

jariq commented Nov 24, 2022

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/.

@angelru
Copy link
Author

angelru commented Nov 24, 2022

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

@Thordax
Copy link

Thordax commented Nov 24, 2022

@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

@jariq
Copy link
Member

jariq commented Nov 24, 2022

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

@Thordax
Copy link

Thordax commented Nov 24, 2022

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

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

@angelru
Copy link
Author

angelru commented Nov 25, 2022

@Thordax @jariq

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

@jariq
Copy link
Member

jariq commented Nov 25, 2022

@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?

@angelru
Copy link
Author

angelru commented Nov 25, 2022

@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?

@Thordax
Copy link

Thordax commented Nov 25, 2022

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 ?

@angelru
Copy link
Author

angelru commented Nov 25, 2022

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

@Thordax
Copy link

Thordax commented Nov 25, 2022

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);

@angelru
Copy link
Author

angelru commented Nov 25, 2022

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
Copy link
Author

angelru commented Jan 20, 2023

@jariq @Thordax
something new?

@angelru
Copy link
Author

angelru commented Mar 23, 2024

is there news?

@jariq
Copy link
Member

jariq commented Mar 23, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants