public void testBadCertificateName()
        {
            Interest   interest1  = fixture_.makeCommandInterest(fixture_.identity_);
            KeyLocator keyLocator = new KeyLocator();

            keyLocator.setType(net.named_data.jndn.KeyLocatorType.KEYNAME);
            keyLocator.setKeyName(new Name("/bad/cert/name"));
            Sha256WithRsaSignature signatureInfo = new Sha256WithRsaSignature();

            signatureInfo.setKeyLocator(keyLocator);

            setNameComponent(interest1, net.named_data.jndn.security.CommandInterestSigner.POS_SIGNATURE_INFO,
                             net.named_data.jndn.encoding.TlvWireFormat.get().encodeSignatureInfo(signatureInfo));
            validateExpectFailure(interest1, "Should fail (bad certificate name)");
        }
        public void testBadKeyLocatorType()
        {
            Interest   interest1  = fixture_.makeCommandInterest(fixture_.identity_);
            KeyLocator keyLocator = new KeyLocator();

            keyLocator.setType(net.named_data.jndn.KeyLocatorType.KEY_LOCATOR_DIGEST);
            keyLocator.setKeyData(new Blob(new int[] { 0xdd, 0xdd, 0xdd, 0xdd,
                                                       0xdd, 0xdd, 0xdd, 0xdd }));
            Sha256WithRsaSignature signatureInfo = new Sha256WithRsaSignature();

            signatureInfo.setKeyLocator(keyLocator);

            setNameComponent(interest1, net.named_data.jndn.security.CommandInterestSigner.POS_SIGNATURE_INFO,
                             net.named_data.jndn.encoding.TlvWireFormat.get().encodeSignatureInfo(signatureInfo));
            validateExpectFailure(interest1, "Should fail (bad KeyLocator type)");
        }
Пример #3
0
        private static Sha256WithRsaSignature generateFakeSignature()
        {
            Sha256WithRsaSignature signatureInfo = new Sha256WithRsaSignature();

            Name       keyLocatorName = new Name("/ndn/site1/KEY/ksk-2516425377094");
            KeyLocator keyLocator     = new KeyLocator();

            keyLocator.setType(net.named_data.jndn.KeyLocatorType.KEYNAME);
            keyLocator.setKeyName(keyLocatorName);
            signatureInfo.setKeyLocator(keyLocator);

            ValidityPeriod period = new ValidityPeriod();

            period.setPeriod(net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20141111T050000"),
                             net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20141111T060000"));
            signatureInfo.setValidityPeriod(period);

            Blob block2 = new Blob(SIG_VALUE, false);

            signatureInfo.setSignature(block2);

            return(signatureInfo);
        }
Пример #4
0
        benchmarkEncodeDataSeconds
            (int nIterations, bool useComplex, bool useCrypto, KeyType keyType,
            Blob[] encoding)
        {
            Name name;
            Blob content;

            if (useComplex)
            {
                // Use a large name and content.
                name = new Name
                           ("/ndn/ucla.edu/apps/lwndn-test/numbers.txt/%FD%05%05%E8%0C%CE%1D/%00");

                StringBuilder contentStream = new StringBuilder();
                int           count         = 1;
                contentStream.append(count++);
                while (contentStream.toString().Length < 1115)
                {
                    contentStream.append(" ").append(count++);
                }
                content = new Blob(contentStream.toString());
            }
            else
            {
                // Use a small name and content.
                name    = new Name("/test");
                content = new Blob("abc");
            }
            Name.Component finalBlockId =
                new Name.Component(new Blob(new byte[] { (byte)0 }));

            // Initialize the KeyChain storage in case useCrypto is true.
            MemoryIdentityStorage   identityStorage   = new MemoryIdentityStorage();
            MemoryPrivateKeyStorage privateKeyStorage = new MemoryPrivateKeyStorage();
            KeyChain keyChain = new KeyChain
                                    (new IdentityManager(identityStorage, privateKeyStorage),
                                    new SelfVerifyPolicyManager(identityStorage));
            Name keyName         = new Name("/testname/DSK-123");
            Name certificateName = keyName.getSubName(0, keyName.size() - 1).append
                                       ("KEY").append(keyName.get(-1)).append("ID-CERT").append("0");

            privateKeyStorage.setKeyPairForKeyName
                (keyName, KeyType.RSA, new ByteBuffer(DEFAULT_RSA_PUBLIC_KEY_DER),
                new ByteBuffer(DEFAULT_RSA_PRIVATE_KEY_DER));

            Blob signatureBits = new Blob(new byte[256]);
            Blob emptyBlob     = new Blob(new byte[0]);

            double start = getNowSeconds();

            for (int i = 0; i < nIterations; ++i)
            {
                Data data = new Data(name);
                data.setContent(content);
                if (useComplex)
                {
                    data.getMetaInfo().setFreshnessPeriod(30000);
                    data.getMetaInfo().setFinalBlockId(finalBlockId);
                }

                if (useCrypto)
                {
                    // This sets the signature fields.
                    keyChain.sign(data, certificateName);
                }
                else
                {
                    // Imitate IdentityManager.signByCertificate to set up the signature
                    //   fields, but don't sign.
                    KeyLocator keyLocator = new KeyLocator();
                    keyLocator.setType(KeyLocatorType.KEYNAME);
                    keyLocator.setKeyName(certificateName);
                    Sha256WithRsaSignature sha256Signature =
                        (Sha256WithRsaSignature)data.getSignature();
                    sha256Signature.setKeyLocator(keyLocator);
                    sha256Signature.setSignature(signatureBits);
                }

                encoding[0] = data.wireEncode();
            }
            double finish = getNowSeconds();

            return(finish - start);
        }