コード例 #1
0
 public Anonymous_C3(TestProducer.CheckEncryptionKeys checkEncryptionKeys_0,
                     double testTime2_1, net.named_data.jndn.Name.Component testTimeRounded2_2)
 {
     this.checkEncryptionKeys = checkEncryptionKeys_0;
     this.testTime2           = testTime2_1;
     this.testTimeRounded2    = testTimeRounded2_2;
 }
コード例 #2
0
        public void testContentKeyRequest()
        {
            Name prefix           = new Name("/prefix");
            Name suffix           = new Name("/a/b/c");
            Name expectedInterest = new Name(prefix);

            expectedInterest.append(net.named_data.jndn.encrypt.algo.Encryptor.NAME_COMPONENT_READ);
            expectedInterest.append(suffix);
            expectedInterest.append(net.named_data.jndn.encrypt.algo.Encryptor.NAME_COMPONENT_E_KEY);

            Name cKeyName = new Name(prefix);

            cKeyName.append(net.named_data.jndn.encrypt.algo.Encryptor.NAME_COMPONENT_SAMPLE);
            cKeyName.append(suffix);
            cKeyName.append(net.named_data.jndn.encrypt.algo.Encryptor.NAME_COMPONENT_C_KEY);

            Name   timeMarker = new Name("20150101T100000/20150101T120000");
            double testTime1  = net.named_data.jndn.encrypt.Schedule.fromIsoString("20150101T100001");
            double testTime2  = net.named_data.jndn.encrypt.Schedule.fromIsoString("20150101T110001");

            Name.Component testTimeRounded1 = new Name.Component(
                "20150101T100000");
            Name.Component testTimeRounded2 = new Name.Component(
                "20150101T110000");
            Name.Component testTimeComponent2 = new Name.Component(
                "20150101T110001");

            // Create content keys required for this test case:
            for (int i = 0; i < suffix.size(); ++i)
            {
                createEncryptionKey(expectedInterest, timeMarker);
                expectedInterest = expectedInterest.getPrefix(-2).append(
                    net.named_data.jndn.encrypt.algo.Encryptor.NAME_COMPONENT_E_KEY);
            }

            int[] expressInterestCallCount = new int[] { 0 };

            // Prepare a LocalTestFace to instantly answer calls to expressInterest.


            TestProducer.LocalTestFace face = new TestProducer.LocalTestFace(this, timeMarker,
                                                                             expressInterestCallCount);

            // Verify that the content key is correctly encrypted for each domain, and
            // the produce method encrypts the provided data with the same content key.
            ProducerDb testDb = new Sqlite3ProducerDb(
                databaseFilePath.FullName);
            Producer producer = new Producer(prefix, suffix, face, keyChain, testDb);

            Blob[] contentKey = new Blob[] { null };



            TestProducer.CheckEncryptionKeys checkEncryptionKeys = new TestProducer.CheckEncryptionKeys(
                this, expressInterestCallCount, contentKey, cKeyName, testDb);

            // An initial test to confirm that keys are created for this time slot.
            Name contentKeyName1 = producer.createContentKey(testTime1,
                                                             new TestProducer.Anonymous_C4(checkEncryptionKeys, testTimeRounded1,
                                                                                           testTime1));

            // Verify that we do not repeat the search for e-keys. The total
            //   expressInterestCallCount should be the same.
            Name contentKeyName2 = producer.createContentKey(testTime2,
                                                             new TestProducer.Anonymous_C3(checkEncryptionKeys, testTime2,
                                                                                           testTimeRounded2));

            // Confirm content key names are correct
            Assert.AssertEquals(cKeyName, contentKeyName1.getPrefix(-1));
            Assert.AssertEquals(testTimeRounded1, contentKeyName1.get(6));
            Assert.AssertEquals(cKeyName, contentKeyName2.getPrefix(-1));
            Assert.AssertEquals(testTimeRounded2, contentKeyName2.get(6));

            // Confirm that produce encrypts with the correct key and has the right name.
            Data testData = new Data();

            producer.produce(testData, testTime2, new Blob(DATA_CONTENT, false));

            Name producedName = testData.getName();

            Assert.AssertEquals(cKeyName.getPrefix(-1), producedName.getSubName(0, 5));
            Assert.AssertEquals(testTimeComponent2, producedName.get(5));
            Assert.AssertEquals(net.named_data.jndn.encrypt.algo.Encryptor.NAME_COMPONENT_FOR, producedName.get(6));
            Assert.AssertEquals(cKeyName, producedName.getSubName(7, 6));
            Assert.AssertEquals(testTimeRounded2, producedName.get(13));

            Blob dataBlob = testData.getContent();

            EncryptedContent dataContent = new EncryptedContent();

            dataContent.wireDecode(dataBlob);
            Blob encryptedData = dataContent.getPayload();
            Blob initialVector = dataContent.getInitialVector();

            EncryptParams paras = new EncryptParams(net.named_data.jndn.encrypt.algo.EncryptAlgorithmType.AesCbc,
                                                    16);

            paras.setInitialVector(initialVector);
            Blob decryptTest = net.named_data.jndn.encrypt.algo.AesAlgorithm.decrypt(contentKey[0], encryptedData,
                                                                                     paras);

            Assert.AssertTrue(decryptTest.equals(new Blob(DATA_CONTENT, false)));
        }