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

Could not load engine on macOS #353

Open
x87-va opened this issue Sep 6, 2021 · 18 comments
Open

Could not load engine on macOS #353

x87-va opened this issue Sep 6, 2021 · 18 comments

Comments

@x87-va
Copy link

x87-va commented Sep 6, 2021

Hello.

I have issues when trying to use engine on macOS 11.5 with OpenSSL 1.1.1l installed from Homebrew.

I've built engine from branch openssl_1_1_1 with variables:

export LDFLAGS="-L/usr/local/opt/[email protected]/lib"
export CPPFLAGS="-I/usr/local/opt/[email protected]/include"
export PKG_CONFIG_PATH="/usr/local/opt/[email protected]/lib/pkgconfig"

Also OPENSSL_CONF variable points to openssl.conf from example.

gcc --version:

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.5 (clang-1205.0.22.11)
Target: x86_64-apple-darwin20.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

When I try to load engine with sh openssl engine -vvv:

4402085376:error:2506406A:DSO support routines:dlfcn_bind_func:could not bind to the requested symbol name:crypto/dso/dso_dlfcn.c:188:symname(bind_engine): dlsym(0x7fd91c61a1c0, bind_engine): symbol not found
4402085376:error:2506C06A:DSO support routines:DSO_bind_func:could not bind to the requested symbol name:crypto/dso/dso_lib.c:186:
4402085376:error:260B6068:engine routines:dynamic_load:DSO failure:crypto/engine/eng_dyn.c:427:
4402085376:error:2606A074:engine routines:ENGINE_by_id:no such engine:crypto/engine/eng_list.c:334:id=gost
4402085376:error:260BC066:engine routines:int_engine_configure:engine configuration error:crypto/engine/eng_cnf.c:141:section=gost_section, name=default_algorithms, value=ALL
4402085376:error:0E07606D:configuration file routines:module_run:module initialization error:crypto/conf/conf_mod.c:177:module=engines, value=engine_section, retcode=-1 

There is no bind_engine symbol:

nm /usr/local/opt/[email protected]/lib/engines-1.1/gost.dylib | grep bind_engine

How to fix it?

@beldmit
Copy link
Contributor

beldmit commented Sep 6, 2021

Could you please check that you didn't build openssl with -DOPENSSL_NO_DYNAMIC_ENGINE ?

@x87-va
Copy link
Author

x87-va commented Sep 6, 2021

Could you please check that you didn't build openssl with -DOPENSSL_NO_DYNAMIC_ENGINE ?

Seems like there is no such option here:
https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/[email protected]

@beldmit
Copy link
Contributor

beldmit commented Sep 6, 2021

Could you please add explicit shared option to the Configure arguments?

@x87-va
Copy link
Author

x87-va commented Sep 7, 2021

Could you please add explicit shared option to the Configure arguments?

I've tried to build openssl with shared argument:

==> perl ./Configure --prefix=/usr/local/Cellar/[email protected]/1.1.1l --openssldir=/usr/local/etc/[email protected] no-ssl3 no-ssl3-method no-zlib shared darwin64-x86_64-cc enable-ec_nist

Then installed it and rebuilt gost engine. But it didn't fix the issue.

@beldmit
Copy link
Contributor

beldmit commented Sep 7, 2021

Speaking frankly, I have no ideas. The MacOS tests run on regular basis during the CI, and the engine initialization code is here for ages. Could you check that you built the engine against the OpenSSL you built, not against the system one?

@x87-va
Copy link
Author

x87-va commented Sep 7, 2021

Speaking frankly, I have no ideas. The MacOS tests run on regular basis during the CI, and the engine initialization code is here for ages. Could you check that you built the engine against the OpenSSL you built, not against the system one?

otool -L /usr/local/Cellar/[email protected]/1.1.1l/lib/engines-1.1/gost.1.1.dylib
/usr/local/Cellar/[email protected]/1.1.1l/lib/engines-1.1/gost.1.1.dylib:
	@rpath/gost.1.1.dylib (compatibility version 1.1.0, current version 1.1.0)
	/usr/local/opt/[email protected]/lib/libcrypto.1.1.dylib (compatibility version 1.1.0, current version 1.1.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1292.100.5)

@x87-va
Copy link
Author

x87-va commented Sep 7, 2021

Maybe the issue related to compiler version? Is clang fully supported?

@beldmit
Copy link
Contributor

beldmit commented Sep 7, 2021

I didn't come across any clang-related issues before.

@x87-va
Copy link
Author

x87-va commented Sep 7, 2021

I had to modify this line https://github.com/gost-engine/engine/blob/openssl_1_1_1/CMakeLists.txt#L88
Because these variables were not resolved. Engine file was named bin/gost...dylib
Maybe this helps.

@levitte
Copy link
Contributor

levitte commented Sep 7, 2021

This was solved on the master branch with #27.
@beldmit, should I backport that? The above is exactly the sort of issue you get into when you treat what's to be a dynamically loadable module as a shared library with cmake.

@beldmit
Copy link
Contributor

beldmit commented Sep 7, 2021

If you do it, it would be great. I don't understand the MacOs model here at all and we didn't get this issue with the commercial implementation...

@levitte
Copy link
Contributor

levitte commented Sep 7, 2021

Well, the Linux model is really not better, you just happen to cheat a lot 😉

@levitte
Copy link
Contributor

levitte commented Sep 7, 2021

Essentially, a plugin is not a shared library and vice versa, conceptually speaking. But, on some platforms, this is just a naming difference, while on others, the difference is more tangible.

@levitte
Copy link
Contributor

levitte commented Sep 7, 2021

@x87-va, this is a quick hack that should probably produce what you want. Beware, though, that the tests will fail miserably, they aren't prepared for this...

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d86737a..74af03d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -265,9 +265,9 @@ add_library(gost_core STATIC ${GOST_LIB_SOURCE_FILES})
 set_target_properties(gost_core PROPERTIES POSITION_INDEPENDENT_CODE ON)
 target_link_libraries(gost_core PRIVATE OpenSSL::Crypto)
 
-add_library(gost_engine SHARED ${GOST_ENGINE_SOURCE_FILES})
+add_library(gost_engine MODULE ${GOST_ENGINE_SOURCE_FILES})
 set_target_properties(gost_engine PROPERTIES PREFIX "" OUTPUT_NAME "gost")
-set_target_properties(gost_engine PROPERTIES VERSION ${GOST_SOVERSION} SOVERSION ${GOST_SOVERSION})
+#set_target_properties(gost_engine PROPERTIES VERSION ${GOST_SOVERSION} SOVERSION ${GOST_SOVERSION})
 target_link_libraries(gost_engine PRIVATE gost_core)
 
 add_library(gost_engine_static STATIC ${GOST_ENGINE_SOURCE_FILES})

@x87-va
Copy link
Author

x87-va commented Sep 8, 2021

@x87-va, this is a quick hack that should probably produce what you want. Beware, though, that the tests will fail miserably, they aren't prepared for this...

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d86737a..74af03d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -265,9 +265,9 @@ add_library(gost_core STATIC ${GOST_LIB_SOURCE_FILES})
 set_target_properties(gost_core PROPERTIES POSITION_INDEPENDENT_CODE ON)
 target_link_libraries(gost_core PRIVATE OpenSSL::Crypto)
 
-add_library(gost_engine SHARED ${GOST_ENGINE_SOURCE_FILES})
+add_library(gost_engine MODULE ${GOST_ENGINE_SOURCE_FILES})
 set_target_properties(gost_engine PROPERTIES PREFIX "" OUTPUT_NAME "gost")
-set_target_properties(gost_engine PROPERTIES VERSION ${GOST_SOVERSION} SOVERSION ${GOST_SOVERSION})
+#set_target_properties(gost_engine PROPERTIES VERSION ${GOST_SOVERSION} SOVERSION ${GOST_SOVERSION})
 target_link_libraries(gost_engine PRIVATE gost_core)
 
 add_library(gost_engine_static STATIC ${GOST_ENGINE_SOURCE_FILES})

Now I have build error:

[ 54%] Building C object CMakeFiles/test_keyexpimp.dir/test_keyexpimp.c.o
[ 56%] Linking C executable bin/test_keyexpimp
ld: can't link with bundle (MH_BUNDLE) only dylibs (MH_DYLIB) file 'bin/gost.so' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [bin/test_keyexpimp] Error 1
make[1]: *** [CMakeFiles/test_keyexpimp.dir/all] Error 2
make: *** [all] Error 2

@levitte
Copy link
Contributor

levitte commented Sep 8, 2021

Yeah, I'll look through that, it didn't get right on Linux even, for reasons that currently escape me. Be back in a day or two

@levitte
Copy link
Contributor

levitte commented Sep 8, 2021

(this reminds me: I actually have access to a Mac since recently!)

@x87-va
Copy link
Author

x87-va commented Sep 20, 2021

Are there any updates?

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