Exemplo n.º 1
0
        public async Task TestSettingKnownFoldersAndLoggingOnAndOff()
        {
            KnownIdentities       knownIdentities = new KnownIdentities(Resolve.FileSystemState, Resolve.SessionNotify);
            KnownFoldersViewModel vm = new KnownFoldersViewModel(Resolve.FileSystemState, Resolve.SessionNotify, knownIdentities);

            Assert.That(vm.KnownFolders.Count(), Is.EqualTo(0));

            IDataContainer betterCloudInfo = New <IDataContainer>(@"C:\BetterCloud");
            IDataContainer fasterCloudInfo = New <IDataContainer>(@"C:\FasterCloud");
            KnownFolder    folder1         = new KnownFolder(betterCloudInfo, @"My AxCrypt", KnownFolderKind.WindowsMyDocuments, null);
            KnownFolder    folder2         = new KnownFolder(fasterCloudInfo, @"My AxCrypt", KnownFolderKind.Dropbox, null);

            FakeDataStore.AddFolder(folder1.My.FullName);
            FakeDataStore.AddFolder(folder2.My.FullName);

            vm.KnownFolders = new KnownFolder[] { folder1, folder2 };
            Assert.That(vm.KnownFolders.Count(), Is.EqualTo(2));
            Assert.That(vm.KnownFolders.First().Enabled, Is.False, "We are not signed in so the folder should not be enabled");
            Assert.That(vm.KnownFolders.Last().Enabled, Is.False, "We are not signed in so the folder should not be enabled");

            await knownIdentities.SetDefaultEncryptionIdentity(new LogOnIdentity("aaa"));

            Assert.That(vm.KnownFolders.Count(), Is.EqualTo(2));
            Assert.That(vm.KnownFolders.First().Enabled, Is.True, "We are signed in so the folder should be enabled");
            Assert.That(vm.KnownFolders.Last().Enabled, Is.True, "We are signed in so the folder should be enabled");

            await knownIdentities.SetDefaultEncryptionIdentity(LogOnIdentity.Empty);

            Assert.That(vm.KnownFolders.Count(), Is.EqualTo(2));
            Assert.That(vm.KnownFolders.First().Enabled, Is.False, "We are no longer signed in so the folder should not be enabled");
            Assert.That(vm.KnownFolders.Last().Enabled, Is.False, "We are no longer signed in so the folder should not be enabled");
        }
Exemplo n.º 2
0
        public void TestConstructor()
        {
            KnownIdentities       knownIdentities = new KnownIdentities(Resolve.FileSystemState, Resolve.SessionNotify);
            KnownFoldersViewModel vm = new KnownFoldersViewModel(Resolve.FileSystemState, Resolve.SessionNotify, knownIdentities);

            Assert.That(vm.KnownFolders.Count(), Is.EqualTo(0));
        }
Exemplo n.º 3
0
        public async Task TestFileWasCreatedWhereAKnownFolderWasExpected()
        {
            IDataContainer betterCloudInfo = New <IDataContainer>(@"C:\BetterCloud");
            IDataContainer fasterCloudInfo = New <IDataContainer>(@"C:\FasterCloud");
            KnownFolder    folder1         = new KnownFolder(betterCloudInfo, @"My AxCrypt", KnownFolderKind.GoogleDrive, null);
            KnownFolder    folder2         = new KnownFolder(fasterCloudInfo, @"My AxCrypt", KnownFolderKind.Dropbox, null);

            FakeDataStore.AddFile(@"C:\BetterCloud\My AxCrypt", Stream.Null);
            FakeDataStore.AddFolder(folder2.My.FullName);

            KnownIdentities       knownIdentities = new KnownIdentities(Resolve.FileSystemState, Resolve.SessionNotify);
            KnownFoldersViewModel vm = new KnownFoldersViewModel(Resolve.FileSystemState, Resolve.SessionNotify, knownIdentities);

            Assert.That(vm.KnownFolders.Count(), Is.EqualTo(0));

            vm.KnownFolders = new KnownFolder[] { folder1, folder2 };
            Assert.That(vm.KnownFolders.Count(), Is.EqualTo(2));
            Assert.That(vm.KnownFolders.First().Enabled, Is.False);
            Assert.That(vm.KnownFolders.Last().Enabled, Is.False);

            await knownIdentities.SetDefaultEncryptionIdentity(new LogOnIdentity("aaa"));

            Assert.That(Resolve.FileSystemState.WatchedFolders.Count(), Is.EqualTo(1));
            Assert.That(vm.KnownFolders.Count(), Is.EqualTo(2));
            Assert.That(vm.KnownFolders.First().Enabled, Is.False);
            Assert.That(vm.KnownFolders.Last().Enabled, Is.True);
        }
Exemplo n.º 4
0
        public async Task TestAlreadyKnownFoldersAndLoggingOn()
        {
            IDataContainer betterCloudInfo = New <IDataContainer>(@"C:\BetterCloud");
            IDataContainer fasterCloudInfo = New <IDataContainer>(@"C:\FasterCloud");
            KnownFolder    folder1         = new KnownFolder(betterCloudInfo, @"My AxCrypt", KnownFolderKind.OneDrive, null);
            KnownFolder    folder2         = new KnownFolder(fasterCloudInfo, @"My AxCrypt", KnownFolderKind.WindowsMyDocuments, null);

            FakeDataStore.AddFolder(folder1.My.FullName);
            FakeDataStore.AddFolder(folder2.My.FullName);

            await Resolve.FileSystemState.AddWatchedFolderAsync(new WatchedFolder(folder1.My.FullName, new LogOnIdentity("PassPhrase").Tag));

            await Resolve.FileSystemState.AddWatchedFolderAsync(new WatchedFolder(folder2.My.FullName, new LogOnIdentity(new Passphrase("aaa")).Tag));

            KnownIdentities       knownIdentities = new KnownIdentities(Resolve.FileSystemState, Resolve.SessionNotify);
            KnownFoldersViewModel vm = new KnownFoldersViewModel(Resolve.FileSystemState, Resolve.SessionNotify, knownIdentities);

            Assert.That(vm.KnownFolders.Count(), Is.EqualTo(0));

            vm.KnownFolders = new KnownFolder[] { folder1, folder2 };
            Assert.That(vm.KnownFolders.Count(), Is.EqualTo(2));
            Assert.That(vm.KnownFolders.First().Enabled, Is.False);
            Assert.That(vm.KnownFolders.Last().Enabled, Is.False);

            await knownIdentities.SetDefaultEncryptionIdentity(new LogOnIdentity("aaa"));

            Assert.That(vm.KnownFolders.Count(), Is.EqualTo(2));
            Assert.That(vm.KnownFolders.First().Enabled, Is.False, "This folder should not be enabled, because it's not watched by the signed in identity.");
            Assert.That(vm.KnownFolders.Last().Enabled, Is.True, "This folder should be enabled, since it is watched by the signed in identity.");
        }
Exemplo n.º 5
0
        public async Task TestLoggingOffWhenLoggingOnWhenAlreadyLoggedOn()
        {
            int             wasLoggedOnCount    = 0;
            int             wasLoggedOffCount   = 0;
            SessionNotify   notificationMonitor = new SessionNotify();
            KnownIdentities knownIdentities     = new KnownIdentities(Resolve.FileSystemState, notificationMonitor);

            notificationMonitor.AddCommand((SessionNotification notification) =>
            {
                if (notification.NotificationType == SessionNotificationType.SignIn)
                {
                    Assert.That(knownIdentities.IsLoggedOn, Is.True, "The state of the IsLoggedOn property should be consistent with the event.");
                    ++wasLoggedOnCount;
                }
                if (notification.NotificationType == SessionNotificationType.SignOut)
                {
                    Assert.That(knownIdentities.IsLoggedOn, Is.False, "The state of the IsLoggedOn property should be consistent with the event.");
                    ++wasLoggedOffCount;
                }
                return(Constant.CompletedTask);
            });

            await knownIdentities.SetDefaultEncryptionIdentity(new LogOnIdentity("passphrase1"));

            Assert.That(wasLoggedOnCount, Is.EqualTo(1));
            Assert.That(wasLoggedOffCount, Is.EqualTo(0));
            Assert.That(knownIdentities.IsLoggedOn, Is.True);

            await knownIdentities.SetDefaultEncryptionIdentity(new LogOnIdentity("passphrase"));

            Assert.That(wasLoggedOnCount, Is.EqualTo(2));
            Assert.That(wasLoggedOffCount, Is.EqualTo(1));
            Assert.That(knownIdentities.IsLoggedOn, Is.True);
        }
Exemplo n.º 6
0
        public async Task TestAddKeyForKnownIdentity()
        {
            Resolve.FileSystemState.KnownPassphrases.Add(new Passphrase("a"));
            KnownIdentities knownIdentities = new KnownIdentities(Resolve.FileSystemState, Resolve.SessionNotify);
            await knownIdentities.AddAsync(new LogOnIdentity("a"));

            Assert.That(knownIdentities.DefaultEncryptionIdentity.Equals(LogOnIdentity.Empty), "When adding a key that is for a known identity it should not be set as the default.");
        }
 public SessionNotificationHandler(FileSystemState fileSystemState, KnownIdentities knownIdentities, ActiveFileAction activeFileAction, AxCryptFile axCryptFile, IStatusChecker statusChecker)
 {
     _fileSystemState  = fileSystemState;
     _knownIdentities  = knownIdentities;
     _activeFileAction = activeFileAction;
     _axCryptFile      = axCryptFile;
     _statusChecker    = statusChecker;
 }
Exemplo n.º 8
0
        public async Task TestAddNewKnownKey()
        {
            KnownIdentities knownIdentities = new KnownIdentities(Resolve.FileSystemState, Resolve.SessionNotify);
            LogOnIdentity   passphrase      = new LogOnIdentity("a");
            await knownIdentities.AddAsync(passphrase);

            Assert.That(knownIdentities.Identities.First(), Is.EqualTo(passphrase), "The first and only key should be the one just added.");
        }
Exemplo n.º 9
0
        public ImportPrivateKeysViewModel(UserSettings userSettings, KnownIdentities knownIdentities)
        {
            _userSettings    = userSettings;
            _knownIdentities = knownIdentities;

            InitializePropertyValues();
            BindPropertyChangedEvents();
            SubscribeToModelEvents();
        }
        public KnownFoldersViewModel(FileSystemState fileSystemState, SessionNotify sessionNotify, KnownIdentities knownIdentities)
        {
            _fileSystemState = fileSystemState;
            _sessionNotify   = sessionNotify;
            _knownIdentities = knownIdentities;

            InitializePropertyValues();
            SubscribeToModelEvents();
        }
Exemplo n.º 11
0
        public async Task TestAddEmptyKey()
        {
            KnownIdentities knownIdentities = new KnownIdentities(Resolve.FileSystemState, Resolve.SessionNotify);
            LogOnIdentity   key             = new LogOnIdentity(String.Empty);
            await knownIdentities.AddAsync(key);

            await knownIdentities.AddAsync(key);

            Assert.That(knownIdentities.Identities.Count(), Is.EqualTo(0), "No key should be in the collection even if added twice, since it is empty.");
        }
Exemplo n.º 12
0
        public async Task TestDefaultEncryptionKey()
        {
            KnownIdentities knownIdentities = new KnownIdentities(Resolve.FileSystemState, Resolve.SessionNotify);
            LogOnIdentity   key             = new LogOnIdentity("a");
            await knownIdentities.SetDefaultEncryptionIdentity(key);

            Assert.That(knownIdentities.DefaultEncryptionIdentity, Is.EqualTo(key), "The DefaultEncryptionKey should be the one just set as it.");
            Assert.That(knownIdentities.Identities.Count(), Is.EqualTo(1), "Only one key should be in the collection.");
            Assert.That(knownIdentities.Identities.First(), Is.EqualTo(key), "The first and only key should be the one just set as DefaultEncryptionKey.");
        }
Exemplo n.º 13
0
        public async Task TestWatchedFoldersNotLoggedOn()
        {
            KnownIdentities knownIdentities = new KnownIdentities(Resolve.FileSystemState, Resolve.SessionNotify);

            FakeDataStore.AddFolder(@"C:\WatchedFolder\");
            await Resolve.FileSystemState.AddWatchedFolderAsync(new WatchedFolder(@"C:\WatchedFolder\", IdentityPublicTag.Empty));

            IEnumerable <WatchedFolder> watchedFolders = knownIdentities.LoggedOnWatchedFolders;

            Assert.That(watchedFolders.Count(), Is.EqualTo(0), "When not logged on, no watched folders should be known.");
        }
Exemplo n.º 14
0
        public async Task TestAddSameKeyTwice()
        {
            KnownIdentities knownIdentities = new KnownIdentities(Resolve.FileSystemState, Resolve.SessionNotify);
            LogOnIdentity   key             = new LogOnIdentity("abc");
            await knownIdentities.AddAsync(key);

            await knownIdentities.AddAsync(key);

            Assert.That(knownIdentities.Identities.Count(), Is.EqualTo(1), "Only one key should be in the collection even if added twice.");
            Assert.That(knownIdentities.Identities.First(), Is.EqualTo(key), "The first and only key should be the one just added.");
        }
Exemplo n.º 15
0
        public async Task TestAddTwoNewKnownIdentities()
        {
            KnownIdentities knownIdentities = new KnownIdentities(Resolve.FileSystemState, Resolve.SessionNotify);
            LogOnIdentity   key1            = new LogOnIdentity("key1");
            await knownIdentities.AddAsync(key1);

            LogOnIdentity key2 = new LogOnIdentity("key2");
            await knownIdentities.AddAsync(key2);

            Assert.That(knownIdentities.Identities.First(), Is.EqualTo(key2), "The first key should be the last one added.");
            Assert.That(knownIdentities.Identities.Last(), Is.EqualTo(key1), "The last key should be the first one added.");
        }
        public FileOperationViewModel(FileSystemState fileSystemState, SessionNotify sessionNotify, KnownIdentities knownIdentities, ParallelFileOperation fileOperation, IStatusChecker statusChecker, IdentityViewModel identityViewModel)
        {
            _fileSystemState = fileSystemState;
            _sessionNotify   = sessionNotify;
            _knownIdentities = knownIdentities;
            _fileOperation   = fileOperation;
            _statusChecker   = statusChecker;

            IdentityViewModel = identityViewModel;

            InitializePropertyValues();
            SubscribeToModelEvents();
        }
Exemplo n.º 17
0
        public async Task TestSettingNullDefaultEncryptionKey()
        {
            KnownIdentities knownIdentities = new KnownIdentities(Resolve.FileSystemState, Resolve.SessionNotify);
            LogOnIdentity   key1            = new LogOnIdentity("a");
            await knownIdentities.AddAsync(key1);

            LogOnIdentity key2 = new LogOnIdentity("B");
            await knownIdentities.SetDefaultEncryptionIdentity(key2);

            Assert.That(knownIdentities.Identities.Count(), Is.EqualTo(2), "Setting the DefaultEncryptionKey should also add it as a known key.");

            await knownIdentities.SetDefaultEncryptionIdentity(LogOnIdentity.Empty);

            Assert.That(knownIdentities.Identities.Count(), Is.EqualTo(0), "Setting the DefaultEncryptionKey to empty should clear the known keys.");
        }
Exemplo n.º 18
0
        public async Task TestChangedEventWhenAddingEmptyIdentity()
        {
            bool            wasChanged          = false;
            SessionNotify   notificationMonitor = new SessionNotify();
            KnownIdentities knownIdentities     = new KnownIdentities(Resolve.FileSystemState, notificationMonitor);

            notificationMonitor.AddCommand((SessionNotification notification) =>
            {
                wasChanged |= notification.NotificationType == SessionNotificationType.KnownKeyChange;
                return(Constant.CompletedTask);
            });
            LogOnIdentity key1 = new LogOnIdentity(String.Empty);
            await knownIdentities.AddAsync(key1);

            Assert.That(wasChanged, Is.False, "A new key should not trigger the Changed event.");
        }
        public ImportPrivatePasswordDialog(Form parent, UserSettings userSettings, KnownIdentities knownIdentities)
            : this()
        {
            InitializeStyle(parent);

            _viewModel = new ImportPrivateKeysViewModel(userSettings, knownIdentities);

            _privateKeyFileTextBox.TextChanged     += (sender, e) => { _viewModel.PrivateKeyFileName = _privateKeyFileTextBox.Text; ClearErrorProviders(); };
            _passphraseTextBox.TextChanged         += (sender, e) => { _viewModel.PasswordText = _passphraseTextBox.Text; _privateKeyFileTextBox.ScrollToCaret(); ClearErrorProviders(); };
            _showPassphraseCheckBox.CheckedChanged += (sender, e) => { _viewModel.ShowPassword = _showPassphraseCheckBox.Checked; };

            _viewModel.BindPropertyChanged <bool>(nameof(_viewModel.ImportSuccessful), (ok) => { if (!ok)
                                                                                                 {
                                                                                                     _errorProvider1.SetError(_browsePrivateKeyFileButton, Texts.FailedPrivateImport);
                                                                                                 }
                                                  });
            _viewModel.BindPropertyChanged <bool>(nameof(_viewModel.ShowPassword), (show) => { _showPassphraseCheckBox.Checked = show; _passphraseTextBox.UseSystemPasswordChar = !show; });
        }
Exemplo n.º 20
0
        public async Task TestWatchedFoldersWhenLoggedOn()
        {
            Passphrase      key1            = new Passphrase("a");
            LogOnIdentity   key2            = new LogOnIdentity("b");
            KnownIdentities knownIdentities = new KnownIdentities(Resolve.FileSystemState, Resolve.SessionNotify);

            FakeDataStore.AddFolder(@"C:\WatchedFolder1\");
            FakeDataStore.AddFolder(@"C:\WatchedFolder2\");
            await Resolve.FileSystemState.AddWatchedFolderAsync(new WatchedFolder(@"C:\WatchedFolder1\", new LogOnIdentity(key1).Tag));

            await Resolve.FileSystemState.AddWatchedFolderAsync(new WatchedFolder(@"C:\WatchedFolder2\", key2.Tag));

            await knownIdentities.SetDefaultEncryptionIdentity(key2);

            IEnumerable <WatchedFolder> watchedFolders = knownIdentities.LoggedOnWatchedFolders;

            Assert.That(watchedFolders.Count(), Is.EqualTo(1), "Only one of the two watched folders should be shown.");
            Assert.That(watchedFolders.First().Tag.Matches(key2.Tag), "The returned watched folder should be number 2.");
        }
Exemplo n.º 21
0
        public async Task TestClear()
        {
            KnownIdentities knownIdentities = new KnownIdentities(Resolve.FileSystemState, Resolve.SessionNotify);
            LogOnIdentity   key1            = new LogOnIdentity("key1");
            await knownIdentities.AddAsync(key1);

            LogOnIdentity key2 = new LogOnIdentity("key2");
            await knownIdentities.AddAsync(key2);

            Assert.That(knownIdentities.Identities.Count(), Is.EqualTo(2), "There should be two keys in the collection.");

            await knownIdentities.SetDefaultEncryptionIdentity(LogOnIdentity.Empty);

            Assert.That(knownIdentities.Identities.Count(), Is.EqualTo(0), "There should be zero keys in the collection after Clear().");

            await knownIdentities.SetDefaultEncryptionIdentity(LogOnIdentity.Empty);

            Assert.That(knownIdentities.Identities.Count(), Is.EqualTo(0), "There should be zero keys in the collection after Clear() with zero keys to start with.");
        }
Exemplo n.º 22
0
        public IdentityViewModel(FileSystemState fileSystemState, KnownIdentities knownIdentities, UserSettings userSettings, SessionNotify sessionNotify)
        {
            _fileSystemState = fileSystemState;
            _knownIdentities = knownIdentities;
            _userSettings    = userSettings;
            _sessionNotify   = sessionNotify;

            LogOnIdentity = LogOnIdentity.Empty;

            LogOnAsync = new AsyncDelegateAction <object>(async(o) => { if (!_knownIdentities.IsLoggedOn)
                                                                        {
                                                                            LogOnIdentity = await LogOnActionAsync();
                                                                        }
                                                          });
            LogOff                  = new AsyncDelegateAction <object>(async(p) => { await LogOffAction(); LogOnIdentity = LogOnIdentity.Empty; }, (o) => Task.FromResult(_knownIdentities.IsLoggedOn));
            LogOnLogOff             = new AsyncDelegateAction <object>(async(o) => LogOnIdentity = await LogOnLogOffActionAsync());
            AskForDecryptPassphrase = new AsyncDelegateAction <string>(async(name) => LogOnIdentity = await AskForDecryptPassphraseActionAsync(name));
            AskForLogOnPassphrase   = new AsyncDelegateAction <LogOnIdentity>(async(id) => LogOnIdentity = await AskForLogOnPassphraseActionAsync(id, String.Empty));

            _sessionNotify.AddCommand(HandleLogOnLogOffNotifications);
        }