security: refactor CertificateStore class

Refs: #5075

Change-Id: I8ab92012b3acf405503ab33c9320463accc682a9
diff --git a/tests/communication/test-sync-logic-handler.cpp b/tests/communication/test-sync-logic-handler.cpp
index 2352735..de99239 100644
--- a/tests/communication/test-sync-logic-handler.cpp
+++ b/tests/communication/test-sync-logic-handler.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2019,  The University of Memphis,
+ * Copyright (c) 2014-2020,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
  *
@@ -20,7 +20,7 @@
  **/
 
 #include "communication/sync-logic-handler.hpp"
-#include "../test-common.hpp"
+#include "tests/test-common.hpp"
 #include "common.hpp"
 #include "nlsr.hpp"
 #include "lsa.hpp"
@@ -38,7 +38,7 @@
 public:
   SyncLogicFixture()
     : face(m_ioService, m_keyChain)
-    , conf(face)
+    , conf(face, m_keyChain)
     , confProcessor(conf, Protocol)
     , testIsLsaNew([] (const ndn::Name& name, const Lsa::Type& lsaType,
                        const uint64_t sequenceNumber) {
diff --git a/tests/publisher/publisher-fixture.hpp b/tests/publisher/publisher-fixture.hpp
index f5b37fa..be97a34 100644
--- a/tests/publisher/publisher-fixture.hpp
+++ b/tests/publisher/publisher-fixture.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2019,  The University of Memphis,
+ * Copyright (c) 2014-2020,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
  *
@@ -45,7 +45,7 @@
 public:
   PublisherFixture()
     : face(m_ioService, m_keyChain, {true, true})
-    , conf(face)
+    , conf(face, m_keyChain)
     , confProcessor(conf)
     , nlsr(face, m_keyChain, conf)
     , lsdb(nlsr.m_lsdb)
@@ -58,23 +58,6 @@
   }
 
   void
-  checkPrefixRegistered(const Name& prefix)
-  {
-    bool registerCommandEmitted = false;
-    for (const auto& interest : face.sentInterests) {
-      if (interest.getName().size() > 4 && interest.getName().get(3) == name::Component("register")) {
-        name::Component test = interest.getName().get(4);
-        ndn::nfd::ControlParameters params(test.blockFromValue());
-        if (params.getName() == prefix) {
-          registerCommandEmitted = true;
-          break;
-        }
-      }
-    }
-    BOOST_CHECK(registerCommandEmitted);
-  }
-
-  void
   addAdjacency(AdjLsa& lsa, const std::string& name, const std::string& faceUri, double cost)
   {
     Adjacent adjacency(name, ndn::FaceUri(faceUri), cost, Adjacent::STATUS_ACTIVE, 0, 0);
diff --git a/tests/publisher/test-dataset-interest-handler.cpp b/tests/publisher/test-dataset-interest-handler.cpp
index 102be58..b25576f 100644
--- a/tests/publisher/test-dataset-interest-handler.cpp
+++ b/tests/publisher/test-dataset-interest-handler.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2019,  The University of Memphis,
+ * Copyright (c) 2014-2020,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
  *
@@ -52,7 +52,7 @@
 
 BOOST_AUTO_TEST_CASE(Localhost)
 {
-  checkPrefixRegistered(Nlsr::LOCALHOST_PREFIX);
+  nlsr::test::checkPrefixRegistered(face, Nlsr::LOCALHOST_PREFIX);
 
   // Install adjacency LSA
   AdjLsa adjLsa;
@@ -109,7 +109,7 @@
   // Should already be added to dispatcher
   BOOST_CHECK_THROW(nlsr.m_dispatcher.addTopPrefix(regRouterPrefix), std::out_of_range);
 
-  checkPrefixRegistered(regRouterPrefix);
+  nlsr::test::checkPrefixRegistered(face,regRouterPrefix);
 
   // Install adjacencies LSA
   AdjLsa adjLsa;
diff --git a/tests/route/test-fib.cpp b/tests/route/test-fib.cpp
index ae297de..5d2d27e 100644
--- a/tests/route/test-fib.cpp
+++ b/tests/route/test-fib.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2019,  The University of Memphis,
+ * Copyright (c) 2014-2020,  The University of Memphis,
  *                           Regents of the University of California
  *
  * This file is part of NLSR (Named-data Link State Routing).
@@ -37,7 +37,7 @@
 public:
   FibFixture()
     : face(std::make_shared<ndn::util::DummyClientFace>(m_ioService, m_keyChain))
-    , conf(*face)
+    , conf(*face, m_keyChain)
     , interests(face->sentInterests)
   {
     Adjacent neighbor1(router1Name, ndn::FaceUri(router1FaceUri), 0, Adjacent::STATUS_ACTIVE, 0, router1FaceId);
diff --git a/tests/route/test-name-prefix-table.cpp b/tests/route/test-name-prefix-table.cpp
index a97520d..213ba04 100644
--- a/tests/route/test-name-prefix-table.cpp
+++ b/tests/route/test-name-prefix-table.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2019,  The University of Memphis,
+ * Copyright (c) 2014-2020,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
  *
@@ -33,7 +33,7 @@
 public:
   NamePrefixTableFixture()
     : face(m_ioService, m_keyChain)
-    , conf(face)
+    , conf(face, m_keyChain)
     , nlsr(face, m_keyChain, conf)
     , lsdb(nlsr.m_lsdb)
     , npt(nlsr.m_namePrefixTable)
diff --git a/tests/route/test-routing-table.cpp b/tests/route/test-routing-table.cpp
index 0f630aa..f8a7df5 100644
--- a/tests/route/test-routing-table.cpp
+++ b/tests/route/test-routing-table.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2019,  The University of Memphis,
+ * Copyright (c) 2014-2020,  The University of Memphis,
  *                           Regents of the University of California
  *
  * This file is part of NLSR (Named-data Link State Routing).
@@ -35,8 +35,8 @@
 BOOST_AUTO_TEST_CASE(RoutingTableAddNextHop)
 {
   ndn::util::DummyClientFace face;
-  ConfParameter conf(face);
   ndn::KeyChain keyChain;
+  ConfParameter conf(face, keyChain);
   Nlsr nlsr(face, keyChain, conf);
 
   RoutingTable rt1(m_scheduler, nlsr.m_fib, nlsr.m_lsdb,
diff --git a/tests/security/test-certificate-store.cpp b/tests/security/test-certificate-store.cpp
index a37e6d8..b09bd5a 100644
--- a/tests/security/test-certificate-store.cpp
+++ b/tests/security/test-certificate-store.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2017,  The University of Memphis,
+ * Copyright (c) 2014-2020,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
  *
@@ -21,49 +21,202 @@
 
 #include "security/certificate-store.hpp"
 
-#include "../test-common.hpp"
+#include "tests/test-common.hpp"
+#include "nlsr.hpp"
+#include "lsdb.hpp"
 
 #include <ndn-cxx/security/key-chain.hpp>
 
 namespace nlsr {
-namespace security {
 namespace test {
 
 using std::shared_ptr;
 using namespace nlsr::test;
 
-class CertificateStoreFixture : public BaseFixture
+class CertificateStoreFixture : public UnitTestTimeFixture
 {
 public:
   CertificateStoreFixture()
+    : face(m_ioService, m_keyChain, {true, true})
+    , conf(face, m_keyChain, "unit-test-nlsr.conf")
+    , confProcessor(conf, SYNC_PROTOCOL_PSYNC, HYPERBOLIC_STATE_OFF,
+                    "/ndn/", "/site", "/%C1.Router/router1")
+    , rootIdName(conf.getNetwork())
+    , siteIdentityName(ndn::Name(conf.getNetwork()).append(conf.getSiteName()))
+    , opIdentityName(ndn::Name(conf.getNetwork())
+                     .append(ndn::Name(conf.getSiteName()))
+                     .append(ndn::Name("%C1.Operator")))
+    , routerIdName(conf.getRouterPrefix())
+    , nlsr(face, m_keyChain, conf)
+    , lsdb(nlsr.getLsdb())
+    , certStore(face, conf, lsdb)
+    , ROOT_CERT_PATH(boost::filesystem::current_path() / std::string("root.cert"))
+
   {
-    auto identity = addIdentity("/TestNLSR/identity");
-    certificateKey = identity.getDefaultKey().getName();
-    certificate = identity.getDefaultKey().getDefaultCertificate();
+    rootId = addIdentity(rootIdName);
+    siteIdentity = addSubCertificate(siteIdentityName, rootId);
+    opIdentity = addSubCertificate(opIdentityName, siteIdentity);
+    routerId = addSubCertificate(routerIdName, opIdentity);
+
+    auto certificate = conf.initializeKey();
+    if (certificate) {
+      certStore.insert(*certificate);
+    };
+
+    // Create certificate and load it to the validator
+    // previously this was done by in nlsr ctor
+    conf.loadCertToValidator(rootId.getDefaultKey().getDefaultCertificate());
+    conf.loadCertToValidator(siteIdentity.getDefaultKey().getDefaultCertificate());
+    conf.loadCertToValidator(opIdentity.getDefaultKey().getDefaultCertificate());
+    conf.loadCertToValidator(routerId.getDefaultKey().getDefaultCertificate());
+
+    std::ifstream inputFile;
+    inputFile.open(std::string("nlsr.conf"));
+
+    BOOST_REQUIRE(inputFile.is_open());
+
+    boost::property_tree::ptree pt;
+
+    boost::property_tree::read_info(inputFile, pt);
+
+    // Load security section and file name
+    for (const auto& tn : pt) {
+      if (tn.first == "security") {
+        auto it = tn.second.begin();
+        conf.getValidator().load(it->second, std::string("nlsr.conf"));
+        break;
+      }
+    }
+    inputFile.close();
+
+    this->advanceClocks(ndn::time::milliseconds(20));
   }
 
 public:
+  void
+  checkForInterest(ndn::Name& interstName)
+  {
+    std::vector<ndn::Interest>& interests = face.sentInterests;
+    BOOST_REQUIRE(interests.size() > 0);
+
+    bool didFindInterest = false;
+    for (const auto& interest : interests) {
+      didFindInterest = didFindInterest || interest.getName() == interstName;
+    }
+    BOOST_CHECK(didFindInterest);
+  }
+
+  ndn::util::DummyClientFace face;
+
+  ConfParameter conf;
+  DummyConfFileProcessor confProcessor;
+
+  ndn::Name rootIdName, siteIdentityName, opIdentityName, routerIdName;
+  ndn::security::pib::Identity rootId, siteIdentity, opIdentity, routerId;
+
+  Nlsr nlsr;
+  Lsdb& lsdb;
   ndn::security::v2::Certificate certificate;
   ndn::Name certificateKey;
+  security::CertificateStore certStore;
+  const boost::filesystem::path ROOT_CERT_PATH;
 };
 
 BOOST_FIXTURE_TEST_SUITE(TestSecurityCertificateStore, CertificateStoreFixture)
 
 BOOST_AUTO_TEST_CASE(Basic)
 {
-  CertificateStore store;
+  ndn::Name identityName("/TestNLSR/identity");
+  identityName.appendVersion();
 
-  BOOST_REQUIRE(store.find(certificateKey) == nullptr);
-  store.insert(certificate);
+  auto identity = m_keyChain.createIdentity(identityName);
+  auto certificate = identity.getDefaultKey().getDefaultCertificate();
 
-  BOOST_CHECK(*store.find(certificateKey) == certificate);
+  ndn::Name certKey = certificate.getKeyName();
 
-  store.clear();
-  BOOST_REQUIRE(store.find(certificateKey) == nullptr);
+  BOOST_CHECK(certStore.find(certKey) == nullptr);
+
+  // Certificate should be retrievable from the CertificateStore
+  certStore.insert(certificate);
+  conf.loadCertToValidator(certificate);
+
+  BOOST_CHECK(certStore.find(certKey) != nullptr);
+
+  lsdb.expressInterest(certKey, 0);
+
+  advanceClocks(10_ms);
+  checkForInterest(certKey);
+}
+
+BOOST_AUTO_TEST_CASE(TestKeyPrefixRegistration)
+{
+  // check if nlsrKeyPrefix is registered
+  ndn::Name nlsrKeyPrefix = conf.getRouterPrefix();
+  nlsrKeyPrefix.append("nlsr");
+  nlsrKeyPrefix.append("KEY");
+  checkPrefixRegistered(face, nlsrKeyPrefix);
+
+  // check if routerPrefix is registered
+  ndn::Name routerKeyPrefix = conf.getRouterPrefix();
+  routerKeyPrefix.append("KEY");
+  checkPrefixRegistered(face, routerKeyPrefix);
+
+  // check if operatorKeyPrefix is registered
+  ndn::Name operatorKeyPrefix = conf.getNetwork();
+  operatorKeyPrefix.append(conf.getSiteName());
+  operatorKeyPrefix.append(std::string("%C1.Operator"));
+  checkPrefixRegistered(face, operatorKeyPrefix);
+}
+
+BOOST_AUTO_TEST_CASE(SegmentValidatedSignal)
+{
+  ndn::Name lsaInterestName("/localhop");
+  lsaInterestName.append(conf.getLsaPrefix().getSubName(1));
+  lsaInterestName.append(conf.getSiteName());
+  lsaInterestName.append(conf.getRouterName());
+  lsaInterestName.append(std::to_string(Lsa::Type::NAME));
+  lsaInterestName.appendNumber(nlsr.m_lsdb.m_sequencingManager.getNameLsaSeq() + 1);
+
+  lsdb.expressInterest(lsaInterestName, 0);
+  advanceClocks(10_ms);
+
+  checkForInterest(lsaInterestName);
+
+  ndn::Name lsaDataName(lsaInterestName);
+  lsaDataName.appendVersion();
+  lsaDataName.appendSegment(0);
+
+  ndn::Data data(lsaDataName);
+  data.setFreshnessPeriod(ndn::time::seconds(10));
+  ndn::Data dummyData;
+  data.setContent(dummyData.getContent());
+  data.setFinalBlock(lsaDataName[-1]);
+
+  // Sign data with this NLSR's key (in real it would be different NLSR)
+  m_keyChain.sign(data, conf.m_signingInfo);
+  face.put(data);
+
+  this->advanceClocks(ndn::time::milliseconds(1));
+
+  // Make NLSR validate data signed by its own key
+  conf.getValidator().validate(data,
+                               [] (const ndn::Data&) { BOOST_CHECK(true); },
+                               [] (const ndn::Data&, const ndn::security::v2::ValidationError&) {
+                                 BOOST_CHECK(false);
+                               });
+
+  lsdb.emitSegmentValidatedSignal(data);
+  const auto keyName = data.getSignature().getKeyLocator().getName();
+  BOOST_CHECK(certStore.find(keyName) != nullptr);
+
+  // testing a callback after segment validation signal from lsdb
+  ndn::util::signal::ScopedConnection connection = lsdb.afterSegmentValidatedSignal.connect(
+  [&] (const ndn::Data& lsaSegment) {
+    BOOST_CHECK_EQUAL(lsaSegment.getName(), data.getName());
+  });
 }
 
 BOOST_AUTO_TEST_SUITE_END()
 
 } // namespace test
-} // namespace security
 } // namespace nlsr
diff --git a/tests/test-adjacency-list.cpp b/tests/test-adjacency-list.cpp
index 721d8f6..c1bf482 100644
--- a/tests/test-adjacency-list.cpp
+++ b/tests/test-adjacency-list.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2019,  The University of Memphis,
+ * Copyright (c) 2014-2020,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
  *
@@ -88,7 +88,8 @@
   adjacencies.insert(adjacencyB);
 
   ndn::util::DummyClientFace face;
-  ConfParameter conf(face);
+  ndn::KeyChain keyChain;
+  ConfParameter conf(face, keyChain);
   BOOST_CHECK(adjacencies.isAdjLsaBuildable(conf.getInterestRetryNumber()));
 }
 
@@ -108,7 +109,8 @@
   adjacencies.insert(adjacencyB);
 
   ndn::util::DummyClientFace face;
-  ConfParameter conf(face);
+  ndn::KeyChain keyChain;
+  ConfParameter conf(face, keyChain);
   conf.setInterestRetryNumber(HELLO_RETRIES_DEFAULT);
 
   BOOST_CHECK(adjacencies.isAdjLsaBuildable(conf.getInterestRetryNumber()));
@@ -130,7 +132,8 @@
   adjacencies.insert(adjacencyB);
 
   ndn::util::DummyClientFace face;
-  ConfParameter conf(face);
+  ndn::KeyChain keyChain;
+  ConfParameter conf(face, keyChain);
   conf.setInterestRetryNumber(HELLO_RETRIES_DEFAULT);
 
   BOOST_CHECK(!adjacencies.isAdjLsaBuildable(conf.getInterestRetryNumber()));
diff --git a/tests/test-common.cpp b/tests/test-common.cpp
index 11ca06d..b611390 100644
--- a/tests/test-common.cpp
+++ b/tests/test-common.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2017,  The University of Memphis,
+ * Copyright (c) 2014-2020,  The University of Memphis,
  *                           Regents of the University of California
  *
  * This file is part of NLSR (Named-data Link State Routing).
@@ -34,6 +34,24 @@
   return data;
 }
 
+void
+checkPrefixRegistered(const ndn::util::DummyClientFace& face, const ndn::Name& prefix)
+{
+  bool registerCommandEmitted = false;
+  for (const auto& interest : face.sentInterests) {
+    if (interest.getName().size() > 4 &&
+        interest.getName().get(3) == ndn::name::Component("register")) {
+      ndn::name::Component test = interest.getName().get(4);
+      ndn::nfd::ControlParameters params(test.blockFromValue());
+      if (params.getName() == prefix) {
+        registerCommandEmitted = true;
+        break;
+      }
+    }
+  }
+  BOOST_CHECK(registerCommandEmitted);
+}
+
 MockNfdMgmtFixture::MockNfdMgmtFixture()
   : m_face(m_ioService, m_keyChain, {true, true})
 {
diff --git a/tests/test-common.hpp b/tests/test-common.hpp
index 339fd82..49238ad 100644
--- a/tests/test-common.hpp
+++ b/tests/test-common.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2019,  The University of Memphis,
+ * Copyright (c) 2014-2020,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
  *
@@ -24,9 +24,10 @@
 
 #include "common.hpp"
 #include "conf-parameter.hpp"
+#include "identity-management-fixture.hpp"
 
 #include "boost-test.hpp"
-#include "identity-management-fixture.hpp"
+#include "route/fib.hpp"
 
 #include <boost/asio.hpp>
 
@@ -45,6 +46,9 @@
 ndn::Data&
 signData(ndn::Data& data);
 
+void
+checkPrefixRegistered(const ndn::util::DummyClientFace& face, const ndn::Name& prefix);
+
 /** \brief add a fake signature to Data
  */
 inline shared_ptr<ndn::Data>
@@ -177,11 +181,13 @@
 public:
   DummyConfFileProcessor(ConfParameter& conf,
                          int32_t protocol = SYNC_PROTOCOL_PSYNC,
-                         int32_t hyperbolicState = HYPERBOLIC_STATE_OFF)
+                         int32_t hyperbolicState = HYPERBOLIC_STATE_OFF,
+                         ndn::Name networkName = "/ndn", ndn::Name siteName = "/site",
+                         ndn::Name routerName = "/%C1.Router/this-router")
   {
-    conf.setNetwork("/ndn");
-    conf.setSiteName("/site");
-    conf.setRouterName("/%C1.Router/this-router");
+    conf.setNetwork(networkName);
+    conf.setSiteName(siteName);
+    conf.setRouterName(routerName);
     conf.buildRouterAndSyncUserPrefix();
 
     conf.setSyncProtocol(protocol);
diff --git a/tests/test-conf-file-processor.cpp b/tests/test-conf-file-processor.cpp
index 8ddb6ee..bacae9f 100644
--- a/tests/test-conf-file-processor.cpp
+++ b/tests/test-conf-file-processor.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2019,  The University of Memphis,
+ * Copyright (c) 2014-2020,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
  *
@@ -123,7 +123,7 @@
 public:
   ConfFileProcessorFixture()
     : face(m_ioService, m_keyChain)
-    , conf(face, "unit-test-nlsr.conf")
+    , conf(face, m_keyChain, "unit-test-nlsr.conf")
   {
   }
 
@@ -401,8 +401,6 @@
 
   BOOST_CHECK(processConfigurationString(SECTION_SECURITY));
 
-  // Certificate should now be in the CertificateStore
-  BOOST_CHECK(conf.getCertStore().find(identity.getDefaultKey().getName()) != nullptr);
 }
 
 BOOST_AUTO_TEST_CASE(PrefixUpdateValidatorOptional) // Bug #2814
diff --git a/tests/test-conf-parameter.cpp b/tests/test-conf-parameter.cpp
index 4bc9c54..e45a605 100644
--- a/tests/test-conf-parameter.cpp
+++ b/tests/test-conf-parameter.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2019,  The University of Memphis,
+ * Copyright (c) 2014-2020,  The University of Memphis,
  *                           Regents of the University of California
  *
  * This file is part of NLSR (Named-data Link State Routing).
@@ -35,7 +35,8 @@
 BOOST_AUTO_TEST_CASE(ConfParameterSettersAndGetters)
 {
   ndn::util::DummyClientFace face;
-  ConfParameter cp1(face);
+  ndn::KeyChain keyChain;
+  ConfParameter cp1(face, keyChain);
 
   const string NAME = "router1";
   const string SITE = "memphis";
diff --git a/tests/test-hyperbolic-calculator.cpp b/tests/test-hyperbolic-calculator.cpp
index 28f7323..0011ce9 100644
--- a/tests/test-hyperbolic-calculator.cpp
+++ b/tests/test-hyperbolic-calculator.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2019,  The University of Memphis,
+ * Copyright (c) 2014-2020,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
  *
@@ -44,7 +44,7 @@
 public:
   HyperbolicCalculatorFixture()
     : face(m_ioService, m_keyChain)
-    , conf(face)
+    , conf(face, m_keyChain)
     , nlsr(face, m_keyChain, conf)
     , routingTable(nlsr.m_routingTable)
     , adjacencies(conf.getAdjacencyList())
diff --git a/tests/test-link-state-calculator.cpp b/tests/test-link-state-calculator.cpp
index 8e1710b..2d8ee1b 100644
--- a/tests/test-link-state-calculator.cpp
+++ b/tests/test-link-state-calculator.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2019,  The University of Memphis,
+ * Copyright (c) 2014-2020,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
  *
@@ -43,7 +43,7 @@
 public:
   LinkStateCalculatorFixture()
     : face(m_ioService, m_keyChain)
-    , conf(face)
+    , conf(face, m_keyChain)
     , confProcessor(conf)
     , nlsr(face, m_keyChain, conf)
     , routingTable(nlsr.m_routingTable)
diff --git a/tests/test-lsa-rule.cpp b/tests/test-lsa-rule.cpp
index 56b1f5c..dffe174 100644
--- a/tests/test-lsa-rule.cpp
+++ b/tests/test-lsa-rule.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2019,  The University of Memphis,
+ * Copyright (c) 2014-2020,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
  *
@@ -21,6 +21,7 @@
 
 #include "test-common.hpp"
 #include "nlsr.hpp"
+#include "security/certificate-store.hpp"
 
 #include <ndn-cxx/interest.hpp>
 #include <ndn-cxx/security/key-chain.hpp>
@@ -46,8 +47,9 @@
     , siteIdentityName("/ndn/edu/test-site")
     , opIdentityName("/ndn/edu/test-site/%C1.Operator/op1")
     , routerIdName("/ndn/edu/test-site/%C1.Router/router1")
-    , confParam(face)
-    , confProcessor(confParam)
+    , confParam(face, m_keyChain)
+    , confProcessor(confParam, SYNC_PROTOCOL_PSYNC, HYPERBOLIC_STATE_OFF,
+                    "/ndn/", "/edu/test-site", "/%C1.Router/router1")
     , nlsr(face, m_keyChain, confParam)
     , ROOT_CERT_PATH(boost::filesystem::current_path() / std::string("root.cert"))
   {
@@ -56,15 +58,16 @@
     opIdentity = addSubCertificate(opIdentityName, siteIdentity);
     routerId = addSubCertificate(routerIdName, opIdentity);
 
+    // Create certificate and load it to the validator
+    // previously this was done by in nlsr ctor
+    confParam.initializeKey();
+
     saveCertificate(rootId, ROOT_CERT_PATH.string());
 
-    auto load = [this] (const ndn::security::Identity& id) {
-      nlsr.loadCertToPublish(id.getDefaultKey().getDefaultCertificate());
-    };
-    load(rootId);
-    load(siteIdentity);
-    load(opIdentity);
-    load(routerId);
+    confParam.loadCertToValidator(rootId.getDefaultKey().getDefaultCertificate());
+    confParam.loadCertToValidator(siteIdentity.getDefaultKey().getDefaultCertificate());
+    confParam.loadCertToValidator(opIdentity.getDefaultKey().getDefaultCertificate());
+    confParam.loadCertToValidator(routerId.getDefaultKey().getDefaultCertificate());
 
     // Loading the security section's validator part into the validator
     // See conf file processor for more details
@@ -100,7 +103,6 @@
 
   ndn::Name rootIdName, siteIdentityName, opIdentityName, routerIdName;
   ndn::security::pib::Identity rootId, siteIdentity, opIdentity, routerId;
-
   ConfParameter confParam;
   DummyConfFileProcessor confProcessor;
   Nlsr nlsr;
@@ -129,7 +131,7 @@
   data.setFreshnessPeriod(ndn::time::seconds(10));
 
   // Sign data with NLSR's key
-  m_keyChain.sign(data, nlsr.m_signingInfo);
+  m_keyChain.sign(data, confParam.getSigningInfo());
 
   // Make NLSR validate data signed by its own key
   confParam.getValidator().validate(data,
diff --git a/tests/test-lsa-segment-storage.cpp b/tests/test-lsa-segment-storage.cpp
index e8f90bf..2881d88 100644
--- a/tests/test-lsa-segment-storage.cpp
+++ b/tests/test-lsa-segment-storage.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2019,  Regents of the University of California,
+ * Copyright (c) 2014-2020,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -36,7 +36,7 @@
 public:
   LsaSegmentStorageFixture()
     : face(m_ioService, m_keyChain, {true, true})
-    , conf(face)
+    , conf(face, m_keyChain)
     , confProcessor(conf)
     , nlsr(face, m_keyChain, conf)
     , lsdb(nlsr.m_lsdb)
diff --git a/tests/test-lsdb.cpp b/tests/test-lsdb.cpp
index 9bec39a..56e862b 100644
--- a/tests/test-lsdb.cpp
+++ b/tests/test-lsdb.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2019,  The University of Memphis,
+ * Copyright (c) 2014-2020,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
  *
@@ -41,7 +41,7 @@
 public:
   LsdbFixture()
     : face(m_ioService, m_keyChain, {true, true})
-    , conf(face)
+    , conf(face, m_keyChain)
     , confProcessor(conf)
     , nlsr(face, m_keyChain, conf)
     , lsdb(nlsr.m_lsdb)
@@ -190,7 +190,7 @@
   ndn::util::DummyClientFace face2(m_ioService, m_keyChain, {true, true});
   face.linkTo(face2);
 
-  ConfParameter conf2(face2);
+  ConfParameter conf2(face2, m_keyChain);
   std::string config = R"CONF(
               trust-anchor
                 {
diff --git a/tests/test-nlsr.cpp b/tests/test-nlsr.cpp
index f5ffb8e..ab69692 100644
--- a/tests/test-nlsr.cpp
+++ b/tests/test-nlsr.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2019,  The University of Memphis,
+ * Copyright (c) 2014-2020,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
  *
@@ -35,7 +35,7 @@
 {
 public:
   NlsrFixture()
-    : conf(m_face)
+    : conf(m_face, m_keyChain)
     , confProcessor(conf)
     , nlsr(m_face, m_keyChain, conf)
     , lsdb(nlsr.m_lsdb)
@@ -354,29 +354,6 @@
   BOOST_CHECK(rtEntry == nullptr);
 }
 
-BOOST_AUTO_TEST_CASE(GetCertificate)
-{
-  // Create certificate
-  ndn::Name identityName("/TestNLSR/identity");
-  identityName.appendVersion();
-
-  ndn::security::pib::Identity identity = m_keyChain.createIdentity(identityName);
-
-  ndn::security::v2::Certificate certificate =
-    identity.getDefaultKey().getDefaultCertificate();
-
-  const ndn::Name certKey = certificate.getKeyName();
-
-  BOOST_CHECK(nlsr.getCertificate(certKey) == nullptr);
-
-  // Certificate should be retrievable from the CertificateStore
-  nlsr.loadCertToPublish(certificate);
-
-  BOOST_CHECK(nlsr.getCertificate(certKey) != nullptr);
-
-  nlsr.getCertificateStore().clear();
-}
-
 BOOST_AUTO_TEST_CASE(BuildAdjLsaAfterHelloResponse)
 {
   // Configure NLSR
diff --git a/tests/test-statistics.cpp b/tests/test-statistics.cpp
index 83479c7..0dbe274 100644
--- a/tests/test-statistics.cpp
+++ b/tests/test-statistics.cpp
@@ -1,6 +1,6 @@
  /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2019,  The University of Memphis,
+ * Copyright (c) 2014-2020,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
  *
@@ -35,7 +35,7 @@
 public:
   StatisticsFixture()
     : face(m_ioService, m_keyChain)
-    , conf(face)
+    , conf(face, m_keyChain)
     , confProcessor(conf)
     , nlsr(face, m_keyChain, conf)
     , lsdb(nlsr.m_lsdb)
diff --git a/tests/update/test-advertise-crash.cpp b/tests/update/test-advertise-crash.cpp
index 7f0cad3..4e8f112 100644
--- a/tests/update/test-advertise-crash.cpp
+++ b/tests/update/test-advertise-crash.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2019,  The University of Memphis,
+ * Copyright (c) 2014-2020,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
  *
@@ -31,7 +31,7 @@
 public:
   AdvertiseCrashFixture()
     : face(m_ioService, m_keyChain, {true, true})
-    , conf(face)
+    , conf(face, m_keyChain)
     , confProcessor(conf)
     , nlsr(face, m_keyChain, conf)
     , namePrefixList(conf.getNamePrefixList())
diff --git a/tests/update/test-nfd-rib-command-processor.cpp b/tests/update/test-nfd-rib-command-processor.cpp
index 17485da..514fa1c 100644
--- a/tests/update/test-nfd-rib-command-processor.cpp
+++ b/tests/update/test-nfd-rib-command-processor.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2019,  The University of Memphis,
+ * Copyright (c) 2014-2020,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
  *
@@ -35,7 +35,7 @@
 public:
   NfdRibCommandProcessorFixture()
     : face(m_ioService, m_keyChain, {true, true})
-    , conf(face)
+    , conf(face, m_keyChain)
     , confProcessor(conf)
     , nlsr(face, m_keyChain, conf)
     , namePrefixes(conf.getNamePrefixList())
diff --git a/tests/update/test-prefix-update-processor.cpp b/tests/update/test-prefix-update-processor.cpp
index 5a6cbde..711935f 100644
--- a/tests/update/test-prefix-update-processor.cpp
+++ b/tests/update/test-prefix-update-processor.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2019,  The University of Memphis,
+ * Copyright (c) 2014-2020,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
  *
@@ -22,8 +22,8 @@
 #include "update/prefix-update-processor.hpp"
 #include "nlsr.hpp"
 
-#include "../control-commands.hpp"
-#include "../test-common.hpp"
+#include "tests/control-commands.hpp"
+#include "tests/test-common.hpp"
 
 #include <ndn-cxx/mgmt/nfd/control-response.hpp>
 #include <ndn-cxx/security/command-interest-signer.hpp>
@@ -46,7 +46,7 @@
     : face(m_ioService, m_keyChain, {true, true})
     , siteIdentityName(ndn::Name("site"))
     , opIdentityName(ndn::Name("site").append(ndn::Name("%C1.Operator")))
-    , conf(face)
+    , conf(face, m_keyChain)
     , confProcessor(conf)
     , nlsr(face, m_keyChain, conf)
     , namePrefixList(conf.getNamePrefixList())
@@ -59,6 +59,12 @@
     // Operator cert
     opIdentity = addSubCertificate(opIdentityName, siteIdentity);
 
+    // Create certificate and load it to the validator
+    conf.initializeKey();
+
+    conf.loadCertToValidator(siteIdentity.getDefaultKey().getDefaultCertificate());
+    conf.loadCertToValidator(opIdentity.getDefaultKey().getDefaultCertificate());
+
     std::ifstream inputFile;
     inputFile.open(std::string("nlsr.conf"));
 
@@ -78,8 +84,6 @@
     }
     inputFile.close();
 
-    nlsr.loadCertToPublish(opIdentity.getDefaultKey().getDefaultCertificate());
-
     addIdentity(conf.getRouterPrefix());
 
     // Initialize NLSR so a sync socket is created
@@ -131,7 +135,9 @@
   ndn::security::pib::Identity siteIdentity;
 
   ndn::Name opIdentityName;
+  ndn::Name routerIdName;
   ndn::security::pib::Identity opIdentity;
+  ndn::security::pib::Identity routerId;
 
   ConfParameter conf;
   DummyConfFileProcessor confProcessor;
@@ -175,7 +181,6 @@
 
   BOOST_REQUIRE_EQUAL(namePrefixList.size(), 1);
   BOOST_CHECK_EQUAL(namePrefixList.getNames().front(), parameters.getName());
-
   BOOST_CHECK(wasRoutingUpdatePublished());
   BOOST_CHECK(nameLsaSeqNoBeforeInterest < nlsr.m_lsdb.m_sequencingManager.getNameLsaSeq());
 
diff --git a/tests/update/test-save-delete-prefix.cpp b/tests/update/test-save-delete-prefix.cpp
index 10988bf..1bcca79 100644
--- a/tests/update/test-save-delete-prefix.cpp
+++ b/tests/update/test-save-delete-prefix.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2019,  The University of Memphis,
+ * Copyright (c) 2014-2020,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
  *
@@ -22,8 +22,8 @@
 #include "update/prefix-update-processor.hpp"
 #include "nlsr.hpp"
 
-#include "../control-commands.hpp"
-#include "../test-common.hpp"
+#include "tests/control-commands.hpp"
+#include "tests/test-common.hpp"
 #include "conf-parameter.hpp"
 
 #include <ndn-cxx/mgmt/nfd/control-response.hpp>
@@ -47,7 +47,7 @@
     , siteIdentityName(ndn::Name("/edu/test-site"))
     , opIdentityName(ndn::Name("/edu/test-site").append(ndn::Name("%C1.Operator")))
     , testConfFile("/tmp/nlsr.conf.test")
-    , conf(face, testConfFile)
+    , conf(face, m_keyChain, testConfFile)
     , confProcessor(conf)
     , nlsr(face, m_keyChain, conf)
     , SITE_CERT_PATH(boost::filesystem::current_path() / std::string("site.cert"))
@@ -91,7 +91,11 @@
 
     // Operator cert
     opIdentity = addSubCertificate(opIdentityName, siteIdentity);
-    nlsr.loadCertToPublish(opIdentity.getDefaultKey().getDefaultCertificate());
+
+    // Create certificate and load it to the validator
+    conf.initializeKey();
+    conf.loadCertToValidator(siteIdentity.getDefaultKey().getDefaultCertificate());
+    conf.loadCertToValidator(opIdentity.getDefaultKey().getDefaultCertificate());
 
     // Set the network so the LSA prefix is constructed
     addIdentity(conf.getRouterPrefix());
@@ -156,8 +160,8 @@
 
 public:
   ndn::util::DummyClientFace face;
-  ndn::Name siteIdentityName;
-  ndn::security::pib::Identity siteIdentity;
+  ndn::Name siteIdentityName, routerIdName;
+  ndn::security::pib::Identity siteIdentity, routerId;
 
   ndn::Name opIdentityName;
   ndn::security::pib::Identity opIdentity;