TsgcWebSocketServer | Verifica certificato server

Per impostazione predefinita, il server non verifica i certificati peer. Per configurare il server in modo che verifichi i certificati client, eseguire i seguenti passaggi:

 

  1. Impostare la proprietà SSLOptions.VerifyCertificate = true

 

Gestire l'evento OnSSLVerifyPeer e implementare il codice seguente per ricevere una notifica ogni volta che un client si connette con un certificato.

 


function OnSSLVerifyPeerEvent(Sender: TObject; Certificate:
    TIdX509; AOk: Boolean; ADepth, AError: Integer; var Accept: Boolean);
begin
  // ... validate the certificate
  if Certificate_OK then
    Accept := True
  else 
    Accept := False;
end;

Si noti che l'evento OnSSLVerifyPeer viene chiamato solo se il client fornisce un certificato, se un client non fornisce un certificato l'evento non viene attivato.

 

È possibile configurare il server in modo da consentire solo connessioni SSL che utilizzano un certificato. Per farlo, impostare la seguente proprietà:

 

 

Se il client non fornisce un certificato, la connessione verrà chiusa durante l'handshake SSL.