public void testProducerWithLink() { Name prefix = new Name("/prefix"); Name suffix = new Name("/suffix"); 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); double testTime = net.named_data.jndn.encrypt.Schedule.fromIsoString("20150101T100001"); int[] timeoutCount = new int[] { 0 }; // Prepare a LocalTestFace to instantly answer calls to expressInterest. TestProducer.LocalTestFace4 face = new TestProducer.LocalTestFace4(expectedInterest, timeoutCount); // Verify that if no response is received, the producer appropriately times // out. The result vector should not contain elements that have timed out. Link link = new Link(); link.addDelegation(10, new Name("/test1")); link.addDelegation(20, new Name("/test2")); link.addDelegation(100, new Name("/test3")); keyChain.sign(link); ProducerDb testDb = new Sqlite3ProducerDb( databaseFilePath.FullName); Producer producer = new Producer(prefix, suffix, face, keyChain, testDb, 3, link); producer.createContentKey(testTime, new TestProducer.Anonymous_C0(timeoutCount)); }
public void testContentKeySearch() { Name timeMarkerFirstHop = new Name("20150101T070000/20150101T080000"); Name timeMarkerSecondHop = new Name("20150101T080000/20150101T090000"); Name timeMarkerThirdHop = new Name( "20150101T100000/20150101T110000"); Name prefix = new Name("/prefix"); Name suffix = new Name("/suffix"); 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); double testTime = net.named_data.jndn.encrypt.Schedule.fromIsoString("20150101T100001"); // Create content keys required for this test case: createEncryptionKey(expectedInterest, timeMarkerFirstHop); createEncryptionKey(expectedInterest, timeMarkerSecondHop); createEncryptionKey(expectedInterest, timeMarkerThirdHop); int[] requestCount = new int[] { 0 }; // Prepare a LocalTestFace to instantly answer calls to expressInterest. TestProducer.LocalTestFace2 face = new TestProducer.LocalTestFace2(this, expectedInterest, timeMarkerFirstHop, timeMarkerSecondHop, timeMarkerThirdHop, requestCount); // Verify that if a key is found, but not within the right time slot, the // search is refined until a valid time slot is found. ProducerDb testDb = new Sqlite3ProducerDb( databaseFilePath.FullName); Producer producer = new Producer(prefix, suffix, face, keyChain, testDb); producer.createContentKey(testTime, new TestProducer.Anonymous_C2(cKeyName, expectedInterest, requestCount, timeMarkerThirdHop)); }
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))); }
public void testDatabaseFunctions() { // Test construction. ProducerDb database = new Sqlite3ProducerDb( databaseFilePath.FullName); // Create member. AesKeyParams // Create member. paras = new AesKeyParams(128); Blob keyBlob1 = net.named_data.jndn.encrypt.algo.AesAlgorithm.generateKey(paras).getKeyBits(); Blob keyBlob2 = net.named_data.jndn.encrypt.algo.AesAlgorithm.generateKey(paras).getKeyBits(); double point1 = net.named_data.jndn.encrypt.Schedule.fromIsoString("20150101T100000"); double point2 = net.named_data.jndn.encrypt.Schedule.fromIsoString("20150102T100000"); double point3 = net.named_data.jndn.encrypt.Schedule.fromIsoString("20150103T100000"); double point4 = net.named_data.jndn.encrypt.Schedule.fromIsoString("20150104T100000"); // Add keys into the database. database.addContentKey(point1, keyBlob1); database.addContentKey(point2, keyBlob1); database.addContentKey(point3, keyBlob2); // Throw an exception when adding a key to an existing time slot. try { database.addContentKey(point1, keyBlob1); Assert.Fail("addContentKey did not throw an exception"); } catch (ProducerDb.Error ex) { } catch (Exception ex_0) { Assert.Fail("addContentKey did not throw an exception"); } // Check has functions. Assert.AssertEquals(true, database.hasContentKey(point1)); Assert.AssertEquals(true, database.hasContentKey(point2)); Assert.AssertEquals(true, database.hasContentKey(point3)); Assert.AssertEquals(false, database.hasContentKey(point4)); // Get content keys. Blob keyResult = database.getContentKey(point1); Assert.AssertTrue(keyResult.equals(keyBlob1)); keyResult = database.getContentKey(point3); Assert.AssertTrue(keyResult.equals(keyBlob2)); // Throw exception when there is no such time slot in the database. try { database.getContentKey(point4); Assert.Fail("getContentKey did not throw an exception"); } catch (ProducerDb.Error ex_1) { } catch (Exception ex_2) { Assert.Fail("getContentKey did not throw an exception"); } // Delete content keys. Assert.AssertEquals(true, database.hasContentKey(point1)); database.deleteContentKey(point1); Assert.AssertEquals(false, database.hasContentKey(point1)); // Delete at a non-existing time slot. try { database.deleteContentKey(point4); } catch (Exception ex_3) { Assert.Fail("deleteContentKey threw an exception"); } }