Adapting to TLV-specific ndn-cpp

Change-Id: I5f39f38156221fc978db5048c1ff4a3bbb0c17d9
diff --git a/ChronoSync b/ChronoSync
index 6e235db..0cb0f2b 160000
--- a/ChronoSync
+++ b/ChronoSync
@@ -1 +1 @@
-Subproject commit 6e235db7ec1df8e6a26c28345b9e9341f84823ce
+Subproject commit 0cb0f2bcc689e6b771393036f283f035465c7c87
diff --git a/src/addcontactpanel.cpp b/src/addcontactpanel.cpp
index f43cddb..dc6618f 100644
--- a/src/addcontactpanel.cpp
+++ b/src/addcontactpanel.cpp
@@ -13,7 +13,7 @@
 #include <QMessageBox>
 
 #ifndef Q_MOC_RUN
-#include <ndn-cpp/security/signature/sha256-with-rsa-handler.hpp>
+#include <ndn-cpp/security/verifier.hpp>
 #include <boost/iostreams/stream.hpp>
 #include "null-ptrs.h"
 #include "endorse-collection.pb.h"
@@ -207,7 +207,8 @@
 {
   // _LOG_TRACE("displayContactInfo");
   const Profile& profile = m_currentEndorseCertificate->getProfileData().getProfile();
-  const Blob& profileBlob = m_currentEndorseCertificate->getProfileData().getContent();
+  const Block& profileContent = m_currentEndorseCertificate->getProfileData().getContent();
+  Buffer profileBlock(profileContent.value(), profileContent.value_size());
 
   map<string, int> endorseCount;
 
@@ -216,7 +217,8 @@
       Chronos::EndorseCollection endorseCollection;
       
       boost::iostreams::stream
-        <boost::iostreams::array_source> is ((const char*)m_currentCollectEndorse->getContent().buf(), m_currentCollectEndorse->getContent().size());
+        <boost::iostreams::array_source> is (reinterpret_cast<const char*>(m_currentCollectEndorse->getContent().value()), 
+                                             m_currentCollectEndorse->getContent().value_size());
       
       endorseCollection.ParseFromIstream(&is);
 
@@ -224,7 +226,8 @@
         {
           try{
             Data data;
-            data.wireDecode((const uint8_t*)endorseCollection.endorsement(i).blob().c_str(), endorseCollection.endorsement(i).blob().size());
+            data.wireDecode(Block(reinterpret_cast<const uint8_t*>(endorseCollection.endorsement(i).blob().c_str()),
+                                  endorseCollection.endorsement(i).blob().size()));
             EndorseCertificate endorseCert(data);
             
             Name signerKeyName = endorseCert.getSigner();
@@ -237,11 +240,12 @@
             if(!contact->isIntroducer() || !contact->canBeTrustedFor(m_currentEndorseCertificate->getProfileData().getIdentityName()))
               continue;
           
-            if(!Sha256WithRsaHandler::verifySignature(data, contact->getSelfEndorseCertificate().getPublicKeyInfo()))
+            if(!Verifier::verifySignature(data, data.getSignature(), contact->getSelfEndorseCertificate().getPublicKeyInfo()))
               continue;
 
-            const Blob& tmpProfileBlob = endorseCert.getProfileData().getContent();
-            if(!isSameBlob(profileBlob, tmpProfileBlob))
+            const Block& tmpProfileContent = endorseCert.getProfileData().getContent();
+            Buffer tmpProfileBlock(tmpProfileContent.value(), tmpProfileContent.value_size());
+            if(profileBlock != tmpProfileBlock)
               continue;
 
           const vector<string>& endorseList = endorseCert.getEndorseList();
@@ -286,26 +290,26 @@
   }
 }
 
-bool
-AddContactPanel::isSameBlob(const ndn::Blob& blobA, const ndn::Blob& blobB)
-{
-  size_t size = blobA.size();
+// bool
+// AddContactPanel::isSameBlob(const ndn::Blob& blobA, const ndn::Blob& blobB)
+// {
+//   size_t size = blobA.size();
 
-  if(size != blobB.size())
-    return false;
+//   if(size != blobB.size())
+//     return false;
 
-  const uint8_t* ap = blobA.buf();
-  const uint8_t* bp = blobB.buf();
+//   const uint8_t* ap = blobA.buf();
+//   const uint8_t* bp = blobB.buf();
   
-  for(int i = 0; i < size; i++)
-    {
-      if(ap[i] != bp[i])
-        return false;
-    }
+//   for(int i = 0; i < size; i++)
+//     {
+//       if(ap[i] != bp[i])
+//         return false;
+//     }
 
-  return true;
+//   return true;
 
-}
+// }
 
 
 #if WAF
diff --git a/src/addcontactpanel.h b/src/addcontactpanel.h
index efc1dc0..4ecf3bd 100644
--- a/src/addcontactpanel.h
+++ b/src/addcontactpanel.h
@@ -48,8 +48,8 @@
   bool
   isCorrectName(const ndn::Name& name);
 
-  static bool
-  isSameBlob(const ndn::Blob& blobA, const ndn::Blob& blobB);
+  // static bool
+  // isSameBlob(const ndn::Blob& blobA, const ndn::Blob& blobB);
 
 private slots:
   void
diff --git a/src/browsecontactdialog.cpp b/src/browsecontactdialog.cpp
index 58396ba..c84b5f9 100644
--- a/src/browsecontactdialog.cpp
+++ b/src/browsecontactdialog.cpp
@@ -17,7 +17,6 @@
 #include <boost/asio.hpp>
 #include <boost/tokenizer.hpp>
 #include "logging.h"
-#include "exception.h"
 // #include "ndn.cxx/error.h"
 #endif
 
diff --git a/src/chat-policy-rule.cpp b/src/chat-policy-rule.cpp
index db1d910..a4a6245 100644
--- a/src/chat-policy-rule.cpp
+++ b/src/chat-policy-rule.cpp
@@ -9,7 +9,7 @@
  */
 
 #include "chat-policy-rule.h"
-#include <ndn-cpp/sha256-with-rsa-signature.hpp>
+#include <ndn-cpp/security/signature/signature-sha256-with-rsa.hpp>
 
 using namespace ndn;
 using namespace std;
@@ -36,16 +36,15 @@
 bool 
 ChatPolicyRule::matchSignerName(const Data & data)
 { 
-  const Sha256WithRsaSignature* sigPtr = dynamic_cast<const Sha256WithRsaSignature*> (data.getSignature());
-
-  if(NULL == sigPtr)
+  try{
+    SignatureSha256WithRsa sig(data.getSignature());
+    Name signerName = sig.getKeyLocator().getName ();
+    return m_signerRegex->match(signerName); 
+  }catch(SignatureSha256WithRsa::Error &e){
     return false;
-
-  if(ndn_KeyLocatorType_KEYNAME != sigPtr->getKeyLocator().getType())
+  }catch(KeyLocator::Error &e){
     return false;
-
-  Name signerName = sigPtr->getKeyLocator ().getKeyName ();
-  return m_signerRegex->match(signerName); 
+  }
 }
 
 bool
diff --git a/src/chatdialog.cpp b/src/chatdialog.cpp
index c2d498d..cd7a7ea 100644
--- a/src/chatdialog.cpp
+++ b/src/chatdialog.cpp
@@ -21,7 +21,7 @@
 #include <sync-intro-certificate.h>
 #include <boost/random/random_device.hpp>
 #include <boost/random/uniform_int_distribution.hpp>
-#include <ndn-cpp/sha256-with-rsa-signature.hpp>
+#include <ndn-cpp/security/signature/signature-sha256-with-rsa.hpp>
 #include "logging.h"
 #endif
 
@@ -35,7 +35,6 @@
 Q_DECLARE_METATYPE(size_t)
 
 ChatDialog::ChatDialog(ndn::ptr_lib::shared_ptr<ContactManager> contactManager,
-                       ndn::ptr_lib::shared_ptr<ndn::IdentityManager> identityManager,
                        const ndn::Name& chatroomPrefix,
 		       const ndn::Name& localPrefix,
                        const ndn::Name& defaultIdentity,
@@ -49,7 +48,7 @@
   , m_localPrefix(localPrefix)
   , m_defaultIdentity(defaultIdentity)
   , m_invitationPolicyManager(new InvitationPolicyManager(m_chatroomPrefix.get(-1).toEscapedString(), m_defaultIdentity))
-  , m_identityManager(identityManager)
+  , m_keyChain(new ndn::KeyChain())
   , m_nick(nick)
   , m_sock(NULL)
   , m_lastMsgTime(0)
@@ -89,8 +88,8 @@
 
   startFace();
 
-  ndn::Name certificateName = m_identityManager->getDefaultCertificateNameForIdentity(m_defaultIdentity);
-  m_syncPolicyManager = ndn::ptr_lib::make_shared<SyncPolicyManager>(m_defaultIdentity, certificateName, m_chatroomPrefix, m_face, m_transport);
+  ndn::Name certificateName = m_keyChain->getDefaultCertificateNameForIdentity(m_defaultIdentity);
+  m_syncPolicyManager = ndn::ptr_lib::make_shared<SyncPolicyManager>(m_defaultIdentity, certificateName, m_chatroomPrefix, m_face);
 
   connect(ui->inviteButton, SIGNAL(clicked()),
           this, SLOT(openInviteListDialog()));
@@ -134,8 +133,7 @@
 void
 ChatDialog::startFace()
 {
-  m_transport = ndn::ptr_lib::make_shared<ndn::TcpTransport>();
-  m_face = ndn::ptr_lib::make_shared<ndn::Face>(m_transport, ndn::ptr_lib::make_shared<ndn::TcpTransport::ConnectionInfo>("localhost"));
+  m_face = ndn::ptr_lib::make_shared<ndn::Face>();
   
   connectToDaemon();
 
@@ -334,7 +332,7 @@
 {
   m_invitationPolicyManager->addTrustAnchor(contact->getSelfEndorseCertificate());
 
-  ndn::Name certificateName = m_identityManager->getDefaultCertificateNameForIdentity(m_defaultIdentity);
+  ndn::Name certificateName = m_keyChain->getDefaultCertificateNameForIdentity(m_defaultIdentity);
 
   ndn::Name interestName("/ndn/broadcast/chronos/invitation");
   interestName.append(contact->getNameSpace());
@@ -346,16 +344,11 @@
   interestName.append(certificateName);
 
   string signedUri = interestName.toUri();
-  ndn::Blob signedBlob((const uint8_t*)signedUri.c_str(), signedUri.size());
 
-  ndn::ptr_lib::shared_ptr<const ndn::Sha256WithRsaSignature> sha256sig = ndn::ptr_lib::dynamic_pointer_cast<const ndn::Sha256WithRsaSignature>(m_identityManager->signByCertificate(signedBlob.buf(), signedBlob.size(), certificateName));
-  const ndn::Blob& sigBits = sha256sig->getSignature();
+  ndn::Signature sig = m_keyChain->sign(reinterpret_cast<const uint8_t*>(signedUri.c_str()), signedUri.size(), certificateName);
+  const ndn::Block& sigValue = sig.getValue();
 
-  _LOG_DEBUG("size A: " << interestName.size());
-
-  interestName.append(sigBits);
-
-  _LOG_DEBUG("size B: " << interestName.size());
+  interestName.append(sigValue);
 
   //TODO... remove version from invitation interest
   //  interestName.appendVersion();
@@ -385,7 +378,7 @@
                                   const ndn::Name& identity, 
                                   bool isIntroducer)
 {
-  string content((const char*)data->getContent().buf(), data->getContent().size());
+  string content(reinterpret_cast<const char*>(data->getContent().value()), data->getContent().value_size());
   if(content == string("nack"))
     invitationRejected(identity);
   else
@@ -422,8 +415,8 @@
 ChatDialog::invitationAccepted(const ndn::Name& identity, ndn::ptr_lib::shared_ptr<ndn::Data> data, const string& inviteePrefix, bool isIntroducer)
 {
   _LOG_DEBUG(" " << identity.toUri() << " Accepted your invitation!");
-  const ndn::Sha256WithRsaSignature* sha256sig = dynamic_cast<const ndn::Sha256WithRsaSignature*>(data->getSignature());
-  const ndn::Name & keyLocatorName = sha256sig->getKeyLocator().getKeyName();
+  ndn::SignatureSha256WithRsa sig(data->getSignature());
+  const ndn::Name & keyLocatorName = sig.getKeyLocator().getName();
   ndn::ptr_lib::shared_ptr<ndn::IdentityCertificate> dskCertificate = m_invitationPolicyManager->getValidatedDskCertificate(keyLocatorName);
   m_syncPolicyManager->addChatDataRule(inviteePrefix, *dskCertificate, isIntroducer);
   publishIntroCert(*dskCertificate, isIntroducer);
@@ -434,15 +427,15 @@
 {
   SyncIntroCertificate syncIntroCertificate(m_chatroomPrefix,
                                             dskCertificate.getPublicKeyName(),
-                                            m_identityManager->getDefaultKeyNameForIdentity(m_defaultIdentity),
+                                            m_keyChain->getDefaultKeyNameForIdentity(m_defaultIdentity),
                                             dskCertificate.getNotBefore(),
                                             dskCertificate.getNotAfter(),
                                             dskCertificate.getPublicKeyInfo(),
                                             (isIntroducer ? SyncIntroCertificate::INTRODUCER : SyncIntroCertificate::PRODUCER));
-  ndn::Name certName = m_identityManager->getDefaultCertificateNameForIdentity(m_defaultIdentity);
+  ndn::Name certName = m_keyChain->getDefaultCertificateNameForIdentity(m_defaultIdentity);
   _LOG_DEBUG("Publish Intro Certificate: " << syncIntroCertificate.getName());
-  m_identityManager->signByCertificate(syncIntroCertificate, certName);
-  m_transport->send(*syncIntroCertificate.wireEncode());
+  m_keyChain->sign(syncIntroCertificate, certName);
+  m_face->put(syncIntroCertificate);
 }
 
 void
@@ -464,7 +457,6 @@
   m_sock = new Sync::SyncSocket(m_chatroomPrefix.toUri(),
                                 m_syncPolicyManager,
                                 m_face,
-                                m_transport,
                                 boost::bind(&ChatDialog::processTreeUpdateWrapper, this, _1, _2),
                                 boost::bind(&ChatDialog::processRemoveWrapper, this, _1));
   
@@ -604,8 +596,8 @@
 ChatDialog::processDataWrapper(const ndn::ptr_lib::shared_ptr<ndn::Data>& data)
 {
   string name = data->getName().toUri();
-  const char* buf = (const char*)data->getContent().buf();
-  size_t len = data->getContent().size();
+  const char* buf = reinterpret_cast<const char*>(data->getContent().value());
+  size_t len = data->getContent().value_size();
 
   char *tempBuf = new char[len];
   memcpy(tempBuf, buf, len);
@@ -617,8 +609,8 @@
 ChatDialog::processDataNoShowWrapper(const ndn::ptr_lib::shared_ptr<ndn::Data>& data)
 {
   string name = data->getName().toUri();
-  const char* buf = (const char*)data->getContent().buf();
-  size_t len = data->getContent().size();
+  const char* buf = reinterpret_cast<const char*>(data->getContent().value());
+  size_t len = data->getContent().value_size();
 
   char *tempBuf = new char[len];
   memcpy(tempBuf, buf, len);
@@ -899,7 +891,6 @@
       m_sock = new Sync::SyncSocket(m_chatroomPrefix.toUri(),
                                     m_syncPolicyManager,
                                     m_face,
-                                    m_transport,
                                     bind(&ChatDialog::processTreeUpdateWrapper, this, _1, _2),
                                     bind(&ChatDialog::processRemoveWrapper, this, _1));
       usleep(100000);
@@ -1050,8 +1041,7 @@
   m_newLocalPrefixReady = false;
   ndn::Name interestName("/local/ndn/prefix");
   ndn::Interest interest(interestName);
-  interest.setChildSelector(ndn_Interest_CHILD_SELECTOR_RIGHT);
-  interest.setInterestLifetimeMilliseconds(1000);
+  interest.setInterestLifetime(1000);
 
   m_face->expressInterest(interest, 
                           bind(&ChatDialog::onLocalPrefix, this, _1, _2), 
@@ -1078,7 +1068,7 @@
 ChatDialog::onLocalPrefix(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, 
                           const ndn::ptr_lib::shared_ptr<ndn::Data>& data)
 {
-  string dataString((const char*)data->getContent().buf(), data->getContent().size());
+  string dataString(reinterpret_cast<const char*>(data->getContent().value()), data->getContent().value_size());
   QString originPrefix = QString::fromStdString (dataString).trimmed ();
   string trimmedString = originPrefix.toStdString();
   m_newLocalPrefix = ndn::Name(trimmedString);
diff --git a/src/chatdialog.h b/src/chatdialog.h
index be2c89b..a4b168f 100644
--- a/src/chatdialog.h
+++ b/src/chatdialog.h
@@ -25,7 +25,7 @@
 #ifndef Q_MOC_RUN
 #include <ndn-cpp/data.hpp>
 #include <ndn-cpp/face.hpp>
-#include <ndn-cpp/security/identity/identity-manager.hpp>
+#include <ndn-cpp/security/key-chain.hpp>
 #include "invitation-policy-manager.h"
 #include "contact-item.h"
 
@@ -53,7 +53,6 @@
 
 public:
   explicit ChatDialog(ndn::ptr_lib::shared_ptr<ContactManager> contactManager,
-                      ndn::ptr_lib::shared_ptr<ndn::IdentityManager> identityManager,
                       const ndn::Name& chatroomPrefix,
                       const ndn::Name& localPrefix,
                       const ndn::Name& defaultIdentity,
@@ -344,9 +343,8 @@
   ndn::Name m_defaultIdentity;
   ndn::ptr_lib::shared_ptr<InvitationPolicyManager> m_invitationPolicyManager;
   ndn::ptr_lib::shared_ptr<SyncPolicyManager> m_syncPolicyManager; 
-  ndn::ptr_lib::shared_ptr<ndn::IdentityManager> m_identityManager;
+  ndn::ptr_lib::shared_ptr<ndn::KeyChain> m_keyChain;
   ndn::ptr_lib::shared_ptr<ndn::Face> m_face;
-  ndn::ptr_lib::shared_ptr<ndn::Transport> m_transport;
 
   boost::recursive_mutex m_mutex;
   boost::thread m_thread;
diff --git a/src/chronos-invitation.cpp b/src/chronos-invitation.cpp
index fb9d918..7912a2d 100644
--- a/src/chronos-invitation.cpp
+++ b/src/chronos-invitation.cpp
@@ -11,7 +11,6 @@
 #include "chronos-invitation.h"
 
 #include <ndn-cpp/security/certificate/identity-certificate.hpp>
-#include "exception.h"
 #include "logging.h"
 
 using namespace std;
@@ -27,7 +26,7 @@
      || interestName.get(1).toEscapedString() != string("broadcast")
      || interestName.get(2).toEscapedString() != string("chronos")
      || interestName.get(3).toEscapedString() != string("invitation"))
-    throw LnException("Wrong ChronosInvitation Name");
+    throw Error("Wrong ChronosInvitation Name");
     
   int i = 4;
   int size = interestName.size();
@@ -39,7 +38,7 @@
       break;
 
   if(i >= size)
-    throw LnException("Wrong ChronosInvitation Name, No chatroom tag");
+    throw Error("Wrong ChronosInvitation Name, No chatroom tag");
   m_inviteeNameSpace = interestName.getSubName(inviteeBegin, i - inviteeBegin);
 
   string inviterPrefixStr("inviter-prefix");
@@ -49,7 +48,7 @@
       break;
 
   if(i > size)
-    throw LnException("Wrong ChronosInvitation Name, No inviter-prefix tag");
+    throw Error("Wrong ChronosInvitation Name, No inviter-prefix tag");
   m_chatroom = interestName.getSubName(chatroomBegin, i - chatroomBegin);
 
   string inviterStr("inviter");
@@ -59,7 +58,7 @@
       break;
   
   if(i > size)
-    throw LnException("Wrong ChronosInvitation Name, No inviter tag");
+    throw Error("Wrong ChronosInvitation Name, No inviter tag");
   m_inviterPrefix = interestName.getSubName(inviterPrefixBegin, i - inviterPrefixBegin);
 
   int inviterCertBegin = (++i);
@@ -71,7 +70,7 @@
   m_inviterNameSpace = keyName.getPrefix(-1);
 
   string signedName = interestName.getSubName(0, size - 1).toUri();
-  m_signedBlob = Blob((const uint8_t*)signedName.c_str(), signedName.size());
+  m_signedBlob = Buffer(signedName.c_str(), signedName.size());
 }
 
 ChronosInvitation::ChronosInvitation(const ChronosInvitation& invitation)
diff --git a/src/chronos-invitation.h b/src/chronos-invitation.h
index e343b15..98380e8 100644
--- a/src/chronos-invitation.h
+++ b/src/chronos-invitation.h
@@ -17,6 +17,8 @@
 class ChronosInvitation
 {
 public:
+  struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
+
   ChronosInvitation() {}
 
   ChronosInvitation(const ndn::Name& interestName);
@@ -42,7 +44,7 @@
   getInviterCertificateName() const
   { return m_inviterCertificateName; }
 
-  const ndn::Blob&
+  const ndn::Buffer&
   getSignatureBits() const
   { return m_signatureBits; }
 
@@ -50,7 +52,7 @@
   getInviterNameSpace() const
   { return m_inviterNameSpace; }
 
-  const ndn::Blob&
+  const ndn::Buffer&
   getSignedBlob() const
   { return m_signedBlob; }
   
@@ -65,10 +67,10 @@
   ndn::Name m_chatroom;
   ndn::Name m_inviterPrefix;
   ndn::Name m_inviterCertificateName;
-  ndn::Blob m_signatureBits;
+  ndn::Buffer m_signatureBits;
   ndn::Name m_inviterNameSpace;
 
-  ndn::Blob m_signedBlob;
+  ndn::Buffer m_signedBlob;
 };
 
 #endif
diff --git a/src/contact-item.cpp b/src/contact-item.cpp
index 46cc4a3..8c02b29 100644
--- a/src/contact-item.cpp
+++ b/src/contact-item.cpp
@@ -9,7 +9,6 @@
  */
 
 #include "contact-item.h"
-#include "exception.h"
 #include "null-ptrs.h"
 
 #include "logging.h"
diff --git a/src/contact-manager.cpp b/src/contact-manager.cpp
index b940bd8..3095177 100644
--- a/src/contact-manager.cpp
+++ b/src/contact-manager.cpp
@@ -8,12 +8,25 @@
  * Author: Yingdi Yu <yingdi@cs.ucla.edu>
  */
 
+#if __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wreorder"
+#pragma clang diagnostic ignored "-Wtautological-compare"
+#pragma clang diagnostic ignored "-Wunused-variable"
+#pragma clang diagnostic ignored "-Wunused-function"
+#elif __GNUC__
+#pragma GCC diagnostic ignored "-Wreorder"
+#pragma GCC diagnostic ignored "-Wunused-variable"
+#pragma GCC diagnostic ignored "-Wunused-function"
+#endif
+
+
 #include "contact-manager.h"
 
 #ifndef Q_MOC_RUN
 #include <ndn-cpp/face.hpp>
-#include <ndn-cpp/sha256-with-rsa-signature.hpp>
-#include <ndn-cpp/security/signature/sha256-with-rsa-handler.hpp>
+#include <ndn-cpp/security/signature/signature-sha256-with-rsa.hpp>
+#include <ndn-cpp/security/verifier.hpp>
 #include <cryptopp/base64.h>
 #include <ndn-cpp-et/policy-manager/identity-policy-rule.hpp>
 #include <fstream>
@@ -28,15 +41,13 @@
 
 INIT_LOGGER("ContactManager");
 
-ContactManager::ContactManager(shared_ptr<IdentityManager> identityManager, 
+ContactManager::ContactManager(shared_ptr<KeyChain> keyChain, 
                                shared_ptr<Face> face,
-                               shared_ptr<Transport> transport,
                                QObject* parent)
   : QObject(parent),
-    m_face(face),
-    m_transport(transport)
+    m_face(face)
 {
-  m_identityManager = identityManager;
+  m_keyChain = keyChain;
   m_contactStorage = make_shared<ContactStorage>();
   m_dnsStorage = make_shared<DnsStorage>();
 
@@ -46,30 +57,6 @@
 ContactManager::~ContactManager()
 {}
 
-// void
-// ContactManager::connectToDaemon()
-// {
-//   //Hack! transport does not connect to daemon unless an interest is expressed.
-//   Name name("/ndn");
-//   shared_ptr<ndn::Interest> interest = make_shared<ndn::Interest>(name);
-//   m_face->expressInterest(*interest, 
-//                           bind(&ContactManager::onConnectionData, this, _1, _2),
-//                           bind(&ContactManager::onConnectionDataTimeout, this, _1));
-// }
-
-// void
-// ContactManager::onConnectionData(const shared_ptr<const ndn::Interest>& interest,
-//                             const shared_ptr<Data>& data)
-// {
-//   _LOG_DEBUG("onConnectionData");
-// }
-
-// void
-// ContactManager::onConnectionDataTimeout(const shared_ptr<const ndn::Interest>& interest)
-// {
-//   _LOG_DEBUG("onConnectionDataTimeout");
-// }
-
 void
 ContactManager::initializeSecurity()
 {
@@ -124,7 +111,7 @@
                             true,
                             new CryptoPP::Base64Decoder(new CryptoPP::StringSink(decoded)));
   Data data;
-  data.wireDecode((const uint8_t*)decoded.c_str(), decoded.size());
+  data.wireDecode(Block(reinterpret_cast<const uint8_t*>(decoded.c_str()), decoded.size()));
   shared_ptr<IdentityCertificate> anchor = make_shared<IdentityCertificate>(data);
   m_policyManager->addTrustAnchor(anchor);  
 
@@ -154,7 +141,7 @@
                             true,
                             new CryptoPP::Base64Decoder(new CryptoPP::StringSink(decoded2)));
   Data data2;
-  data2.wireDecode((const uint8_t*)decoded2.c_str(), decoded2.size());
+  data2.wireDecode(Block(reinterpret_cast<const uint8_t*>(decoded.c_str()), decoded.size()));
   shared_ptr<IdentityCertificate>anchor2 = make_shared<IdentityCertificate>(data2);
   m_policyManager->addTrustAnchor(anchor2);  
 
@@ -169,11 +156,10 @@
   interestName.append("DNS").append("PROFILE");
   
   Interest interest(interestName);
-  interest.setChildSelector(ndn_Interest_CHILD_SELECTOR_RIGHT);
 
-  OnVerified onVerified = boost::bind(&ContactManager::onDnsSelfEndorseCertificateVerified, this, _1, identity);
-  OnVerifyFailed onVerifyFailed = boost::bind(&ContactManager::onDnsSelfEndorseCertificateVerifyFailed, this, _1, identity);
-  TimeoutNotify timeoutNotify = boost::bind(&ContactManager::onDnsSelfEndorseCertificateTimeoutNotify, this, identity);
+  OnVerified onVerified = func_lib::bind(&ContactManager::onDnsSelfEndorseCertificateVerified, this, _1, identity);
+  OnVerifyFailed onVerifyFailed = func_lib::bind(&ContactManager::onDnsSelfEndorseCertificateVerifyFailed, this, _1, identity);
+  TimeoutNotify timeoutNotify = func_lib::bind(&ContactManager::onDnsSelfEndorseCertificateTimeoutNotify, this, identity);
 
   sendInterest(interest, onVerified, onVerifyFailed, timeoutNotify);
 }
@@ -188,9 +174,9 @@
 {
   try{
     Data plainData;
-    plainData.wireDecode(data->getContent().buf(), data->getContent().size());
+    plainData.wireDecode(Block(data->getContent().value(), data->getContent().value_size()));
     EndorseCertificate selfEndorseCertificate(plainData);
-    if(Sha256WithRsaHandler::verifySignature(plainData, selfEndorseCertificate.getPublicKeyInfo()))
+    if(Verifier::verifySignature(plainData, plainData.getSignature(), selfEndorseCertificate.getPublicKeyInfo()))
       emit contactFetched (selfEndorseCertificate); 
     else
       emit contactFetchFailed (identity);
@@ -212,12 +198,11 @@
   interestName.append("DNS").append("ENDORSED");
 
   Interest interest(interestName);
-  interest.setChildSelector(ndn_Interest_CHILD_SELECTOR_RIGHT);
-  interest.setInterestLifetimeMilliseconds(1000);
+  interest.setInterestLifetime(1000);
 
-  OnVerified onVerified = boost::bind(&ContactManager::onDnsCollectEndorseVerified, this, _1, identity);
-  OnVerifyFailed onVerifyFailed = boost::bind(&ContactManager::onDnsCollectEndorseVerifyFailed, this, _1, identity);
-  TimeoutNotify timeoutNotify = boost::bind(&ContactManager::onDnsCollectEndorseTimeoutNotify, this, identity);
+  OnVerified onVerified = func_lib::bind(&ContactManager::onDnsCollectEndorseVerified, this, _1, identity);
+  OnVerifyFailed onVerifyFailed = func_lib::bind(&ContactManager::onDnsCollectEndorseVerifyFailed, this, _1, identity);
+  TimeoutNotify timeoutNotify = func_lib::bind(&ContactManager::onDnsCollectEndorseTimeoutNotify, this, identity);
 
   sendInterest(interest, onVerified, onVerifyFailed, timeoutNotify);
 }
@@ -243,12 +228,11 @@
   Name interestName = certName;
   
   Interest interest(interestName);
-  interest.setChildSelector(ndn_Interest_CHILD_SELECTOR_RIGHT);
-  interest.setInterestLifetimeMilliseconds(1000);
+  interest.setInterestLifetime(1000);
 
-  OnVerified onVerified = boost::bind(&ContactManager::onKeyVerified, this, _1, certName);
-  OnVerifyFailed onVerifyFailed = boost::bind(&ContactManager::onKeyVerifyFailed, this, _1, certName);
-  TimeoutNotify timeoutNotify = boost::bind(&ContactManager::onKeyTimeoutNotify, this, certName);
+  OnVerified onVerified = func_lib::bind(&ContactManager::onKeyVerified, this, _1, certName);
+  OnVerifyFailed onVerifyFailed = func_lib::bind(&ContactManager::onKeyVerifyFailed, this, _1, certName);
+  TimeoutNotify timeoutNotify = func_lib::bind(&ContactManager::onKeyTimeoutNotify, this, certName);
 
   sendInterest(interest, onVerified, onVerifyFailed, timeoutNotify);
 }
@@ -262,12 +246,12 @@
   Profile profile(identityCertificate);
   ProfileData profileData(profile);
 
-  Name certificateName = m_identityManager->getDefaultCertificateName();
-  m_identityManager->signByCertificate(profileData, certificateName);
+  Name certificateName = m_keyChain->getDefaultCertificateName();
+  m_keyChain->sign(profileData, certificateName);
 
   try{
     EndorseCertificate endorseCertificate(identityCertificate, profileData);
-    m_identityManager->signByCertificate(endorseCertificate, certificateName);
+    m_keyChain->sign(endorseCertificate, certificateName);
     emit contactKeyFetched (endorseCertificate); 
   }catch(std::exception& e){
     _LOG_ERROR("Exception: " << e.what());
@@ -295,8 +279,7 @@
   Name interestName = certName;
   
   Interest interest(interestName);
-  interest.setChildSelector(ndn_Interest_CHILD_SELECTOR_RIGHT);
-  interest.setInterestLifetimeMilliseconds(1000);
+  interest.setInterestLifetime(1000);
 
   OnVerified onVerified = boost::bind(&ContactManager::onIdCertificateVerified, this, _1, certName);
   OnVerifyFailed onVerifyFailed = boost::bind(&ContactManager::onIdCertificateVerifyFailed, this, _1, certName);
@@ -426,7 +409,7 @@
                                       onVerifyFailed,
                                       timeoutNotify));
 
-  _LOG_DEBUG("id: " << id << " entry id: " << m_face->getNode().getEntryIndexForExpressedInterest(interest.getName()));
+  // _LOG_DEBUG("id: " << id << " entry id: " << m_face->getNode().getEntryIndexForExpressedInterest(interest.getName()));
 }
 
 void
@@ -443,11 +426,12 @@
     return;
 
   // Check if profile exists
-  Blob profileDataBlob = m_contactStorage->getSelfEndorseCertificate(identity);
-  if(CHRONOCHAT_NULL_BLOB != profileDataBlob)
+  try{
+    Block profileDataBlob = m_contactStorage->getSelfEndorseCertificate(identity);
     m_contactStorage->updateSelfEndorseCertificate(*newEndorseCertificate, identity);
-  else
+  }catch(ContactStorage::Error &e){
     m_contactStorage->addSelfEndorseCertificate(*newEndorseCertificate, identity);
+  }
 
   publishSelfEndorseCertificateInDNS(*newEndorseCertificate);
 }
@@ -455,17 +439,18 @@
 void
 ContactManager::updateEndorseCertificate(const ndn::Name& identity, const ndn::Name& signerIdentity)
 {
-  Blob oldEndorseCertificateBlob = m_contactStorage->getEndorseCertificate(identity);
   shared_ptr<EndorseCertificate> newEndorseCertificate = generateEndorseCertificate(identity, signerIdentity);
 
   if(CHRONOCHAT_NULL_ENDORSECERTIFICATE_PTR == newEndorseCertificate)
     return;
 
-  if(CHRONOCHAT_NULL_BLOB != oldEndorseCertificateBlob)
+  try{
+    Block oldEndorseCertificateBlob = m_contactStorage->getEndorseCertificate(identity);
     m_contactStorage->updateEndorseCertificate(*newEndorseCertificate, identity);
-  else
+  }catch(ContactStorage::Error &e){
     m_contactStorage->addEndorseCertificate(*newEndorseCertificate, identity);
- 
+  }
+
   publishEndorseCertificateInDNS(*newEndorseCertificate, signerIdentity);
 }
 
@@ -476,8 +461,8 @@
   if(contact == CHRONOCHAT_NULL_CONTACTITEM_PTR)
     return CHRONOCHAT_NULL_ENDORSECERTIFICATE_PTR;
 
-  Name signerKeyName = m_identityManager->getDefaultKeyNameForIdentity(signerIdentity);
-  Name signerCertName = m_identityManager->getDefaultCertificateNameForIdentity(signerIdentity);
+  Name signerKeyName = m_keyChain->getDefaultKeyNameForIdentity(signerIdentity);
+  Name signerCertName = m_keyChain->getDefaultCertificateNameForIdentity(signerIdentity);
 
   vector<string> endorseList;
   m_contactStorage->getEndorseList(identity, endorseList);
@@ -485,7 +470,7 @@
   
   try{
     shared_ptr<EndorseCertificate> cert = make_shared<EndorseCertificate>(contact->getSelfEndorseCertificate(), signerKeyName, endorseList); 
-    m_identityManager->signByCertificate(*cert, signerCertName);
+    m_keyChain->sign(*cert, signerCertName);
     return cert;
   }catch(std::exception& e){
     _LOG_ERROR("Exception: " << e.what());
@@ -505,14 +490,14 @@
 ContactManager::getSignedSelfEndorseCertificate(const Name& identity,
                                                 const Profile& profile)
 {
-  Name certificateName = m_identityManager->getDefaultCertificateNameForIdentity(identity);
+  Name certificateName = m_keyChain->getDefaultCertificateNameForIdentity(identity);
   if(0 == certificateName.size())
     return CHRONOCHAT_NULL_ENDORSECERTIFICATE_PTR;
 
   ProfileData profileData(profile);
-  m_identityManager->signByCertificate(profileData, certificateName);
+  m_keyChain->sign(profileData, certificateName);
 
-  shared_ptr<IdentityCertificate> signingCert = m_identityManager->getCertificate(certificateName);
+  shared_ptr<IdentityCertificate> signingCert = m_keyChain->getCertificate(certificateName);
   if(CHRONOCHAT_NULL_IDENTITYCERTIFICATE_PTR == signingCert)
     return CHRONOCHAT_NULL_ENDORSECERTIFICATE_PTR;
 
@@ -521,14 +506,14 @@
   shared_ptr<IdentityCertificate> kskCert;
   if(signingKeyName.get(-1).toEscapedString().substr(0,4) == string("dsk-"))
     {
-      const Sha256WithRsaSignature* dskCertSig = dynamic_cast<const Sha256WithRsaSignature*>(signingCert->getSignature());
+      SignatureSha256WithRsa dskCertSig(signingCert->getSignature());
       // HACK! KSK certificate should be retrieved from network.
-      Name keyName = IdentityCertificate::certificateNameToPublicKeyName(dskCertSig->getKeyLocator().getKeyName());
+      Name keyName = IdentityCertificate::certificateNameToPublicKeyName(dskCertSig.getKeyLocator().getName());
 
       // TODO: check null existing cases.
-      Name kskCertName = m_identityManager->getDefaultCertificateNameForIdentity(keyName.getPrefix(-1));
+      Name kskCertName = m_keyChain->getDefaultCertificateNameForIdentity(keyName.getPrefix(-1));
 
-      kskCert = m_identityManager->getCertificate(kskCertName);
+      kskCert = m_keyChain->getCertificate(kskCertName);
     }
   else
     {
@@ -545,7 +530,7 @@
   
   try{
     shared_ptr<EndorseCertificate> selfEndorseCertificate = make_shared<EndorseCertificate>(*kskCert, profileData, endorseList);
-    m_identityManager->signByCertificate(*selfEndorseCertificate, kskCert->getName());
+    m_keyChain->sign(*selfEndorseCertificate, kskCert->getName());
 
     return selfEndorseCertificate;
   }catch(std::exception& e){
@@ -573,12 +558,12 @@
 
   data.setContent(selfEndorseCertificate.wireEncode());
 
-  Name signCertName = m_identityManager->getDefaultCertificateNameForIdentity(identity);
-  m_identityManager->signByCertificate(data, signCertName);
+  Name signCertName = m_keyChain->getDefaultCertificateNameForIdentity(identity);
+  m_keyChain->sign(data, signCertName);
 
   m_dnsStorage->updateDnsSelfProfileData(data, identity);
   
-   m_transport->send(*data.wireEncode());
+  m_face->put(data);
 }
 
 void
@@ -599,12 +584,12 @@
 
   data.setContent(endorseCertificate.wireEncode());
 
-  Name signCertName = m_identityManager->getDefaultCertificateNameForIdentity(signerIdentity);
-  m_identityManager->signByCertificate(data, signCertName);
+  Name signCertName = m_keyChain->getDefaultCertificateNameForIdentity(signerIdentity);
+  m_keyChain->sign(data, signCertName);
 
   m_dnsStorage->updateDnsEndorseOthers(data, signerIdentity, endorsee);
 
-  m_transport->send(*data.wireEncode());
+  m_face->put(data);
 }
 
 void
@@ -620,29 +605,29 @@
   dnsName.append("DNS").append("ENDORSED").appendVersion(version);
   data.setName(dnsName);
   
-  vector<Blob> collectEndorseList;
+  vector<Buffer> collectEndorseList;
   m_contactStorage->getCollectEndorseList(identity, collectEndorseList);
   
   Chronos::EndorseCollection endorseCollection;
 
-  vector<Blob>::const_iterator it = collectEndorseList.begin();
+  vector<Buffer>::const_iterator it = collectEndorseList.begin();
   for(; it != collectEndorseList.end(); it++)
     {
-      string entryStr((const char*)it->buf(), it->size());
+      string entryStr(reinterpret_cast<const char*>(it->buf()), it->size());
       endorseCollection.add_endorsement()->set_blob(entryStr);
     }
 
   string encoded;
   endorseCollection.SerializeToString(&encoded);
 
-  data.setContent((const uint8_t*)encoded.c_str(), encoded.size());
+  data.setContent(reinterpret_cast<const uint8_t*>(encoded.c_str()), encoded.size());
   
-  Name signCertName = m_identityManager->getDefaultCertificateNameForIdentity(identity);
-  m_identityManager->signByCertificate(data, signCertName);
+  Name signCertName = m_keyChain->getDefaultCertificateNameForIdentity(identity);
+  m_keyChain->sign(data, signCertName);
 
   m_dnsStorage->updateDnsOthersEndorse(data, identity);
 
-  m_transport->send(*data.wireEncode());
+  m_face->put(data);
 }
 
 void
@@ -650,14 +635,14 @@
 {
   ProfileData profileData(profile);
   
-  Name certificateName = m_identityManager->getDefaultCertificateNameForIdentity (m_defaultIdentity);
-  m_identityManager->signByCertificate(profileData, certificateName);
+  Name certificateName = m_keyChain->getDefaultCertificateNameForIdentity (m_defaultIdentity);
+  m_keyChain->sign(profileData, certificateName);
 
 
   try{
     EndorseCertificate endorseCertificate(identityCertificate, profileData);
     
-    m_identityManager->signByCertificate(endorseCertificate, certificateName);
+    m_keyChain->sign(endorseCertificate, certificateName);
 
     ContactItem contactItem(endorseCertificate);
 
diff --git a/src/contact-manager.h b/src/contact-manager.h
index d096abf..d27e1cb 100644
--- a/src/contact-manager.h
+++ b/src/contact-manager.h
@@ -19,6 +19,7 @@
 #include "endorse-certificate.h"
 #include "profile.h"
 #include <ndn-cpp/face.hpp>
+#include <ndn-cpp/security/key-chain.hpp>
 #include <ndn-cpp/security/policy/validation-request.hpp>
 #include <ndn-cpp-et/policy-manager/simple-policy-manager.hpp>
 #endif
@@ -30,9 +31,8 @@
   Q_OBJECT
 
 public:
-  ContactManager(ndn::ptr_lib::shared_ptr<ndn::IdentityManager> identityManager,
+  ContactManager(ndn::ptr_lib::shared_ptr<ndn::KeyChain> keyChain,
                  ndn::ptr_lib::shared_ptr<ndn::Face> m_face,
-                 ndn::ptr_lib::shared_ptr<ndn::Transport> m_transport,
                  QObject* parent = 0);
 
   ~ContactManager();
@@ -71,7 +71,7 @@
 
   ndn::Name
   getDefaultIdentity()
-  { return m_identityManager->getDefaultIdentity(); }
+  { return m_keyChain->getDefaultIdentity(); }
 
   void
   publishEndorsedDataInDns(const ndn::Name& identity);
@@ -86,21 +86,11 @@
   void
   removeContact(const ndn::Name& contactNameSpace);
   
-  ndn::ptr_lib::shared_ptr<ndn::IdentityManager>
-  getIdentityManager()
-  { return m_identityManager; }
+  // ndn::ptr_lib::shared_ptr<ndn::KeyChain>
+  // getKeyChain()
+  // { return m_keyChain; }
 
-private:
-  // void 
-  // connectToDaemon();
-
-  // void
-  // onConnectionData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
-  //                  const ndn::ptr_lib::shared_ptr<ndn::Data>& data);
- 
-  // void
-  // onConnectionDataTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest);
-  
+private:  
   void
   initializeSecurity();
 
@@ -237,9 +227,8 @@
   ndn::ptr_lib::shared_ptr<ContactStorage> m_contactStorage;
   ndn::ptr_lib::shared_ptr<DnsStorage> m_dnsStorage;
   ndn::ptr_lib::shared_ptr<ndn::SimplePolicyManager> m_policyManager;
-  ndn::ptr_lib::shared_ptr<ndn::IdentityManager> m_identityManager;
+  ndn::ptr_lib::shared_ptr<ndn::KeyChain> m_keyChain;
   ndn::ptr_lib::shared_ptr<ndn::Face> m_face;
-  ndn::ptr_lib::shared_ptr<ndn::Transport> m_transport;
   ndn::Name m_defaultIdentity;
 };
 
diff --git a/src/contact-storage.cpp b/src/contact-storage.cpp
index 61ed746..7ea965c 100644
--- a/src/contact-storage.cpp
+++ b/src/contact-storage.cpp
@@ -10,7 +10,6 @@
 
 #include "contact-storage.h"
 #include "null-ptrs.h"
-#include "exception.h"
 
 #include <boost/filesystem.hpp>
 #include "logging.h"
@@ -118,7 +117,7 @@
 
   int res = sqlite3_open((chronosDir / "chronos.db").c_str (), &m_db);
   if (res != SQLITE_OK)
-    throw LnException("Chronos DB cannot be open/created");
+    throw Error("Chronos DB cannot be open/created");
 
   // Check if SelfProfile table exists
   sqlite3_stmt *stmt;
@@ -135,7 +134,7 @@
       char *errmsg = 0;
       res = sqlite3_exec (m_db, INIT_SP_TABLE.c_str (), NULL, NULL, &errmsg);
       if (res != SQLITE_OK && errmsg != 0)
-        throw LnException("Init \"error\" in SelfProfile");
+        throw Error("Init \"error\" in SelfProfile");
     }
 
   // Check if SelfEndorse table exists
@@ -152,7 +151,7 @@
       char *errmsg = 0;
       res = sqlite3_exec (m_db, INIT_SE_TABLE.c_str (), NULL, NULL, &errmsg);
       if (res != SQLITE_OK && errmsg != 0)
-        throw LnException("Init \"error\" in SelfEndorse");
+        throw Error("Init \"error\" in SelfEndorse");
     }
 
 
@@ -170,7 +169,7 @@
       char *errmsg = 0;
       res = sqlite3_exec (m_db, INIT_CONTACT_TABLE.c_str (), NULL, NULL, &errmsg);
       if (res != SQLITE_OK && errmsg != 0)
-        throw LnException("Init \"error\" in Contact");
+        throw Error("Init \"error\" in Contact");
     }
 
   // Check if TrustScope table exists
@@ -187,7 +186,7 @@
       char *errmsg = 0;
       res = sqlite3_exec (m_db, INIT_TS_TABLE.c_str (), NULL, NULL, &errmsg);
       if (res != SQLITE_OK && errmsg != 0)
-        throw LnException("Init \"error\" in TrustScope");
+        throw Error("Init \"error\" in TrustScope");
     }
 
   // Check if ContactProfile table exists
@@ -204,7 +203,7 @@
       char *errmsg = 0;
       res = sqlite3_exec (m_db, INIT_CP_TABLE.c_str (), NULL, NULL, &errmsg);
       if (res != SQLITE_OK && errmsg != 0)
-        throw LnException("Init \"error\" in ContactProfile");
+        throw Error("Init \"error\" in ContactProfile");
     }
 
   // Check if ProfileEndorse table exists
@@ -221,7 +220,7 @@
       char *errmsg = 0;
       res = sqlite3_exec (m_db, INIT_PE_TABLE.c_str (), NULL, NULL, &errmsg);
       if (res != SQLITE_OK && errmsg != 0)
-        throw LnException("Init \"error\" in ProfileEndorse");
+        throw Error("Init \"error\" in ProfileEndorse");
     }
 
   // Check if CollectEndorse table exists
@@ -238,7 +237,7 @@
       char *errmsg = 0;
       res = sqlite3_exec (m_db, INIT_CE_TABLE.c_str (), NULL, NULL, &errmsg);
       if (res != SQLITE_OK && errmsg != 0)
-        throw LnException("Init \"error\" in CollectEndorse");
+        throw Error("Init \"error\" in CollectEndorse");
     }
 }
 
@@ -265,13 +264,13 @@
 }
 
 void
-ContactStorage::setSelfProfileEntry(const Name& identity, const string& profileType, const Blob& profileValue)
+ContactStorage::setSelfProfileEntry(const Name& identity, const string& profileType, const Buffer &profileValue)
 {
   sqlite3_stmt *stmt;  
   if(doesSelfEntryExist(identity, profileType))
     {
       sqlite3_prepare_v2 (m_db, "UPDATE SelfProfile SET profile_value=? WHERE profile_type=? and profile_identity=?", -1, &stmt, 0);
-      sqlite3_bind_text(stmt, 1, (const char*)profileValue.buf(), profileValue.size(), SQLITE_TRANSIENT);
+      sqlite3_bind_text(stmt, 1, reinterpret_cast<const char*>(profileValue.buf()), profileValue.size(), SQLITE_TRANSIENT);
       sqlite3_bind_text(stmt, 2, profileType.c_str(), profileType.size(), SQLITE_TRANSIENT);
       sqlite3_bind_text(stmt, 3, identity.toUri().c_str(), identity.toUri().size(), SQLITE_TRANSIENT);
     }
@@ -280,7 +279,7 @@
       sqlite3_prepare_v2 (m_db, "INSERT INTO SelfProfile (profile_identity, profile_type, profile_value) values (?, ?, ?)", -1, &stmt, 0);
       sqlite3_bind_text(stmt, 1, identity.toUri().c_str(), identity.toUri().size(), SQLITE_TRANSIENT);
       sqlite3_bind_text(stmt, 2, profileType.c_str(), profileType.size(), SQLITE_TRANSIENT);
-      sqlite3_bind_text(stmt, 3, (const char*)profileValue.buf(), profileValue.size(), SQLITE_TRANSIENT);
+      sqlite3_bind_text(stmt, 3, reinterpret_cast<const char*>(profileValue.buf()), profileValue.size(), SQLITE_TRANSIENT);
     }
   sqlite3_step (stmt);
   sqlite3_finalize (stmt);
@@ -341,7 +340,7 @@
 ContactStorage::addContact(const ContactItem& contact)
 {
   if(doesContactExist(contact.getNameSpace()))
-    throw LnException("Normal Contact has already existed");
+    throw Error("Normal Contact has already existed");
 
   bool isIntroducer = contact.isIntroducer();
 
@@ -354,8 +353,8 @@
 
   sqlite3_bind_text(stmt, 1, contact.getNameSpace().toUri().c_str(),  contact.getNameSpace().toUri().size (), SQLITE_TRANSIENT);
   sqlite3_bind_text(stmt, 2, contact.getAlias().c_str(), contact.getAlias().size(), SQLITE_TRANSIENT);
-  Blob selfCertificateBlob = contact.getSelfEndorseCertificate().wireEncode();
-  sqlite3_bind_text(stmt, 3, (const char*)selfCertificateBlob.buf(), selfCertificateBlob.size(), SQLITE_TRANSIENT);
+  const Block& selfCertificateBlock = contact.getSelfEndorseCertificate().wireEncode();
+  sqlite3_bind_text(stmt, 3, reinterpret_cast<const char*>(selfCertificateBlock.wire()), selfCertificateBlock.size(), SQLITE_TRANSIENT);
   sqlite3_bind_int(stmt, 4, (isIntroducer ? 1 : 0));
 
   int res = sqlite3_step (stmt);
@@ -456,7 +455,7 @@
       string alias(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0));
 
       Data certData;
-      certData.wireDecode(reinterpret_cast<const uint8_t*>(sqlite3_column_text(stmt, 1)), sqlite3_column_bytes (stmt, 1));
+      certData.wireDecode(Block(reinterpret_cast<const uint8_t*>(sqlite3_column_text(stmt, 1)), sqlite3_column_bytes (stmt, 1)));
       EndorseCertificate endorseCertificate(certData);
 
       int isIntroducer = sqlite3_column_int (stmt, 2);
@@ -495,7 +494,7 @@
       string alias(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0));
 
       Data certData;
-      certData.wireDecode(reinterpret_cast<const uint8_t*>(sqlite3_column_text(stmt, 1)), sqlite3_column_bytes (stmt, 1));
+      certData.wireDecode(Block(reinterpret_cast<const uint8_t*>(sqlite3_column_text(stmt, 1)), sqlite3_column_bytes (stmt, 1)));
       EndorseCertificate endorseCertificate(certData);
 
       int isIntroducer = sqlite3_column_int (stmt, 2);
@@ -542,7 +541,7 @@
   return profile;
 }
 
-Blob
+Block
 ContactStorage::getSelfEndorseCertificate(const Name& identity)
 {
   sqlite3_stmt *stmt;
@@ -551,24 +550,26 @@
 
   if(sqlite3_step (stmt) == SQLITE_ROW)
     {
-      Blob result(reinterpret_cast<const uint8_t*>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0));
+      Block result(reinterpret_cast<const uint8_t*>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0));
       sqlite3_finalize (stmt);
       return result;
     }
 
   sqlite3_finalize (stmt);
 
-  return CHRONOCHAT_NULL_BLOB;
+  throw Error("ContactStorage: No self-endorse certificate found!");
+
+  return Block();
 }
 
 void
 ContactStorage::updateSelfEndorseCertificate(const EndorseCertificate& newEndorseCertificate, const Name& identity)
 {
-  Blob newEndorseCertificateBlob = newEndorseCertificate.wireEncode();
+  const Block& newEndorseCertificateBlock = newEndorseCertificate.wireEncode();
 
   sqlite3_stmt *stmt;
   sqlite3_prepare_v2 (m_db, "UPDATE SelfEndorse SET endorse_data=? WHERE identity=?", -1, &stmt, 0);
-  sqlite3_bind_text(stmt, 1, (const char*)newEndorseCertificateBlob.buf(), newEndorseCertificateBlob.size(), SQLITE_TRANSIENT);
+  sqlite3_bind_text(stmt, 1, reinterpret_cast<const char*>(newEndorseCertificateBlock.wire()), newEndorseCertificateBlock.size(), SQLITE_TRANSIENT);
   sqlite3_bind_text(stmt, 2, identity.toUri().c_str(), identity.toUri().size(), SQLITE_TRANSIENT);
   sqlite3_step(stmt);
   
@@ -578,18 +579,18 @@
 void
 ContactStorage::addSelfEndorseCertificate(const EndorseCertificate& newEndorseCertificate, const Name& identity)
 {
-  Blob newEndorseCertificateBlob = newEndorseCertificate.wireEncode();
+  const Block& newEndorseCertificateBlock = newEndorseCertificate.wireEncode();
 
   sqlite3_stmt *stmt;
   sqlite3_prepare_v2 (m_db, "INSERT INTO SelfEndorse (identity, endorse_data) values (?, ?)", -1, &stmt, 0);
   sqlite3_bind_text(stmt, 1, identity.toUri().c_str(), identity.toUri().size(), SQLITE_TRANSIENT);
-  sqlite3_bind_text(stmt, 2, (const char*)newEndorseCertificateBlob.buf(), newEndorseCertificateBlob.size(), SQLITE_TRANSIENT);
+  sqlite3_bind_text(stmt, 2, reinterpret_cast<const char*>(newEndorseCertificateBlock.wire()), newEndorseCertificateBlock.size(), SQLITE_TRANSIENT);
   sqlite3_step(stmt);
 
   sqlite3_finalize (stmt);
 }
 
-Blob
+Block
 ContactStorage::getEndorseCertificate(const Name& identity)
 {
   sqlite3_stmt *stmt;
@@ -599,24 +600,26 @@
   
   if(sqlite3_step (stmt) == SQLITE_ROW)
     {
-      Blob result(reinterpret_cast<const uint8_t*>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0));
+      Block result(reinterpret_cast<const uint8_t*>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0));
       sqlite3_finalize (stmt);
       return result;
     }
 
   sqlite3_finalize (stmt);
+
+  throw Error("ContactStorage: No endorse certificate found!");
   
-  return CHRONOCHAT_NULL_BLOB;
+  return Block();
 }
 
 void
 ContactStorage::updateEndorseCertificate(const EndorseCertificate& endorseCertificate, const Name& identity)
 {
-  Blob newEndorseCertificateBlob = endorseCertificate.wireEncode();
+  const Block& newEndorseCertificateBlock = endorseCertificate.wireEncode();
 
   sqlite3_stmt *stmt;
   sqlite3_prepare_v2 (m_db, "UPDATE ProfileEndorse SET endorse_data=? WHERE identity=?", -1, &stmt, 0);
-  sqlite3_bind_text(stmt, 1, (const char*)newEndorseCertificateBlob.buf(), newEndorseCertificateBlob.size(), SQLITE_TRANSIENT);
+  sqlite3_bind_text(stmt, 1, reinterpret_cast<const char*>(newEndorseCertificateBlock.wire()), newEndorseCertificateBlock.size(), SQLITE_TRANSIENT);
   sqlite3_bind_text(stmt, 2, identity.toUri().c_str(), identity.toUri().size(), SQLITE_TRANSIENT);
   sqlite3_step(stmt);
 
@@ -626,12 +629,12 @@
 void
 ContactStorage::addEndorseCertificate(const EndorseCertificate& endorseCertificate, const Name& identity)
 {
-  Blob newEndorseCertificateBlob = endorseCertificate.wireEncode();
+  const Block& newEndorseCertificateBlock = endorseCertificate.wireEncode();
 
   sqlite3_stmt *stmt;
   sqlite3_prepare_v2 (m_db, "INSERT INTO ProfileEndorse (identity, endorse_data) values (?, ?)", -1, &stmt, 0);
   sqlite3_bind_text(stmt, 1, identity.toUri().c_str(), identity.toUri().size(), SQLITE_TRANSIENT);
-  sqlite3_bind_text(stmt, 2, (const char*)newEndorseCertificateBlob.buf(), newEndorseCertificateBlob.size(), SQLITE_TRANSIENT);
+  sqlite3_bind_text(stmt, 2, reinterpret_cast<const char*>(newEndorseCertificateBlock.value()), newEndorseCertificateBlock.size(), SQLITE_TRANSIENT);
   sqlite3_step(stmt);
 
   sqlite3_finalize (stmt);
@@ -683,8 +686,8 @@
       sqlite3_bind_text(stmt, 1, endorserName.toUri().c_str(), endorserName.toUri().size(), SQLITE_TRANSIENT);
       sqlite3_bind_text(stmt, 2, endorseeName.toUri().c_str(), endorseeName.toUri().size(), SQLITE_TRANSIENT);
       sqlite3_bind_text(stmt, 3, getCertName.toUri().c_str(), getCertName.toUri().size(), SQLITE_TRANSIENT);
-      Blob blob = endorseCertificate.wireEncode();
-      sqlite3_bind_text(stmt, 4, (const char*)blob.buf(), blob.size(), SQLITE_TRANSIENT);
+      const Block &block = endorseCertificate.wireEncode();
+      sqlite3_bind_text(stmt, 4, reinterpret_cast<const char*>(block.wire()), block.size(), SQLITE_TRANSIENT);
       int res = sqlite3_step (stmt);
       sqlite3_finalize (stmt); 
       return;
@@ -693,8 +696,8 @@
     {
       sqlite3_prepare_v2 (m_db, "UPDATE CollectEndorse SET endorse_name=?, endorse_data=? WHERE endorser=? AND endorsee=?", -1, &stmt, 0);
       sqlite3_bind_text(stmt, 1, getCertName.toUri().c_str(), getCertName.toUri().size(), SQLITE_TRANSIENT);
-      Blob blob = endorseCertificate.wireEncode();
-      sqlite3_bind_text(stmt, 2, (const char*)blob.buf(), blob.size(), SQLITE_TRANSIENT);
+      const Block &block = endorseCertificate.wireEncode();
+      sqlite3_bind_text(stmt, 2, reinterpret_cast<const char*>(block.value()), block.size(), SQLITE_TRANSIENT);
       sqlite3_bind_text(stmt, 3, endorserName.toUri().c_str(), endorserName.toUri().size(), SQLITE_TRANSIENT);
       sqlite3_bind_text(stmt, 4, endorseeName.toUri().c_str(), endorseeName.toUri().size(), SQLITE_TRANSIENT);
       int res = sqlite3_step (stmt);
@@ -704,7 +707,7 @@
 }
 
 void
-ContactStorage::getCollectEndorseList(const Name& name, vector<Blob>& endorseList)
+ContactStorage::getCollectEndorseList(const Name& name, vector<Buffer>& endorseList)
 {
   sqlite3_stmt *stmt;
   sqlite3_prepare_v2 (m_db, "SELECT endorse_data FROM CollectEndorse WHERE endorsee=?", -1, &stmt, 0);
@@ -712,7 +715,7 @@
 
   while(sqlite3_step (stmt) == SQLITE_ROW)
     {
-      Blob blob(reinterpret_cast<const uint8_t*>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0));
+      Buffer blob(reinterpret_cast<const uint8_t*>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0));
       endorseList.push_back(blob);
     }
 
diff --git a/src/contact-storage.h b/src/contact-storage.h
index 8b7bc6e..dfc06ef 100644
--- a/src/contact-storage.h
+++ b/src/contact-storage.h
@@ -14,20 +14,21 @@
 #include <sqlite3.h>
 #include "contact-item.h"
 #include "endorse-certificate.h"
-#include <ndn-cpp/security/identity/identity-manager.hpp>
 
 
 class ContactStorage
 {
 
 public:
+  struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
+
   ContactStorage();
   
   ~ContactStorage() 
   {sqlite3_close(m_db);}
 
   void
-  setSelfProfileEntry(const ndn::Name& identity, const std::string& profileType, const ndn::Blob& profileValue);
+  setSelfProfileEntry(const ndn::Name& identity, const std::string& profileType, const ndn::Buffer& profileValue);
 
   ndn::ptr_lib::shared_ptr<Profile>
   getSelfProfile(const ndn::Name& identity);
@@ -55,7 +56,7 @@
 
 
   //SelfEndorse
-  ndn::Blob
+  ndn::Block
   getSelfEndorseCertificate(const ndn::Name& identity);
 
   void
@@ -66,7 +67,7 @@
 
 
   //ProfileEndorse
-  ndn::Blob
+  ndn::Block
   getEndorseCertificate(const ndn::Name& identity);
 
   void
@@ -84,7 +85,7 @@
   updateCollectEndorse(const EndorseCertificate& endorseCertificate);
 
   void
-  getCollectEndorseList(const ndn::Name& name, std::vector<ndn::Blob>& endorseList);
+  getCollectEndorseList(const ndn::Name& name, std::vector<ndn::Buffer>& endorseList);
   
 
 private:
diff --git a/src/contactpanel.cpp b/src/contactpanel.cpp
index d9f3324..0a9ffcd 100644
--- a/src/contactpanel.cpp
+++ b/src/contactpanel.cpp
@@ -21,16 +21,14 @@
 #include <QtSql/QSqlError>
 
 #ifndef Q_MOC_RUN
-#include <ndn-cpp/security/identity/osx-private-key-storage.hpp>
-#include <ndn-cpp/security/identity/basic-identity-storage.hpp>
-#include <ndn-cpp/security/signature/sha256-with-rsa-handler.hpp>
+#include <ndn-cpp/security/verifier.hpp>
+#include <ndn-cpp/security/signature/signature-sha256-with-rsa.hpp>
 #include <boost/filesystem.hpp>
 #include <boost/random/random_device.hpp>
 #include <boost/random/uniform_int_distribution.hpp>
 #include "panel-policy-manager.h"
 #include "null-ptrs.h"
 #include "logging.h"
-#include "exception.h"
 #endif
 
 namespace fs = boost::filesystem;
@@ -61,11 +59,9 @@
 
   createAction();
 
-  shared_ptr<BasicIdentityStorage> publicStorage = make_shared<BasicIdentityStorage>();
-  shared_ptr<OSXPrivateKeyStorage> privateStorage = make_shared<OSXPrivateKeyStorage>();
-  m_identityManager = make_shared<IdentityManager>(publicStorage, privateStorage);
+  m_keyChain = make_shared<KeyChain>();
 
-  m_contactManager = make_shared<ContactManager>(m_identityManager, m_face, m_transport);
+  m_contactManager = make_shared<ContactManager>(m_keyChain, m_face);
 
   connect(&*m_contactManager, SIGNAL(noNdnConnection(const QString&)),
           this, SLOT(showError(const QString&)));
@@ -76,10 +72,10 @@
 
   loadTrustAnchor();
 
-  m_defaultIdentity = m_identityManager->getDefaultIdentity();
+  m_defaultIdentity = m_keyChain->getDefaultIdentity();
   if(m_defaultIdentity.size() == 0)
     showError(QString::fromStdString("certificate of ") + QString::fromStdString(m_defaultIdentity.toUri()) + " is missing!\nHave you installed the certificate?");
-  Name defaultCertName = m_identityManager->getDefaultCertificateNameForIdentity(m_defaultIdentity);
+  Name defaultCertName = m_keyChain->getDefaultCertificateNameForIdentity(m_defaultIdentity);
   if(defaultCertName.size() == 0)
     showError(QString::fromStdString("certificate of ") + QString::fromStdString(m_defaultIdentity.toUri()) + " is missing!\nHave you installed the certificate?");
 
@@ -206,8 +202,7 @@
 void
 ContactPanel::startFace()
 {
-  m_transport = make_shared<TcpTransport>();
-  m_face = make_shared<Face>(m_transport, make_shared<TcpTransport::ConnectionInfo>("localhost"));
+  m_face = make_shared<Face>();
   
   connectToDaemon();
 
@@ -248,8 +243,8 @@
   Name name("/ndn");
   ndn::Interest interest(name);
   m_face->expressInterest(interest, 
-                          bind(&ContactPanel::onConnectionData, this, _1, _2),
-                          bind(&ContactPanel::onConnectionDataTimeout, this, _1));
+                          func_lib::bind(&ContactPanel::onConnectionData, this, _1, _2),
+                          func_lib::bind(&ContactPanel::onConnectionDataTimeout, this, _1));
 }
 
 void
@@ -299,11 +294,10 @@
 {
   Name interestName("/local/ndn/prefix");
   Interest interest(interestName);
-  interest.setChildSelector(ndn_Interest_CHILD_SELECTOR_RIGHT);
 
   m_face->expressInterest(interest, 
-                          bind(&ContactPanel::onLocalPrefix, this, _1, _2), 
-                          bind(&ContactPanel::onLocalPrefixTimeout, this, _1, 10));
+                          func_lib::bind(&ContactPanel::onLocalPrefix, this, _1, _2), 
+                          func_lib::bind(&ContactPanel::onLocalPrefixTimeout, this, _1, 10));
   
 }
 
@@ -311,7 +305,7 @@
 ContactPanel::onLocalPrefix(const shared_ptr<const Interest>& interest, 
                             const shared_ptr<Data>& data)
 {
-  string originPrefix((const char*)data->getContent().buf(), data->getContent().size());
+  string originPrefix((const char*)data->getContent().value(), data->getContent().value_size());
   string prefix = QString::fromStdString (originPrefix).trimmed ().toUtf8().constData();
   string randomSuffix = getRandomString();
   m_localPrefix = Name(prefix);
@@ -338,9 +332,9 @@
   m_inviteListenPrefix = Name("/ndn/broadcast/chronos/invitation");
   m_inviteListenPrefix.append(m_defaultIdentity);
   _LOG_DEBUG("Listening for invitation on prefix: " << m_inviteListenPrefix.toUri());
-  m_invitationListenerId = m_face->registerPrefix(m_inviteListenPrefix, 
-                                                  boost::bind(&ContactPanel::onInvitation, this, _1, _2, _3, _4),
-                                                  boost::bind(&ContactPanel::onInvitationRegisterFailed, this, _1));
+  m_invitationListenerId = m_face->setInterestFilter(m_inviteListenPrefix, 
+                                                     func_lib::bind(&ContactPanel::onInvitation, this, _1, _2, _3, _4),
+                                                     func_lib::bind(&ContactPanel::onInvitationRegisterFailed, this, _1));
 }
 
 void
@@ -352,7 +346,7 @@
                            int stepCount /* = 0 */)
 {
   m_face->expressInterest(interest, 
-                          boost::bind(&ContactPanel::onTargetData, 
+                          func_lib::bind(&ContactPanel::onTargetData, 
                                       this,
                                       _1,
                                       _2,
@@ -360,7 +354,7 @@
                                       onVerified, 
                                       onVerifyFailed,
                                       timeoutNotify),
-                          boost::bind(&ContactPanel::onTargetTimeout,
+                          func_lib::bind(&ContactPanel::onTargetTimeout,
                                       this,
                                       _1,
                                       retry,
@@ -383,8 +377,8 @@
   if (nextStep)
     m_face->expressInterest
       (*nextStep->interest_, 
-       bind(&ContactPanel::onCertData, this, _1, _2, nextStep), 
-       bind(&ContactPanel::onCertTimeout, this, _1, onVerifyFailed, data, nextStep));
+       func_lib::bind(&ContactPanel::onCertData, this, _1, _2, nextStep), 
+       func_lib::bind(&ContactPanel::onCertTimeout, this, _1, onVerifyFailed, data, nextStep));
 
 }
 
@@ -418,8 +412,8 @@
   if (nextStep)
     m_face->expressInterest
       (*nextStep->interest_, 
-       bind(&ContactPanel::onCertData, this, _1, _2, nextStep), 
-       bind(&ContactPanel::onCertTimeout, this, _1, previousStep->onVerifyFailed_, cert, nextStep));
+       func_lib::bind(&ContactPanel::onCertData, this, _1, _2, nextStep), 
+       func_lib::bind(&ContactPanel::onCertTimeout, this, _1, previousStep->onVerifyFailed_, cert, nextStep));
 }
 
 void
@@ -430,12 +424,12 @@
 {
   if(nextStep->retry_ > 0)
     m_face->expressInterest(*interest, 
-                            bind(&ContactPanel::onCertData,
+                            func_lib::bind(&ContactPanel::onCertData,
                                  this,
                                  _1,
                                  _2,
                                  nextStep),
-                            bind(&ContactPanel::onCertTimeout,
+                            func_lib::bind(&ContactPanel::onCertTimeout,
                                  this,
                                  _1,
                                  onVerifyFailed,
@@ -478,7 +472,11 @@
     }
 
   shared_ptr<PublicKey> keyPtr = m_policyManager->getTrustedKey(invitation->getInviterCertificateName());
-  if(CHRONOCHAT_NULL_PUBLICKEY_PTR != keyPtr && Sha256WithRsaHandler::verifySignature(invitation->getSignedBlob(), invitation->getSignatureBits(), *keyPtr))
+
+  SignatureSha256WithRsa invitationSig;
+  Block sigBlock(invitation->getSignatureBits().buf(), invitation->getSignatureBits().size());
+  invitationSig.setValue(sigBlock);
+  if(CHRONOCHAT_NULL_PUBLICKEY_PTR != keyPtr && Verifier::verifySignature(invitation->getSignedBlob(), invitationSig, *keyPtr))
     {
       shared_ptr<IdentityCertificate> certificate = make_shared<IdentityCertificate>();
       // hack: incomplete certificate, we don't send it to the wire nor store it anywhere, we only use it to carry information
@@ -508,9 +506,9 @@
   _LOG_DEBUG("Cannot find the inviter's key in trust anchors");
 
   Interest newInterest(invitation->getInviterCertificateName());
-  OnVerified onVerified = boost::bind(&ContactPanel::onInvitationCertVerified, this, _1, invitation);
-  OnVerifyFailed onVerifyFailed = boost::bind(&ContactPanel::onInvitationCertVerifyFailed, this, _1);
-  TimeoutNotify timeoutNotify = boost::bind(&ContactPanel::onInvitationCertTimeoutNotify, this);
+  OnVerified onVerified = func_lib::bind(&ContactPanel::onInvitationCertVerified, this, _1, invitation);
+  OnVerifyFailed onVerifyFailed = func_lib::bind(&ContactPanel::onInvitationCertVerifyFailed, this, _1);
+  TimeoutNotify timeoutNotify = func_lib::bind(&ContactPanel::onInvitationCertTimeoutNotify, this);
 
   sendInterest(newInterest, onVerified, onVerifyFailed, timeoutNotify);
 }
@@ -520,8 +518,12 @@
                                        shared_ptr<ChronosInvitation> invitation)
 {
   shared_ptr<IdentityCertificate> certificate = make_shared<IdentityCertificate>(*data);
+
+  SignatureSha256WithRsa invitationSig;
+  Block sigBlock(invitation->getSignatureBits().buf(), invitation->getSignatureBits().size());
+  invitationSig.setValue(sigBlock);
   
-  if(Sha256WithRsaHandler::verifySignature(invitation->getSignedBlob(), invitation->getSignatureBits(), certificate->getPublicKeyInfo()))
+  if(Verifier::verifySignature(invitation->getSignedBlob(), invitationSig, certificate->getPublicKeyInfo()))
     {
       Name keyName = certificate->getPublicKeyName();
       Name inviterNameSpace = keyName.getPrefix(-1);
@@ -568,12 +570,11 @@
       Name interestName = (*it)->getNameSpace();
       interestName.append("DNS").append(m_defaultIdentity).append("ENDORSEE");
       Interest interest(interestName);
-      interest.setChildSelector(ndn_Interest_CHILD_SELECTOR_RIGHT);
-      interest.setInterestLifetimeMilliseconds(1000);
+      interest.setInterestLifetime(1000);
 
-      OnVerified onVerified = boost::bind(&ContactPanel::onDnsEndorseeVerified, this, _1, count);
-      OnVerifyFailed onVerifyFailed = boost::bind(&ContactPanel::onDnsEndorseeVerifyFailed, this, _1, count);
-      TimeoutNotify timeoutNotify = boost::bind(&ContactPanel::onDnsEndorseeTimeoutNotify, this, count);
+      OnVerified onVerified = func_lib::bind(&ContactPanel::onDnsEndorseeVerified, this, _1, count);
+      OnVerifyFailed onVerifyFailed = func_lib::bind(&ContactPanel::onDnsEndorseeVerifyFailed, this, _1, count);
+      TimeoutNotify timeoutNotify = func_lib::bind(&ContactPanel::onDnsEndorseeTimeoutNotify, this, count);
   
       sendInterest(interest, onVerified, onVerifyFailed, timeoutNotify, 0);
     }
@@ -583,7 +584,7 @@
 ContactPanel::onDnsEndorseeVerified(const shared_ptr<Data>& data, int count)
 {
   Data endorseData;
-  endorseData.wireDecode(data->getContent().buf(), data->getContent().size());
+  endorseData.wireDecode(Block(data->getContent().value(), data->getContent().value_size()));
   EndorseCertificate endorseCertificate(endorseData);
 
   m_contactManager->getContactStorage()->updateCollectEndorse(endorseCertificate);
@@ -731,7 +732,7 @@
 { 
   // _LOG_DEBUG(identity.toStdString());
   Name defaultIdentity = Name(identity.toStdString());
-  Name defaultCertName = m_identityManager->getDefaultCertificateNameForIdentity(defaultIdentity);
+  Name defaultCertName = m_keyChain->getDefaultCertificateNameForIdentity(defaultIdentity);
   if(defaultCertName.size() == 0)
     {
       showWarning(QString::fromStdString("Corresponding certificate is missing!\nHave you installed the certificate?"));
@@ -740,7 +741,7 @@
   m_defaultIdentity = defaultIdentity;
   m_profileEditor->setCurrentIdentity(m_defaultIdentity);
   m_nickName = nickName.toStdString();
-  m_face->removeRegisteredPrefix(m_invitationListenerId);
+  m_face->unsetInterestFilter(m_invitationListenerId);
   m_contactManager->setDefaultIdentity(m_defaultIdentity);
   setInvitationListener();
   collectEndorsement();
@@ -860,7 +861,7 @@
   Name inviteeNamespace(invitee.toStdString());
   shared_ptr<ContactItem> inviteeItem = m_contactManager->getContact(inviteeNamespace);
 
-  ChatDialog* chatDialog = new ChatDialog(m_contactManager, m_identityManager, chatroomName, m_localPrefix, m_defaultIdentity, m_nickName);
+  ChatDialog* chatDialog = new ChatDialog(m_contactManager, chatroomName, m_localPrefix, m_defaultIdentity, m_nickName);
   m_chatDialogs.insert(pair <Name, ChatDialog*> (chatroomName, chatDialog));
 
   connect(chatDialog, SIGNAL(closeChatDialog(const ndn::Name&)),
@@ -886,7 +887,7 @@
   Name chatroomName("/ndn/broadcast/chronos");
   chatroomName.append(invitation.getChatroom());
 
-  ChatDialog* chatDialog = new ChatDialog(m_contactManager, m_identityManager, chatroomName, m_localPrefix, m_defaultIdentity, m_nickName, true);
+  ChatDialog* chatDialog = new ChatDialog(m_contactManager, chatroomName, m_localPrefix, m_defaultIdentity, m_nickName, true);
 
   connect(chatDialog, SIGNAL(closeChatDialog(const ndn::Name&)),
           this, SLOT(removeChatDialog(const ndn::Name&)));
@@ -917,18 +918,17 @@
   Data data(dataName);
   string content = m_localPrefix.toUri();
   data.setContent((const uint8_t *)&content[0], content.size());
-  data.getMetaInfo().setTimestampMilliseconds(time(NULL) * 1000.0);
 
   Name certificateName;
   Name inferredIdentity = m_policyManager->inferSigningIdentity(data.getName());
 
   if(inferredIdentity.getComponentCount() == 0)
-    certificateName = m_identityManager->getDefaultCertificateName();
+    certificateName = m_keyChain->getDefaultCertificateName();
   else
-    certificateName = m_identityManager->getDefaultCertificateNameForIdentity(inferredIdentity);   
-  m_identityManager->signByCertificate(data, certificateName);
+    certificateName = m_keyChain->getDefaultCertificateNameForIdentity(inferredIdentity);   
+  m_keyChain->sign(data, certificateName);
 
-  m_transport->send(*data.wireEncode());
+  m_face->put(data);
 
   startChatroom2(invitation, identityCertificate);
 }
@@ -939,17 +939,16 @@
   Data data(invitation.getInterestName());
   string content("nack");
   data.setContent((const uint8_t *)&content[0], content.size());
-  data.getMetaInfo().setTimestampMilliseconds(time(NULL) * 1000.0);
 
   Name certificateName;
   Name inferredIdentity = m_policyManager->inferSigningIdentity(data.getName());
   if(inferredIdentity.getComponentCount() == 0)
-    certificateName = m_identityManager->getDefaultCertificateName();
+    certificateName = m_keyChain->getDefaultCertificateName();
   else
-    certificateName = m_identityManager->getDefaultCertificateNameForIdentity(inferredIdentity);   
-  m_identityManager->signByCertificate(data, certificateName);
+    certificateName = m_keyChain->getDefaultCertificateNameForIdentity(inferredIdentity);   
+  m_keyChain->sign(data, certificateName);
 
-  m_transport->send(*data.wireEncode());
+  m_face->put(data);
 }
 
 void
diff --git a/src/contactpanel.h b/src/contactpanel.h
index 615a836..ce7f7b7 100644
--- a/src/contactpanel.h
+++ b/src/contactpanel.h
@@ -285,8 +285,7 @@
   ndn::ptr_lib::shared_ptr<std::vector<bool> > m_collectStatus;
 
   ndn::ptr_lib::shared_ptr<PanelPolicyManager> m_policyManager;
-  ndn::ptr_lib::shared_ptr<ndn::IdentityManager> m_identityManager;
-  ndn::ptr_lib::shared_ptr<ndn::Transport> m_transport;
+  ndn::ptr_lib::shared_ptr<ndn::KeyChain> m_keyChain;
   ndn::ptr_lib::shared_ptr<ndn::Face> m_face;
 
   boost::recursive_mutex m_mutex;
diff --git a/src/dns-storage.cpp b/src/dns-storage.cpp
index a5a9588..7ce9245 100644
--- a/src/dns-storage.cpp
+++ b/src/dns-storage.cpp
@@ -10,7 +10,6 @@
 
 #include "dns-storage.h"
 #include "null-ptrs.h"
-#include "exception.h"
 
 #include <boost/filesystem.hpp>
 #include "logging.h"
@@ -45,7 +44,7 @@
 
   int res = sqlite3_open((chronosDir / "dns.db").c_str (), &m_db);
   if (res != SQLITE_OK)
-    throw LnException("Chronos DNS DB cannot be open/created");
+    throw Error("Chronos DNS DB cannot be open/created");
 
   // Check if SelfProfile table exists
   sqlite3_stmt *stmt;
@@ -62,7 +61,7 @@
       char *errmsg = 0;
       res = sqlite3_exec (m_db, INIT_DD_TABLE.c_str (), NULL, NULL, &errmsg);
       if (res != SQLITE_OK && errmsg != 0)
-        throw LnException("Init \"error\" in DnsData");
+        throw Error("Init \"error\" in DnsData");
     }
 }
 
@@ -72,7 +71,7 @@
 }
 
 void
-DnsStorage::updateDnsData(const ndn::Blob& data, const std::string& identity, const std::string& name, const std::string& type, const string& dataName)
+DnsStorage::updateDnsData(const ndn::Block& data, const std::string& identity, const std::string& name, const std::string& type, const string& dataName)
 {  
   sqlite3_stmt *stmt;
   sqlite3_prepare_v2 (m_db, "SELECT data_name FROM DnsData where dns_identity=? and dns_name=? and dns_type=?", -1, &stmt, 0);
@@ -87,7 +86,7 @@
       sqlite3_bind_text(stmt, 1, identity.c_str(), identity.size(), SQLITE_TRANSIENT);
       sqlite3_bind_text(stmt, 2, name.c_str(), name.size(), SQLITE_TRANSIENT);
       sqlite3_bind_text(stmt, 3, type.c_str(), type.size(), SQLITE_TRANSIENT);
-      sqlite3_bind_text(stmt, 4, (const char*)data.buf(), data.size(), SQLITE_TRANSIENT); 
+      sqlite3_bind_text(stmt, 4, (const char*)data.wire(), data.size(), SQLITE_TRANSIENT); 
       sqlite3_bind_text(stmt, 5, dataName.c_str(), dataName.size(), SQLITE_TRANSIENT);
       sqlite3_step(stmt);
       sqlite3_finalize(stmt);
@@ -96,7 +95,7 @@
     {
       sqlite3_finalize(stmt);
       sqlite3_prepare_v2 (m_db, "UPDATE DnsData SET dns_value=?, data_name=? WHERE dns_identity=? and dns_name=?, dns_type=?", -1, &stmt, 0);
-      sqlite3_bind_text(stmt, 1, (const char*)data.buf(), data.size(), SQLITE_TRANSIENT);
+      sqlite3_bind_text(stmt, 1, (const char*)data.wire(), data.size(), SQLITE_TRANSIENT);
       sqlite3_bind_text(stmt, 2, dataName.c_str(), dataName.size(), SQLITE_TRANSIENT);
       sqlite3_bind_text(stmt, 3, identity.c_str(), identity.size(), SQLITE_TRANSIENT);
       sqlite3_bind_text(stmt, 4, name.c_str(), name.size(), SQLITE_TRANSIENT);
@@ -112,9 +111,9 @@
   string dnsIdentity = identity.toUri();
   string dnsName("N/A");
   string dnsType("PROFILE");
-  Blob dnsValue = data.wireEncode();
+  
 
-  updateDnsData(dnsValue, dnsIdentity, dnsName, dnsType, data.getName().toUri());
+  updateDnsData(data.wireEncode(), dnsIdentity, dnsName, dnsType, data.getName().toUri());
 }
 
 void
@@ -123,9 +122,8 @@
   string dnsIdentity = identity.toUri();
   string dnsName = endorsee.toUri();
   string dnsType("ENDORSEE");
-  Blob dnsValue = data.wireEncode();
 
-  updateDnsData(dnsValue, dnsIdentity, dnsName, dnsType, data.getName().toUri());
+  updateDnsData(data.wireEncode(), dnsIdentity, dnsName, dnsType, data.getName().toUri());
 }
   
 void
@@ -134,9 +132,8 @@
   string dnsIdentity = identity.toUri();
   string dnsName("N/A");
   string dnsType("ENDORSED");
-  Blob dnsValue = data.wireEncode();
 
-  updateDnsData(dnsValue, dnsIdentity, dnsName, dnsType, data.getName().toUri());
+  updateDnsData(data.wireEncode(), dnsIdentity, dnsName, dnsType, data.getName().toUri());
 }
 
 shared_ptr<Data>
@@ -149,7 +146,7 @@
   if(sqlite3_step (stmt) == SQLITE_ROW)
     {
       shared_ptr<Data> data = make_shared<Data>();
-      data->wireDecode(reinterpret_cast<const uint8_t*>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0));
+      data->wireDecode(Block(reinterpret_cast<const uint8_t*>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0)));
       sqlite3_finalize(stmt);
       return data;
     }
diff --git a/src/dns-storage.h b/src/dns-storage.h
index 0c7934b..de37540 100644
--- a/src/dns-storage.h
+++ b/src/dns-storage.h
@@ -17,6 +17,8 @@
 class DnsStorage
 {
 public:
+  struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
+
   DnsStorage();
 
   ~DnsStorage();
@@ -35,7 +37,7 @@
 
 private:
   void
-  updateDnsData(const ndn::Blob& data, const std::string& identity, const std::string& name, const std::string& type, const std::string& dataName);
+  updateDnsData(const ndn::Block& data, const std::string& identity, const std::string& name, const std::string& type, const std::string& dataName);
 
 private:
   sqlite3 *m_db;
diff --git a/src/endorse-certificate.cpp b/src/endorse-certificate.cpp
index 8101eb3..ae07796 100644
--- a/src/endorse-certificate.cpp
+++ b/src/endorse-certificate.cpp
@@ -9,7 +9,6 @@
  */
 
 #include "endorse-certificate.h"
-#include "exception.h"
 #include "endorse-extension.pb.h"
 #include <boost/date_time/posix_time/posix_time.hpp>
 #include <boost/iostreams/stream.hpp>
@@ -23,7 +22,7 @@
 INIT_LOGGER("EndorseCertificate");
 
 ProfileExtension::ProfileExtension(const ProfileData & profileData)
-  : CertificateExtension("1.3.6.1.5.32.2.1", true, profileData.wireEncode())
+  : CertificateExtension("1.3.6.1.5.32.2.1", true, Buffer(profileData.wireEncode().wire(), profileData.wireEncode().size()))
 {}
 
 ProfileExtension::ProfileExtension(const ProfileExtension& profileExtension)
@@ -34,14 +33,14 @@
   : CertificateExtension(extension.getOid(), extension.getIsCritical(), extension.getValue())
 {
   if(extensionId_ != OID("1.3.6.1.5.32.2.1"))
-    throw LnException("Wrong ProfileExtension Number!");
+    throw Error("Wrong ProfileExtension Number!");
 }
 
 shared_ptr<ProfileData>
 ProfileExtension::getProfileData()
 {
   Data data;
-  data.wireDecode(extensionValue_.buf(), extensionValue_.size());
+  data.wireDecode(Block(extensionValue_.buf(), extensionValue_.size()));
   return make_shared<ProfileData>(data);
 }
 
@@ -57,7 +56,7 @@
   : CertificateExtension(extension.getOid(), extension.getIsCritical(), extension.getValue())
 {
   if(extensionId_ != OID("1.3.6.1.5.32.2.2"))
-    throw LnException("Wrong EndorseExtension Number!");
+    throw Error("Wrong EndorseExtension Number!");
 }
 
 vector<string>
@@ -78,7 +77,7 @@
   return endorseList;
 }
 
-Blob
+Buffer
 EndorseExtension::encodeEndorseList(const vector<string>& endorseList)
 {
   Chronos::EndorseExtensionMsg endorseExtension;
@@ -90,7 +89,7 @@
   string encoded;
   endorseExtension.SerializeToString(&encoded);
   
-  return Blob((const uint8_t*)encoded.c_str(), encoded.size());
+  return Buffer(encoded.c_str(), encoded.size());
 }
 
 EndorseCertificate::EndorseCertificate(const IdentityCertificate& kskCertificate,
@@ -168,7 +167,7 @@
 	}
     }
   if(profileIndex < 0)
-    throw LnException("No PROFILE-CERT component in data name!");
+    throw Error("No PROFILE-CERT component in data name!");
 
   m_keyName = dataName.getSubName(0, profileIndex);
   m_signer = dataName.getSubName(profileIndex + 1, dataName.size() - profileIndex - 2);
diff --git a/src/endorse-certificate.h b/src/endorse-certificate.h
index 5f076f2..a727552 100644
--- a/src/endorse-certificate.h
+++ b/src/endorse-certificate.h
@@ -21,6 +21,8 @@
 class ProfileExtension : public ndn::CertificateExtension
 {
 public:
+  struct Error : public ndn::CertificateExtension::Error { Error(const std::string &what) : ndn::CertificateExtension::Error(what) {} };
+
   ProfileExtension(const ProfileData& profileData);
   
   ProfileExtension(const ProfileExtension& profileExtension);
@@ -36,6 +38,8 @@
 class EndorseExtension : public ndn::CertificateExtension
 {
 public:
+  struct Error : public ndn::CertificateExtension::Error { Error(const std::string &what) : ndn::CertificateExtension::Error(what) {} };
+
   EndorseExtension(const std::vector<std::string>& endorseList);
 
   EndorseExtension(const EndorseExtension& endorseExtension);
@@ -48,13 +52,15 @@
   getEndorseList();
 
 private:
-  static ndn::Blob
+  static ndn::Buffer
   encodeEndorseList(const std::vector<std::string>& endorsedList);
 };
 
 class EndorseCertificate : public ndn::Certificate
 {
 public:
+  struct Error : public ndn::Certificate::Error { Error(const std::string &what) : ndn::Certificate::Error(what) {} };
+
   EndorseCertificate() {}
 
   EndorseCertificate(const ndn::IdentityCertificate& kskCertificate,
diff --git a/src/endorse-combobox-delegate.cpp b/src/endorse-combobox-delegate.cpp
index a70a772..bbefbeb 100644
--- a/src/endorse-combobox-delegate.cpp
+++ b/src/endorse-combobox-delegate.cpp
@@ -15,7 +15,6 @@
 
 #ifndef Q_MOC_RUN
 #include "logging.h"
-#include "exception.h"
 #endif
 
 INIT_LOGGER("EndorseComboBoxDelegate");
diff --git a/src/exception.cpp b/src/exception.cpp
deleted file mode 100644
index 22f89a1..0000000
--- a/src/exception.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013, Regents of the University of California
- *                     Yingdi Yu
- *
- * BSD license, See the LICENSE file for more information
- *
- * Author: Yingdi Yu <yingdi@cs.ucla.edu>
- */
-
-#include "exception.h"
-
-using namespace std;
-
-LnException::LnException(const string & errMsg) throw()
-  : m_errMsg(errMsg)
-{}
diff --git a/src/exception.h b/src/exception.h
deleted file mode 100644
index 5cce5aa..0000000
--- a/src/exception.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013, Regents of the University of California
- *                     Yingdi Yu
- *
- * BSD license, See the LICENSE file for more information
- *
- * Author: Yingdi Yu <yingdi@cs.ucla.edu>
- */
-
-#ifndef LINKEDN_EXCEPTION_H
-#define LINKEDN_EXCEPTION_H
-
-#include <exception>
-#include <string>
-
-class LnException : public std::exception
-{
-public:
-  LnException(const std::string & errMsg) throw();
-  
-  ~LnException() throw()
-  {}
-  
-  const char* what() const throw()
-  {
-    return m_errMsg.c_str();
-  }
-  
-private:
-  const std::string m_errMsg;
-};
-
-#endif
diff --git a/src/invitation-policy-manager.cpp b/src/invitation-policy-manager.cpp
index 0885e25..dd7b33c 100644
--- a/src/invitation-policy-manager.cpp
+++ b/src/invitation-policy-manager.cpp
@@ -10,8 +10,8 @@
 
 #include "invitation-policy-manager.h"
 #include "null-ptrs.h"
-#include <ndn-cpp/sha256-with-rsa-signature.hpp>
-#include <ndn-cpp/security/signature/sha256-with-rsa-handler.hpp>
+#include <ndn-cpp/security/verifier.hpp>
+#include <ndn-cpp/security/signature/signature-sha256-with-rsa.hpp>
 
 #include "logging.h"
 
@@ -65,101 +65,104 @@
       return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;
     }
 
-  const Sha256WithRsaSignature* sha256sig = dynamic_cast<const Sha256WithRsaSignature*> (data->getSignature());    
+  try{
+    SignatureSha256WithRsa sig(data->getSignature());    
 
-  if(ndn_KeyLocatorType_KEYNAME != sha256sig->getKeyLocator().getType())
-    {
-      _LOG_ERROR("KeyLocator is not name!");
-      onVerifyFailed(data);
-      return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;
-    }
+    const Name & keyLocatorName = sig.getKeyLocator().getName();
 
-  const Name & keyLocatorName = sha256sig->getKeyLocator().getKeyName();
+    if(m_invitationPolicyRule->satisfy(*data))
+      {
+        // Name keyName = IdentityCertificate::certificateNameToPublicKeyName(keyLocatorName);
+        // map<Name, PublicKey>::iterator it = m_trustAnchors.find(keyName);
+        // if(m_trustAnchors.end() != it)
+        //   {
+        //     if(Sha256WithRsaHandler::verifySignature(*data, it->second))
+        //       onVerified(data);
+        //     else
+        //       onVerifyFailed(data);
 
-  if(m_invitationPolicyRule->satisfy(*data))
-    {
-      // Name keyName = IdentityCertificate::certificateNameToPublicKeyName(keyLocatorName);
-      // map<Name, PublicKey>::iterator it = m_trustAnchors.find(keyName);
-      // if(m_trustAnchors.end() != it)
-      //   {
-      //     if(Sha256WithRsaHandler::verifySignature(*data, it->second))
-      //       onVerified(data);
-      //     else
-      //       onVerifyFailed(data);
+        //     return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;
+        //   }
 
-      //     return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;
-      //   }
-
-      shared_ptr<const Certificate> trustedCert = m_certificateCache.getCertificate(keyLocatorName);
+        shared_ptr<const Certificate> trustedCert = m_certificateCache.getCertificate(keyLocatorName);
       
-      if(trustedCert != ndn::TCC_NULL_CERTIFICATE_PTR){
-	if(Sha256WithRsaHandler::verifySignature(*data, trustedCert->getPublicKeyInfo()))
-	  onVerified(data);
-	else
-	  onVerifyFailed(data);
-
-	return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;
-      }
-
-      OnVerified recursiveVerifiedCallback = boost::bind(&InvitationPolicyManager::onDskCertificateVerified, 
-                                                         this, 
-                                                         _1, 
-                                                         data, 
-                                                         onVerified, 
-                                                         onVerifyFailed);
-      
-      OnVerifyFailed recursiveUnverifiedCallback = boost::bind(&InvitationPolicyManager::onDskCertificateVerifyFailed, 
-                                                               this, 
-                                                               _1, 
-                                                               data, 
-                                                               onVerifyFailed);
-
-
-      shared_ptr<Interest> interest = make_shared<Interest>(keyLocatorName);
-      
-      shared_ptr<ValidationRequest> nextStep = make_shared<ValidationRequest>(interest, 
-                                                                              recursiveVerifiedCallback,
-                                                                              recursiveUnverifiedCallback,
-                                                                              0,
-                                                                              stepCount + 1);
-      return nextStep;
-    }
-
-  if(m_kskRegex->match(data->getName()))
-    {
-      Name keyName = m_kskRegex->expand();
-      map<Name, PublicKey>::iterator it = m_trustAnchors.find(keyName);
-      if(m_trustAnchors.end() != it)
-        {
-          IdentityCertificate identityCertificate(*data);
-          if(isSameKey(it->second.getKeyDer(), identityCertificate.getPublicKeyInfo().getKeyDer()))
-            {
-              onVerified(data);
-            }
+        if(trustedCert != ndn::TCC_NULL_CERTIFICATE_PTR){
+          if(Verifier::verifySignature(*data, sig, trustedCert->getPublicKeyInfo()))
+            onVerified(data);
           else
             onVerifyFailed(data);
+
+          return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;
         }
-      else
-        onVerifyFailed(data);
 
-      return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;
-    }
+        OnVerified recursiveVerifiedCallback = boost::bind(&InvitationPolicyManager::onDskCertificateVerified, 
+                                                           this, 
+                                                           _1, 
+                                                           data, 
+                                                           onVerified, 
+                                                           onVerifyFailed);
+      
+        OnVerifyFailed recursiveUnverifiedCallback = boost::bind(&InvitationPolicyManager::onDskCertificateVerifyFailed, 
+                                                                 this, 
+                                                                 _1, 
+                                                                 data, 
+                                                                 onVerifyFailed);
 
-  if(m_dskRule->satisfy(*data))
-    {
-      m_keyNameRegex->match(keyLocatorName);
-      Name keyName = m_keyNameRegex->expand();
 
-      if(m_trustAnchors.end() != m_trustAnchors.find(keyName))
-        if(Sha256WithRsaHandler::verifySignature(*data, m_trustAnchors[keyName]))
-          onVerified(data);
+        shared_ptr<Interest> interest = make_shared<Interest>(keyLocatorName);
+      
+        shared_ptr<ValidationRequest> nextStep = make_shared<ValidationRequest>(interest, 
+                                                                                recursiveVerifiedCallback,
+                                                                                recursiveUnverifiedCallback,
+                                                                                0,
+                                                                                stepCount + 1);
+        return nextStep;
+      }
+
+    if(m_kskRegex->match(data->getName()))
+      {
+        Name keyName = m_kskRegex->expand();
+        map<Name, PublicKey>::iterator it = m_trustAnchors.find(keyName);
+        if(m_trustAnchors.end() != it)
+          {
+            IdentityCertificate identityCertificate(*data);
+            if(it->second == identityCertificate.getPublicKeyInfo())
+              {
+                onVerified(data);
+              }
+            else
+              onVerifyFailed(data);
+          }
         else
           onVerifyFailed(data);
-      else
-        onVerifyFailed(data);
 
-      return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;	
-    }
+        return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;
+      }
+
+    if(m_dskRule->satisfy(*data))
+      {
+        m_keyNameRegex->match(keyLocatorName);
+        Name keyName = m_keyNameRegex->expand();
+
+        if(m_trustAnchors.end() != m_trustAnchors.find(keyName))
+          if(Verifier::verifySignature(*data, sig, m_trustAnchors[keyName]))
+            onVerified(data);
+          else
+            onVerifyFailed(data);
+        else
+          onVerifyFailed(data);
+
+        return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;	
+      }
+  }catch(SignatureSha256WithRsa::Error &e){
+    _LOG_DEBUG("checkVerificationPolicy " << e.what());
+    onVerifyFailed(data);
+    return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;
+  }catch(KeyLocator::Error &e){
+    _LOG_DEBUG("checkVerificationPolicy " << e.what());
+    onVerifyFailed(data);
+    return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;
+  }
 
   onVerifyFailed(data);
   return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;
@@ -218,7 +221,7 @@
       if(it == m_dskCertificates.end())
         m_dskCertificates.insert(pair <Name, shared_ptr<IdentityCertificate> > (certName, certificate));
 
-      if(Sha256WithRsaHandler::verifySignature(*originalData, certificate->getPublicKeyInfo()))
+      if(Verifier::verifySignature(*originalData, originalData->getSignature(), certificate->getPublicKeyInfo()))
         {
           onVerified(originalData);
           return;
@@ -246,24 +249,3 @@
   else
     return CHRONOCHAT_NULL_IDENTITYCERTIFICATE_PTR;
 }
-
-
-bool
-InvitationPolicyManager::isSameKey(const Blob& keyA, const Blob& keyB)
-{
-  size_t size = keyA.size();
-
-  if(size != keyB.size())
-    return false;
-
-  const uint8_t* ap = keyA.buf();
-  const uint8_t* bp = keyB.buf();
-  
-  for(int i = 0; i < size; i++)
-    {
-      if(ap[i] != bp[i])
-        return false;
-    }
-
-  return true;
-}
diff --git a/src/invitation-policy-manager.h b/src/invitation-policy-manager.h
index a49124f..83b77bc 100644
--- a/src/invitation-policy-manager.h
+++ b/src/invitation-policy-manager.h
@@ -71,9 +71,6 @@
                                ndn::ptr_lib::shared_ptr<ndn::Data> originalData,
                                const ndn::OnVerifyFailed& onVerifyFailed);
 
-  static bool
-  isSameKey(const ndn::Blob& keyA, const ndn::Blob& keyB);
-
 private:
   std::string m_chatroomName;
   ndn::Name m_signingIdentity;
diff --git a/src/panel-policy-manager.cpp b/src/panel-policy-manager.cpp
index 92511ed..e60eb4f 100644
--- a/src/panel-policy-manager.cpp
+++ b/src/panel-policy-manager.cpp
@@ -10,8 +10,8 @@
 
 #include "panel-policy-manager.h"
 #include "null-ptrs.h"
-#include <ndn-cpp/sha256-with-rsa-signature.hpp>
-#include <ndn-cpp/security/signature/sha256-with-rsa-handler.hpp>
+#include <ndn-cpp/security/verifier.hpp>
+#include <ndn-cpp/security/signature/signature-sha256-with-rsa.hpp>
 // #include <boost/bind.hpp>
 
 #include "logging.h"
@@ -86,66 +86,68 @@
       return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;
     }
 
-  const Sha256WithRsaSignature* sha256sig = dynamic_cast<const Sha256WithRsaSignature*>(data->getSignature());    
+  try{
+    SignatureSha256WithRsa sig(data->getSignature());    
+    const Name & keyLocatorName = sig.getKeyLocator().getName();
 
-  if(ndn_KeyLocatorType_KEYNAME != sha256sig->getKeyLocator().getType())
-    {
-      _LOG_ERROR("Keylocator is not name!");
-      onVerifyFailed(data);
-      return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;
-    }
+    if(m_kskRegex->match(data->getName()))
+      {
+        Name keyName = m_kskRegex->expand();
+        map<Name, PublicKey>::iterator it = m_trustAnchors.find(keyName);
+        if(m_trustAnchors.end() != it)
+          {
+            // _LOG_DEBUG("found key!");
+            IdentityCertificate identityCertificate(*data);
+            if(it->second == identityCertificate.getPublicKeyInfo())
+              onVerified(data);
+            else
+              onVerifyFailed(data);
+          }
+        else
+          onVerifyFailed(data);
 
-  const Name & keyLocatorName = sha256sig->getKeyLocator().getKeyName();
+        return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;
+      }
 
-  if(m_kskRegex->match(data->getName()))
-    {
-      Name keyName = m_kskRegex->expand();
-      map<Name, PublicKey>::iterator it = m_trustAnchors.find(keyName);
-      if(m_trustAnchors.end() != it)
-        {
-          // _LOG_DEBUG("found key!");
-          IdentityCertificate identityCertificate(*data);
-          if(isSameKey(it->second.getKeyDer(), identityCertificate.getPublicKeyInfo().getKeyDer()))
+    if(m_dskRule->satisfy(*data))
+      {
+        m_keyNameRegex->match(keyLocatorName);
+        Name keyName = m_keyNameRegex->expand();
+
+        if(m_trustAnchors.end() != m_trustAnchors.find(keyName))
+          if(Verifier::verifySignature(*data, sig, m_trustAnchors[keyName]))
             onVerified(data);
           else
             onVerifyFailed(data);
-        }
-      else
-        onVerifyFailed(data);
-
-      return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;
-    }
-
-  if(m_dskRule->satisfy(*data))
-    {
-      m_keyNameRegex->match(keyLocatorName);
-      Name keyName = m_keyNameRegex->expand();
-
-      if(m_trustAnchors.end() != m_trustAnchors.find(keyName))
-        if(Sha256WithRsaHandler::verifySignature(*data, m_trustAnchors[keyName]))
-          onVerified(data);
         else
           onVerifyFailed(data);
-      else
-        onVerifyFailed(data);
 
-      return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;	
-    }
+        return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;	
+      }
 
-  if(m_endorseeRule->satisfy(*data))
-    {
-      m_keyNameRegex->match(keyLocatorName);
-      Name keyName = m_keyNameRegex->expand();
-      if(m_trustAnchors.end() != m_trustAnchors.find(keyName))
-        if(Sha256WithRsaHandler::verifySignature(*data, m_trustAnchors[keyName]))
-          onVerified(data);
+    if(m_endorseeRule->satisfy(*data))
+      {
+        m_keyNameRegex->match(keyLocatorName);
+        Name keyName = m_keyNameRegex->expand();
+        if(m_trustAnchors.end() != m_trustAnchors.find(keyName))
+          if(Verifier::verifySignature(*data, sig, m_trustAnchors[keyName]))
+            onVerified(data);
+          else
+            onVerifyFailed(data);
         else
           onVerifyFailed(data);
-      else
-        onVerifyFailed(data);
 
-      return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;
-    }
+        return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;
+      }
+  }catch(SignatureSha256WithRsa::Error &e){
+    _LOG_DEBUG("checkVerificationPolicy: " << e.what());
+    onVerifyFailed(data);
+    return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;
+  }catch(KeyLocator::Error &e){
+    _LOG_DEBUG("checkVerificationPolicy: " << e.what());
+    onVerifyFailed(data);
+    return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;
+  }
 
   _LOG_DEBUG("Unverified!");
 
@@ -193,23 +195,3 @@
     return make_shared<PublicKey>(m_trustAnchors[keyName]);
   return CHRONOCHAT_NULL_PUBLICKEY_PTR;
 }
-
-bool
-PanelPolicyManager::isSameKey(const Blob& keyA, const Blob& keyB)
-{
-  size_t size = keyA.size();
-
-  if(size != keyB.size())
-    return false;
-
-  const uint8_t* ap = keyA.buf();
-  const uint8_t* bp = keyB.buf();
-  
-  for(int i = 0; i < size; i++)
-    {
-      if(ap[i] != bp[i])
-        return false;
-    }
-
-  return true;
-}
diff --git a/src/panel-policy-manager.h b/src/panel-policy-manager.h
index 712f9e5..1c5d688 100644
--- a/src/panel-policy-manager.h
+++ b/src/panel-policy-manager.h
@@ -85,10 +85,6 @@
   getTrustedKey(const ndn::Name& inviterCertName);
 
 private:
-  static bool
-  isSameKey(const ndn::Blob& keyA, const ndn::Blob& keyB);
-
-private:
   int m_stepLimit;
   ndn::TTLCertificateCache m_certificateCache;
   ndn::ptr_lib::shared_ptr<ndn::Regex> m_localPrefixRegex;
diff --git a/src/profile-data.cpp b/src/profile-data.cpp
index 0e17552..2288f9d 100644
--- a/src/profile-data.cpp
+++ b/src/profile-data.cpp
@@ -10,7 +10,6 @@
 
 #include "profile-data.h"
 #include <boost/date_time/posix_time/posix_time.hpp>
-#include "exception.h"
 #include "logging.h"
 
 
@@ -40,8 +39,6 @@
   profile.encode(&content);
   setContent((const uint8_t *)&content[0], content.size());
 
-  getMetaInfo().setTimestampMilliseconds(time(NULL) * 1000.0);
-
 }
 
 // ProfileData::ProfileData(const ProfileData& profileData)
@@ -67,10 +64,10 @@
     }
 
   if(profileIndex < 0)
-    throw LnException("No PROFILE component in data name!");
+    throw Error("No PROFILE component in data name!");
 
   m_identity = dataName.getPrefix(profileIndex);
 
-  string encoded((const char*)data.getContent().buf(), data.getContent().size());
+  string encoded(reinterpret_cast<const char*>(data.getContent().value()), data.getContent().value_size());
   m_profile = *Profile::decode(encoded);
 }
diff --git a/src/profile-data.h b/src/profile-data.h
index dbe4ca5..92353a1 100644
--- a/src/profile-data.h
+++ b/src/profile-data.h
@@ -17,6 +17,8 @@
 class ProfileData : public ndn::Data
 {
 public:
+  struct Error : public ndn::Data::Error { Error(const std::string &what) : ndn::Data::Error(what) {} };
+
   ProfileData();
 
   ProfileData(const Profile& profile);
diff --git a/src/profileeditor.cpp b/src/profileeditor.cpp
index 4abad5a..9d0d844 100644
--- a/src/profileeditor.cpp
+++ b/src/profileeditor.cpp
@@ -16,7 +16,6 @@
 
 #ifndef Q_MOC_RUN
 #include "logging.h"
-#include "exception.h"
 #endif
 
 using namespace ndn;
@@ -31,7 +30,7 @@
     , ui(new Ui::ProfileEditor)
     , m_tableModel(new QSqlTableModel())
     , m_contactManager(contactManager)
-    , m_identityManager(contactManager->getIdentityManager())
+    , m_keyChain(new KeyChain())
 {
   ui->setupUi(this);
   
@@ -85,7 +84,7 @@
 void
 ProfileEditor::onOkClicked()
 {
-  Name defaultCertName = m_identityManager->getDefaultCertificateNameForIdentity(m_currentIdentity);
+  Name defaultCertName = m_keyChain->getDefaultCertificateNameForIdentity(m_currentIdentity);
   if(defaultCertName.size() == 0)
     {
       emit noKeyOrCert(QString::fromStdString("Corresponding certificate is missing!\nHave you installed the certificate?"));
diff --git a/src/profileeditor.h b/src/profileeditor.h
index 6f8477c..5446be9 100644
--- a/src/profileeditor.h
+++ b/src/profileeditor.h
@@ -16,7 +16,7 @@
 
 #ifndef Q_MOC_RUN
 #include "contact-manager.h"
-#include <ndn-cpp/security/identity/identity-manager.hpp>
+#include <ndn-cpp/security/key-chain.hpp>
 #endif
 
 namespace Ui {
@@ -58,7 +58,7 @@
   Ui::ProfileEditor *ui;
   QSqlTableModel* m_tableModel;
   ndn::ptr_lib::shared_ptr<ContactManager> m_contactManager;
-  ndn::ptr_lib::shared_ptr<ndn::IdentityManager> m_identityManager;
+  ndn::ptr_lib::shared_ptr<ndn::KeyChain> m_keyChain;
   ndn::Name m_currentIdentity;
 };