Example #1
0
        public void GetContactTest()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 13, 11, 12, 13, 14, 15, 16
            };
            byte[] initialCounter = new byte[] { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xf1, 0xfc, 0xfd, 0xfe, 0xff };

            SettingsAES_CTR settingsAES_CTR = new SettingsAES_CTR(initialCounter);

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

            string firstName  = "Super110";
            string lastName   = "Awesome220";
            string middleName = "Mega330";
            string namePrefix = "Sirest";
            string nameSuffix = "IIIII";
            string nickname   = "MegaDragon";
            string company    = "EverDragons COTYERT";
            string jobTitle   = "Mid dragon";
            string department = "Cave";

            string[] emails                  = { "*****@*****.**", "*****@*****.**" };
            string[] emailDescriptions       = { "work", "home" };
            string[] phoneNumbers            = { "1234-123-123", "2344-234-234" };
            string[] phoneNumberDescriptions = { "work", "hotel" };
            string   country                 = "dragonland II";
            string   streetAddress           = "dragon street 122";
            string   streetAddressAdditional = "no addition";
            string   postalCode              = "12345";
            string   city         = "dragoncave";
            string   poBox        = "no po box";
            string   birthday     = "11-09-1697";
            string   relationship = "single";
            string   notes        = "Very awesome dragon again";

            string[] websites = { "https://dacoolastdragons4life.com", "https://nicevalleyvaults.net" };
            Contact  c1       = new Contact(firstName, lastName, middleName, namePrefix, nameSuffix, nickname, company, jobTitle, department,
                                            emails, emailDescriptions, phoneNumbers, phoneNumberDescriptions,
                                            country, streetAddress, streetAddressAdditional, postalCode, city, poBox, birthday,
                                            websites, relationship, notes);

            ContactSecret cs = new ContactSecret(c1, "does not matter", skaAES_CTR, derivedKey);

            // Act
            Contact contactCopy = cs.GetContact(derivedKey);

            // Assert
            Assert.IsTrue(ComparisonHelper.AreContactsEqual(c1, contactCopy));
            Assert.AreEqual(c1.creationTime, contactCopy.creationTime);
            Assert.AreEqual(c1.modificationTime, contactCopy.modificationTime);
        }
        public void RoundTripComplexTest()
        {
            // Arrange
            CommonSecretsContainer csc = new CommonSecretsContainer();

            string password = "******";

            byte[]                initialCounter1  = new byte[] { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff };
            SettingsAES_CTR       settingsAES_CTR1 = new SettingsAES_CTR(initialCounter1);
            SymmetricKeyAlgorithm skaAES           = new SymmetricKeyAlgorithm(SymmetricEncryptionAlgorithm.AES_CTR, 256, settingsAES_CTR1);

            KeyDerivationFunctionEntry kdfe = KeyDerivationFunctionEntry.CreateHMACSHA256KeyDerivationFunctionEntry("does not matter");

            int loginsAmount       = 12;
            int loginsSecretAmount = 14;

            int notesAmount       = 17;
            int notesSecretAmount = 11;

            int filesAmount       = 5;
            int filesSecretAmount = 3;

            int contactAmount       = 4;
            int contactSecretAmount = 2;

            int paymentAmount       = 3;
            int paymentSecretAmount = 7;

            // Act
            byte[] derivedPassword = kdfe.GeneratePasswordBytes(password);

            csc.keyDerivationFunctionEntries.Add(kdfe);

            for (int i = 0; i < loginsAmount; i++)
            {
                csc.loginInformations.Add(ContentGenerator.GenerateRandomLoginInformation());
            }

            for (int i = 0; i < loginsSecretAmount; i++)
            {
                csc.loginInformationSecrets.Add(new LoginInformationSecret(ContentGenerator.GenerateRandomLoginInformation(), kdfe.GetKeyIdentifier(), skaAES, derivedPassword));
            }

            for (int i = 0; i < notesAmount; i++)
            {
                csc.notes.Add(ContentGenerator.GenerateRandomNote());
            }

            for (int i = 0; i < notesSecretAmount; i++)
            {
                csc.noteSecrets.Add(new NoteSecret(ContentGenerator.GenerateRandomNote(), kdfe.GetKeyIdentifier(), skaAES, derivedPassword));
            }

            for (int i = 0; i < filesAmount; i++)
            {
                csc.files.Add(ContentGenerator.GenerateRandomFileEntry());
            }

            for (int i = 0; i < filesSecretAmount; i++)
            {
                csc.fileSecrets.Add(new FileEntrySecret(ContentGenerator.GenerateRandomFileEntry(), kdfe.GetKeyIdentifier(), skaAES, derivedPassword));
            }

            for (int i = 0; i < contactAmount; i++)
            {
                csc.contacts.Add(ContentGenerator.GenerateRandomContact());
            }

            for (int i = 0; i < contactSecretAmount; i++)
            {
                csc.contactSecrets.Add(new ContactSecret(ContentGenerator.GenerateRandomContact(), kdfe.GetKeyIdentifier(), skaAES, derivedPassword));
            }

            for (int i = 0; i < paymentAmount; i++)
            {
                csc.paymentCards.Add(ContentGenerator.GenerateRandomPaymentCard());
            }

            for (int i = 0; i < paymentSecretAmount; i++)
            {
                csc.paymentCardSecrets.Add(new PaymentCardSecret(ContentGenerator.GenerateRandomPaymentCard(), kdfe.GetKeyIdentifier(), skaAES, derivedPassword));
            }

            string json = JsonSerializer.Serialize(csc, serializerOptions);

            CommonSecretsContainer cscDeserialized = JsonSerializer.Deserialize <CommonSecretsContainer>(json);

            // Assert
            Assert.AreEqual(1, csc.keyDerivationFunctionEntries.Count);
            Assert.AreEqual(1, cscDeserialized.keyDerivationFunctionEntries.Count);
            Assert.IsTrue(ComparisonHelper.AreKeyDerivationFunctionEntriesEqual(csc.keyDerivationFunctionEntries[0], cscDeserialized.keyDerivationFunctionEntries[0]));

            Assert.AreEqual(loginsAmount, csc.loginInformations.Count);
            Assert.AreEqual(loginsAmount, cscDeserialized.loginInformations.Count);
            for (int i = 0; i < loginsAmount; i++)
            {
                Assert.IsTrue(ComparisonHelper.AreLoginInformationsEqual(csc.loginInformations[i], cscDeserialized.loginInformations[i]));
            }

            Assert.AreEqual(loginsSecretAmount, csc.loginInformationSecrets.Count);
            Assert.AreEqual(loginsSecretAmount, cscDeserialized.loginInformationSecrets.Count);
            for (int i = 0; i < loginsSecretAmount; i++)
            {
                Assert.IsTrue(ComparisonHelper.AreLoginInformationSecretsEqual(csc.loginInformationSecrets[i], cscDeserialized.loginInformationSecrets[i]));
            }


            Assert.AreEqual(notesAmount, csc.notes.Count);
            Assert.AreEqual(notesAmount, cscDeserialized.notes.Count);
            for (int i = 0; i < notesAmount; i++)
            {
                Assert.IsTrue(ComparisonHelper.AreNotesEqual(csc.notes[i], cscDeserialized.notes[i]));
            }

            Assert.AreEqual(notesSecretAmount, csc.noteSecrets.Count);
            Assert.AreEqual(notesSecretAmount, cscDeserialized.noteSecrets.Count);
            for (int i = 0; i < notesSecretAmount; i++)
            {
                Assert.IsTrue(ComparisonHelper.AreNotesSecretEqual(csc.noteSecrets[i], cscDeserialized.noteSecrets[i]));
            }


            Assert.AreEqual(filesAmount, csc.files.Count);
            Assert.AreEqual(filesAmount, cscDeserialized.files.Count);
            for (int i = 0; i < filesAmount; i++)
            {
                Assert.IsTrue(ComparisonHelper.AreFileEntriesEqual(csc.files[i], cscDeserialized.files[i]));
            }

            Assert.AreEqual(filesSecretAmount, csc.fileSecrets.Count);
            Assert.AreEqual(filesSecretAmount, cscDeserialized.fileSecrets.Count);
            for (int i = 0; i < filesSecretAmount; i++)
            {
                Assert.IsTrue(ComparisonHelper.AreFileEntrySecretsEqual(csc.fileSecrets[i], cscDeserialized.fileSecrets[i]));
            }


            Assert.AreEqual(contactAmount, csc.contacts.Count);
            Assert.AreEqual(contactAmount, cscDeserialized.contacts.Count);
            for (int i = 0; i < contactAmount; i++)
            {
                Assert.IsTrue(ComparisonHelper.AreContactsEqual(csc.contacts[i], cscDeserialized.contacts[i]));
            }

            Assert.AreEqual(contactSecretAmount, csc.contactSecrets.Count);
            Assert.AreEqual(contactSecretAmount, cscDeserialized.contactSecrets.Count);
            for (int i = 0; i < contactSecretAmount; i++)
            {
                Assert.IsTrue(ComparisonHelper.AreContactSecretsEqual(csc.contactSecrets[i], cscDeserialized.contactSecrets[i]));
            }


            Assert.AreEqual(paymentAmount, csc.paymentCards.Count);
            Assert.AreEqual(paymentAmount, cscDeserialized.paymentCards.Count);
            for (int i = 0; i < paymentAmount; i++)
            {
                Assert.IsTrue(ComparisonHelper.ArePaymentCardsEqual(csc.paymentCards[i], cscDeserialized.paymentCards[i]));
            }

            Assert.AreEqual(paymentSecretAmount, csc.paymentCardSecrets.Count);
            Assert.AreEqual(paymentSecretAmount, cscDeserialized.paymentCardSecrets.Count);
            for (int i = 0; i < paymentSecretAmount; i++)
            {
                Assert.IsTrue(ComparisonHelper.ArePaymentCardSecretsEqual(csc.paymentCardSecrets[i], cscDeserialized.paymentCardSecrets[i]));
            }
        }