Example #1
0
 private void ShowSensible_Button_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (!_showsSensible)
         {
             var decrypted = CryptMemProtection_ForUtilityProject.DecryptInMemoryData(_encryptedData);
             Sensible_Textblock.Text = ByteHelper.ByteArrayToString(decrypted);
             decrypted      = null;
             _showsSensible = true;
         }
         else
         {
             Sensible_Textblock.Text = "*********************************";
             _showsSensible          = false;
         }
     }
     catch (Exception ex)
     {
         Logger.log.Error($"Couldn't handle sensible data: {ex}");
         ex.SetUserMessage(WellKnownExceptionMessages.DataExceptionMessage());
         Communication.InformUserAboutError(ex);
         _encryptedData = null;
         Close();
     }
 }
        public async Task SendResponse(byte[] data)
        {
            _logger.LogTrace($"Sending: {ByteHelper.ByteArrayToString(data)}");

            _networkStream.Write(data, 0, data.Length);
            await _networkStream.FlushAsync();

            _clientSocket.Close();
        }
        public RequestData GetRequestData()
        {
            var result = new RequestData(_bytesFrom);

            result["machine:IPEndPoint"] = _clientSocket.Client.RemoteEndPoint;

            _logger.LogTrace($"Received: {ByteHelper.ByteArrayToString(_bytesFrom)}");

            return(result);
        }
        public async Task <OperationResult> UpdateRemoteMachinePriceTableAsync(Machine machine, IEnumerable <ProductRail> products)
        {
            //if (!IPAddress.TryParse(machine.IPEndPoint, out var ipAddr))
            if (!IPEndPointHelper.TryParse(machine.IPEndPoint, out var ipAddr))
            {
                return(OperationResult.Failed(OperationErrorFactory.FromWellKnowErrors(WellKnowErrors.InvalidMachineIPEndPoint)));
            }

            var productsArr = products.ToArray();

            using (var client = new TcpClient())
            {
                _logger.LogInformationIfEnabled(() => $"Connection to machine {machine}");
                _logger.LogInformationIfEnabled(() => $"Openning TCP connection in {ipAddr.Address}:{MACHINE_TCP_PORT}");
                await client.ConnectAsync(ipAddr.Address, MACHINE_TCP_PORT);


                var stream = client.GetStream();
                _logger.LogDebug("Got stream!");

                var productsCount = productsArr.Length;
                _logger.LogDebugIfEnabled(() => $"Sending {productsCount} products update.");

                var data = new byte[OFFSET.PRODUCTS + (productsCount * PRODUCT_SIZE)];

                data[OFFSET.INTENTION] = 0x02;
                data[OFFSET.COUNT]     = (byte)productsCount;

                for (int i = 0; i < productsCount; i++)
                {
                    var p = productsArr[i];
                    ToBytes(p).CopyTo(data, OFFSET.PRODUCTS + (i * PRODUCT_SIZE));
                }

                _logger.LogInformationIfEnabled(() => $"Awaiting...");
                await Task.Delay(500);

                _logger.LogTraceIfEnabled(() => $"Sending bulk update data: '{ByteHelper.ByteArrayToString(data)}'.");
                stream.Write(data, 0, data.Length);

                _logger.LogDebug("Ignoring response....");
                // var buffer = new byte[255];
                // var result = await stream.ReadAsync(buffer, 0, 255);
            }

            _logger.LogDebug("Returning OperationResult.Success.");
            return(OperationResult.Success);
        }
        /// <summary>
        /// Takes in an encrypted pw and calculates its strength => return list of tips and blackList status.
        /// </summary>
        /// <param name="pw"></param>
        /// <returns></returns>
        public static double CalculatePasswordStrength(byte[] encryptedPw, out HashSet <string> resultTips, out bool isBlackListed)
        {
            // Load in the pw blacklist
            isBlackListed = false;
            resultTips    = new HashSet <string>();
            var    pw = ByteHelper.ByteArrayToString(CryptMemoryProtection.DecryptInMemoryData(encryptedPw));
            double passwordStrengthValue = 1;

            if (!pw.Any(c => char.IsUpper(c)))
            {
                passwordStrengthValue -= 0.25;
                resultTips.Add("The password doesn't contain upper case characters.");
            }
            if (!pw.Any(c => char.IsDigit(c)))
            {
                passwordStrengthValue -= 0.25;
                resultTips.Add("The password doesn't contain digits.");
            }
            if (pw.Length < 12)
            {
                passwordStrengthValue -= 0.50;
                resultTips.Add("The password is too short. It should be at least 12 characters long.");
            }
            if (!WellKnownSpecialCharacters.ContainsSpecialCharacters(pw))
            {
                passwordStrengthValue -= 0.25;
                resultTips.Add("The password doesn't contain special characters.");
            }
            if (PasswordBlackList.GetBlackList().Contains(pw))
            {
                passwordStrengthValue -= 1;
                isBlackListed          = true;
                resultTips.Add("This password has already been leaked and is widely spread on the internet - combined with it's hash. It is not save.");
            }

            // We do not want a "negative" value password strength
            if (passwordStrengthValue <= 0)
            {
                passwordStrengthValue = 0.1;
            }
            if (isBlackListed)
            {
                passwordStrengthValue = 0;
            }

            pw = string.Empty;
            return(passwordStrengthValue);
        }
        /// <summary>
        /// Visualises a leafList to a printablePasswordEntity-List
        /// </summary>
        /// <param name="allLeafVms"></param>
        public void StartPasswordEntriesPrintProcess(HashSet <LeafViewModel> allLeafVms)
        {
            try
            {
                foreach (var leafVm in allLeafVms)
                {
                    if (DataAccessService.Instance.TryGetSensible <LeafPassword>(leafVm.Id, out var leafPw))
                    {
                        var pw = string.Empty;
                        if (leafPw.Value != null)
                        {
                            pw = ByteHelper.ByteArrayToString(leafPw.Value);
                        }
                        else
                        {
                            pw = ByteHelper.ByteArrayToString(CryptMemoryProtection.DecryptInMemoryData(leafPw.EncryptedValue));
                        }

                        // Get the parent model
                        var tuples = new Tuple <string, object>[] { Tuple.Create("Id", (object)leafVm.BranchId) };
                        var parent = DataAccessService.Instance.GetExplicit <Branch>(tuples).FirstOrDefault();

                        if (parent != default)
                        {
                            var printableVm = new PrintablePasswordEntryViewModel(leafVm.Name, parent.Name, leafVm.Username, pw);
                            PrintablePasswordEntries.Add(printableVm);
                        }

                        pw     = null;
                        leafPw = null;
                    }
                }

                Print();
            }
            catch (Exception ex)
            {
                ex.SetUserMessage($"Couldn't print the requested document.");
                Communication.InformUserAboutError(ex);
                Logger.log.Error($"Error while trying to print emergency sheet: {ex}");
            }
        }
Example #7
0
 public override string ToString()
 {
     return(ByteHelper.ByteArrayToString(Value));
 }
Example #8
0
 public ChangePasswordView(byte[] encryptedBytes)
 {
     InitializeComponent();
     Password_Textbox.Text = ByteHelper.ByteArrayToString(CryptMemoryProtection.DecryptInMemoryData(encryptedBytes));
     _pwAtStart            = Password_Textbox.Text;
 }
        private void Webbrowser_LoadCompleted(object sender, NavigationEventArgs e)
        {
            try
            {
                if (!_isRun && _isLoginAttempt)
                {
                    // Get the website document first
                    mshtml.HTMLDocument document = (mshtml.HTMLDocument)Webbrowser.Document;

                    // Set the username
                    var username = document.getElementById("ap_email");
                    if (username != null)
                    {
                        username.innerText = _username;
                    }
                    // Now for amazon we need to click first
                    var theElementCollection = document.getElementsByTagName("input");
                    if (theElementCollection != null)
                    {
                        foreach (var el in theElementCollection)
                        {
                            if (((HTMLDTElement)el).id == "continue")
                            {
                                ((HTMLDTElement)el).click();
                            }
                        }
                    }

                    // Let the page load
                    System.Threading.Thread.Sleep(2000);

                    // Get the newly loaded document
                    document = (mshtml.HTMLDocument)Webbrowser.Document;

                    // Fill in password
                    var pw = document.getElementById("ap_password");
                    if (pw != null)
                    {
                        pw.innerText = ByteHelper.ByteArrayToString(CryptMemoryProtection.DecryptInMemoryData(_encryptedPassword));
                    }

                    theElementCollection = document.getElementsByTagName("input");
                    if (theElementCollection != null)
                    {
                        // Click login button
                        foreach (var el in theElementCollection)
                        {
                            if (((HTMLDTElement)el).id == "signInSubmit")
                            {
                                ((HTMLDTElement)el).click();
                            }
                        }
                    }

                    Navigation_Textblock.Text = Webbrowser.Source.AbsoluteUri;
                    _isRun = true;
                }
            }
            catch (Exception ex)
            {
                Communication.InformUser("Couldn't log into page.");
                Logger.log.Error($"Couldn't login to page: {ex}");
                Close();
            }
        }