Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

Enumerate Server-Advertised Acceptable Client CAs

See more Socket/SSL/TLS Examples

Demonstrates Socket.GetSslAcceptableClientCaDn, which returns a certificate-authority distinguished name advertised by a TLS server when it requests a client certificate.

Background. Valid indexes range from 0 through NumSslAcceptableClientCAs minus one. A client can use these names to select an appropriate client certificate.

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.Socket;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  socket: TSocket;
  bTls: Boolean;
  maxWaitMs: Integer;
  numCAs: Integer;
  i: Integer;
  caDn: string;

begin
  success := False;

  socket := TSocket.Create;

  //  Connect to the server using TLS.
  bTls := True;
  maxWaitMs := 5000;
  success := socket.Connect('example.com',5000,bTls,maxWaitMs);
  if (success = False) then
    begin
      WriteLn(socket.LastErrorText);
      Exit;
    end;

  //  After connecting to a server that requests a client certificate, enumerate the certificate-
  //  authority distinguished names the server advertised as acceptable.
  numCAs := socket.NumSslAcceptableClientCAs;

  for i := 0 to numCAs - 1 do
    begin
      caDn := socket.GetSslAcceptableClientCaDn(i);
      if (socket.LastMethodSuccess = False) then
        begin
          WriteLn(socket.LastErrorText);
          Exit;
        end;
      WriteLn(caDn);
    end;



  socket.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.