Beispiel #1
0
 public string AcceptClient(string[] commandParts)
 {
     if (commandParts.Length < 2)
     {
         // TODO: PrintInteractiveHelp(commandParts[0]);
         throw new ArgumentException("invalid command parts");
     }
     else
     {
         lock (_whitelist)
         {
             var thumbprint = commandParts[1];
             _whitelist.TryGetAlias(thumbprint, out string alias);
             alias = commandParts.Length > 2
                 ? commandParts[2]
                 : alias
                     ?? thumbprint;
             _whitelist.Set(thumbprint, alias);
             _cqHub.UpdatePeerInfo(peer =>
             {
                 if (peer.Thumbprint.Equals(thumbprint, StringComparison.OrdinalIgnoreCase))
                 {
                     peer.Alias = alias;
                     return(true);
                 }
                 else
                 {
                     return(false);
                 }
             });
             _whitelist.StoreWhitelist();
             return($"ACCEPT: '{thumbprint}' => '{alias}'".Log());
         }
     }
 }
Beispiel #2
0
        private void ValidateWhitelistAndSetAlias(CQConnection connection)
        {
            $"Checking whitelist for {connection}".Log();
            // check thumbprint against whitelist, if not in whitelist then
            // force a disconnect
            if (_whitelist.TryGetAlias(connection.Peer.Thumbprint, out string alias))
            {
                connection.Peer.Alias = alias;
                _onStatusChange($"{connection} whitelisted as '{connection.Peer.Alias}' ({connection.Peer.Thumbprint})".Log());
            }
            else
            {
                connection.Peer.Alias = connection.Peer.Thumbprint;
                var err = $@"Rejecting {connection.Peer.Thumbprint} -- not authorized.
Use `/WHITELIST <thumbprint>` and `/BAN <thumbprint>` to authorized/deauthorize.".Log();
                _onStatusChange(err);
                throw new Exception(err);
            }
        }