Recent

Author Topic: fphttpclient: Connect to URL failed.  (Read 2141 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 15557
  • Censorship about opinions does not belong here.
Re: fphttpclient: Connect to URL failed.
« Reply #15 on: July 29, 2024, 11:49:41 am »
Can you type
Code: Bash  [Select][+][-]
  1.  openssl version
in a console or terminal?
If I smell bad code it usually is bad code and that includes my own code.

CM630

  • Hero Member
  • *****
  • Posts: 1168
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: fphttpclient: Connect to URL failed.
« Reply #16 on: July 29, 2024, 06:55:37 pm »

...
I have installed (some time ago) OpenSSL-Win v.1.0.2u and copied the ssleay32.dll, libeay32.dll to Windows\System32.
...

What do you mean by "I have installed"? I have downloaded https://wiki.overbyte.eu/arch/openssl-1.0.2u-win64.zip.
There is nothing that seems installable there.
I have compiled your app (source attached). When I run it I get:


Quote

An unhandled exception occurred at $00430021:
ESocketError: Connect to github.com:443 failed.
  $00430021
  $00413F22
  $00415E30
  $00416189
  $0041675F
  $00401920  HTTPTest,  line 12 of project1.lpr
  $004019DE  $main,  line 20 of project1.lpr


I have copied libeay32.dll and ssleay32.dll in its folder. Still I get the same.
Then I have removed then and copied the entire content of https://wiki.overbyte.eu/arch/openssl-3.3.1-win64.zip, which was proposed by @Thaddy.
Still the same.



Can you type
Code: Bash  [Select][+][-]
  1.  openssl version
in a console or terminal?

I get 'openssl' is not recognized as an internal or external command,
operable program or batch file. in Windows.


In Linux I get:

OpenSSL 3.0.2 15 Mar 2022 (Library: OpenSSL 3.0.2 15 Mar 2022)
But still, @Alpine's app returns:


Quote
An unhandled exception occurred at $000000000042DBE6:
EInOutError: Could not initialize OpenSSL library
  $000000000042DBE6
  $000000000042E22A
  $0000000000427BAE
  $000000000042A717
  $000000000042AEE9
  $00000000004012C3  HTTPTest,  line 12 of project1.lpr
  $00000000004013B7  $main,  line 20 of project1.lpr

On a PC with Win10, @Alpine's coded showed exactly what @Thaddy expected.
« Last Edit: July 29, 2024, 07:12:07 pm by CM630 »
Лазар 3,4 32 bit (sometimes 64 bit); FPC3,2,2

alpine

  • Hero Member
  • *****
  • Posts: 1255
Re: fphttpclient: Connect to URL failed.
« Reply #17 on: July 29, 2024, 07:27:13 pm »

...
I have installed (some time ago) OpenSSL-Win v.1.0.2u and copied the ssleay32.dll, libeay32.dll to Windows\System32.
...

What do you mean by "I have installed"? I have downloaded https://wiki.overbyte.eu/arch/openssl-1.0.2u-win64.zip.
There is nothing that seems installable there.
I have compiled your app (source attached). When I run it I get:


Quote

An unhandled exception occurred at $00430021:
ESocketError: Connect to github.com:443 failed.
  $00430021
  $00413F22
  $00415E30
  $00416189
  $0041675F
  $00401920  HTTPTest,  line 12 of project1.lpr
  $004019DE  $main,  line 20 of project1.lpr


I have copied libeay32.dll and ssleay32.dll in its folder. Still I get the same.
Then I have removed then and copied the entire content of https://wiki.overbyte.eu/arch/openssl-3.3.1-win64.zip, which was proposed by @Thaddy.
Still the same.

Please, would you state for each machine you're trying: What is the OS version, OS bitness, OpenSSL DLLs version, OpenSSL DLLs bitness, and the full version of your FPC compiler and what is the project application target bitness. Thank you!
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

CM630

  • Hero Member
  • *****
  • Posts: 1168
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: fphttpclient: Connect to URL failed.
« Reply #18 on: July 29, 2024, 07:43:24 pm »
Linux:

Operating System: Linux Mint 21.3                 
Kernel: Linux 5.15.0-91-generic
Architecture: x86-64
Hardware Vendor: System manufacturer
Hardware Model: System Product Name

Lazarus 2.2.0+dfsg1_5 ununtu1, 64 bit
FPC version: 3.2.2
Revision: Debian Package 2.2.0+dfsg1_5 ubuntu1, x86_64-linux-gtk2


Windows:
  Windows 7, 64 bit.
  Lazarus 2.2.4, 64 bit (latest official release)


About OpenSSL DLLs version, OpenSSL DLLs bitness,  - I can say nothing, I am downloading what you tell me.
« Last Edit: July 30, 2024, 06:33:41 am by CM630 »
Лазар 3,4 32 bit (sometimes 64 bit); FPC3,2,2

alpine

  • Hero Member
  • *****
  • Posts: 1255
Re: fphttpclient: Connect to URL failed.
« Reply #19 on: July 29, 2024, 09:02:22 pm »
Well, here is an excerpt from openssl.pas with file names to be loaded:
Code: Pascal  [Select][+][-]
  1. var
  2.   {$IFDEF WINDOWS}
  3.   DLLSSLName: string = 'ssleay32.dll';
  4.   DLLSSLName2: string = 'libssl32.dll';
  5.   DLLSSLName3: string = {$IFDEF WIN64}'libssl-1_1-x64.dll'{$ELSE}'libssl-1_1.dll'{$ENDIF};
  6.   DLLUtilName: string = 'libeay32.dll';
  7.   DLLUtilName2: string = {$IFDEF WIN64}'libcrypto-1_1-x64.dll'{$ELSE}'libcrypto-1_1.dll'{$ENDIF};
  8.  

then excerpt  from opensslsockets.pp:
Code: Pascal  [Select][+][-]
  1. Resourcestring
  2.   SErrNoLibraryInit = 'Could not initialize OpenSSL library';
  3.  
  4. Procedure MaybeInitSSLInterface;
  5.  
  6. begin
  7.   if not IsSSLloaded then
  8.     if not InitSSLInterface then
  9.       Raise EInOutError.Create(SErrNoLibraryInit);
  10. end;

As I can see in your Linux output the above exception (EInOutError) but not in your Win7 output, I guess the library was initialized correctly in Win7.

OTOH:
Quote
On a PC with Win10, @Alpine's coded showed exactly what @Thaddy expected.
Does it mean that it works in Win10?

If that is the case (and you're trying from the same network) then the:
Quote
ESocketError: Connect to github.com:443 failed.
is something IMO very specific to your Win7 installation, , e.g. like this.

Moreover you mentioned it worked some time ago.






« Last Edit: July 29, 2024, 09:06:28 pm by alpine »
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

TRon

  • Hero Member
  • *****
  • Posts: 3176
Re: fphttpclient: Connect to URL failed.
« Reply #20 on: July 29, 2024, 10:49:46 pm »
As I can see in your Linux output the above exception (EInOutError) but not in your Win7 output, I guess the library was initialized correctly in Win7.
TS has indeed two distinct situations
1) Linux where the library is not loaded at all (unable to locate a supported ssl library version) and
2) Win7 where it seems there is an ssl library loaded but is unable to securely connect.

Quote
is something IMO very specific to your Win7 installation, , e.g. like this.
Nice catch. I did not found that yet but I guess it makes sense in TS' context.

Quote
Moreover you mentioned it worked some time ago.
Indeed, that is why I asked what something like wget does when trying to retrieve the same information on that win7 machine. Unfortunately TS did not answer. Basically nothing should be able to connect if your link indeed applies.
All software is open source (as long as you can read assembler)

CM630

  • Hero Member
  • *****
  • Posts: 1168
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: fphttpclient: Connect to URL failed.
« Reply #21 on: July 29, 2024, 11:30:46 pm »
In Windows it used to work before a clean reinstall. After it it does not work.
Win 10 was on another place, but it is not impossible to bring the pc to the same location, maybe next week.
But I got the impression, that the Linux has an SSL, since it reports its version, now you are telling me there is no SSL  :o


In Win, I will try to copy all these files in the folder ot the app.



DLLSSLName: string = 'ssleay32.dll';
  DLLSSLName2: string = 'libssl32.dll';
  DLLSSLName3: string = {$IFDEF WIN64}'libssl-1_1-x64.dll'{$ELSE}'libssl-1_1.dll'{$ENDIF};
  DLLUtilName: string = 'libeay32.dll';
  DLLUtilName2: string = {$IFDEF WIN64}'libcrypto-1_1-x64.dll'{$ELSE}'libcrypto-1_1.dll'{$ENDIF};

« Last Edit: July 29, 2024, 11:33:09 pm by CM630 »
Лазар 3,4 32 bit (sometimes 64 bit); FPC3,2,2

TRon

  • Hero Member
  • *****
  • Posts: 3176
Re: fphttpclient: Connect to URL failed.
« Reply #22 on: July 29, 2024, 11:57:02 pm »
But I got the impression, that the Linux has an SSL, since it reports its version, now you are telling me there is no SSL  :o
No, you are reading too much into what was written  :)

In one of your first post your stated (and that is the only place where it is stated)
I tried the same code it in Linux Mint, latest version.
I have got the following exception:
Could not initialize OpenSSL library.
To which I responded that the free pascal openssl unit is unable to open/load the openssl library.

You have also shown us/stated that openssl is installed on your system.

In Linux I get:
OpenSSL 3.0.2 15 Mar 2022 (Library: OpenSSL 3.0.2 15 Mar 2022)

So that can only mean one thing and that is that the free pascal openssl unit is unable to load your openssl library. There can be several reasons for that:
- the openssl library version number installed on your system in not supported by Free Pascal
- the installed library depends on other (3th party) libraries that are not installed (properly) (and thus fails to load).
- Free Pascal is unable to locate the openssl library installed on your system. That is usually caused by missing the correct softlink (usually installed by a package manager installing the dev package of the library that you are trying to load/use)

So, it is not a yes and/or no situation but a more complex one. My guess would be the missing softlink. In order to verify you can show us the output of the terminal command  apt search libssl-dev

BTW: the fact that you are mixing 3 different operating systems/setups into the equation isn't particularly helpful either.

FWIW: The answer provided in this post only applies to linux and/or linux-alike operating systems.
« Last Edit: July 30, 2024, 12:26:09 am by TRon »
All software is open source (as long as you can read assembler)

CM630

  • Hero Member
  • *****
  • Posts: 1168
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: fphttpclient: Connect to URL failed.
« Reply #23 on: July 30, 2024, 06:22:01 am »

So, it is not a yes and/or no situation but a more complex one. My guess would be the missing softlink. In order to verify you can show us the output of the terminal command  apt search libssl-dev



That is what I get from apt search libssl-dev:


Quote

:~$ apt search libssl-dev
p   libssl-dev                      - Secure Sockets Layer toolkit - development
p   libssl-dev:i386                 - Secure Sockets Layer toolkit - development

BTW, I just noticed, that in my previous post, I have stated some absurd Lazarus versions, I will fix that when possible.
« Last Edit: July 30, 2024, 07:27:36 am by CM630 »
Лазар 3,4 32 bit (sometimes 64 bit); FPC3,2,2

alpine

  • Hero Member
  • *****
  • Posts: 1255
Re: fphttpclient: Connect to URL failed.
« Reply #24 on: July 30, 2024, 09:30:23 am »
I would try with wget on your Win7 machine first, as TRon suggested.
Quote
BTW, I just noticed, that in my previous post, I have stated some absurd Lazarus versions, I will fix that when possible.
Lazarus version is not relevant, FPC version is.
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

silvercoder70

  • New Member
  • *
  • Posts: 44
Re: fphttpclient: Connect to URL failed.
« Reply #25 on: July 30, 2024, 10:05:01 am »
In Windows it used to work before a clean reinstall. After it it does not work.

Just going out on a limb here ... I would search the whole of your Windows PC for the SSL libraries (DLLs). My guess is that you will have multiple copies from different (for lack of a better word) and the one that gets picked up  when the program runs is old (/borked) and this is what is giving you grief. Once you have the latest version, put them into the same folder as your .exe program and run again?

TRon

  • Hero Member
  • *****
  • Posts: 3176
Re: fphttpclient: Connect to URL failed.
« Reply #26 on: July 31, 2024, 12:24:28 am »
That is what I get from apt search libssl-dev:

[/size]
Quote

:~$ apt search libssl-dev
p   libssl-dev                      - Secure Sockets Layer toolkit - development
p   libssl-dev:i386                 - Secure Sockets Layer toolkit - development
Purged or never installed.

Please install (if your target 64-bit then the package which name does not include i386 and when you target 32-bit then the package name with i386 attached) and retry the code.

That should take care of adding the softlink so that (other) programs that you compile and link against openssl are able to find/locate and load the (correct) library.

Quote
BTW, I just noticed, that in my previous post, I have stated some absurd Lazarus versions, I will fix that when possible.
As already stated by alpine, the Lazarus version number does not really matter as the openssl package is from FPC.
« Last Edit: July 31, 2024, 12:27:13 am by TRon »
All software is open source (as long as you can read assembler)

dbannon

  • Hero Member
  • *****
  • Posts: 3026
    • tomboy-ng, a rewrite of the classic Tomboy
Re: fphttpclient: Connect to URL failed.
« Reply #27 on: July 31, 2024, 11:27:22 am »
Lets be clear here. The OP believes that Lazarus 2.2.4 is the latest official release, he/she probably is using FPC3.2.2 ?

On Linux, it will not open openssl3 library unless the openssl dev libraries are installed. That is because FPC322 does not know the file name, you must have that symlink installed by the dev package (intended for linking but helping at runtime).  I do not know if the same problem exists on Windows, might be even more serious there.

On Windows its possible to use openssl in two ways, using an openssl installer that make it available system wide (and "openssl version" will work) or just tuck the two dll files in with your binary.

Sounds like linux Mint is being used, please type, at the command line -

dpkg -l | grep libssl <enter>     // that switch is a lowercase L, not a one

It should show "libssl-dev:amd64" and "libssl3:amd64" or similar. On Mint, easy solution to install the openssl dev package.  Better solution would be to download and make the fpc324-rc1 source and use that. It knows how to open libssl3 directly.

This code - https://github.com/tomboy-notes/tomboy-ng/blob/master/source/transgithub.pas  down loads from github both with and without authentication. See in particular the DownloaderSafe() function.  But I build it using FPC324 !

Davo

 
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

CM630

  • Hero Member
  • *****
  • Posts: 1168
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: fphttpclient: Connect to URL failed.
« Reply #28 on: July 31, 2024, 11:36:22 pm »
Alpines example seems to work now in Linux Mint  :D
Now I get

Quote
Status: 200
Connection: close
Content-Length: 13800439
Content-Type: application/octet-stream
Last-Modified: Tue, 23 Aug 2022 12:48:53 GMT
ETag: "0x8DA8505D5C413A5"
Server: Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-request-id: 013be7f4-801e-001b-17c3-e0df56000000
x-ms-version: 2020-10-02
x-ms-creation-time: Tue, 23 Aug 2022 12:48:53 GMT
x-ms-blob-content-md5: 6Z7eT2N/r68pzz+DDO8QhA==
x-ms-lease-status: unlocked
x-ms-lease-state: available
x-ms-blob-type: BlockBlob
Content-Disposition: attachment; filename=lazpaint7.2.2_setup_win32_win64.exe
x-ms-server-encrypted: true
Via: 1.1 varnish, 1.1 varnish
Fastly-Restarts: 1
Accept-Ranges: bytes
Date: Wed, 31 Jul 2024 21:32:46 GMT
Age: 685
X-Served-By: cache-iad-kjyo7100122-IAD, cache-sof1510039-SOF
X-Cache: HIT, HIT
X-Cache-Hits: 5, 1
X-Timer: S1722461566.728787,VS0,VE1
All I did was:
sudo apt install libssl-dev

Unfortunately meawhile I have damaged my Lazarus and I cannot try until anything else until I fix it.

I will continue attempts with Windows next week.




Лазар 3,4 32 bit (sometimes 64 bit); FPC3,2,2

dbannon

  • Hero Member
  • *****
  • Posts: 3026
    • tomboy-ng, a rewrite of the classic Tomboy
Re: fphttpclient: Connect to URL failed.
« Reply #29 on: August 01, 2024, 01:40:34 pm »
...
All I did was:
sudo apt install libssl-dev

Glad you are making progress.

Don't forget that if you distribute your app, your end users will also have to have libssl-dev installed. And they will ask why ?

As I mentioned, a better solution is to build with a newer FPC.

Davo
 
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

 

TinyPortal © 2005-2018