Jump to content
JustinCase

Could not load OpenSSL library.

Recommended Posts

Keep trying to connect to a simple https site, but keep getting this error "Could not load OpenSSL library".

The DLL files are in my executable directory (libeay32.dll and ssleay32.dll). As far as I know, it is the correct version, though finding what OpenSSL version fits my installed Indy version does not seem easy and I may be wrong.

Downloaded the files from here: https://indy.fulgan.com/SSL/ 

My Indy version is 26.0.34749.6593

 

I also set a specific directory to look in, just in case:
  IdOpenSSLSetLibPath('C:\\Projects\\TestSSL\\Win32\\Debug\\');
  IdHTTP1.Get('https://www.vg.no');

 

Spent the whole day on this now, but solved the same issue in C# in under 5 minutes. Seems to be the way it is with Delphi these days.....

 

What am I doing wrong? Tried several proposed solutions online, but none of them work ('cause it can't even load the library).

Share this post


Link to post

Did you download the 32 bit version or the 64 bit ones?

The DLL bitness must match your programs bitness.

 

There shouldn't be any need to set the IdOpenSSLSetLibPath.

 

But if you want to set it, you can do it with:

Initialization
  IdOpenSSLSetLibPath(ExtractFilePath(Application.ExeName));

 

Share this post


Link to post
3 hours ago, JustinCase said:

Keep trying to connect to a simple https site, but keep getting this error "Could not load OpenSSL library".

When that error happens, you can then call Indy's WhichFailedToLoad() function in the IdSSLOpenSSLHeaders unit to find out WHY it failed.  Either the DLLs themselves could not be loaded into memory, or else they are missing exports that Indy requires.

3 hours ago, JustinCase said:

The DLL files are in my executable directory (libeay32.dll and ssleay32.dll). As far as I know, it is the correct version, though finding what OpenSSL version fits my installed Indy version does not seem easy and I may be wrong.

Indy supports up to the latest OpenSSL 1.0.2 DLLs.

3 hours ago, JustinCase said:

Downloaded the files from here: https://indy.fulgan.com/SSL/ 

Those DLLs are known to be working with Indy.

 

Share this post


Link to post
Posted (edited)

@Remy Lebeau

I upgraded to a new server (Win2008 to Win2019) and now I'm getting the same issue (trying to send eMail via Amazon SES).

 

This is inside an ISAPI 32bit dll that worked just fine when running under Windows 2008, but fails to send email when running under Windows 2019.

I literally use the same code, same DLLs as the Win2008 machine, all DLLs (my DLL & SSL) are 32bit, everything else in the code works fine except for sending eMail using TLS (SSL).

Inside IIS's application pool, the DLL is defined as 32bit, classic and "no managed code".

 

When calling "smtp.send" (TIdSMTP), I get the following exception and additional info:


3/22/2020 10:00:49 AM [       11854 ms] : SMTP Send Exception : SSL negotiation failed.

3/22/2020 10:00:49 AM [       11854 ms] : Inner Exception : Could not load SSL library.
3/22/2020 10:00:49 AM [       11855 ms] : WhichFailedToLoad : "Failed to load libeay32.dll."

 

The DLLs are in the same folder as the ISAPI DLL, I also tried placing them in the Windows/System32 folder but it made no difference.

Both "libeay32.dll" and "ssleay32.dll" are v1.0.2.19 and I'm using Delphi 10.3.3.

 

Edited by Yaron

Share this post


Link to post
Posted (edited)

I did further testing and it's also failing outside of IIS, when running as a normal process on my local Windows 10 machine (which I also recently upgraded from Windows 7 where the code worked fine).

 

So is this issue possibly specific to Windows 10/2019?

Edited by Yaron

Share this post


Link to post
Posted (edited)

I managed to debug the SSL DLL's LoadLibrary's GetLastError value and it's #193, which according to microsoft is "ERROR_BAD_EXE_FORMAT".

 

I don't belive the DLLs were corrupted, but just in case I downloaded the latest versions of the DLLs (v1.0.2.21) and no more errors on my local Win10 machine, but the Win2019 server is still triggering the same exceptions.

Edited by Yaron

Share this post


Link to post
Posted (edited)

Running the same code on the server, GetLastError returns #126 "ERROR_MOD_NOT_FOUND", however the OpenSSL DLLs are both in the same path as the running DLL and in the Windows/System32 folder.

Edited by Yaron

Share this post


Link to post

I placed another copy of the DLLs under "Windows/SysWow64" and now it seems to find the DLLs.

 

It would help debugging if calling "WhichFailedToLoad" or possibly the InnerException would return the GetLastError value from the LoadLibrary function.

  • Like 1

Share this post


Link to post
2 hours ago, Yaron said:

It would help debugging if calling "WhichFailedToLoad" or possibly the InnerException would return the GetLastError value from the LoadLibrary function.

Code has already been written to do exactly that, actually, but it hasn't been checked in yet.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×