Beispiel #1
0
        public void testEncryptAndPublishCk()
        {
            fixture_.encryptor_.clearKekData_();
            Assert.AssertEquals(false, fixture_.encryptor_.getIsKekRetrievalInProgress_());
            fixture_.encryptor_.regenerateCk();
            // Unlike the ndn-group-encrypt unit tests, we don't check
            // isKekRetrievalInProgress_ true because we use a synchronous face which
            // finishes immediately.

            Blob             plainText        = new Blob("Data to encrypt");
            EncryptedContent encryptedContent = fixture_.encryptor_
                                                .encrypt(plainText.getImmutableArray());

            Name ckPrefix = encryptedContent.getKeyLocatorName();

            Assert.AssertTrue(new Name("/some/ck/prefix/CK")
                              .equals(ckPrefix.getPrefix(-1)));

            Assert.AssertTrue(encryptedContent.hasInitialVector());
            Assert.AssertTrue(!encryptedContent.getPayload().equals(plainText));

            // Check that the KEK Interest has been sent.
            Assert.AssertTrue(fixture_.face_.sentInterests_[0].getName().getPrefix(6)
                              .equals(new Name("/access/policy/identity/NAC/dataset/KEK")));

            Data kekData = fixture_.face_.sentData_[0];

            Assert.AssertTrue(kekData.getName().getPrefix(6)
                              .equals(new Name("/access/policy/identity/NAC/dataset/KEK")));
            Assert.AssertEquals(7, kekData.getName().size());

            ILOG.J2CsMapping.Collections.Collections.Clear(fixture_.face_.sentData_);
            ILOG.J2CsMapping.Collections.Collections.Clear(fixture_.face_.sentInterests_);

            fixture_.face_.receive(new Interest(ckPrefix).setCanBePrefix(true)
                                   .setMustBeFresh(true));

            Name ckName = fixture_.face_.sentData_[0].getName();

            Assert.AssertTrue(ckName.getPrefix(4).equals(new Name("/some/ck/prefix/CK")));
            Assert.AssertTrue(ckName.get(5).equals(new Name.Component("ENCRYPTED-BY")));

            Name extractedKek = ckName.getSubName(6);

            Assert.AssertTrue(extractedKek.equals(kekData.getName()));

            Assert.AssertEquals(false, fixture_.encryptor_.getIsKekRetrievalInProgress_());
        }