Recent

Author Topic: TFPHTTPClient : ESSL failed to create SSL context  (Read 10475 times)

guest58172

  • Guest
TFPHTTPClient : ESSL failed to create SSL context
« on: December 06, 2017, 07:12:48 pm »
I'm on Fedora 27 with libopenssl / libcrypto at 1.1.0g, Laz 1.6.4, FPC 3.0.2. A simple request gives the error "ESSL, Failed to create SSL context". I suspect that the versions the loader use to load the libraries are not up to date, see

https://github.com/graemeg/freepascal/blob/master/packages/openssl/src/openssl.pas#L112

Just
Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. uses fphttpclient;
  4.  
  5. procedure test;
  6. var
  7.   cli: TFPHTTPClient = nil;
  8. begin
  9.   cli := TFPHTTPClient.Create(nil);
  10.   try
  11.     cli.AddHeader('User-Agent','Mozilla/5.0 (compatible; fpweb)');
  12.     cli.Get('https://api.github.com/users/defunkt');
  13.   finally
  14.     cli.free;
  15.   end;
  16. end;
  17.  
  18. begin
  19.   test();
  20. end.

is enough to get the error. The same kind of request worked fine when i made the feature using another distribution (although once done i didn't use the feature so it could be broken too for months).

What can i do ?

guest58172

  • Guest
Re: TFPHTTPClient : ESSL failed to create SSL context
« Reply #1 on: December 06, 2017, 07:15:12 pm »
And don't tell me "use wget / curl" please  ;D

guest58172

  • Guest
Re: TFPHTTPClient : ESSL failed to create SSL context
« Reply #2 on: December 06, 2017, 09:00:14 pm »
After modification of the version string the same error is still raised. I suspect an API breakage from 1.0.X to 1.1.X. Can anyone run the sample above with SSL 1.1 (1.1.0f or 1.1.0g) ?

eolandro

  • New Member
  • *
  • Posts: 14
Re: TFPHTTPClient : ESSL failed to create SSL context
« Reply #3 on: August 27, 2018, 04:04:34 am »
Did you find answer? i'm stuck in the same error.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8744
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: TFPHTTPClient : ESSL failed to create SSL context
« Reply #4 on: August 27, 2018, 11:02:21 am »
Working for me, but I have both 1.0.2.p and 1.1.0.i installed.
Code: [Select]
$ cat a.pas
uses fphttpclient;
 
procedure test;
var
  cli: TFPHTTPClient = nil;
begin
  cli := TFPHTTPClient.Create(nil);
  try
    cli.AddHeader('User-Agent','Mozilla/5.0 (compatible; fpweb)');
    cli.Get('https://api.github.com/users/defunkt');
  finally
    cli.free;
  end;
end;
 
begin
  test();
end.

$ fpc -S2 a.pas
Hint: End of reading config file /etc/fpc.cfg
Target OS: Linux for x86-64
Compiling a.pas
Linking a
a.pas(18,1) Warning: "crtbegin.o" not found, this will probably cause a linking failure
a.pas(18,1) Warning: "crtend.o" not found, this will probably cause a linking failure
19 lines compiled, 0.4 sec
2 warning(s) issued
1 hint(s) issued

$ ./a
{"login":"defunkt","id":2,"node_id":"MDQ6VXNlcjI=","avatar_url":"https://avatars0.githubusercontent.com/u/2?v=4","gravatar_id":"","url":"https://api.github.com/users/defunkt","html_url":"https://github.com/defunkt","followers_url":"https://api.github.com/users/defunkt/followers","following_url":"https://api.github.com/users/defunkt/following{/other_user}","gists_url":"https://api.github.com/users/defunkt/gists{/gist_id}","starred_url":"https://api.github.com/users/defunkt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/defunkt/subscriptions","organizations_url":"https://api.github.com/users/defunkt/orgs","repos_url":"https://api.github.com/users/defunkt/repos","events_url":"https://api.github.com/users/defunkt/events{/privacy}","received_events_url":"https://api.github.com/users/defunkt/received_events","type":"User","site_admin":true,"name":"Chris Wanstrath","company":"@github ","blog":"http://chriswanstrath.com/","location":"San Francisco","email":null,"hireable":null,"bio":"🍔 ","public_repos":107,"public_gists":273,"followers":20407,"following":210,"created_at":"2007-10-20T05:24:19Z","updated_at":"2018-08-15T02:05:37Z"}

eolandro

  • New Member
  • *
  • Posts: 14
Re: TFPHTTPClient : ESSL failed to create SSL context
« Reply #5 on: August 28, 2018, 08:17:40 am »
I'm still getting the error in debian unstable with openssl 1.1.0h-4.
openssl from 1.0.X to 1.1 changes many things (includes, structs even version handling).

IMO https://github.com/graemeg/freepascal/blob/master/packages/fcl-net/src/sslsockets.pp#L44

TSSLSocketHandler it must be create FCTX with some type like says TSSLContext.Create  in https://github.com/graemeg/freepascal/blob/master/packages/openssl/src/fpopenssl.pp#L177 but it seems don't initialize  TSSLSocketHandler.create in https://github.com/graemeg/freepascal/blob/master/packages/fcl-net/src/sslsockets.pp#L135


TCH

  • Full Member
  • ***
  • Posts: 200
Re: TFPHTTPClient : ESSL failed to create SSL context
« Reply #6 on: January 17, 2019, 11:33:25 am »
I've ran into this just now and i managed to solve it on my computer.

It worked under Debian 8, but when i upgraded to Debian 9, then it broke. However, if you install libssl1.0.0 from the Debian 8 repo and downgrade your libssl-dev to the same version, then it will work, after you rebuilt your program. (Don't try to remove libssl-dev, it will broke tons of stuff, do
Code: Text  [Select][+][-]
  1. wget http://security.debian.org/debian-security/pool/updates/main/o/openssl/libssl-dev_1.0.1t-1+deb8u10_amd64.deb
  2. dpkg -i libssl-dev_1.0.1t-1+deb8u10_amd64.deb
  3. rm libssl-dev_1.0.1t-1+deb8u10_amd64.deb
instead.)

I do not know the whys, but this solved my problem.

simonm

  • Newbie
  • Posts: 3
Re: TFPHTTPClient : ESSL failed to create SSL context
« Reply #7 on: January 18, 2019, 11:28:32 pm »
I had the same problem with debian 9 (testing). Without downgrading to debian 8 packages, I just installed the libssl1.0-dev package and all was good again. This process uninstalled the more recent version which is installed by the libssl-dev package and allows both libssl1.1 and libssl1.0.2 to be installed.

Haven't had any problems yet with this setup. Like TCH, I have no idea why but when I get a chance I'll look into it deeper.

bonmario

  • Sr. Member
  • ****
  • Posts: 346
Re: TFPHTTPClient : ESSL failed to create SSL context
« Reply #8 on: April 20, 2019, 07:45:34 pm »
A simple request gives the error "ESSL, Failed to create SSL context".

Hi,
i have the same problem today, after upgrading my Ubuntu from 18.10 to 19.04.

Someone know how i can solve it?

Thanks, Mario

bonmario

  • Sr. Member
  • ****
  • Posts: 346
Re: TFPHTTPClient : ESSL failed to create SSL context
« Reply #9 on: April 21, 2019, 09:08:45 am »
Some versions ...
- openssl version1.1.1b-1ubuntu2
- libssl version 1.1.1b-1ubuntu2
- libssl-dev version 1.1.1b-1ubuntu2
- Lazarus 2.1.0 r61017 FPC 3.0.4 x86_64-linux-gtk2

Thanks, Mario

Handoko

  • Hero Member
  • *****
  • Posts: 5122
  • My goal: build my own game engine using Lazarus
Re: TFPHTTPClient : ESSL failed to create SSL context
« Reply #10 on: May 09, 2019, 05:52:05 am »
I got same error too after I upgraded to Ubuntu 19.04.
Any suggestion what should I do?

bonmario

  • Sr. Member
  • ****
  • Posts: 346
Re: TFPHTTPClient : ESSL failed to create SSL context
« Reply #11 on: May 09, 2019, 07:54:51 am »
You can try one of these:
- use Synapse SVN: https://forum.lazarus.freepascal.org/index.php/topic,45201.msg319446.html#msg319446 (this worked for me)
- try to download fcl-web from SVN (i've never tried this solution).
- download openssl 1.0 and modify fcl-web to use that version (i've never tried this solution).


Hi, Mario

bonmario

  • Sr. Member
  • ****
  • Posts: 346
Re: TFPHTTPClient : ESSL failed to create SSL context
« Reply #12 on: August 08, 2019, 10:06:30 am »
Hi,
someone have found a solution in meantime to correct fcl-web's problem?

Thanks, Mario

Thaddy

  • Hero Member
  • *****
  • Posts: 14161
  • Probably until I exterminate Putin.
Re: TFPHTTPClient : ESSL failed to create SSL context
« Reply #13 on: August 08, 2019, 10:51:41 am »
The original code, one unit added, openssl version is 1.1.1c
Code: Pascal  [Select][+][-]
  1. program Project1;
  2. {$mode delphi}
  3. uses opensslsockets,fphttpclient;
  4.  
  5. procedure test;
  6.  
  7. var
  8.   cli: TFPHTTPClient = nil;
  9. begin
  10.   cli := TFPHTTPClient.Create(nil);
  11.   try
  12.     cli.AddHeader('User-Agent','Mozilla/5.0 (compatible; fpweb)');
  13.     cli.Get('https://api.github.com/users/defunkt');
  14.   finally
  15.     cli.free;
  16.   end;
  17. end;
  18.  
  19. begin
  20.   test();
  21. end.

Works like a charm
« Last Edit: August 08, 2019, 11:03:53 am by Thaddy »
Specialize a type, not a var.

rumen-lazarus

  • Newbie
  • Posts: 3
Re: TFPHTTPClient : ESSL failed to create SSL context
« Reply #14 on: August 08, 2019, 11:05:47 am »
  Hi,
  Try this:

      HttpClient.OnGetSocketHandler:=HttpClientGetSocketHandler;

     ......

procedure TForm1.HttpClientGetSocketHandler(Sender: TObject;
  const UseSSL: Boolean; out AHandler: TSocketHandler);
begin
  If UseSSL then begin
    AHandler:=TSSLSocketHandler.Create;
    TSSLSocketHandler(AHandler).SSLType:=stTLSv1_1;  // <--
  end else begin
      ....
  end;
end;


 

TinyPortal © 2005-2018