[SOLVED] Indy and SSL lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- DanishMale · 2017-02-23 06:24 Solution: I found that the DateTime handling in the DLL was mixed up and had to be rewritten to form the dynamic URL Hi, I am going NUTS... over Indy and their OpenSSL.... I am trying to create a DLL which collects some JSON data from a website, I have got to work perfectly on numerous of other sites, however, this sites really got got my brains out... If I create this app an run it directly as an EXE with only this changed in the SSLOptions.Method := sslvTLSv1_2 and SSLOptions.Versions := [sslvTLSv1_2] to the IdSSLIOHandlerSocketOpenSSL  it works perfectly but as DLL NOT: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  function CreateSSLHandler: TIdSSLIOHandlerSocketOpenSSL;var  SSL_org: TIdSSLIOHandlerSocketOpenSSL;begin  SSL_org := TIdSSLIOHandlerSocketOpenSSL.Create(nil);  SSL_org.IPVersion := Id_IPv4;  SSL_org.MaxLineAction := maException;  SSL_org.MaxLineLength := 16384;  SSL_org.Port := 0;  SSL_org.ReadTimeout := -1;  SSL_org.ReuseSocket := rsOSDependent;  SSL_org.SendBufferSize := 32768;  SSL_org.SSLOptions.Method := sslvTLSv1_2;  SSL_org.SSLOptions.Mode := sslmUnassigned;  SSL_org.SSLOPtions.SSLVersions := [sslvTLSv1_2];  SSL_org.SSLOptions.VerifyDepth := 0;  SSL_org.UseNagle := True;  CreateSSLHandler := SSL_org;end; function CreateHTTP: TIdHTTP;var  HTTP_org: TIdHTTP;begin  HTTP_org := TIdHTTP.Create(nil);  HTTP_org.IOHandler := CreateSSLHandler;  HTTP_org.Request.ContentType := 'text/html';  HTTP_org.AllowCookies := True;  HTTP_org.ProxyParams.BasicAuthentication := False;  HTTP_org.ProxyParams.ProxyPort := 0;  HTTP_org.Request.ContentLength := -1;  HTTP_org.Request.ContentRangeEnd := -1;  HTTP_org.Request.ContentRangeStart := -1;  HTTP_org.Request.ContentRangeInstanceLength := -1;  HTTP_org.Request.Date := 0;  HTTP_org.Request.Expires := 0;  HTTP_org.Request.LastModified := 0;  HTTP_org.Request.Accept := 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';  HTTP_org.Request.BasicAuthentication := False;  HTTP_org.Request.UserAgent := 'My Custom UserAgent';  HTTP_org.Request.Ranges.Units := 'bytes';  HTTP_org.HTTPOptions := [hoForceEncodeParams];  HTTP_org.ProtocolVersion := pv1_1;  CreateHTTP := HTTP_org;end;       It's exactly the same settings as in the EXE file .. which works  I am getting desperate .... ---------------------------------------------------------------------- Cyrax · 2017-02-23 06:30 Which site you are trying to access? Can you show to us your application main source code? ---------------------------------------------------------------------- DanishMale · 2017-02-23 06:33 this site with this url: https://web- api.horizon.tv/oesp/api/CH/fra/web/programschedules/20170225/1 ---------------------------------------------------------------------- Cyrax · 2017-02-23 06:54 Which version of Indy you are using? ---------------------------------------------------------------------- balazsszekely · 2017-02-23 07:19 QuoteIf I create this app an run it directly as an EXE with only this changed in the SSLOptions.Method := sslvTLSv1_2 and SSLOptions.Versions := [sslvTLSv1_2] to the IdSSLIOHandlerSocketOpenSSL  it works perfectly but as DLL NOT:Ok and how exactly fails? What is the error message? I see in your description Lazarus 1.6 x64, are you creating 64bit application/dll? Make sure libeay32.dll and ssleay32.dll match your binary format so you don't mix 32 with 64 and vice versa. Of course this is just guessing...the problem may be something completely different. ---------------------------------------------------------------------- DanishMale · 2017-02-23 15:02 The error looks like this: Error connecting with SSL. error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure I have used the  libeay32.dll and ssleay32.dll in previous x64 DLL / Apps ---------------------------------------------------------------------- Phil · 2017-02-23 15:39 Quote from: DanishMale on February 23, 2017, 04:02:47 pmError connecting with SSL. error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure I feel your pain. I would spend the day searching that error message. I solved a recent Indy problem by trying various suggestions given here: https://stackoverflow.com/questions/35987485/eidosslconnecterror- error-connecting-with-ssl-eof-was-observed# Interestingly, FPC's HTTP client did not have this EOF problem at all. You could try FPC's just to see if there's any difference. I've had a lot of problems keeping code that retrieves data from Web sites running, as they transition from http to https, change APIs, change handshake policies, change WSDL, etc. No two http clients in my experience work the same and they all have problems if you're hitting against enough different sites. I work with 4: Indy, FPC, Synapse and Foundation (Mac). Also, who's responsible for freeing the TIdSSLIOHandlerSocketOpenSSL object? It looks like you're assuming that Indy is. Edit: I've never seen a problem where it works in an executable and not in a dynamic library. In my experience, if it works in one, it will work in the other and vice versa. Make sure both the executable and the library are using the same SSL libraries. ---------------------------------------------------------------------- Remy Lebeau · 2017-02-24 03:24 Quote from: DanishMale on February 23, 2017, 07:24:47 amI am going NUTS... over Indy and their OpenSSL.... It is not OUR OpenSSL.  OpenSSL is a 3rd party open source library independent of Indy. To use TLS 1.2 in Indy, make sure you are using up-to-date versions of Indy and OpenSSL 1.0.2 (Indy does not support OpenSSL 1.1.0 yet). Quote from: DanishMale on February 23, 2017, 07:24:47 amIf I create this app an run it directly as an EXE with only this changed in the SSLOptions.Method := sslvTLSv1_2 and SSLOptions.Versions := [sslvTLSv1_2] to the IdSSLIOHandlerSocketOpenSSL  it works perfectly but as DLL NOT Neither Indy nor OpenSSL behave differently whether used in an EXE or a DLL.  So something else is going on. Quote from: DanishMale on February 23, 2017, 07:24:47 amIt's exactly the same settings as in the EXE file .. which works  Have you tried using a packet sniffer, like Wireshark, to look at the actual TLS handshake to see if anything is different between the EXE and DLL handshakes? Quote from: DanishMale on February 23, 2017, 07:24:47 amError connecting with SSL. error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure A TLS alert comes from the peer.  So, in this case, it means the HTTP server is rejecting the TLS handshake.  Now you need to figure out why.  And that is where Wireshark comes into play.