STUN Server | Long-Term Credentials

Normalmente os Servidores STUN são configurados sem Autenticação, de modo que qualquer cliente STUN pode enviar uma requisição de binding e esperar uma resposta do servidor sem Autenticação.

 

O servidor STUN sgcWebSockets suporta Long-Term Credentials, então você pode configurar o TsgcSTUNServer para permitir somente requisições de binding com informações de credenciais Long-Term.

 

Para configurá-lo, acesse a propriedade STUNOptions.Authorization e habilite-a.

Em seguida, acesse a propriedade LongTermCredentials e habilite-a. Por padrão, este tipo de autorização já vem configurado com uma string Realm e com um valor StaleNonce padrão de 10 minutos (= 600 segundos).

 


oSTUN := TsgcSTUNServer.Create(nil);
oSTUN.Port := 3478;
oSTUN.STUNOptions.Authentication.Enabled := True;
oSTUN.STUNOptions.Authentication.LongTermCredentials.Enabled := True;
oSTUN.STUNOptions.Authentication.LongTermCredentials.Realm := 'sgcWebSockets';
oSTUN.STUNOptions.Authentication.LongTermCredentials.StaleNonce := 600;
oSTUN.Active := True;

procedure OnSTUNRequestAuthorization(Sender: TObject; const aRequest: TsgcSTUN_Message; 
  const aUsername, aRealm: string; var Password: string);
begin
  if aUsername = 'my-user' then
    Password := 'my-password';
end;