You need to put the static library at the END of your link command. A static library is searched when it is encountered in the link stream, and only the items needed will be used from it.
Because you have it first, there are no undefined symbols, and no items will be used from it.
From: openssl-users <openssl-users-bounces@xxxxxxxxxxx>
On Behalf Of Shariful Alam
Sent: Tuesday, November 17, 2020 12:40 PM
To: openssl-users@xxxxxxxxxxx
Subject: Can't link a static library with custom OpenSSL rsa engine
Hello,
I have a custom rsa engine. It builds and works fine. Later, I have added a static library with my custom engine code. My code compiles. However, when I try to load the custom engine it shows invalid engine "rsa-engine-new".
The full error is given below,
x@x:~/Downloads/x/x/x/rsa_engine$ openssl rsautl -decrypt -inkey private.pem -in msg.enc -engine rsa-engine-new
invalid engine "rsa-engine-new"
140112744122112:error:25066067:DSO support routines:dlfcn_load:could not load the shared library:crypto/dso/dso_dlfcn.c:119:filename(/opt/openssl/lib/engines-1.1/rsa-engine-new.so):
/opt/openssl/lib/engines-1.1/rsa-engine-new.so: undefined
symbol: dune_init
140112744122112:error:25070067:DSO support routines:DSO_load:could not load the shared library:crypto/dso/dso_lib.c:162:
140112744122112:error:260B6084:engine routines:dynamic_load:dso not found:crypto/engine/eng_dyn.c:414:
140112744122112:error:2606A074:engine routines:ENGINE_by_id:no such engine:crypto/engine/eng_list.c:334:id=rsa-engine-new
140112744122112:error:25066067:DSO support routines:dlfcn_load:could not load the shared library:crypto/dso/dso_dlfcn.c:119:filename(librsa-engine-new.so):
librsa-engine-new.so: cannot open shared object file: No such file or directory
140112744122112:error:25070067:DSO support routines:DSO_load:could not load the shared library:crypto/dso/dso_lib.c:162:
140112744122112:error:260B6084:engine routines:dynamic_load:dso not found:crypto/engine/eng_dyn.c:414:
Now the error doesn't say much about the cause of invalid engine. However my guess is it is from the "undefined symbol: dune_init". "dune_init" is from the static library. Therefire I believe my linking is not working. I use the
following Makefile to compile the engine,
-
rsa-engine: rsa/rsa.c rsa/bignum.c rsa/aes.c rsa/x509parse.c rsa/pem.c
-
gcc -fPIC -o rsa/rsa.o -c rsa/rsa.c
-
gcc -fPIC -o rsa/bignum.o -c rsa/bignum.c
-
gcc -fPIC -o rsa/aes.o -c rsa/aes.c
-
gcc -fPIC -o rsa/x509parse.o -c rsa/x509parse.c
-
gcc -fPIC -o rsa/pem.o -c rsa/pem.c
-
gcc -fPIC -c rsa-engine.c
-
gcc -shared -o
librsa_engine.so libdune/libdune.a -lcrypto rsa-engine.o rsa/rsa.o rsa/bignum.o rsa/aes.o rsa/x509parse.o rsa/pem.o
-
mv
librsa_engine.so
rsa-engine-new.so
-
sudo cp
rsa-engine-new.so /opt/openssl/lib/engines-1.1/
-
clean:
-
rm -f *.o rsa/*.o *.so rsa-engine
So, can anyone please if my guess is correct or not? If my guess is correct, how can I fix my Makefile?
-
libdune/libdune.a is in the same directory with the main rsa-engine.c
-
libdune/libdune.a is compiled with -fPIC flag
|