コード例 #1
0
        public AuthWindow(ImClientHandler clientHandler)
        {
            InitializeComponent();

            this._clientHandler = clientHandler;
            this._clientModel   = new Client();
            DataContext         = _clientModel;

            _clientHandler.LoginAuthorised += LoginAuthorised;
            _serverErrorEventHandler        = ServerError;
            _clientHandler.ServerError     += _serverErrorEventHandler;

            txtPassword.ToolTip = "Password must be atleast 10-20 characters long, contain a\n uppercase character, a number and a special character.";
            txtUsername.ToolTip = "Username must be atleast 4-12 characters long,\n and only contain characters.";
        }
コード例 #2
0
        public void Is_Server_Available_Test()
        {
            Server s = new Server();

            ThreadPool.QueueUserWorkItem(s.ImServer.StartServer);
            Thread.Sleep(20);

            if (s.ImServer.ServerActive)
            {
                ImClientHandler clientAuth = new ImClientHandler(
                    s.ImServer.IpAddress.ToString(),
                    s.ImServer.PortAddress);
                Assert.IsTrue(clientAuth.IsServerAvailable());
            }
            s.ImServer.StopServer();
        }
コード例 #3
0
        private void Connect(object sender, RoutedEventArgs e)
        {
            button.IsEnabled = false;


            switch (_hostModel.CheckDetails())
            {
            case Host.DETAILS_MATCHED:
                try
                {
                    _clientHandler = new ImClientHandler(txtIP.Text, Int32.Parse(txtPort.Text));
                    if (_clientHandler.IsServerAvailable())
                    {
                        _authWindow = new AuthWindow(_clientHandler)
                        {
                            Left = this.Left,
                            Top  = this.Top
                        };
                        _authWindow.Show();
                        this.Hide();
                    }
                }
                catch (Exception ex)
                {
                    LabelErrorMessageAnimator(ex.Message, lblErrorMessage);
                }
                break;

            case Host.DETAILS_UNMATCHED:
                LabelErrorMessageAnimator("Both details fail to meet the requirements", lblErrorMessage);
                break;

            case Host.IP_UNMATCHED:
                LabelErrorMessageAnimator("IP Address doesn't meet necessary requirements", lblErrorMessage);
                break;

            case Host.PORT_UNMATCHED:
                LabelErrorMessageAnimator("Port doesn't meet necessary requirements", lblErrorMessage);
                break;

            default:
                LabelErrorMessageAnimator("Unspecified error occurred...", lblErrorMessage);
                break;
            }
            button.IsEnabled = true;
        }
コード例 #4
0
        public void Multiple_Login_Attempts()
        {
            Server s = new Server();

            ThreadPool.QueueUserWorkItem(s.ImServer.StartServer, null);
            Thread.Sleep(20);

            int reg = 0;

            while (s.ImServer.ServerActive && reg != 6)
            {
                var clientAuth1 = new ImClientHandler(
                    s.ImServer.IpAddress.ToString(),
                    s.ImServer.PortAddress);
                clientAuth1.Login(_clients[reg]);
                Thread.Sleep(200);
                reg++;
            }
            Assert.IsTrue(
                s.ImServer.CurrentClients._imUsers.ToList()
                .Select(cli => cli.Value.LoggedIn).Count() == 6);
            s.ImServer.StopServer();
        }
コード例 #5
0
        public void Asymmetrical_Key_Regeneration_Attempt()
        {
            Server s = new Server();

            ThreadPool.QueueUserWorkItem(s.ImServer.StartServer, null);
            Thread.Sleep(20);

            ImClientHandler client =
                new ImClientHandler(s.ImServer.IpAddress.ToString(), s.ImServer.PortAddress);

            client.Login(_clients[0]);
            Thread.Sleep(200);

            RSAParameters oldKey = client.PublicKey;

            IMClient.utils.Cryptography.DeleteKeyFromContainer();
            IMClient.utils.Cryptography.GenerateKeys(out client.PublicKey);

            Thread.Sleep(1000);

            Assert.IsFalse(oldKey.Equals(client.PublicKey));
            s.ImServer.StopServer();
        }
コード例 #6
0
        public void Multiple_Register_Attempts()
        {
            Server s = new Server();

            ThreadPool.QueueUserWorkItem(s.ImServer.StartServer, null);

            s.ImServer.CurrentClients._imUsers.Clear();
            s.ImServer.CurrentClients.SaveDictionaryToFile();
            Thread.Sleep(20);

            int reg = 0;

            while (s.ImServer.ServerActive && reg != 6)
            {
                var clientAuth1 = new ImClientHandler(
                    s.ImServer.IpAddress.ToString(),
                    s.ImServer.PortAddress);
                clientAuth1.Register(_clients[reg]);
                Thread.Sleep(400);
                reg++;
            }
            Assert.IsTrue(s.ImServer.CurrentClients._imUsers.Count == 6);
            s.ImServer.StopServer();
        }
コード例 #7
0
        public ImMainWindowNew(ImClientHandler clientHandler)
        {
            InitializeComponent();
            _clientHandler = clientHandler;

            GeneratedClientList = new ObservableCollection <User>();
            foreach (IMLibrary.Client client in _clientHandler.GeneratedClientList)
            {
                GeneratedClientList.Add(new User(client.UserName, client.Available, client.FingerPrint, client.PublicKey, client.Buddies, 0));
            }

            //GeneratedClientList.CollectionChanged += GeneratedClientList_CollectionChanged;

            _clientHandler.ListEventHandler           += _clientHandler_ListEventHandler;
            _clientHandler.KeyNegotiationEventHandler += _clientHandler_KeyNegotiationEventHandler;
            _clientHandler.NegotiationEventHandler    += _clientHandler_InitiateNegotiation;
            _clientHandler.BuddyEventHandler          += _clientHandler_BuddyEventHandler;
            _filteredView = new CollectionViewSource {
                Source = GeneratedClientList
            }.View;

            DataContext = new
            {
                user    = _clientHandler.ClientInfo,
                clients = _filteredView,
                //messages = _clientMessagesReceivedTupleList
            };
            _filteredView.Refresh();
            IMChatPromtEventHandler chatPromtEventHandler = MessageReceiveHandler;

            clientHandler.ChatPromtCheck += chatPromtEventHandler;

            foreach (User client in GeneratedClientList)
            {
                ChatDialogueLocal chatDialogoue = new ChatDialogueLocal {
                    lblUsername = { Content = client.UserName }, lblFingerPrint = { Content = client.FingerPrint }
                };
                chatDialogoue.ButtonRegenerateKeys.Click += ButtonRegenerateKeys_Click;
                _clientPromtList.Add(new Tuple <IMLibrary.Client, ChatDialogueLocal>(client, chatDialogoue));
                //_clientMessagesReceivedTupleList.Add(new Pair<IMLibrary.Client, string>(client, "0"));
                if (client.FingerPrint != null)
                {
                    chatDialogoue.ChangeColourOfPrint();
                    chatDialogoue.LoadPrint();

                    //new instant of aes, key and IV are created and access through properties. f
                    try
                    {
                        Tuple <byte[], byte[]> unencryptedKeySaltPair = GenerateUnencryptedKeySaltPair();
                        Tuple <byte[], byte[]> encryptedKeySaltPair   = EncryptKeySaltPair(client.PublicKey, unencryptedKeySaltPair);

                        if (client.UserName != _clientHandler.ClientInfo.UserName)
                        {
                            _clientHandler.NegotiateSymmetricKeys(encryptedKeySaltPair, client.UserName);
                        }

                        this._clientKeyIvDictionary.Add(client.UserName, unencryptedKeySaltPair);
                    }
                    catch (Exception e)
                    {
                        //will fail if we don't know the clients public key
                    }
                }
            }
        }