Example #1
0
        public MainWindow()
        {
            componentContext = (App.Current as App).Services;

            var encryptedOptions = componentContext.Resolve <EncryptedOptions>();

            DecryptedOptions decryptedOptions = LoadOptions(encryptedOptions);

            if (decryptedOptions == null)
            {
                Application.Current.Shutdown();
                return;
            }
            s3      = new AWSS3API(decryptedOptions.AWSS3Options);
            athena  = new AWSAthenaAPI(decryptedOptions.AWSAthenaOptions);
            options = decryptedOptions.AthenaClientOptions;
            InitializeComponent();
            s3Tree.ItemsSource     = S3ItemsSource;
            tabQueries.ItemsSource = FormatedQuerySource;
            dgJobList.ItemsSource  = QueryTasks;
            LoadS3();
        }
Example #2
0
        private DecryptedOptions LoadOptions(EncryptedOptions encryptedOptions)
        {
            DecryptedOptions decryptedOptions = null;
            bool             needLogin        = true;

            while (needLogin)
            {
                LoginWindow loginWindow = new LoginWindow();
                var         result      = loginWindow.ShowDialog();

                if (!result.HasValue || !result.Value)
                {
                    Application.Current.Shutdown();
                    return(null);
                }

                var username = loginWindow.Username;
                var password = loginWindow.Password;

                var base64IV  = "NhbsNbMmiZo3Ql4wMorPMg==";
                var base64Key = "zFJnXBUqQVW+0UTexm79qT4muUVHaypmQjoFN1mGJog=";
                var IV        = Convert.FromBase64String(base64IV);
                var Key       = Convert.FromBase64String(base64Key);

                var aes = Aes.Create();
                aes.KeySize = 256;
                var secret      = $"{username}+{password}";
                var secretBytes = Encoding.UTF8.GetBytes(secret);
                Array.Copy(secretBytes, Key, secretBytes.Length);
                aes.IV  = IV;
                aes.Key = Key;

                var encrypted = Convert.FromBase64String(encryptedOptions.Value);

                byte[] data = null;

                try
                {
                    data      = aes.CreateDecryptor().TransformFinalBlock(encrypted, 0, encrypted.Length);
                    needLogin = false;
                }
                catch (CryptographicException ex)
                {
                    var msgResult = MessageBox.Show("Wrong Username or Password! Do you want to try again?",
                                                    "Login Error",
                                                    MessageBoxButton.YesNo);

                    if (msgResult == MessageBoxResult.No)
                    {
                        return(null);
                    }
                    else if (msgResult == MessageBoxResult.Yes)
                    {
                        continue;
                    }
                }

                var json = Encoding.UTF8.GetString(data);

                decryptedOptions = JsonConvert.DeserializeObject <DecryptedOptions>(json);
            }



            return(decryptedOptions);
        }