예제 #1
0
        public void testSetters()
        {
            CertificateV2 certificate = new CertificateV2();

            certificate.setName(new Name(
                                    "/ndn/site1/KEY/ksk-1416425377094/0123/%FD%00%00%01I%C9%8B"));
            certificate.getMetaInfo().setFreshnessPeriod(3600 * 1000.0d);
            certificate.setContent(new Blob(PUBLIC_KEY, false));
            certificate.setSignature(generateFakeSignature());

            Assert.AssertEquals(new Name(
                                    "/ndn/site1/KEY/ksk-1416425377094/0123/%FD%00%00%01I%C9%8B"),
                                certificate.getName());
            Assert.AssertEquals(new Name("/ndn/site1/KEY/ksk-1416425377094"),
                                certificate.getKeyName());
            Assert.AssertEquals(new Name("/ndn/site1"), certificate.getIdentity());
            Assert.AssertEquals(new Name.Component("0123"), certificate.getIssuerId());
            Assert.AssertEquals(new Name.Component("ksk-1416425377094"),
                                certificate.getKeyId());
            Assert.AssertEquals(new Name("/ndn/site1/KEY/ksk-2516425377094"), net.named_data.jndn.KeyLocator
                                .getFromSignature(certificate.getSignature()).getKeyName());
            Assert.AssertEquals(net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20141111T050000"), certificate
                                .getValidityPeriod().getNotBefore(), 0);
            Assert.AssertEquals(net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20141111T060000"), certificate
                                .getValidityPeriod().getNotAfter(), 0);

            try {
                certificate.getPublicKey();
            } catch (Exception ex) {
                Assert.Fail(ex.Message);
            }
        }
예제 #2
0
        /// <summary>
        /// Add the certificate. If a certificate with the same name (without implicit
        /// digest) already exists, then overwrite the certificate. If the key or
        /// identity does not exist, they will be created. If no default certificate
        /// for the key has been set, then set the added certificate as the default for
        /// the key. If no default key was set for the identity, it will be set as the
        /// default key for the identity. If no default identity was selected, the
        /// certificate's identity becomes the default.
        /// </summary>
        ///
        /// <param name="certificate">The certificate to add. This copies the object.</param>
        public override void addCertificate(CertificateV2 certificate)
        {
            Name certificateNameCopy = new Name(certificate.getName());
            // getKeyName already makes a new Name.
            Name keyNameCopy = certificate.getKeyName();
            Name identity    = certificate.getIdentity();

            addKey(identity, keyNameCopy, certificate.getContent().buf());

            try {
                ILOG.J2CsMapping.Collections.Collections.Put(certificates_, certificateNameCopy, new CertificateV2(
                                                                 certificate));
            } catch (CertificateV2.Error ex) {
                // We don't expect an error in the copy constructor.
                throw new PibImpl.Error(ex.Message);
            }
            if (!defaultCertificateNames_.Contains(keyNameCopy))
            {
                ILOG.J2CsMapping.Collections.Collections.Put(defaultCertificateNames_, keyNameCopy, certificateNameCopy);
            }
        }
예제 #3
0
        public void testConstructor()
        {
            CertificateV2 certificate = new CertificateV2();

            certificate.wireDecode(new Blob(CERT, false));

            Assert.AssertEquals(new Name(
                                    "/ndn/site1/KEY/ksk-1416425377094/0123/%FD%00%00%01I%C9%8B"),
                                certificate.getName());
            Assert.AssertEquals(new Name("/ndn/site1/KEY/ksk-1416425377094"),
                                certificate.getKeyName());
            Assert.AssertEquals(new Name("/ndn/site1"), certificate.getIdentity());
            Assert.AssertEquals(new Name.Component("0123"), certificate.getIssuerId());
            Assert.AssertEquals(new Name.Component("ksk-1416425377094"),
                                certificate.getKeyId());
            Assert.AssertEquals(new Name("/ndn/site1/KEY/ksk-2516425377094"), net.named_data.jndn.KeyLocator
                                .getFromSignature(certificate.getSignature()).getKeyName());
            Assert.AssertEquals(net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150814T223739"), certificate
                                .getValidityPeriod().getNotBefore(), 0);
            Assert.AssertEquals(net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150818T223738"), certificate
                                .getValidityPeriod().getNotAfter(), 0);

            try {
                certificate.getPublicKey();
            } catch (Exception ex) {
                Assert.Fail(ex.Message);
            }

            Data data = new Data();

            data.wireDecode(new Blob(CERT, false));
            CertificateV2 certificate2 = new CertificateV2(data);

            Assert.AssertEquals(certificate.getName(), certificate2.getName());
            Assert.AssertTrue(certificate.getPublicKey().equals(
                                  certificate2.getPublicKey()));
        }
예제 #4
0
        /// <summary>
        /// Add the certificate. If a certificate with the same name (without implicit
        /// digest) already exists, then overwrite the certificate. If the key or
        /// identity does not exist, they will be created. If no default certificate
        /// for the key has been set, then set the added certificate as the default for
        /// the key. If no default key was set for the identity, it will be set as the
        /// default key for the identity. If no default identity was selected, the
        /// certificate's identity becomes the default.
        /// </summary>
        ///
        /// <param name="certificate">The certificate to add. This copies the object.</param>
        /// <exception cref="PibImpl.Error">for a non-semantic (database access) error.</exception>
        public override void addCertificate(CertificateV2 certificate)
        {
            // Ensure the key exists.
            Blob content = certificate.getContent();

            addKey(certificate.getIdentity(), certificate.getKeyName(),
                   content.buf());

            if (!hasCertificate(certificate.getName()))
            {
                try {
                    PreparedStatement statement = database_
                                                  .prepareStatement(net.named_data.jndn.security.pib.PibSqlite3Base.INSERT_addCertificate);
                    statement.setBytes(1, certificate.getKeyName().wireEncode()
                                       .getImmutableArray());
                    statement.setBytes(2, certificate.getName().wireEncode()
                                       .getImmutableArray());
                    statement.setBytes(3, certificate.wireEncode()
                                       .getImmutableArray());

                    try {
                        statement.executeUpdate();
                    } finally {
                        statement.close();
                    }
                } catch (SQLException exception) {
                    throw new PibImpl.Error("PibSqlite3: SQLite error: "
                                            + exception);
                }
            }
            else
            {
                try {
                    PreparedStatement statement_0 = database_
                                                    .prepareStatement(net.named_data.jndn.security.pib.PibSqlite3Base.UPDATE_addCertificate);
                    statement_0.setBytes(1, certificate.wireEncode()
                                         .getImmutableArray());
                    statement_0.setBytes(2, certificate.getName().wireEncode()
                                         .getImmutableArray());

                    try {
                        statement_0.executeUpdate();
                    } finally {
                        statement_0.close();
                    }
                } catch (SQLException exception_1) {
                    throw new PibImpl.Error("PibSqlite3: SQLite error: "
                                            + exception_1);
                }
            }

            if (!hasDefaultCertificateOfKey(certificate.getKeyName()))
            {
                try {
                    setDefaultCertificateOfKey(certificate.getKeyName(),
                                               certificate.getName());
                } catch (Pib.Error ex) {
                    throw new PibImpl.Error(
                              "PibSqlite3: Error setting the default certificate: "
                              + ex);
                }
            }
        }