private static LogOnIdentity FindKnownKeyOrEmpty(ActiveFile activeFile) { foreach (LogOnIdentity key in Resolve.KnownIdentities.Identities) { if (activeFile.ThumbprintMatch(key.Passphrase)) { return(key); } } return(LogOnIdentity.Empty); }
private static ActiveFile CheckIfKeyIsKnown(FileSystemState fileSystemState, ActiveFile activeFile) { if ((activeFile.Status & (ActiveFileStatus.AssumedOpenAndDecrypted | ActiveFileStatus.DecryptedIsPendingDelete | ActiveFileStatus.NotDecrypted)) == 0) { return(activeFile); } if (activeFile.Key != null) { return(activeFile); } foreach (AesKey key in fileSystemState.KnownKeys.Keys) { if (activeFile.ThumbprintMatch(key)) { activeFile = new ActiveFile(activeFile, key); } return(activeFile); } return(activeFile); }
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 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."); } } }
private static ActiveFile CheckIfKeyIsKnown(FileSystemState fileSystemState, ActiveFile activeFile) { if ((activeFile.Status & (ActiveFileStatus.AssumedOpenAndDecrypted | ActiveFileStatus.DecryptedIsPendingDelete | ActiveFileStatus.NotDecrypted)) == 0) { return activeFile; } if (activeFile.Key != null) { return activeFile; } foreach (AesKey key in fileSystemState.KnownKeys.Keys) { if (activeFile.ThumbprintMatch(key)) { activeFile = new ActiveFile(activeFile, key); } return activeFile; } return activeFile; }