TsgcWebSocketClient | SChannel 获取连接信息

客户端连接到安全服务器后,您可以请求获取所使用的 TLS 版本(TLS 1.2、TLS 1.3 等)、所用密码套件、强度等相关信息。

 

调用 SChannel 处理程序的 GetInfo 函数以访问此信息。您可以使用 OnSSLAfterCreateHandler 方法访问 SSL 处理程序,该方法在 SChannel 处理程序创建后调用。客户端连接到服务器后,如果已分配 SSL 处理程序,请调用 GetInfo 函数,成功后将返回连接数据。

 


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;