Exemplo n.º 1
0
        static void Main(string[] args)
        {
            try {
            var face = new Face
              (new TcpTransport(), new TcpTransport.ConnectionInfo("localhost"));

            var counter = new Counter1();

            Console.Out.WriteLine("Enter a word to echo:");
            var word = Console.In.ReadLine();

            var name = new Name("/testecho");
            name.append(word);
            Console.Out.WriteLine("Express name " + name.toUri());
            face.expressInterest(name, counter, counter);

            // The main event loop.
            while (counter.callbackCount_ < 1) {
              face.processEvents();

              // We need to sleep for a few milliseconds so we don't use 100% of the CPU.
              System.Threading.Thread.Sleep(5);
            }
              } catch (Exception e) {
            Console.Out.WriteLine("exception: " + e.Message);
              }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            try {
            var face = new Face("aleph.ndn.ucla.edu");

            var counter = new Counter();

            // Try to fetch anything.
            var name1 = new Name("/");
            Console.Out.WriteLine("Express name " + name1.toUri());
            face.expressInterest(name1, counter, counter);

            // Try to fetch using a known name.
            var name2 = new Name("/ndn/edu/ucla/remap/demo/ndn-js-test/hello.txt/%FDU%8D%9DM");
            Console.Out.WriteLine("Express name " + name2.toUri());
            face.expressInterest(name2, counter, counter);

            // Expect this to time out.
            var name3 = new Name("/test/timeout");
            Console.Out.WriteLine("Express name " + name3.toUri());
            face.expressInterest(name3, counter, counter);

            // The main event loop.
            while (counter.callbackCount_ < 3) {
              face.processEvents();
              // We need to sleep for a few milliseconds so we don't use 100% of the CPU.
              System.Threading.Thread.Sleep(5);
            }
              } catch (Exception e) {
            Console.Out.WriteLine("exception: " + e.Message);
              }
        }
        /// <summary>
        /// Delete a pair of asymmetric keys. If the key doesn't exist, do nothing.
        /// </summary>
        ///
        /// <param name="keyName">The name of the key pair.</param>
        public override void deleteKeyPair(Name keyName)
        {
            String keyUri = keyName.toUri();

            ILOG.J2CsMapping.Collections.Collections.Remove(publicKeyStore_,keyUri);
            ILOG.J2CsMapping.Collections.Collections.Remove(privateKeyStore_,keyUri);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Determine if the provided NDN regex matches the given Name.
        /// </summary>
        ///
        /// <param name="pattern">The NDN regex.</param>
        /// <param name="name">The Name to match against the regex.</param>
        /// <returns>The Matcher object from Pattern.matcher after the first find, or
        /// null if the pattern does not match.</returns>
        public static Matcher match(String pattern, Name name)
        {
            String nameUri = name.toUri();

            pattern = sanitizeSets(pattern);

            pattern = pattern.Replace("<>", "(?:<.+?>)");
            pattern = pattern.Replace(">", "");
            // Explicitly use regex replace for portability.
            pattern = ILOG.J2CsMapping.Text.Pattern.Compile("<(?!!)").Matcher(pattern).replaceAll("/");

            Matcher match = ILOG.J2CsMapping.Text.Pattern.Compile(pattern).Matcher(nameUri);
            if (match.Find())
                return match;
            else
                return null;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Fetch a certificate from the cache.
        /// </summary>
        ///
        /// <param name="certificateName"></param>
        /// <returns>A new copy of the IdentityCertificate, or null if not found.</returns>
        public IdentityCertificate getCertificate(Name certificateName)
        {
            Blob certData = (Blob) ILOG.J2CsMapping.Collections.Collections.Get(cache_,certificateName.toUri());
            if (certData == null)
                return null;

            IdentityCertificate cert = new IdentityCertificate();
            try {
                cert.wireDecode(certData.buf());
            } catch (EncodingException ex) {
                ILOG.J2CsMapping.Util.Logging.Logger.getLogger(typeof(CertificateCache).FullName).log(
                        ILOG.J2CsMapping.Util.Logging.Level.SEVERE, null, ex);
                throw new Exception(ex.Message);
            }

            return cert;
        }
        /// <summary>
        /// Get the public key DER blob from the identity storage.
        /// </summary>
        ///
        /// <param name="keyName">The name of the requested public key.</param>
        /// <returns>The DER Blob.</returns>
        /// <exception cref="System.Security.SecurityException">if the key doesn't exist.</exception>
        public override Blob getKey(Name keyName)
        {
            if (keyName.size() == 0)
                throw new SecurityException(
                        "MemoryIdentityStorage::getKey: Empty keyName");

            MemoryIdentityStorage.KeyRecord  keyRecord = (MemoryIdentityStorage.KeyRecord ) ILOG.J2CsMapping.Collections.Collections.Get(keyStore_,keyName.toUri());
            if (keyRecord == null)
                throw new SecurityException(
                        "MemoryIdentityStorage::getKey: The key does not exist");

            return keyRecord.getKeyDer();
        }
        /// <summary>
        /// Set the private key for the keyName.
        /// </summary>
        ///
        /// <param name="keyName">The key name.</param>
        /// <param name="keyType">The KeyType, such as KeyType.RSA.</param>
        /// <param name="privateKeyDer">The private key DER byte buffer.</param>
        /// <exception cref="System.Security.SecurityException">if can't decode the key DER.</exception>
        public void setPrivateKeyForKeyName(Name keyName, KeyType keyType,
				ByteBuffer privateKeyDer)
        {
            ILOG.J2CsMapping.Collections.Collections.Put(privateKeyStore_,keyName.toUri(),new MemoryPrivateKeyStorage.PrivateKey (keyType,
                            privateKeyDer));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Get the public key name from the full certificate name.
        /// </summary>
        ///
        /// <param name="certificateName">The full certificate name.</param>
        /// <returns>The related public key name.</returns>
        public static Name certificateNameToPublicKeyName(Name certificateName)
        {
            String idString = "ID-CERT";
            bool foundIdString = false;
            int idCertComponentIndex = certificateName.size() - 1;
            for (; idCertComponentIndex + 1 > 0; --idCertComponentIndex) {
                if (certificateName.get(idCertComponentIndex).toEscapedString()
                        .equals(idString)) {
                    foundIdString = true;
                    break;
                }
            }

            if (!foundIdString)
                throw new Exception("Incorrect identity certificate name "
                        + certificateName.toUri());

            Name tempName = certificateName.getSubName(0, idCertComponentIndex);
            String keyString = "KEY";
            bool foundKeyString = false;
            int keyComponentIndex = 0;
            for (; keyComponentIndex < tempName.size(); keyComponentIndex++) {
                if (tempName.get(keyComponentIndex).toEscapedString()
                        .equals(keyString)) {
                    foundKeyString = true;
                    break;
                }
            }

            if (!foundKeyString)
                throw new Exception("Incorrect identity certificate name "
                        + certificateName.toUri());

            return tempName.getSubName(0, keyComponentIndex).append(
                    tempName.getSubName(keyComponentIndex + 1, tempName.size()
                            - keyComponentIndex - 1));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Call registerPrefix on the Face given to the constructor so that this
        /// MemoryContentCache will answer interests whose name has the prefix.
        /// Alternatively, if the Face's registerPrefix has already been called, then
        /// you can call this object's setInterestFilter.
        /// </summary>
        ///
        /// <param name="prefix">The Name for the prefix to register. This copies the Name.</param>
        /// <param name="onRegisterFailed">NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        /// <param name="onRegisterSuccess">receives a success message from the forwarder. If onRegisterSuccess is null, this does not use it. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        /// <param name="onDataNotFound">onDataNotFound.onInterest(prefix, interest, face, interestFilterId, filter). Your callback can find the Data packet for the interest and call face.putData(data).  If your callback cannot find the Data packet, it can optionally call storePendingInterest(interest, face) to store the pending interest in this object to be satisfied by a later call to add(data). If you want to automatically store all pending interests, you can simply use getStorePendingInterest() for onDataNotFound. If onDataNotFound is null, this does not use it. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        /// <param name="flags">See Face.registerPrefix.</param>
        /// <param name="wireFormat">See Face.registerPrefix.</param>
        /// <exception cref="IOException">For I/O error in sending the registration request.</exception>
        /// <exception cref="System.Security.SecurityException">If signing a command interest for NFD and cannotfind the private key for the certificateName.</exception>
        public void registerPrefix(Name prefix,
				OnRegisterFailed onRegisterFailed,
				OnRegisterSuccess onRegisterSuccess,
				OnInterestCallback onDataNotFound, ForwardingFlags flags,
				WireFormat wireFormat)
        {
            if (onDataNotFound != null)
                ILOG.J2CsMapping.Collections.Collections.Put(onDataNotFoundForPrefix_,prefix.toUri(),onDataNotFound);
            long registeredPrefixId = face_.registerPrefix(prefix, this,
                    onRegisterFailed, onRegisterSuccess, flags, wireFormat);
            ILOG.J2CsMapping.Collections.Collections.Add(registeredPrefixIdList_,registeredPrefixId);
        }
Exemplo n.º 10
0
        public void testAppend()
        {
            // could possibly split this into different tests
            String uri = "/localhost/user/folders/files/%00%0F";
            Name name = new Name(uri);
            Name name2 = new Name("/localhost").append(new Name("/user/folders/"));
            Assert.AssertEquals("Name constructed by appending names has " + name2.size()
                    + " components instead of 3", 3, name2.size());
            Assert.AssertTrue("Name constructed with append has wrong suffix", name2
                    .get(2).getValue().equals(new Blob("folders")));
            name2 = name2.append("files");
            Assert.AssertEquals("Name constructed by appending string has " + name2.size()
                    + " components instead of 4", 4, name2.size());
            name2 = name2.appendSegment(15);
            Assert.AssertTrue(
                    "Name constructed by appending segment has wrong segment value",
                    name2.get(4).getValue()
                            .equals(new Blob(new int[] { 0x00, 0x0F })));

            Assert.AssertTrue(
                    "Name constructed with append is not equal to URI constructed name",
                    name2.equals(name));
            Assert.AssertEquals("Name constructed with append has wrong URI",
                    name.toUri(), name2.toUri());
        }
Exemplo n.º 11
0
 /// <summary>
 /// Remove a certificate from the cache. This does nothing if it is not present.
 /// </summary>
 ///
 /// <param name="certificateName"></param>
 public void deleteCertificate(Name certificateName)
 {
     ILOG.J2CsMapping.Collections.Collections.Remove(cache_,certificateName.toUri());
 }
Exemplo n.º 12
0
        /// <summary>
        /// Add a public key to the identity storage. Also call addIdentity to ensure
        /// that the identityName for the key exists. However, if the key already
        /// exists, do nothing.
        /// </summary>
        ///
        /// <param name="keyName">The name of the public key to be added.</param>
        /// <param name="keyType">Type of the public key to be added.</param>
        /// <param name="publicKeyDer">A blob of the public key DER to be added.</param>
        public override void addKey(Name keyName, KeyType keyType, Blob publicKeyDer)
        {
            if (keyName.size() == 0)
                return;

            if (doesKeyExist(keyName))
                return;

            Name identityName = keyName.getSubName(0, keyName.size() - 1);

            addIdentity(identityName);

            ILOG.J2CsMapping.Collections.Collections.Put(keyStore_,keyName.toUri(),new MemoryIdentityStorage.KeyRecord (keyType, publicKeyDer));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Add a new identity. Do nothing if the identity already exists.
        /// </summary>
        ///
        /// <param name="identityName">The identity name to be added.</param>
        public override void addIdentity(Name identityName)
        {
            String identityUri = identityName.toUri();
            if (identityStore_.Contains(identityUri))
                return;

            ILOG.J2CsMapping.Collections.Collections.Put(identityStore_,identityUri,new MemoryIdentityStorage.IdentityRecord ());
        }
Exemplo n.º 14
0
        /// <summary>
        /// Generate a self-signed certificate for a public key.
        /// </summary>
        ///
        /// <param name="keyName">The name of the public key.</param>
        /// <returns>The generated certificate.</returns>
        public IdentityCertificate selfSign(Name keyName)
        {
            IdentityCertificate certificate = new IdentityCertificate();

            Blob keyBlob = identityStorage_.getKey(keyName);
            PublicKey publicKey = new PublicKey(keyBlob);

            Calendar calendar = ILOG.J2CsMapping.Util.Calendar.getInstance();
            double notBefore = (double) calendar.getTimeInMillis();
            calendar.add(ILOG.J2CsMapping.Util.Calendar.YEAR, 2);
            double notAfter = (double) calendar.getTimeInMillis();

            certificate.setNotBefore(notBefore);
            certificate.setNotAfter(notAfter);

            Name certificateName = keyName.getPrefix(-1).append("KEY")
                    .append(keyName.get(-1)).append("ID-CERT")
                    .appendVersion((long) certificate.getNotBefore());
            certificate.setName(certificateName);

            certificate.setPublicKeyInfo(publicKey);
            certificate.addSubjectDescription(new CertificateSubjectDescription(
                    "2.5.4.41", keyName.toUri()));
            try {
                certificate.encode();
            } catch (DerEncodingException ex) {
                // We don't expect this to happen.
                ILOG.J2CsMapping.Util.Logging.Logger.getLogger(typeof(IdentityManager).FullName).log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE,
                        null, ex);
                return null;
            } catch (DerDecodingException ex_0) {
                // We don't expect this to happen.
                ILOG.J2CsMapping.Util.Logging.Logger.getLogger(typeof(IdentityManager).FullName).log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE,
                        null, ex_0);
                return null;
            }

            signByCertificate(certificate, certificate.getName());

            return certificate;
        }
 /// <summary>
 /// Check if a particular key exists.
 /// </summary>
 ///
 /// <param name="keyName">The name of the key.</param>
 /// <param name="keyClass"></param>
 /// <returns>True if the key exists, otherwise false.</returns>
 public override bool doesKeyExist(Name keyName, KeyClass keyClass)
 {
     if (keyClass == net.named_data.jndn.security.KeyClass.PUBLIC)
         return publicKeyStore_.Contains(keyName.toUri());
     else if (keyClass == net.named_data.jndn.security.KeyClass.PRIVATE)
         return privateKeyStore_.Contains(keyName.toUri());
     else
         // KeyClass.SYMMETRIC not implemented yet.
         return false;
 }
        /// <summary>
        /// Fetch the private key for keyName and sign the data, returning a signature
        /// Blob.
        /// </summary>
        ///
        /// <param name="data">Pointer the input byte buffer to sign.</param>
        /// <param name="keyName">The name of the signing key.</param>
        /// <param name="digestAlgorithm">the digest algorithm.</param>
        /// <returns>The signature Blob.</returns>
        /// <exception cref="System.Security.SecurityException"></exception>
        public override Blob sign(ByteBuffer data, Name keyName,
				DigestAlgorithm digestAlgorithm)
        {
            if (digestAlgorithm != net.named_data.jndn.security.DigestAlgorithm.SHA256)
                throw new SecurityException(
                        "MemoryPrivateKeyStorage.sign: Unsupported digest algorithm");

            // Find the private key and sign.
            MemoryPrivateKeyStorage.PrivateKey  privateKey = (MemoryPrivateKeyStorage.PrivateKey ) ILOG.J2CsMapping.Collections.Collections.Get(privateKeyStore_,keyName
                            .toUri());
            if (privateKey == null)
                throw new SecurityException(
                        "MemoryPrivateKeyStorage: Cannot find private key "
                                + keyName.toUri());

            System.SecuritySignature signature = null;
            if (privateKey.getKeyType() == net.named_data.jndn.security.KeyType.RSA) {
                try {
                    signature = System.SecuritySignature
                            .getInstance("SHA256withRSA");
                } catch (Exception e) {
                    // Don't expect this to happen.
                    throw new SecurityException(
                            "SHA256withRSA algorithm is not supported");
                }
            } else if (privateKey.getKeyType() == net.named_data.jndn.security.KeyType.ECDSA) {
                try {
                    signature = System.SecuritySignature
                            .getInstance("SHA256withECDSA");
                } catch (Exception e_0) {
                    // Don't expect this to happen.
                    throw new SecurityException(
                            "SHA256withECDSA algorithm is not supported");
                }
            } else
                // We don't expect this to happen.
                throw new SecurityException("Unrecognized private key type");

            try {
                signature.initSign(privateKey.getPrivateKey());
            } catch (InvalidKeyException exception) {
                throw new SecurityException("InvalidKeyException: "
                        + exception.Message);
            }
            try {
                signature.update(data);
                return new Blob(signature.sign(), false);
            } catch (SignatureException exception_1) {
                throw new SecurityException("SignatureException: "
                        + exception_1.Message);
            }
        }
        /// <summary>
        /// Set the public key for the keyName.
        /// </summary>
        ///
        /// <param name="keyName">The key name.</param>
        /// <param name="keyType">The KeyType, such as KeyType.RSA.</param>
        /// <param name="publicKeyDer">The public key DER byte buffer.</param>
        /// <exception cref="System.Security.SecurityException">if can't decode the key DER.</exception>
        public void setPublicKeyForKeyName(Name keyName, KeyType keyType,
				ByteBuffer publicKeyDer)
        {
            ILOG.J2CsMapping.Collections.Collections.Put(publicKeyStore_,keyName.toUri(),new PublicKey(new Blob(
                            publicKeyDer, true)));
        }
Exemplo n.º 18
0
        /// <summary>
        /// Set the default key name for the specified identity.
        /// </summary>
        ///
        /// <param name="keyName">The key name.</param>
        /// <param name="certificateName">The certificate name.</param>
        public override void setDefaultCertificateNameForKey(Name keyName,
				Name certificateName)
        {
            String key = keyName.toUri();
            if (keyStore_.Contains(key)) {
                ((MemoryIdentityStorage.KeyRecord ) ILOG.J2CsMapping.Collections.Collections.Get(keyStore_,key)).setDefaultCertificate(new Name(
                        certificateName));
            }
        }
Exemplo n.º 19
0
 /// <summary>
 /// Set the default identity.  If the identityName does not exist, then clear
 /// the default identity so that getDefaultIdentity() throws an exception.
 /// </summary>
 ///
 /// <param name="identityName">The default identity name.</param>
 public override void setDefaultIdentity(Name identityName)
 {
     String identityUri = identityName.toUri();
     if (identityStore_.Contains(identityUri))
         defaultIdentity_ = identityUri;
     else
         // The identity doesn't exist, so clear the default.
         defaultIdentity_ = "";
 }
Exemplo n.º 20
0
 /// <summary>
 /// Check if the specified certificate already exists.
 /// </summary>
 ///
 /// <param name="certificateName">The name of the certificate.</param>
 /// <returns>True if the certificate exists, otherwise false.</returns>
 public override bool doesCertificateExist(Name certificateName)
 {
     return certificateStore_.Contains(certificateName.toUri());
 }
Exemplo n.º 21
0
 /// <summary>
 /// Check if the specified identity already exists.
 /// </summary>
 ///
 /// <param name="identityName">The identity name.</param>
 /// <returns>True if the identity exists, otherwise false.</returns>
 public override bool doesIdentityExist(Name identityName)
 {
     return identityStore_.Contains(identityName.toUri());
 }
Exemplo n.º 22
0
 /// <summary>
 /// Check if the specified key already exists.
 /// </summary>
 ///
 /// <param name="keyName">The name of the key.</param>
 /// <returns>true if the key exists, otherwise false.</returns>
 public override bool doesKeyExist(Name keyName)
 {
     return keyStore_.Contains(keyName.toUri());
 }
Exemplo n.º 23
0
 public void testUriConstructor()
 {
     Name name = new Name(expectedURI);
     Assert.AssertEquals("Constructed name has " + name.size()
             + " components instead of 3", 3, name.size());
     Assert.AssertEquals("URI is incorrect", expectedURI, name.toUri());
 }
Exemplo n.º 24
0
        /// <summary>
        /// Get a certificate from the identity storage.
        /// </summary>
        ///
        /// <param name="certificateName">The name of the requested certificate.</param>
        /// <returns>The requested certificate.</returns>
        /// <exception cref="System.Security.SecurityException">if the certificate doesn't exist.</exception>
        public override IdentityCertificate getCertificate(Name certificateName)
        {
            Blob certificateDer = (Blob) ILOG.J2CsMapping.Collections.Collections.Get(certificateStore_,certificateName
                            .toUri());
            if (certificateDer == null)
                throw new SecurityException(
                        "MemoryIdentityStorage::getKey: The certificate does not exist");

            IdentityCertificate certificate = new IdentityCertificate();
            try {
                certificate.wireDecode(certificateDer);
            } catch (EncodingException ex) {
                throw new SecurityException(
                        "MemoryIdentityStorage::getKey: The certificate cannot be decoded");
            }
            return certificate;
        }
Exemplo n.º 25
0
        public void onInterest(Name prefix, Interest interest, Face face,
				long interestFilterId, InterestFilter filter)
        {
            doCleanup();

            Name.Component selectedComponent = null;
            Blob selectedEncoding = null;
            // We need to iterate over both arrays.
            int totalSize = staleTimeCache_.Count + noStaleTimeCache_.Count;
            for (int i = 0; i < totalSize; ++i) {
                MemoryContentCache.Content  content;
                if (i < staleTimeCache_.Count)
                    content = staleTimeCache_[i];
                else
                    // We have iterated over the first array. Get from the second.
                    content = noStaleTimeCache_[i - staleTimeCache_.Count];

                if (interest.matchesName(content.getName())) {
                    if (interest.getChildSelector() < 0) {
                        // No child selector, so send the first match that we have found.
                        try {
                            face.send(content.getDataEncoding());
                        } catch (IOException ex) {
                            ILOG.J2CsMapping.Util.Logging.Logger.getLogger(typeof(MemoryContentCache).FullName)
                                    .log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, null, ex);
                        }
                        return;
                    } else {
                        // Update selectedEncoding based on the child selector.
                        Name.Component component;
                        if (content.getName().size() > interest.getName().size())
                            component = content.getName().get(
                                    interest.getName().size());
                        else
                            component = emptyComponent_;

                        bool gotBetterMatch = false;
                        if (selectedEncoding == null)
                            // Save the first match.
                            gotBetterMatch = true;
                        else {
                            if (interest.getChildSelector() == 0) {
                                // Leftmost child.
                                if (component.compare(selectedComponent) < 0)
                                    gotBetterMatch = true;
                            } else {
                                // Rightmost child.
                                if (component.compare(selectedComponent) > 0)
                                    gotBetterMatch = true;
                            }
                        }

                        if (gotBetterMatch) {
                            selectedComponent = component;
                            selectedEncoding = content.getDataEncoding();
                        }
                    }
                }
            }

            if (selectedEncoding != null) {
                // We found the leftmost or rightmost child.
                try {
                    face.send(selectedEncoding);
                } catch (IOException ex_0) {
                    ILOG.J2CsMapping.Util.Logging.Logger.getLogger(typeof(MemoryContentCache).FullName).log(
                            ILOG.J2CsMapping.Util.Logging.Level.SEVERE, null, ex_0);
                }
            } else {
                // Call the onDataNotFound callback (if defined).
                Object onDataNotFound = ILOG.J2CsMapping.Collections.Collections.Get(onDataNotFoundForPrefix_,prefix.toUri());
                if (onDataNotFound != null) {
                    try {
                        ((OnInterestCallback) onDataNotFound).onInterest(prefix,
                                interest, face, interestFilterId, filter);
                    } catch (Exception ex_1) {
                        logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onDataNotFound", ex_1);
                    }
                }
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// Determine whether the timestamp from the interest is newer than the last
        /// use of this key, or within the grace interval on first use.
        /// </summary>
        ///
        /// <param name="keyName">The name of the public key used to sign the interest.</param>
        /// <param name="timestamp">The timestamp extracted from the interest name.</param>
        /// <param name="failureReason"></param>
        /// <returns>True if timestamp is fresh as described above.</returns>
        private bool interestTimestampIsFresh(Name keyName, double timestamp,
				String[] failureReason)
        {
            String keyNameUri = keyName.toUri();
            if (!keyTimestamps_.Contains(keyNameUri)) {
                double now = net.named_data.jndn.util.Common.getNowMilliseconds();
                double notBefore = now - keyGraceInterval_;
                double notAfter = now + keyGraceInterval_;

                if (!(timestamp > notBefore && timestamp < notAfter)) {
                    failureReason[0] = "The command interest timestamp is not within the first use grace period of"
                            + keyGraceInterval_ + " milliseconds.";
                    return false;
                }
                return true;
            } else {
                double lastTimestamp = (double) (Double) ILOG.J2CsMapping.Collections.Collections.Get(keyTimestamps_,keyNameUri);
                if (timestamp <= lastTimestamp) {
                    failureReason[0] = "The command interest timestamp is not newer than the previous timestamp";
                    return false;
                }
                return true;
            }
        }
Exemplo n.º 27
0
        /// <summary>
        /// Call setInterestFilter on the Face given to the constructor so that this
        /// MemoryContentCache will answer interests whose name has the prefix.
        /// </summary>
        ///
        /// <param name="prefix"></param>
        /// <param name="onDataNotFound">onDataNotFound.onInterest(prefix, interest, face, interestFilterId, filter). Your callback can find the Data packet for the interest and call face.putData(data).  Note: If you call setInterestFilter multiple times where filter.getPrefix() is the same, it is undetermined which onDataNotFound will be called. If your callback cannot find the Data packet, it can optionally call storePendingInterest(interest, face) to store the pending interest in this object to be satisfied by a later call to add(data). If you want to automatically store all pending interests, you can simply use getStorePendingInterest() for onDataNotFound. If onDataNotFound is null, this does not use it. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        public void setInterestFilter(Name prefix,
				OnInterestCallback onDataNotFound)
        {
            if (onDataNotFound != null)
                ILOG.J2CsMapping.Collections.Collections.Put(onDataNotFoundForPrefix_,prefix.toUri(),onDataNotFound);
            long interestFilterId = face_.setInterestFilter(prefix, this);
            ILOG.J2CsMapping.Collections.Collections.Add(interestFilterIdList_,interestFilterId);
        }
Exemplo n.º 28
0
 /// <summary>
 /// Get the default key name for the specified identity.
 /// </summary>
 ///
 /// <param name="identityName">The identity name.</param>
 /// <returns>The default key name.</returns>
 /// <exception cref="System.Security.SecurityException">if the default key name for the identity is not set.</exception>
 public override Name getDefaultKeyNameForIdentity(Name identityName)
 {
     String identity = identityName.toUri();
     if (identityStore_.Contains(identity)) {
         if (((MemoryIdentityStorage.IdentityRecord ) ILOG.J2CsMapping.Collections.Collections.Get(identityStore_,identity)).hasDefaultKey()) {
             return ((MemoryIdentityStorage.IdentityRecord ) ILOG.J2CsMapping.Collections.Collections.Get(identityStore_,identity))
                     .getDefaultKey();
         } else {
             throw new SecurityException("No default key set.");
         }
     } else {
         throw new SecurityException("Identity not found.");
     }
 }
Exemplo n.º 29
0
 /// <summary>
 /// Get the default certificate name for the specified key.
 /// </summary>
 ///
 /// <param name="keyName">The key name.</param>
 /// <returns>The default certificate name.</returns>
 /// <exception cref="System.Security.SecurityException">if the default certificate name for the key nameis not set.</exception>
 public override Name getDefaultCertificateNameForKey(Name keyName)
 {
     String key = keyName.toUri();
     if (keyStore_.Contains(key)) {
         if (((MemoryIdentityStorage.KeyRecord ) ILOG.J2CsMapping.Collections.Collections.Get(keyStore_,key)).hasDefaultCertificate()) {
             return ((MemoryIdentityStorage.KeyRecord ) ILOG.J2CsMapping.Collections.Collections.Get(keyStore_,key)).getDefaultCertificate();
         } else {
             throw new SecurityException("No default certificate set.");
         }
     } else {
         throw new SecurityException("Key not found.");
     }
 }
 /// <summary>
 /// Get the public key
 /// </summary>
 ///
 /// <param name="keyName">The name of public key.</param>
 /// <returns>The public key.</returns>
 /// <exception cref="System.Security.SecurityException"></exception>
 public override PublicKey getPublicKey(Name keyName)
 {
     PublicKey publicKey = (PublicKey) ILOG.J2CsMapping.Collections.Collections.Get(publicKeyStore_,keyName.toUri());
     if (publicKey == null)
         throw new SecurityException(
                 "MemoryPrivateKeyStorage: Cannot find public key "
                         + keyName.toUri());
     return publicKey;
 }