public static void TestCheckProcessExitedWhenExited() { DateTime utcNow = OS.Current.UtcNow; FakeRuntimeFileInfo.AddFile(_encryptedFile1, utcNow, utcNow, utcNow, Stream.Null); FakeRuntimeFileInfo.AddFile(_decryptedFile1, utcNow, utcNow, utcNow, Stream.Null); FakeLauncher fakeLauncher = new FakeLauncher(_decryptedFile1); ActiveFile activeFile = new ActiveFile(OS.Current.FileInfo(_encryptedFile1), OS.Current.FileInfo(_decryptedFile1), new AesKey(), ActiveFileStatus.AssumedOpenAndDecrypted | ActiveFileStatus.NotShareable, fakeLauncher); _fileSystemState.Add(activeFile); SetupAssembly.FakeRuntimeEnvironment.TimeFunction = (() => { return(utcNow.AddMinutes(1)); }); bool changedWasRaised = false; _fileSystemState.Changed += ((object sender, ActiveFileChangedEventArgs e) => { changedWasRaised = true; }); SetupAssembly.FakeRuntimeEnvironment.Platform = Platform.WindowsDesktop; fakeLauncher.HasExited = true; _fileSystemState.CheckActiveFiles(ChangedEventMode.RaiseOnlyOnModified, new ProgressContext()); activeFile = _fileSystemState.FindEncryptedPath(_encryptedFile1); Assert.That(changedWasRaised, Is.True, "A changed event should be raised because the process has exited."); Assert.That(activeFile.Status.HasMask(ActiveFileStatus.NotDecrypted), Is.True, "The ActiveFile plain text should be deleted after the checking of active files because the launcher is no longer active."); Assert.That(activeFile.Status.HasMask(ActiveFileStatus.NotShareable), Is.False, "The file should be shareable after checking of active files because the launcher is no longer active."); }
public async Task TestSimpleDecryptAndLaunch() { FakeLauncher launcher = new FakeLauncher(); bool called = false; TypeMap.Register.New <ILauncher>(() => { called = true; return(launcher); }); FileOperationsController controller = new FileOperationsController(); controller.QueryDecryptionPassphrase = (FileOperationEventArgs e) => { e.LogOnIdentity = new LogOnIdentity("a"); return(Task.FromResult <object>(null)); }; FileOperationContext status = await controller.DecryptAndLaunchAsync(New <IDataStore>(_helloWorldAxxPath)); Assert.That(status.ErrorStatus, Is.EqualTo(ErrorStatus.Success), "The status should indicate success."); Assert.That(called, Is.True, "There should be a call to launch."); Assert.That(Path.GetFileName(launcher.Path), Is.EqualTo("HelloWorld-Key-a.txt"), "The file should be decrypted and the name should be the original from the encrypted headers."); IDataStore destinationInfo = New <IDataStore>(launcher.Path); Assert.That(destinationInfo.IsAvailable, "After decryption the destination file should be created."); string fileContent; using (Stream stream = destinationInfo.OpenRead()) { fileContent = new StreamReader(stream).ReadToEnd(); } Assert.That(fileContent.Contains("Hello"), "A file named Hello World should contain that text when decrypted."); }
public async Task TestExitEvent() { IDataStore dataStore = New <IDataStore>(_helloWorldAxxPath); IEnumerable <LogOnIdentity> keys = new LogOnIdentity[] { new LogOnIdentity("a") }; FakeLauncher launcher = new FakeLauncher(); bool called = false; TypeMap.Register.New <ILauncher>(() => { called = true; launcher.WasStarted = true; return(launcher); }); SessionNotify notificationMonitor = new SessionNotify(); FileOperation fileOperation = new FileOperation(Resolve.FileSystemState, notificationMonitor); FileOperationContext status = await fileOperation.OpenAndLaunchApplication(keys, dataStore, new ProgressContext()); Assert.That(status.ErrorStatus, Is.EqualTo(ErrorStatus.Success), "The launch should succeed."); Assert.That(called, Is.True, "There should be a call to launch to try launching."); Assert.That(Path.GetFileName(launcher.Path), Is.EqualTo("HelloWorld-Key-a.txt"), "The file should be decrypted and the name should be the original from the encrypted headers."); bool changedWasRaised = false; notificationMonitor.AddCommand((SessionNotification notification) => { changedWasRaised = true; return(Constant.CompletedTask); }); Assert.That(changedWasRaised, Is.False, "The global changed event should not have been raised yet."); launcher.RaiseExited(); Assert.That(changedWasRaised, Is.True, "The global changed event should be raised when the process exits."); }
public async Task TestCheckProcessExitedWhenExited() { DateTime utcNow = New <INow>().Utc; FakeDataStore.AddFile(_anAxxPath, utcNow, utcNow, utcNow, new MemoryStream(Resources.helloworld_key_a_txt)); FakeDataStore.AddFile(_decryptedFile1, utcNow, utcNow, utcNow, Stream.Null); await New <KnownIdentities>().SetDefaultEncryptionIdentity(new LogOnIdentity(EmailAddress.Parse("*****@*****.**"), new Passphrase("test"))); FakeLauncher fakeLauncher = new FakeLauncher(); fakeLauncher.Launch(_decryptedFile1); ActiveFile activeFile = new ActiveFile(New <IDataStore>(_anAxxPath), New <IDataStore>(_decryptedFile1), new LogOnIdentity("passphrase"), ActiveFileStatus.NotDecrypted, new V1Aes128CryptoFactory().CryptoId); activeFile = new ActiveFile(activeFile, ActiveFileStatus.AssumedOpenAndDecrypted | ActiveFileStatus.NotShareable); Resolve.FileSystemState.Add(activeFile, fakeLauncher); ((FakeNow)New <INow>()).TimeFunction = (() => { return(utcNow.AddMinutes(1)); }); bool changedWasRaised = false; Resolve.SessionNotify.AddCommand((SessionNotification notification) => { changedWasRaised = notification.NotificationType == SessionNotificationType.ActiveFileChange; return(Constant.CompletedTask); }); SetupAssembly.FakeRuntimeEnvironment.Platform = Platform.WindowsDesktop; fakeLauncher.HasExited = true; await New <ActiveFileAction>().CheckActiveFiles(new ProgressContext()); activeFile = Resolve.FileSystemState.FindActiveFileFromEncryptedPath(_anAxxPath); Assert.That(changedWasRaised, Is.True, "A changed event should be raised because the process has exited."); Assert.That(activeFile.Status.HasMask(ActiveFileStatus.NotDecrypted), Is.True, "The ActiveFile plain text should be deleted after the checking of active files because the launcher is no longer active."); Assert.That(activeFile.Status.HasMask(ActiveFileStatus.NotShareable), Is.False, "The file should be shareable after checking of active files because the launcher is no longer active."); }
public static void TestExitEvent() { IEnumerable <AesKey> keys = new AesKey[] { new Passphrase("a").DerivedPassphrase }; FakeLauncher launcher = null; SetupAssembly.FakeRuntimeEnvironment.Launcher = ((string path) => { launcher = new FakeLauncher(path); launcher.WasStarted = true; return(launcher); }); FileOperationStatus status = _fileSystemState.OpenAndLaunchApplication(_helloWorldAxxPath, keys, new ProgressContext()); Assert.That(status, Is.EqualTo(FileOperationStatus.Success), "The launch should succeed."); Assert.That(launcher, Is.Not.Null, "There should be a call to launch to try launching."); Assert.That(Path.GetFileName(launcher.Path), Is.EqualTo("HelloWorld-Key-a.txt"), "The file should be decrypted and the name should be the original from the encrypted headers."); bool changedWasRaised = false; OS.Current.WorkFolderStateChanged += (object sender, EventArgs e) => { changedWasRaised = true; }; Assert.That(changedWasRaised, Is.False, "The global changed event should not have been raised yet."); launcher.RaiseExited(); Assert.That(changedWasRaised, Is.True, "The global changed event should be raised when the process exits."); }
public static void TestOpenAndLaunchOfAxCryptDocumentWhenAlreadyDecrypted() { TestOpenAndLaunchOfAxCryptDocument(); FakeLauncher launcher = null; SetupAssembly.FakeRuntimeEnvironment.Launcher = ((string path) => { launcher = new FakeLauncher(path); return(launcher); }); FileOperationStatus status; using (AxCryptDocument document = new AxCryptDocument()) { using (Stream stream = OS.Current.FileInfo(_helloWorldAxxPath).OpenRead()) { document.Load(stream, new Passphrase("a").DerivedPassphrase); status = _fileSystemState.OpenAndLaunchApplication(_helloWorldAxxPath, document, new ProgressContext()); } } Assert.That(status, Is.EqualTo(FileOperationStatus.Success), "The launch should succeed."); Assert.That(launcher, Is.Not.Null, "There should be a call to launch."); Assert.That(Path.GetFileName(launcher.Path), Is.EqualTo("HelloWorld-Key-a.txt"), "The file should be decrypted and the name should be the original from the encrypted headers."); }
public static void TestSimpleDecryptAndLaunchOnThreadWorker() { FakeLauncher launcher = null; FakeRuntimeEnvironment environment = (FakeRuntimeEnvironment)OS.Current; environment.Launcher = ((string path) => { launcher = new FakeLauncher(path); return(launcher); }); FileOperationsController controller = new FileOperationsController(_fileSystemState); controller.QueryDecryptionPassphrase += (object sender, FileOperationEventArgs e) => { e.Passphrase = "a"; }; FileOperationStatus status = FileOperationStatus.Unknown; controller.Completed += (object sender, FileOperationEventArgs e) => { status = e.Status; }; using (ThreadWorker worker = new ThreadWorker(new ProgressContext())) { controller.DecryptAndLaunch(_helloWorldAxxPath, worker); worker.Join(); } Assert.That(status, Is.EqualTo(FileOperationStatus.Success), "The status should indicate success."); Assert.That(launcher, Is.Not.Null, "There should be a call to launch."); Assert.That(Path.GetFileName(launcher.Path), Is.EqualTo("HelloWorld-Key-a.txt"), "The file should be decrypted and the name should be the original from the encrypted headers."); IRuntimeFileInfo destinationInfo = OS.Current.FileInfo(launcher.Path); Assert.That(destinationInfo.Exists, "After decryption the destination file should be created."); string fileContent; using (Stream stream = destinationInfo.OpenRead()) { fileContent = new StreamReader(stream).ReadToEnd(); } Assert.That(fileContent.Contains("Hello"), "A file named Hello World should contain that text when decrypted."); }
public async Task TestImmediateExit() { IDataStore dataStore = New <IDataStore>(_helloWorldAxxPath); IEnumerable <LogOnIdentity> keys = new LogOnIdentity[] { new LogOnIdentity("a") }; FakeLauncher launcher = new FakeLauncher(); bool called = false; TypeMap.Register.New <ILauncher>(() => { called = true; launcher.WasStarted = true; launcher.HasExited = true; return(launcher); }); FileOperation fileOperation = new FileOperation(Resolve.FileSystemState, new SessionNotify()); FileOperationContext status = await fileOperation.OpenAndLaunchApplication(keys, dataStore, new ProgressContext()); Assert.That(status.ErrorStatus, Is.EqualTo(ErrorStatus.Success), "The launch should succeed even if the process exits immediately."); Assert.That(called, Is.True, "There should be a call to launch to try launching."); Assert.That(Path.GetFileName(launcher.Path), Is.EqualTo("HelloWorld-Key-a.txt"), "The file should be decrypted and the name should be the original from the encrypted headers."); }
public async Task TestOpenAndLaunchOfAxCryptDocument() { FakeLauncher launcher = new FakeLauncher(); bool called = false; TypeMap.Register.New <ILauncher>(() => { called = true; return(launcher); }); FileOperationContext status; FileOperation fileOperation = new FileOperation(Resolve.FileSystemState, new SessionNotify()); IDataStore axCryptDataStore = New <IDataStore>(_helloWorldAxxPath); status = await fileOperation.OpenAndLaunchApplication(new LogOnIdentity("a"), axCryptDataStore, new ProgressContext()); Assert.That(status.ErrorStatus, Is.EqualTo(ErrorStatus.Success), "The launch should succeed."); Assert.That(called, Is.True, "There should be a call to launch."); Assert.That(Path.GetFileName(launcher.Path), Is.EqualTo("HelloWorld-Key-a.txt"), "The file should be decrypted and the name should be the original from the encrypted headers."); }
public static void TestInvalidArguments() { IRuntimeFileInfo nullFileInfo = null; ILauncher nullProcess = null; IRuntimeFileInfo decryptedFileInfo = OS.Current.FileInfo(_testTextPath); IRuntimeFileInfo encryptedFileInfo = OS.Current.FileInfo(_helloWorldAxxPath); AesKey key = new AesKey(); AesKey nullKey = null; ILauncher process = new FakeLauncher(String.Empty); ActiveFile nullActiveFile = null; ActiveFile originalActiveFile = new ActiveFile(decryptedFileInfo, decryptedFileInfo, key, ActiveFileStatus.None, process); Assert.Throws <ArgumentNullException>(() => { if (new ActiveFile(nullActiveFile, key) == null) { } }); Assert.Throws <ArgumentNullException>(() => { if (new ActiveFile(originalActiveFile, nullKey) == null) { } }); Assert.Throws <ArgumentNullException>(() => { if (new ActiveFile(nullActiveFile, ActiveFileStatus.None, nullProcess) == null) { } }); Assert.Throws <ArgumentNullException>(() => { if (new ActiveFile(nullActiveFile, ActiveFileStatus.None) == null) { } }); Assert.Throws <ArgumentNullException>(() => { if (new ActiveFile(nullActiveFile, DateTime.MinValue, ActiveFileStatus.None) == null) { } }); Assert.Throws <ArgumentNullException>(() => { if (new ActiveFile(nullFileInfo, decryptedFileInfo, new AesKey(), ActiveFileStatus.None, nullProcess) == null) { } }); Assert.Throws <ArgumentNullException>(() => { if (new ActiveFile(encryptedFileInfo, nullFileInfo, new AesKey(), ActiveFileStatus.None, nullProcess) == null) { } }); Assert.Throws <ArgumentNullException>(() => { if (new ActiveFile(encryptedFileInfo, decryptedFileInfo, nullKey, ActiveFileStatus.None, nullProcess) == null) { } }); }
public static void TestCopyConstructorWithKey() { ILauncher process = new FakeLauncher(String.Empty); AesKey key = new AesKey(); IRuntimeFileInfo decryptedFileInfo = OS.Current.FileInfo(_testTextPath); IRuntimeFileInfo encryptedFileInfo = OS.Current.FileInfo(_helloWorldAxxPath); using (ActiveFile activeFile = new ActiveFile(encryptedFileInfo, decryptedFileInfo, key, ActiveFileStatus.None, process)) { AesKey newKey = new AesKey(); using (ActiveFile newActiveFile = new ActiveFile(activeFile, newKey)) { Assert.That(activeFile.Key, Is.Not.EqualTo(newKey), "Ensure that it's really a different key."); Assert.That(newActiveFile.Key, Is.EqualTo(newKey), "The constructor should assign the new key to the new ActiveFile instance."); } } }
public static void TestSimpleOpenAndLaunch() { IEnumerable <AesKey> keys = new AesKey[] { new Passphrase("a").DerivedPassphrase }; FakeLauncher launcher = null; SetupAssembly.FakeRuntimeEnvironment.Launcher = ((string path) => { launcher = new FakeLauncher(path); return(launcher); }); FileOperationStatus status = _fileSystemState.OpenAndLaunchApplication(_helloWorldAxxPath, keys, new ProgressContext()); Assert.That(status, Is.EqualTo(FileOperationStatus.Success), "The launch should succeed."); Assert.That(launcher, Is.Not.Null, "There should be a call to launch."); Assert.That(Path.GetFileName(launcher.Path), Is.EqualTo("HelloWorld-Key-a.txt"), "The file should be decrypted and the name should be the original from the encrypted headers."); }
public static void TestThumbprintNullKey() { IRuntimeFileInfo decryptedFileInfo = OS.Current.FileInfo(_testTextPath); IRuntimeFileInfo encryptedFileInfo = OS.Current.FileInfo(_helloWorldAxxPath); ILauncher process = new FakeLauncher(String.Empty); AesKey key = new AesKey(); using (MemoryStream stream = new MemoryStream()) { using (ActiveFile activeFile = new ActiveFile(encryptedFileInfo, decryptedFileInfo, key, ActiveFileStatus.None, process)) { Assert.Throws <ArgumentNullException>(() => { AesKey nullKey = null; activeFile.ThumbprintMatch(nullKey); }); } } }
public static void TestThumbprint() { IRuntimeFileInfo decryptedFileInfo = OS.Current.FileInfo(_testTextPath); IRuntimeFileInfo encryptedFileInfo = OS.Current.FileInfo(_helloWorldAxxPath); ILauncher process = new FakeLauncher(String.Empty); AesKey key = new AesKey(); using (MemoryStream stream = new MemoryStream()) { DataContractSerializer serializer = new DataContractSerializer(typeof(ActiveFile)); using (ActiveFile activeFile = new ActiveFile(encryptedFileInfo, decryptedFileInfo, key, ActiveFileStatus.None, process)) { serializer.WriteObject(stream, activeFile); } stream.Position = 0; ActiveFile deserializedActiveFile = (ActiveFile)serializer.ReadObject(stream); Assert.That(deserializedActiveFile.ThumbprintMatch(key), Is.True, "The deserialized object should match the thumbprint with the key."); } }
public static void TestConstructor() { AesKey key = new AesKey(); ILauncher process = new FakeLauncher(String.Empty); IRuntimeFileInfo decryptedFileInfo = OS.Current.FileInfo(_testTextPath); IRuntimeFileInfo encryptedFileInfo = OS.Current.FileInfo(_helloWorldAxxPath); using (ActiveFile activeFile = new ActiveFile(encryptedFileInfo, decryptedFileInfo, key, ActiveFileStatus.None, process)) { decryptedFileInfo = activeFile.DecryptedFileInfo; Assert.That(decryptedFileInfo.Exists, Is.True, "The file should exist in the fake file system."); Assert.That(decryptedFileInfo.FullName, Is.EqualTo(_testTextPath), "The file should be named as it was in the constructor"); Assert.That(decryptedFileInfo.LastWriteTimeUtc, Is.EqualTo(decryptedFileInfo.LastWriteTimeUtc), "When a LastWriteTime is not specified, the decrypted file should be used to determine the value."); Assert.That(activeFile.Process, Is.EqualTo(process), "The process should be set from the constructor."); SetupAssembly.FakeRuntimeEnvironment.TimeFunction = (() => { return(DateTime.UtcNow.AddMinutes(1)); }); using (ActiveFile otherFile = new ActiveFile(activeFile, ActiveFileStatus.AssumedOpenAndDecrypted)) { Assert.That(otherFile.Status, Is.EqualTo(ActiveFileStatus.AssumedOpenAndDecrypted), "The status should be as given in the constructor."); Assert.That(otherFile.DecryptedFileInfo.FullName, Is.EqualTo(activeFile.DecryptedFileInfo.FullName), "This should be copied from the original instance."); Assert.That(otherFile.EncryptedFileInfo.FullName, Is.EqualTo(activeFile.EncryptedFileInfo.FullName), "This should be copied from the original instance."); Assert.That(otherFile.Key, Is.EqualTo(activeFile.Key), "This should be copied from the original instance."); Assert.That(otherFile.LastActivityTimeUtc, Is.GreaterThan(activeFile.LastActivityTimeUtc), "This should not be copied from the original instance, but should be a later time."); Assert.That(otherFile.Process, Is.EqualTo(process), "This should be copied from the original instance."); Assert.That(activeFile.Process, Is.Null, "The process should only be owned by one instance at a time."); Assert.That(otherFile.ThumbprintMatch(activeFile.Key), Is.True, "The thumbprints should match."); } using (ActiveFile otherFile = new ActiveFile(activeFile, ActiveFileStatus.AssumedOpenAndDecrypted, process)) { Assert.That(otherFile.Process, Is.EqualTo(process), "This should be copied from the instance provided in the constructor."); } activeFile.DecryptedFileInfo.LastWriteTimeUtc = activeFile.DecryptedFileInfo.LastWriteTimeUtc.AddDays(1); using (ActiveFile otherFile = new ActiveFile(activeFile, OS.Current.UtcNow, ActiveFileStatus.AssumedOpenAndDecrypted)) { Assert.That(activeFile.IsModified, Is.True, "The original instance has not been encrypted since the last change."); Assert.That(otherFile.IsModified, Is.False, "The copy indicates that it has been encrypted and thus is not modified."); } } }
public static void TestConstructor() { AesKey key = new AesKey(); ILauncher process = new FakeLauncher(String.Empty); IRuntimeFileInfo decryptedFileInfo = OS.Current.FileInfo(_testTextPath); IRuntimeFileInfo encryptedFileInfo = OS.Current.FileInfo(_helloWorldAxxPath); using (ActiveFile activeFile = new ActiveFile(encryptedFileInfo, decryptedFileInfo, key, ActiveFileStatus.None, process)) { decryptedFileInfo = activeFile.DecryptedFileInfo; Assert.That(decryptedFileInfo.Exists, Is.True, "The file should exist in the fake file system."); Assert.That(decryptedFileInfo.FullName, Is.EqualTo(_testTextPath), "The file should be named as it was in the constructor"); Assert.That(decryptedFileInfo.LastWriteTimeUtc, Is.EqualTo(decryptedFileInfo.LastWriteTimeUtc), "When a LastWriteTime is not specified, the decrypted file should be used to determine the value."); Assert.That(activeFile.Process, Is.EqualTo(process), "The process should be set from the constructor."); SetupAssembly.FakeRuntimeEnvironment.TimeFunction = (() => { return DateTime.UtcNow.AddMinutes(1); }); using (ActiveFile otherFile = new ActiveFile(activeFile, ActiveFileStatus.AssumedOpenAndDecrypted)) { Assert.That(otherFile.Status, Is.EqualTo(ActiveFileStatus.AssumedOpenAndDecrypted), "The status should be as given in the constructor."); Assert.That(otherFile.DecryptedFileInfo.FullName, Is.EqualTo(activeFile.DecryptedFileInfo.FullName), "This should be copied from the original instance."); Assert.That(otherFile.EncryptedFileInfo.FullName, Is.EqualTo(activeFile.EncryptedFileInfo.FullName), "This should be copied from the original instance."); Assert.That(otherFile.Key, Is.EqualTo(activeFile.Key), "This should be copied from the original instance."); Assert.That(otherFile.LastActivityTimeUtc, Is.GreaterThan(activeFile.LastActivityTimeUtc), "This should not be copied from the original instance, but should be a later time."); Assert.That(otherFile.Process, Is.EqualTo(process), "This should be copied from the original instance."); Assert.That(activeFile.Process, Is.Null, "The process should only be owned by one instance at a time."); Assert.That(otherFile.ThumbprintMatch(activeFile.Key), Is.True, "The thumbprints should match."); } using (ActiveFile otherFile = new ActiveFile(activeFile, ActiveFileStatus.AssumedOpenAndDecrypted, process)) { Assert.That(otherFile.Process, Is.EqualTo(process), "This should be copied from the instance provided in the constructor."); } activeFile.DecryptedFileInfo.LastWriteTimeUtc = activeFile.DecryptedFileInfo.LastWriteTimeUtc.AddDays(1); using (ActiveFile otherFile = new ActiveFile(activeFile, OS.Current.UtcNow, ActiveFileStatus.AssumedOpenAndDecrypted)) { Assert.That(activeFile.IsModified, Is.True, "The original instance has not been encrypted since the last change."); Assert.That(otherFile.IsModified, Is.False, "The copy indicates that it has been encrypted and thus is not modified."); } } }
public static void TestPurgeInactive() { TypeMap.Register.New <ILauncher>(() => new FakeLauncher()); ProcessState ps = new ProcessState(); ActiveFile activeFile1 = new ActiveFile(New <IDataStore>(@"C:\encrypted.axx"), New <IDataStore>(@"C:\decrypted.txt"), new LogOnIdentity("passphrase"), ActiveFileStatus.NotDecrypted, new V1Aes128CryptoFactory().CryptoId); ILauncher launcher1 = New <ILauncher>(); launcher1.Launch(activeFile1.EncryptedFileInfo.FullName); ps.Add(launcher1, activeFile1); Assert.That(ps.HasActiveProcess(activeFile1), Is.True); FakeLauncher fakeLauncher1 = (FakeLauncher)launcher1; fakeLauncher1.HasExited = true; Assert.That(ps.HasActiveProcess(activeFile1), Is.False); fakeLauncher1.HasExited = false; Assert.That(ps.HasActiveProcess(activeFile1), Is.True); fakeLauncher1.HasExited = true; Assert.That(ps.HasActiveProcess(activeFile1), Is.False); ActiveFile activeFile2 = new ActiveFile(New <IDataStore>(@"C:\encrypted2.axx"), New <IDataStore>(@"C:\decrypted2.txt"), new LogOnIdentity("passphrase"), ActiveFileStatus.NotDecrypted, new V1Aes128CryptoFactory().CryptoId); ILauncher launcher2 = New <ILauncher>(); launcher2.Launch(activeFile2.EncryptedFileInfo.FullName); ps.Add(launcher2, activeFile2); Assert.That(ps.HasActiveProcess(activeFile1), Is.False); fakeLauncher1.HasExited = false; Assert.That(ps.HasActiveProcess(activeFile1), Is.False); }
public static void TestThumbprintNullKey() { IRuntimeFileInfo decryptedFileInfo = OS.Current.FileInfo(_testTextPath); IRuntimeFileInfo encryptedFileInfo = OS.Current.FileInfo(_helloWorldAxxPath); ILauncher process = new FakeLauncher(String.Empty); AesKey key = new AesKey(); using (MemoryStream stream = new MemoryStream()) { using (ActiveFile activeFile = new ActiveFile(encryptedFileInfo, decryptedFileInfo, key, ActiveFileStatus.None, process)) { Assert.Throws<ArgumentNullException>(() => { AesKey nullKey = null; activeFile.ThumbprintMatch(nullKey); }); } } }
public static void TestSimpleDecryptAndLaunchOnThreadWorker() { FakeLauncher launcher = null; FakeRuntimeEnvironment environment = (FakeRuntimeEnvironment)OS.Current; environment.Launcher = ((string path) => { launcher = new FakeLauncher(path); return launcher; }); FileOperationsController controller = new FileOperationsController(_fileSystemState); controller.QueryDecryptionPassphrase += (object sender, FileOperationEventArgs e) => { e.Passphrase = "a"; }; FileOperationStatus status = FileOperationStatus.Unknown; controller.Completed += (object sender, FileOperationEventArgs e) => { status = e.Status; }; using (ThreadWorker worker = new ThreadWorker(new ProgressContext())) { controller.DecryptAndLaunch(_helloWorldAxxPath, worker); worker.Join(); } Assert.That(status, Is.EqualTo(FileOperationStatus.Success), "The status should indicate success."); Assert.That(launcher, Is.Not.Null, "There should be a call to launch."); Assert.That(Path.GetFileName(launcher.Path), Is.EqualTo("HelloWorld-Key-a.txt"), "The file should be decrypted and the name should be the original from the encrypted headers."); IRuntimeFileInfo destinationInfo = OS.Current.FileInfo(launcher.Path); Assert.That(destinationInfo.Exists, "After decryption the destination file should be created."); string fileContent; using (Stream stream = destinationInfo.OpenRead()) { fileContent = new StreamReader(stream).ReadToEnd(); } Assert.That(fileContent.Contains("Hello"), "A file named Hello World should contain that text when decrypted."); }
public static void TestSimpleOpenAndLaunch() { IEnumerable<AesKey> keys = new AesKey[] { new Passphrase("a").DerivedPassphrase }; FakeLauncher launcher = null; SetupAssembly.FakeRuntimeEnvironment.Launcher = ((string path) => { launcher = new FakeLauncher(path); return launcher; }); FileOperationStatus status = _fileSystemState.OpenAndLaunchApplication(_helloWorldAxxPath, keys, new ProgressContext()); Assert.That(status, Is.EqualTo(FileOperationStatus.Success), "The launch should succeed."); Assert.That(launcher, Is.Not.Null, "There should be a call to launch."); Assert.That(Path.GetFileName(launcher.Path), Is.EqualTo("HelloWorld-Key-a.txt"), "The file should be decrypted and the name should be the original from the encrypted headers."); }
public static void TestExitEvent() { IEnumerable<AesKey> keys = new AesKey[] { new Passphrase("a").DerivedPassphrase }; FakeLauncher launcher = null; SetupAssembly.FakeRuntimeEnvironment.Launcher = ((string path) => { launcher = new FakeLauncher(path); launcher.WasStarted = true; return launcher; }); FileOperationStatus status = _fileSystemState.OpenAndLaunchApplication(_helloWorldAxxPath, keys, new ProgressContext()); Assert.That(status, Is.EqualTo(FileOperationStatus.Success), "The launch should succeed."); Assert.That(launcher, Is.Not.Null, "There should be a call to launch to try launching."); Assert.That(Path.GetFileName(launcher.Path), Is.EqualTo("HelloWorld-Key-a.txt"), "The file should be decrypted and the name should be the original from the encrypted headers."); bool changedWasRaised = false; OS.Current.WorkFolderStateChanged += (object sender, EventArgs e) => { changedWasRaised = true; }; Assert.That(changedWasRaised, Is.False, "The global changed event should not have been raised yet."); launcher.RaiseExited(); Assert.That(changedWasRaised, Is.True, "The global changed event should be raised when the process exits."); }
public static void TestInvalidArguments() { IRuntimeFileInfo nullFileInfo = null; ILauncher nullProcess = null; IRuntimeFileInfo decryptedFileInfo = OS.Current.FileInfo(_testTextPath); IRuntimeFileInfo encryptedFileInfo = OS.Current.FileInfo(_helloWorldAxxPath); AesKey key = new AesKey(); AesKey nullKey = null; ILauncher process = new FakeLauncher(String.Empty); ActiveFile nullActiveFile = null; ActiveFile originalActiveFile = new ActiveFile(decryptedFileInfo, decryptedFileInfo, key, ActiveFileStatus.None, process); Assert.Throws<ArgumentNullException>(() => { if (new ActiveFile(nullActiveFile, key) == null) { } }); Assert.Throws<ArgumentNullException>(() => { if (new ActiveFile(originalActiveFile, nullKey) == null) { } }); Assert.Throws<ArgumentNullException>(() => { if (new ActiveFile(nullActiveFile, ActiveFileStatus.None, nullProcess) == null) { } }); Assert.Throws<ArgumentNullException>(() => { if (new ActiveFile(nullActiveFile, ActiveFileStatus.None) == null) { } }); Assert.Throws<ArgumentNullException>(() => { if (new ActiveFile(nullActiveFile, DateTime.MinValue, ActiveFileStatus.None) == null) { } }); Assert.Throws<ArgumentNullException>(() => { if (new ActiveFile(nullFileInfo, decryptedFileInfo, new AesKey(), ActiveFileStatus.None, nullProcess) == null) { } }); Assert.Throws<ArgumentNullException>(() => { if (new ActiveFile(encryptedFileInfo, nullFileInfo, new AesKey(), ActiveFileStatus.None, nullProcess) == null) { } }); Assert.Throws<ArgumentNullException>(() => { if (new ActiveFile(encryptedFileInfo, decryptedFileInfo, nullKey, ActiveFileStatus.None, nullProcess) == null) { } }); }
public static void TestOpenAndLaunchOfAxCryptDocumentWhenAlreadyDecrypted() { TestOpenAndLaunchOfAxCryptDocument(); FakeLauncher launcher = null; SetupAssembly.FakeRuntimeEnvironment.Launcher = ((string path) => { launcher = new FakeLauncher(path); return launcher; }); FileOperationStatus status; using (AxCryptDocument document = new AxCryptDocument()) { using (Stream stream = OS.Current.FileInfo(_helloWorldAxxPath).OpenRead()) { document.Load(stream, new Passphrase("a").DerivedPassphrase); status = _fileSystemState.OpenAndLaunchApplication(_helloWorldAxxPath, document, new ProgressContext()); } } Assert.That(status, Is.EqualTo(FileOperationStatus.Success), "The launch should succeed."); Assert.That(launcher, Is.Not.Null, "There should be a call to launch."); Assert.That(Path.GetFileName(launcher.Path), Is.EqualTo("HelloWorld-Key-a.txt"), "The file should be decrypted and the name should be the original from the encrypted headers."); }