Exemplo n.º 1
0
        internal void ApplyNewKey(Mazing mazeHandshake, byte[] key, byte[] salt)
        {
            mazeHandshake.ApplyKey(this.HeaderEncryption, key);
            mazeHandshake.ApplyKey(this.HeaderEncryption, salt);

            mazeHandshake.ApplyKey(this.PayloadEncryption, key);
            mazeHandshake.ApplyKey(this.PayloadEncryption, salt);

            mazeHandshake.ApplyKey(this.EncAES, key);
            mazeHandshake.ApplyKey(this.EncAES, salt);
        }
Exemplo n.º 2
0
        public override void ProcessPayload(SSPClient client, OperationalSocket OpSocket)
        {
            SSPClient _client = client as SSPClient;

            if (_client != null)
            {
                byte[]        responseData  = new byte[0];
                MazeErrorCode errorCode     = MazeErrorCode.Error;
                Mazing        mazeHandshake = _client.IsServerSided ? _client.serverHS : _client.clientHS;

                if (mazeHandshake == null)
                {
                    //error could occur on a unexpected disconnect
                    client.Connection.HandShakeCompleted = false;
                    client.Connection.HandshakeSync.Pulse();
                    return;
                }

                errorCode = mazeHandshake.onReceiveData(Data, ref responseData);


                if (errorCode != MazeErrorCode.Finished && errorCode != MazeErrorCode.Success && client.TimingConfiguration.Enable_Timing)
                {
                    //something went wrong, annoy the attacker
                    Thread.Sleep(client.TimingConfiguration.Authentication_WrongPassword);
                }

                if (responseData.Length > 0)
                {
                    client.Connection.SendMessage(new MsgHandshake(responseData), new SystemHeader());
                }

                if (client == null || client.Connection == null || client.Connection.HandshakeSync == null)
                {
                    //error could occur on a unexpected disconnect
                    return;
                }

                client.Connection.HandshakeSync.Value = errorCode;
                if (errorCode != MazeErrorCode.Finished && errorCode != MazeErrorCode.Success)
                {
                    client.Connection.HandshakeSync.Pulse();
                }
                else if (errorCode == MazeErrorCode.Finished)
                {
                    //let's tell it's completed and apply the new key
                    client.Connection.ApplyNewKey(mazeHandshake, mazeHandshake.FinalKey, mazeHandshake.FinalSalt);

                    if (_client.IsServerSided)
                    {
                        if (mazeHandshake as ServerMaze != null)
                        {
                            client.Username = (mazeHandshake as ServerMaze).Username;
                        }

                        client.Connection.HandShakeCompleted = true;

                        /*try
                         * {
                         *  client.onBeforeConnect();
                         * }
                         * catch (Exception ex)
                         * {
                         *  SysLogger.Log(ex.Message, SysLogType.Error);
                         *  client.onException(ex, ErrorType.UserLand);
                         *  return; //don't send that we're ready since we're clearly not at this point
                         * }*/

                        client.Connection.SendMessage(new MsgInitOk(), new SystemHeader());

                        try
                        {
                            client.onConnect();
                        }
                        catch (Exception ex)
                        {
                            SysLogger.Log(ex.Message, SysLogType.Error);
                            client.onException(ex, ErrorType.UserLand);
                            return; //don't send that we're ready since we're clearly not at this point
                        }
                    }
                    else
                    {
                        client.Connection.HandShakeCompleted = true;
                        client.Connection.HandshakeSync.Pulse();
                    }
                }
            }
        }