Example #1
0
        /// <summary>
        /// Extract the KeyLocator Name from a signed Interest.
        /// The Interest must have SignatureInfo and contain a KeyLocator of type
        /// KEYNAME. Otherwise, state.fail is invoked with INVALID_KEY_LOCATOR.
        /// </summary>
        ///
        /// <param name="interest">The signed Interest with the KeyLocator.</param>
        /// <param name="state">On error, this calls state.fail and returns an empty Name.</param>
        /// <returns>The KeyLocator name, or an empty Name for failure.</returns>
        public static Name getKeyLocatorName(Interest interest,
                                             ValidationState state)
        {
            Name name = interest.getName();

            if (name.size() < 2)
            {
                state.fail(new ValidationError(net.named_data.jndn.security.v2.ValidationError.INVALID_KEY_LOCATOR,
                                               "Invalid signed Interest: name too short"));
                return(new Name());
            }

            Signature signatureInfo;

            try {
                // TODO: Generalize the WireFormat.
                signatureInfo = net.named_data.jndn.encoding.WireFormat.getDefaultWireFormat()
                                .decodeSignatureInfoAndValue(
                    interest.getName().get(-2).getValue().buf(),
                    interest.getName().get(-1).getValue().buf());
            } catch (Exception ex) {
                state.fail(new ValidationError(net.named_data.jndn.security.v2.ValidationError.INVALID_KEY_LOCATOR,
                                               "Invalid signed Interest: " + ex));
                return(new Name());
            }

            return(getKeyLocatorNameFromSignature(signatureInfo, state));
        }
Example #2
0
        /// <summary>
        /// Find a certificate for the given interest.
        /// </summary>
        ///
        /// <param name="interest">The input interest packet.</param>
        /// <returns>The found certificate, or null if not found.</returns>
        /// @note Interest with implicit digest is not supported.
        /// @note ChildSelector is not supported.
        public CertificateV2 find(Interest interest)
        {
            refresh();

            Name firstKey = (Name)anchors_.anchorsByName_.ceilingKey(interest
                                                                     .getName());

            if (firstKey == null)
            {
                return(null);
            }

            /* foreach */
            foreach (Object key  in  anchors_.anchorsByName_.navigableKeySet().tailSet(
                         firstKey))
            {
                CertificateV2 certificate = (CertificateV2)anchors_.anchorsByName_[(Name)key];
                if (!interest.getName().isPrefixOf(certificate.getName()))
                {
                    break;
                }

                try {
                    if (interest.matchesData(certificate))
                    {
                        return(certificate);
                    }
                } catch (EncodingException ex) {
                    // We don't expect this to happen.
                    throw new Exception("Error in matchesData: " + ex);
                }
            }

            return(null);
        }
Example #3
0
    public void onInterest(Name prefix, Interest interest, Face face, long interestFilterId,
                           InterestFilter filter)
    {
        int    linkPrefixSize = webComm.getLinkPrefix().size();
        string phoneId        = interest.getName().get(linkPrefixSize).toEscapedString();
        string linkContent    = interest.getName().get(linkPrefixSize + 1).toEscapedString();

        webComm.handleLink(phoneId, linkContent);

        var data    = new Data(interest.getName());
        var content = "User " + phoneId + " clicked link \"" + linkContent + "\"";

        data.setContent(new Blob(content));
        data.getMetaInfo().setFreshnessPeriod(4000);

        try {
            FaceSingleton.getKeychain().sign(data, FaceSingleton.getCertificateName());
        } catch (SecurityException exception) {
            // Don't expect this to happen.
            throw new SecurityException("SecurityException in sign: " + exception);
        }

        try {
            FaceSingleton.getFace().putData(data);
        } catch (Exception ex) {
            Debug.Log("Echo: Exception in sending data " + ex);
        }
    }
Example #4
0
        public void onInterest(Name prefix, Interest interest, Face face, long interestFilterId,
                               InterestFilter filter)
        {
            // TODO: command interest verification
            string matchId = interest.getName().get(matcher_.prefix_.size()).toEscapedString();
            // TODO: merge with class Track (Person) and Tracks to tell if there's tracks that can be matched
            //   for now, return match success

            var data    = new Data(interest.getName());
            var content = "{\"status\": \"200\", \"trackId\": \"3\", \"mobileId\":\"" + matchId + "\"}";

            data.setContent(new Blob(content));
            data.getMetaInfo().setFreshnessPeriod(2000);

            try {
                matcher_.keyChain_.sign(data, matcher_.certificateName_);
            } catch (SecurityException exception) {
                // Don't expect this to happen.
                throw new SecurityException("SecurityException in sign: " + exception);
            }

            Console.Out.WriteLine("Sent content " + content);
            try {
                matcher_.face_.putData(data);
            } catch (Exception ex) {
                Console.Out.WriteLine("Echo: Exception in sending data " + ex);
            }
        }
Example #5
0
        /// <summary>
        /// Append a timestamp component and a random nonce component to interest's
        /// name. This ensures that the timestamp is greater than the timestamp used in
        /// the previous call.
        /// </summary>
        ///
        /// <param name="interest">The interest whose name is append with components.</param>
        /// <param name="wireFormat">A WireFormat object used to encode the SignatureInfo.</param>
        public void prepareCommandInterestName(Interest interest,
                                               WireFormat wireFormat)
        {
            double timestamp;

            lock (lastUsedTimestampLock_) {
                // nowOffsetMilliseconds_ is only used for testing.
                double now = net.named_data.jndn.util.Common.getNowMilliseconds() + nowOffsetMilliseconds_;
                timestamp = Math.Round(now, MidpointRounding.AwayFromZero);
                while (timestamp <= lastUsedTimestamp_)
                {
                    timestamp += 1.0d;
                }

                // Update the timestamp now while it is locked. In the small chance that
                //   signing fails, it just means that we have bumped the timestamp.
                lastUsedTimestamp_ = timestamp;
            }

            // The timestamp is encoded as a TLV nonNegativeInteger.
            TlvEncoder encoder = new TlvEncoder(8);

            encoder.writeNonNegativeInteger((long)timestamp);
            interest.getName().append(new Blob(encoder.getOutput(), false));

            // The random value is a TLV nonNegativeInteger too, but we know it is 8
            //   bytes, so we don't need to call the nonNegativeInteger encoder.
            ByteBuffer randomBuffer = ILOG.J2CsMapping.NIO.ByteBuffer.allocate(8);

            // Note: SecureRandom is thread safe.
            net.named_data.jndn.util.Common.getRandom().nextBytes(randomBuffer.array());
            interest.getName().append(new Blob(randomBuffer, false));
        }
Example #6
0
            onInterest
                (Name prefix, Interest interest, Face face, long interestFilterId,
                InterestFilter filter)
            {
                ++responseCount_;

                // Make and sign a Data packet.
                var data    = new Data(interest.getName());
                var content = "Echo " + interest.getName().toUri();

                data.setContent(new Blob(content));

                try {
                    keyChain_.sign(data, certificateName_);
                }
                catch (SecurityException exception) {
                    // Don't expect this to happen.
                    throw new SecurityException
                              ("SecurityException in sign: " + exception);
                }

                Console.Out.WriteLine("Sent content " + content);
                try {
                    face.putData(data);
                } catch (Exception ex) {
                    Console.Out.WriteLine("Echo: Exception in sending data " + ex);
                }
            }
        /// <summary>
        /// Get the keyLocatorName and timestamp from the command interest.
        /// </summary>
        ///
        /// <param name="interest">The Interest to parse.</param>
        /// <param name="state">On error, this calls state.fail and returns false.</param>
        /// <param name="keyLocatorName">Set keyLocatorName[0] to the KeyLocator name.</param>
        /// <param name="timestamp_0"></param>
        /// <returns>On success, return true. On error, call state.fail and return false.</returns>
        private static bool parseCommandInterest(Interest interest,
                                                 ValidationState state, Name[] keyLocatorName, double[] timestamp_0)
        {
            keyLocatorName[0] = new Name();
            timestamp_0[0]    = 0;

            Name name = interest.getName();

            if (name.size() < net.named_data.jndn.security.CommandInterestSigner.MINIMUM_SIZE)
            {
                state.fail(new ValidationError(net.named_data.jndn.security.v2.ValidationError.POLICY_ERROR,
                                               "Command interest name `" + interest.getName().toUri()
                                               + "` is too short"));
                return(false);
            }

            timestamp_0[0] = name.get(net.named_data.jndn.security.CommandInterestSigner.POS_TIMESTAMP).toNumber();

            keyLocatorName[0] = net.named_data.jndn.security.v2.ValidationPolicy.getKeyLocatorName(interest, state);
            if (state.isOutcomeFailed())
            {
                // Already failed.
                return(false);
            }

            return(true);
        }
Example #8
0
        public void testAppendParametersDigest()
        {
            Name     name     = new Name("/local/ndn/prefix");
            Interest interest = new Interest(name);

            Assert.AssertTrue(!interest.hasParameters());
            // No parameters yet, so it should do nothing.
            interest.appendParametersDigestToName();
            Assert.AssertEquals("/local/ndn/prefix", interest.getName().toUri());

            Blob parameters = new Blob(toBuffer(new int[] { 0x23, 0x01, 0xC0 }),
                                       false);

            interest.setParameters(parameters);
            Assert.AssertTrue(interest.hasParameters());
            interest.appendParametersDigestToName();
            Assert.AssertEquals(name.size() + 1, interest.getName().size());
            Assert.AssertTrue(interest.getName().getPrefix(-1).equals(name));
            int SHA256_LENGTH = 32;

            Assert.AssertEquals(SHA256_LENGTH, interest.getName().get(-1).getValue()
                                .size());

            Assert.AssertEquals(
                interest.getName().toUri(),
                "/local/ndn/prefix/"
                + "params-sha256=a16cc669b4c9ef6801e1569488513f9523ffb28a39e53aa6e11add8d00a413fc");
        }
Example #9
0
        public void onInterest(Name prefix, Interest interest, Face face, long interestFilterId,
                               InterestFilter filter)
        {
            string phoneId     = interest.getName().get(phoneHandler_.linkPrefix_.size()).toEscapedString();
            string linkContent = interest.getName().get(phoneHandler_.linkPrefix_.size() + 1).toEscapedString();

            Console.Out.WriteLine("User " + phoneId + " clicked link \"" + linkContent + "\"");

            var data    = new Data(interest.getName());
            var content = "User " + phoneId + " clicked link \"" + linkContent + "\"";

            data.setContent(new Blob(content));
            data.getMetaInfo().setFreshnessPeriod(2000);

            try {
                phoneHandler_.keyChain_.sign(data, phoneHandler_.certificateName_);
            } catch (SecurityException exception) {
                // Don't expect this to happen.
                throw new SecurityException("SecurityException in sign: " + exception);
            }

            Console.Out.WriteLine("Sent content " + content);
            try {
                phoneHandler_.face_.putData(data);
            } catch (Exception ex) {
                Console.Out.WriteLine("Echo: Exception in sending data " + ex);
            }
        }
        static internal void setNameComponent(Interest interest, int index,
                                              Name.Component component)
        {
            Name name = interest.getName().getPrefix(index);

            name.append(component);
            name.append(interest.getName().getSubName(name.size()));
            interest.setName(name);
        }
Example #11
0
        /// <summary>
        /// Find the certificate by the given interest.
        /// </summary>
        ///
        /// <param name="interest">The input interest object.</param>
        /// <returns>The found certificate which matches the interest, or null if not
        /// found. You must not modify the returned object. If you need to modify it,
        /// then make a copy.</returns>
        /// @note ChildSelector is not supported.
        public CertificateV2 find(Interest interest)
        {
            if (interest.getChildSelector() >= 0)
            {
                logger_.log(
                    ILOG.J2CsMapping.Util.Logging.Level.FINE,
                    "Certificate search using a ChildSelector is not supported. Searching as if this selector not specified");
            }

            if (interest.getName().size() > 0 &&
                interest.getName().get(-1).isImplicitSha256Digest())
            {
                logger_.log(ILOG.J2CsMapping.Util.Logging.Level.FINE,
                            "Certificate search using a name with an implicit digest is not yet supported");
            }

            refresh();

            Name firstKey = (Name)certificatesByName_.ceilingKey(interest
                                                                 .getName());

            if (firstKey == null)
            {
                return(null);
            }

            /* foreach */
            foreach (Object key  in  certificatesByName_.navigableKeySet().tailSet(
                         firstKey))
            {
                CertificateV2 certificate = ((CertificateCacheV2.Entry)certificatesByName_[(Name)key]).certificate_;
                if (!interest.getName().isPrefixOf(certificate.getName()))
                {
                    break;
                }

                try {
                    if (interest.matchesData(certificate))
                    {
                        return(certificate);
                    }
                } catch (EncodingException ex) {
                    // We don't expect this. Promote to Error.
                    throw new Exception("Error in Interest.matchesData: " + ex);
                }
            }

            return(null);
        }
Example #12
0
        public override void checkPolicy(Interest interest, ValidationState state,
                                         ValidationPolicy.ValidationContinuation continueValidation)
        {
            if (hasInnerPolicy())
            {
                throw new ValidatorConfigError(
                          "ValidationPolicyConfig must be a terminal inner policy");
            }

            if (shouldBypass_)
            {
                continueValidation.continueValidation(null, state);
                return;
            }

            Name keyLocatorName = net.named_data.jndn.security.v2.ValidationPolicy.getKeyLocatorName(interest, state);

            if (state.isOutcomeFailed())
            {
                // Already called state.fail() .
                return;
            }

            for (int i = 0; i < interestRules_.Count; ++i)
            {
                ConfigRule rule = interestRules_[i];

                if (rule.match(true, interest.getName()))
                {
                    if (rule.check(true, interest.getName(), keyLocatorName, state))
                    {
                        continueValidation
                        .continueValidation(new CertificateRequest(
                                                new Interest(keyLocatorName)), state);
                        return;
                    }
                    else
                    {
                        // rule.check failed and already called state.fail() .
                        return;
                    }
                }
            }

            state.fail(new ValidationError(net.named_data.jndn.security.v2.ValidationError.POLICY_ERROR,
                                           "No rule matched for interest `" + interest.getName().toUri()
                                           + "`"));
        }
Example #13
0
        public void onTimeout(Interest interest)
        {
            string trackId = interest.getName().get(consumerOuterInstance.producerNameComponents.trackIdOffset).toEscapedString();

            try {
                Track track;
                try {
                    track = consumerOuterInstance.activeTracks [trackId];
                } catch (KeyNotFoundException) {
                    track = consumerOuterInstance.pendingTracks [trackId];
                }
                int timeoutCnt = track.incTimeoutCnt();
                if (timeoutCnt <= consumerOuterInstance.config.trackTimeoutCntThreshold)
                {
                    consumerOuterInstance.face.expressInterest(interest, this, this);
                }
                else
                {
                    consumerOuterInstance.deactivateTrack(trackId);
                }
            } catch (KeyNotFoundException) {
                Debug.Log("Unexectedly adding track " + trackId + " because of expressed interest");
                // this shouldn't happen but lets add the track just in case
                // if we are here its probably because trackIDs are being mangled somehow
                consumerOuterInstance.addPendingTrack(trackId);
            }
        }
Example #14
0
            public void onInterest(Name prefix, Interest interest,
                                   Face face, long interestFilterId,
                                   InterestFilter filter)
            {
                Data data = outer_EncryptorV2.storage_.find(interest);

                if (data != null)
                {
                    net.named_data.jndn.encrypt.EncryptorV2.logger_.log(ILOG.J2CsMapping.Util.Logging.Level.INFO,
                                                                        "Serving {0} from InMemoryStorage",
                                                                        data.getName());
                    try {
                        face.putData(data);
                    } catch (IOException ex) {
                        net.named_data.jndn.encrypt.EncryptorV2.logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE,
                                                                            "Error in Face.putData: {0}", ex);
                    }
                }
                else
                {
                    net.named_data.jndn.encrypt.EncryptorV2.logger_.log(ILOG.J2CsMapping.Util.Logging.Level.INFO,
                                                                        "Didn't find CK data for {0}",
                                                                        interest.getName());
                    // TODO: Send NACK?
                }
            }
        /// <summary>
        /// Extract the signature information from the interest name.
        /// </summary>
        ///
        /// <param name="interest">The interest whose signature is needed.</param>
        /// <param name="wireFormat"></param>
        /// <returns>The Signature object, or null if can't decode.</returns>
        private static Signature extractSignature(Interest interest,
                                                  WireFormat wireFormat)
        {
            if (interest.getName().size() < 2)
            {
                return(null);
            }

            try {
                return(wireFormat.decodeSignatureInfoAndValue(interest.getName()
                                                              .get(-2).getValue().buf(), interest.getName().get(-1)
                                                              .getValue().buf(), false));
            } catch (EncodingException ex) {
                return(null);
            }
        }
Example #16
0
        public void testMaxNdnPacketSize()
        {
            // Construct an interest whose encoding is one byte larger than getMaxNdnPacketSize.
            int targetSize = net.named_data.jndn.Face.getMaxNdnPacketSize() + 1;
            // Start with an interest which is almost the right size.
            Interest interest = new Interest();

            interest.getName().append(new byte[targetSize]);
            int initialSize = interest.wireEncode().size();

            // Now replace the component with the desired size which trims off the extra encoding.
            interest.setName(new Name().append(new byte[targetSize
                                                        - (initialSize - targetSize)]));
            int interestSize = interest.wireEncode().size();

            Assert.AssertEquals("Wrong interest size for MaxNdnPacketSize", targetSize,
                                interestSize);

            CallbackCounter counter  = new CallbackCounter();
            bool            gotError = true;

            try {
                face.expressInterest(interest, counter, counter);
                gotError = false;
            } catch (Exception ex) {
            }
            if (!gotError)
            {
                Assert.Fail("expressInterest didn't throw an exception when the interest size exceeds getMaxNdnPacketSize()");
            }
        }
 onTimeout(Interest interest)
 {
     Console.Out.WriteLine("Time out for interest " + interest.getName().toUri());
     ++callbackCount_;
     if (callbackCount_ >= maxCallbackCount_)
     {
         done_.Set();
     }
 }
Example #18
0
 public virtual void onTimeout(Interest interest)
 {
     try {
         onError_.onError(net.named_data.jndn.util.SegmentFetcher.ErrorCode.INTEREST_TIMEOUT,
                          "Time out for interest " + interest.getName().toUri());
     } catch (Exception ex) {
         logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onError", ex);
     }
 }
        public void onInterest(Name prefix, Interest interest, Face face, long interestFilterId, InterestFilter filter)
        {
            logTextBox.text += "\n" + "Got a status interest with name: " + prefix.ToString();
            logTextBox.text += "\n";

            Data statusAckData = new Data(new Name(interest.getName()));

            statusAckData.setContent(new Blob("Status acknowledged"));
            face.putData(statusAckData);
        }
Example #20
0
            public override long expressInterest(Interest interest, OnData onData,
                                                 OnTimeout onTimeout, OnNetworkNack onNetworkNack,
                                                 WireFormat wireFormat)
            {
                Assert.AssertEquals(expectedInterest_, interest.getName());
                ++timeoutCount_[0];
                onTimeout.onTimeout(interest);

                return(0);
            }
        public void testFindByInterest()
        {
            anchorContainer.insert("group1", certificatePath1.FullName,
                                   400.0d);
            Interest interest = new Interest(identity1.getName());

            Assert.AssertTrue(anchorContainer.find(interest) != null);
            Interest interest1 = new Interest(identity1.getName().getPrefix(-1));

            Assert.AssertTrue(anchorContainer.find(interest1) != null);
            Interest interest2 = new Interest(
                new Name(identity1.getName()).appendVersion(1));

            Assert.AssertTrue(anchorContainer.find(interest2) == null);

            CertificateV2 certificate3 = fixture.addCertificate(
                identity1.getDefaultKey(), "3");
            CertificateV2 certificate4 = fixture.addCertificate(
                identity1.getDefaultKey(), "4");
            CertificateV2 certificate5 = fixture.addCertificate(
                identity1.getDefaultKey(), "5");

            CertificateV2 certificate3Copy = new CertificateV2(certificate3);

            anchorContainer.insert("group2", certificate3Copy);
            anchorContainer.insert("group3", certificate4);
            anchorContainer.insert("group4", certificate5);

            Interest      interest3        = new Interest(certificate3.getKeyName());
            CertificateV2 foundCertificate = anchorContainer.find(interest3);

            Assert.AssertTrue(foundCertificate != null);
            Assert.AssertTrue(interest3.getName().isPrefixOf(foundCertificate.getName()));
            Assert.AssertTrue(certificate3.getName().equals(foundCertificate.getName()));

            interest3.getExclude().appendComponent(
                certificate3.getName().get(net.named_data.jndn.security.v2.CertificateV2.ISSUER_ID_OFFSET));
            foundCertificate = anchorContainer.find(interest3);
            Assert.AssertTrue(foundCertificate != null);
            Assert.AssertTrue(interest3.getName().isPrefixOf(foundCertificate.getName()));
            Assert.AssertTrue(!foundCertificate.getName().equals(certificate3.getName()));
        }
Example #22
0
            public override long expressInterest(Interest interest, OnData onData,
                                                 OnTimeout onTimeout, OnNetworkNack onNetworkNack,
                                                 WireFormat wireFormat)
            {
                Assert.AssertEquals(expectedInterest_, interest.getName());

                bool gotInterestName = false;
                Name interestName    = null;

                for (int i = 0; i < 3; ++i)
                {
                    interestName = new Name(interest.getName());
                    if (i == 0)
                    {
                        interestName.append(timeMarkerFirstHop_);
                    }
                    else if (i == 1)
                    {
                        interestName.append(timeMarkerSecondHop_);
                    }
                    else if (i == 2)
                    {
                        interestName.append(timeMarkerThirdHop_);
                    }

                    // matchesName will check the Exclude.
                    if (interest.matchesName(interestName))
                    {
                        gotInterestName = true;
                        ++requestCount_[0];
                        break;
                    }
                }

                if (gotInterestName)
                {
                    onData.onData(interest,
                                  (Data)ILOG.J2CsMapping.Collections.Collections.Get(outer_TestProducer.encryptionKeys, interestName));
                }

                return(0);
            }
Example #23
0
 public void onNetworkNack(Interest interest,
                           NetworkNack networkNack)
 {
     contentKey.pendingInterest = 0;
     onError.onError(
         net.named_data.jndn.encrypt.EncryptError.ErrorCode.KdkRetrievalFailure,
         "Retrieval of KDK ["
         + interest.getName().toUri()
         + "] failed. Got NACK ("
         + networkNack.getReason() + ")");
 }
 public void getMatchedFilters(Interest interest,
                               ArrayList matchedFilters)
 {
     for (int i = 0; i < table_.Count; ++i)
     {
         InterestFilterTable.Entry entry = table_[i];
         if (entry.getFilter().doesMatch(interest.getName()))
         {
             ILOG.J2CsMapping.Collections.Collections.Add(matchedFilters, entry);
         }
     }
 }
Example #25
0
            public void onData(Interest ckInterest, Data ckData)
            {
                try {
                    contentKey.pendingInterest = 0;
                    // TODO: Verify that the key is legitimate.
                    Name[] kdkPrefix       = new Name[1];
                    Name[] kdkIdentityName = new Name[1];
                    Name[] kdkKeyName      = new Name[1];
                    if (!DecryptorV2.extractKdkInfoFromCkName(ckData.getName(),
                                                              ckInterest.getName(), onError,
                                                              kdkPrefix, kdkIdentityName, kdkKeyName))
                    {
                        // The error has already been reported.
                        return;
                    }

                    // Check if the KDK already exists.
                    PibIdentity kdkIdentity = null;
                    try {
                        kdkIdentity = outer_DecryptorV2.internalKeyChain_.getPib()
                                      .getIdentity(kdkIdentityName[0]);
                    } catch (Pib.Error ex) {
                    }
                    if (kdkIdentity != null)
                    {
                        PibKey kdkKey = null;
                        try {
                            kdkKey = kdkIdentity
                                     .getKey(kdkKeyName[0]);
                        } catch (Pib.Error ex_0) {
                        }
                        if (kdkKey != null)
                        {
                            // The KDK was already fetched and imported.
                            net.named_data.jndn.encrypt.DecryptorV2.logger_.log(
                                ILOG.J2CsMapping.Util.Logging.Level.INFO,
                                "KDK {0} already exists, so directly using it to decrypt the CK",
                                kdkKeyName);
                            outer_DecryptorV2.decryptCkAndProcessPendingDecrypts(
                                contentKey, ckData,
                                kdkKeyName[0], onError);
                            return;
                        }
                    }

                    outer_DecryptorV2.fetchKdk(contentKey, kdkPrefix[0], ckData,
                                               onError, net.named_data.jndn.encrypt.EncryptorV2.N_RETRIES);
                } catch (Exception ex_1) {
                    onError.onError(net.named_data.jndn.encrypt.EncryptError.ErrorCode.General,
                                    "Error in fetchCk onData: " + ex_1);
                }
            }
Example #26
0
 public void processInterest(Interest interest, OnData onData,
                             OnTimeout onTimeout, OnNetworkNack onNetworkNack)
 {
     if (interest.getName().isPrefixOf(expiredCertificate.getName()))
     {
         onData.onData(interest, expiredCertificate);
     }
     else
     {
         originalProcessInterest.processInterest(interest, onData,
                                                 onTimeout, onNetworkNack);
     }
 }
Example #27
0
        /// <summary>
        /// Append a timestamp component and a random value component to interest's
        /// name. This ensures that the timestamp is greater than the timestamp used in
        /// the previous call. Then use keyChain to sign the interest which appends a
        /// SignatureInfo component and a component with the signature bits. If the
        /// interest lifetime is not set, this sets it.
        /// </summary>
        ///
        /// <param name="interest">The interest whose name is append with components.</param>
        /// <param name="keyChain">The KeyChain for calling sign.</param>
        /// <param name="certificateName">The certificate name of the key to use for signing.</param>
        /// <param name="wireFormat"></param>
        public void generate(Interest interest, KeyChain keyChain,
                             Name certificateName, WireFormat wireFormat)
        {
            double timestamp;

            lock (lastTimestampLock_) {
                timestamp = Math.Round(net.named_data.jndn.util.Common.getNowMilliseconds(), MidpointRounding.AwayFromZero);
                while (timestamp <= lastTimestamp_)
                {
                    timestamp += 1.0d;
                }
                // Update the timestamp now while it is locked. In the small chance that
                //   signing fails, it just means that we have bumped the timestamp.
                lastTimestamp_ = timestamp;
            }

            // The timestamp is encoded as a TLV nonNegativeInteger.
            TlvEncoder encoder = new TlvEncoder(8);

            encoder.writeNonNegativeInteger((long)timestamp);
            interest.getName().append(new Blob(encoder.getOutput(), false));

            // The random value is a TLV nonNegativeInteger too, but we know it is 8 bytes,
            //   so we don't need to call the nonNegativeInteger encoder.
            ByteBuffer randomBuffer = ILOG.J2CsMapping.NIO.ByteBuffer.allocate(8);

            // Note: SecureRandom is thread safe.
            net.named_data.jndn.util.Common.getRandom().nextBytes(randomBuffer.array());
            interest.getName().append(new Blob(randomBuffer, false));

            keyChain.sign(interest, certificateName, wireFormat);

            if (interest.getInterestLifetimeMilliseconds() < 0)
            {
                // The caller has not set the interest lifetime, so set it here.
                interest.setInterestLifetimeMilliseconds(1000.0d);
            }
        }
Example #28
0
            public override long expressInterest(Interest interest, OnData onData,
                                                 OnTimeout onTimeout, OnNetworkNack onNetworkNack,
                                                 WireFormat wireFormat)
            {
                ++expressInterestCallCount_[0];

                Name interestName = new Name(interest.getName());

                interestName.append(timeMarker_);
                Assert.AssertEquals(true, outer_TestProducer.encryptionKeys.Contains(interestName));
                onData.onData(interest, (Data)ILOG.J2CsMapping.Collections.Collections.Get(outer_TestProducer.encryptionKeys, interestName));

                return(0);
            }
Example #29
0
        public void onTimeout(Interest interest)
        {
            //logTextBox.text += "\n" + "Time out for interest " + interest.getName().toUri();
            //logTextBox.text += "\n";

            Interest statusInterest = new Interest(interest.getName());

            statusInterest.setInterestLifetimeMilliseconds(2000);

            var onStatusData    = new onStatusDataClass(logTextBox, mNotifyScript, mFace);
            var onStatusTimeout = new onStatusTimeoutClass(logTextBox, mFace, mNotifyScript);

            mFace.expressInterest(statusInterest, onStatusData, onStatusTimeout);
        }
Example #30
0
        public override void checkPolicy(Interest interest, ValidationState state,
                                         ValidationPolicy.ValidationContinuation continueValidation)
        {
            Name keyLocatorName = net.named_data.jndn.security.v2.ValidationPolicy.getKeyLocatorName(interest, state);

            if (state.isOutcomeFailed())
            {
                // Already called state.fail().)
                return;
            }

            if (keyLocatorName.getPrefix(-2).isPrefixOf(interest.getName()))
            {
                continueValidation.continueValidation(new CertificateRequest(
                                                          new Interest(keyLocatorName)), state);
            }
            else
            {
                state.fail(new ValidationError(net.named_data.jndn.security.v2.ValidationError.INVALID_KEY_LOCATOR,
                                               "Interest signing policy violation for "
                                               + interest.getName().toUri() + " by "
                                               + keyLocatorName.toUri()));
            }
        }
 public void onTimeout(Interest interest)
 {
     ++callbackCount_;
     Console.Out.WriteLine("Time out for interest " + interest.getName().toUri());
 }