Recent

Author Topic: TFPHTTPClient throws "Could not initialize OpenSSL library" error  (Read 3578 times)

fedkad

  • Full Member
  • ***
  • Posts: 179
I have the following simple test program:

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls
  9.   , fphttpclient, opensslsockets;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     Button1: TButton;
  17.     Label1: TLabel;
  18.     procedure Button1Click(Sender: TObject);
  19.   private
  20.  
  21.   public
  22.  
  23.   end;
  24.  
  25. var
  26.   Form1: TForm1;
  27.  
  28. implementation
  29.  
  30. {$R *.lfm}
  31.  
  32. { TForm1 }
  33.  
  34. procedure TForm1.Button1Click(Sender: TObject);
  35. const
  36.   check_url = 'https://www.example.com/';
  37. var
  38.   cl : TFPHTTPClient;
  39. begin
  40.   Label1.Caption := 'Accessing '+check_url;
  41.   Application.ProcessMessages;
  42.   cl := TFPHTTPClient.Create(Form1);
  43.   try
  44.     cl.AllowRedirect := True;
  45.     Label1.Caption := cl.Get(check_url);
  46.   except
  47.     on E: Exception do
  48.       MessageDlg ('Error accessing ' + check_url + LineEnding + E.ClassName + ':'
  49.         + LineEnding + E.Message,
  50.         mtError, [mbOK], 0);
  51.   end;
  52.   cl.Free;
  53. end;
  54.  
  55. end.

This code works perfectly on Ubuntu 22.04: It accesses the page at https://www.example.com/ and displays its raw HTML contents.

However, the same program gives the error:
Error accessing https://www.example.com/
EInOutError:
Could not initialize OpenSSL library

on Ubuntu 22.10.

Note: The same problem is present on Windows 11. I remember a similar code working as expected on Windows 10, but currently I do not have a Windows 10 installation to test. It is working OK on Windows XP (32-bit compilation).

Please, note that the problem is not related to compilation environment. By, copying the executable from system to system, I can confirm that the same executable works correctly on Ubuntu 22.04, but not on 22.10. So, the problem is obviously related to the run-time environment.

The same problem occurs on the sample programs given at: https://wiki.lazarus.freepascal.org/fphttpclient

Lazarus is at its latest version 2.2.4.



Update:

* I have read similar threads in this forum, but they didn't help. I am in a pure 64-bit environment. OS and Lazarus applications are all 64-bit. I remember that the program was running OK in my test system while it was on Ubuntu 22.04, but not after the upgrade to 22.10.

* Comparing the differences between the two versions of Ubuntu (22.04 vs 22.10) I noticed that the package libssl1.1/now 1.1.1l-1ubuntu1.2 amd64 is no longer available for Ubuntu 22.10 and it was removed.  So, running the commands:

Code: Text  [Select][+][-]
  1. # wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_amd64.deb
  2. # apt install ./libssl1.1_1.1.1f-1ubuntu2_amd64.deb

fixes the problem. But, obviously, this is not something I would like to do.

What are my options?
« Last Edit: October 24, 2022, 09:33:46 pm by fedkad »
Lazarus 4.6 / FPC 3.2.2 on latest amd/arm_64-linux-gtk2 (Ubuntu/GNOME) and x86_64-win64-win32/win64 (Windows 11)

ruewa

  • Newbie
  • Posts: 2
Re: TFPHTTPClient throws "Could not initialize OpenSSL library" error
« Reply #1 on: November 02, 2022, 11:55:07 pm »
Not sure whether it's the same problem, but I had the same  error on Ubuntu 22.04. Installing libssl-dev solved it.

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: TFPHTTPClient throws "Could not initialize OpenSSL library" error
« Reply #2 on: November 03, 2022, 12:31:36 am »
hello,
when you have this kind of problem, look at the file openssl.pas in the folder fpcsrc\packages\openssl\src. At the beginning of the file, you can see something like this :
Code: Pascal  [Select][+][-]
  1. var
  2.   {$IFDEF WINDOWS}
  3.   DLLSSLName: string = 'ssleay32.dll';
  4.   DLLSSLName2: string = 'libssl32.dll';
  5.   DLLUtilName: string = 'libeay32.dll';
  6.   {$ELSE}
  7.    {$IFDEF OS2}
  8.     {$IFDEF OS2GCC}
  9.   DLLSSLName: string = 'kssl10.dll';
  10.   DLLUtilName: string = 'kcrypt10.dll';
  11.   DLLSSLName2: string = 'kssl.dll';
  12.   DLLUtilName2: string = 'kcrypto.dll';
  13.     {$ELSE OS2GCC}
  14.   DLLSSLName: string = 'emssl10.dll';
  15.   DLLUtilName: string = 'emcrpt10.dll';
  16.   DLLSSLName2: string = 'ssl.dll';
  17.   DLLUtilName2: string = 'crypto.dll';
  18.     {$ENDIF OS2GCC}
  19.    {$ELSE OS2}
  20.   DLLSSLName: string = 'libssl';
  21.   DLLUtilName: string = 'libcrypto';
  22.  
  23.   { ADD NEW ONES WHEN THEY APPEAR!
  24.     Always make .so/dylib first, then versions, in descending order!
  25.     Add "." .before the version, first is always just "" }
  26.   DLLVersions: array[1..17] of string = ('', '.1.1', '.1.0.6', '.1.0.5', '.1.0.4', '.1.0.3',
  27.                                         '.1.0.2', '.1.0.1','.1.0.0','.0.9.8',
  28.                                         '.0.9.7', '.0.9.6', '.0.9.5', '.0.9.4',
  29.                                         '.0.9.3', '.0.9.2', '.0.9.1');
  30.    {$ENDIF OS2}
  31.   {$ENDIF WINDOWS}

As you can see the last version of libssl and libcrypto that you can use is the 1.1 for linux
To see what are the crypto libraries installed on your linux O.S, in a terminal launch this :

Code: Pascal  [Select][+][-]
  1. ldconfig -p | grep crypto
  2. ldconfig -p | grep ssl
  3.  

on my Ubuntu 20.04 :
Quote
ubuntu$ldconfig -p | grep ssl
libwolfssl.so.24 (libc6,x86-64) => /lib/x86_64-linux-gnu/libwolfssl.so.24
libssl3.so (libc6,x86-64) => /lib/x86_64-linux-gnu/libssl3.so
libssl.so.1.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/libssl.so.1.1
ubuntu$ldconfig -p | grep crypto
libmbedcrypto.so.3 (libc6,x86-64) => /lib/x86_64-linux-gnu/libmbedcrypto.so.3
libk5crypto.so.3 (libc6,x86-64) => /lib/x86_64-linux-gnu/libk5crypto.so.3
libhcrypto.so.4 (libc6,x86-64) => /lib/x86_64-linux-gnu/libhcrypto.so.4
libcrypto.so.1.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/libcrypto.so.1.1
libbd_crypto.so.2 (libc6,x86-64) => /lib/x86_64-linux-gnu/libbd_crypto.so.2

version 1.1 is installed.

Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

fedkad

  • Full Member
  • ***
  • Posts: 179
Re: TFPHTTPClient throws "Could not initialize OpenSSL library" error
« Reply #3 on: November 03, 2022, 11:38:45 am »
version 1.1 is installed.

Thanks J.P. for the reply. The problem is that "libssl1.1" is no longer provided in newer versions of Ubuntu. Instead we have only "libssl3".

I think FreePascal should be updated for this.
« Last Edit: November 03, 2022, 03:17:35 pm by fedkad »
Lazarus 4.6 / FPC 3.2.2 on latest amd/arm_64-linux-gtk2 (Ubuntu/GNOME) and x86_64-win64-win32/win64 (Windows 11)

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: TFPHTTPClient throws "Could not initialize OpenSSL library" error
« Reply #4 on: November 03, 2022, 12:37:36 pm »
Hello,
Thanks J.P. for the reply. The problem is that "libssl1.1" is not longer provided in newer versions of Ubuntu. Instead we have only "libssl3".
the last version of openssl.pas manages  this library but it is only in the fpc trunk ( i think not yet out in a release version of fpc)
Quote
21 Apr, 2022 1 commit
Add support for OpenSSL 3.0
Bi0T1N authored 6 months ago and Michael Van Canneyt's avatar Michael Van Canneyt committed 6 months ago

Friendly, J.P
« Last Edit: November 03, 2022, 12:40:53 pm by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

fedkad

  • Full Member
  • ***
  • Posts: 179
Re: TFPHTTPClient throws "Could not initialize OpenSSL library" error
« Reply #5 on: November 03, 2022, 01:27:52 pm »

the last version of openssl.pas manages  this library but it is only in the fpc trunk ( i think not yet out in a release version of fpc)
Quote
21 Apr, 2022 1 commit
Add support for OpenSSL 3.0
Bi0T1N authored 6 months ago and Michael Van Canneyt's avatar Michael Van Canneyt committed 6 months ago



Thanks for the info!
Lazarus 4.6 / FPC 3.2.2 on latest amd/arm_64-linux-gtk2 (Ubuntu/GNOME) and x86_64-win64-win32/win64 (Windows 11)

prof7bit

  • Full Member
  • ***
  • Posts: 163
Re: TFPHTTPClient throws "Could not initialize OpenSSL library" error
« Reply #6 on: November 17, 2022, 02:56:32 pm »
In my application I am doing something like this to make it run on current Ubuntu without being forced to use fpc trunk. This seems to work for now.
Code: Pascal  [Select][+][-]
  1.         {$ifndef windows}
  2.         if not InitSSLInterface then begin
  3.           Debug('ssl version 1.x not found, trying version 3');
  4.           openssl.DLLVersions[1] := '.3';
  5.         end;
  6.         {$endif}
  7.         if not InitSSLInterface then begin
  8.           Debug('ssl not supported');
  9.           exit(mqeSSLNotSupported);
  10.         end;
  11.  


PizzaProgram

  • Jr. Member
  • **
  • Posts: 62
  • ...developing Delphi apps since 25 years.
(I know this topic is mostly for *nix OS, and only mentioning Windows, but it's the first finding of DuckDuckGo, so I post it here...)

I've just tried using TFPHTTPClient under latest: Lazarus 4.4 (FPC 3.2.2)
32bit app, OS = WinServer2016 (=Win10 based)
Downloaded latest SSL binaries + installed both: 32 + 64 from recommended site:
https://slproweb.com/products/Win32OpenSSL.html

Same error message.
Looking at the openssl.pas unit, I do not see any SSL3 initialisation / filenames at all!

The 7 year old SSL v1.1.1w ended 2+ years ago!  :o https://endoflife.date/openssl

IMHO there are 3 problems:
1. The official wiki needs a big bold red-coloured warning, that it does not support current (Recommended) SSL versions at the top: https://wiki.lazarus.freepascal.org/fphttpclient

2. The official SSL binaries do not include v1.1 any more. (For obvious reason)
 Checked this one too: https://kb.firedaemon.com/support/solutions/articles/4000121705-openssl-binary-distributions-for-microsoft-windows
-> So a direct link to the last version of binaries of 1.1.1 should be on the Wiki too, if somebody still wants to use the old ones with this source.

3. Either a new version of TFPHTTPClient.pas + openssl.pas should be included in Lazarus install, which does support SSL3.5+,
or drop a recommendation to the wiki page for best preferred alternative.

Either way, the current Wiki + PAS files are not working under Windows!

Thanks!
x86_64-win64 --Win7 PRO 64bit HUN

PizzaProgram

  • Jr. Member
  • **
  • Posts: 62
  • ...developing Delphi apps since 25 years.
Re: TFPHTTPClient throws "Could not initialize OpenSSL library" error
« Reply #8 on: December 27, 2025, 09:56:10 am »
PS:

Latest trunc of Ararat Synaps does support SSL3 fine since years!
https://sourceforge.net/p/synalist/code/HEAD/tree/trunk/

( Reported it 3+ years ago: https://forum.lazarus.freepascal.org/index.php/topic,48677.msg441043.html#msg441043 )

Why is not the latest source included in Lazarus/FPC ?
x86_64-win64 --Win7 PRO 64bit HUN

paweld

  • Hero Member
  • *****
  • Posts: 1644
Re: TFPHTTPClient throws "Could not initialize OpenSSL library" error
« Reply #9 on: December 27, 2025, 10:04:28 am »
Version 3.2.2 does not support OpenSSL3, but version 3.2-fixes and the upcoming 3.2.4 (currently RC1) already support OpenSSL3. You can also use the following components:
- synapse: https://github.com/geby/synapse
- indy ( https://github.com/IndySockets/Indy ) + IndySecOpenSSL ( https://github.com/MWASoftware/IndySecOpenSSL )
- mormot2: https://github.com/synopse/mORMot2
All these components are also available in OPM.
Best regards / Pozdrawiam
paweld

dsiders

  • Hero Member
  • *****
  • Posts: 1635
Re: TFPHTTPClient throws "Could not initialize OpenSSL library" error. Laz v4.4
« Reply #10 on: December 27, 2025, 10:06:41 am »
(I know this topic is mostly for *nix OS, and only mentioning Windows, but it's the first finding of DuckDuckGo, so I post it here...)

I've just tried using TFPHTTPClient under latest: Lazarus 4.4 (FPC 3.2.2)
32bit app, OS = WinServer2016 (=Win10 based)
Downloaded latest SSL binaries + installed both: 32 + 64 from recommended site:
https://slproweb.com/products/Win32OpenSSL.html

Same error message.
Looking at the openssl.pas unit, I do not see any SSL3 initialisation / filenames at all!

What leads you to believe that FPC 3.2.2 supports SSL 3.X?

Thaddy

  • Hero Member
  • *****
  • Posts: 19275
  • Glad to be alive.
Re: TFPHTTPClient throws "Could not initialize OpenSSL library" error
« Reply #11 on: December 27, 2025, 10:42:50 am »
Yes. Also all this has been answered so many times everybody lost count....

If you definitely want to stick to 3.2.2 there is also the option to just checkout the openssl bindings from the fixes branch or trunk, since the bindings do not contain new language features.
objects are fine constructs. You can even initialize them with constructors.

 

TinyPortal © 2005-2018