public EditViewFileViewModel(FileEntrySecret current, byte[] derivedPassword, int zeroBasedIndexNumber, List <string> keyIds, Action positiveAction, Action negativeAction, Action <int /* zeroBasedIndexNumber */, bool /* isNowSecure */, bool /* Was Security Modified */, string /* Key identifier */> edit) { this.KeyIdentifiers = new ObservableCollection <string>(); foreach (string keyIdentifier in keyIds) { this.KeyIdentifiers.Add(keyIdentifier); } if (keyIds.Count > 0) { this.SelectedKeyIdentifier = keyIds[0]; } this.onPositiveClose = positiveAction; this.onNegativeClose = negativeAction; this.editFile = edit; this.currentFileEntrySecret = current; this.derivedPassword = derivedPassword; this.zeroBasedIndexNumber = zeroBasedIndexNumber; this.wasOriginallySecret = true; this.IsSecret = true; this.Filename = currentFileEntrySecret.GetFilename(this.derivedPassword); }
public void DeepCopyTest() { // Arrange byte[] derivedKey = new byte[16] { 111, 222, 31, 4, 5, 6, 1, 82, 93, 102, 112, 120, 103, 104, 15, 16 }; byte[] initialCounter = new byte[] { 0xf0, 0xf1, 0xfb, 0x13, 0xaa, 0xf5, 0x36, 0xbb, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff }; SettingsAES_CTR settingsAES_CTR = new SettingsAES_CTR(initialCounter); SymmetricKeyAlgorithm skaAES_CTR = new SymmetricKeyAlgorithm(SymmetricEncryptionAlgorithm.AES_CTR, 128, settingsAES_CTR); string filename = "nic2e.pdf"; byte[] fileContent = new byte[] { 1, 2, 3, 1, 2, byte.MaxValue, 0, 0, 0, 0, 0, 0, 23, 34, 33, 22, 222, 111 }; FileEntry fe = new FileEntry(filename, fileContent); FileEntrySecret fes = new FileEntrySecret(fe, "does not matter", skaAES_CTR, derivedKey); // Act FileEntrySecret fesCopy = new FileEntrySecret(fes); string filenameInCopy = fesCopy.GetFilename(derivedKey); // Assert Assert.IsFalse(string.IsNullOrEmpty(filenameInCopy)); Assert.AreEqual(filename, filenameInCopy); Assert.AreNotSame(fes.audalfData, fesCopy.audalfData, "AUDALF byte arrays should be in different memory locations"); CollectionAssert.AreEqual(fes.keyIdentifier, fesCopy.keyIdentifier); Assert.AreNotSame(fes.keyIdentifier, fesCopy.keyIdentifier, "Key identifier byte arrays should be in different memory locations"); Assert.AreEqual(fes.checksum, fesCopy.checksum); }
public void GetFilenameTest() { // Arrange byte[] derivedKey = new byte[16] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; byte[] initialCounter = new byte[] { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff }; SettingsAES_CTR settingsAES_CTR = new SettingsAES_CTR(initialCounter); SymmetricKeyAlgorithm skaAES_CTR = new SymmetricKeyAlgorithm(SymmetricEncryptionAlgorithm.AES_CTR, 128, settingsAES_CTR); string filename = "nice.pdf"; byte[] fileContent = new byte[] { 1, 2, 3, 1, 2, byte.MaxValue, 0, 0, 0, 0, 0, 0 }; FileEntry fe = new FileEntry(filename, fileContent); FileEntrySecret fes = new FileEntrySecret(fe, "does not matter", skaAES_CTR, derivedKey); // Act string rtFilename = fes.GetFilename(derivedKey); // Assert Assert.AreEqual(filename, rtFilename); }
public void SetFilenameTest() { // Arrange byte[] derivedKey = new byte[16] { 111, 222, 31, 4, 5, 6, 7, 8, 98, 10, 11, 12, 131, 104, 15, 16 }; SymmetricKeyAlgorithm ska = SymmetricKeyAlgorithm.GenerateNew(SymmetricEncryptionAlgorithm.AES_CTR); string filename = "backup.zip"; byte[] fileContent = Encoding.UTF8.GetBytes("peace, happiness, freedom and something..."); FileEntry fileEntry = new FileEntry(filename, fileContent); FileEntrySecret fes = new FileEntrySecret(fileEntry, "does not matter", ska, derivedKey); string filename1 = "another_backup.zip"; // Act bool shouldBeTrue = fes.SetFilename(filename1, derivedKey); string filename2 = fes.GetFilename(derivedKey); bool shouldBeFalse = fes.SetFilename(filename1, new byte[] { 1, 2, 3 }); // Assert Assert.IsTrue(shouldBeTrue); Assert.IsFalse(shouldBeFalse); Assert.IsFalse(string.IsNullOrEmpty(filename2)); Assert.AreEqual(filename1, filename2); }
private void EditFileInCollection(int zeroBasedIndexNumber, bool isNowSecure, bool wasSecurityModified, string keyIdentifier) { if (wasSecurityModified) { // If file jumps from secure <-> unsecure if (isNowSecure) { this.csc.AddFileEntrySecret(this.derivedPasswords[keyIdentifier], this.csc.files[zeroBasedIndexNumber], keyIdentifier); this.csc.files.RemoveAt(zeroBasedIndexNumber); } else { FileEntrySecret fes = this.csc.fileSecrets[zeroBasedIndexNumber]; byte[] derivedPassword = derivedPasswords[fes.GetKeyIdentifier()]; FileEntry tempFileEntry = new FileEntry(fes.GetFilename(derivedPassword), fes.GetFileContent(derivedPassword)); this.csc.fileSecrets.RemoveAt(zeroBasedIndexNumber); this.csc.files.Add(tempFileEntry); } } else { if (isNowSecure) { // TODO: support key change } } // Editing a file modifies the structure this.isModified = true; this.UpdateMainTitle(this.filePath != null ? this.filePath : untitledTempName); this.GenerateFileSimplifiedsFromCommonSecrets(); }