eclipse / paho.mqtt.cpp

Other
990 stars 429 forks source link

Paho sync client ssl return "Error: MQTT error [-13]: SSL is not supported [0]" #506

Open Manfred-O opened 1 month ago

Manfred-O commented 1 month ago

Hi, i'm trying to setup a secure connection to my broker by using the paho sync client library. But unfortunately i'm getting the error ssl not supported. But i have compiled them, so i'm wondering how it comes to get that error. I'm using the vcpkg manager and when listing my packages those are my results. paho-mqtt:x64-windows-static 1.3.13#1 Paho project provides open-source client impleme... paho-mqttpp3:x64-windows-static 1.4.1 Paho project provides open-source C++ wrapper fo... paho-mqttpp3[ssl]:x64-windows-static Build with SSL support

When using your "examples/ssl_publish.cpp" together with the async dlls it work. paho-mqttpp3[ssl]:x64-windows Build with SSL support

But i like to use the static one with sync client. Do i miss something.

Thanks in advance

fpagliughi commented 1 month ago

That error bubbles up from the Paho C library. It means the version of the C library that you linked to was built without OpenSSL support.

Both the Paho C and C++ libraries must be compiled with SSL support. By default the C library is not built with SSL support. It must be turned on via a CMake build option.

Unfortunately, I don't use Windows much, and I've never used vpkg. I have no idea who even created the vpkg support for this library (but I much appreciate it!).

Make sure you have the correct Paho C lib installed and that you're linking to the one that you think you're linking to...

Manfred-O commented 1 month ago

I tried to build the c++ like you advised under "Build the Paho C++ and Paho C libraries together" with little difference in for cmake i used mine. cmake -Bbuild -H. -DPAHO_WITH_MQTT_C=ON -DPAHO_WITH_SSL=ON -DCMAKE_POSITION_INDEPENDENT_CODE=OFF -DPAHO_BUILD_SHARED=OFF -DOPENSSL_ROOT_DIR=C:\xxx\xxx\openssl -DCMAKE_INSTALL_PREFIX=C:\xxx\xxx\paho

i could build it and had my 5 static libraries under paho\lib. I linked paho-mqttpp3-static.lib to my Project in VStudio. But got tons of unresolved external symbol errors. When checking the symbols with dumpbin they are visible. I also checked the machine and it's compiled for x64. I also tried to download both repos separately and compiling them, but same issue. Do i miss any thing...

dg0yt commented 1 month ago

With static library linkage, paho-mqttpp3-static.lib is not enough. You also have to supply all transitive usage requirements: paho-mqtt3as, OpenSSL, maybe more. (With CMake, these are resolved via imported targets.)

Manfred-O commented 1 month ago

Ok, i included all five libs now and also ws2_32.lib but still unresolved external symbols. Pretty much all of them are paho-mqtt3as-static.lib(SSLSocket.obj). Which library should i include for that one.

dg0yt commented 1 month ago

Uninformed guessing, litte details... Don't expect much progress. Add actual error messages here. Attach actual error logs in the vcpkg issue. (You may remove sensitive details, but you cannot hide all relevant details.)

Manfred-O commented 1 month ago

I have placed libeay32.lib and ssleay32.lib from the openssl64 folder. But still one error after building in VC paho-mqtt3as-static.lib(SSLSocket.obj) : error LNK2019: unresolved external symbol SSL_CTX_set_psk_client_callback referenced in function SSLSocket_createContext

dg0yt commented 1 month ago

I don't know where you openssl64 libs comes from. Does it matches the includes and how you used them? (I do know what is installed in vcpkg, and it does not include any *eay* libs for OpenSSL 3. There is libssl.lib and libcrypto.lib.)

Manfred-O commented 1 month ago

I'm not using vcpkg for now. I was building the libraries from the github repositories. And the openssl library, i downloaded it from here "https://code.google.com/archive/p/openssl-for-windows/downloads". Had no error just compiled gave me 5 libs all marked as static. linked them to my project, which is an example paho-mqtt-cpp provided, and got those errors.

dg0yt commented 1 month ago

openssl 0.9.8, seriously? Then I also don't need to speak about import libs and dllimport.

fpagliughi commented 1 month ago

Yeah, that's a horribly outdated OpenSSL. For Windows, I've been using the latest binaries from here: https://slproweb.com/products/Win32OpenSSL.html

Currently that's v3.3.1

Manfred-O commented 1 month ago

Thanks for the hint. I changed the Openssl to the one i have in my vcpkg includes and it worked. But had to do a little change.

inside paho.mqtt.c

C:\Users\Manfr\source\repos\Manfred-O\paho\paho.mqtt.c>cmake -Bbuild -H. -DPAHO_WITH_SSL=TRUE -DOPENSSL_ROOT_DIR=C:\Users\Manfr\vcpkg\installed\x64-windows-static -DPAHO_BUILD_STATIC=TRUE -DPAHO_BUILD_SHARED=FALSE -DPAHO_ENABLE_TESTING=FALSE -DCMAKE_INSTALL_PREFIX=C:\Users\Manfr\source\repos\Manfred-O\paho\static -- Building for: Visual Studio 17 2022 CMake Deprecation Warning at CMakeLists.txt:20 (CMAKE_MINIMUM_REQUIRED): Compatibility with CMake < 3.5 will be removed from a future version of CMake.

Update the VERSION argument value or use a ... suffix to tell CMake that the project does not need compatibility with older versions.

-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.22635. -- The C compiler identification is MSVC 19.38.33130.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.38.33130/bin/Hostx64/x64/cl.exe - skipped -- Detecting C compile features -- Detecting C compile features - done -- CMake version: 3.27.2-msvc1 -- CMake system name: Windows -- Timestamp is 2024-07-19T06:15:12Z -- Found OpenSSL: C:/Users/Manfr/vcpkg/installed/x64-windows-static/lib/libcrypto.lib (found version "3.3.1") -- Configuring done (1.9s) -- Generating done (0.1s) -- Build files have been written to: C:/Users/Manfr/source/repos/Manfred-O/paho/paho.mqtt.c/build

then

C:\Users\Manfr\source\repos\Manfred-O\paho\paho.mqtt.c>cmake --build build/ --target install

warnings C:\Users\Manfr\source\repos\Manfred-O\paho\paho.mqtt.c\src\Thread.c(88,10): warning C4101: 'wchars': unreferenced local variable [C:\User s\Manfr\source\repos\Manfred-O\paho\paho.mqtt.c\build\src\common_ssl_obj_static.vcxproj] C:\Users\Manfr\source\repos\Manfred-O\paho\paho.mqtt.c\src\WebSocket.c(1324,3): warning C4996: 'SHA1_Init': Since OpenSSL 3.0 [C:\Users\M anfr\source\repos\Manfred-O\paho\paho.mqtt.c\build\src\common_ssl_obj_static.vcxproj] C:\Users\Manfr\source\repos\Manfred-O\paho\paho.mqtt.c\src\WebSocket.c(1325,3): warning C4996: 'SHA1_Update': Since OpenSSL 3.0 [C:\Users \Manfr\source\repos\Manfred-O\paho\paho.mqtt.c\build\src\common_ssl_obj_static.vcxproj] C:\Users\Manfr\source\repos\Manfred-O\paho\paho.mqtt.c\src\WebSocket.c(1326,3): warning C4996: 'SHA1_Final': Since OpenSSL 3.0 [C:\Users\ Manfr\source\repos\Manfred-O\paho\paho.mqtt.c\build\src\common_ssl_obj_static.vcxproj]

and for paho.mqtt.cpp

C:\Users\Manfr\source\repos\Manfred-O\paho\paho.mqtt.cpp>cmake -Bbuild -H. -DPAHO_WITH_SSL=TRUE -DOPENSSL_ROOT_DIR=C:\Users\Manfr\vcpkg\installed\x64-windows-static -DPAHO_BUILD_STATIC=TRUE -DPAHO_BUILD_SHARED=FALSE -DPAHO_ENABLE_TESTING=FALSE -DCMAKE_PREFIX_PATH=C:\Users\Manfr\source\repos\Manfred-O\paho\static -DCMAKE_INSTALL_PREFIX=C:\Users\Manfr\source\repos\Manfred-O\paho\static -- Building for: Visual Studio 17 2022 -- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.22635. -- The C compiler identification is MSVC 19.38.33130.0 -- The CXX compiler identification is MSVC 19.38.33130.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.38.33130/bin/Hostx64/x64/cl.exe - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.38.33130/bin/Hostx64/x64/cl.exe - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Found OpenSSL: C:/Users/Manfr/vcpkg/installed/x64-windows-static/lib/libcrypto.lib (found version "3.3.1") -- Performing Test CMAKE_HAVE_LIBC_PTHREAD -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed -- Looking for pthread_create in pthreads -- Looking for pthread_create in pthreads - not found -- Looking for pthread_create in pthread -- Looking for pthread_create in pthread - not found -- Found Threads: TRUE -- Configuring done (4.7s) -- Generating done (0.1s) CMake Warning: Manually-specified variables were not used by the project:

PAHO_ENABLE_TESTING

-- Build files have been written to: C:/Users/Manfr/source/repos/Manfred-O/paho/paho.mqtt.cpp/build

after that C:\Users\Manfr\source\repos\Manfred-O\paho\paho.mqtt.cpp>cmake --build build/ --target install

no warnings

Visualstudio gave me that errors

Severity Code Description Project File Line Suppression State Details Error LNK2005 SHA1_Update already defined in paho-mqtt3a-static.lib(SHA1.obj) SSL_PAHO C:\Users\Manfr\source\repos\Manfred-O\SSL_PAHO\libcrypto.lib(libcrypto-lib-sha1dgst.obj) 1
Error LNK2005 SHA1_Init already defined in paho-mqtt3a-static.lib(SHA1.obj) SSL_PAHO C:\Users\Manfr\source\repos\Manfred-O\SSL_PAHO\libcrypto.lib(libcrypto-lib-sha1dgst.obj) 1
Error LNK2005 SHA1_Final already defined in paho-mqtt3a-static.lib(SHA1.obj) SSL_PAHO C:\Users\Manfr\source\repos\Manfred-O\SSL_PAHO\libcrypto.lib(libcrypto-lib-sha1dgst.obj) 1
Error LNK1169 one or more multiply defined symbols found SSL_PAHO C:\Users\Manfr\source\repos\Manfred-O\SSL_PAHO\x64\Debug\SSL_PAHO.exe 1

So i just comment the SHA1.c file from the build process inside the CMakeList.txt and build again. Now when using your example for a ssl publishing it works for both asyn client and for sync client. Now the next challenge is to automate it via vcpkg manager.

Thanks for help

fpagliughi commented 1 month ago

The build warnings for the SHA1 functions are expected. That should be fixed in the Paho C v1.4 release. But it should still link. I don't know where the linker errors are coming from.