TsgcWebSocketClient | SChannel Verbindingsinformatie ophalen

Zodra de client verbinding heeft gemaakt met de beveiligde server, kunt u informatie opvragen over welke TLS-versie wordt gebruikt (TLS 1.2, TLS 1.3, enz.), de gebruikte cipher, sterkte en meer.

 

Roep de functie GetInfo of the SChannel Handler to access this info. U kunt access the SSL Handler using de methode OnSSLAfterCreateHandler, which is called after the SChannel Handler is created. After de client connects to de server, if the SSL Handler is assigned, call the functie GetInfo and if succesvol, will return the verbinding data.

 


uses
  sgcIdSSL, sgcSSL_SChannel_Indy, sgcSSL_SChannel;

var
  SSL: TsgcIdSSLIOHandlerSocketSChannel;
oClient := TsgcWebSocketClient.Create(nil);
oClient.URL := 'wss://www.esegece.com:2053';
oClient.TLSOptions.Version := tls1_2;
oClient.TLSOptions.IOHandler := iohSChannel;
oClient.OnSSLAfterCreateHandler := OnSSLAfterCreateHandlerEvent;
oClient.OnConnect := OnConnectEvent;
oClient.Active := True;
procedure OnSSLAfterCreateHandlerEvent(Sender: TObject; aType: TwsSSLHandler; 
  aSSLHandler: TIdSSLIOHandlerSocketBase);
begin
  if aSSLHandler.ClassType = TsgcIdSSLIOHandlerSocketSChannel  then
    SSL := TsgcIdSSLIOHandlerSocketSChannel(aSSLHandler);
end;
procedure OnConnectEvent(Connection: TsgcWSConnection);
var
  oInfo: TsgcSChannelConnectionInfo;
begin
  if Assigned(SSL) then
  begin
    oInfo := SSL.GetInfo;
    if (oInfo.Protocol != tls1_2) then
      raise Exception.Create('Client cannot connect using TLS 1.2');
  end;
end;