Recent

Author Topic: fphttpclient https/tls on Linux Mint 19.3 (base Ubuntu 18.04)  (Read 2755 times)

Xelandre

  • Newbie
  • Posts: 1
fphttpclient https/tls on Linux Mint 19.3 (base Ubuntu 18.04)
« on: January 31, 2020, 08:22:03 pm »
Hello,

I'm trying to get a bunch of code compiled in 3.0.4 from an earlier Linux version  to work on a machine with a fresh Linux Mint 19.3 installation, which is based on Ubuntu 18.04.

My problem is that fphttpclient get(url) fails on https URLs. As plain http links do work correctly, my immediate supposition was a problem in TLS/SSL library versions. I dug into the FCL source code and the system libraries for a couple of hours, alas without much success.

This is the test code snippet:

Code: Pascal  [Select][+][-]
  1. {$mode delphi}
  2. uses
  3.     classes,
  4.     sysutils,
  5.     strutils,
  6.     fileutil,
  7.     fpopenssl,
  8.     openssl,
  9.     sslsockets,
  10.     ssockets,
  11.     fphttpclient;
  12.  
  13. var cli: TFPHTTPClient;
  14.     s,url: string;
  15. const useragent = 'Mozilla/5.0 (compatible; fpweb)';
  16. begin
  17.    InitSSLInterface;
  18.    url:='https://forum.lazarus.freepascal.org/';
  19.    cli := TFPHTTPClient.Create(nil);
  20.    try
  21.       s:=cli.get(url);
  22.       cli.AddHeader('User-Agent',useragent);
  23.       cli.AllowRedirect := true;
  24.    except
  25.       writeln(erroutput,'Ouch!');
  26.    end;
  27.    
  28.    writeln(length(s));
  29.    writeln(s);
  30.  
  31.    cli.free;  
  32. end.
  33.  

Looking at other threads, it seems that I'm experiencing a known problem in 3.0.4, e.g. here: https://forum.lazarus.freepascal.org/index.php/topic,46560.0.html , and I persist in thinking that the issue lies in the interface to TLS.

At this point, I see the following alternatives, in decreasing order of preference:

3) Upgrade to fpc 3.2 (The preceding thread suggests that it solves this issue)
2) Rewrite a skeleton fphttpclient based on libcurl.
1) Downgrading the installed TLS to an earlier version (as suggested in earlier threads), but I have no real guarantee that this would solve the problem.

Does any one have any other ideas? I'm hoping for a patch to the FCL library. Or am I barking up the wrong tree?

Where/how can I get 3.2, or parts thereof? I can't access that directory under ftp://ftp.freepascal.org/fpc/beta/ .

Rewriting a barebones fphttpclient would probably require a couple of hours (I have a libcurl code base I can reuse). But I would gladly reuse someone else's code, if some exists.

Thanks!
« Last Edit: January 31, 2020, 08:35:50 pm by Xelandre »

fireboxsoft

  • New Member
  • *
  • Posts: 11
Re: fphttpclient https/tls on Linux Mint 19.3 (base Ubuntu 18.04)
« Reply #1 on: December 13, 2024, 12:38:12 am »
我也遇到你这个问题,我尝试把libeay32.dll放到可执行程序的同级目录中,顺利访问https网站 :D

BSaidus

  • Hero Member
  • *****
  • Posts: 606
  • lazarus 1.8.4 Win8.1 / cross FreeBSD
Re: fphttpclient https/tls on Linux Mint 19.3 (base Ubuntu 18.04)
« Reply #2 on: December 19, 2024, 07:53:32 pm »
I think, you do not need to Initialize the SSL, just see if the .so lib exists on your system & seen by your program (in the path env. var) then use it.
See also the name of the ssl .so library if it is the same as in the openssl unit.

check
Code: Pascal  [Select][+][-]
  1.  // ...
  2.  
  3. const
  4. // SSL and Crypto DLL arrays must have the same length and contain
  5. // matched pairs of DLL filenames. Place newer versions at the beginning.
  6. {$IF DEFINED(WIN64)}
  7.   SSL_DLL_Names:    array[1..4] of string = ('libssl-3-x64',    'libssl-1_1-x64',    'ssleay32', 'libssl32');
  8.   Crypto_DLL_Names: array[1..4] of string = ('libcrypto-3-x64', 'libcrypto-1_1-x64', 'libeay32', 'libeay32');
  9. {$ELSEIF DEFINED(WINDOWS)}
  10.   SSL_DLL_Names:    array[1..4] of string = ('libssl-3',    'libssl-1_1',    'ssleay32', 'libssl32');
  11.   Crypto_DLL_Names: array[1..4] of string = ('libcrypto-3', 'libcrypto-1_1', 'libeay32', 'libeay32');
  12. {$ELSEIF DEFINED(OS2GCC)}
  13.   SSL_DLL_Names:    array[1..2] of string = ('kssl10',   'kssl');
  14.   Crypto_DLL_Names: array[1..2] of string = ('kcrypt10', 'kcrypto');
  15. {$ELSEIF DEFINED(OS2)}
  16.   SSL_DLL_Names:    array[1..2] of string = ('emssl10',  'ssl');
  17.   Crypto_DLL_Names: array[1..2] of string = ('emcrpt10', 'crypto');
  18. {$ELSE}
  19.   BaseSSLName: string = 'libssl';
  20.   BaseCryptoName: string = 'libcrypto';
  21.   { ADD NEW ONES WHEN THEY APPEAR!
  22.     Always make .so/dylib first, then versions, in descending order!
  23.     Add "." .before the version, first is always just "" }
  24.   DLLVersions: array[1..20] of string = ('', '.3', '.1.1', '.11', '.10', '.1.0.6', '.1.0.5', '.1.0.4', '.1.0.3',
  25.                                         '.1.0.2', '.1.0.1','.1.0.0','.0.9.8',
  26.                                         '.0.9.7', '.0.9.6', '.0.9.5', '.0.9.4',
  27.                                         '.0.9.3', '.0.9.2', '.0.9.1');
  28.   LibreSSLVersions : Array[1..8] of string =
  29.                      ('', '.48', '.47', '.46', '.45', '.44', '.43', '.35');
  30.  
  31.  
  32.  // ...
  33.  

If no, then create a symlink to the existents one on the system.
lazarus 1.8.4 Win8.1 / cross FreeBSD
dhukmucmur vernadh!

 

TinyPortal © 2005-2018