**breaking change**: Switch Face and related classes to v2::KeyChain

security::v2::KeyChain is now exposed as ndn::KeyChain, which should
ensure that dependent code can be mostly compiled.  However, expect code
that explicitly uses the old KeyChain interface to be broken.

Change-Id: I7330d0250d92f3f0f2570ab6d0214ab3dfdd18cc
Refs: #3098
diff --git a/src/mgmt/dispatcher.cpp b/src/mgmt/dispatcher.cpp
index 62f9114..3220864 100644
--- a/src/mgmt/dispatcher.cpp
+++ b/src/mgmt/dispatcher.cpp
@@ -42,7 +42,7 @@
   };
 }
 
-Dispatcher::Dispatcher(Face& face, security::v1::KeyChain& keyChain,
+Dispatcher::Dispatcher(Face& face, KeyChain& keyChain,
                        const security::SigningInfo& signingInfo,
                        size_t imsCapacity)
   : m_face(face)
diff --git a/src/mgmt/dispatcher.hpp b/src/mgmt/dispatcher.hpp
index a8b30b4..b3c9967 100644
--- a/src/mgmt/dispatcher.hpp
+++ b/src/mgmt/dispatcher.hpp
@@ -145,7 +145,7 @@
    *  \param signingInfo signing parameters to sign Data with \p keyChain
    *  \param imsCapacity capacity of the internal InMemoryStorage used by dispatcher
    */
-  Dispatcher(Face& face, security::v1::KeyChain& keyChain,
+  Dispatcher(Face& face, KeyChain& keyChain,
              const security::SigningInfo& signingInfo = security::SigningInfo(),
              size_t imsCapacity = 256);
 
@@ -462,7 +462,7 @@
   std::unordered_map<Name, TopPrefixEntry> m_topLevelPrefixes;
 
   Face& m_face;
-  security::v1::KeyChain& m_keyChain;
+  KeyChain& m_keyChain;
   security::SigningInfo m_signingInfo;
 
   typedef std::unordered_map<PartialName, InterestHandler> HandlerMap;
diff --git a/src/mgmt/nfd/controller.cpp b/src/mgmt/nfd/controller.cpp
index 4ccb895..bfb0843 100644
--- a/src/mgmt/nfd/controller.cpp
+++ b/src/mgmt/nfd/controller.cpp
@@ -36,9 +36,10 @@
 const uint32_t Controller::ERROR_LBOUND = 400;
 ValidatorNull Controller::s_validatorNull;
 
-Controller::Controller(Face& face, security::v1::KeyChain& keyChain, Validator& validator)
+Controller::Controller(Face& face, KeyChain& keyChain, Validator& validator)
   : m_face(face)
   , m_keyChain(keyChain)
+  , m_signer(keyChain)
   , m_validator(validator)
 {
 }
@@ -56,9 +57,8 @@
     onFailure1 : [] (const ControlResponse&) {};
 
   Name requestName = command->getRequestName(options.getPrefix(), parameters);
-  Interest interest(requestName);
+  Interest interest = m_signer.makeCommandInterest(requestName, options.getSigningInfo());
   interest.setInterestLifetime(options.getTimeout());
-  m_keyChain.sign(interest, options.getSigningInfo());
 
   m_face.expressInterest(interest,
     [=] (const Interest&, const Data& data) {
diff --git a/src/mgmt/nfd/controller.hpp b/src/mgmt/nfd/controller.hpp
index aa4b285..d9bfa1f 100644
--- a/src/mgmt/nfd/controller.hpp
+++ b/src/mgmt/nfd/controller.hpp
@@ -28,6 +28,7 @@
 #include "command-options.hpp"
 #include "../../security/validator-null.hpp"
 #include "../../security/key-chain.hpp"
+#include "../../security/command-interest-signer.hpp"
 
 namespace ndn {
 
@@ -66,7 +67,7 @@
   /** \brief construct a Controller that uses face for transport,
    *         and uses the passed KeyChain to sign commands
    */
-  Controller(Face& face, security::v1::KeyChain& keyChain, security::Validator& validator = s_validatorNull);
+  Controller(Face& face, KeyChain& keyChain, security::Validator& validator = s_validatorNull);
 
   /** \brief start command execution
    */
@@ -170,7 +171,8 @@
 
 protected:
   Face& m_face;
-  security::v1::KeyChain& m_keyChain;
+  KeyChain& m_keyChain;
+  security::CommandInterestSigner m_signer;
   security::Validator& m_validator;
 
 private:
diff --git a/src/security/command-interest-signer.cpp b/src/security/command-interest-signer.cpp
index 0d2f82f..3704a7e 100644
--- a/src/security/command-interest-signer.cpp
+++ b/src/security/command-interest-signer.cpp
@@ -47,7 +47,7 @@
   return name;
 }
 
-CommandInterestSigner::CommandInterestSigner(v2::KeyChain& keyChain)
+CommandInterestSigner::CommandInterestSigner(KeyChain& keyChain)
   : m_keyChain(keyChain)
 {
 }
diff --git a/src/security/command-interest-signer.hpp b/src/security/command-interest-signer.hpp
index 6c5e2ce..730260d 100644
--- a/src/security/command-interest-signer.hpp
+++ b/src/security/command-interest-signer.hpp
@@ -67,7 +67,7 @@
 {
 public:
   explicit
-  CommandInterestSigner(v2::KeyChain& keyChain);
+  CommandInterestSigner(KeyChain& keyChain);
 
   /**
    * @brief Create CommandInterest
@@ -82,10 +82,10 @@
    * @sa https://redmine.named-data.net/projects/ndn-cxx/wiki/CommandInterest
    */
   Interest
-  makeCommandInterest(const Name& name, const SigningInfo& params = v2::KeyChain::getDefaultSigningInfo());
+  makeCommandInterest(const Name& name, const SigningInfo& params = KeyChain::getDefaultSigningInfo());
 
 private:
-  v2::KeyChain& m_keyChain;
+  KeyChain& m_keyChain;
 };
 
 } // namespace security
diff --git a/src/security/command-interest-validator.cpp b/src/security/command-interest-validator.cpp
index 73358bf..57c9c82 100644
--- a/src/security/command-interest-validator.cpp
+++ b/src/security/command-interest-validator.cpp
@@ -20,7 +20,6 @@
  */
 
 #include "command-interest-validator.hpp"
-#include "v1/identity-certificate.hpp"
 #include <boost/lexical_cast.hpp>
 
 namespace ndn {
@@ -146,12 +145,14 @@
   }
 
   try {
-    keyName = v1::IdentityCertificate::certificateNameToPublicKeyName(keyLocator.getName());
+    v2::extractIdentityFromKeyName(keyLocator.getName());
   }
-  catch (const v1::IdentityCertificate::Error&) {
+  catch (const std::invalid_argument&) {
     return ErrorCode::BAD_CERT_NAME;
   }
 
+  keyName = keyLocator.getName();
+
   return ErrorCode::NONE;
 }
 
diff --git a/src/security/key-chain.hpp b/src/security/key-chain.hpp
index 31b26ea..2bd847b 100644
--- a/src/security/key-chain.hpp
+++ b/src/security/key-chain.hpp
@@ -19,21 +19,10 @@
  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
  */
 
-/**
- * @file security/key-chain.hpp
- */
+#ifndef NDN_CXX_SECURITY_KEY_CHAIN_HPP
+#define NDN_CXX_SECURITY_KEY_CHAIN_HPP
 
 #include "security-common.hpp"
-#include "v1/key-chain.hpp"
 #include "v2/key-chain.hpp"
 
-namespace ndn {
-namespace security {
-
-using security::v1::KeyChain;
-
-} // namespace security
-
-using ndn::security::KeyChain;
-
-} // namespace ndn
+#endif // NDN_CXX_SECURITY_KEY_CHAIN_HPP
diff --git a/src/security/v2/key-chain.hpp b/src/security/v2/key-chain.hpp
index f0299c3..e564326 100644
--- a/src/security/v2/key-chain.hpp
+++ b/src/security/v2/key-chain.hpp
@@ -503,6 +503,9 @@
 
 } // namespace v2
 } // namespace security
+
+using security::v2::KeyChain;
+
 } // namespace ndn
 
 #endif // NDN_SECURITY_V2_KEY_CHAIN_HPP
diff --git a/src/util/dummy-client-face.cpp b/src/util/dummy-client-face.cpp
index af1f702..79586c6 100644
--- a/src/util/dummy-client-face.cpp
+++ b/src/util/dummy-client-face.cpp
@@ -86,13 +86,13 @@
 
 DummyClientFace::DummyClientFace(const Options& options/* = DummyClientFace::DEFAULT_OPTIONS*/)
   : Face(make_shared<DummyClientFace::Transport>())
-  , m_internalKeyChain(new security::v1::KeyChain)
+  , m_internalKeyChain(new KeyChain)
   , m_keyChain(*m_internalKeyChain)
 {
   this->construct(options);
 }
 
-DummyClientFace::DummyClientFace(security::v1::KeyChain& keyChain,
+DummyClientFace::DummyClientFace(KeyChain& keyChain,
                                  const Options& options/* = DummyClientFace::DEFAULT_OPTIONS*/)
   : Face(make_shared<DummyClientFace::Transport>(), keyChain)
   , m_keyChain(keyChain)
@@ -103,13 +103,13 @@
 DummyClientFace::DummyClientFace(boost::asio::io_service& ioService,
                                  const Options& options/* = DummyClientFace::DEFAULT_OPTIONS*/)
   : Face(make_shared<DummyClientFace::Transport>(), ioService)
-  , m_internalKeyChain(new security::v1::KeyChain)
+  , m_internalKeyChain(new KeyChain)
   , m_keyChain(*m_internalKeyChain)
 {
   this->construct(options);
 }
 
-DummyClientFace::DummyClientFace(boost::asio::io_service& ioService, security::v1::KeyChain& keyChain,
+DummyClientFace::DummyClientFace(boost::asio::io_service& ioService, KeyChain& keyChain,
                                  const Options& options/* = DummyClientFace::DEFAULT_OPTIONS*/)
   : Face(make_shared<DummyClientFace::Transport>(), ioService, keyChain)
   , m_keyChain(keyChain)
diff --git a/src/util/dummy-client-face.hpp b/src/util/dummy-client-face.hpp
index cbf22f1..630913c 100644
--- a/src/util/dummy-client-face.hpp
+++ b/src/util/dummy-client-face.hpp
@@ -80,7 +80,7 @@
   /** \brief Create a dummy face with internal IO service and the specified KeyChain
    */
   explicit
-  DummyClientFace(security::v1::KeyChain& keyChain, const Options& options = Options());
+  DummyClientFace(KeyChain& keyChain, const Options& options = Options());
 
   /** \brief Create a dummy face with the provided IO service
    */
@@ -89,7 +89,7 @@
 
   /** \brief Create a dummy face with the provided IO service and the specified KeyChain
    */
-  DummyClientFace(boost::asio::io_service& ioService, security::v1::KeyChain& keyChain,
+  DummyClientFace(boost::asio::io_service& ioService, KeyChain& keyChain,
                   const Options& options = Options());
 
   /** \brief cause the Face to receive an interest
@@ -166,8 +166,8 @@
   Signal<DummyClientFace, lp::Nack> onSendNack;
 
 private:
-  std::unique_ptr<security::v1::KeyChain> m_internalKeyChain;
-  security::v1::KeyChain& m_keyChain;
+  std::unique_ptr<KeyChain> m_internalKeyChain;
+  KeyChain& m_keyChain;
   std::function<void(time::milliseconds)> m_processEventsOverride;
 };
 
diff --git a/src/util/notification-stream.hpp b/src/util/notification-stream.hpp
index 212f7e5..1c7887e 100644
--- a/src/util/notification-stream.hpp
+++ b/src/util/notification-stream.hpp
@@ -30,7 +30,7 @@
 
 #include "../name.hpp"
 #include "../face.hpp"
-#include "../security/v1/key-chain.hpp"
+#include "../security/v2/key-chain.hpp"
 
 #include "concepts.hpp"