Home > database >  THTTPClient Get to a TLS 1.3 only site results in an error
THTTPClient Get to a TLS 1.3 only site results in an error

Time:03-17

This code:

uses
  System.Net.HttpClient;

procedure TForm2.Button1Click(Sender: TObject);
var
  LHTTP: THTTPClient;
  LResponse: IHTTPResponse;
begin
  LHTTP := THTTPClient.Create;
  try
    LHTTP.SecureProtocols := [THTTPSecureProtocol.TLS13];
    LResponse := LHTTP.Get('https://tls13.1d.pw'); // TLS 1.3 ONLY site
    if LResponse.StatusCode = 200 then
      ShowMessage('TLS 1.3 worked');
  finally
    LHTTP.Free;
  end;
end;

Results in:

---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class ENetHTTPClientException with message 'Error sending data: (12175) A security error occurred'.
---------------------------
Break   Continue   Help   Copy   
---------------------------

Using Windows 10 (The same code works on Windows 11). I've gone into the Internet Options settings in Windows and enabled TLS 1.3, however that does not resolve the issue.

Anything else I need to do?

CodePudding user response:

Per the WinHTTP Error Messages documentation:

ERROR_WINHTTP_SECURE_FAILURE

12175

One or more errors were found in the Secure Sockets Layer (SSL) certificate sent by the server. To determine what type of error was encountered, check for a WINHTTP_CALLBACK_STATUS_SECURE_FAILURE notification in a status callback function. For more information, see WINHTTP_STATUS_CALLBACK.

Unfortunately, THTTPClient does not provide access for you to use such a callback, but it does use an internal callback to capture the reason for ERROR_WINHTTP_SECURE_FAILURE in its SecureFailureReasons property. So you can check that for more info.

Are you sure you enabled TLS 1.3 on Windows 10? Are you using build 1903 or later? Earlier builds do not support TLS 1.3.

how to enable TLS 1.3 in windows 10

  • Related