Recent

Author Topic: TFPHttpClient and openSSL woes  (Read 306 times)

Frogfather

  • New member
  • *
  • Posts: 9
TFPHttpClient and openSSL woes
« on: November 25, 2018, 06:17:27 pm »
Hi,
I'm having similar problems to other folk in that requests to an http resource work fine, but those to https return the error:
Quote
ElnOutError Could not initialise OpenSSL library

I've read all recent posts on this topic and have tried all the suggestions mentioned in them but to no effect.
I've manually installed openssl.1.0.2 from source. I've also tried adding copies of the libssl and libcrypto files to the project directory.

System details:
--------------------------------
fpc: 3.0.4
lazarus: 1.8.2
x86_64-linux-gtk2
Fedora 29
--------------------------------
$which openssl
/usr/bin/openssl

$openssl version
OpenSSL 1.1.1 FIPS  11 Sep 2018

One slight oddity of Fedora is that the ssl library files are in /lib64 rather than /usr/lib64. I've added this to LD_LIBRARY_PATH in my .bashrc file. The current library path is:

:/lib64:/lib:/usr/lib:/usr/local/lib

in /lib64 the relevant libssl files are:
lrwxrwxrwx.   1 root root       16 Nov 23 20:07 libssl1.so -> libssl.so.1.0.2o
-rwxr-xr-x.   1 root root   409128 Sep  3 13:40 libssl3.so
lrwxrwxrwx.   1 root root       16 Aug  3 10:51 libssl.so.10 -> libssl.so.1.0.2o
-rwxr-xr-x.   1 root root   474456 Aug  3 10:51 libssl.so.1.0.2o
lrwxrwxrwx.   1 root root       15 Sep 17 12:03 libssl.so.1.1 -> libssl.so.1.1.1
-rwxr-xr-x.   1 root root   623016 Sep 17 12:03 libssl.so.1.1.1

similar for libcrypto:
lrwxrwxrwx.   1 root root       21 Oct  8 14:08 libbd_crypto.so.2 -> libbd_crypto.so.2.0.0
-rwxr-xr-x.   1 root root    47736 Oct  8 14:08 libbd_crypto.so.2.0.0
lrwxrwxrwx.   1 root root       19 Nov 23 20:06 libcrypto1.so -> libcrypto.so.1.0.2o
lrwxrwxrwx.   1 root root       19 Aug  3 10:51 libcrypto.so.10 -> libcrypto.so.1.0.2o
-rwxr-xr-x.   1 root root  2692984 Aug  3 10:51 libcrypto.so.1.0.2o
lrwxrwxrwx.   1 root root       18 Sep 17 12:03 libcrypto.so.1.1 -> libcrypto.so.1.1.1
-rwxr-xr-x.   1 root root  3192840 Sep 17 12:03 libcrypto.so.1.1.1
lrwxrwxrwx.   1 root root       18 Oct  9 22:04 libk5crypto.so.3 -> libk5crypto.so.3.1
-rwxr-xr-x.   1 root root   144440 Oct  9 22:04 libk5crypto.so.3.1

The code is pretty much what's in the documentation:
Code: Pascal  [Select]
  1. unit httpclientunit;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  9.   fphttpclient, openssl;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     Button1: TButton;
  17.     Memo1: TMemo;
  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.  
  35.  
  36. procedure TForm1.Button1Click(Sender: TObject);
  37. var S: String;
  38. var myClient: TFPHttpClient;
  39. begin
  40.   InitSSLInterface;
  41.   myClient := TFPHttpClient.Create(nil);
  42.   with myClient do
  43.   try
  44.      AllowRedirect:=true;
  45.      S:=Get('https://jsonplaceholder.typicode.com/todos/5');
  46.      Memo1.text:=S;
  47.   finally
  48.     free;
  49.   end;
  50. end;
  51.  
  52. end.
  53.                                                    
  54.  

nouzi

  • New member
  • *
  • Posts: 43
my english is  bad
Lazarus trunk 2.0 free pascal 3.1.1
System : windows 7 64bit

Frogfather

  • New member
  • *
  • Posts: 9
Re: TFPHttpClient and openSSL woes
« Reply #2 on: November 26, 2018, 09:42:30 am »
Hi, thanks for the reply.

I did try the code mentioned in the post you referred to, but the error is thrown at the InitSSLInterface line so at this point it doesn't really make much difference what's below that line!

I've tried putting copies of libssl and libcrypto in the same folder as the executable as one user suggested but same error results :(

I'm thinking it's more a library loading than fpc issue but any suggestions that might resolve it would be welcome.





rvk

  • Hero Member
  • *****
  • Posts: 3505
Re: TFPHttpClient and openSSL woes
« Reply #3 on: November 26, 2018, 10:07:56 am »
You have a libssl.so.1.0.2o. I'm not sure Lazarus loads that one. It does try to load libssl.so.1.0.2 (without the o at the end).

So you could try creating a symlink to libssl.so.1.0.2o.

sudo ln -s /lib64/library.so.1.0.2o /lib64/library.so.1.0.2
sudo ln -s /lib64/libcrypto.so.1.0.2o /lib64/libcrypto.so.1.0.2

Frogfather

  • New member
  • *
  • Posts: 9
Re: TFPHttpClient and openSSL woes
« Reply #4 on: November 26, 2018, 02:17:16 pm »
Yes that worked. Many thanks!