Question

For troubleshooting purposes, is there a pragmatic way my app could check at runtime:

  1. whether the openssl dll's (ssleay32.dll and libeay32.dll) actually exist and will be able to successfully be loaded by my app?
  2. what path the openssl dll's are actually loaded from (so I could verify whether it's loading it from the copy in the app's directory, or whether it's picking up some stray copy from the system path somewhere)
  3. what version of openssl is my app (or Indy) using? (If I know the exact path, most versions of openssl dlls include the version info that I could check from viewing Windows file properties)
Was it helpful?

Solution

Yes. In the same order you asked:

  1. Use LoadLibrary for each DLL and check the return value.
  2. If #1 succeeds, use GetModuleFileName to retrieve the full pathname to the DLL that was loaded..
  3. If #2 succeeds, use GetFileVersionInfo to see if the DLL has file version information available. If it does, use VerQueryValue to read the version info (the same info you see by viewing Windows file properties).

They're all available from the Windows unit. Examples of all three in Delphi should be found here at StackOverflow. If you can't find them, post separate questions (see below) here asking for help using them.

(Posts here should contain a single question, so that a single answer can be selected as an answer. If you include multiple questions in the same post, several people can each answer one of them separately; in that case, how do you choose which one to accept as correct?)

OTHER TIPS

Indy 10 has an IdOpenSSLSetLibPath() function in the IdSSLOpenSSLHeaders.pas unit so you can tell Indy where the DLLs are located, instead of it having to hunt for them on the OS search path.

The best option is to just ship the desired DLLs in your app's installation directory, then there is no guesswork needed to know what your app will load.

You can get the version number using the OpenSSL api. Using Marco Ferrante's libeay32.pas found here and the following function (I modified Marco's GetVersion example because it was slightly incorrect):

function GetOpenSSLVersion: string;
var
  v: cardinal;
  s: PCharacter;
begin
  //Get the numeric release version identifier as described in http://www.openssl.org/docs/crypto/OPENSSL_VERSION_NUMBER.html#
  v := SSLeay;

  //Get text version number and release date, e.g.: "OpenSSL 0.9.5a 1 Apr 2000"
  s := SSLeay_version(_SSLEAY_VERSION);
  result := s + ' (' + IntToHex(v, 9) + ')';
end;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top