示例#1
0
        public void GetKeyIdentifierTest()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                111, 222, 31, 47, 75, 168, 78, 83, 91, 110, 221, 18, 213, 104, 15, 16
            };
            byte[] initialCounter = new byte[] { 0xa0, 0xb1, 0xcb, 0xcd, 0xaa, 0xc5, 0xd3, 0xb5, 0x58, 0x59, 0x15, 0x2b, 0x33, 0xfd, 0xfe, 0xff };

            SettingsAES_CTR settingsAES_CTR = new SettingsAES_CTR(initialCounter);

            SymmetricKeyAlgorithm skaAES_CTR = new SymmetricKeyAlgorithm(SymmetricEncryptionAlgorithm.AES_CTR, 256, settingsAES_CTR);

            string keyIdentifier = "primary";

            string title = "Wishlist for holidays, eh";
            string text  = "peace, happiness, freedom, faster";

            Note note = new Note(title, text);

            // Act
            NoteSecret noteSecret = new NoteSecret(note, keyIdentifier, skaAES_CTR, derivedKey);

            // Assert
            Assert.AreEqual(keyIdentifier, noteSecret.GetKeyIdentifier());
        }
        public void CanBeDecryptedWithDerivedPassword()
        {
            byte[] derivedKey1 = new byte[16] {
                111, 222, 36, 47, 75, 168, 78, 13, 61, 118, 221, 18, 213, 104, 15, 16
            };
            byte[] derivedKey2 = new byte[16] {
                111, 222, 36, 47, 75, 168, 78, 13, 61, 118, 221, 18, 213, 104, 15, 15
            };
            byte[] initialCounter = new byte[] { 0xa7, 0xb1, 0xcb, 0xcd, 0xaa, 0xc5, 0xd3, 0xb5, 0x58, 0x51, 0x95, 0x2b, 0x33, 0xfd, 0xfe, 0xff };

            SettingsAES_CTR settingsAES_CTR = new SettingsAES_CTR(initialCounter);

            SymmetricKeyAlgorithm skaAES_CTR = new SymmetricKeyAlgorithm(SymmetricEncryptionAlgorithm.AES_CTR, 256, settingsAES_CTR);

            string keyIdentifier = "primary";

            string filename = "nice.pdf";

            byte[] fileContent = new byte[] { 1, 2, 3, 100, 222, 1, 2, byte.MaxValue, 0, 0, 0, 0, 0, 0 };

            FileEntry fe = new FileEntry(filename, fileContent);

            // Act
            FileEntrySecret fes = new FileEntrySecret(fe, keyIdentifier, skaAES_CTR, derivedKey1);

            // Assert
            Assert.IsTrue(fes.CanBeDecryptedWithDerivedPassword(derivedKey1));
            Assert.IsFalse(fes.CanBeDecryptedWithDerivedPassword(null));
            Assert.IsFalse(fes.CanBeDecryptedWithDerivedPassword(new byte[] {}));
            Assert.IsFalse(fes.CanBeDecryptedWithDerivedPassword(derivedKey2));
        }
        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 GetFileContentLengthInBytes()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 255
            };
            byte[] initialCounter = new byte[] { 0x40, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0x38, 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 = "nice232fwf.pdf";

            byte[] fileContent = new byte[] { 1, 2, 3, 1, 2, byte.MaxValue, 0, 0, 0, 0, 0, 0, 4, 5, 6, 7, 8, 9, 33, 44, 55, 66, 77 };

            FileEntry fe = new FileEntry(filename, fileContent);

            FileEntrySecret fes = new FileEntrySecret(fe, "does not matter", skaAES_CTR, derivedKey);

            // Act
            long fileContentLength = fes.GetFileContentLengthInBytes(derivedKey);

            // Assert
            Assert.AreEqual(fileContent.LongLength, fileContentLength);
        }
        public void GetModificationTimeTest()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 255
            };
            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
            DateTimeOffset fileEntryModificationTime1 = fes.GetModificationTime(derivedKey);

            Thread.Sleep(1100);
            fes.SetFilename("much_nicer.pdf", derivedKey);
            DateTimeOffset fileEntryModificationTime2 = fes.GetModificationTime(derivedKey);

            // Assert
            Assert.Greater(fileEntryModificationTime2, fileEntryModificationTime1);
        }
示例#6
0
        public void CanBeDecryptedWithDerivedPassword()
        {
            byte[] derivedKey1 = new byte[16] {
                11, 222, 31, 47, 75, 168, 78, 13, 61, 118, 221, 18, 213, 104, 15, 16
            };
            byte[] derivedKey2 = new byte[16] {
                11, 222, 31, 47, 75, 168, 78, 13, 61, 118, 221, 18, 213, 104, 15, 15
            };
            byte[] initialCounter = new byte[] { 0xa7, 0xb1, 0xcb, 0xcd, 0xaa, 0xc5, 0xd3, 0xb5, 0x58, 0x51, 0x95, 0x2b, 0x33, 0xfd, 0xfe, 0xff };

            SettingsAES_CTR settingsAES_CTR = new SettingsAES_CTR(initialCounter);

            SymmetricKeyAlgorithm skaAES_CTR = new SymmetricKeyAlgorithm(SymmetricEncryptionAlgorithm.AES_CTR, 256, settingsAES_CTR);

            string keyIdentifier = "primary";

            PaymentCard paymentCard = new PaymentCard("Bank of  Dragon", "Cool Dragon", "Debit", "0000000000001234", "111", "11/20", "05/33", "Super cool card I have here");

            // Act
            PaymentCardSecret paymentCardSecret = new PaymentCardSecret(paymentCard, keyIdentifier, skaAES_CTR, derivedKey1);

            // Assert
            Assert.IsTrue(paymentCardSecret.CanBeDecryptedWithDerivedPassword(derivedKey1));
            Assert.IsFalse(paymentCardSecret.CanBeDecryptedWithDerivedPassword(null));
            Assert.IsFalse(paymentCardSecret.CanBeDecryptedWithDerivedPassword(new byte[] {}));
            Assert.IsFalse(paymentCardSecret.CanBeDecryptedWithDerivedPassword(derivedKey2));
        }
示例#7
0
        public void ChecksumSurvivesRoundtrip()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                15, 200, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 104, 15, 16
            };
            byte[] initialCounter = new byte[] { 0xf0, 0xf1, 0xfb, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xf3, 0xff };

            SettingsAES_CTR settingsAES_CTR = new SettingsAES_CTR(initialCounter);

            SymmetricKeyAlgorithm skaAES_CTR = new SymmetricKeyAlgorithm(SymmetricEncryptionAlgorithm.AES_CTR, 128, settingsAES_CTR);

            PaymentCard paymentCard = new PaymentCard("Bank of  Dragon", "Cool Dragon", "Debit", "0000000000001234", "111", "11/20", "05/33", "Super cool card I have here");

            PaymentCardSecret paymentCardSecret = new PaymentCardSecret(paymentCard, "does not matter", skaAES_CTR, derivedKey);

            // Act
            string checksum1 = paymentCardSecret.GetChecksumAsHex();

            string json = JsonConvert.SerializeObject(paymentCardSecret, Formatting.Indented);

            PaymentCardSecret paymentCardSecret2 = JsonConvert.DeserializeObject <PaymentCardSecret>(json);

            // Assert
            Assert.AreEqual(64, checksum1.Length);
            Assert.AreEqual(checksum1, paymentCardSecret2.GetChecksumAsHex());
        }
        public void GetLoginInformationNotesTest()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                111, 222, 31, 4, 5, 68, 78, 83, 9, 110, 211, 128, 213, 104, 15, 16
            };
            byte[] initialCounter = new byte[] { 0xf0, 0xf1, 0xfb, 0xf3, 0xaa, 0xc5, 0xd6, 0xbb, 0xf8, 0x19, 0x11, 0xfb, 0x33, 0xfd, 0xfe, 0xff };

            SettingsAES_CTR settingsAES_CTR = new SettingsAES_CTR(initialCounter);

            SymmetricKeyAlgorithm skaAES_CTR = new SymmetricKeyAlgorithm(SymmetricEncryptionAlgorithm.AES_CTR, 128, settingsAES_CTR);

            LoginInformation loginInformationModified = loginInformation.ShallowCopy();

            loginInformationModified.UpdateNotes("Nice story about how I found the missing tapes of ...");

            LoginInformationSecret loginInformationSecret = new LoginInformationSecret(loginInformationModified, "does not matter", skaAES_CTR, derivedKey);

            // Act
            string loginInformationNotes = loginInformationSecret.GetNotes(derivedKey);

            // Assert
            Assert.IsFalse(string.IsNullOrEmpty(loginInformationNotes));
            Assert.AreEqual(loginInformationModified.notes, loginInformationNotes);
        }
        public void GetLoginInformatioMFATest()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                111, 222, 231, 42, 5, 68, 78, 83, 9, 110, 211, 128, 213, 104, 15, 16
            };
            byte[] initialCounter = new byte[] { 0xf0, 0xf1, 0xfc, 0xf3, 0xaa, 0xc5, 0xd6, 0xbb, 0xf8, 0x19, 0x11, 0xfb, 0x33, 0xfd, 0xfe, 0xff };

            SettingsAES_CTR settingsAES_CTR = new SettingsAES_CTR(initialCounter);

            SymmetricKeyAlgorithm skaAES_CTR = new SymmetricKeyAlgorithm(SymmetricEncryptionAlgorithm.AES_CTR, 128, settingsAES_CTR);

            LoginInformation loginInformationModified = loginInformation.ShallowCopy();

            loginInformationModified.UpdateMFA("otpauth://totp/DRAGONFIER?secret=YOUR_DRAGON");

            LoginInformationSecret loginInformationSecret = new LoginInformationSecret(loginInformationModified, "does not matter", skaAES_CTR, derivedKey);

            // Act
            string loginInformationMFA = loginInformationSecret.GetMFA(derivedKey);

            // Assert
            Assert.IsFalse(string.IsNullOrEmpty(loginInformationMFA));
            Assert.AreEqual(loginInformationModified.mfa, loginInformationMFA);
        }
示例#10
0
        public void GetNoteTest()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 104, 15, 16
            };
            byte[] initialCounter = new byte[] { 0xf0, 0xf1, 0xfb, 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 title = "Wishlist for holidays";
            string text  = "peace, happiness, freedom";

            Note note = new Note(title, text);

            NoteSecret noteSecret = new NoteSecret(note, "does not matter", skaAES_CTR, derivedKey);

            // Act
            Note noteCopy = noteSecret.GetNote(derivedKey);

            // Assert
            Assert.IsTrue(ComparisonHelper.AreNotesEqual(note, noteCopy));
            Assert.AreEqual(note.creationTime, noteCopy.creationTime);
            Assert.AreEqual(note.modificationTime, noteCopy.modificationTime);
        }
        public void ConstructorTest()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                127, 1, 250, 4, 5, 6, 7, 13, 7, 10, 11, 12, 13, 14, 15, 16
            };
            byte[] initialCounter = new byte[] { 0x10, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf1, 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);

            Dictionary <string, object> testDictionary = new Dictionary <string, object>()
            {
                { LoginInformation.titleKey, "Shopping site" }
            };

            LoginInformationSecret loginInformationSecret = new LoginInformationSecret(testDictionary, "does not matter", skaAES_CTR, derivedKey);

            // Act

            // Assert
            Assert.IsNotNull(loginInformationSecret);
            Assert.IsNotNull(loginInformationSecret.audalfData);
        }
示例#12
0
        public void DeepCopyTest()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                111, 222, 31, 4, 5, 6, 1, 82, 93, 102, 11, 12, 13, 104, 15, 16
            };
            byte[] initialCounter = new byte[] { 0xf0, 0xf1, 0xfb, 0xf3, 0xaa, 0xf5, 0xf6, 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 title = "Wishlist for holidays";
            string text  = "peace, happiness, freedom and something";

            Note note = new Note(title, text);

            NoteSecret noteSecret = new NoteSecret(note, "does not matter", skaAES_CTR, derivedKey);

            // Act
            NoteSecret noteSecretCopy = new NoteSecret(noteSecret);
            string     noteTitle      = noteSecretCopy.GetNoteTitle(derivedKey);

            // Assert
            Assert.IsFalse(string.IsNullOrEmpty(noteTitle));
            Assert.AreEqual(title, noteTitle);
            Assert.AreNotSame(noteSecret.audalfData, noteSecretCopy.audalfData, "AUDALF byte arrays should be in different memory locations");
            CollectionAssert.AreEqual(noteSecret.keyIdentifier, noteSecretCopy.keyIdentifier);
            Assert.AreNotSame(noteSecret.keyIdentifier, noteSecretCopy.keyIdentifier, "Key identifier byte arrays should be in different memory locations");
            Assert.AreEqual(noteSecret.checksum, noteSecretCopy.checksum);
        }
示例#13
0
        public void ChecksumSurvivesRoundtrip()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                15, 200, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 104, 15, 16
            };
            byte[] initialCounter = new byte[] { 0xf0, 0xf1, 0xfb, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xf3, 0xff };

            SettingsAES_CTR settingsAES_CTR = new SettingsAES_CTR(initialCounter);

            SymmetricKeyAlgorithm skaAES_CTR = new SymmetricKeyAlgorithm(SymmetricEncryptionAlgorithm.AES_CTR, 128, settingsAES_CTR);

            string title = "Wishlist for holidays";
            string text  = "peace, happiness, freedom";

            Note note = new Note(title, text);

            NoteSecret noteSecret1 = new NoteSecret(note, "does not matter", skaAES_CTR, derivedKey);

            // Act
            string checksum1 = noteSecret1.GetChecksumAsHex();

            string json = JsonConvert.SerializeObject(noteSecret1, Formatting.Indented);

            NoteSecret noteSecret2 = JsonConvert.DeserializeObject <NoteSecret>(json);

            // Assert
            Assert.AreEqual(64, checksum1.Length);
            Assert.AreEqual(checksum1, noteSecret2.GetChecksumAsHex());
        }
示例#14
0
        public void CanBeDecryptedWithDerivedPassword()
        {
            byte[] derivedKey1 = new byte[16] {
                11, 222, 31, 47, 75, 168, 78, 13, 61, 118, 221, 18, 213, 104, 15, 16
            };
            byte[] derivedKey2 = new byte[16] {
                11, 222, 31, 47, 75, 168, 78, 13, 61, 118, 221, 18, 213, 104, 15, 15
            };
            byte[] initialCounter = new byte[] { 0xa7, 0xb1, 0xcb, 0xcd, 0xaa, 0xc5, 0xd3, 0xb5, 0x58, 0x51, 0x95, 0x2b, 0x33, 0xfd, 0xfe, 0xff };

            SettingsAES_CTR settingsAES_CTR = new SettingsAES_CTR(initialCounter);

            SymmetricKeyAlgorithm skaAES_CTR = new SymmetricKeyAlgorithm(SymmetricEncryptionAlgorithm.AES_CTR, 256, settingsAES_CTR);

            string keyIdentifier = "primary";

            string title = "Wishlist for holidays, eh";
            string text  = "peace, happiness, freedom, faster";

            Note note = new Note(title, text);

            // Act
            NoteSecret noteSecret = new NoteSecret(note, keyIdentifier, skaAES_CTR, derivedKey1);

            // Assert
            Assert.IsTrue(noteSecret.CanBeDecryptedWithDerivedPassword(derivedKey1));
            Assert.IsFalse(noteSecret.CanBeDecryptedWithDerivedPassword(null));
            Assert.IsFalse(noteSecret.CanBeDecryptedWithDerivedPassword(new byte[] {}));
            Assert.IsFalse(noteSecret.CanBeDecryptedWithDerivedPassword(derivedKey2));
        }
示例#15
0
        public void ConstructorTest()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                1, 1, 1, 4, 5, 6, 7, 6, 7, 10, 11, 12, 13, 4, 15, 16
            };
            byte[] initialCounter = new byte[] { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf1, 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);

            Dictionary <string, object> testDictionary = new Dictionary <string, object>()
            {
                { PaymentCard.titleKey, "Super cool card" }
            };

            PaymentCardSecret paymentCardSecret = new PaymentCardSecret(testDictionary, "does not matter", skaAES_CTR, derivedKey);

            // Act

            // Assert
            Assert.IsNotNull(paymentCardSecret);
            Assert.IsNotNull(paymentCardSecret.audalfData);
        }
        public void GetModificationTimeTest()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                111, 222, 31, 4, 5, 68, 78, 83, 9, 110, 211, 128, 213, 104, 15, 16
            };
            byte[] initialCounter = new byte[] { 0xf0, 0xf1, 0xfb, 0xf3, 0xaa, 0xc5, 0xd6, 0xbb, 0xf8, 0x19, 0x11, 0xfb, 0x33, 0xfd, 0xfe, 0xff };

            SettingsAES_CTR settingsAES_CTR = new SettingsAES_CTR(initialCounter);

            SymmetricKeyAlgorithm skaAES_CTR = new SymmetricKeyAlgorithm(SymmetricEncryptionAlgorithm.AES_CTR, 128, settingsAES_CTR);

            LoginInformation loginInformationModified = loginInformation.ShallowCopy();

            Thread.Sleep(1100);
            loginInformationModified.UpdateNotes("Some text to here so modification time triggers");

            LoginInformationSecret loginInformationSecret = new LoginInformationSecret(loginInformationModified, "does not matter", skaAES_CTR, derivedKey);

            // Act
            DateTimeOffset loginInformationModificationTime = loginInformationSecret.GetModificationTime(derivedKey);

            // Assert
            Assert.IsTrue(loginInformationModified.modificationTime > loginInformationModified.creationTime);
            Assert.AreEqual(loginInformationModified.GetModificationTime(), loginInformationModificationTime);
        }
示例#17
0
        public void GetModificationTimeTest()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                15, 200, 3, 4, 15, 6, 7, 8, 9, 10, 11, 112, 139, 104, 15, 16
            };
            byte[] initialCounter = new byte[] { 0xf0, 0xf1, 0xfb, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xf3, 0xff };

            SettingsAES_CTR settingsAES_CTR = new SettingsAES_CTR(initialCounter);

            SymmetricKeyAlgorithm skaAES_CTR = new SymmetricKeyAlgorithm(SymmetricEncryptionAlgorithm.AES_CTR, 128, settingsAES_CTR);

            PaymentCard paymentCard = new PaymentCard("Bank of  Dragon", "Cool Dragon", "Debit", "0000000000001234", "111", "11/20", "05/33", "Super cool card I have here");

            PaymentCardSecret paymentCardSecret = new PaymentCardSecret(paymentCard, "does not matter", skaAES_CTR, derivedKey);

            // Act
            DateTimeOffset modificationTime1 = paymentCardSecret.GetModificationTime(derivedKey);

            Thread.Sleep(1100);
            paymentCardSecret.SetTitle("1234567", derivedKey);
            DateTimeOffset modificationTime2 = paymentCardSecret.GetModificationTime(derivedKey);

            // Assert
            Assert.Greater(modificationTime2, modificationTime1);
        }
        public void GetLoginInformationIconTest()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                181, 229, 31, 44, 55, 61, 7, 8, 9, 110, 211, 128, 213, 104, 15, 16
            };
            byte[] initialCounter = new byte[] { 0x10, 0x21, 0x3b, 0xf3, 0xaa, 0xc5, 0xd6, 0xbb, 0xf8, 0x19, 0x11, 0xfb, 0x33, 0xfd, 0xfe, 0xff };

            SettingsAES_CTR settingsAES_CTR = new SettingsAES_CTR(initialCounter);

            SymmetricKeyAlgorithm skaAES_CTR = new SymmetricKeyAlgorithm(SymmetricEncryptionAlgorithm.AES_CTR, 128, settingsAES_CTR);

            Random rng = new Random(Seed: 1337);

            byte[] iconBytes = new byte[2048];
            rng.NextBytes(iconBytes);

            LoginInformation loginInformationModified = loginInformation.ShallowCopy();

            loginInformationModified.UpdateIcon(iconBytes);

            LoginInformationSecret loginInformationSecret = new LoginInformationSecret(loginInformationModified, "does not matter", skaAES_CTR, derivedKey);

            // Act
            byte[] loginInformationIcon = loginInformationSecret.GetIcon(derivedKey);

            // Assert
            Assert.IsNotNull(loginInformationIcon);
            CollectionAssert.AreEqual(iconBytes, loginInformationIcon);
        }
示例#19
0
        public void DeepCopyTest()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                111, 222, 31, 4, 5, 6, 1, 82, 93, 102, 11, 12, 13, 104, 15, 16
            };
            byte[] initialCounter = new byte[] { 0xf0, 0xf1, 0xfb, 0xf3, 0xaa, 0xf5, 0xf6, 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      title       = "Bank of  Dragon";
            PaymentCard paymentCard = new PaymentCard(title, "Cool Dragon", "Debit", "0000000000001234", "111", "11/20", "05/33", "Super cool card I have here");

            PaymentCardSecret paymentCardSecret = new PaymentCardSecret(paymentCard, "does not matter", skaAES_CTR, derivedKey);

            // Act
            PaymentCardSecret paymentCardSecretCopy = new PaymentCardSecret(paymentCardSecret);
            string            paymentCardTitle      = paymentCardSecretCopy.GetTitle(derivedKey);

            // Assert
            Assert.IsFalse(string.IsNullOrEmpty(paymentCardTitle));
            Assert.AreEqual(title, paymentCardTitle);
            Assert.AreNotSame(paymentCardSecret.audalfData, paymentCardSecretCopy.audalfData, "AUDALF byte arrays should be in different memory locations");
            CollectionAssert.AreEqual(paymentCardSecret.keyIdentifier, paymentCardSecretCopy.keyIdentifier);
            Assert.AreNotSame(paymentCardSecret.keyIdentifier, paymentCardSecretCopy.keyIdentifier, "Key identifier byte arrays should be in different memory locations");
            Assert.AreEqual(paymentCardSecret.checksum, paymentCardSecretCopy.checksum);
        }
        public void GetLoginInformationCategoryTest()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                111, 222, 31, 4, 5, 68, 78, 83, 91, 10, 21, 18, 213, 104, 15, 16
            };
            byte[] initialCounter = new byte[] { 0xf0, 0xf1, 0xfb, 0xf3, 0xaa, 0xc5, 0xd5, 0xb5, 0x58, 0x59, 0x15, 0xfb, 0x33, 0xfd, 0xfe, 0xff };

            SettingsAES_CTR settingsAES_CTR = new SettingsAES_CTR(initialCounter);

            SymmetricKeyAlgorithm skaAES_CTR = new SymmetricKeyAlgorithm(SymmetricEncryptionAlgorithm.AES_CTR, 128, settingsAES_CTR);

            LoginInformation loginInformationModified = loginInformation.ShallowCopy();

            loginInformationModified.UpdateCategory("Shopping");

            LoginInformationSecret loginInformationSecret = new LoginInformationSecret(loginInformationModified, "does not matter", skaAES_CTR, derivedKey);

            // Act
            string loginInformationCategory = loginInformationSecret.GetCategory(derivedKey);

            // Assert
            Assert.IsFalse(string.IsNullOrEmpty(loginInformationCategory));
            Assert.AreEqual(loginInformationModified.category, loginInformationCategory);
        }
        public void GetFileContentTest()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 255
            };
            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
            byte[] rtFileContent = fes.GetFileContent(derivedKey);

            // Assert
            CollectionAssert.AreEqual(fileContent, rtFileContent);
        }
        public void GetLoginInformationTagsTest()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                111, 222, 31, 47, 75, 168, 78, 83, 91, 110, 221, 18, 213, 104, 15, 16
            };
            byte[] initialCounter = new byte[] { 0xa0, 0xb1, 0xcb, 0xfd, 0xaa, 0xc5, 0xd5, 0xb5, 0x58, 0x59, 0x15, 0xfb, 0x33, 0xfd, 0xfe, 0xff };

            SettingsAES_CTR settingsAES_CTR = new SettingsAES_CTR(initialCounter);

            SymmetricKeyAlgorithm skaAES_CTR = new SymmetricKeyAlgorithm(SymmetricEncryptionAlgorithm.AES_CTR, 256, settingsAES_CTR);

            LoginInformation loginInformationModified = loginInformation.ShallowCopy();

            loginInformationModified.UpdateTags("personal");

            LoginInformationSecret loginInformationSecret = new LoginInformationSecret(loginInformationModified, "does not matter", skaAES_CTR, derivedKey);

            // Act
            string loginInformationTags = loginInformationSecret.GetTags(derivedKey);

            // Assert
            Assert.IsFalse(string.IsNullOrEmpty(loginInformationTags));
            Assert.AreEqual(loginInformationModified.tags, loginInformationTags);
        }
        public void ConstructorTest()
        {
            // 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);

            Dictionary <string, object> testDictionary = new Dictionary <string, object>()
            {
                { FileEntry.filenameKey, "filename.txt" }
            };

            FileEntrySecret fes = new FileEntrySecret(testDictionary, "does not matter", skaAES_CTR, derivedKey);

            // Act

            // Assert
            Assert.IsNotNull(fes);
            Assert.IsNotNull(fes.audalfData);
        }
        public void CanBeDecryptedWithDerivedPassword()
        {
            byte[] derivedKey1 = new byte[16] {
                111, 222, 31, 47, 75, 168, 78, 13, 61, 118, 221, 18, 213, 104, 15, 16
            };
            byte[] derivedKey2 = new byte[16] {
                111, 222, 31, 47, 75, 168, 78, 13, 61, 118, 221, 18, 213, 104, 15, 15
            };
            byte[] initialCounter = new byte[] { 0xa7, 0xb1, 0xcb, 0xcd, 0xaa, 0xc5, 0xd3, 0xb5, 0x58, 0x51, 0x95, 0x2b, 0x33, 0xfd, 0xfe, 0xff };

            SettingsAES_CTR settingsAES_CTR = new SettingsAES_CTR(initialCounter);

            SymmetricKeyAlgorithm skaAES_CTR = new SymmetricKeyAlgorithm(SymmetricEncryptionAlgorithm.AES_CTR, 256, settingsAES_CTR);

            string keyIdentifier = "primary";

            // Act
            LoginInformationSecret loginInformationSecret = new LoginInformationSecret(loginInformation, keyIdentifier, skaAES_CTR, derivedKey1);

            // Assert
            Assert.IsTrue(loginInformationSecret.CanBeDecryptedWithDerivedPassword(derivedKey1));
            Assert.IsFalse(loginInformationSecret.CanBeDecryptedWithDerivedPassword(null));
            Assert.IsFalse(loginInformationSecret.CanBeDecryptedWithDerivedPassword(new byte[] {}));
            Assert.IsFalse(loginInformationSecret.CanBeDecryptedWithDerivedPassword(derivedKey2));
        }
        public void GetKeyIdentifierTest()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                111, 222, 31, 47, 25, 138, 78, 83, 111, 110, 221, 18, 213, 104, 15, 16
            };
            byte[] initialCounter = new byte[] { 0xa0, 0xb1, 0xcb, 0xcd, 0xaa, 0xc5, 0x13, 0xb5, 0x58, 0x59, 0x13, 0x2b, 0x33, 0xfd, 0xfe, 0xff };

            SettingsAES_CTR settingsAES_CTR = new SettingsAES_CTR(initialCounter);

            SymmetricKeyAlgorithm skaAES_CTR = new SymmetricKeyAlgorithm(SymmetricEncryptionAlgorithm.AES_CTR, 256, settingsAES_CTR);

            string keyIdentifier = "primary";

            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);

            // Act
            FileEntrySecret fes = new FileEntrySecret(fe, keyIdentifier, skaAES_CTR, derivedKey);

            // Assert
            Assert.AreEqual(keyIdentifier, fes.GetKeyIdentifier());
        }
        public void DeepCopyTest()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                111, 222, 31, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 104, 15, 16
            };
            byte[] initialCounter = new byte[] { 0xf0, 0xf1, 0xfb, 0xf3, 0xaa, 0xf5, 0xf6, 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);

            LoginInformationSecret loginInformationSecret = new LoginInformationSecret(loginInformation, "does not matter", skaAES_CTR, derivedKey);

            // Act
            LoginInformationSecret loginInformationSecretCopy = new LoginInformationSecret(loginInformationSecret);
            string loginInformationTitle = loginInformationSecretCopy.GetTitle(derivedKey);

            // Assert
            Assert.IsFalse(string.IsNullOrEmpty(loginInformationTitle));
            Assert.AreEqual(loginInformation.title, loginInformationTitle);
            Assert.AreNotSame(loginInformationSecret.audalfData, loginInformationSecretCopy.audalfData, "AUDALF byte arrays should be in different memory locations");
            CollectionAssert.AreEqual(loginInformationSecret.keyIdentifier, loginInformationSecretCopy.keyIdentifier);
            Assert.AreNotSame(loginInformationSecret.keyIdentifier, loginInformationSecretCopy.keyIdentifier, "Key identifier byte arrays should be in different memory locations");
            Assert.AreEqual(loginInformationSecret.checksum, loginInformationSecretCopy.checksum);
        }
        public void ChecksumSurvivesRoundtrip()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 255
            };
            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 fes1 = new FileEntrySecret(fe, "does not matter", skaAES_CTR, derivedKey);

            // Act
            string checksum1 = fes1.GetChecksumAsHex();

            string json = JsonConvert.SerializeObject(fes1, Formatting.Indented);

            FileEntrySecret fes2 = JsonConvert.DeserializeObject <FileEntrySecret>(json);

            // Assert
            Assert.AreEqual(64, checksum1.Length);
            Assert.AreEqual(checksum1, fes2.GetChecksumAsHex());
        }
        public void ChecksumSurvivesRoundtrip()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                111, 222, 31, 4, 5, 6, 7, 88, 9, 107, 11, 12, 13, 104, 15, 16
            };
            byte[] initialCounter = new byte[] { 0xf0, 0xf1, 0xfb, 0xf3, 0xaa, 0xf5, 0xf6, 0xcc, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff };

            SettingsAES_CTR settingsAES_CTR = new SettingsAES_CTR(initialCounter);

            SymmetricKeyAlgorithm skaAES_CTR = new SymmetricKeyAlgorithm(SymmetricEncryptionAlgorithm.AES_CTR, 192, settingsAES_CTR);

            LoginInformationSecret loginInformationSecret1 = new LoginInformationSecret(loginInformation, "does not matter", skaAES_CTR, derivedKey);

            // Act
            string checksum1 = loginInformationSecret1.GetChecksumAsHex();

            string json = JsonConvert.SerializeObject(loginInformationSecret1, Formatting.Indented);

            LoginInformationSecret loginInformationSecret2 = JsonConvert.DeserializeObject <LoginInformationSecret>(json);

            // Assert
            Assert.AreEqual(64, checksum1.Length);
            Assert.AreEqual(checksum1, loginInformationSecret2.GetChecksumAsHex());
        }
        public void GetFileEntryTest()
        {
            // 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 = "ni12ce.pdf";

            byte[] fileContent = new byte[] { 1, 2, 32, 11, 2, byte.MaxValue, 0, 0, 2, 34, 45, 0, 0, 0, 0 };

            FileEntry fe = new FileEntry(filename, fileContent);

            FileEntrySecret fes = new FileEntrySecret(fe, "does not matter", skaAES_CTR, derivedKey);

            // Act
            FileEntry feCopy = fes.GetFileEntry(derivedKey);

            // Assert
            Assert.IsTrue(ComparisonHelper.AreFileEntriesEqual(fe, feCopy));
            Assert.AreEqual(fe.creationTime, feCopy.creationTime);
            Assert.AreEqual(fe.modificationTime, feCopy.modificationTime);
        }
示例#30
0
        public void ConstructorTest()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                1, 1, 1, 4, 5, 6, 7, 7, 7, 10, 11, 12, 13, 14, 15, 16
            };
            byte[] initialCounter = new byte[] { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf1, 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);

            Dictionary <string, object> testDictionary = new Dictionary <string, object>()
            {
                { Note.noteTitleKey, "My shopping list for tomorrow" }
            };

            NoteSecret noteSecret = new NoteSecret(testDictionary, "does not matter", skaAES_CTR, derivedKey);

            // Act

            // Assert
            Assert.IsNotNull(noteSecret);
            Assert.IsNotNull(noteSecret.audalfData);
        }