Recent

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

fedkad

  • Full Member
  • ***
  • Posts: 176
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 2.2.6 / FPC 3.2.2 on x86_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: 1228
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: 176
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 2.2.6 / FPC 3.2.2 on x86_64-linux-gtk2 (Ubuntu/GNOME) and x86_64-win64-win32/win64 (Windows 11)

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
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: 176
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 2.2.6 / FPC 3.2.2 on x86_64-linux-gtk2 (Ubuntu/GNOME) and x86_64-win64-win32/win64 (Windows 11)

prof7bit

  • Full Member
  • ***
  • Posts: 161
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.  


 

TinyPortal © 2005-2018