TsgcWebSocketClient | SChannel Get Connection Info

Uma vez que o cliente tenha conectado ao servidor seguro, você pode solicitar informações sobre qual versão do TLS está sendo usada (TLS 1.2, TLS 1.3, etc.), a cifra usada, a força e mais.

 

Chame a função GetInfo do SChannel Handler para acessar essa informação. Você pode acessar o SSL Handler utilizando o método OnSSLAfterCreateHandler, que é chamado depois que o SChannel Handler é criado. Depois que o cliente conecta ao servidor, se o SSL Handler estiver atribuído, chame a função GetInfo e, se bem-sucedida, retornará os dados da conexão.

 


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;