security: Add 'type dir' trust-anchor in ValidatorConfig
Refs: #1483
Change-Id: I4a34947026edc929624b64fe0a996df36d3fb8ed
diff --git a/tests/integrated/test-validator-config.cpp b/tests/integrated/test-validator-config.cpp
index 1f118af..800fc2a 100644
--- a/tests/integrated/test-validator-config.cpp
+++ b/tests/integrated/test-validator-config.cpp
@@ -979,7 +979,7 @@
boost::filesystem::remove(CERT_PATH);
}
-BOOST_AUTO_TEST_CASE(Wildcard)
+BOOST_AUTO_TEST_CASE(TrustAnchorWildcard)
{
KeyChain keyChain;
@@ -1013,6 +1013,156 @@
}
+
+struct DirTestFixture
+{
+ DirTestFixture()
+ : m_scheduler(m_face.getIoService())
+ , m_validator(m_face, ValidatorConfig::DEFAULT_CERTIFICATE_CACHE, 0)
+ {
+ m_certDirPath = (boost::filesystem::current_path() / std::string("test-cert-dir"));
+ boost::filesystem::create_directory(m_certDirPath);
+
+ m_firstCertPath = (boost::filesystem::current_path() /
+ std::string("test-cert-dir") /
+ std::string("trust-anchor-1.cert"));
+
+ m_secondCertPath = (boost::filesystem::current_path() /
+ std::string("test-cert-dir") /
+ std::string("trust-anchor-2.cert"));
+
+ m_firstIdentity = Name("/TestValidatorConfig/Dir/First");
+ BOOST_REQUIRE_NO_THROW(m_keyChain.createIdentity(m_firstIdentity));
+ Name firstCertName = m_keyChain.getDefaultCertificateNameForIdentity(m_firstIdentity);
+ m_firstCert = m_keyChain.getCertificate(firstCertName);
+ io::save(*m_firstCert, m_firstCertPath.string());
+
+ m_secondIdentity = Name("/TestValidatorConfig/Dir/Second");
+ BOOST_REQUIRE_NO_THROW(m_keyChain.createIdentity(m_secondIdentity));
+ Name secondCertName = m_keyChain.getDefaultCertificateNameForIdentity(m_secondIdentity);
+ m_secondCert = m_keyChain.getCertificate(secondCertName);
+ }
+
+ ~DirTestFixture()
+ {
+ m_keyChain.deleteIdentity(m_firstIdentity);
+ m_keyChain.deleteIdentity(m_secondIdentity);
+
+ boost::filesystem::remove_all(m_certDirPath);
+ }
+
+ void
+ insertSecondTrustAnchor()
+ {
+ io::save(*m_secondCert, m_secondCertPath.string());
+ }
+
+ void
+ validate(shared_ptr<Data> data)
+ {
+ m_validator.validate(*data,
+ bind(&onValidated, _1),
+ bind(&onValidationFailed, _1, _2));
+ }
+
+ void
+ invalidate(shared_ptr<Data> data)
+ {
+ m_validator.validate(*data,
+ bind(&onIntentionalFailureValidated, _1),
+ bind(&onIntentionalFailureInvalidated, _1, _2));
+ }
+
+ void
+ terminate()
+ {
+ m_face.getIoService().stop();
+ }
+
+protected:
+
+ KeyChain m_keyChain;
+
+ boost::filesystem::path m_certDirPath;
+ boost::filesystem::path m_firstCertPath;
+ boost::filesystem::path m_secondCertPath;
+
+ Name m_firstIdentity;
+ Name m_secondIdentity;
+
+ shared_ptr<IdentityCertificate> m_firstCert;
+ shared_ptr<IdentityCertificate> m_secondCert;
+
+ Face m_face;
+ Scheduler m_scheduler;
+ ValidatorConfig m_validator;
+};
+
+BOOST_FIXTURE_TEST_CASE(TrustAnchorDir, DirTestFixture)
+{
+ Name dataName1("/any/data/1");
+ shared_ptr<Data> data1 = make_shared<Data>(dataName1);
+ BOOST_CHECK_NO_THROW(m_keyChain.signByIdentity(*data1, m_firstIdentity));
+
+ Name dataName2("/any/data/2");
+ shared_ptr<Data> data2 = make_shared<Data>(dataName2);
+ BOOST_CHECK_NO_THROW(m_keyChain.signByIdentity(*data2, m_secondIdentity));
+
+ std::string CONFIG =
+ "rule\n"
+ "{\n"
+ " id \"Any Rule\"\n"
+ " for data\n"
+ " filter\n"
+ " {\n"
+ " type name\n"
+ " regex ^<>*$\n"
+ " }\n"
+ " checker\n"
+ " {\n"
+ " type customized\n"
+ " sig-type rsa-sha256\n"
+ " key-locator\n"
+ " {\n"
+ " type name\n"
+ " regex ^<>*$\n"
+ " }\n"
+ " }\n"
+ "}\n"
+ "trust-anchor\n"
+ "{\n"
+ " type dir\n"
+ " dir test-cert-dir\n"
+ " refresh 1s\n"
+ "}\n";
+
+ const boost::filesystem::path CONFIG_PATH =
+ (boost::filesystem::current_path() / std::string("unit-test-nfd.conf"));
+
+
+ m_validator.load(CONFIG, CONFIG_PATH.native());
+
+ m_scheduler.scheduleEvent(time::milliseconds(200),
+ bind(&DirTestFixture::validate, this, data1));
+ m_scheduler.scheduleEvent(time::milliseconds(200),
+ bind(&DirTestFixture::invalidate, this, data2));
+
+ m_scheduler.scheduleEvent(time::milliseconds(500),
+ bind(&DirTestFixture::insertSecondTrustAnchor, this));
+
+ m_scheduler.scheduleEvent(time::milliseconds(1500),
+ bind(&DirTestFixture::validate, this, data1));
+ m_scheduler.scheduleEvent(time::milliseconds(1500),
+ bind(&DirTestFixture::validate, this, data2));
+
+ m_scheduler.scheduleEvent(time::milliseconds(2000),
+ bind(&DirTestFixture::terminate, this));
+
+ BOOST_REQUIRE_NO_THROW(m_face.processEvents());
+}
+
+
+
BOOST_AUTO_TEST_SUITE_END()
} // namespace ndn