Thalhammer / jwt-cpp

A header only library for creating and validating json web tokens in c++
https://thalhammer.github.io/jwt-cpp/
MIT License
828 stars 229 forks source link

undefined reference error in compiling #311

Closed quanchentg closed 9 months ago

quanchentg commented 9 months ago

What's your question?

undefined reference error in compiling

Additional Context

I used centoOS 7 and openssl version is OpenSSL 1.0.2k-fips 26 Jan 2017. get error while compiling /opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: librestpp_lib.a(auth.cpp.o): in function jwt::algorithm::rsa::verify(std::string const&, std::string const&, std::error_code&) const': *****/jwt-cpp/jwt.h:957: undefined reference toEVP_MD_CTX_destroy' /opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: *****/jwt/jwt-cpp/jwt.h:957: undefined reference to `EVP_MD_CTX_create' collect2: error: ld returned 1 exit status

prince-chrismc commented 9 months ago

What version of jwt-cpp are you using?

quanchentg commented 9 months ago

0.6.0 thanks for your reply @prince-chrismc

prince-chrismc commented 9 months ago

🤔 hmm are you sure about that version of openssl is the one being pulled into your build scripts and being linked against? I've not used devtoolset-9 but perhaps it has a never version? You could run scl enable devtoolset-9 "openssl --version" to check.


I wanted to double check the docs but I am only getting a 404 https://www.openssl.org/docs/man1.0.2/man3/EVP_MD_CTX_destroy.html

This should be the correct logic, in 1.1.0 they changed everything to free https://github.com/Thalhammer/jwt-cpp/blob/ce1f9df3a9f861d136d6f0c93a6f811c364d1d3d/include/jwt-cpp/jwt.h#L486

You can check the CI but we compile from source and test each one

https://github.com/Thalhammer/jwt-cpp/blob/ce1f9df3a9f861d136d6f0c93a6f811c364d1d3d/.github/workflows/ssl.yml#L14

quanchentg commented 9 months ago

i used the command scl enable devtoolset-9 "openssl --version" it returns OpenSSL 1.0.2k-fips 26 Jan 2017.

quanchentg commented 9 months ago

more info if i use auto verify = jwt::verify().allow_algorithm(jwt::algorithm::hs512{jwt_secret}).with_issuer("auth0"); in my project, it compiles OK. but i add the other verify = jwt::verify().allow_algorithm(jwt::algorithm::rs256(private_key, "", "", "")) .with_issuer("auth0"); in my project, then it returns undefined reference error by compiler.

I think it may related to rs256 algorighm?

prince-chrismc commented 9 months ago

Can you comment out the library code and print OPENSSL_VERSION_TEXT https://www.openssl.org/docs/manmaster/man3/OPENSSL_VERSION_NUMBER.html

How are you linking to OpenSSL? What build system are you using?

prince-chrismc commented 9 months ago

I think it may related to rs256 algorighm?

Yes the cryptographic keys use the evp context, the hmac is very basic (and insecure) so it doesn't use APIs that have changed

quanchentg commented 9 months ago

seems like i use openssl 1.1.0 version for linker but i have another openssl 1.0.2 version installed on my machine.

prince-chrismc commented 9 months ago

I highly recommend using a package manager to manage 3rd party dependencies.

Unfortunately there is jot much I can , I will mark this as closed. Bestnof luck!