Closed jorialand closed 1 year ago
try using this:
Poco::Crypto::OpenSSLInitializer openSSLInitializer;
try {
{
Poco::Path cPath(getApplicationPath());
cPath.makeDirectory();
OSSL_PROVIDER_set_default_search_path(NULL, cPath.toString().c_str());
}
OSSL_PROVIDER* legacy = NULL;
OSSL_PROVIDER* deflt = NULL;
if ((legacy == nullptr) && (OSSL_PROVIDER_available(NULL, "legacy") == 0)) {
legacy = OSSL_PROVIDER_try_load(NULL, "legacy", 1);
}
if (deflt == nullptr) {
deflt = OSSL_PROVIDER_load(NULL, "default");
}
}
catch (Poco::Exception& exc) {
}
when you end software you need
if (legacy != NULL) {
OSSL_PROVIDER_unload(legacy);
legacy = NULL;
}
if (deflt != NULL) {
OSSL_PROVIDER_unload(deflt);
deflt = NULL;
}
Hello @micheleselea!
Thank you for your suggestion, however, I get the same exception in first line, when I declare the openSSLInitializer.
Furthermore, I have discovered the problem is the application depends on the absolute path to \vcpkg\packages\openssl_x64-windows\bin\legacy.dll
, because if i rename the legacy.dll file to _legacy.dll, it throws the same exception, even in the same machine where i perform the build.
I have even tried to manually copy legacy.dll
to the same directory as the exectuable, and it doesn't work.
So, how could I configure the project to include this needed dll during the building process?
Thank you again.
Ah ok you are using DLL OpenSSL, so I think you have to put that dll in the executable folder
That’s the problem! If i manually put the dll in executable folder, i still get the same exception.
did you try using OSSL_PROVIDER_set_default_search_path setting the correct DLL path? you need to use that before Poco::Crypto::OpenSSLInitializer openSSLInitializer;
Hello @micheleselea ! Thank you again,
I tried the following and IT WORKED! 👯 👍 Thanks a lot.
BUT what last question. What is the default provider call for? I somehow remove it from your example code and it worked. Now the application consumes the legacy.dll
from the executable's path, instead the one from the vcpkg directory, so I am able to distribute my app to others.
int main()
{
try
{
std::cout << "Initializing OpenSsl provider." << std::endl;
{
Poco::Path cPath("C:\\workcopy\\PLAYGROUND\\PocoFailedLoadOpenSSL\\x64\\Release\\");
cPath.makeDirectory();
OSSL_PROVIDER_set_default_search_path(NULL, cPath.toString().c_str());
}
OSSL_PROVIDER* legacy = NULL;
if ((legacy == nullptr) && (OSSL_PROVIDER_available(NULL, "legacy") == 0))
legacy = OSSL_PROVIDER_try_load(NULL, "legacy", 1);
}
catch (Poco::Exception & e)
{
std::cout << "Exception initializing OpenSsl provider." << std::endl;
std::cout << e.displayText() << std::endl;
}
try
{
std::cout << "Initializing Poco Ssl." << std::endl;
Poco::Crypto::OpenSSLInitializer openSSLInitializer;
}
catch (const Poco::Exception & e)
{
std::cout << "Exception initializing Poco Ssl library." << std::endl;
std::cout << e.displayText() << std::endl;
}
std::string sTmp;
std::getline(std::cin, sTmp);
}
I do not understand what is the default provider, probably it's useless for you and for 99% of applications, I read month ago when I switch from Openssl 1.1.1 to 3.0 that was added legacy and default, but I do not remeber. Anyway good for your app
Hello everyone!
I am stucked with the following issue, when I try to initialize the SSL functionality using Poco's Crypto
Poco::Crypto::initializeCrypto();
. The issue is that in the machine where I perform the build, it works fine, but in other machines, a Poco::Exception is thrownCrypto Exception: Failed to load OpenSSL legacy provider
.My development environment is the following:
C:\workcopy\vcpkg>vcpkg list
Thank you very much in advance.