Indy10 HTTP & SSL issues lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- JD · 2016-07-25 15:06 Hi there everybody, I'm trying to connect to an Indy HTTP server from an Indy HTTP client using the code below: Server side: 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   //  HTTPServer := TIdHTTPServer.Create(nil);  HTTPIOHandler := TIdServerIOHandlerSSLOpenSSL.Create(nil);  HTTPIOHandler.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2];   //  with HTTPServer do  begin    IOHandler         := HTTPIOHandler;    OnCommandGet      := @HTTPServerCommandGet;    OnCommandOther    := @HTTPServerCommandOther;    OnConnect         := @HTTPServerConnect;    OnCreateSession   := @HTTPServerCreateSession;    OnDisconnect      := @HTTPServerDisconnect;    OnSessionEnd      := @HTTPServerSessionEnd;    OnSessionStart    := @HTTPServerSessionStart;    KeepAlive         := True;  end;  Client side: 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   lHTTP := TIdHTTP.Create(nil);  lIOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);  lIOHandler.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2];  //  try    lHTTP.Request.Username := Trim(User.Text);  lHTTP.Request.Password := Trim(Password.Text);    lHTTP.IOHandler := lIOHandler;    lHTTP.HandleRedirects := True;    s := lHTTP.Get(Format('https://%s:%d' + '/login', [Host, Port]));    ShowMessage(s);  finally    lHTTP.Free;    lIOHandler.Free;  end;  The client throws an exception saying sslv3 alert handshake failure (see attached screenshot). Everything works perfectly without the SSL related code parts. In addition, I'm using the latest libeay32.dll and ssleay32.dll that I downloaded from the indy.fulgan.com site. Can anyone tell me what I'm doing wrong? Thanks, JD ---------------------------------------------------------------------- Phil · 2016-07-25 15:10 That looks like an Indy exception. Find where that occurs in Indy source. Might be a clue as to what's happening. If it were related to the SSL .dll's, I would expect a different exception. Also, it looks like something to do with the version of SSL. I'm not familiar with that, but what "version" certificate does your server have? ---------------------------------------------------------------------- JD · 2016-07-25 15:14 Quote from: Phil on July 25, 2016, 05:10:56 pmThat looks like an Indy exception. Find where that occurs in Indy source. Might be a clue as to what's happening. If it were related to the SSL .dll's, I would expect a different exception. Also, it looks like something to do with the version of SSL. I'm not familiar with that, but what "version" certificate does your server have? I'm not using any certificates at all. ---------------------------------------------------------------------- Phil · 2016-07-25 15:28 Does it make any difference if you use FPC HTTP client and server instead of Indy? You'll probably need an SSL certificate eventually: https://www.startssl.com/ ---------------------------------------------------------------------- JD · 2016-07-25 17:17 Quote from: Phil on July 25, 2016, 05:28:27 pmDoes it make any difference if you use FPC HTTP client and server instead of Indy? You'll probably need an SSL certificate eventually: https://www.startssl.com/ I can't use FPC HTTP client because the code snippets I posted are part of a large application & rewriting it is simply not possible. I'll take a look at the link you gave me & see what I can learn from it. Thanks JD ---------------------------------------------------------------------- Phil · 2016-07-25 17:29 Many links turn up for that error message. http://eigenjoy.com/2008/04/26/fix-for-sslv3-alert-handshake-failure- opensslsslsslerror/ ---------------------------------------------------------------------- Thaddy · 2016-07-25 18:49 Quote from: Phil on July 25, 2016, 07:29:50 pmMany links turn up for that error message. http://eigenjoy.com/2008/04/26/fix-for-sslv3-alert-handshake-failure- opensslsslsslerror/ Google on POODLE attack: SSL3 is highly unsafe and not accepted any more by recent decent server software. You should not use it! No, I mean, really should not use it!!!! Better to use a recent version (1.1 or higher) of TLS. There's a good write-up in wikipedia: https://en.wikipedia.org/wiki/Tr ansport_Layer_Security#SSL_1.0.2C_2.0_and_3.0 Btw: whereas the wiki states that SSLv2 is prohibited, it is considered somewhat safe as a bottom-line fall-back, whereas SSLv3 should be avoided like the plague. Hence you will get errors if your software tries to connect to properly maintained servers if you do ONLY support  SSLv3 on the client side. That is programmer error big time. E.g. in OpenSLL compiled from source you have to EXPLICITLY enable SSLv3 to be able to support it. And you will get abused by warnings Do not try this at home. OpenSSL is very, very,very difficult to compile correctly from source. Since the majority of server software use OpenSSL, like Apache and ngynx, SSLv3 won't work anymore unless your engineer is called "sleeping beauty". ---------------------------------------------------------------------- Thaddy · 2016-07-25 19:19 Btw: I am surprised (NOT!  )that Indy still seems to support SSLv3?  (Yes,yes, yes, Indy Bashing. Icecubes are gone, but temperature is down too, so garden is safe) BTW: Answering the original question: TLS 1.0 almost equals SSLv3 so the exception is correct. Because of what I descibed above. You can remove sslvTLSv1 and your code should work. For older software you can add sslv2 as the only allowed fallback. [edit] Indy uses opensll (and you have a recent version of openSSL installed, hence it returns the exception) but Indy should throw a compile-time warning or better error  when you want to use ssl3 or tls1. Or remove the option, but that would break legacy too easy. I know that. But QED: OpenSSL doesn't work anymore.... With SSLv3 that is.... Remy is up to the job to correct this. I think. [edit2] Note TLS1.2 will not fall back to ssl2. tls1.1 needs to be in the chain to fall back to sslv2 but that is still allowed for the time being afaik. ssl3 and tls1 are always out of the fall back chain in current OpenSSL versions. ---------------------------------------------------------------------- Thaddy · 2016-07-26 15:09 This code should work with up-to-date OpenSSL: Server side: 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   //  HTTPServer := TIdHTTPServer.Create(nil);  HTTPIOHandler := TIdServerIOHandlerSSLOpenSSL.Create(nil);  HTTPIOHandler.SSLOptions.SSLVersions := [sslvTLSv1_1, sslvTLSv1_2];   //  with HTTPServer do  begin    IOHandler         := HTTPIOHandler;  OnCommandGet      := @HTTPServerCommandGet;    OnCommandOther    := @HTTPServerCommandOther;    OnConnect         := @HTTPServerConnect;  OnCreateSession   := @HTTPServerCreateSession;    OnDisconnect      := @HTTPServerDisconnect;    OnSessionEnd      := @HTTPServerSessionEnd;    OnSessionStart    := @HTTPServerSessionStart;    KeepAlive         := True;  end;  Client side: 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   lHTTP := TIdHTTP.Create(nil);  lIOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);  lIOHandler.SSLOptions.SSLVersions := [sslvTLSv1_1, sslvTLSv1_2];  //  try    lHTTP.Request.Username := Trim(User.Text);    lHTTP.Request.Password := Trim(Password.Text);    lHTTP.IOHandler := lIOHandler;    lHTTP.HandleRedirects := True;    s := lHTTP.Get(Format('https://%s:%d' + '/login', [Host, Port]));    ShowMessage(s);  finally    lHTTP.Free;    lIOHandler.Free;  end;