Search code examples
delphiindyindy10

SSL error 1409442E downloading file over HTTPS with TIdHTTP


I'm using Delphi 10.3.3. The code below used to work but now I'm getting an error when trying to download a file over HTTPS:

Error connecting with SSL error:1409442E:SSL routines:SSL3_READ_BYTES:tlsv1 alert protocol version'

var
  ms : tmemorystream;
  ssl : TIdSSLIOHandlerSocketOpenSSL;
  source,dest : string;
begin
  source := 'https://www.myaddress.com/myfile.zip';
  dest := 'c:\myfile.zip';
  ms := TMemoryStream.Create;
  try
    if pos('https',source) > 0 then
    begin
      ssl := TIdSSLIOHandlerSocketOpenSSL.Create();
      idh.IOHandler := ssl;
    end;
    idhttp1.get(source,ms);
    ms.savetofile(dest);
    result := 'ok';
  finally
    ms.Free;
  end;
end;

Solution

  • TIdSSLIOHandlerSocketOpenSSL uses only TLS v1.0 by default and the server is rejecting that. You must explicitly allow newer TLS versions:

    ssl := TIdSSLIOHandlerSocketOpenSSL.Create();
    ssl.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2];
    idh.IOHandler := ssl;