delete references to ndn-cxx KeyChain v1

This commit also fixes an assertation error in TestClientModule/ProbeAndNew
test case when running with a debug build of ndn-cxx.

refs #4089

Change-Id: Ie1f6236e679f1bb9e7f269280bc3de78c2fe30f1
diff --git a/src/ca-module.cpp b/src/ca-module.cpp
index 9df8384..15f28e0 100644
--- a/src/ca-module.cpp
+++ b/src/ca-module.cpp
@@ -24,6 +24,7 @@
 #include <ndn-cxx/face.hpp>
 #include <ndn-cxx/security/verification-helpers.hpp>
 #include <ndn-cxx/security/signing-helpers.hpp>
+#include <ndn-cxx/util/random.hpp>
 
 namespace ndn {
 namespace ndncert {
diff --git a/src/challenge-module.cpp b/src/challenge-module.cpp
index 371be25..224a30c 100644
--- a/src/challenge-module.cpp
+++ b/src/challenge-module.cpp
@@ -20,7 +20,7 @@
 
 #include "challenge-module.hpp"
 #include "logging.hpp"
-#include <random>
+#include <ndn-cxx/util/random.hpp>
 
 namespace ndn {
 namespace ndncert {
diff --git a/tests/identity-management-fixture.cpp b/tests/identity-management-fixture.cpp
index 30d00d8..f2b7e1b 100644
--- a/tests/identity-management-fixture.cpp
+++ b/tests/identity-management-fixture.cpp
@@ -34,62 +34,6 @@
 namespace ndncert {
 namespace tests {
 
-IdentityManagementFixture::IdentityManagementFixture()
-  : m_keyChain("sqlite3", "file")
-{
-  m_keyChain.getDefaultCertificate(); // side effect: create a default cert if it doesn't exist
-}
-
-IdentityManagementFixture::~IdentityManagementFixture()
-{
-  for (const auto& id : m_identities) {
-    m_keyChain.deleteIdentity(id);
-  }
-
-  boost::system::error_code ec;
-  for (const auto& certFile : m_certFiles) {
-    boost::filesystem::remove(certFile, ec); // ignore error
-  }
-}
-
-bool
-IdentityManagementFixture::addIdentity(const Name& identity, const ndn::KeyParams& params)
-{
-  try {
-    m_keyChain.createIdentity(identity, params);
-    m_identities.push_back(identity);
-    return true;
-  }
-  catch (std::runtime_error&) {
-    return false;
-  }
-}
-
-bool
-IdentityManagementFixture::saveIdentityCertificate(const Name& identity,
-                                                   const std::string& filename, bool wantAdd)
-{
-  shared_ptr<ndn::IdentityCertificate> cert;
-  try {
-    cert = m_keyChain.getCertificate(m_keyChain.getDefaultCertificateNameForIdentity(identity));
-  }
-  catch (const ndn::SecPublicInfo::Error&) {
-    if (wantAdd && this->addIdentity(identity)) {
-      return this->saveIdentityCertificate(identity, filename, false);
-    }
-    return false;
-  }
-
-  m_certFiles.push_back(filename);
-  try {
-    ndn::io::save(*cert, filename);
-    return true;
-  }
-  catch (const ndn::io::Error&) {
-    return false;
-  }
-}
-
 IdentityManagementV2Fixture::IdentityManagementV2Fixture()
   : m_keyChain("pib-memory:", "tpm-memory:")
 {
diff --git a/tests/identity-management-fixture.hpp b/tests/identity-management-fixture.hpp
index 8a80da8..68a6d14 100644
--- a/tests/identity-management-fixture.hpp
+++ b/tests/identity-management-fixture.hpp
@@ -29,7 +29,6 @@
 #define NDNCERT_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP
 
 #include "test-common.hpp"
-#include <ndn-cxx/security/key-chain.hpp>
 #include <ndn-cxx/security/v2/key-chain.hpp>
 #include <ndn-cxx/security/v2/additional-description.hpp>
 #include <ndn-cxx/security/signing-helpers.hpp>
@@ -38,41 +37,6 @@
 namespace ndncert {
 namespace tests {
 
-/** \brief a fixture that cleans up KeyChain identities and certificate files upon destruction
- */
-class IdentityManagementFixture : public virtual BaseFixture
-{
-public:
-  IdentityManagementFixture();
-
-  /** \brief deletes created identities and saved certificate files
-   */
-  ~IdentityManagementFixture();
-
-  /** \brief add identity
-   *  \return whether successful
-   */
-  bool
-  addIdentity(const Name& identity,
-              const ndn::KeyParams& params = ndn::KeyChain::DEFAULT_KEY_PARAMS);
-
-  /** \brief save identity certificate to a file
-   *  \param identity identity name
-   *  \param filename file name, should be writable
-   *  \param wantAdd if true, add new identity when necessary
-   *  \return whether successful
-   */
-  bool
-  saveIdentityCertificate(const Name& identity, const std::string& filename, bool wantAdd = false);
-
-protected:
-  ndn::KeyChain m_keyChain;
-
-private:
-  std::vector<ndn::Name> m_identities;
-  std::vector<std::string> m_certFiles;
-};
-
 /**
  * @brief A test suite level fixture to help with identity management
  *
@@ -129,14 +93,6 @@
 };
 
 /** \brief convenience base class for inheriting from both UnitTestTimeFixture
- *         and IdentityManagementFixture
- */
-class IdentityManagementTimeFixture : public UnitTestTimeFixture
-                                    , public IdentityManagementFixture
-{
-};
-
-/** \brief convenience base class for inheriting from both UnitTestTimeFixture
  *         and IdentityManagementV2Fixture
  */
 class IdentityManagementV2TimeFixture : public UnitTestTimeFixture
diff --git a/tests/unit-tests/client-module.t.cpp b/tests/unit-tests/client-module.t.cpp
index 02eb3b6..777948f 100644
--- a/tests/unit-tests/client-module.t.cpp
+++ b/tests/unit-tests/client-module.t.cpp
@@ -56,43 +56,44 @@
   client.getClientConf().m_caItems.push_back(item);
 
   int nInterest = 0;
-  face.onSendInterest.connect([&] (const Interest& interest) {
-      nInterest++;
-      if (nInterest == 1) {
-        // PROBE interest and return identifier
-        BOOST_CHECK_EQUAL(interest.getName().toUri(), "/site/CA/_PROBE/zhiyi%40cs.ucla.edu");
-        BOOST_CHECK_EQUAL(interest.getMustBeFresh(), 1);
+  auto processInterest = [&] (const Interest& interest) {
+    nInterest++;
+    if (nInterest == 1) {
+      // PROBE interest and return identifier
+      BOOST_CHECK_EQUAL(interest.getName().toUri(), "/site/CA/_PROBE/zhiyi%40cs.ucla.edu");
+      BOOST_CHECK_EQUAL(interest.getMustBeFresh(), 1);
 
-        auto data = make_shared<Data>();
-        data->setName(interest.getName());
-        JsonSection json = genResponseProbeJson(Name("/site/CA/ucla-cs-zhiyi"), Name(""));
-        std::stringstream ss;
-        boost::property_tree::write_json(ss, json);
-        Block dataContent = makeStringBlock(ndn::tlv::Content, ss.str());
-        data->setContent(dataContent);
-        m_keyChain.sign(*data, signingByCertificate(cert));
-        face.receive(*data);
-      }
-      else {
-        // NEW interest and return challenge list, request ID
-        BOOST_CHECK_EQUAL(interest.getName().getPrefix(3).toUri(), "/site/CA/_NEW");
-        BOOST_CHECK_EQUAL(interest.getName().size(), 6);
+      auto data = make_shared<Data>();
+      data->setName(interest.getName());
+      JsonSection json = genResponseProbeJson(Name("/site/CA/ucla-cs-zhiyi"), Name(""));
+      std::stringstream ss;
+      boost::property_tree::write_json(ss, json);
+      Block dataContent = makeStringBlock(ndn::tlv::Content, ss.str());
+      data->setContent(dataContent);
+      m_keyChain.sign(*data, signingByCertificate(cert));
+      face.receive(*data);
+    }
+    else {
+      // NEW interest and return challenge list, request ID
+      BOOST_CHECK_EQUAL(interest.getName().getPrefix(3).toUri(), "/site/CA/_NEW");
+      BOOST_CHECK_EQUAL(interest.getName().size(), 6);
 
-        auto data = make_shared<Data>();
-        data->setName(interest.getName());
-        std::list<std::string> challenges;
-        challenges.push_back("EMAIL");
-        challenges.push_back("PIN");
-        JsonSection json = genResponseNewJson("1234", ChallengeModule::WAIT_SELECTION, challenges);
-        std::stringstream ss;
-        boost::property_tree::write_json(ss, json);
-        Block dataContent = makeStringBlock(ndn::tlv::Content, ss.str());
-        data->setContent(dataContent);
-        m_keyChain.sign(*data, signingByCertificate(cert));
+      auto data = make_shared<Data>();
+      data->setName(interest.getName());
+      std::list<std::string> challenges;
+      challenges.push_back("EMAIL");
+      challenges.push_back("PIN");
+      JsonSection json = genResponseNewJson("1234", ChallengeModule::WAIT_SELECTION, challenges);
+      std::stringstream ss;
+      boost::property_tree::write_json(ss, json);
+      Block dataContent = makeStringBlock(ndn::tlv::Content, ss.str());
+      data->setContent(dataContent);
+      m_keyChain.sign(*data, signingByCertificate(cert));
 
-        face.receive(*data);
-      }
-    });
+      face.receive(*data);
+    }
+  };
+  face.onSendInterest.connect([=] (const Interest& interest) { m_io.post([=] { processInterest(interest); }); });
 
   int nCallback = 0;
   shared_ptr<RequestState> requestState = nullptr;