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

Better handling of attempts to load PKCS#11 library with incorrect bitness #28

Closed
jariq opened this issue Jun 14, 2016 · 0 comments
Closed
Assignees

Comments

@jariq
Copy link
Member

jariq commented Jun 14, 2016

Pkcs11Interop 3.1 throws exception with hard to understand message "Unable to load library: %1 is not a valid Win32 application" when there is an attempt to load 32-bit PKCS#11 library in 64-bit runtime or 64-bit PKCS#11 library in 32-bit runtime. This problem seems to be hit quite frequently (e.g. in #25).

Code generating this message was removed in 4e45617 as a side effect of adding support for netstandard1.1 compatible platforms so this message should never appear in the exception again but I still believe such frequent error deserves its own exception type or at least exception message.

ERROR_BAD_EXE_FORMAT error code returned by Marshal.GetLastWin32Error() seems to be a natural choice for detection whether there was an attempt to load PKCS#11 library with incorrect bitness but I am not sure whether the same error code is returned on all supported platforms so I will need to investigate this further and "manually" check the code (or find other solution) on all platforms.

Following table tracks my progress:

Platform Runtime Solution
Windows 10 net20 32-bit GetLastWin32Error() returns 0xC1
Windows 10 net20 64-bit GetLastWin32Error() returns 0xC1
Windows 10 net40 32-bit GetLastWin32Error() returns 0xC1
Windows 10 net40 64-bit GetLastWin32Error() returns 0xC1
Windows 10 sl5 32-bit I can't get it working on 64-bit OS
Windows 10 sl5 64-bit GetLastWin32Error() returns 0xC1
Windows 10 corefx 32-bit GetLastWin32Error() returns 0xC1
Windows 10 corefx 64-bit GetLastWin32Error() returns 0xC1
Linux mono/corefx 5th byte of ELF binary provides architecture info
Mac OS X mono/corefx dlopen_preflight checks if the library architecture is compatible with the current process
Android Xamarin 5th byte of ELF binary provides architecture info
iOS Xamarin PKCS#11 library is linked statically so it cannot be targeting invalid platform
@jariq jariq self-assigned this Jun 14, 2016
jariq added a commit that referenced this issue Jun 24, 2016
Partial solution (currently Windows only) for issue #28
jariq added a commit that referenced this issue Jun 24, 2016
jariq added a commit that referenced this issue Jun 24, 2016
jariq added a commit that referenced this issue Jun 25, 2016
Partial solution for issue #28
@jariq jariq closed this as completed Jun 25, 2016
@Pkcs11Interop Pkcs11Interop deleted a comment from Goncharuk-Nikita Feb 7, 2018
@Pkcs11Interop Pkcs11Interop deleted a comment from Goncharuk-Nikita Feb 7, 2018
@Pkcs11Interop Pkcs11Interop locked as resolved and limited conversation to collaborators Feb 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant