Delphi connection to FTP SSL\TLS error 550 - delphi

I have this FTP config in Delphi and it worked until few days ago:
clFtp1.Port := 21;
clFtp1.Server := 'server name';
clFtp1.UserName := 'username';
clFtp1.Password := 'password';
clFtp1.PassiveMode := true;
clFtp1.BatchSize := 32 * 8 * 1024;
clFtp1.Open();
Now I get error 550.
I found the solution for it in c# in similar app:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
Maybe it is not the same issue, but documentation for Delphi is really bad and I don't have any idea what to do...

Related

Receiving e-mail using Indy on Windows Server 2008-2012

This code works for me just fine on Windows 7 - Windows 10
IdPOP31.IOHandler := IdSSLIOHandlerSocketOpenSSL1;
IdPop31.Autologin:=True;
IdPop31.AuthType := patUserPass;
IdPOP31.UseTLS := utUseImplicitTLS;
IdPOP31.Host := 'mail.*****com';
IdPOP31.Port := 995;
IdPOP31.Username := '*******';
IdPOP31.Password := 'password';
Try
IdPOP31.Connect;
ShowMessage('Connected!')
Except
Exit;
End;
But when I try to run it on Server 2008 or 2012 it does nothing.
When Port 110 was available all worked fine, now, as I said it works only on Windows but not on Servers.
Please, give me any idea how to solve this problem.
Thank you.

Delphi XE8 Indy OpenSSL , after update for windows 11 i got error 14077410 SSL23_GET_SERVER_HELLO

I have a project that still works on Windows 10, and it was working on Windows 11. But, after I installed updates for Windows 11 (not 22H2):
I now get an error:
error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert
handshake failure.
My setup is Indy 10.6.2.5263, OpenSSL 1.0.2u, Delphi XE8, and I am using the following code:
CInitialized := false;
idHttpC := TIdHTTP.Create(nil);
idHttpC.ConnectTimeout := 80000;
idHttpC.ReadTimeout := 80000;
idHttpC.AllowCookies := true;
// config Redirect's
idHttpC.RedirectMaximum := 35;
idHttpC.HandleRedirects := true;
idHttpC.HTTPOptions := [hoTreat302Like303, hoKeepOrigProtocol];
idHttpC.OnRedirect := IdHTTP1Redirect;
// create Cookie's
idCookieC := TIdCookieManager.Create(IdHttpC);
idHttpC.CookieManager := idCookieC;
// create gzip Compressor
idHttpC.Compressor := TIdCompressorZLib.Create(idHttpC);
// create OpenSSL
lIOHandlerC := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
lIOHandlerC.SSLOptions.Mode := sslmClient;
lIOHandlerC.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2];
idHttpC.IOHandler := lIOHandlerC;
On my request:
Result := idHttpC.Get('https://leinestern.de/');
I get:
error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure.
What's is wrong here? Maybe I have to change some new settings?
I am not using any antivirus or firewall, the built-in antivirus and firewall are disabled.
i updated Indy from GitHub and it's working again.

Indy 10.5.8.0 + XE2 + Windows 10 "Access violation at address 00000000. Read of address 00000000"

The code below works perfectly on Windows 7 machines 32 and 64 bits, it posts data to a https server on 5443 port and receive its response. However, machines with windows 10 it throws an Access violation at address 00000000. Read of address 00000000 message.
Some situations we might consider:
- Delphi XE2
- Indy 10.5.8.0
- [OpenSSL v1.1.1g][1]
- Windows 10 Version 1909
- No firewall and antivirus for tests
Here's the code:
_idHTTP := TIdHTTP.Create(Self);
_idHTTP.AllowCookies := True;
_idHTTP.HandleRedirects := True;
_idHTTP.HTTPOptions := [hoForceEncodeParams];
_idHTTP.ProxyParams.BasicAuthentication := False;
_idHTTP.Request.Accept := 'text/html, */*';
_idHTTP.Request.BasicAuthentication := False;
_idHTTP.Request.ContentLength := -1;
_idHTTP.Request.ContentRangeEnd := -1;
_idHTTP.Request.ContentRangeInstanceLength := -1;
_idHTTP.Request.ContentRangeStart := -1;
_idHTTP.Request.UserAgent := 'Mozilla/3.0 (compatible; Indy Library)';
_idHTTP.IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(_idHTTP);
_idHTTP.Request.CustomHeaders.Clear;
_idHTTP.Request.CustomHeaders.AddValue('Content-Type', 'application/json');
_idHTTP.Request.CustomHeaders.AddValue('Accept', 'application/json');
try
json := '{user: "<myuser>", pass: "<mypass>"}';
RequestBody := TStringStream.Create(json, TEncoding.UTF8);
try
sRet := _idHTTP.Post('https://10.200.200.213:5443/auth', RequestBody);
except
raise ex;
end;
finally
_idHTTP.Free;
end;
Edit:
The error message is throwing by the line
sRet := _idHTTP.Post('https://10.200.200.213:5443/auth', RequestBody);
As #zed commented, the problem is my OpenSSL version, it cannot be 1.1.1.
I installed 1.0.2 version from here and it's working now!

Gmail failing with 'Connection Closed Gracefully' using Indy in Delphi XE on Windows 8

Roughly 2-3 out of hundreds of Windows 8 clients began getting this message 2-3 weeks ago.
per Wireshark the last transmission before the connection is closed is
'2.0.0 Ready to start TLS'
Code snippet:
Smtp := TIdSMTP.Create(nil);
try
IdSSLIOHandlerSocketOpenSSL1 := TIdSSLIOHandlerSocketOpenSSL.Create(smtp);
try
Smtp.OnStatus := IdSMTP1Status;
Smtp.OnWorkBegin := IdSMTP1WorkBegin;
Smtp.OnWorkEnd := IdSMTP1WorkEnd;
Smtp.OnWork := IdSMTPWork;
Smtp.Host := 'smtp.gmail.com'
Smtp.Port := 487, 565 both tried here;
Smtp.Username := 'the email#gmail.com'
Smtp.Password := 'The password'
// TLS for Gmail, etc
if UseSSL then // true
begin
Smtp.IOHandler := IdSSLIOHandlerSocketOpenSSL1;
if Smtp.Port = 465 then
Smtp.UseTLS := utUseImplicitTLS
else
if Smtp.Port = 587 then
Smtp.UseTLS := utUseExplicitTLS
else
Smtp.UseTLS := utUseExplicitTLS;
IdSSLIOHandlerSocketOpenSSL1.Host := 'gmail smtp again'
IdSSLIOHandlerSocketOpenSSL1.Destination :=
Smtp.Host + ':' + IntToStr(Smtp.Port);
IdSSLIOHandlerSocketOpenSSL1.Port := Smtp.Port;
end;
try
Smtp.Connect;
sTempFileName := data1.GetSettingsFileFolder+'\tmp.email';
EmailMessage.SaveToFile(sTempFileName);
AssignFile(F,sTempFileName);
Reset(F);
iFileSize := FileSize(F) * 128;
CloseFile(F);
SysUtils.DeleteFile(sTempFileName);
StatusForm.SetProgress(0,iFileSize);
Smtp.Send(EmailMessage);
except on E:Exception do
begin
MessageDlg(E.Message, mtError, [mbOK], 0);
Exit;
end;
end;
finally
IdSSLIOHandlerSocketOpenSSL1.Free;
end;
finally
EmailMessage.MessageParts.Clear;
if Smtp.Connected then smtp.Disconnect;
Smtp.Free;
end;
2.0.0 Ready to start TLS is sent in reply to a STARTTLS command. If you are getting disconnected immediately afterwards, then the TLS handshake is likely failing, and you should be getting an exception explaining why it failed. Double-check your TLS settings. Also keep in mind that setting the UseTLS property may change the Port property, so it is best to set UseTLS before setting Port rather than the other way around.
Also, You do not need to set the IOHandler's Host, Port, or Destination properties. Connect() will handle that for you.

Random Indy ResponseCode = -1 / EIdSocketError Socket Error # 0 exceptions

I have a delphi code that basically upload files to remote secure server using Indy 10.4.704:
IdHTTP := TIdHTTP.Create(nil);
try
TheCompressor := TIdCompressorZLib.Create(nil);
TheSSL := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
with IdHTTP do
begin
HTTPOptions := [hoForceEncodeParams];
AllowCookies := True;
HandleRedirects := True;
ProtocolVersion := pv1_1;
IOHandler := TheSSL;
Compressor := TheCompressor;
end; // with
// Get upload resume offset
try
IdHttp.Head('https://www.domain.com/my-file.bin');
if (IdHttp.Response.ResponseCode <> 404) And (IdHttp.Response.ContentLength >= 0) then
StartPos := IdHttp.Response.ContentLength
else
StartPos := 0;
except
StartPos := 0;
end; // try/except
// Upload File
TheFile := TFileStream.Create(FileName, fmOpenRead OR fmShareDenyWrite);
RangeStream := TIdHTTPRangeStream.Create(TheFile, StartPos, -1, True);
try
if (RangeStream.ResponseCode = 206) then
IdHTTP.Post(https://www.domain.com/upload.php', RangeStream);
finally
RangeStream.Free;
end; // try/finally
finally
FreeAndNil(IdHTTP);
end; // try/finally
The problem is that sometimes the code fails with Indy throwing a EIdSocketError Socket Error # 0 exception (idHTTP.ResponseCode is -1)
Given my crappy internet connection, I launched an EC2 windows instance and tested my code on it (the windows instance is running on the cloud, so I assume connection is not a problem), yet I got the same issue!
The error seems to be random, sometimes upload works, sometimes not. I debugged with TidLogFile, all I could find is something like this:
Stat Connected.
Sent 4/26/2012 4:18:42: POST /app/upload.php...
Sent 4/26/2012 4:18:42: <uploaded_file_data_here>
Stat Disconnected.
Anyone knows what's causing this/how to fix this?
EDIT
I traced the exception back to TIdSSLIOHandlerSocketOpenSSL. I googled a lot, it seems that it's not an SSL error.
Please upgrade to the latest Indy 10 version, which is 10.5.8 r4743. SSL-related issues with Error Code 0 were fixed over a year ago.

Resources