public void testEncodeDecode()
        {
            toyCert.encode();
            Blob cert_data = toyCert.getContent();
            Data plainData = new Data();
            plainData.setName(toyCert.getName());
            plainData.setContent(cert_data);
            // The constructor Certificate(Data) calls decode().
            Certificate decoded_cert = new Certificate(plainData);

            Assert.AssertEquals("Certificate representation changed after encoding", ""
                    + toyCert, "" + decoded_cert);
        }
Beispiel #2
0
        /// <summary>
        /// Get the content key from the database_ and encrypt it for the timeSlot
        /// using encryptionKey.
        /// </summary>
        ///
        /// <param name="encryptionKey">The encryption key value.</param>
        /// <param name="eKeyName">The key name for the EncryptedContent.</param>
        /// <param name="timeSlot_0">The time slot as milliseconds since Jan 1, 1970 UTC.</param>
        /// <param name="onEncryptedKeys_1">encrypted content key Data packets. If onEncryptedKeys is null, this does not use it.</param>
        /// <returns>True if encryption succeeds, otherwise false.</returns>
        private bool encryptContentKey(Blob encryptionKey, Name eKeyName,
				double timeSlot_0, Producer.OnEncryptedKeys  onEncryptedKeys_1, net.named_data.jndn.encrypt.EncryptError.OnError  onError_2)
        {
            double timeCount = Math.Round(timeSlot_0,MidpointRounding.AwayFromZero);
            Producer.KeyRequest  keyRequest = (Producer.KeyRequest ) ILOG.J2CsMapping.Collections.Collections.Get(keyRequests_,timeCount);

            Name keyName = new Name(namespace_);
            keyName.append(net.named_data.jndn.encrypt.algo.Encryptor.NAME_COMPONENT_C_KEY);
            keyName.append(net.named_data.jndn.encrypt.Schedule.toIsoString(getRoundedTimeSlot(timeSlot_0)));

            Blob contentKey = database_.getContentKey(timeSlot_0);

            Data cKeyData = new Data();
            cKeyData.setName(keyName);
            EncryptParams paras = new EncryptParams(net.named_data.jndn.encrypt.algo.EncryptAlgorithmType.RsaOaep);
            try {
                net.named_data.jndn.encrypt.algo.Encryptor.encryptData(cKeyData, contentKey, eKeyName,
                        encryptionKey, paras);
            } catch (Exception ex) {
                try {
                    onError_2.onError(net.named_data.jndn.encrypt.EncryptError.ErrorCode.EncryptionFailure, ex.Message);
                } catch (Exception exception) {
                    logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onError", exception);
                }
                return false;
            }

            keyChain_.sign(cKeyData);
            ILOG.J2CsMapping.Collections.Collections.Add(keyRequest.encryptedKeys,cKeyData);
            updateKeyRequest(keyRequest, timeCount, onEncryptedKeys_1);
            return true;
        }
        public void testMatchesData()
        {
            Interest interest = new Interest(new Name("/A"));
            interest.setMinSuffixComponents(2);
            interest.setMaxSuffixComponents(2);
            interest.getKeyLocator().setType(net.named_data.jndn.KeyLocatorType.KEYNAME);
            interest.getKeyLocator().setKeyName(new Name("/B"));
            interest.getExclude().appendComponent(new Name.Component("J"));
            interest.getExclude().appendAny();

            Data data = new Data(new Name("/A/D"));
            Sha256WithRsaSignature signature = new Sha256WithRsaSignature();
            signature.getKeyLocator().setType(net.named_data.jndn.KeyLocatorType.KEYNAME);
            signature.getKeyLocator().setKeyName(new Name("/B"));
            data.setSignature(signature);
            Assert.AssertEquals(true, interest.matchesData(data));

            // Check violating MinSuffixComponents.
            Data data1 = new Data(data);
            data1.setName(new Name("/A"));
            Assert.AssertEquals(false, interest.matchesData(data1));

            Interest interest1 = new Interest(interest);
            interest1.setMinSuffixComponents(1);
            Assert.AssertEquals(true, interest1.matchesData(data1));

            // Check violating MaxSuffixComponents.
            Data data2 = new Data(data);
            data2.setName(new Name("/A/E/F"));
            Assert.AssertEquals(false, interest.matchesData(data2));

            Interest interest2 = new Interest(interest);
            interest2.setMaxSuffixComponents(3);
            Assert.AssertEquals(true, interest2.matchesData(data2));

            // Check violating PublisherPublicKeyLocator.
            Data data3 = new Data(data);
            Sha256WithRsaSignature signature3 = new Sha256WithRsaSignature();
            signature3.getKeyLocator().setType(net.named_data.jndn.KeyLocatorType.KEYNAME);
            signature3.getKeyLocator().setKeyName(new Name("/G"));
            data3.setSignature(signature3);
            Assert.AssertEquals(false, interest.matchesData(data3));

            Interest interest3 = new Interest(interest);
            interest3.getKeyLocator().setType(net.named_data.jndn.KeyLocatorType.KEYNAME);
            interest3.getKeyLocator().setKeyName(new Name("/G"));
            Assert.AssertEquals(true, interest3.matchesData(data3));

            Data data4 = new Data(data);
            data4.setSignature(new DigestSha256Signature());
            Assert.AssertEquals(false, interest.matchesData(data4));

            Interest interest4 = new Interest(interest);
            interest4.setKeyLocator(new KeyLocator());
            Assert.AssertEquals(true, interest4.matchesData(data4));

            // Check violating Exclude.
            Data data5 = new Data(data);
            data5.setName(new Name("/A/J"));
            Assert.AssertEquals(false, interest.matchesData(data5));

            Interest interest5 = new Interest(interest);
            interest5.getExclude().clear();
            interest5.getExclude().appendComponent(new Name.Component("K"));
            interest5.getExclude().appendAny();
            Assert.AssertEquals(true, interest5.matchesData(data5));

            // Check violating Name.
            Data data6 = new Data(data);
            data6.setName(new Name("/H/I"));
            Assert.AssertEquals(false, interest.matchesData(data6));

            Data data7 = new Data(data);
            data7.setName(new Name("/A/B"));

            Interest interest7 = new Interest(
                    new Name(
                            "/A/B/sha256digest="
                                    + "54008e240a7eea2714a161dfddf0dd6ced223b3856e9da96792151e180f3b128"));
            Assert.AssertEquals(true, interest7.matchesData(data7));

            // Check violating the implicit digest.
            Interest interest7b = new Interest(new Name(
                    "/A/B/%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00"
                            + "%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00"));
            Assert.AssertEquals(false, interest7b.matchesData(data7));

            // Check excluding the implicit digest.
            Interest interest8 = new Interest(new Name("/A/B"));
            interest8.getExclude().appendComponent(interest7.getName().get(2));
            Assert.AssertEquals(false, interest8.matchesData(data7));
        }
Beispiel #4
0
        /// <summary>
        /// Encrypt the given content with the content key that covers timeSlot, and
        /// update the data packet with the encrypted content and an appropriate data
        /// name.
        /// </summary>
        ///
        /// <param name="data">An empty Data object which is updated.</param>
        /// <param name="timeSlot_0">The time slot as milliseconds since Jan 1, 1970 UTC.</param>
        /// <param name="content">The content to encrypt.</param>
        /// <param name="onError_1">better error handling the callback should catch and properly handle any exceptions.</param>
        public void produce(Data data, double timeSlot_0, Blob content,
				net.named_data.jndn.encrypt.EncryptError.OnError  onError_1)
        {
            // Get a content key.
            Name contentKeyName = createContentKey(timeSlot_0, null, onError_1);
            Blob contentKey = database_.getContentKey(timeSlot_0);

            // Produce data.
            Name dataName = new Name(namespace_);
            dataName.append(net.named_data.jndn.encrypt.Schedule.toIsoString(timeSlot_0));

            data.setName(dataName);
            EncryptParams paras = new EncryptParams(net.named_data.jndn.encrypt.algo.EncryptAlgorithmType.AesCbc,
                    16);
            net.named_data.jndn.encrypt.algo.Encryptor
                    .encryptData(data, content, contentKeyName, contentKey, paras);
            keyChain_.sign(data);
        }
        internal void setManager(GroupManager manager)
        {
            // Set up the first schedule.
            Schedule schedule1 = new Schedule();
            RepetitiveInterval interval11 = new RepetitiveInterval(
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150825T000000"),
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150827T000000"), 5, 10, 2,
                    net.named_data.jndn.encrypt.RepetitiveInterval.RepeatUnit.DAY);
            RepetitiveInterval interval12 = new RepetitiveInterval(
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150825T000000"),
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150827T000000"), 6, 8, 1,
                    net.named_data.jndn.encrypt.RepetitiveInterval.RepeatUnit.DAY);
            RepetitiveInterval interval13 = new RepetitiveInterval(
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150827T000000"),
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150827T000000"), 7, 8);
            schedule1.addWhiteInterval(interval11);
            schedule1.addWhiteInterval(interval12);
            schedule1.addBlackInterval(interval13);

            // Set up the second schedule.
            Schedule schedule2 = new Schedule();
            RepetitiveInterval interval21 = new RepetitiveInterval(
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150825T000000"),
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150827T000000"), 9, 12, 1,
                    net.named_data.jndn.encrypt.RepetitiveInterval.RepeatUnit.DAY);
            RepetitiveInterval interval22 = new RepetitiveInterval(
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150827T000000"),
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150827T000000"), 6, 8);
            RepetitiveInterval interval23 = new RepetitiveInterval(
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150827T000000"),
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150827T000000"), 2, 4);
            schedule2.addWhiteInterval(interval21);
            schedule2.addWhiteInterval(interval22);
            schedule2.addBlackInterval(interval23);

            // Add them to the group manager database.
            manager.addSchedule("schedule1", schedule1);
            manager.addSchedule("schedule2", schedule2);

            // Make some adaptions to certificate.
            Blob dataBlob = certificate.wireEncode();

            Data memberA = new Data();
            memberA.wireDecode(dataBlob, net.named_data.jndn.encoding.TlvWireFormat.get());
            memberA.setName(new Name("/ndn/memberA/KEY/ksk-123/ID-CERT/123"));
            Data memberB = new Data();
            memberB.wireDecode(dataBlob, net.named_data.jndn.encoding.TlvWireFormat.get());
            memberB.setName(new Name("/ndn/memberB/KEY/ksk-123/ID-CERT/123"));
            Data memberC = new Data();
            memberC.wireDecode(dataBlob, net.named_data.jndn.encoding.TlvWireFormat.get());
            memberC.setName(new Name("/ndn/memberC/KEY/ksk-123/ID-CERT/123"));

            // Add the members to the database.
            manager.addMember("schedule1", memberA);
            manager.addMember("schedule1", memberB);
            manager.addMember("schedule2", memberC);
        }