How to resolve Error creating SSL context()?
-
I'm developing on Windows 10, and I get this error when creating desktop application.
I've read and tried the recommendation in this link, Re: Ssl in application.. I've also read similar issues with similar recommendations with all kinds of google searches. I'm confused as ever because nowhere is there a clear and concise step-by-step solution.
I get "Error creating SSL context()" with just a simple app to connect to a REST api. Here is the simple code, just trying to get a session token:
QUrlQuery query; query.addQueryItem(QStringLiteral("userid"), QStringLiteral("myname@myaddress")); query.addQueryItem(QStringLiteral("password"), QStringLiteral("mypassword")); QUrl url(QStringLiteral("https://www.somesite.com/api/login")); url.setQuery(query); m_reply = m_network_manager->get(QNetworkRequest(url));
In the application output, I get this:
qt.network.ssl: QSslSocket: cannot call unresolved function SSLv23_client_method qt.network.ssl: QSslSocket: cannot call unresolved function SSL_CTX_new qt.network.ssl: QSslSocket: cannot call unresolved function SSL_library_init qt.network.ssl: QSslSocket: cannot call unresolved function ERR_get_error qt.network.ssl: QSslSocket: cannot call unresolved function ERR_get_error
What has to be done to make this work? Even worse, if I've got the dlls in the right place, then how to troubleshoot this error?
Thanks.
-
Qt(binary packages) already provides DLLs(like
libeay32.dll
/ssleay32.dll
) related to it. Put those DLLs within the execution path. -
Can you identify specific file names and location that Qt binary package provides? I've searched my entire system and there are no files with those names. I've even installed something called OpenSSL-Win32 and there is nothing like that. The closest I got is libcrypto-1_1.dll and libssl-1_1.dll.
-
Okay, my search tool is not as good as I thought, I found those in C:\Qt\Tools\mingw530_32\opt\bin and put into the execution path it works. Thank you for that.
Now I have similar new problem. The only reason I was running the app on Windows was to understand why it won't run on on Android :). So I know the code works as I expect, but now if I deploy to android, I get similar error and I guess I'm assuming same reason but how do I get this to work with Android?
Invalid or empty cipher list (error:100000b1:SSL routines:OPENSSL_internal:NO_CIPHER_MATCH)
And the application output:
D ViewRootImpl@e6dadc9[QtActivity]: ViewPostIme pointer 0 D InputMethodManager: HSIFW - flag : 0 Pid : 7843 I InputMethodManager: hideSoftInputFromWindow ignore mServedView == null or mServedView.getWindowToken() != windowToken, mServedView :DecorView@21c6cce[QtActivity] D InputMethodManager: HSIFW - flag : 0 Pid : 7843 I InputMethodManager: hideSoftInputFromWindow ignore mServedView == null or mServedView.getWindowToken() != windowToken, mServedView :DecorView@21c6cce[QtActivity] I zygote : Do full code cache collection, code=125KB, data=104KB I zygote : After code cache collection, code=119KB, data=86KB D ViewRootImpl@e6dadc9[QtActivity]: ViewPostIme pointer 1 W linker : library "libcrypto.so" ("/system/lib/libcrypto.so") needed or dlopened by "/data/app/org.qtproject.example.TestAndy2-lT_LT2h5WHkQMJr1VGzERw==/lib/arm/libQt5Core.so" is not accessible for the namespace "classloader-namespace" - the access is temporarily granted as a workaround for http://b/26394120, note that the access will be removed in future releases of Android. Could not load shared library symbols for /system/lib/libcrypto.so. Do you need "set solib-search-path" or "set sysroot"? W linker : library "libssl.so" ("/system/lib/libssl.so") needed or dlopened by "/data/app/org.qtproject.example.TestAndy2-lT_LT2h5WHkQMJr1VGzERw==/lib/arm/libQt5Core.so" is not accessible for the namespace "classloader-namespace" - the access is temporarily granted as a workaround for http://b/26394120, note that the access will be removed in future releases of Android. Could not load shared library symbols for /system/lib/libssl.so. Do you need "set solib-search-path" or "set sysroot"? W libTestAndy2.so: (null):0 ((null)): qt.network.ssl: QSslSocket: cannot resolve CRYPTO_free W libTestAndy2.so: (null):0 ((null)): qt.network.ssl: QSslSocket: cannot resolve CONF_get1_default_config_file W libTestAndy2.so: (null):0 ((null)): qt.network.ssl: QSslSocket: cannot resolve EC_curve_nist2nid W libTestAndy2.so: (null):0 ((null)): qt.network.ssl: QSslSocket: cannot resolve SSL_CTX_ctrl W libTestAndy2.so: (null):0 ((null)): qt.network.ssl: QSslSocket: cannot resolve SSL_CONF_CTX_new W libTestAndy2.so: (null):0 ((null)): qt.network.ssl: QSslSocket: cannot resolve SSL_CONF_CTX_free W libTestAndy2.so: (null):0 ((null)): qt.network.ssl: QSslSocket: cannot resolve SSL_CONF_CTX_set_ssl_ctx W libTestAndy2.so: (null):0 ((null)): qt.network.ssl: QSslSocket: cannot resolve SSL_CONF_CTX_set_flags W libTestAndy2.so: (null):0 ((null)): qt.network.ssl: QSslSocket: cannot resolve SSL_CONF_CTX_finish W libTestAndy2.so: (null):0 ((null)): qt.network.ssl: QSslSocket: cannot resolve SSL_CONF_cmd D NetworkSecurityConfig: No Network Security Config specified, using platform default I zygote : Do partial code cache collection, code=123KB, data=88KB I zygote : After code cache collection, code=123KB, data=88KB I zygote : Increasing code cache capacity to 512KB W libTestAndy2.so: (null):0 ((null)): qt.network.ssl: QSslSocket: cannot call unresolved function SSL_CTX_ctrl
Thank you.
-
Please read this document.
http://doc.qt.io/qt-5/opensslsupport.html -
Thank you for that. I've managed to get through 90% of the instructions. I'm at step 8 in which I must run make to build the libraries. Only problem is I don't have make on my system, it is windows environment. I'm using msys2.
Do I need to install make in msys2 environment? Then what about compiler, what compiler do I use?
Thanks.
-
I installed make into msys2 and ran make and I guess I don't need to worry about compiler, it is using whatever is provided by the android sdk. However, I now have a new hurdle. It can't find assert.h. Which assert.h is it wanting, shouldn't the setup script have added the right paths needed for building?
Is this the location of assert.h that is needed?
C:\Users\JosedeLeon\AppData\Local\Android\Sdk\ndk-bundle\sysroot\usr\include
Here is the output from setup script
ANDROID_NDK_ROOT: /c/Users/JosedeLeon/AppData/Local/Android/Sdk/ndk-bundle ANDROID_ARCH: arch-arm64 ANDROID_EABI: aarch64-linux-android-4.9 ANDROID_API: android-28 ANDROID_SYSROOT: /c/Users/JosedeLeon/AppData/Local/Android/Sdk/ndk-bundle/platforms/android-28/arch-arm64 ANDROID_TOOLCHAIN: /c/Users/JosedeLeon/AppData/Local/Android/Sdk/ndk-bundle/toolchains/aarch64-linux-android-4.9/prebuilt/windows-x86_64/bin FIPS_SIG: CROSS_COMPILE: aarch64-linux-android- ANDROID_DEV: /c/Users/JosedeLeon/AppData/Local/Android/Sdk/ndk-bundle/platforms/android-28/arch-arm64/usr
Here is the error
$ make CALC_VERSIONS="SHLIB_COMPAT=; SHLIB_SOVER=" build_libs make depend && make _build_libs make[1]: Entering directory '/c/Users/JosedeLeon/Documents/Development/Tools/Libraries/openssl-1.1.0i' make[1]: Leaving directory '/c/Users/JosedeLeon/Documents/Development/Tools/Libraries/openssl-1.1.0i' make[1]: Entering directory '/c/Users/JosedeLeon/Documents/Development/Tools/Libraries/openssl-1.1.0i' aarch64-linux-android-gcc -I. -Icrypto/include -Iinclude -DDSO_DLFCN -DHAVE_DLFCN_H -DNDEBUG -DOPENSSL_THREADS -DOPENSSL_NO_STATIC_ENGINE -DOPENSSL_PIC -DOPENSSLDIR="\"/usr/local/ssl\"" -DENGINESDIR="\"/usr/local/lib/engines-1.1\"" -Wall -O3 -pthread -mandroid -fPIC --sysroot=/c/Users/JosedeLeon/AppData/Local/Android/Sdk/ndk-bundle/platforms/android-28/arch-arm64 -Wa,--noexecstack -fPIC -DOPENSSL_USE_NODELETE -MMD -MF crypto/aes/aes_core.d.tmp -MT crypto/aes/aes_core.o -c -o crypto/aes/aes_core.o crypto/aes/aes_core.c crypto/aes/aes_core.c:39:20: fatal error: assert.h: No such file or directory #include <assert.h> ^ compilation terminated. make[1]: *** [Makefile:678: crypto/aes/aes_core.o] Error 1 make[1]: Leaving directory '/c/Users/JosedeLeon/Documents/Development/Tools/Libraries/openssl-1.1.0i' make: *** [Makefile:132: build_libs] Error 2
Thanks.
-
Okay, finally got it to work but what a big pain. I think the main problem is that the guide is out of date and it needs to mention how specific environments need to resolve any issues that come up. Just a quick search online shows that there are common problems that everybody seems to be going through just to get Qt and OpenSSL to work with Android or otherwise.
For the record this is what I had to do, and the discovery process was not fun, here are the errors I came across in order:
ERROR 1: can't find headers
RESOLUTION: Something is wrong with the latest android NDK. I was using r17b. I downloaded and instead used r14b. Maybe I didn't need to go that far back, but the issue is the location of include and libraries are changed. Go download older version of NDK.
ERROR 2: "CreateProcess: No such file or directory".
RESOLUTION: Stupid windows file limitations. Go move the openssl source directory to top level on your HD. The issue is the paths were too long in windows.
ERROR 3: Something about incompatible version of libssl or some such.
RESOLUTION: You'll see the message in the application log. Downgrade your openssl package. I started with openssl-1.1.0i. I reverted to openssl-1.0.2p.
ERROR 4: 64-bit version wrong version. Can't remember the exact message, you'll find it in the application output log and you will recognize the error easily.
RESOLUTION: Be aware of your environment, 32bit vs 64bit. The guide gives example for 64 bit arch. Instead, build for 32 bit architecture. Unless your build environment is already set for 64 bit, then I don't have any advice.
Thank you!
-
check out this video for ssl context error fix
https://www.youtube.com/watch?v=nsPrI0aSkoI