Esempio n. 1
0
        public static SecureFileBroker Create(IFilePathProvider filePathProvider, string mSecretsSecretKey, string ivName, string dataFileName, string dataVersionFileName, string saltName)
        {
            var remoteSecureFileBroker    = new Ec2SecureFileBroker(mSecretsSecretKey, ivName, dataFileName, saltName);
            var localSecureFileRepository = new LocalSecureFileRepository(filePathProvider, ivName, dataFileName, dataVersionFileName, saltName);

            return(new SecureFileBroker(remoteSecureFileBroker, localSecureFileRepository, false));
        }
Esempio n. 2
0
        private Button CreateSaveButton(Control parent)
        {
            var b = new Button {
                Text = "Save"
            };

            b.Click += (sender, args) =>
            {
                if (FilterCollection.Count > 1)
                {
                    var result = PasswordInputBox.GetPassword(parent, "Master Password");
                    if (!string.IsNullOrEmpty(result))
                    {
                        using (var password = new SecureStringOrArray(Encoding.ASCII.GetBytes(result)))
                        {
                            var folderBasedFilePathProvider = new FolderBasedFilePathProvider(".");
                            var localSecureFileRepository   = new LocalSecureFileRepository(folderBasedFilePathProvider, "muipw.iv", DataFileName, "muipw.ver", "muipw.salt");
                            var aesFormatter = new AesFormatter(localSecureFileRepository);

                            try
                            {
                                //just test that the password is correct by deserializing the current data.
                                var credentialSet = aesFormatter.DeserializeData <CredentialSet>(password);
                                _secretKeyProvider.Initialize(credentialSet.Credentials);
                                _secretKeyProvider.Initialize(FilterCollection);
                                var mSecretsSecretKey = _secretKeyProvider.GetSecret(SecretKeyConstants.MSecretsSecretKeyName);
                                if (mSecretsSecretKey == null)
                                {
                                    MessageBox.Show($"Missing {SecretKeyConstants.MSecretsSecretKeyName}!");
                                    return;
                                }
                                var fileBroker2 = SecureFileBroker.Create(folderBasedFilePathProvider, mSecretsSecretKey, "muipw.iv", DataFileName, "muipw.ver", "muipw.salt");
                                aesFormatter = new AesFormatter(fileBroker2);

                                var set = new CredentialSet();
                                foreach (var credential in FilterCollection)
                                {
                                    set.Credentials.Add(credential);
                                }
                                aesFormatter.SerializeData(password, set);
                            }
                            catch (Exception)
                            {
                                MessageBox.Show("Incorrect password!");
                            }
                        }
                    }
                }
            };
            return(b);
        }
Esempio n. 3
0
        private Button CreateLoadButton(Control parent)
        {
            var b = new Button {
                Text = "Load"
            };

            b.Click += (sender, args) =>
            {
                var folderBasedFilePathProvider = new FolderBasedFilePathProvider(".");
                var localSecureFileRepository   = new LocalSecureFileRepository(folderBasedFilePathProvider,
                                                                                "muipw.iv", DataFileName, "muipw.ver", "muipw.salt");
                var aesFormatter = new AesFormatter(localSecureFileRepository);
                var password     = PasswordInputBox.GetPassword(parent, "Master Password");
                try
                {
                    var credentialSet =
                        aesFormatter.DeserializeData <CredentialSet>(
                            new SecureStringOrArray(Encoding.ASCII.GetBytes(password)));
                    _secretKeyProvider.Initialize(credentialSet.Credentials);
                    var mSecretsSecretKey = _secretKeyProvider.GetSecret(SecretKeyConstants.MSecretsSecretKeyName);
                    if (mSecretsSecretKey == null)
                    {
                        MessageBox.Show(parent, $"Missing {SecretKeyConstants.MSecretsSecretKeyName}!  Can't sync with S3.");
                        FilterCollection.Clear();
                        FilterCollection.AddRange(credentialSet.Credentials);
                        return;
                    }
                    var fileBroker2 = SecureFileBroker.Create(new FolderBasedFilePathProvider("."), mSecretsSecretKey,
                                                              "muipw.iv", DataFileName, "muipw.ver", "muipw.salt");
                    aesFormatter  = new AesFormatter(fileBroker2);
                    credentialSet =
                        aesFormatter.DeserializeData <CredentialSet>(
                            new SecureStringOrArray(Encoding.ASCII.GetBytes(password)));

                    FilterCollection.Clear();
                    FilterCollection.AddRange(credentialSet.Credentials);
                }
                catch (Exception e)
                {
                    var dataFilePath  = Path.GetFullPath($"./{DataFileName}");
                    var dataFileStart = string.Join(",", localSecureFileRepository.GetDataFile().Take(3).Select(a => ((int)a).ToString()).ToArray());
                    var salt          = string.Join(",", localSecureFileRepository.GetSalt().Take(3).Select(a => ((int)a).ToString()).ToArray());
                    var iv            = string.Join(",", localSecureFileRepository.GetIv().Take(3).Select(a => ((int)a).ToString()).ToArray());
                    var pw            = string.Join(",", Encoding.ASCII.GetBytes(password).Take(3).Select(a => ((int)a).ToString()).ToArray());

                    MessageBox.Show(parent, $"Incorrect Password For {dataFilePath}, {dataFileStart} {salt} {iv} {pw}.");
                }
            };
            return(b);
        }