Ejemplo n.º 1
0
        public void ParameterizedTests(
            IEnvelopeEncryption <byte[]> envelopeEncryptionJson,
            Mock <IMetastorePersistence <JObject> > metastorePersistence,
            KeyState cacheIK,
            KeyState metaIK,
            KeyState cacheSK,
            KeyState metaSK,
            AppEncryptionPartition appEncryptionPartition)
        {
            using (AppEncryption <JObject, byte[]> appEncryptionJsonImpl =
                       new AppEncryptionJsonImpl <byte[]>(envelopeEncryptionJson))
            {
                EncryptMetastoreInteractions encryptMetastoreInteractions =
                    new EncryptMetastoreInteractions(cacheIK, metaIK, cacheSK, metaSK);
                DecryptMetastoreInteractions decryptMetastoreInteractions =
                    new DecryptMetastoreInteractions(cacheIK, cacheSK);

                // encrypt with library object(appEncryptionJsonImpl)
                byte[] encryptedPayload = appEncryptionJsonImpl.Encrypt(payload);

                Assert.NotNull(encryptedPayload);
                VerifyEncryptFlow(metastorePersistence, encryptMetastoreInteractions, appEncryptionPartition);

                metastorePersistence.Invocations.Clear();
                JObject decryptedPayload = appEncryptionJsonImpl.Decrypt(encryptedPayload);

                VerifyDecryptFlow(metastorePersistence, decryptMetastoreInteractions, appEncryptionPartition);
                Assert.True(JToken.DeepEquals(payload, decryptedPayload));
            }
        }
Ejemplo n.º 2
0
        private void RoundTripGeneric(string testData, AeadEnvelopeCrypto aeadEnvelopeCrypto)
        {
            CryptoPolicy cryptoPolicy = new DummyCryptoPolicy();

            using (SecureCryptoKeyDictionary <DateTimeOffset> secureCryptoKeyDictionary =
                       new SecureCryptoKeyDictionary <DateTimeOffset>(cryptoPolicy.GetRevokeCheckPeriodMillis()))
            {
                IEnvelopeEncryption <JObject> envelopeEncryptionJsonImpl = new EnvelopeEncryptionJsonImpl(
                    appEncryptionPartition,
                    metastorePersistence,
                    secureCryptoKeyDictionary,
                    new SecureCryptoKeyDictionaryFactory <DateTimeOffset>(cryptoPolicy),
                    aeadEnvelopeCrypto,
                    cryptoPolicy,
                    keyManagementService);
                using (AppEncryption <JObject, JObject> appEncryptionJsonImpl =
                           new AppEncryptionJsonImpl <JObject>(envelopeEncryptionJsonImpl))
                {
                    Asherah.AppEncryption.Util.Json testJson = new Asherah.AppEncryption.Util.Json();
                    testJson.Put("Test", testData);

                    string persistenceKey = appEncryptionJsonImpl.Store(testJson.ToJObject(), dataPersistence);

                    Option <JObject> testJson2 = appEncryptionJsonImpl.Load(persistenceKey, dataPersistence);
                    Assert.True(testJson2.IsSome);
                    string resultData = ((JObject)testJson2)["Test"].ToObject <string>();

                    Assert.Equal(testData, resultData);
                }
            }
        }
Ejemplo n.º 3
0
        private void TestConstructor()
        {
            AppEncryptionJsonImpl <string> appEncryption = new AppEncryptionJsonImpl <string>(envelopeEncryptionMock.Object);

            Assert.NotNull(appEncryption);
        }
Ejemplo n.º 4
0
 public AppEncryptionJsonImplTest()
 {
     envelopeEncryptionMock = new Mock <IEnvelopeEncryption <string> >();
     appEncryptionJsonImpl  = new AppEncryptionJsonImpl <string>(envelopeEncryptionMock.Object);
 }