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);
        }
        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);
        }
        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 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 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 SetLoginInformationUsernameTest()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                111, 222, 31, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 104, 15, 16
            };

            SymmetricKeyAlgorithm ska = SymmetricKeyAlgorithm.GenerateNew(SymmetricEncryptionAlgorithm.AES_CTR);

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

            string newUsername = "******";

            // Act
            string loginInformationUsername1 = loginInformationSecret.GetUsername(derivedKey);
            bool   shouldBeTrue = loginInformationSecret.SetUsername(newUsername, derivedKey);
            string loginInformationUsername2 = loginInformationSecret.GetUsername(derivedKey);
            bool   shouldBeFalse             = loginInformationSecret.SetUsername(newUsername, new byte[] { 1, 2, 3 });

            // Assert
            Assert.IsTrue(shouldBeTrue);
            Assert.IsFalse(shouldBeFalse);
            Assert.IsFalse(string.IsNullOrEmpty(loginInformationUsername1));
            Assert.IsFalse(string.IsNullOrEmpty(loginInformationUsername2));
            Assert.AreEqual(loginInformation.username, loginInformationUsername1);
            Assert.AreEqual(newUsername, loginInformationUsername2);
        }
        public void SetLoginInformationPasswordTest()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                111, 222, 31, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 104, 15, 16
            };

            SymmetricKeyAlgorithm ska = SymmetricKeyAlgorithm.GenerateNew(SymmetricEncryptionAlgorithm.AES_CTR);

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

            string newPassword = "******";

            // Act
            string loginInformationPassword1 = loginInformationSecret.GetPassword(derivedKey);
            bool   shouldBeTrue = loginInformationSecret.SetPassword(newPassword, derivedKey);
            string loginInformationPassword2 = loginInformationSecret.GetPassword(derivedKey);
            bool   shouldBeFalse             = loginInformationSecret.SetPassword(newPassword, new byte[] { 1, 2, 3 });

            // Assert
            Assert.IsTrue(shouldBeTrue);
            Assert.IsFalse(shouldBeFalse);
            Assert.IsFalse(string.IsNullOrEmpty(loginInformationPassword1));
            Assert.IsFalse(string.IsNullOrEmpty(loginInformationPassword2));
            Assert.AreEqual(loginInformation.password, loginInformationPassword1);
            Assert.AreEqual(newPassword, loginInformationPassword2);
        }
        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 SetLoginInformationEmailTest()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                111, 222, 31, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 104, 15, 16
            };

            SymmetricKeyAlgorithm ska = SymmetricKeyAlgorithm.GenerateNew(SymmetricEncryptionAlgorithm.AES_CTR);

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

            string newEmail = "*****@*****.**";

            // Act
            string loginInformationEmail1 = loginInformationSecret.GetEmail(derivedKey);
            bool   shouldBeTrue           = loginInformationSecret.SetEmail(newEmail, derivedKey);
            string loginInformationEmail2 = loginInformationSecret.GetEmail(derivedKey);
            bool   shouldBeFalse          = loginInformationSecret.SetEmail(newEmail, new byte[] { 1, 2, 3 });

            // Assert
            Assert.IsTrue(shouldBeTrue);
            Assert.IsFalse(shouldBeFalse);
            Assert.IsFalse(string.IsNullOrEmpty(loginInformationEmail1));
            Assert.IsFalse(string.IsNullOrEmpty(loginInformationEmail2));
            Assert.AreEqual(loginInformation.email, loginInformationEmail1);
            Assert.AreEqual(newEmail, loginInformationEmail2);
        }
        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 SetLoginInformationModificationTimeTest()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                111, 222, 31, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 104, 15, 16
            };

            SymmetricKeyAlgorithm ska = SymmetricKeyAlgorithm.GenerateNew(SymmetricEncryptionAlgorithm.AES_CTR);

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

            DateTimeOffset newModificationTime = DateTimeOffset.UtcNow.AddDays(1);

            // Act
            DateTimeOffset loginInformationModificationTime1 = loginInformationSecret.GetModificationTime(derivedKey);
            bool           shouldBeTrue = loginInformationSecret.SetModificationTime(newModificationTime, derivedKey);
            DateTimeOffset loginInformationModificationTime2 = loginInformationSecret.GetModificationTime(derivedKey);
            bool           shouldBeFalse = loginInformationSecret.SetModificationTime(newModificationTime, new byte[] { 1, 29, 3, 99, 134, 255, 0 });

            // Assert
            Assert.IsTrue(shouldBeTrue);
            Assert.IsFalse(shouldBeFalse);
            Assert.AreEqual(loginInformation.modificationTime, loginInformationModificationTime1.ToUnixTimeSeconds());
            Assert.AreEqual(newModificationTime.ToUnixTimeSeconds(), loginInformationModificationTime2.ToUnixTimeSeconds());
        }
        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);
        }
        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);
        }
Beispiel #15
0
 public static LoginSimplified TurnIntoEditable(LoginInformationSecret loginInformationSecret, byte[] derivedPassword, int zeroBasedIndexNumber)
 {
     return(new LoginSimplified()
     {
         zeroBasedIndexNumber = zeroBasedIndexNumber,
         IsSecure = true,
         Title = loginInformationSecret.GetTitle(derivedPassword),
         URL = loginInformationSecret.GetURL(derivedPassword),
         Email = loginInformationSecret.GetEmail(derivedPassword),
         Username = loginInformationSecret.GetUsername(derivedPassword),
         Password = loginInformationSecret.GetPassword(derivedPassword),
         Notes = loginInformationSecret.GetNotes(derivedPassword),
         Icon = loginInformationSecret.GetIcon(derivedPassword),
         Category = loginInformationSecret.GetCategory(derivedPassword),
         Tags = loginInformationSecret.GetTags(derivedPassword),
         CreationTime = loginInformationSecret.GetCreationTime(derivedPassword).ToString("s", System.Globalization.CultureInfo.InvariantCulture),
         ModificationTime = loginInformationSecret.GetModificationTime(derivedPassword).ToString("s", System.Globalization.CultureInfo.InvariantCulture),
     });
 }
        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";

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

            // Assert
            Assert.AreEqual(keyIdentifier, loginInformationSecret.GetKeyIdentifier());
        }
        public void GetCreationTimeTest()
        {
            // 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);

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

            // Act
            DateTimeOffset loginInformationCreationTime = loginInformationSecret.GetCreationTime(derivedKey);

            // Assert
            Assert.AreEqual(loginInformation.GetCreationTime(), loginInformationCreationTime);
        }
        public void GetLoginInformationTitleTest()
        {
            // 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
            string loginInformationTitle = loginInformationSecret.GetTitle(derivedKey);

            // Assert
            Assert.IsFalse(string.IsNullOrEmpty(loginInformationTitle));
            Assert.AreEqual(loginInformation.title, loginInformationTitle);
        }
        public void GetLoginInformationTest()
        {
            // 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
            LoginInformation loginInformationCopy = loginInformationSecret.GetLoginInformation(derivedKey);

            // Assert
            Assert.IsTrue(ComparisonHelper.AreLoginInformationsEqual(loginInformation, loginInformationCopy));
            Assert.AreEqual(loginInformation.creationTime, loginInformationCopy.creationTime);
            Assert.AreEqual(loginInformation.modificationTime, loginInformationCopy.modificationTime);
        }
        public void SetLoginInformationNotesTest()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                111, 222, 31, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 104, 15, 16
            };

            SymmetricKeyAlgorithm ska = SymmetricKeyAlgorithm.GenerateNew(SymmetricEncryptionAlgorithm.AES_CTR);

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

            string newNotes = "future text that is happy and joyful for all purposes...";

            // Act
            bool   shouldBeTrue           = loginInformationSecret.SetNotes(newNotes, derivedKey);
            string loginInformationNotes2 = loginInformationSecret.GetNotes(derivedKey);
            bool   shouldBeFalse          = loginInformationSecret.SetNotes(newNotes, new byte[] { 1, 2, 3 });

            // Assert
            Assert.IsTrue(shouldBeTrue);
            Assert.IsFalse(shouldBeFalse);
            Assert.IsFalse(string.IsNullOrEmpty(loginInformationNotes2));
            Assert.AreEqual(newNotes, loginInformationNotes2);
        }
        public void SetLoginInformationTagsTest()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                111, 222, 31, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 104, 15, 16
            };

            SymmetricKeyAlgorithm ska = SymmetricKeyAlgorithm.GenerateNew(SymmetricEncryptionAlgorithm.AES_CTR);

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

            string newTags = "Finance; Home; Travel; Future";

            // Act
            bool   shouldBeTrue          = loginInformationSecret.SetTags(newTags, derivedKey);
            string loginInformationTags2 = loginInformationSecret.GetTags(derivedKey);
            bool   shouldBeFalse         = loginInformationSecret.SetTags(newTags, new byte[] { 13, 129, 0, 91, 194, 255, 0 });

            // Assert
            Assert.IsTrue(shouldBeTrue);
            Assert.IsFalse(shouldBeFalse);
            Assert.IsFalse(string.IsNullOrEmpty(loginInformationTags2));
            Assert.AreEqual(newTags, loginInformationTags2);
        }
        public void SetLoginInformationIconTest()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                111, 222, 31, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 104, 15, 16
            };

            SymmetricKeyAlgorithm ska = SymmetricKeyAlgorithm.GenerateNew(SymmetricEncryptionAlgorithm.AES_CTR);

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

            byte[] newIcon = new byte[] { 1, 2, 44, 55, 66, 33, 89, 23, 222, 111, 100, 99, 45, 127, 198, 255 };

            // Act
            bool shouldBeTrue = loginInformationSecret.SetIcon(newIcon, derivedKey);

            byte[] loginInformationIcon2 = loginInformationSecret.GetIcon(derivedKey);
            bool   shouldBeFalse         = loginInformationSecret.SetIcon(newIcon, new byte[] { 13, 129, 3, 99, 134, 255, 0 });

            // Assert
            Assert.IsTrue(shouldBeTrue);
            Assert.IsFalse(shouldBeFalse);
            CollectionAssert.AreEqual(newIcon, loginInformationIcon2);
        }
        public void SetLoginInformationMFATest()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                111, 222, 31, 4, 15, 6, 7, 8, 9, 10, 11, 12, 13, 104, 15, 196
            };

            SymmetricKeyAlgorithm ska = SymmetricKeyAlgorithm.GenerateNew(SymmetricEncryptionAlgorithm.AES_CTR);

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

            string newMFA = "otpauth://totp/BIG_DRAGON?secret=YOUR_FIRE";

            // Act
            bool   shouldBeTrue         = loginInformationSecret.SetMFA(newMFA, derivedKey);
            string loginInformationMFA2 = loginInformationSecret.GetMFA(derivedKey);
            bool   shouldBeFalse        = loginInformationSecret.SetMFA(newMFA, new byte[] { 1, 2, 3 });

            // Assert
            Assert.IsTrue(shouldBeTrue);
            Assert.IsFalse(shouldBeFalse);
            Assert.IsFalse(string.IsNullOrEmpty(loginInformationMFA2));
            Assert.AreEqual(newMFA, loginInformationMFA2);
        }
 public static bool AreLoginInformationSecretsEqual(LoginInformationSecret loginSecret1, LoginInformationSecret loginSecret2)
 {
     return(StructuralComparisons.StructuralEqualityComparer.Equals(loginSecret1.audalfData, loginSecret2.audalfData) && AreSymmetricKeyAlgorithmsEqual(loginSecret1.algorithm, loginSecret2.algorithm));
 }