Changing API from ndn.cxx to ndn-cpp

Change-Id: Ie0fe7d75e4ed056dec6e9da906f9c8808ad9a0ca
diff --git a/src/addcontactpanel.cpp b/src/addcontactpanel.cpp
index 38bc6e9..f43cddb 100644
--- a/src/addcontactpanel.cpp
+++ b/src/addcontactpanel.cpp
@@ -13,18 +13,20 @@
 #include <QMessageBox>
 
 #ifndef Q_MOC_RUN
-// #include <cryptopp/base64.h>
-// #include <ndn.cxx/helpers/der/der.h>
-#include <ndn.cxx/helpers/der/visitor/simple-visitor.h>
+#include <ndn-cpp/security/signature/sha256-with-rsa-handler.hpp>
+#include <boost/iostreams/stream.hpp>
+#include "null-ptrs.h"
+#include "endorse-collection.pb.h"
 #include "logging.h"
 #endif
 
 using namespace ndn;
+using namespace ndn::ptr_lib;
 using namespace std;
 
 INIT_LOGGER("AddContactPanel");
 
-AddContactPanel::AddContactPanel(Ptr<ContactManager> contactManager,
+AddContactPanel::AddContactPanel(shared_ptr<ContactManager> contactManager,
                                  QWidget *parent) 
   : QDialog(parent)
   , ui(new Ui::AddContactPanel)
@@ -78,7 +80,7 @@
   for(int i = ui->infoView->rowCount() - 1; i >= 0 ; i--)
     ui->infoView->removeRow(i);
   QString inputIdentity = ui->contactInput->text();
-  m_searchIdentity = Name(inputIdentity.toUtf8().constData());
+  m_searchIdentity = Name(inputIdentity.toStdString());
 
   if(Qt::Checked == ui->fetchBox->checkState())
     {
@@ -102,13 +104,13 @@
   string key("KEY");
   string idCert("ID-CERT");
 
-  if(name.get(-1).toUri() != idCert)
+  if(name.get(-1).toEscapedString() != idCert)
     return false;
   
   int keyIndex = -1;
   for(int i = 0; i < name.size(); i++)
     {
-      if(name.get(i).toUri() == key)
+      if(name.get(i).toEscapedString() == key)
         {
           keyIndex = i;
           break;
@@ -127,7 +129,7 @@
   ContactItem contactItem(*m_currentEndorseCertificate);
   try{
     m_contactManager->getContactStorage()->addContact(contactItem);
-  }catch(exception& e){
+  }catch(std::exception& e){
     QMessageBox::information(this, tr("Chronos"), QString::fromStdString(e.what()));
     _LOG_ERROR("Exception: " << e.what());
     return;
@@ -140,8 +142,8 @@
 AddContactPanel::selfEndorseCertificateFetched(const EndorseCertificate& endorseCertificate)
 {
   try{
-    m_currentEndorseCertificate = Ptr<EndorseCertificate>(new EndorseCertificate(endorseCertificate));
-  }catch(exception& e){
+    m_currentEndorseCertificate = make_shared<EndorseCertificate>(endorseCertificate);
+  }catch(std::exception& e){
     QMessageBox::information(this, tr("Chronos"), QString::fromStdString(e.what()));
     _LOG_ERROR("Exception: " << e.what());
     return;
@@ -162,8 +164,8 @@
 AddContactPanel::onContactKeyFetched(const EndorseCertificate& endorseCertificate)
 {
   try{
-    m_currentEndorseCertificate = Ptr<EndorseCertificate>(new EndorseCertificate(endorseCertificate));
-  }catch(exception& e){
+    m_currentEndorseCertificate = make_shared<EndorseCertificate>(endorseCertificate);
+  }catch(std::exception& e){
     QMessageBox::information(this, tr("Chronos"), QString::fromStdString(e.what()));
     _LOG_ERROR("Exception: " << e.what());
     return;
@@ -183,7 +185,7 @@
 void
 AddContactPanel::onCollectEndorseFetched(const Data& data)
 {
-  m_currentCollectEndorse = Ptr<Data>(new Data(data));
+  m_currentCollectEndorse = make_shared<Data>(data);
   m_currentCollectEndorseReady = true;
 
   if(m_currentEndorseCertificateReady == true)
@@ -193,7 +195,7 @@
 void
 AddContactPanel::onCollectEndorseFetchFailed(const Name& identity)
 {
-  m_currentCollectEndorse = NULL;
+  m_currentCollectEndorse = CHRONOCHAT_NULL_DATA_PTR;
   m_currentCollectEndorseReady = true;
   
   if(m_currentEndorseCertificateReady == true)
@@ -204,55 +206,52 @@
 AddContactPanel::displayContactInfo()
 {
   // _LOG_TRACE("displayContactInfo");
-  const Profile& profile = m_currentEndorseCertificate->getProfileData()->getProfile();
-  const Blob& profileBlob = m_currentEndorseCertificate->getProfileData()->content();
+  const Profile& profile = m_currentEndorseCertificate->getProfileData().getProfile();
+  const Blob& profileBlob = m_currentEndorseCertificate->getProfileData().getContent();
 
   map<string, int> endorseCount;
 
-  if(m_currentCollectEndorse != NULL)
+  if(m_currentCollectEndorse != CHRONOCHAT_NULL_DATA_PTR)
     {
-      boost::iostreams::stream
-        <boost::iostreams::array_source> is (m_currentCollectEndorse->content().buf(), m_currentCollectEndorse->content().size());
-  
-      Ptr<der::DerSequence> root = DynamicCast<der::DerSequence>(der::DerNode::parse(reinterpret_cast<InputIterator &>(is)));
-      const der::DerNodePtrList & children = root->getChildren();
-      der::SimpleVisitor simpleVisitor;
+      Chronos::EndorseCollection endorseCollection;
       
-      for(int i = 0; i < children.size(); i++)
+      boost::iostreams::stream
+        <boost::iostreams::array_source> is ((const char*)m_currentCollectEndorse->getContent().buf(), m_currentCollectEndorse->getContent().size());
+      
+      endorseCollection.ParseFromIstream(&is);
+
+      for(int i = 0; i < endorseCollection.endorsement_size(); i ++)
         {
-          Ptr<Blob> dataBlob = boost::any_cast<Ptr<Blob> >(children[i]->accept(simpleVisitor));
-          
-          Ptr<Data> data = NULL;
-          Ptr<EndorseCertificate> endorseCert = NULL;
           try{
-            data = Data::decodeFromWire(dataBlob);
-            endorseCert = Ptr<EndorseCertificate>(new EndorseCertificate(*data));
-          }catch(exception& e){
-            continue;
-          }
-
-          Name signerKeyName = endorseCert->getSigner();
-          Name signerName = signerKeyName.getPrefix(signerKeyName.size()-1);
+            Data data;
+            data.wireDecode((const uint8_t*)endorseCollection.endorsement(i).blob().c_str(), endorseCollection.endorsement(i).blob().size());
+            EndorseCertificate endorseCert(data);
+            
+            Name signerKeyName = endorseCert.getSigner();
+            Name signerName = signerKeyName.getPrefix(-1);
           
-          Ptr<ContactItem> contact = m_contactManager->getContact(signerName);
-          if(contact == NULL)
-            continue;
+            shared_ptr<ContactItem> contact = m_contactManager->getContact(signerName);
+            if(contact == CHRONOCHAT_NULL_CONTACTITEM_PTR)
+              continue;
 
-          if(!contact->isIntroducer() || !contact->canBeTrustedFor(m_currentEndorseCertificate->getProfileData()->getIdentityName()))
-            continue;
+            if(!contact->isIntroducer() || !contact->canBeTrustedFor(m_currentEndorseCertificate->getProfileData().getIdentityName()))
+              continue;
           
-          if(!security::PolicyManager::verifySignature(*data, contact->getSelfEndorseCertificate().getPublicKeyInfo()))
-            continue;
+            if(!Sha256WithRsaHandler::verifySignature(data, contact->getSelfEndorseCertificate().getPublicKeyInfo()))
+              continue;
 
-          const Blob& tmpProfileBlob = endorseCert->getProfileData()->content();
-          if(profileBlob != tmpProfileBlob)
-            continue;
+            const Blob& tmpProfileBlob = endorseCert.getProfileData().getContent();
+            if(!isSameBlob(profileBlob, tmpProfileBlob))
+              continue;
 
-          const vector<string>& endorseList = endorseCert->getEndorseList();
+          const vector<string>& endorseList = endorseCert.getEndorseList();
           vector<string>::const_iterator it = endorseList.begin();
           for(; it != endorseList.end(); it++)
             endorseCount[*it] += 1;
-        }
+          }catch(std::exception& e){
+            continue;
+          }
+        }  
     }
   
   ui->infoView->setColumnCount(3);
@@ -269,11 +268,10 @@
   for(; it != profile.end(); it++)
   {
     ui->infoView->insertRow(rowCount);  
-    QTableWidgetItem *type = new QTableWidgetItem(QString::fromUtf8(it->first.c_str()));
+    QTableWidgetItem *type = new QTableWidgetItem(QString::fromStdString(it->first));
     ui->infoView->setItem(rowCount, 0, type);
     
-    string valueString(it->second.buf(), it->second.size());
-    QTableWidgetItem *value = new QTableWidgetItem(QString::fromUtf8(valueString.c_str()));
+    QTableWidgetItem *value = new QTableWidgetItem(QString::fromStdString(it->second));
     ui->infoView->setItem(rowCount, 1, value);
     
     map<string, int>::iterator map_it = endorseCount.find(it->first);
@@ -288,6 +286,28 @@
   }
 }
 
+bool
+AddContactPanel::isSameBlob(const ndn::Blob& blobA, const ndn::Blob& blobB)
+{
+  size_t size = blobA.size();
+
+  if(size != blobB.size())
+    return false;
+
+  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;
+    }
+
+  return true;
+
+}
+
+
 #if WAF
 #include "addcontactpanel.moc"
 #include "addcontactpanel.cpp.moc"
diff --git a/src/addcontactpanel.h b/src/addcontactpanel.h
index 3437e54..efc1dc0 100644
--- a/src/addcontactpanel.h
+++ b/src/addcontactpanel.h
@@ -36,7 +36,7 @@
   Q_OBJECT
 
 public:
-  explicit AddContactPanel(ndn::Ptr<ContactManager> contactManager,
+  explicit AddContactPanel(ndn::ptr_lib::shared_ptr<ContactManager> contactManager,
                            QWidget *parent = 0);
 
   ~AddContactPanel();
@@ -48,6 +48,9 @@
   bool
   isCorrectName(const ndn::Name& name);
 
+  static bool
+  isSameBlob(const ndn::Blob& blobA, const ndn::Blob& blobB);
+
 private slots:
   void
   onCancelClicked();
@@ -83,10 +86,10 @@
 private:
   Ui::AddContactPanel *ui;
   ndn::Name m_searchIdentity;
-  ndn::Ptr<ContactManager> m_contactManager;
+  ndn::ptr_lib::shared_ptr<ContactManager> m_contactManager;
   WarningDialog* m_warningDialog;
-  ndn::Ptr<EndorseCertificate> m_currentEndorseCertificate;
-  ndn::Ptr<ndn::Data> m_currentCollectEndorse;
+  ndn::ptr_lib::shared_ptr<EndorseCertificate> m_currentEndorseCertificate;
+  ndn::ptr_lib::shared_ptr<ndn::Data> m_currentCollectEndorse;
   bool m_currentEndorseCertificateReady;
   bool m_currentCollectEndorseReady;
 };
diff --git a/src/browsecontactdialog.cpp b/src/browsecontactdialog.cpp
index e556e0c..ee783e5 100644
--- a/src/browsecontactdialog.cpp
+++ b/src/browsecontactdialog.cpp
@@ -18,17 +18,18 @@
 #include <boost/tokenizer.hpp>
 #include "logging.h"
 #include "exception.h"
-#include "ndn.cxx/error.h"
+// #include "ndn.cxx/error.h"
 #endif
 
 using namespace std;
 using namespace ndn;
+using namespace ndn::ptr_lib;
 
 INIT_LOGGER("BrowseContactDialog");
 
 // Q_DECLARE_METATYPE(ndn::security::IdentityCertificate)
 
-BrowseContactDialog::BrowseContactDialog(Ptr<ContactManager> contactManager,
+BrowseContactDialog::BrowseContactDialog(shared_ptr<ContactManager> contactManager,
 					 QWidget *parent) 
   : QDialog(parent)
   , ui(new Ui::BrowseContactDialog)
@@ -139,24 +140,24 @@
   
   if(filter)
     {
-      map<Name, Name> certificateMap;
+      map<Name, Name, Name::BreadthFirstLess> certificateMap;
 
       vector<string>::iterator it = certNameList.begin();
   
       for(; it != certNameList.end(); it++)
 	{
 	  Name newCertName(*it);
-	  Name keyName = security::IdentityCertificate::certificateNameToPublicKeyName(newCertName, true);
-	  Name identity = keyName.getPrefix(keyName.size()-1);
+	  Name keyName = IdentityCertificate::certificateNameToPublicKeyName(newCertName);
+	  Name identity = keyName.getPrefix(-1);
 	  
 	  map<Name, Name>::iterator map_it = certificateMap.find(identity);
 	  if(map_it != certificateMap.end())
 	    {
 	      Name oldCertName = map_it->second;
-	      Name oldKeyName = security::IdentityCertificate::certificateNameToPublicKeyName(oldCertName, true);
-	      if(keyName > oldKeyName)
+	      Name oldKeyName = IdentityCertificate::certificateNameToPublicKeyName(oldCertName);
+	      if(keyName.get(-1).toEscapedString() > oldKeyName.get(-1).toEscapedString())
 		map_it->second = newCertName;
-	      else if(keyName == oldKeyName && newCertName > oldCertName)
+	      else if(keyName == oldKeyName && newCertName.get(-1).toVersion() > oldCertName.get(-1).toVersion())
 		map_it->second = newCertName;
 	    }
 	  else
@@ -174,17 +175,18 @@
   
       for(; it != certNameList.end(); it++)
 	{
-          try {
-            m_certificateNameList.push_back(Name (*it));
-          }
-          catch(error::Name)
-            {
-              _LOG_ERROR ("Error parsing: [" << *it << "]");
-            }
-          catch(error::name::Component)
-            {
-              _LOG_ERROR ("Error parsing: [" << *it << "]");
-            }
+          m_certificateNameList.push_back(Name (*it));
+          // try {
+          //   m_certificateNameList.push_back(Name (*it));
+          // }
+          // catch(error::Name)
+          //   {
+          //     _LOG_ERROR ("Error parsing: [" << *it << "]");
+          //   }
+          // catch(error::name::Component)
+          //   {
+          //     _LOG_ERROR ("Error parsing: [" << *it << "]");
+          //   }
 	}
     }
 }
@@ -201,13 +203,13 @@
 }
 
 void
-BrowseContactDialog::onCertificateFetched(const security::IdentityCertificate& identityCertificate)
+BrowseContactDialog::onCertificateFetched(const IdentityCertificate& identityCertificate)
 {
   Name certName = identityCertificate.getName();
   Name certNameNoVersion = certName.getPrefix(certName.size()-1);
-  m_certificateMap.insert(pair<Name, security::IdentityCertificate>(certNameNoVersion, identityCertificate));
+  m_certificateMap.insert(pair<Name, IdentityCertificate>(certNameNoVersion, identityCertificate));
   m_profileMap.insert(pair<Name, Profile>(certNameNoVersion, Profile(identityCertificate)));
-  string name(m_profileMap[certNameNoVersion].getProfileEntry("name")->buf(), m_profileMap[certNameNoVersion].getProfileEntry("name")->size());
+  string name = m_profileMap[certNameNoVersion].getProfileEntry("name");
   // Name contactName = m_profileMap[certNameNoVersion].getIdentityName();
   {
       UniqueRecLock lock(m_mutex);
@@ -270,8 +272,7 @@
 	  QTableWidgetItem *type = new QTableWidgetItem(QString::fromStdString(pro_it->first));
 	  ui->InfoTable->setItem(rowCount, 0, type);
 	  
-	  string valueString(pro_it->second.buf(), pro_it->second.size());
-	  QTableWidgetItem *value = new QTableWidgetItem(QString::fromStdString(valueString));
+	  QTableWidgetItem *value = new QTableWidgetItem(QString::fromStdString(pro_it->second));
 	  ui->InfoTable->setItem(rowCount, 1, value);	  
 	}
     }
diff --git a/src/browsecontactdialog.h b/src/browsecontactdialog.h
index 9369d05..1f74bc1 100644
--- a/src/browsecontactdialog.h
+++ b/src/browsecontactdialog.h
@@ -19,7 +19,7 @@
 
 
 #ifndef Q_MOC_RUN
-#include <ndn.cxx/security/certificate/identity-certificate.h>
+#include <ndn-cpp/security/certificate/identity-certificate.hpp>
 #include <boost/thread/locks.hpp>
 #include <boost/thread/recursive_mutex.hpp>
 #include "profile.h"
@@ -35,7 +35,7 @@
   Q_OBJECT
   
 public:
-  explicit BrowseContactDialog(ndn::Ptr<ContactManager> contactManager,
+  explicit BrowseContactDialog(ndn::ptr_lib::shared_ptr<ContactManager> contactManager,
                                QWidget *parent = 0);
 
   ~BrowseContactDialog();
@@ -67,7 +67,7 @@
                   const QItemSelection &deselected);
 
   void
-  onCertificateFetched(const ndn::security::IdentityCertificate& identityCertificate);
+  onCertificateFetched(const ndn::IdentityCertificate& identityCertificate);
 
   void
   onCertificateFetchFailed(const ndn::Name& identity);
@@ -95,7 +95,7 @@
 private:
   Ui::BrowseContactDialog *ui;
   
-  ndn::Ptr<ContactManager> m_contactManager;
+  ndn::ptr_lib::shared_ptr<ContactManager> m_contactManager;
 
   WarningDialog* m_warningDialog;
   QStringListModel* m_contactListModel;
@@ -103,8 +103,8 @@
   QStringList m_contactList;  
   std::vector<ndn::Name> m_contactNameList;
   std::vector<ndn::Name> m_certificateNameList;
-  std::map<ndn::Name, ndn::security::IdentityCertificate> m_certificateMap;
-  std::map<ndn::Name, Profile> m_profileMap;
+  std::map<ndn::Name, ndn::IdentityCertificate, ndn::Name::BreadthFirstLess> m_certificateMap;
+  std::map<ndn::Name, Profile, ndn::Name::BreadthFirstLess> m_profileMap;
 
   RecLock m_mutex;
 
diff --git a/src/chat-policy-rule.cpp b/src/chat-policy-rule.cpp
index 76d0cf1..db1d910 100644
--- a/src/chat-policy-rule.cpp
+++ b/src/chat-policy-rule.cpp
@@ -9,15 +9,15 @@
  */
 
 #include "chat-policy-rule.h"
-#include <ndn.cxx/fields/signature-sha256-with-rsa.h>
+#include <ndn-cpp/sha256-with-rsa-signature.hpp>
 
 using namespace ndn;
 using namespace std;
-using namespace ndn::security;
+using namespace ndn::ptr_lib;
 
 
-ChatPolicyRule::ChatPolicyRule(Ptr<Regex> dataRegex,
-			       Ptr<Regex> signerRegex)
+ChatPolicyRule::ChatPolicyRule(shared_ptr<Regex> dataRegex,
+			       shared_ptr<Regex> signerRegex)
   : PolicyRule(PolicyRule::IDENTITY_POLICY, true)
   , m_dataRegex(dataRegex)
   , m_signerRegex(signerRegex)
@@ -36,13 +36,12 @@
 bool 
 ChatPolicyRule::matchSignerName(const Data & data)
 { 
-  Ptr<const Signature> sig = data.getSignature();
+  const Sha256WithRsaSignature* sigPtr = dynamic_cast<const Sha256WithRsaSignature*> (data.getSignature());
 
-  if(NULL == sig)
+  if(NULL == sigPtr)
     return false;
 
-  Ptr<const signature::Sha256WithRsa> sigPtr = DynamicCast<const signature::Sha256WithRsa> (sig);
-  if(KeyLocator::KEYNAME != sigPtr->getKeyLocator().getType())
+  if(ndn_KeyLocatorType_KEYNAME != sigPtr->getKeyLocator().getType())
     return false;
 
   Name signerName = sigPtr->getKeyLocator ().getKeyName ();
diff --git a/src/chat-policy-rule.h b/src/chat-policy-rule.h
index 4534bab..fec4b69 100644
--- a/src/chat-policy-rule.h
+++ b/src/chat-policy-rule.h
@@ -11,15 +11,15 @@
 #ifndef CHAT_POLICY_RULE_H
 #define CHAT_POLICY_RULE_H
 
-#include <ndn.cxx/security/policy/policy-rule.h>
-#include <ndn.cxx/regex/regex.h>
+#include <ndn-cpp-et/policy-manager/policy-rule.hpp>
+#include <ndn-cpp-et/regex/regex.hpp>
 
-class ChatPolicyRule : public ndn::security::PolicyRule
+class ChatPolicyRule : public ndn::PolicyRule
 {
   
 public:
-  ChatPolicyRule(ndn::Ptr<ndn::Regex> dataRegex,
-                 ndn::Ptr<ndn::Regex> signerRegex);
+  ChatPolicyRule(ndn::ptr_lib::shared_ptr<ndn::Regex> dataRegex,
+                 ndn::ptr_lib::shared_ptr<ndn::Regex> signerRegex);
 
   ChatPolicyRule(const ChatPolicyRule& rule);
 
@@ -39,8 +39,8 @@
   satisfy(const ndn::Name & dataName, const ndn::Name & signerName);
   
 private:
-  ndn::Ptr<ndn::Regex> m_dataRegex;
-  ndn::Ptr<ndn::Regex> m_signerRegex;
+  ndn::ptr_lib::shared_ptr<ndn::Regex> m_dataRegex;
+  ndn::ptr_lib::shared_ptr<ndn::Regex> m_signerRegex;
 };
 
 #endif //CHAT_POLICY_RULE_H
diff --git a/src/chatdialog.cpp b/src/chatdialog.cpp
index 6a3f70c..5a6d483 100644
--- a/src/chatdialog.cpp
+++ b/src/chatdialog.cpp
@@ -18,12 +18,10 @@
 #include <QCloseEvent>
 
 #ifndef Q_MOC_RUN
-#include <ndn.cxx/security/identity/identity-manager.h>
-#include <ndn.cxx/security/policy/no-verify-policy-manager.h>
-#include <ndn.cxx/security/encryption/basic-encryption-manager.h>
 #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 "logging.h"
 #endif
 
@@ -36,7 +34,7 @@
 Q_DECLARE_METATYPE(std::vector<Sync::MissingDataInfo> )
 Q_DECLARE_METATYPE(size_t)
 
-ChatDialog::ChatDialog(ndn::Ptr<ContactManager> contactManager,
+ChatDialog::ChatDialog(ndn::ptr_lib::shared_ptr<ContactManager> contactManager,
                        const ndn::Name& chatroomPrefix,
 		       const ndn::Name& localPrefix,
                        const ndn::Name& defaultIdentity,
@@ -49,7 +47,7 @@
   , m_chatroomPrefix(chatroomPrefix)
   , m_localPrefix(localPrefix)
   , m_defaultIdentity(defaultIdentity)
-  , m_invitationPolicyManager(ndn::Ptr<InvitationPolicyManager>(new InvitationPolicyManager(m_chatroomPrefix.get(-1).toUri(), m_defaultIdentity)))
+  , m_invitationPolicyManager(new InvitationPolicyManager(m_chatroomPrefix.get(-1).toEscapedString(), m_defaultIdentity))
   , m_nick(nick)
   , m_sock(NULL)
   , m_lastMsgTime(0)
@@ -87,7 +85,13 @@
 
   m_timer = new QTimer(this);
 
-  setWrapper(trial);
+  ndn::Name certificateName = m_identityManager->getDefaultCertificateNameForIdentity(m_defaultIdentity);
+  m_syncPolicyManager = ndn::ptr_lib::make_shared<SyncPolicyManager>(m_defaultIdentity, certificateName, m_chatroomPrefix);
+
+  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"));
+
+  connectToDaemon();
 
   connect(ui->inviteButton, SIGNAL(clicked()),
           this, SLOT(openInviteListDialog()));
@@ -125,34 +129,34 @@
       delete m_sock;
       m_sock = NULL;
     }
-  m_handler->shutdown();
+  m_face->shutdown();
 }
 
 void
-ChatDialog::setWrapper(bool trial)
+ChatDialog::connectToDaemon()
 {
-  m_identityManager = ndn::Ptr<ndn::security::IdentityManager>::Create();
-
-  ndn::Name certificateName = m_identityManager->getDefaultCertificateNameByIdentity(m_defaultIdentity);
-  m_syncPolicyManager = ndn::Ptr<SyncPolicyManager>(new SyncPolicyManager(m_defaultIdentity, certificateName, m_chatroomPrefix));
-
-  m_keychain = ndn::Ptr<ndn::security::Keychain>(new ndn::security::Keychain(m_identityManager, m_invitationPolicyManager, NULL));
-
-  ndn::Ptr<ndn::security::Keychain> noVerifyKeychain = ndn::Ptr<ndn::security::Keychain>(new ndn::security::Keychain(m_identityManager,
-ndn::Ptr<ndn::security::NoVerifyPolicyManager>::Create(), NULL));
-  try{
-    m_handler = ndn::Ptr<ndn::Wrapper>(new ndn::Wrapper(m_keychain));
-    m_localPrefixHandler = ndn::Ptr<ndn::Wrapper>(new ndn::Wrapper(noVerifyKeychain));
-  }catch(ndn::Error::ndnOperation& e){
-    emit noNdnConnection(QString::fromStdString("Cannot conect to ndnd!\n Have you started your ndnd?"));
-  }
+  //Hack! transport does not connect to daemon unless an interest is expressed.
+  ndn::Name name("/ndn");
+  ndn::ptr_lib::shared_ptr<ndn::Interest> interest = ndn::ptr_lib::make_shared<ndn::Interest>(name);
+  m_face->expressInterest(*interest, 
+                          boost::bind(&ChatDialog::onConnectionData, this, _1, _2),
+                          boost::bind(&ChatDialog::onConnectionDataTimeout, this, _1));
 }
 
 void
+ChatDialog::onConnectionData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
+                             const ndn::ptr_lib::shared_ptr<ndn::Data>& data)
+{ _LOG_DEBUG("onConnectionData"); }
+
+void
+ChatDialog::onConnectionDataTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest)
+{ _LOG_DEBUG("onConnectionDataTimeout"); }
+
+void
 ChatDialog::initializeSetting()
 {
   m_user.setNick(QString::fromStdString(m_nick));
-  m_user.setChatroom(QString::fromStdString(m_chatroomPrefix.get(-1).toUri()));
+  m_user.setChatroom(QString::fromStdString(m_chatroomPrefix.get(-1).toEscapedString()));
   m_user.setOriginPrefix(QString::fromStdString(m_localPrefix.toUri()));
   m_user.setPrefix(QString::fromStdString(m_localChatPrefix.toUri()));
   m_scene->setCurrentPrefix(QString::fromStdString(m_localChatPrefix.toUri()));
@@ -179,11 +183,121 @@
 }
 
 void
-ChatDialog::sendInvitation(ndn::Ptr<ContactItem> contact, bool isIntroducer)
+ChatDialog::sendInterest(const ndn::Interest& interest,
+                         const ndn::OnVerified& onVerified,
+                         const ndn::OnVerifyFailed& onVerifyFailed,
+                         const OnEventualTimeout& timeoutNotify,
+                         const ndn::ptr_lib::shared_ptr<ndn::PolicyManager>& policyManager,
+                         int retry /* = 1 */,
+                         int stepCount /* = 0 */)
+{
+  m_face->expressInterest(interest, 
+                          boost::bind(&ChatDialog::onTargetData, 
+                                      this,
+                                      _1,
+                                      _2,
+                                      stepCount,
+                                      onVerified, 
+                                      onVerifyFailed,
+                                      timeoutNotify,
+                                      policyManager),
+                          boost::bind(&ChatDialog::onTargetTimeout,
+                                      this,
+                                      _1,
+                                      retry,
+                                      stepCount,
+                                      onVerified,
+                                      onVerifyFailed,
+                                      timeoutNotify,
+                                      policyManager));
+}
+
+void
+ChatDialog::onTargetData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, 
+                         const ndn::ptr_lib::shared_ptr<ndn::Data>& data,
+                         int stepCount,
+                         const ndn::OnVerified& onVerified,
+                         const ndn::OnVerifyFailed& onVerifyFailed,
+                         const OnEventualTimeout& timeoutNotify,
+                         const ndn::ptr_lib::shared_ptr<ndn::PolicyManager>& policyManager)
+{
+  ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> nextStep = policyManager->checkVerificationPolicy(data, stepCount, onVerified, onVerifyFailed);
+
+  if (nextStep)
+    m_face->expressInterest
+      (*nextStep->interest_, 
+       boost::bind(&ChatDialog::onCertData, this, _1, _2, nextStep, policyManager), 
+       boost::bind(&ChatDialog::onCertTimeout, this, _1, onVerifyFailed, data, nextStep, policyManager));
+}
+
+void
+ChatDialog::onTargetTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, 
+                            int retry,
+                            int stepCount,
+                            const ndn::OnVerified& onVerified,
+                            const ndn::OnVerifyFailed& onVerifyFailed,
+                            const OnEventualTimeout& timeoutNotify,
+                            const ndn::ptr_lib::shared_ptr<ndn::PolicyManager>& policyManager)
+{
+  if(retry > 0)
+    sendInterest(*interest, onVerified, onVerifyFailed, timeoutNotify, policyManager, retry-1, stepCount);
+  else
+    {
+      _LOG_DEBUG("Interest: " << interest->getName().toUri() << " eventually times out!");
+      timeoutNotify();
+    }
+}
+
+void
+ChatDialog::onCertData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, 
+                       const ndn::ptr_lib::shared_ptr<ndn::Data>& cert,
+                       ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> previousStep,
+                       const ndn::ptr_lib::shared_ptr<ndn::PolicyManager>& policyManager)
+{
+  ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> nextStep = policyManager->checkVerificationPolicy(cert, 
+                                                                                                     previousStep->stepCount_, 
+                                                                                                     previousStep->onVerified_, 
+                                                                                                     previousStep->onVerifyFailed_);
+
+  if (nextStep)
+    m_face->expressInterest
+      (*nextStep->interest_, 
+       boost::bind(&ChatDialog::onCertData, this, _1, _2, nextStep, policyManager), 
+       boost::bind(&ChatDialog::onCertTimeout, this, _1, previousStep->onVerifyFailed_, cert, nextStep, policyManager));
+}
+
+void
+ChatDialog::onCertTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
+                          const ndn::OnVerifyFailed& onVerifyFailed,
+                          const ndn::ptr_lib::shared_ptr<ndn::Data>& data,
+                          ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> nextStep,
+                          const ndn::ptr_lib::shared_ptr<ndn::PolicyManager>& policyManager)
+{
+  if(nextStep->retry_ > 0)
+    m_face->expressInterest(*interest, 
+                            boost::bind(&ChatDialog::onCertData,
+                                        this,
+                                        _1,
+                                        _2,
+                                        nextStep,
+                                        policyManager),
+                            boost::bind(&ChatDialog::onCertTimeout,
+                                        this,
+                                        _1,
+                                        onVerifyFailed,
+                                        data,
+                                        nextStep,
+                                        policyManager));
+ else
+   onVerifyFailed(data);
+}
+
+void
+ChatDialog::sendInvitation(ndn::ptr_lib::shared_ptr<ContactItem> contact, bool isIntroducer)
 {
   m_invitationPolicyManager->addTrustAnchor(contact->getSelfEndorseCertificate());
 
-  ndn::Name certificateName = m_identityManager->getDefaultCertificateNameByIdentity(m_defaultIdentity);
+  ndn::Name certificateName = m_identityManager->getDefaultCertificateNameForIdentity(m_defaultIdentity);
 
   ndn::Name interestName("/ndn/broadcast/chronos/invitation");
   interestName.append(contact->getNameSpace());
@@ -195,57 +309,63 @@
   interestName.append(certificateName);
 
   string signedUri = interestName.toUri();
-  ndn::Blob signedBlob(signedUri.c_str(), signedUri.size());
+  ndn::Blob signedBlob((const uint8_t*)signedUri.c_str(), signedUri.size());
 
-  ndn::Ptr<const ndn::signature::Sha256WithRsa> sha256sig = ndn::DynamicCast<const ndn::signature::Sha256WithRsa>(m_identityManager->signByCertificate(signedBlob, certificateName));
-  const ndn::Blob& sigBits = sha256sig->getSignatureBits();
+  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();
 
-  interestName.append(sigBits.buf(), sigBits.size());
-  interestName.appendVersion();
+  interestName.append(sigBits);
+  //TODO... remove version from invitation interest
+  //  interestName.appendVersion();
 
-  ndn::Ptr<ndn::Interest> interest = ndn::Ptr<ndn::Interest>(new ndn::Interest(interestName));
-  ndn::Ptr<ndn::Closure> closure = ndn::Ptr<ndn::Closure>(new ndn::Closure(boost::bind(&ChatDialog::onInviteReplyVerified,
-                                                                                       this,
-                                                                                       _1,
-                                                                                       contact->getNameSpace(),
-                                                                                       isIntroducer),
-                                                                           boost::bind(&ChatDialog::onInviteTimeout,
-                                                                                       this,
-                                                                                       _1,
-                                                                                       _2,
-                                                                                       contact->getNameSpace(),
-                                                                                       7),
-                                                                           boost::bind(&ChatDialog::onUnverified,
-                                                                                       this,
-                                                                                       _1)));
+  ndn::Interest interest(interestName);
+  ndn::OnVerified onVerified = boost::bind(&ChatDialog::onInviteReplyVerified,
+                                           this,
+                                           _1,
+                                           contact->getNameSpace(),
+                                           isIntroducer);
 
-  m_handler->sendInterest(interest, closure);
+  ndn::OnVerifyFailed onVerifyFailed = boost::bind(&ChatDialog::onInviteReplyVerifyFailed,
+                                                   this,
+                                                   _1,
+                                                   contact->getNameSpace());
+
+  OnEventualTimeout timeoutNotify = boost::bind(&ChatDialog::onInviteReplyTimeout,
+                                                     this,
+                                                     contact->getNameSpace());
+                                                 
+
+  sendInterest(interest, onVerified, onVerifyFailed, timeoutNotify, m_invitationPolicyManager);
+}
+
+void 
+ChatDialog::onInviteReplyVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, 
+                                  const ndn::Name& identity, 
+                                  bool isIntroducer)
+{
+  string content((const char*)data->getContent().buf(), data->getContent().size());
+  if(content == string("nack"))
+    invitationRejected(identity);
+  else
+    invitationAccepted(identity, data, content, isIntroducer);
 }
 
 void
-ChatDialog::addTrustAnchor(const EndorseCertificate& selfEndorseCertificate)
-{ m_invitationPolicyManager->addTrustAnchor(selfEndorseCertificate); }
-
-void
-ChatDialog::addChatDataRule(const ndn::Name& prefix, 
-                            const ndn::security::IdentityCertificate& identityCertificate,
-                            bool isIntroducer)
-{ m_syncPolicyManager->addChatDataRule(prefix, identityCertificate, isIntroducer); }
-
-void
-ChatDialog::publishIntroCert(const ndn::security::IdentityCertificate& dskCertificate, bool isIntroducer)
+ChatDialog::onInviteReplyVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data,
+                                      const ndn::Name& identity)
 {
-  SyncIntroCertificate syncIntroCertificate(m_chatroomPrefix,
-                                            dskCertificate.getPublicKeyName(),
-                                            m_identityManager->getDefaultKeyNameForIdentity(m_defaultIdentity),
-                                            dskCertificate.getNotBefore(),
-                                            dskCertificate.getNotAfter(),
-                                            dskCertificate.getPublicKeyInfo(),
-                                            (isIntroducer ? SyncIntroCertificate::INTRODUCER : SyncIntroCertificate::PRODUCER));
-  ndn::Name certName = m_identityManager->getDefaultCertificateNameByIdentity(m_defaultIdentity);
-  _LOG_DEBUG("Publish Intro Certificate: " << syncIntroCertificate.getName());
-  m_identityManager->signByCertificate(syncIntroCertificate, certName);
-  m_handler->putToNdnd(*syncIntroCertificate.encodeToWire());
+  _LOG_DEBUG("Reply from " << identity.toUri() << " cannot be verified!");
+  QString msg = QString::fromUtf8("Reply from ") + QString::fromStdString(identity.toUri()) + " cannot be verified!";
+  emit inivationRejection(msg);
+}
+
+
+void
+ChatDialog::onInviteReplyTimeout(const ndn::Name& identity)
+{
+  _LOG_DEBUG("Your invitation to " << identity.toUri() << " times out!");
+  QString msg = QString::fromUtf8("Your invitation to ") + QString::fromStdString(identity.toUri()) + " times out!";
+  emit inivationRejection(msg);
 }
 
 void
@@ -257,55 +377,43 @@
 }
 
 void
-ChatDialog::invitationAccepted(const ndn::Name& identity, ndn::Ptr<ndn::Data> data, const string& inviteePrefix, bool isIntroducer)
+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!");
-  ndn::Ptr<const ndn::signature::Sha256WithRsa> sha256sig = boost::dynamic_pointer_cast<const ndn::signature::Sha256WithRsa> (data->getSignature());
+  const ndn::Sha256WithRsaSignature* sha256sig = dynamic_cast<const ndn::Sha256WithRsaSignature*>(data->getSignature());
   const ndn::Name & keyLocatorName = sha256sig->getKeyLocator().getKeyName();
-  ndn::Ptr<ndn::security::IdentityCertificate> dskCertificate = m_invitationPolicyManager->getValidatedDskCertificate(keyLocatorName);
+  ndn::ptr_lib::shared_ptr<ndn::IdentityCertificate> dskCertificate = m_invitationPolicyManager->getValidatedDskCertificate(keyLocatorName);
   m_syncPolicyManager->addChatDataRule(inviteePrefix, *dskCertificate, isIntroducer);
   publishIntroCert(*dskCertificate, isIntroducer);
 }
 
-void 
-ChatDialog::onInviteReplyVerified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity, bool isIntroducer)
+void
+ChatDialog::publishIntroCert(const ndn::IdentityCertificate& dskCertificate, bool isIntroducer)
 {
-  string content(data->content().buf(), data->content().size());
-  if(content == string("nack"))
-    invitationRejected(identity);
-  else
-    invitationAccepted(identity, data, content, isIntroducer);
+  SyncIntroCertificate syncIntroCertificate(m_chatroomPrefix,
+                                            dskCertificate.getPublicKeyName(),
+                                            m_identityManager->getDefaultKeyNameForIdentity(m_defaultIdentity),
+                                            dskCertificate.getNotBefore(),
+                                            dskCertificate.getNotAfter(),
+                                            dskCertificate.getPublicKeyInfo(),
+                                            (isIntroducer ? SyncIntroCertificate::INTRODUCER : SyncIntroCertificate::PRODUCER));
+  ndn::Name certName = m_identityManager->getDefaultCertificateNameForIdentity(m_defaultIdentity);
+  _LOG_DEBUG("Publish Intro Certificate: " << syncIntroCertificate.getName());
+  m_identityManager->signByCertificate(syncIntroCertificate, certName);
+  m_transport->send(*syncIntroCertificate.wireEncode());
 }
 
-void 
-ChatDialog::onInviteTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest, const ndn::Name& identity, int retry)
-{
-  if(retry > 0)
-    {
-      ndn::Ptr<ndn::Closure> newClosure = ndn::Ptr<ndn::Closure>(new ndn::Closure(closure->m_dataCallback,
-                                                                                  boost::bind(&ChatDialog::onInviteTimeout, 
-                                                                                              this, 
-                                                                                              _1, 
-                                                                                              _2, 
-                                                                                              identity,
-                                                                                              retry - 1),
-                                                                                  closure->m_unverifiedCallback,
-                                                                                  closure->m_stepCount)
-                                                                 );
-      m_handler->sendInterest(interest, newClosure);
-    }
-  else
-    invitationRejected(identity);
-}
+void
+ChatDialog::addTrustAnchor(const EndorseCertificate& selfEndorseCertificate)
+{ m_invitationPolicyManager->addTrustAnchor(selfEndorseCertificate); }
+
+void
+ChatDialog::addChatDataRule(const ndn::Name& prefix, 
+                            const ndn::IdentityCertificate& identityCertificate,
+                            bool isIntroducer)
+{ m_syncPolicyManager->addChatDataRule(prefix, identityCertificate, isIntroducer); }
+
  
-void
-ChatDialog::onUnverified(ndn::Ptr<ndn::Data> data)
-{}
-
-void
-ChatDialog::onTimeout(ndn::Ptr<ndn::Closure> closure, 
-                      ndn::Ptr<ndn::Interest> interest)
-{}
 
 void
 ChatDialog::initializeSync()
@@ -313,8 +421,8 @@
   
   m_sock = new Sync::SyncSocket(m_chatroomPrefix.toUri(),
                                 m_syncPolicyManager,
-                                bind(&ChatDialog::processTreeUpdateWrapper, this, _1, _2),
-                                bind(&ChatDialog::processRemoveWrapper, this, _1));
+                                boost::bind(&ChatDialog::processTreeUpdateWrapper, this, _1, _2),
+                                boost::bind(&ChatDialog::processRemoveWrapper, this, _1));
   
   usleep(100000);
 
@@ -449,11 +557,11 @@
 }
 
 void
-ChatDialog::processDataWrapper(ndn::Ptr<ndn::Data> data)
+ChatDialog::processDataWrapper(const ndn::ptr_lib::shared_ptr<ndn::Data>& data)
 {
   string name = data->getName().toUri();
-  const char* buf = data->content().buf();
-  size_t len = data->content().size();
+  const char* buf = (const char*)data->getContent().buf();
+  size_t len = data->getContent().size();
 
   char *tempBuf = new char[len];
   memcpy(tempBuf, buf, len);
@@ -462,11 +570,11 @@
 }
 
 void
-ChatDialog::processDataNoShowWrapper(ndn::Ptr<ndn::Data> data)
+ChatDialog::processDataNoShowWrapper(const ndn::ptr_lib::shared_ptr<ndn::Data>& data)
 {
   string name = data->getName().toUri();
-  const char* buf = data->content().buf();
-  size_t len = data->content().size();
+  const char* buf = (const char*)data->getContent().buf();
+  size_t len = data->getContent().size();
 
   char *tempBuf = new char[len];
   memcpy(tempBuf, buf, len);
@@ -755,7 +863,7 @@
       m_timer->start(FRESHNESS * 1000);
       disableTreeDisplay();
       QTimer::singleShot(2200, this, SLOT(enableTreeDisplay()));
-    }catch(ndn::Error::ndnOperation& e){
+    }catch(std::exception& e){
       emit noNdnConnection(QString::fromStdString("Cannot conect to ndnd!\n Have you started your ndnd?"));
     }
   }
@@ -894,22 +1002,15 @@
 ChatDialog::updateLocalPrefix()
 {
   m_newLocalPrefixReady = false;
-  ndn::Ptr<ndn::Interest> interest = ndn::Ptr<ndn::Interest>(new ndn::Interest(ndn::Name("/local/ndn/prefix")));
-  interest->setChildSelector(ndn::Interest::CHILD_RIGHT);
-  interest->setInterestLifetime(1);
+  ndn::Name interestName("/local/ndn/prefix");
+  ndn::Interest interest(interestName);
+  interest.setChildSelector(ndn_Interest_CHILD_SELECTOR_RIGHT);
+  interest.setInterestLifetimeMilliseconds(1000);
 
-  ndn::Ptr<ndn::Closure> closure = ndn::Ptr<ndn::Closure>(new ndn::Closure(boost::bind(&ChatDialog::onLocalPrefix,
-                                                                                       this,
-                                                                                       _1),
-                                                                           boost::bind(&ChatDialog::onLocalPrefixTimeout,
-                                                                                       this,
-                                                                                       _1,
-                                                                                       _2),
-                                                                           boost::bind(&ChatDialog::onLocalPrefix,
-                                                                                       this,
-                                                                                       _1)));
+  m_face->expressInterest(interest, 
+                          bind(&ChatDialog::onLocalPrefix, this, _1, _2), 
+                          bind(&ChatDialog::onLocalPrefixTimeout, this, _1));
   
-  m_localPrefixHandler->sendInterest(interest, closure);
   while(m_newLocalPrefixReady == false)
     {
 #if BOOST_VERSION >= 1050000
@@ -926,6 +1027,25 @@
     emit settingUpdated(m_user.getNick (), m_user.getChatroom (), originPrefix);
 }
 
+
+void
+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());
+  QString originPrefix = QString::fromStdString (dataString).trimmed ();
+  string trimmedString = originPrefix.toStdString();
+  m_newLocalPrefix = ndn::Name(trimmedString);
+  m_newLocalPrefixReady = true;
+}
+
+void
+ChatDialog::onLocalPrefixTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest)
+{
+  m_newLocalPrefix = m_localPrefix;
+  m_newLocalPrefixReady = true;
+}
+
 static std::string chars2("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789");
 
 QString
@@ -942,23 +1062,6 @@
 }
 
 void
-ChatDialog::onLocalPrefix(ndn::Ptr<ndn::Data> data)
-{
-  string dataString(data->content().buf(), data->content().size());
-  QString originPrefix = QString::fromStdString (dataString).trimmed ();
-  string trimmedString = originPrefix.toStdString();
-  m_newLocalPrefix = ndn::Name(trimmedString);
-  m_newLocalPrefixReady = true;
-}
-
-void
-ChatDialog::onLocalPrefixTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest)
-{
-  m_newLocalPrefix = m_localPrefix;
-  m_newLocalPrefixReady = true;
-}
-
-void
 ChatDialog::changeEvent(QEvent *e)
 {
   switch(e->type())
@@ -1155,8 +1258,8 @@
 void
 ChatDialog::sendInvitationWrapper(QString invitee, bool isIntroducer)
 {
-  ndn::Name inviteeNamespace(invitee.toUtf8().constData());
-  ndn::Ptr<ContactItem> inviteeItem = m_contactManager->getContact(inviteeNamespace);
+  ndn::Name inviteeNamespace(invitee.toStdString());
+  ndn::ptr_lib::shared_ptr<ContactItem> inviteeItem = m_contactManager->getContact(inviteeNamespace);
   sendInvitation(inviteeItem, isIntroducer);
 }
 
diff --git a/src/chatdialog.h b/src/chatdialog.h
index 504d60f..0c06783 100644
--- a/src/chatdialog.h
+++ b/src/chatdialog.h
@@ -23,9 +23,9 @@
 #include "invitelistdialog.h"
 
 #ifndef Q_MOC_RUN
-#include <ndn.cxx/data.h>
-#include <ndn.cxx/security/keychain.h>
-#include <ndn.cxx/wrapper/wrapper.h>
+#include <ndn-cpp/data.hpp>
+#include <ndn-cpp/face.hpp>
+#include <ndn-cpp/security/identity/identity-manager.hpp>
 #include "invitation-policy-manager.h"
 #include "contact-item.h"
 
@@ -35,6 +35,8 @@
 #include "digesttreescene.h"
 #endif
 
+typedef ndn::func_lib::function<void()> OnEventualTimeout;
+
 #define MAX_HISTORY_ENTRY   20
 
 namespace Ui {
@@ -46,7 +48,7 @@
   Q_OBJECT
 
 public:
-  explicit ChatDialog(ndn::Ptr<ContactManager> contactManager,
+  explicit ChatDialog(ndn::ptr_lib::shared_ptr<ContactManager> contactManager,
                       const ndn::Name& chatroomPrefix,
                       const ndn::Name& localPrefix,
                       const ndn::Name& defaultIdentity,
@@ -71,14 +73,14 @@
   { return m_localPrefix; }
 
   void
-  sendInvitation(ndn::Ptr<ContactItem> contact, bool isIntroducer);
+  sendInvitation(ndn::ptr_lib::shared_ptr<ContactItem> contact, bool isIntroducer);
 
   void
   addTrustAnchor(const EndorseCertificate& selfEndorseCertificate);
 
   void
   addChatDataRule(const ndn::Name& prefix, 
-                  const ndn::security::IdentityCertificate& identityCertificate,
+                  const ndn::IdentityCertificate& identityCertificate,
                   bool isIntroducer);
 
   void 
@@ -88,16 +90,16 @@
   processTreeUpdateWrapper(const std::vector<Sync::MissingDataInfo>, Sync::SyncSocket *);
 
   void 
-  processDataWrapper(ndn::Ptr<ndn::Data> data);
+  processDataWrapper(const ndn::ptr_lib::shared_ptr<ndn::Data>& data);
 
   void 
-  processDataNoShowWrapper(ndn::Ptr<ndn::Data> data);
+  processDataNoShowWrapper(const ndn::ptr_lib::shared_ptr<ndn::Data>& data);
 
   void 
   processRemoveWrapper(std::string);
 
   void
-  publishIntroCert(const ndn::security::IdentityCertificate& dskCertificate, bool isIntroducer);
+  publishIntroCert(const ndn::IdentityCertificate& dskCertificate, bool isIntroducer);
 
 protected:
   void 
@@ -109,6 +111,16 @@
 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);
+
+  void
   initializeSetting();
 
   QString 
@@ -118,42 +130,76 @@
   updateLabels();
 
   void
-  setWrapper(bool trial);
+  initializeSync();
 
   void
-  initializeSync();
+  onTargetData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, 
+               const ndn::ptr_lib::shared_ptr<ndn::Data>& data,
+               int stepCount,
+               const ndn::OnVerified& onVerified,
+               const ndn::OnVerifyFailed& onVerifyFailed,
+               const OnEventualTimeout& timeoutNotify,
+               const ndn::ptr_lib::shared_ptr<ndn::PolicyManager>& policyManager);
+
+  void
+  onTargetTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, 
+                  int retry,
+                  int stepCount,
+                  const ndn::OnVerified& onVerified,
+                  const ndn::OnVerifyFailed& onVerifyFailed,
+                  const OnEventualTimeout& timeoutNotify,
+                  const ndn::ptr_lib::shared_ptr<ndn::PolicyManager>& policyManager);
+  
+  void
+  onCertData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, 
+             const ndn::ptr_lib::shared_ptr<ndn::Data>& cert,
+             ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> previousStep,
+             const ndn::ptr_lib::shared_ptr<ndn::PolicyManager>& policyManager);
+
+  void
+  onCertTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
+                const ndn::OnVerifyFailed& onVerifyFailed,
+                const ndn::ptr_lib::shared_ptr<ndn::Data>& data,
+                ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> nextStep,
+                const ndn::ptr_lib::shared_ptr<ndn::PolicyManager>& policyManager);
+
+  void
+  sendInterest(const ndn::Interest& interest,
+               const ndn::OnVerified& onVerified,
+               const ndn::OnVerifyFailed& onVerifyFailed,
+               const OnEventualTimeout& timeoutNotify,
+               const ndn::ptr_lib::shared_ptr<ndn::PolicyManager>& policyManager,
+               int retry = 1,
+               int stepCount = 0);
   
   void 
-  onInviteReplyVerified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity, bool isIntroducer);
+  onInviteReplyVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, 
+                        const ndn::Name& identity, 
+                        bool isIntroduce);
+
+  void
+  onInviteReplyVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data,
+                            const ndn::Name& identity);
 
   void 
-  onInviteTimeout(ndn::Ptr<ndn::Closure> closure, 
-                  ndn::Ptr<ndn::Interest> interest, 
-                  const ndn::Name& identity, 
-                  int retry);
+  onInviteReplyTimeout(const ndn::Name& identity);
+
 
   void
   invitationRejected(const ndn::Name& identity);
   
   void 
-  invitationAccepted(const ndn::Name& identity,
-                     ndn::Ptr<ndn::Data> data, 
-                     const std::string& inviteePrefix,
+  invitationAccepted(const ndn::Name& identity, 
+                     ndn::ptr_lib::shared_ptr<ndn::Data> data, 
+                     const std::string& inviteePrefix, 
                      bool isIntroducer);
 
   void
-  onUnverified(ndn::Ptr<ndn::Data> data);
+  onLocalPrefix(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, 
+                const ndn::ptr_lib::shared_ptr<ndn::Data>& data);
 
   void
-  onTimeout(ndn::Ptr<ndn::Closure> closure, 
-            ndn::Ptr<ndn::Interest> interest);
-
-  void
-  onLocalPrefix(ndn::Ptr<ndn::Data> data);
-
-  void
-  onLocalPrefixTimeout(ndn::Ptr<ndn::Closure> closure, 
-                        ndn::Ptr<ndn::Interest> interest);
+  onLocalPrefixTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest);
 
   // void 
   // fetchHistory(std::string name);
@@ -277,18 +323,17 @@
     
 private:
   Ui::ChatDialog *ui;
-  ndn::Ptr<ContactManager> m_contactManager;
+  ndn::ptr_lib::shared_ptr<ContactManager> m_contactManager;
   ndn::Name m_chatroomPrefix;
   ndn::Name m_localPrefix;
   ndn::Name m_localChatPrefix;
   ndn::Name m_defaultIdentity;
-  ndn::Ptr<InvitationPolicyManager> m_invitationPolicyManager;
-  ndn::Ptr<SyncPolicyManager> m_syncPolicyManager; 
-  ndn::Ptr<ndn::security::IdentityManager> m_identityManager;
-  ndn::Ptr<ndn::security::Keychain> m_keychain;
-  ndn::Ptr<ndn::Wrapper> m_handler;
+  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::Face> m_face;
+  ndn::ptr_lib::shared_ptr<ndn::Transport> m_transport;
 
-  ndn::Ptr<ndn::Wrapper> m_localPrefixHandler;
   ndn::Name m_newLocalPrefix;
   bool m_newLocalPrefixReady;
 
diff --git a/src/chronos-invitation.cpp b/src/chronos-invitation.cpp
index f918342..28d36e1 100644
--- a/src/chronos-invitation.cpp
+++ b/src/chronos-invitation.cpp
@@ -10,7 +10,7 @@
 
 #include "chronos-invitation.h"
 
-#include <ndn.cxx/security/certificate/identity-certificate.h>
+#include <ndn-cpp/security/certificate/identity-certificate.hpp>
 #include "exception.h"
 #include "logging.h"
 
@@ -22,11 +22,11 @@
 ChronosInvitation::ChronosInvitation(const ndn::Name& originalInterestName)
   : m_interestName(originalInterestName)
 {
-  Name interestName = originalInterestName.getPrefix(originalInterestName.size()-1);
-  if(interestName.get(0).toUri() != string("ndn")
-     || interestName.get(1).toUri() != string("broadcast")
-     || interestName.get(2).toUri() != string("chronos")
-     || interestName.get(3).toUri() != string("invitation"))
+  Name interestName = originalInterestName.getPrefix(-1);
+  if(interestName.get(0).toEscapedString() != string("ndn")
+     || interestName.get(1).toEscapedString() != string("broadcast")
+     || interestName.get(2).toEscapedString() != string("chronos")
+     || interestName.get(3).toEscapedString() != string("invitation"))
     throw LnException("Wrong ChronosInvitation Name");
     
   int i = 4;
@@ -35,7 +35,7 @@
   string chatroomStr("chatroom");
   int inviteeBegin = 4;
   for(; i < size; i++)
-    if(interestName.get(i).toUri() == chatroomStr)
+    if(interestName.get(i).toEscapedString() == chatroomStr)
       break;
 
   if(i >= size)
@@ -45,7 +45,7 @@
   string inviterPrefixStr("inviter-prefix");
   int chatroomBegin = (++i);
   for(; i < size;  i++)
-    if(interestName.get(i).toUri() == inviterPrefixStr)
+    if(interestName.get(i).toEscapedString() == inviterPrefixStr)
       break;
 
   if(i > size)
@@ -55,7 +55,7 @@
   string inviterStr("inviter");
   int inviterPrefixBegin = (++i);
   for(; i < size; i++)
-    if(interestName.get(i).toUri() == inviterStr)
+    if(interestName.get(i).toEscapedString() == inviterStr)
       break;
   
   if(i > size)
@@ -65,14 +65,13 @@
   int inviterCertBegin = (++i);
   m_inviterCertificateName = interestName.getSubName(inviterCertBegin, size - 1 - inviterCertBegin);
   
-  string signature = interestName.get(-1).toBlob();
-  m_signatureBits.insert(m_signatureBits.end(), signature.begin(), signature.end());
+  m_signatureBits = interestName.get(-1).getValue();
  
-  Name keyName = security::IdentityCertificate::certificateNameToPublicKeyName(m_inviterCertificateName, true);
-  m_inviterNameSpace = keyName.getPrefix(keyName.size()-1);
+  Name keyName = IdentityCertificate::certificateNameToPublicKeyName(m_inviterCertificateName);
+  m_inviterNameSpace = keyName.getPrefix(-1);
 
   string signedName = interestName.getSubName(0, size - 1).toUri();
-  m_signedBlob.insert(m_signedBlob.end(), signedName.begin(), signedName.end());
+  m_signedBlob = Blob((const uint8_t*)signedName.c_str(), signedName.size());
 }
 
 ChronosInvitation::ChronosInvitation(const ChronosInvitation& invitation)
diff --git a/src/chronos-invitation.h b/src/chronos-invitation.h
index 7f660db..e343b15 100644
--- a/src/chronos-invitation.h
+++ b/src/chronos-invitation.h
@@ -12,7 +12,7 @@
 #define CHRONOS_INVITATION_H
 
 
-#include <ndn.cxx/fields/name.h>
+#include <ndn-cpp/name.hpp>
 
 class ChronosInvitation
 {
@@ -26,35 +26,35 @@
   virtual
   ~ChronosInvitation() {};
 
-  inline const ndn::Name&
+  const ndn::Name&
   getInviteeNameSpace() const
   { return m_inviteeNameSpace; }
 
-  inline const ndn::Name&
+  const ndn::Name&
   getChatroom() const
   { return m_chatroom; }
 
-  inline const ndn::Name&
+  const ndn::Name&
   getInviterPrefix() const
   { return m_inviterPrefix; }
 
-  inline const ndn::Name&
+  const ndn::Name&
   getInviterCertificateName() const
   { return m_inviterCertificateName; }
 
-  inline const ndn::Blob&
+  const ndn::Blob&
   getSignatureBits() const
   { return m_signatureBits; }
 
-  inline const ndn::Name&
+  const ndn::Name&
   getInviterNameSpace() const
   { return m_inviterNameSpace; }
 
-  inline const ndn::Blob&
+  const ndn::Blob&
   getSignedBlob() const
   { return m_signedBlob; }
   
-  inline const ndn::Name&
+  const ndn::Name&
   getInterestName() const
   { return m_interestName; }
 
diff --git a/src/contact-item.cpp b/src/contact-item.cpp
index 60e9a93..46cc4a3 100644
--- a/src/contact-item.cpp
+++ b/src/contact-item.cpp
@@ -10,14 +10,13 @@
 
 #include "contact-item.h"
 #include "exception.h"
-
-#include <ndn.cxx/fields/signature-sha256-with-rsa.h>
+#include "null-ptrs.h"
 
 #include "logging.h"
 
 using namespace std;
 using namespace ndn;
-using namespace ndn::security;
+using namespace ndn::ptr_lib;
 
 INIT_LOGGER("ContactItem");
 
@@ -32,15 +31,10 @@
   m_namespace = endorsedkeyName.getSubName(0, endorsedkeyName.size() - 1);
 
 
-  Ptr<ProfileData> profileData = selfEndorseCertificate.getProfileData();
-  Ptr<const Blob> nameBlob = profileData->getProfile().getProfileEntry("name");
-  m_name = string(nameBlob->buf(), nameBlob->size());
+  const ProfileData& profileData = selfEndorseCertificate.getProfileData();
+  m_name = profileData.getProfile().getProfileEntry("name");
   m_alias = alias.empty() ? m_name : alias;
-  Ptr<const Blob> institutionBlob = profileData->getProfile().getProfileEntry("institution");
-  if(institutionBlob != NULL)
-    m_institution = string(institutionBlob->buf(), institutionBlob->size());
-  else
-    m_institution = string();
+  m_institution = profileData.getProfile().getProfileEntry("institution");
 }
 
 ContactItem::ContactItem(const ContactItem& contactItem)
@@ -57,7 +51,7 @@
 bool 
 ContactItem::canBeTrustedFor(const Name& name)
 {
-  vector<Ptr<Regex> >::iterator it = m_trustScope.begin();
+  vector<shared_ptr<Regex> >::iterator it = m_trustScope.begin();
 
   for(; it != m_trustScope.end(); it++)
     if((*it)->match(name))
diff --git a/src/contact-item.h b/src/contact-item.h
index 9ab478b..238f647 100644
--- a/src/contact-item.h
+++ b/src/contact-item.h
@@ -11,14 +11,14 @@
 #ifndef LINKNDN_CONTACT_ITEM_H
 #define LINKNDN_CONTACT_ITEM_H
 
-#include <ndn.cxx/data.h>
-#include <ndn.cxx/regex/regex.h>
+#include <ndn-cpp/data.hpp>
+#include <ndn-cpp-et/regex/regex.hpp>
 #include <vector>
 #include "endorse-certificate.h"
 
 class ContactItem
 {
-  typedef std::vector<ndn::Ptr<EndorseCertificate> > EndorseCertificateList;
+  typedef std::vector<ndn::ptr_lib::shared_ptr<EndorseCertificate> > EndorseCertificateList;
 
 public:
   ContactItem(const EndorseCertificate& selfEndorseCertificate,
@@ -30,35 +30,35 @@
   virtual
   ~ContactItem() {}
 
-  inline const EndorseCertificate&
+  const EndorseCertificate&
   getSelfEndorseCertificate() const
   { return m_selfEndorseCertificate; }
 
-  inline const ndn::Name&
+  const ndn::Name&
   getNameSpace() const
   { return m_namespace; }
 
-  inline const std::string&
+  const std::string&
   getAlias() const
   { return m_alias; }
 
-  inline const std::string&
+  const std::string&
   getName() const
   { return m_name; }
 
-  inline const std::string&
+  const std::string&
   getInstitution() const
   { return m_institution; }
 
-  inline const ndn::Name
+  const ndn::Name
   getPublicKeyName() const
   { return m_selfEndorseCertificate.getPublicKeyName(); }
 
-  inline bool
+  bool
   isIntroducer() const
   { return m_isIntroducer; }
 
-  inline void
+  void
   setIsIntroducer(bool isIntroducer) 
   { m_isIntroducer = isIntroducer; }
 
@@ -72,7 +72,7 @@
   bool
   canBeTrustedFor(const ndn::Name& name);
 
-  inline const std::vector<ndn::Name>&
+  const std::vector<ndn::Name>&
   getTrustScopeList() const
   { return m_trustScopeName; }
 
@@ -87,7 +87,7 @@
 
   bool m_isIntroducer;
 
-  std::vector<ndn::Ptr<ndn::Regex> > m_trustScope;
+  std::vector<ndn::ptr_lib::shared_ptr<ndn::Regex> > m_trustScope;
   std::vector<ndn::Name> m_trustScopeName;
 };
 
diff --git a/src/contact-manager.cpp b/src/contact-manager.cpp
index 2d722d7..25c32a1 100644
--- a/src/contact-manager.cpp
+++ b/src/contact-manager.cpp
@@ -11,28 +11,36 @@
 #include "contact-manager.h"
 
 #ifndef Q_MOC_RUN
-#include <ndn.cxx/wrapper/wrapper.h>
-#include <ndn.cxx/security/keychain.h>
-#include <ndn.cxx/security/policy/simple-policy-manager.h>
-#include <ndn.cxx/security/policy/identity-policy-rule.h>
-#include <ndn.cxx/helpers/der/der.h>
+#include <ndn-cpp/face.hpp>
+#include <ndn-cpp/sha256-with-rsa-signature.hpp>
+#include <ndn-cpp/security/signature/sha256-with-rsa-handler.hpp>
 #include <cryptopp/base64.h>
+#include <ndn-cpp-et/policy-manager/identity-policy-rule.hpp>
 #include <fstream>
+#include "endorse-collection.pb.h"
+#include "null-ptrs.h"
 #include "logging.h"
 #endif
 
 using namespace ndn;
-using namespace ndn::security;
+using namespace ndn::ptr_lib;
+using namespace std;
 
 INIT_LOGGER("ContactManager");
 
-ContactManager::ContactManager(QObject* parent)
+ContactManager::ContactManager(shared_ptr<IdentityManager> identityManager, QObject* parent)
   : QObject(parent)
 {
-  m_contactStorage = Ptr<ContactStorage>::Create();
-  m_dnsStorage = Ptr<DnsStorage>::Create();
+  m_identityManager = identityManager;
+  m_contactStorage = make_shared<ContactStorage>();
+  m_dnsStorage = make_shared<DnsStorage>();
 
-  setKeychain();
+  m_transport = make_shared<TcpTransport>();
+  m_face = make_shared<Face>(m_transport, make_shared<TcpTransport::ConnectionInfo>("localhost"));
+  
+  connectToDaemon();
+
+  initializeSecurity();
 }
 
 ContactManager::~ContactManager()
@@ -40,46 +48,57 @@
 }
 
 void
-ContactManager::setWrapper()
+ContactManager::connectToDaemon()
 {
-  try{
-    m_wrapper = Ptr<Wrapper>(new Wrapper(m_keychain));
-  }catch(ndn::Error::ndnOperation& e){
-    emit noNdnConnection(QString::fromStdString("Cannot conect to ndnd!\nHave you started your ndnd?"));
-  }
+  //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::setKeychain()
+ContactManager::onConnectionData(const shared_ptr<const ndn::Interest>& interest,
+                            const shared_ptr<Data>& data)
 {
-  Ptr<IdentityManager> identityManager = Ptr<IdentityManager>::Create();
-  Ptr<SimplePolicyManager> policyManager = Ptr<SimplePolicyManager>::Create();
+  _LOG_DEBUG("onConnectionData");
+}
 
-  Ptr<Keychain> keychain = Ptr<Keychain>(new Keychain(identityManager, policyManager, NULL));
+void
+ContactManager::onConnectionDataTimeout(const shared_ptr<const ndn::Interest>& interest)
+{
+  _LOG_DEBUG("onConnectionDataTimeout");
+}
 
-  policyManager->addVerificationPolicyRule(Ptr<IdentityPolicyRule>(new IdentityPolicyRule("^([^<DNS>]*)<DNS><ENDORSED>",
-                                                                                          "^([^<KEY>]*)<KEY>(<>*)[<ksk-.*><dsk-.*>]<ID-CERT>$",
-                                                                                          "==", "\\1", "\\1\\2", true)));
-  policyManager->addVerificationPolicyRule(Ptr<IdentityPolicyRule>(new IdentityPolicyRule("^([^<DNS>]*)<DNS><PROFILE>",
-                                                                                          "^([^<KEY>]*)<KEY>(<>*)[<ksk-.*><dsk-.*>]<ID-CERT>$",
-                                                                                          "==", "\\1", "\\1\\2", true)));
-  policyManager->addVerificationPolicyRule(Ptr<IdentityPolicyRule>(new IdentityPolicyRule("^([^<PROFILE-CERT>]*)<PROFILE-CERT>",
-											  "^([^<KEY>]*)<KEY>(<>*<ksk-.*>)<ID-CERT>$", 
-											  "==", "\\1", "\\1\\2", true)));
-  policyManager->addVerificationPolicyRule(Ptr<IdentityPolicyRule>(new IdentityPolicyRule("^([^<KEY>]*)<KEY>(<>*)<ksk-.*><ID-CERT>",
-											  "^([^<KEY>]*)<KEY><dsk-.*><ID-CERT>$",
-											  ">", "\\1\\2", "\\1", true)));
-  policyManager->addVerificationPolicyRule(Ptr<IdentityPolicyRule>(new IdentityPolicyRule("^([^<KEY>]*)<KEY><dsk-.*><ID-CERT>",
-											  "^([^<KEY>]*)<KEY>(<>*)<ksk-.*><ID-CERT>$",
-											  "==", "\\1", "\\1\\2", true)));
-  policyManager->addVerificationPolicyRule(Ptr<IdentityPolicyRule>(new IdentityPolicyRule("^(<>*)$", 
-                                                                                          "^([^<KEY>]*)<KEY>(<>*)<ksk-.*><ID-CERT>$", 
-                                                                                          ">", "\\1", "\\1\\2", true)));
+void
+ContactManager::initializeSecurity()
+{
+  m_policyManager = make_shared<SimplePolicyManager>();
+
+  m_policyManager->addVerificationPolicyRule(make_shared<IdentityPolicyRule>("^([^<DNS>]*)<DNS><ENDORSED>",
+                                                                             "^([^<KEY>]*)<KEY>(<>*)[<ksk-.*><dsk-.*>]<ID-CERT>$",
+                                                                             "==", "\\1", "\\1\\2", true));
+  m_policyManager->addVerificationPolicyRule(make_shared<IdentityPolicyRule>("^([^<DNS>]*)<DNS><PROFILE>",
+                                                                             "^([^<KEY>]*)<KEY>(<>*)[<ksk-.*><dsk-.*>]<ID-CERT>$",
+                                                                             "==", "\\1", "\\1\\2", true));
+  m_policyManager->addVerificationPolicyRule(make_shared<IdentityPolicyRule>("^([^<PROFILE-CERT>]*)<PROFILE-CERT>",
+                                                                             "^([^<KEY>]*)<KEY>(<>*<ksk-.*>)<ID-CERT>$", 
+                                                                             "==", "\\1", "\\1\\2", true));
+  m_policyManager->addVerificationPolicyRule(make_shared<IdentityPolicyRule>("^([^<KEY>]*)<KEY>(<>*)<ksk-.*><ID-CERT>",
+                                                                             "^([^<KEY>]*)<KEY><dsk-.*><ID-CERT>$",
+                                                                             ">", "\\1\\2", "\\1", true));
+  m_policyManager->addVerificationPolicyRule(make_shared<IdentityPolicyRule>("^([^<KEY>]*)<KEY><dsk-.*><ID-CERT>",
+                                                                             "^([^<KEY>]*)<KEY>(<>*)<ksk-.*><ID-CERT>$",
+                                                                             "==", "\\1", "\\1\\2", true));
+  m_policyManager->addVerificationPolicyRule(make_shared<IdentityPolicyRule>("^(<>*)$", 
+                                                                             "^([^<KEY>]*)<KEY>(<>*)<ksk-.*><ID-CERT>$", 
+                                                                             ">", "\\1", "\\1\\2", true));
   
 
-  policyManager->addSigningPolicyRule(Ptr<IdentityPolicyRule>(new IdentityPolicyRule("^([^<DNS>]*)<DNS><PROFILE>",
-                                                                                     "^([^<KEY>]*)<KEY>(<>*)<><ID-CERT>",
-                                                                                     "==", "\\1", "\\1\\2", true)));
+  m_policyManager->addSigningPolicyRule(make_shared<IdentityPolicyRule>("^([^<DNS>]*)<DNS><PROFILE>",
+                                                                        "^([^<KEY>]*)<KEY>(<>*)<><ID-CERT>",
+                                                                        "==", "\\1", "\\1\\2", true));
 
 
   const string TrustAnchor("BIICqgOyEIWlKzDI2xX2hdq5Azheu9IVyewcV4uM7ylfh67Y8MIxF3tDCTx5JgEn\
@@ -105,10 +124,10 @@
                             TrustAnchor.size(), 
                             true,
                             new CryptoPP::Base64Decoder(new CryptoPP::StringSink(decoded)));
-  Ptr<Blob> blob = Ptr<Blob>(new Blob(decoded.c_str(), decoded.size()));
-  Ptr<Data> data = Data::decodeFromWire(blob);
-  Ptr<IdentityCertificate>anchor = Ptr<IdentityCertificate>(new IdentityCertificate(*data));
-  policyManager->addTrustAnchor(anchor);  
+  Data data;
+  data.wireDecode((const uint8_t*)decoded.c_str(), decoded.size());
+  shared_ptr<IdentityCertificate> anchor = make_shared<IdentityCertificate>(data);
+  m_policyManager->addTrustAnchor(anchor);  
 
 #ifdef _DEBUG
 
@@ -135,14 +154,12 @@
                             FakeAnchor.size(), 
                             true,
                             new CryptoPP::Base64Decoder(new CryptoPP::StringSink(decoded2)));
-  Ptr<Blob> blob2 = Ptr<Blob>(new Blob(decoded2.c_str(), decoded2.size()));
-  Ptr<Data> data2 = Data::decodeFromWire(blob2);
-  Ptr<IdentityCertificate>anchor2 = Ptr<IdentityCertificate>(new IdentityCertificate(*data2));
-  policyManager->addTrustAnchor(anchor2);  
+  Data data2;
+  data2.wireDecode((const uint8_t*)decoded2.c_str(), decoded2.size());
+  shared_ptr<IdentityCertificate>anchor2 = make_shared<IdentityCertificate>(data2);
+  m_policyManager->addTrustAnchor(anchor2);  
 
 #endif
-
-  m_keychain = keychain;
 }
 
 
@@ -152,74 +169,125 @@
   Name interestName = identity;
   interestName.append("DNS").append("PROFILE");
   
-  Ptr<Interest> interestPtr = Ptr<Interest>(new Interest(interestName));
-  interestPtr->setChildSelector(Interest::CHILD_RIGHT);
-  Ptr<Closure> closure = Ptr<Closure> (new Closure(boost::bind(&ContactManager::onDnsSelfEndorseCertificateVerified, 
-                                                               this,
-                                                               _1,
-                                                               identity),
-						   boost::bind(&ContactManager::onDnsSelfEndorseCertificateTimeout,
-                                                               this,
-                                                               _1, 
-                                                               _2,
-                                                               identity,
-                                                               0),
-						   boost::bind(&ContactManager::onDnsSelfEndorseCertificateUnverified,
-                                                               this,
-                                                               _1,
-                                                               identity)));
-  m_wrapper->sendInterest(interestPtr, closure);
+  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);
+
+  sendInterest(interest, onVerified, onVerifyFailed, timeoutNotify);
 }
 
 void
+ContactManager::onDnsSelfEndorseCertificateTimeoutNotify(const Name& identity)
+{ emit contactFetchFailed(identity); }
+
+void
+ContactManager::onDnsSelfEndorseCertificateVerified(const shared_ptr<Data>& data, 
+                                                    const Name& identity)
+{
+  try{
+    Data plainData;
+    plainData.wireDecode(data->getContent().buf(), data->getContent().size());
+    EndorseCertificate selfEndorseCertificate(plainData);
+    if(Sha256WithRsaHandler::verifySignature(plainData, selfEndorseCertificate.getPublicKeyInfo()))
+      emit contactFetched (selfEndorseCertificate); 
+    else
+      emit contactFetchFailed (identity);
+  }catch(std::exception& e){
+    _LOG_ERROR("Exception: " << e.what());
+    emit contactFetchFailed (identity);
+  }
+}
+
+void
+ContactManager::onDnsSelfEndorseCertificateVerifyFailed(const shared_ptr<Data>& data, 
+                                                        const Name& identity)
+{ emit contactFetchFailed (identity); }
+
+void
 ContactManager::fetchCollectEndorse(const ndn::Name& identity)
 {
   Name interestName = identity;
   interestName.append("DNS").append("ENDORSED");
 
-  Ptr<Interest> interestPtr = Ptr<Interest>(new Interest(interestName));
-  interestPtr->setChildSelector(Interest::CHILD_RIGHT);
-  interestPtr->setInterestLifetime(1);
-  Ptr<Closure> closure = Ptr<Closure> (new Closure(boost::bind(&ContactManager::onDnsCollectEndorseVerified, 
-                                                               this,
-                                                               _1,
-                                                               identity),
-						   boost::bind(&ContactManager::onDnsCollectEndorseTimeout,
-                                                               this,
-                                                               _1, 
-                                                               _2,
-                                                               identity,
-                                                               0),
-						   boost::bind(&ContactManager::onDnsCollectEndorseUnverified,
-                                                               this,
-                                                               _1,
-                                                               identity)));
-  m_wrapper->sendInterest(interestPtr, closure);
+  Interest interest(interestName);
+  interest.setChildSelector(ndn_Interest_CHILD_SELECTOR_RIGHT);
+  interest.setInterestLifetimeMilliseconds(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);
+
+  sendInterest(interest, onVerified, onVerifyFailed, timeoutNotify);
 }
 
 void
+ContactManager::onDnsCollectEndorseTimeoutNotify(const Name& identity)
+{
+  emit collectEndorseFetchFailed (identity);
+}
+
+void
+ContactManager::onDnsCollectEndorseVerified(const shared_ptr<Data>& data, const Name& identity)
+{ emit collectEndorseFetched (*data); }
+
+void
+ContactManager::onDnsCollectEndorseVerifyFailed(const shared_ptr<Data>& data, const Name& identity)
+{ emit collectEndorseFetchFailed (identity); }
+
+
+void
 ContactManager::fetchKey(const ndn::Name& certName)
 {
   Name interestName = certName;
   
-  Ptr<Interest> interestPtr = Ptr<Interest>(new Interest(interestName));
-  interestPtr->setChildSelector(Interest::CHILD_RIGHT);
-  interestPtr->setInterestLifetime(1);
-  Ptr<Closure> closure = Ptr<Closure> (new Closure(boost::bind(&ContactManager::onKeyVerified, 
-                                                               this,
-                                                               _1,
-                                                               certName),
-						   boost::bind(&ContactManager::onKeyTimeout,
-                                                               this,
-                                                               _1, 
-                                                               _2,
-                                                               certName,
-                                                               0),
-						   boost::bind(&ContactManager::onKeyUnverified,
-                                                               this,
-                                                               _1,
-                                                               certName)));
-  m_wrapper->sendInterest(interestPtr, closure);
+  Interest interest(interestName);
+  interest.setChildSelector(ndn_Interest_CHILD_SELECTOR_RIGHT);
+  interest.setInterestLifetimeMilliseconds(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);
+
+  sendInterest(interest, onVerified, onVerifyFailed, timeoutNotify);
+}
+
+
+void
+ContactManager::onKeyVerified(const shared_ptr<Data>& data, const Name& identity)
+{
+  IdentityCertificate identityCertificate(*data);
+
+  Profile profile(identityCertificate);
+  ProfileData profileData(profile);
+
+  Name certificateName = m_identityManager->getDefaultCertificateName();
+  m_identityManager->signByCertificate(profileData, certificateName);
+
+  try{
+    EndorseCertificate endorseCertificate(identityCertificate, profileData);
+    m_identityManager->signByCertificate(endorseCertificate, certificateName);
+    emit contactKeyFetched (endorseCertificate); 
+  }catch(std::exception& e){
+    _LOG_ERROR("Exception: " << e.what());
+    return;
+  }
+}
+
+void
+ContactManager::onKeyVerifyFailed(const shared_ptr<Data>& data, const Name& identity)
+{ 
+  _LOG_DEBUG("Key cannot be verified!");
+  emit contactKeyFetchFailed (identity); 
+}
+
+void
+ContactManager::onKeyTimeoutNotify(const Name& identity)
+{ 
+  _LOG_DEBUG("Key timeout!");
+  emit contactKeyFetchFailed(identity); 
 }
 
 void
@@ -227,410 +295,372 @@
 {
   Name interestName = certName;
   
-  Ptr<Interest> interestPtr = Ptr<Interest>(new Interest(interestName));
-  interestPtr->setChildSelector(Interest::CHILD_RIGHT);
-  interestPtr->setInterestLifetime(1);
-  Ptr<Closure> closure = Ptr<Closure> (new Closure(boost::bind(&ContactManager::onIdCertificateVerified, 
-                                                               this,
-                                                               _1,
-                                                               certName),
-						   boost::bind(&ContactManager::onIdCertificateTimeout,
-                                                               this,
-                                                               _1, 
-                                                               _2,
-                                                               certName,
-                                                               0),
-						   boost::bind(&ContactManager::onIdCertificateUnverified,
-                                                               this,
-                                                               _1,
-                                                               certName)));
-  m_wrapper->sendInterest(interestPtr, closure);
+  Interest interest(interestName);
+  interest.setChildSelector(ndn_Interest_CHILD_SELECTOR_RIGHT);
+  interest.setInterestLifetimeMilliseconds(1000);
+
+  OnVerified onVerified = boost::bind(&ContactManager::onIdCertificateVerified, this, _1, certName);
+  OnVerifyFailed onVerifyFailed = boost::bind(&ContactManager::onIdCertificateVerifyFailed, this, _1, certName);
+  TimeoutNotify timeoutNotify = boost::bind(&ContactManager::onIdCertificateTimeoutNotify, this, certName);
+
+  sendInterest(interest, onVerified, onVerifyFailed, timeoutNotify);
 }
 
 void
-ContactManager::onDnsCollectEndorseVerified(Ptr<Data> data, const Name& identity)
-{ emit collectEndorseFetched (*data); }
+ContactManager::onIdCertificateTimeoutNotify(const Name& identity)
+{ emit contactCertificateFetchFailed (identity); }
+
 
 void
-ContactManager::onDnsCollectEndorseTimeout(Ptr<Closure> closure, Ptr<Interest> interest, const Name& identity, int retry)
-{ emit collectEndorseFetchFailed (identity); }
-
-void
-ContactManager::onDnsCollectEndorseUnverified(Ptr<Data> data, const Name& identity)
-{ emit collectEndorseFetchFailed (identity); }
-
-void
-ContactManager::onKeyVerified(Ptr<Data> data, const Name& identity)
-{
-  IdentityCertificate identityCertificate(*data);
-
-  Ptr<ProfileData> profileData = Ptr<ProfileData>(new ProfileData(Profile(identityCertificate)));
-  
-  Ptr<IdentityManager> identityManager = m_keychain->getIdentityManager();
-  Name certificateName = identityManager->getDefaultCertificateName ();
-  identityManager->signByCertificate(*profileData, certificateName);
-
-  Ptr<EndorseCertificate> endorseCertificate = NULL;
-  try{
-    endorseCertificate = Ptr<EndorseCertificate>(new EndorseCertificate(identityCertificate, profileData));
-  }catch(exception& e){
-    _LOG_ERROR("Exception: " << e.what());
-    return;
-  }
-
-  identityManager->signByCertificate(*endorseCertificate, certificateName);
-
-  emit contactKeyFetched (*endorseCertificate); 
-}
-
-void
-ContactManager::onKeyUnverified(Ptr<Data> data, const Name& identity)
-{ 
-  _LOG_DEBUG("Key cannot be verified!");
-  emit contactKeyFetchFailed (identity); 
-}
-
-void
-ContactManager::onKeyTimeout(Ptr<Closure> closure, Ptr<Interest> interest, const Name& identity, int retry)
-{ 
-  _LOG_DEBUG("Key timeout!");
-  emit contactKeyFetchFailed(identity); 
-}
-
-void
-ContactManager::onIdCertificateVerified(Ptr<Data> data, const Name& identity)
+ContactManager::onIdCertificateVerified(const shared_ptr<Data>& data, const Name& identity)
 {
   IdentityCertificate identityCertificate(*data);
   emit contactCertificateFetched(identityCertificate);
 }
 
 void
-ContactManager::onIdCertificateUnverified(Ptr<Data> data, const Name& identity)
+ContactManager::onIdCertificateVerifyFailed(const shared_ptr<Data>& data, const Name& identity)
 { emit contactCertificateFetchFailed (identity); }
 
 void
-ContactManager::onIdCertificateTimeout(Ptr<Closure> closure, Ptr<Interest> interest, const Name& identity, int retry)
-{ emit contactCertificateFetchFailed (identity); }
+ContactManager::onTargetData(const shared_ptr<const ndn::Interest>& interest, 
+                             const shared_ptr<Data>& data,
+                             int stepCount,
+                             const OnVerified& onVerified,
+                             const OnVerifyFailed& onVerifyFailed,
+                             const TimeoutNotify& timeoutNotify)
+{
+  shared_ptr<ValidationRequest> nextStep = m_policyManager->checkVerificationPolicy(data, stepCount, onVerified, onVerifyFailed);
+
+  if (nextStep)
+    m_face->expressInterest
+      (*nextStep->interest_, 
+       bind(&ContactManager::onCertData, this, _1, _2, nextStep), 
+       bind(&ContactManager::onCertTimeout, this, _1, onVerifyFailed, data, nextStep));
+
+}
+
+void
+ContactManager::onTargetTimeout(const shared_ptr<const ndn::Interest>& interest, 
+                                int retry,
+                                int stepCount,
+                                const OnVerified& onVerified,
+                                const OnVerifyFailed& onVerifyFailed,
+                                const TimeoutNotify& timeoutNotify)
+{
+  if(retry > 0)
+    sendInterest(*interest, onVerified, onVerifyFailed, timeoutNotify, retry-1, stepCount);
+  else
+    {
+      _LOG_DEBUG("Interest: " << interest->getName().toUri() << " eventually times out!");
+      timeoutNotify();
+    }
+}
+
+void
+ContactManager::onCertData(const shared_ptr<const ndn::Interest>& interest, 
+                           const shared_ptr<Data>& cert,
+                           shared_ptr<ValidationRequest> previousStep)
+{
+  shared_ptr<ValidationRequest> nextStep = m_policyManager->checkVerificationPolicy(cert, 
+                                                                                    previousStep->stepCount_, 
+                                                                                    previousStep->onVerified_, 
+                                                                                    previousStep->onVerifyFailed_);
+
+  if (nextStep)
+    m_face->expressInterest
+      (*nextStep->interest_, 
+       bind(&ContactManager::onCertData, this, _1, _2, nextStep), 
+       bind(&ContactManager::onCertTimeout, this, _1, previousStep->onVerifyFailed_, cert, nextStep));
+}
+
+void
+ContactManager::onCertTimeout(const shared_ptr<const ndn::Interest>& interest,
+                              const OnVerifyFailed& onVerifyFailed,
+                              const shared_ptr<Data>& data,
+                              shared_ptr<ValidationRequest> nextStep)
+{
+  if(nextStep->retry_ > 0)
+    m_face->expressInterest(*interest, 
+                            bind(&ContactManager::onCertData,
+                                 this,
+                                 _1,
+                                 _2,
+                                 nextStep),
+                            bind(&ContactManager::onCertTimeout,
+                                 this,
+                                 _1,
+                                 onVerifyFailed,
+                                 data,
+                                 nextStep));
+ else
+   onVerifyFailed(data);
+}
+
+void
+ContactManager::sendInterest(const Interest& interest,
+                             const OnVerified& onVerified,
+                             const OnVerifyFailed& onVerifyFailed,
+                             const TimeoutNotify& timeoutNotify,
+                             int retry /* = 1 */,
+                             int stepCount /* = 0 */)
+{
+  m_face->expressInterest(interest, 
+                          boost::bind(&ContactManager::onTargetData, 
+                                      this,
+                                      _1,
+                                      _2,
+                                      stepCount,
+                                      onVerified, 
+                                      onVerifyFailed,
+                                      timeoutNotify),
+                          boost::bind(&ContactManager::onTargetTimeout,
+                                      this,
+                                      _1,
+                                      retry,
+                                      stepCount,
+                                      onVerified,
+                                      onVerifyFailed,
+                                      timeoutNotify));
+}
 
 void
 ContactManager::updateProfileData(const Name& identity)
 {
   // Get current profile;
-  Ptr<Profile> newProfile = m_contactStorage->getSelfProfile(identity);
-  if(NULL == newProfile)
+  shared_ptr<Profile> newProfile = m_contactStorage->getSelfProfile(identity);
+  if(CHRONOCHAT_NULL_PROFILE_PTR == newProfile)
     return;
-  Ptr<Blob> newProfileBlob = newProfile->toDerBlob();
+
+  shared_ptr<EndorseCertificate> newEndorseCertificate = getSignedSelfEndorseCertificate(identity, *newProfile);
+
+  if(CHRONOCHAT_NULL_ENDORSECERTIFICATE_PTR == newEndorseCertificate)
+    return;
 
   // Check if profile exists
-  Ptr<Blob> profileDataBlob = m_contactStorage->getSelfEndorseCertificate(identity);
-  if(NULL != profileDataBlob)
-    {
-      
-      Ptr<EndorseCertificate> oldEndorseCertificate = NULL;
-      try{
-        Ptr<Data> plainData = Data::decodeFromWire(profileDataBlob);
-        oldEndorseCertificate = Ptr<EndorseCertificate>(new EndorseCertificate(*plainData));
-      }catch(exception& e){
-        _LOG_ERROR("Exception: " << e.what());
-        return;
-      }
-
-      const Blob& oldProfileBlob = oldEndorseCertificate->getProfileData()->content();
-
-      if(oldProfileBlob == *newProfileBlob)
-        return;
-
-      Ptr<EndorseCertificate> newEndorseCertificate = getSignedSelfEndorseCertificate(identity, *newProfile);
-
-      if(NULL == newEndorseCertificate)
-        return;
-
-      m_contactStorage->updateSelfEndorseCertificate(newEndorseCertificate, identity);
-
-      publishSelfEndorseCertificateInDNS(newEndorseCertificate);
-    }
+  Blob profileDataBlob = m_contactStorage->getSelfEndorseCertificate(identity);
+  if(CHRONOCHAT_NULL_BLOB != profileDataBlob)
+    m_contactStorage->updateSelfEndorseCertificate(*newEndorseCertificate, identity);
   else
-    {
-      Ptr<EndorseCertificate> newEndorseCertificate = getSignedSelfEndorseCertificate(identity, *newProfile);
+    m_contactStorage->addSelfEndorseCertificate(*newEndorseCertificate, identity);
 
-      if(NULL == newEndorseCertificate)
-        return;
-
-      m_contactStorage->addSelfEndorseCertificate(newEndorseCertificate, identity);
-
-      publishSelfEndorseCertificateInDNS(newEndorseCertificate);
-    }
+  publishSelfEndorseCertificateInDNS(*newEndorseCertificate);
 }
 
 void
 ContactManager::updateEndorseCertificate(const ndn::Name& identity, const ndn::Name& signerIdentity)
 {
-  Ptr<Blob> oldEndorseCertificateBlob = m_contactStorage->getEndorseCertificate(identity);
-  Ptr<EndorseCertificate> newEndorseCertificate = generateEndorseCertificate(identity, signerIdentity);
-  if(NULL != oldEndorseCertificateBlob)
-    {
-      Ptr<EndorseCertificate> oldEndorseCertificate = NULL;
-      try{
-        Ptr<Data> plainData = Data::decodeFromWire(oldEndorseCertificateBlob);
-        oldEndorseCertificate = Ptr<EndorseCertificate>(new EndorseCertificate(*plainData));
-      }catch(exception& e){
-        _LOG_ERROR("Exception: " << e.what());
-        return;
-      }
-      const Blob& oldEndorseContent = oldEndorseCertificate->content();
-      const Blob& newEndorseContent = newEndorseCertificate->content();
-      if(oldEndorseContent == newEndorseContent)
-        return;
-    }
+  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)
+    m_contactStorage->updateEndorseCertificate(*newEndorseCertificate, identity);
   else
-    {
-      if(NULL == newEndorseCertificate)
-        return;
-    }
-  m_contactStorage->addEndorseCertificate(newEndorseCertificate, identity);
-  publishEndorseCertificateInDNS(newEndorseCertificate, signerIdentity);
+    m_contactStorage->addEndorseCertificate(*newEndorseCertificate, identity);
+ 
+  publishEndorseCertificateInDNS(*newEndorseCertificate, signerIdentity);
 }
 
-Ptr<EndorseCertificate> 
+shared_ptr<EndorseCertificate> 
 ContactManager::generateEndorseCertificate(const Name& identity, const Name& signerIdentity)
 {
-  Ptr<ContactItem> contact = getContact(identity);
-  if(contact == NULL)
-    return NULL;
+  shared_ptr<ContactItem> contact = getContact(identity);
+  if(contact == CHRONOCHAT_NULL_CONTACTITEM_PTR)
+    return CHRONOCHAT_NULL_ENDORSECERTIFICATE_PTR;
 
-  Ptr<IdentityManager> identityManager = m_keychain->getIdentityManager();
-  Name signerKeyName = identityManager->getDefaultKeyNameForIdentity(signerIdentity);
-  Name signerCertName = identityManager->getDefaultCertificateNameByIdentity(signerIdentity);
+  Name signerKeyName = m_identityManager->getDefaultKeyNameForIdentity(signerIdentity);
+  Name signerCertName = m_identityManager->getDefaultCertificateNameForIdentity(signerIdentity);
 
-  vector<string> endorseList = m_contactStorage->getEndorseList(identity);
+  vector<string> endorseList;
+  m_contactStorage->getEndorseList(identity, endorseList);
 
-  Ptr<EndorseCertificate> cert = NULL;
+  
   try{
-    cert = Ptr<EndorseCertificate>(new EndorseCertificate(contact->getSelfEndorseCertificate(), signerKeyName, endorseList)); 
-  }catch(exception& e){
+    shared_ptr<EndorseCertificate> cert = make_shared<EndorseCertificate>(contact->getSelfEndorseCertificate(), signerKeyName, endorseList); 
+    m_identityManager->signByCertificate(*cert, signerCertName);
+    return cert;
+  }catch(std::exception& e){
     _LOG_ERROR("Exception: " << e.what());
-    return NULL;
+    return CHRONOCHAT_NULL_ENDORSECERTIFICATE_PTR;
   } 
-  identityManager->signByCertificate(*cert, signerCertName);
-
-  return cert;
 }
 
-vector<Ptr<ContactItem> >
-ContactManager::getContactItemList()
-{ return m_contactStorage->getAllContacts(); }
+void
+ContactManager::getContactItemList(vector<shared_ptr<ContactItem> >& contacts)
+{ return m_contactStorage->getAllContacts(contacts); }
 
-Ptr<ContactItem>
+shared_ptr<ContactItem>
 ContactManager::getContact(const ndn::Name& contactNamespace)
 { return m_contactStorage->getContact(contactNamespace); }
 
-Ptr<EndorseCertificate>
+shared_ptr<EndorseCertificate>
 ContactManager::getSignedSelfEndorseCertificate(const Name& identity,
                                                 const Profile& profile)
 {
-  Ptr<IdentityManager> identityManager = m_keychain->getIdentityManager();
-  Name certificateName = identityManager->getDefaultCertificateNameByIdentity(identity);
+  Name certificateName = m_identityManager->getDefaultCertificateNameForIdentity(identity);
   if(0 == certificateName.size())
-    return NULL;
+    return CHRONOCHAT_NULL_ENDORSECERTIFICATE_PTR;
 
-  Ptr<ProfileData> profileData = Ptr<ProfileData>(new ProfileData(profile));
-  identityManager->signByCertificate(*profileData, certificateName);
+  ProfileData profileData(profile);
+  m_identityManager->signByCertificate(profileData, certificateName);
 
-  Ptr<security::IdentityCertificate> signingCert = identityManager->getCertificate(certificateName);
-  if(NULL == signingCert)
-    return NULL;
+  shared_ptr<IdentityCertificate> signingCert = m_identityManager->getCertificate(certificateName);
+  if(CHRONOCHAT_NULL_IDENTITYCERTIFICATE_PTR == signingCert)
+    return CHRONOCHAT_NULL_ENDORSECERTIFICATE_PTR;
 
-  Name signingKeyName = security::IdentityCertificate::certificateNameToPublicKeyName(signingCert->getName(), true);
+  Name signingKeyName = IdentityCertificate::certificateNameToPublicKeyName(signingCert->getName());
 
-  Ptr<security::IdentityCertificate> kskCert;
-  if(signingKeyName.get(-1).toUri().substr(0,4) == string("dsk-"))
+  shared_ptr<IdentityCertificate> kskCert;
+  if(signingKeyName.get(-1).toEscapedString().substr(0,4) == string("dsk-"))
     {
-      Ptr<const signature::Sha256WithRsa> dskCertSig = DynamicCast<const signature::Sha256WithRsa>(signingCert->getSignature());
+      const Sha256WithRsaSignature* dskCertSig = dynamic_cast<const Sha256WithRsaSignature*>(signingCert->getSignature());
       // HACK! KSK certificate should be retrieved from network.
-      Name keyName = security::IdentityCertificate::certificateNameToPublicKeyName(dskCertSig->getKeyLocator().getKeyName());
+      Name keyName = IdentityCertificate::certificateNameToPublicKeyName(dskCertSig->getKeyLocator().getKeyName());
 
-      Name kskCertName = identityManager->getPublicStorage()->getDefaultCertificateNameForKey(keyName);
+      // TODO: check null existing cases.
+      Name kskCertName = m_identityManager->getDefaultCertificateNameForIdentity(keyName.getPrefix(-1));
 
-      kskCert = identityManager->getCertificate(kskCertName);
-
+      kskCert = m_identityManager->getCertificate(kskCertName);
     }
   else
     {
       kskCert = signingCert;
     }
 
-  if(NULL == kskCert)
-    return NULL;
+  if(CHRONOCHAT_NULL_IDENTITYCERTIFICATE_PTR == kskCert)
+    return CHRONOCHAT_NULL_ENDORSECERTIFICATE_PTR;
 
   vector<string> endorseList;
   Profile::const_iterator it = profile.begin();
   for(; it != profile.end(); it++)
     endorseList.push_back(it->first);
   
-  Ptr<EndorseCertificate> selfEndorseCertificate = NULL;
   try{
-    selfEndorseCertificate = Ptr<EndorseCertificate>(new EndorseCertificate(*kskCert,
-                                                                            profileData,
-                                                                            endorseList));
-  }catch(exception& e){
+    shared_ptr<EndorseCertificate> selfEndorseCertificate = make_shared<EndorseCertificate>(*kskCert, profileData, endorseList);
+    m_identityManager->signByCertificate(*selfEndorseCertificate, kskCert->getName());
+
+    return selfEndorseCertificate;
+  }catch(std::exception& e){
     _LOG_ERROR("Exception: " << e.what());
-    return NULL;
+    return CHRONOCHAT_NULL_ENDORSECERTIFICATE_PTR;
   } 
-
-  identityManager->signByCertificate(*selfEndorseCertificate, kskCert->getName());
-
-  return selfEndorseCertificate;
 }
 
 
 void
-ContactManager::onDnsSelfEndorseCertificateVerified(Ptr<Data> data, const Name& identity)
+ContactManager::publishSelfEndorseCertificateInDNS(const EndorseCertificate& selfEndorseCertificate)
 {
-  Ptr<Blob> dataContentBlob = Ptr<Blob>(new Blob(data->content().buf(), data->content().size()));
+  Data data;
 
-  Ptr<Data> plainData = NULL;
-  Ptr<EndorseCertificate> selfEndorseCertificate = NULL;
-  try{
-    plainData = Data::decodeFromWire(dataContentBlob);
-    selfEndorseCertificate = Ptr<EndorseCertificate>(new EndorseCertificate(*plainData));
-  }catch(exception& e){
-    _LOG_ERROR("Exception: " << e.what());
-    return;
-  }
-
-  const security::Publickey& ksk = selfEndorseCertificate->getPublicKeyInfo();
-
-  if(security::PolicyManager::verifySignature(*plainData, ksk))
-    emit contactFetched (*selfEndorseCertificate); 
-  else
-    emit contactFetchFailed (identity);
-}
-
-void
-ContactManager::onDnsSelfEndorseCertificateUnverified(Ptr<Data> data, const Name& identity)
-{ emit contactFetchFailed (identity); }
-
-void
-ContactManager::onDnsSelfEndorseCertificateTimeout(Ptr<Closure> closure, Ptr<Interest> interest, const Name& identity, int retry)
-{ emit contactFetchFailed(identity); }
-
-void
-ContactManager::publishSelfEndorseCertificateInDNS(Ptr<EndorseCertificate> selfEndorseCertificate)
-{
-  Ptr<Data> data = Ptr<Data>::Create();
-
-  Name keyName = selfEndorseCertificate->getPublicKeyName();
+  Name keyName = selfEndorseCertificate.getPublicKeyName();
   Name identity = keyName.getSubName(0, keyName.size()-1);
 
+  time_t nowSeconds = time(NULL);
+  struct tm current = *gmtime(&nowSeconds);
+  MillisecondsSince1970 version = timegm(&current) * 1000.0;
 
   Name dnsName = identity;
-  dnsName.append("DNS").append("PROFILE").appendVersion();
+  dnsName.append("DNS").append("PROFILE").appendVersion(version);
+  data.setName(dnsName);
+
+  data.setContent(selfEndorseCertificate.wireEncode());
+
+  Name signCertName = m_identityManager->getDefaultCertificateNameForIdentity(identity);
+  m_identityManager->signByCertificate(data, signCertName);
+
+  m_dnsStorage->updateDnsSelfProfileData(data, identity);
   
-  data->setName(dnsName);
-  Ptr<Blob> blob = selfEndorseCertificate->encodeToWire();
-
-  Content content(blob->buf(), blob->size());
-  data->setContent(content);
-
-  m_keychain->signByIdentity(*data, identity);
-
-  m_dnsStorage->updateDnsSelfProfileData(*data, identity);
-  
-  Ptr<Blob> dnsBlob = data->encodeToWire();
-
-  m_wrapper->putToNdnd(*dnsBlob);
+   m_transport->send(*data.wireEncode());
 }
 
 void
-ContactManager::publishEndorseCertificateInDNS(Ptr<EndorseCertificate> endorseCertificate, const Name& signerIdentity)
+ContactManager::publishEndorseCertificateInDNS(const EndorseCertificate& endorseCertificate, const Name& signerIdentity)
 {
-  Ptr<Data> data = Ptr<Data>::Create();
+  Data data;
 
-  Name keyName = endorseCertificate->getPublicKeyName();
+  Name keyName = endorseCertificate.getPublicKeyName();
   Name endorsee = keyName.getSubName(0, keyName.size()-1);
 
+  time_t nowSeconds = time(NULL);
+  struct tm current = *gmtime(&nowSeconds);
+  MillisecondsSince1970 version = timegm(&current) * 1000.0;
 
   Name dnsName = signerIdentity;
-  dnsName.append("DNS").append(endorsee).append("ENDORSEE").appendVersion();
-  
-  data->setName(dnsName);
-  Ptr<Blob> blob = endorseCertificate->encodeToWire();
+  dnsName.append("DNS").append(endorsee).append("ENDORSEE").appendVersion(version);
+  data.setName(dnsName);
 
-  Content content(blob->buf(), blob->size());
-  data->setContent(content);
+  data.setContent(endorseCertificate.wireEncode());
 
-  Name signCertName = m_keychain->getIdentityManager()->getDefaultCertificateNameByIdentity(signerIdentity);
-  m_keychain->getIdentityManager()->signByCertificate(*data, signCertName);
+  Name signCertName = m_identityManager->getDefaultCertificateNameForIdentity(signerIdentity);
+  m_identityManager->signByCertificate(data, signCertName);
 
-  m_dnsStorage->updateDnsEndorseOthers(*data, signerIdentity, endorsee);
-  
-  Ptr<Blob> dnsBlob = data->encodeToWire();
+  m_dnsStorage->updateDnsEndorseOthers(data, signerIdentity, endorsee);
 
-  m_wrapper->putToNdnd(*dnsBlob);
+  m_transport->send(*data.wireEncode());
 }
 
 void
 ContactManager::publishEndorsedDataInDns(const Name& identity)
 {
-  Ptr<Data> data = Ptr<Data>::Create();
+  Data data;
+
+  time_t nowSeconds = time(NULL);
+  struct tm current = *gmtime(&nowSeconds);
+  MillisecondsSince1970 version = timegm(&current) * 1000.0;
 
   Name dnsName = identity;
-  dnsName.append("DNS").append("ENDORSED").appendVersion();
-  data->setName(dnsName);
+  dnsName.append("DNS").append("ENDORSED").appendVersion(version);
+  data.setName(dnsName);
   
-  Ptr<vector<Blob> > collectEndorseList = m_contactStorage->getCollectEndorseList(identity);
+  vector<Blob> collectEndorseList;
+  m_contactStorage->getCollectEndorseList(identity, collectEndorseList);
+  
+  Chronos::EndorseCollection endorseCollection;
 
-  Ptr<der::DerSequence> root = Ptr<der::DerSequence>::Create();
-
-  vector<Blob>::const_iterator it = collectEndorseList->begin();
-  for(; it != collectEndorseList->end(); it++)
+  vector<Blob>::const_iterator it = collectEndorseList.begin();
+  for(; it != collectEndorseList.end(); it++)
     {
-      Ptr<der::DerOctetString> entry = Ptr<der::DerOctetString>(new der::DerOctetString(*it));
-      root->addChild(entry);
+      string entryStr((const char*)it->buf(), it->size());
+      endorseCollection.add_endorsement()->set_blob(entryStr);
     }
-  
-  blob_stream blobStream;
-  OutputIterator & start = reinterpret_cast<OutputIterator &> (blobStream);
-  root->encode(start);
 
-  Content content(blobStream.buf()->buf(), blobStream.buf()->size());
-  data->setContent(content);
-  
-  Name signCertName = m_keychain->getIdentityManager()->getDefaultCertificateNameByIdentity(identity);
-  m_keychain->getIdentityManager()->signByCertificate(*data, signCertName);
+  string encoded;
+  endorseCollection.SerializeToString(&encoded);
 
-  m_dnsStorage->updateDnsOthersEndorse(*data, identity);
+  data.setContent((const uint8_t*)encoded.c_str(), encoded.size());
   
-  Ptr<Blob> dnsBlob = data->encodeToWire();
+  Name signCertName = m_identityManager->getDefaultCertificateNameForIdentity(identity);
+  m_identityManager->signByCertificate(data, signCertName);
 
-  m_wrapper->putToNdnd(*dnsBlob);
+  m_dnsStorage->updateDnsOthersEndorse(data, identity);
+
+  m_transport->send(*data.wireEncode());
 }
 
 void
 ContactManager::addContact(const IdentityCertificate& identityCertificate, const Profile& profile)
 {
-  Ptr<ProfileData> profileData = Ptr<ProfileData>(new ProfileData(profile));
+  ProfileData profileData(profile);
   
-  Ptr<IdentityManager> identityManager = m_keychain->getIdentityManager();
-  Name certificateName = identityManager->getDefaultCertificateNameByIdentity (m_defaultIdentity);
-  identityManager->signByCertificate(*profileData, certificateName);
+  Name certificateName = m_identityManager->getDefaultCertificateNameForIdentity (m_defaultIdentity);
+  m_identityManager->signByCertificate(profileData, certificateName);
 
-  Ptr<EndorseCertificate> endorseCertificate = NULL;
-  try{
-    endorseCertificate = Ptr<EndorseCertificate>(new EndorseCertificate(identityCertificate, profileData));
-  }catch(exception& e){
-    _LOG_ERROR("Exception: " << e.what());
-    return;
-  }
-
-  identityManager->signByCertificate(*endorseCertificate, certificateName);
-
-  ContactItem contactItem(*endorseCertificate);
 
   try{
+    EndorseCertificate endorseCertificate(identityCertificate, profileData);
+    
+    m_identityManager->signByCertificate(endorseCertificate, certificateName);
+
+    ContactItem contactItem(endorseCertificate);
+
     m_contactStorage->addContact(contactItem);
+
     emit contactAdded(contactItem.getNameSpace());
-  }catch(exception& e){
+
+  }catch(std::exception& e){
     emit warning(e.what());
     _LOG_ERROR("Exception: " << e.what());
     return;
@@ -640,8 +670,8 @@
 void
 ContactManager::removeContact(const ndn::Name& contactNameSpace)
 {
-  Ptr<ContactItem> contact = getContact(contactNameSpace);
-  if(contact == NULL)
+  shared_ptr<ContactItem> contact = getContact(contactNameSpace);
+  if(contact == CHRONOCHAT_NULL_CONTACTITEM_PTR)
     return;
   m_contactStorage->removeContact(contactNameSpace);
   emit contactRemoved(contact->getPublicKeyName());
diff --git a/src/contact-manager.h b/src/contact-manager.h
index a19135f..0c4cc06 100644
--- a/src/contact-manager.h
+++ b/src/contact-manager.h
@@ -18,23 +18,24 @@
 #include "dns-storage.h"
 #include "endorse-certificate.h"
 #include "profile.h"
-#include <ndn.cxx/wrapper/wrapper.h>
+#include <ndn-cpp/face.hpp>
+#include <ndn-cpp/security/policy/validation-request.hpp>
+#include <ndn-cpp-et/policy-manager/simple-policy-manager.hpp>
 #endif
 
+typedef ndn::func_lib::function<void()> TimeoutNotify;
 
 class ContactManager : public QObject
 {
   Q_OBJECT
 
 public:
-  ContactManager(QObject* parent = 0);
+  ContactManager(ndn::ptr_lib::shared_ptr<ndn::IdentityManager> identityManager,
+                 QObject* parent = 0);
 
   ~ContactManager();
 
   void
-  setWrapper();
-
-  void
   fetchSelfEndorseCertificate(const ndn::Name& identity);
 
   void
@@ -52,93 +53,142 @@
   void
   updateEndorseCertificate(const ndn::Name& identity, const ndn::Name& signerIdentity);
 
-  std::vector<ndn::Ptr<ContactItem> >
-  getContactItemList();
+  void
+  getContactItemList(std::vector<ndn::ptr_lib::shared_ptr<ContactItem> >& contacts);
 
-  inline ndn::Ptr<ContactStorage>
+  ndn::ptr_lib::shared_ptr<ContactStorage>
   getContactStorage()
   { return m_contactStorage; }
 
-  ndn::Ptr<ContactItem>
+  ndn::ptr_lib::shared_ptr<ContactItem>
   getContact(const ndn::Name& contactNamespace);
 
-  inline ndn::Ptr<DnsStorage>
+  ndn::ptr_lib::shared_ptr<DnsStorage>
   getDnsStorage()
   { return m_dnsStorage; }
 
-  inline ndn::Name
+  ndn::Name
   getDefaultIdentity()
-  { return m_keychain->getDefaultIdentity(); }
-
-  inline ndn::Ptr<ndn::Wrapper>
-  getWrapper()
-  { return m_wrapper; }
+  { return m_identityManager->getDefaultIdentity(); }
 
   void
   publishEndorsedDataInDns(const ndn::Name& identity);
 
-  inline void
+  void
   setDefaultIdentity(const ndn::Name& identity)
   { m_defaultIdentity = identity; }
 
   void
-  addContact(const ndn::security::IdentityCertificate& idCert, const Profile& profile);
+  addContact(const ndn::IdentityCertificate& idCert, const Profile& profile);
 
   void
   removeContact(const ndn::Name& contactNameSpace);
   
+  ndn::ptr_lib::shared_ptr<ndn::IdentityManager>
+  getIdentityManager()
+  { return m_identityManager; }
 
 private:
-  void
-  setKeychain();
+  void 
+  connectToDaemon();
 
-  ndn::Ptr<EndorseCertificate>
+  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);
+  
+  void
+  initializeSecurity();
+
+  ndn::ptr_lib::shared_ptr<EndorseCertificate>
   getSignedSelfEndorseCertificate(const ndn::Name& identity, const Profile& profile);
 
-  ndn::Ptr<EndorseCertificate> 
+  ndn::ptr_lib::shared_ptr<EndorseCertificate> 
   generateEndorseCertificate(const ndn::Name& identity, const ndn::Name& signerIdentity);
 
   void
-  publishSelfEndorseCertificateInDNS(ndn::Ptr<EndorseCertificate> selfEndorseCertificate);
+  publishSelfEndorseCertificateInDNS(const EndorseCertificate& selfEndorseCertificate);
 
   void
-  publishEndorseCertificateInDNS(ndn::Ptr<EndorseCertificate> endorseCertificate, const ndn::Name& signerIdentity);
+  publishEndorseCertificateInDNS(const EndorseCertificate& endorseCertificate, const ndn::Name& signerIdentity);
+
+  void
+  sendInterest(const ndn::Interest& interest,
+               const ndn::OnVerified& onVerified,
+               const ndn::OnVerifyFailed& onVerifyFailed,
+               const TimeoutNotify& timeoutNotify,
+               int retry = 1,
+               int stepCount = 0);
+
+  void
+  onTargetData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, 
+               const ndn::ptr_lib::shared_ptr<ndn::Data>& data,
+               int stepCount,
+               const ndn::OnVerified& onVerified,
+               const ndn::OnVerifyFailed& onVerifyFailed,
+               const TimeoutNotify& timeoutNotify);
+
+  void
+  onTargetTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, 
+                  int retry,
+                  int stepCount,
+                  const ndn::OnVerified& onVerified,
+                  const ndn::OnVerifyFailed& onVerifyFailed,
+                  const TimeoutNotify& timeoutNotify);
+
+
+  void
+  onCertData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, 
+             const ndn::ptr_lib::shared_ptr<ndn::Data>& cert,
+             ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> previousStep);
+
+  void
+  onCertTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
+                const ndn::OnVerifyFailed& onVerifyFailed,
+                const ndn::ptr_lib::shared_ptr<ndn::Data>& data,
+                ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> nextStep);
+
+
+  void
+  onDnsSelfEndorseCertificateTimeoutNotify(const ndn::Name& identity);
 
   void 
-  onDnsSelfEndorseCertificateVerified(ndn::Ptr<ndn::Data> selfEndorseCertificate, const ndn::Name& identity);
+  onDnsSelfEndorseCertificateVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& selfEndorseCertificate, const ndn::Name& identity);
 
   void
-  onDnsSelfEndorseCertificateUnverified(ndn::Ptr<ndn::Data> selfEndorseCertificate, const ndn::Name& identity);
+  onDnsSelfEndorseCertificateVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& selfEndorseCertificate, const ndn::Name& identity);
+ 
 
   void
-  onDnsSelfEndorseCertificateTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest, const ndn::Name& identity, int retry);
+  onDnsCollectEndorseVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
 
   void
-  onKeyVerified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity);
+  onDnsCollectEndorseVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
 
   void
-  onKeyUnverified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity);
+  onDnsCollectEndorseTimeoutNotify(const ndn::Name& identity);
+
 
   void
-  onKeyTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest, const ndn::Name& identity, int retry);
+  onKeyVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
 
   void
-  onDnsCollectEndorseVerified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity);
+  onKeyVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
 
   void
-  onDnsCollectEndorseTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest, const ndn::Name& identity, int retry);
+  onKeyTimeoutNotify(const ndn::Name& identity);
+
 
   void
-  onDnsCollectEndorseUnverified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity);
+  onIdCertificateVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
 
   void
-  onIdCertificateVerified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity);
+  onIdCertificateVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
 
   void
-  onIdCertificateUnverified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity);
-
-  void
-  onIdCertificateTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest, const ndn::Name& identity, int retry);
+  onIdCertificateTimeoutNotify(const ndn::Name& identity);
   
 
 signals:
@@ -158,7 +208,7 @@
   contactKeyFetchFailed(const ndn::Name& identity);
 
   void 
-  contactCertificateFetched(const ndn::security::IdentityCertificate& identityCertificate);
+  contactCertificateFetched(const ndn::IdentityCertificate& identityCertificate);
   
   void
   contactCertificateFetchFailed(const ndn::Name& identity);
@@ -182,10 +232,12 @@
   
   
 private:
-  ndn::Ptr<ContactStorage> m_contactStorage;
-  ndn::Ptr<DnsStorage> m_dnsStorage;
-  ndn::Ptr<ndn::security::Keychain> m_keychain;
-  ndn::Ptr<ndn::Wrapper> m_wrapper;
+  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::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 595dd68..61ed746 100644
--- a/src/contact-storage.cpp
+++ b/src/contact-storage.cpp
@@ -9,14 +9,15 @@
  */
 
 #include "contact-storage.h"
+#include "null-ptrs.h"
 #include "exception.h"
 
 #include <boost/filesystem.hpp>
-#include <ndn.cxx/fields/signature-sha256-with-rsa.h>
 #include "logging.h"
 
 using namespace std;
 using namespace ndn;
+using namespace ndn::ptr_lib;
 namespace fs = boost::filesystem;
 
 INIT_LOGGER ("ContactStorage");
@@ -270,7 +271,7 @@
   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, profileValue.buf(), profileValue.size(), SQLITE_TRANSIENT);
+      sqlite3_bind_text(stmt, 1, (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);
     }
@@ -279,17 +280,17 @@
       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, profileValue.buf(), profileValue.size(), SQLITE_TRANSIENT);
+      sqlite3_bind_text(stmt, 3, (const char*)profileValue.buf(), profileValue.size(), SQLITE_TRANSIENT);
     }
   sqlite3_step (stmt);
   sqlite3_finalize (stmt);
 }
 
-Ptr<Profile>
+shared_ptr<Profile>
 ContactStorage::getSelfProfile(const Name& identity)
 {
   sqlite3_stmt *stmt;
-  Ptr<Profile> profile = Ptr<Profile>(new Profile(identity));
+  shared_ptr<Profile> profile = make_shared<Profile>(identity);
   
   sqlite3_prepare_v2(m_db, "SELECT profile_type, profile_value FROM SelfProfile WHERE profile_identity=?", -1, &stmt, 0);
   sqlite3_bind_text(stmt, 1, identity.toUri().c_str(), identity.toUri().size(), SQLITE_TRANSIENT);
@@ -297,7 +298,7 @@
   while(sqlite3_step (stmt) == SQLITE_ROW)
     {
       string profileType(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0));
-      Blob profileValue(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 1)), sqlite3_column_bytes (stmt, 1));
+      string profileValue(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 1)), sqlite3_column_bytes (stmt, 1));
 
       profile->setProfileEntry(profileType, profileValue );
     }
@@ -310,7 +311,7 @@
 void 
 ContactStorage::removeContact(const Name& contactNameSpace)
 {
-  Ptr<ContactItem> contact = getContact(contactNameSpace);
+  shared_ptr<ContactItem> contact = getContact(contactNameSpace);
   string identity = contactNameSpace.toUri();
   
   if(contact == NULL)
@@ -353,15 +354,14 @@
 
   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);
-  Ptr<Blob> selfCertificateBlob = contact.getSelfEndorseCertificate().encodeToWire();
-  sqlite3_bind_text(stmt, 3, selfCertificateBlob->buf(), selfCertificateBlob->size(), SQLITE_TRANSIENT);
+  Blob selfCertificateBlob = contact.getSelfEndorseCertificate().wireEncode();
+  sqlite3_bind_text(stmt, 3, (const char*)selfCertificateBlob.buf(), selfCertificateBlob.size(), SQLITE_TRANSIENT);
   sqlite3_bind_int(stmt, 4, (isIntroducer ? 1 : 0));
 
   int res = sqlite3_step (stmt);
   sqlite3_finalize (stmt);
 
-  Ptr<ProfileData> profileData = contact.getSelfEndorseCertificate().getProfileData();
-  const Profile&  profile = profileData->getProfile();
+  const Profile&  profile = contact.getSelfEndorseCertificate().getProfileData().getProfile();
   Profile::const_iterator it = profile.begin();
   string identity = contact.getNameSpace().toUri();
   for(; it != profile.end(); it++)
@@ -373,7 +373,7 @@
                           0);
       sqlite3_bind_text(stmt, 1, identity.c_str(),  identity.size (), SQLITE_TRANSIENT);
       sqlite3_bind_text(stmt, 2, it->first.c_str(), it->first.size(), SQLITE_TRANSIENT);
-      sqlite3_bind_text(stmt, 3, it->second.buf(), it->second.size(), SQLITE_TRANSIENT);
+      sqlite3_bind_text(stmt, 3, it->second.c_str(), it->second.size(), SQLITE_TRANSIENT);
       res = sqlite3_step (stmt);
       sqlite3_finalize (stmt);
     }
@@ -445,27 +445,27 @@
   return result;
 }
 
-vector<Ptr<ContactItem> >
-ContactStorage::getAllContacts() const
+void
+ContactStorage::getAllContacts(vector<shared_ptr<ContactItem> >& contacts) const
 {
-  vector<Ptr<ContactItem> > contacts;
-
   sqlite3_stmt *stmt;
   sqlite3_prepare_v2 (m_db, "SELECT contact_alias, self_certificate, is_introducer FROM Contact", -1, &stmt, 0);
   
   while( sqlite3_step (stmt) == SQLITE_ROW)
     {
       string alias(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0));
-      Ptr<Blob> certBlob = Ptr<Blob>(new Blob(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 1)), sqlite3_column_bytes (stmt, 1)));
-      Ptr<Data> certData = Data::decodeFromWire(certBlob);
-      EndorseCertificate endorseCertificate(*certData);
+
+      Data certData;
+      certData.wireDecode(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);
 
-      contacts.push_back(Ptr<ContactItem>(new ContactItem(endorseCertificate, isIntroducer, alias)));      
+      contacts.push_back(make_shared<ContactItem>(endorseCertificate, isIntroducer, alias));      
     }
   sqlite3_finalize (stmt);  
 
-  vector<Ptr<ContactItem> >::iterator it = contacts.begin();
+  vector<shared_ptr<ContactItem> >::iterator it = contacts.begin();
   for(; it != contacts.end(); it++)
     {
       if((*it)->isIntroducer())
@@ -481,11 +481,9 @@
           sqlite3_finalize (stmt);  
         }
     }
-
-  return contacts;
 }
 
-Ptr<ContactItem>
+shared_ptr<ContactItem>
 ContactStorage::getContact(const Name& name)
 {
   sqlite3_stmt *stmt;
@@ -495,14 +493,16 @@
   if( sqlite3_step (stmt) == SQLITE_ROW)
     {
       string alias(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0));
-      Ptr<Blob> certBlob = Ptr<Blob>(new Blob(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 1)), sqlite3_column_bytes (stmt, 1)));
-      Ptr<Data> certData = Data::decodeFromWire(certBlob);
-      EndorseCertificate endorseCertificate(*certData);
+
+      Data certData;
+      certData.wireDecode(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);
 
       sqlite3_finalize (stmt);
       
-      Ptr<ContactItem> contact = Ptr<ContactItem>(new ContactItem(endorseCertificate, isIntroducer, alias));
+      shared_ptr<ContactItem> contact = make_shared<ContactItem>(endorseCertificate, isIntroducer, alias);
 
       if(contact->isIntroducer())
         {
@@ -519,13 +519,13 @@
 
       return contact;      
     } 
-  return NULL;
+  return CHRONOCHAT_NULL_CONTACTITEM_PTR;
 }
 
-Ptr<Profile>
+shared_ptr<Profile>
 ContactStorage::getSelfProfile(const Name& identity) const
 {  
-  Ptr<Profile> profile = Ptr<Profile>(new Profile(identity));
+  shared_ptr<Profile> profile = make_shared<Profile>(identity);
   sqlite3_stmt *stmt;
   sqlite3_prepare_v2 (m_db, "SELECT profile_type, profile_value FROM SelfProfile WHERE profile_identity=?", -1, &stmt, 0);
   sqlite3_bind_text (stmt, 1, identity.toUri().c_str(), identity.toUri().size(), SQLITE_TRANSIENT);
@@ -533,7 +533,7 @@
   while( sqlite3_step (stmt) == SQLITE_ROW)
     {
       string profileType(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0));
-      Blob profileValue(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 1)), sqlite3_column_bytes (stmt, 1));
+      string profileValue(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 1)), sqlite3_column_bytes (stmt, 1));
       profile->setProfileEntry(profileType, profileValue);
     }
 
@@ -542,30 +542,33 @@
   return profile;
 }
 
-Ptr<Blob>
+Blob
 ContactStorage::getSelfEndorseCertificate(const Name& identity)
 {
   sqlite3_stmt *stmt;
   sqlite3_prepare_v2 (m_db, "SELECT endorse_data FROM SelfEndorse where identity=?", -1, &stmt, 0);
   sqlite3_bind_text(stmt, 1, identity.toUri().c_str(), identity.toUri().size(), SQLITE_TRANSIENT);
 
-  Ptr<Blob> result = NULL;
   if(sqlite3_step (stmt) == SQLITE_ROW)
-    result = Ptr<Blob>(new Blob(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0)));
+    {
+      Blob 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 result;
+  return CHRONOCHAT_NULL_BLOB;
 }
 
 void
-ContactStorage::updateSelfEndorseCertificate(Ptr<EndorseCertificate> newEndorseCertificate, const Name& identity)
+ContactStorage::updateSelfEndorseCertificate(const EndorseCertificate& newEndorseCertificate, const Name& identity)
 {
-  Ptr<Blob> newEndorseCertificateBlob = newEndorseCertificate->encodeToWire();
+  Blob newEndorseCertificateBlob = 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, newEndorseCertificateBlob->buf(), newEndorseCertificateBlob->size(), SQLITE_TRANSIENT);
+  sqlite3_bind_text(stmt, 1, (const char*)newEndorseCertificateBlob.buf(), newEndorseCertificateBlob.size(), SQLITE_TRANSIENT);
   sqlite3_bind_text(stmt, 2, identity.toUri().c_str(), identity.toUri().size(), SQLITE_TRANSIENT);
   sqlite3_step(stmt);
   
@@ -573,43 +576,47 @@
 }
 
 void
-ContactStorage::addSelfEndorseCertificate(Ptr<EndorseCertificate> newEndorseCertificate, const Name& identity)
+ContactStorage::addSelfEndorseCertificate(const EndorseCertificate& newEndorseCertificate, const Name& identity)
 {
-  Ptr<Blob> newEndorseCertificateBlob = newEndorseCertificate->encodeToWire();
+  Blob newEndorseCertificateBlob = 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, newEndorseCertificateBlob->buf(), newEndorseCertificateBlob->size(), SQLITE_TRANSIENT);
+  sqlite3_bind_text(stmt, 2, (const char*)newEndorseCertificateBlob.buf(), newEndorseCertificateBlob.size(), SQLITE_TRANSIENT);
   sqlite3_step(stmt);
 
   sqlite3_finalize (stmt);
 }
 
-Ptr<Blob>
-ContactStorage::getEndorseCertificate(const ndn::Name& identity)
+Blob
+ContactStorage::getEndorseCertificate(const Name& identity)
 {
   sqlite3_stmt *stmt;
   sqlite3_prepare_v2 (m_db, "SELECT endorse_data FROM ProfileEndorse where identity=?", -1, &stmt, 0);
   sqlite3_bind_text(stmt, 1, identity.toUri().c_str(), identity.toUri().size(), SQLITE_TRANSIENT);
 
-  Ptr<Blob> result = NULL;
+  
   if(sqlite3_step (stmt) == SQLITE_ROW)
-    result = Ptr<Blob>(new Blob(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0)));
+    {
+      Blob 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 result;
+  
+  return CHRONOCHAT_NULL_BLOB;
 }
 
 void
-ContactStorage::updateEndorseCertificate(ndn::Ptr<EndorseCertificate> endorseCertificate, const ndn::Name& identity)
+ContactStorage::updateEndorseCertificate(const EndorseCertificate& endorseCertificate, const Name& identity)
 {
-  Ptr<Blob> newEndorseCertificateBlob = endorseCertificate->encodeToWire();
+  Blob newEndorseCertificateBlob = 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, newEndorseCertificateBlob->buf(), newEndorseCertificateBlob->size(), SQLITE_TRANSIENT);
+  sqlite3_bind_text(stmt, 1, (const char*)newEndorseCertificateBlob.buf(), newEndorseCertificateBlob.size(), SQLITE_TRANSIENT);
   sqlite3_bind_text(stmt, 2, identity.toUri().c_str(), identity.toUri().size(), SQLITE_TRANSIENT);
   sqlite3_step(stmt);
 
@@ -617,24 +624,22 @@
 }
 
 void
-ContactStorage::addEndorseCertificate(ndn::Ptr<EndorseCertificate> endorseCertificate, const ndn::Name& identity)
+ContactStorage::addEndorseCertificate(const EndorseCertificate& endorseCertificate, const Name& identity)
 {
-  Ptr<Blob> newEndorseCertificateBlob = endorseCertificate->encodeToWire();
+  Blob newEndorseCertificateBlob = 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, newEndorseCertificateBlob->buf(), newEndorseCertificateBlob->size(), SQLITE_TRANSIENT);
+  sqlite3_bind_text(stmt, 2, (const char*)newEndorseCertificateBlob.buf(), newEndorseCertificateBlob.size(), SQLITE_TRANSIENT);
   sqlite3_step(stmt);
 
   sqlite3_finalize (stmt);
 }
 
-vector<string>
-ContactStorage::getEndorseList(const Name& identity)
+void
+ContactStorage::getEndorseList(const Name& identity, vector<string>& endorseList)
 {
-  vector<string> endorseList;
-
   sqlite3_stmt *stmt;
   sqlite3_prepare_v2 (m_db, "SELECT profile_type FROM ContactProfile WHERE profile_identity=? AND endorse=1 ORDER BY profile_type", -1, &stmt, 0);
   sqlite3_bind_text(stmt, 1, identity.toUri().c_str(), identity.toUri().size(), SQLITE_TRANSIENT);
@@ -645,8 +650,6 @@
       endorseList.push_back(profileType);      
     }
   sqlite3_finalize (stmt);  
-  
-  return endorseList;
 }
 
 void
@@ -680,8 +683,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);
-      Ptr<Blob> blob = endorseCertificate.encodeToWire();
-      sqlite3_bind_text(stmt, 4, blob->buf(), blob->size(), SQLITE_TRANSIENT);
+      Blob blob = endorseCertificate.wireEncode();
+      sqlite3_bind_text(stmt, 4, (const char*)blob.buf(), blob.size(), SQLITE_TRANSIENT);
       int res = sqlite3_step (stmt);
       sqlite3_finalize (stmt); 
       return;
@@ -690,8 +693,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);
-      Ptr<Blob> blob = endorseCertificate.encodeToWire();
-      sqlite3_bind_text(stmt, 2, blob->buf(), blob->size(), SQLITE_TRANSIENT);
+      Blob blob = endorseCertificate.wireEncode();
+      sqlite3_bind_text(stmt, 2, (const char*)blob.buf(), blob.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);
@@ -700,22 +703,18 @@
     }
 }
 
-Ptr<vector<Blob> >
-ContactStorage::getCollectEndorseList(const Name& name)
+void
+ContactStorage::getCollectEndorseList(const Name& name, vector<Blob>& endorseList)
 {
-  Ptr<vector<Blob> > collectEndorseList = Ptr<vector<Blob> >::Create();
-
   sqlite3_stmt *stmt;
   sqlite3_prepare_v2 (m_db, "SELECT endorse_data FROM CollectEndorse WHERE endorsee=?", -1, &stmt, 0);
   sqlite3_bind_text(stmt, 1, name.toUri().c_str(), name.toUri().size(), SQLITE_TRANSIENT);
 
   while(sqlite3_step (stmt) == SQLITE_ROW)
     {
-      Blob blob(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0));
-      collectEndorseList->push_back(blob);
+      Blob blob(reinterpret_cast<const uint8_t*>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0));
+      endorseList.push_back(blob);
     }
 
   sqlite3_finalize (stmt);
-
-  return collectEndorseList;
 }
diff --git a/src/contact-storage.h b/src/contact-storage.h
index 4887dbf..8b7bc6e 100644
--- a/src/contact-storage.h
+++ b/src/contact-storage.h
@@ -14,8 +14,7 @@
 #include <sqlite3.h>
 #include "contact-item.h"
 #include "endorse-certificate.h"
-#include <ndn.cxx/security/identity/identity-manager.h>
-#include <ndn.cxx/fields/signature-sha256-with-rsa.h>
+#include <ndn-cpp/security/identity/identity-manager.hpp>
 
 
 class ContactStorage
@@ -30,7 +29,7 @@
   void
   setSelfProfileEntry(const ndn::Name& identity, const std::string& profileType, const ndn::Blob& profileValue);
 
-  ndn::Ptr<Profile>
+  ndn::ptr_lib::shared_ptr<Profile>
   getSelfProfile(const ndn::Name& identity);
 
   void
@@ -45,47 +44,47 @@
   void 
   updateAlias(const ndn::Name& identity, std::string alias);
 
-  std::vector<ndn::Ptr<ContactItem> >
-  getAllContacts() const;
+  void
+  getAllContacts(std::vector<ndn::ptr_lib::shared_ptr<ContactItem> >& contacts) const;
 
-  ndn::Ptr<ContactItem>
+  ndn::ptr_lib::shared_ptr<ContactItem>
   getContact(const ndn::Name& name);
     
-  ndn::Ptr<Profile>
+  ndn::ptr_lib::shared_ptr<Profile>
   getSelfProfile(const ndn::Name& identity) const;
 
 
   //SelfEndorse
-  ndn::Ptr<ndn::Blob>
+  ndn::Blob
   getSelfEndorseCertificate(const ndn::Name& identity);
 
   void
-  updateSelfEndorseCertificate(ndn::Ptr<EndorseCertificate> endorseCertificate, const ndn::Name& identity);
+  updateSelfEndorseCertificate(const EndorseCertificate& endorseCertificate, const ndn::Name& identity);
 
   void
-  addSelfEndorseCertificate(ndn::Ptr<EndorseCertificate> endorseCertificate, const ndn::Name& identity);
+  addSelfEndorseCertificate(const EndorseCertificate& endorseCertificate, const ndn::Name& identity);
 
 
   //ProfileEndorse
-  ndn::Ptr<ndn::Blob>
+  ndn::Blob
   getEndorseCertificate(const ndn::Name& identity);
 
   void
-  updateEndorseCertificate(ndn::Ptr<EndorseCertificate> endorseCertificate, const ndn::Name& identity);
+  updateEndorseCertificate(const EndorseCertificate& endorseCertificate, const ndn::Name& identity);
 
   void
-  addEndorseCertificate(ndn::Ptr<EndorseCertificate> endorseCertificate, const ndn::Name& identity);
+  addEndorseCertificate(const EndorseCertificate& endorseCertificate, const ndn::Name& identity);
 
-  std::vector<std::string>
-  getEndorseList(const ndn::Name& identity);
+  void
+  getEndorseList(const ndn::Name& identity, std::vector<std::string>& endorseList);
 
   
   //CollectEndorse
   void
   updateCollectEndorse(const EndorseCertificate& endorseCertificate);
 
-  ndn::Ptr<std::vector<ndn::Blob> >
-  getCollectEndorseList(const ndn::Name& name);
+  void
+  getCollectEndorseList(const ndn::Name& name, std::vector<ndn::Blob>& endorseList);
   
 
 private:
diff --git a/src/contactpanel.cpp b/src/contactpanel.cpp
index e9fafaa..f3ad618 100644
--- a/src/contactpanel.cpp
+++ b/src/contactpanel.cpp
@@ -21,25 +21,27 @@
 #include <QtSql/QSqlError>
 
 #ifndef Q_MOC_RUN
-#include <ndn.cxx/security/keychain.h>
-#include <ndn.cxx/security/identity/identity-manager.h>
-#include <ndn.cxx/common.h>
+#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 <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;
 using namespace ndn;
+using namespace ndn::ptr_lib;
 
 using namespace std;
 
 INIT_LOGGER("ContactPanel");
 
-Q_DECLARE_METATYPE(ndn::security::IdentityCertificate)
+Q_DECLARE_METATYPE(ndn::IdentityCertificate)
 Q_DECLARE_METATYPE(ChronosInvitation)
 
 ContactPanel::ContactPanel(QWidget *parent) 
@@ -50,35 +52,38 @@
   , m_startChatDialog(new StartChatDialog)
   , m_invitationDialog(new InvitationDialog)
   , m_settingDialog(new SettingDialog)
+  , m_policyManager(new PanelPolicyManager())
 {
-  qRegisterMetaType<ndn::security::IdentityCertificate>("IdentityCertificate");
+  qRegisterMetaType<IdentityCertificate>("IdentityCertificate");
   qRegisterMetaType<ChronosInvitation>("ChronosInvitation");
   
   createAction();
 
-  m_contactManager = Ptr<ContactManager>::Create();
+  shared_ptr<BasicIdentityStorage> publicStorage = make_shared<BasicIdentityStorage>();
+  shared_ptr<OSXPrivateKeyStorage> privateStorage = make_shared<OSXPrivateKeyStorage>();
+  m_identityManager = make_shared<IdentityManager>(publicStorage, privateStorage);
+
+  m_contactManager = make_shared<ContactManager>(m_identityManager);
 
   connect(&*m_contactManager, SIGNAL(noNdnConnection(const QString&)),
           this, SLOT(showError(const QString&)));
-
-  m_contactManager->setWrapper();
   
   openDB();    
 
   refreshContactList();
 
-  setKeychain();
+  loadTrustAnchor();
 
-  m_defaultIdentity = m_keychain->getDefaultIdentity();
+  m_defaultIdentity = m_identityManager->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_keychain->getIdentityManager()->getDefaultCertificateNameByIdentity(m_defaultIdentity);
+  Name defaultCertName = m_identityManager->getDefaultCertificateNameForIdentity(m_defaultIdentity);
   if(defaultCertName.size() == 0)
     showError(QString::fromStdString("certificate of ") + QString::fromStdString(m_defaultIdentity.toUri()) + " is missing!\nHave you installed the certificate?");
 
 
   m_contactManager->setDefaultIdentity(m_defaultIdentity);
-  m_nickName = m_defaultIdentity.get(-1).toUri();
+  m_nickName = m_defaultIdentity.get(-1).toEscapedString();
   m_settingDialog->setIdentity(m_defaultIdentity.toUri(), m_nickName);
   
 
@@ -91,11 +96,10 @@
  
   ui->setupUi(this);
 
-  try{
-    m_handler = Ptr<Wrapper>(new Wrapper(m_keychain));  
-  }catch(ndn::Error::ndnOperation& e){
-    showError(QString::fromStdString("Cannot conect to ndnd!\n Have you started your ndnd?"));
-  }
+  m_transport = make_shared<TcpTransport>();
+  m_face = make_shared<Face>(m_transport, make_shared<TcpTransport::ConnectionInfo>("localhost"));
+  
+  connectToDaemon();
   
   m_localPrefix = Name("/private/local");
   setLocalPrefix();
@@ -144,8 +148,8 @@
   connect(m_startChatDialog, SIGNAL(chatroomConfirmed(const QString&, const QString&, bool)),
           this, SLOT(startChatroom(const QString&, const QString&, bool)));
 
-  connect(m_invitationDialog, SIGNAL(invitationAccepted(const ChronosInvitation&, const ndn::security::IdentityCertificate&)),
-          this, SLOT(acceptInvitation(const ChronosInvitation&, const ndn::security::IdentityCertificate&)));
+  connect(m_invitationDialog, SIGNAL(invitationAccepted(const ChronosInvitation&, const ndn::IdentityCertificate&)),
+          this, SLOT(acceptInvitation(const ChronosInvitation&, const ndn::IdentityCertificate&)));
   connect(m_invitationDialog, SIGNAL(invitationRejected(const ChronosInvitation&)),
           this, SLOT(rejectInvitation(const ChronosInvitation&)));
   
@@ -200,6 +204,26 @@
 }
 
 void
+ContactPanel::connectToDaemon()
+{
+  //Hack! transport does not connect to daemon unless an interest is expressed.
+  Name name("/ndn");
+  ndn::Interest interest(name);
+  m_face->expressInterest(interest, 
+                          bind(&ContactPanel::onConnectionData, this, _1, _2),
+                          bind(&ContactPanel::onConnectionDataTimeout, this, _1));
+}
+
+void
+ContactPanel::onConnectionData(const shared_ptr<const ndn::Interest>& interest,
+                               const shared_ptr<Data>& data)
+{ _LOG_DEBUG("onConnectionData"); }
+
+void
+ContactPanel::onConnectionDataTimeout(const shared_ptr<const ndn::Interest>& interest)
+{ _LOG_DEBUG("onConnectionDataTimeout"); }
+
+void
 ContactPanel::createAction()
 {
   m_menuInvite = new QAction("&Chat", this);
@@ -222,46 +246,33 @@
 }
 
 void 
-ContactPanel::setKeychain()
+ContactPanel::loadTrustAnchor()
 {
-  m_panelPolicyManager = Ptr<PanelPolicyManager>::Create();
-
-  vector<Ptr<ContactItem> >::const_iterator it = m_contactList.begin();
+  vector<shared_ptr<ContactItem> >::const_iterator it = m_contactList.begin();
   for(; it != m_contactList.end(); it++)
     {
-      m_panelPolicyManager->addTrustAnchor((*it)->getSelfEndorseCertificate());
+      m_policyManager->addTrustAnchor((*it)->getSelfEndorseCertificate());
     }
-
-  m_keychain = Ptr<security::Keychain>(new security::Keychain(Ptr<security::IdentityManager>::Create(), 
-                                                              m_panelPolicyManager, 
-                                                              NULL));
 }
 
 void
 ContactPanel::setLocalPrefix(int retry)
 {
-  Ptr<Interest> interest = Ptr<Interest>(new Interest(Name("/local/ndn/prefix")));
-  interest->setChildSelector(Interest::CHILD_RIGHT);
-  
-  Ptr<Closure> closure = Ptr<Closure>(new Closure(boost::bind(&ContactPanel::onLocalPrefixVerified, 
-                                                              this,
-                                                              _1),
-                                                  boost::bind(&ContactPanel::onLocalPrefixTimeout,
-                                                              this,
-                                                              _1, 
-                                                              _2,
-                                                              10),
-                                                  boost::bind(&ContactPanel::onLocalPrefixVerified,
-                                                              this,
-                                                              _1)));
+  Name interestName("/local/ndn/prefix");
+  Interest interest(interestName);
+  interest.setChildSelector(ndn_Interest_CHILD_SELECTOR_RIGHT);
 
-  m_handler->sendInterest(interest, closure);
+  m_face->expressInterest(interest, 
+                          bind(&ContactPanel::onLocalPrefix, this, _1, _2), 
+                          bind(&ContactPanel::onLocalPrefixTimeout, this, _1, 10));
+  
 }
 
 void
-ContactPanel::onLocalPrefixVerified(Ptr<Data> data)
+ContactPanel::onLocalPrefix(const shared_ptr<const Interest>& interest, 
+                            const shared_ptr<Data>& data)
 {
-  string originPrefix(data->content().buf(), data->content().size());
+  string originPrefix((const char*)data->getContent().buf(), data->getContent().size());
   string prefix = QString::fromStdString (originPrefix).trimmed ().toUtf8().constData();
   string randomSuffix = getRandomString();
   m_localPrefix = Name(prefix);
@@ -269,7 +280,8 @@
 }
 
 void
-ContactPanel::onLocalPrefixTimeout(Ptr<Closure> closure, Ptr<Interest> interest, int retry)
+ContactPanel::onLocalPrefixTimeout(const shared_ptr<const Interest>& interest,
+                                   int retry)
 { 
   if(retry > 0)
     {
@@ -287,21 +299,131 @@
   m_inviteListenPrefix = Name("/ndn/broadcast/chronos/invitation");
   m_inviteListenPrefix.append(m_defaultIdentity);
   _LOG_DEBUG("Listening for invitation on prefix: " << m_inviteListenPrefix.toUri());
-  m_handler->setInterestFilter (m_inviteListenPrefix, 
-                                boost::bind(&ContactPanel::onInvitation, 
-                                            this,
-                                            _1));
+  m_invitationListenerId = m_face->registerPrefix(m_inviteListenPrefix, 
+                                                  boost::bind(&ContactPanel::onInvitation, this, _1, _2, _3, _4),
+                                                  boost::bind(&ContactPanel::onInvitationRegisterFailed, this, _1));
 }
 
 void
-ContactPanel::onInvitation(Ptr<Interest> interest)
+ContactPanel::sendInterest(const Interest& interest,
+                           const OnVerified& onVerified,
+                           const OnVerifyFailed& onVerifyFailed,
+                           const TimeoutNotify& timeoutNotify,
+                           int retry /* = 1 */,
+                           int stepCount /* = 0 */)
+{
+  m_face->expressInterest(interest, 
+                          boost::bind(&ContactPanel::onTargetData, 
+                                      this,
+                                      _1,
+                                      _2,
+                                      stepCount,
+                                      onVerified, 
+                                      onVerifyFailed,
+                                      timeoutNotify),
+                          boost::bind(&ContactPanel::onTargetTimeout,
+                                      this,
+                                      _1,
+                                      retry,
+                                      stepCount,
+                                      onVerified,
+                                      onVerifyFailed,
+                                      timeoutNotify));
+}
+
+void
+ContactPanel::onTargetData(const shared_ptr<const ndn::Interest>& interest, 
+                           const shared_ptr<Data>& data,
+                           int stepCount,
+                           const OnVerified& onVerified,
+                           const OnVerifyFailed& onVerifyFailed,
+                           const TimeoutNotify& timeoutNotify)
+{
+  shared_ptr<ValidationRequest> nextStep = m_policyManager->checkVerificationPolicy(data, stepCount, onVerified, onVerifyFailed);
+
+  if (nextStep)
+    m_face->expressInterest
+      (*nextStep->interest_, 
+       bind(&ContactPanel::onCertData, this, _1, _2, nextStep), 
+       bind(&ContactPanel::onCertTimeout, this, _1, onVerifyFailed, data, nextStep));
+
+}
+
+void
+ContactPanel::onTargetTimeout(const shared_ptr<const ndn::Interest>& interest, 
+                              int retry,
+                              int stepCount,
+                              const OnVerified& onVerified,
+                              const OnVerifyFailed& onVerifyFailed,
+                              const TimeoutNotify& timeoutNotify)
+{
+  if(retry > 0)
+    sendInterest(*interest, onVerified, onVerifyFailed, timeoutNotify, retry-1, stepCount);
+  else
+    {
+      _LOG_DEBUG("Interest: " << interest->getName().toUri() << " eventually times out!");
+      timeoutNotify();
+    }
+}
+
+void
+ContactPanel::onCertData(const shared_ptr<const ndn::Interest>& interest, 
+                         const shared_ptr<Data>& cert,
+                         shared_ptr<ValidationRequest> previousStep)
+{
+  shared_ptr<ValidationRequest> nextStep = m_policyManager->checkVerificationPolicy(cert, 
+                                                                                    previousStep->stepCount_, 
+                                                                                    previousStep->onVerified_, 
+                                                                                    previousStep->onVerifyFailed_);
+
+  if (nextStep)
+    m_face->expressInterest
+      (*nextStep->interest_, 
+       bind(&ContactPanel::onCertData, this, _1, _2, nextStep), 
+       bind(&ContactPanel::onCertTimeout, this, _1, previousStep->onVerifyFailed_, cert, nextStep));
+}
+
+void
+ContactPanel::onCertTimeout(const shared_ptr<const ndn::Interest>& interest,
+                            const OnVerifyFailed& onVerifyFailed,
+                            const shared_ptr<Data>& data,
+                            shared_ptr<ValidationRequest> nextStep)
+{
+  if(nextStep->retry_ > 0)
+    m_face->expressInterest(*interest, 
+                            bind(&ContactPanel::onCertData,
+                                 this,
+                                 _1,
+                                 _2,
+                                 nextStep),
+                            bind(&ContactPanel::onCertTimeout,
+                                 this,
+                                 _1,
+                                 onVerifyFailed,
+                                 data,
+                                 nextStep));
+ else
+   onVerifyFailed(data);
+}
+
+void
+ContactPanel::onInvitationRegisterFailed(const shared_ptr<const Name>& prefix)
+{
+  showError(QString::fromStdString("Cannot register invitation listening prefix"));
+}
+
+void
+ContactPanel::onInvitation(const shared_ptr<const Name>& prefix, 
+                           const shared_ptr<const Interest>& interest, 
+                           Transport& transport, 
+                           uint64_t registeredPrefixId)
 {
   _LOG_DEBUG("Receive invitation!" << interest->getName().toUri());
   
-  Ptr<ChronosInvitation> invitation = NULL;
+  shared_ptr<ChronosInvitation> invitation;
   try{
-    invitation = Ptr<ChronosInvitation>(new ChronosInvitation(interest->getName()));
-  }catch(exception& e){
+    invitation = make_shared<ChronosInvitation>(interest->getName());
+  }catch(std::exception& e){
     _LOG_ERROR("Exception: " << e.what());
     return;
   }
@@ -315,14 +437,14 @@
       return;
     }
 
-  Ptr<security::Publickey> keyPtr = m_panelPolicyManager->getTrustedKey(invitation->getInviterCertificateName());
-  if(NULL != keyPtr && security::PolicyManager::verifySignature(invitation->getSignedBlob(), invitation->getSignatureBits(), *keyPtr))
+  shared_ptr<PublicKey> keyPtr = m_policyManager->getTrustedKey(invitation->getInviterCertificateName());
+  if(CHRONOCHAT_NULL_PUBLICKEY_PTR != keyPtr && Sha256WithRsaHandler::verifySignature(invitation->getSignedBlob(), invitation->getSignatureBits(), *keyPtr))
     {
-      Ptr<security::IdentityCertificate> certificate = Ptr<security::IdentityCertificate>::Create();
+      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
       certificate->setName(invitation->getInviterCertificateName());
       bool findCert = false;
-      vector<Ptr<ContactItem> >::const_iterator it = m_contactList.begin();
+      vector<shared_ptr<ContactItem> >::const_iterator it = m_contactList.begin();
       for(; it != m_contactList.end(); it++)
         {
           if((*it)->getNameSpace() == invitation->getInviterNameSpace())
@@ -343,51 +465,43 @@
       return;
     }
 
-  Ptr<Interest> newInterest = Ptr<Interest>(new Interest(invitation->getInviterCertificateName()));
-  Ptr<Closure> closure = Ptr<Closure>(new Closure(boost::bind(&ContactPanel::onInvitationCertVerified, 
-                                                              this,
-                                                              _1,
-                                                              invitation),
-                                                  boost::bind(&ContactPanel::onTimeout,
-                                                              this,
-                                                              _1,
-                                                              _2),
-                                                  boost::bind(&ContactPanel::onUnverified,
-                                                              this,
-                                                              _1)));
-  m_handler->sendInterest(newInterest, closure);
+  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);
+
+  sendInterest(newInterest, onVerified, onVerifyFailed, timeoutNotify);
 }
 
 void
-ContactPanel::onInvitationCertVerified(Ptr<Data> data, 
-                                       Ptr<ChronosInvitation> invitation)
+ContactPanel::onInvitationCertVerified(const shared_ptr<Data>& data, 
+                                       shared_ptr<ChronosInvitation> invitation)
 {
-  using namespace ndn::security;
-  Ptr<IdentityCertificate> certificate = Ptr<IdentityCertificate>(new IdentityCertificate(*data));
+  shared_ptr<IdentityCertificate> certificate = make_shared<IdentityCertificate>(*data);
   
-  if(PolicyManager::verifySignature(invitation->getSignedBlob(), invitation->getSignatureBits(), certificate->getPublicKeyInfo()))
+  if(Sha256WithRsaHandler::verifySignature(invitation->getSignedBlob(), invitation->getSignatureBits(), certificate->getPublicKeyInfo()))
     {
       Name keyName = certificate->getPublicKeyName();
-      Name inviterNameSpace = keyName.getPrefix(keyName.size() - 1);
+      Name inviterNameSpace = keyName.getPrefix(-1);
       popChatInvitation(invitation, inviterNameSpace, certificate);
     }
 }
 
 void
-ContactPanel::onUnverified(Ptr<Data> data)
-{}
+ContactPanel::onInvitationCertVerifyFailed(const shared_ptr<Data>& data)
+{ _LOG_DEBUG("Cannot verify invitation certificate!"); }
 
 void
-ContactPanel::onTimeout(Ptr<Closure> closure, Ptr<Interest> interest)
-{}
+ContactPanel::onInvitationCertTimeoutNotify()
+{ _LOG_DEBUG("interest for invitation certificate times out eventually!"); }
 
 void
-ContactPanel::popChatInvitation(Ptr<ChronosInvitation> invitation,
+ContactPanel::popChatInvitation(shared_ptr<ChronosInvitation> invitation,
                                 const Name& inviterNameSpace,
-                                Ptr<security::IdentityCertificate> certificate)
+                                shared_ptr<IdentityCertificate> certificate)
 {
   string alias;
-  vector<Ptr<ContactItem> >::iterator it = m_contactList.begin();
+  vector<shared_ptr<ContactItem> >::iterator it = m_contactList.begin();
   for(; it != m_contactList.end(); it++)
     if((*it)->getNameSpace() == inviterNameSpace)
       alias = (*it)->getAlias();
@@ -402,43 +516,33 @@
 void
 ContactPanel::collectEndorsement()
 {
-  m_collectStatus = Ptr<vector<bool> >::Create();
+  m_collectStatus = make_shared<vector<bool> >();
   m_collectStatus->assign(m_contactList.size(), false);
 
-  vector<Ptr<ContactItem> >::iterator it = m_contactList.begin();
+  vector<shared_ptr<ContactItem> >::iterator it = m_contactList.begin();
   int count = 0;
   for(; it != m_contactList.end(); it++, count++)
     {
       Name interestName = (*it)->getNameSpace();
       interestName.append("DNS").append(m_defaultIdentity).append("ENDORSEE");
-      Ptr<Interest> interest = Ptr<Interest>(new Interest(interestName));
-      interest->setChildSelector(Interest::CHILD_RIGHT);
-      interest->setInterestLifetime(1);
-  
-      Ptr<Closure> closure = Ptr<Closure>(new Closure(boost::bind(&ContactPanel::onDnsEndorseeVerified, 
-                                                                  this,
-                                                                  _1,
-                                                                  count),
-                                                      boost::bind(&ContactPanel::onDnsEndorseeTimeout,
-                                                                  this,
-                                                                  _1, 
-                                                                  _2,
-                                                                  count),
-                                                      boost::bind(&ContactPanel::onDnsEndorseeUnverified,
-                                                                  this,
-                                                                  _1,
-                                                                  count)));
+      Interest interest(interestName);
+      interest.setChildSelector(ndn_Interest_CHILD_SELECTOR_RIGHT);
+      interest.setInterestLifetimeMilliseconds(1000);
 
-      m_handler->sendInterest(interest, closure);
+      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);
+  
+      sendInterest(interest, onVerified, onVerifyFailed, timeoutNotify, 0);
     }
 }
 
 void
-ContactPanel::onDnsEndorseeVerified(Ptr<Data> data, int count)
+ContactPanel::onDnsEndorseeVerified(const shared_ptr<Data>& data, int count)
 {
-  Ptr<Blob> contentBlob = Ptr<Blob>(new Blob(data->content().buf(), data->content().size()));
-  Ptr<Data> endorseData = Data::decodeFromWire(contentBlob);
-  EndorseCertificate endorseCertificate(*endorseData);
+  Data endorseData;
+  endorseData.wireDecode(data->getContent().buf(), data->getContent().size());
+  EndorseCertificate endorseCertificate(endorseData);
 
   m_contactManager->getContactStorage()->updateCollectEndorse(endorseCertificate);
 
@@ -446,11 +550,11 @@
 }
 
 void
-ContactPanel::onDnsEndorseeTimeout(Ptr<Closure> closure, Ptr<Interest> interest, int count)
+ContactPanel::onDnsEndorseeTimeoutNotify(int count)
 { updateCollectStatus(count); }
 
 void
-ContactPanel::onDnsEndorseeUnverified(Ptr<Data> data, int count)
+ContactPanel::onDnsEndorseeVerifyFailed(const shared_ptr<Data>& data, int count)
 { updateCollectStatus(count); }
 
 void 
@@ -585,13 +689,7 @@
 { 
   // _LOG_DEBUG(identity.toStdString());
   Name defaultIdentity = Name(identity.toStdString());
-  Name defaultKeyName = m_keychain->getIdentityManager()->getPublicStorage()->getDefaultKeyNameForIdentity(defaultIdentity);
-  if(defaultKeyName.size() == 0)
-    {
-      showWarning(QString::fromStdString("Corresponding key is missing!\nHave you created the key?"));
-      return;
-    }
-  Name defaultCertName = m_keychain->getIdentityManager()->getPublicStorage()->getDefaultCertificateNameForKey(defaultKeyName);
+  Name defaultCertName = m_identityManager->getDefaultCertificateNameForIdentity(defaultIdentity);
   if(defaultCertName.size() == 0)
     {
       showWarning(QString::fromStdString("Corresponding certificate is missing!\nHave you installed the certificate?"));
@@ -600,7 +698,7 @@
   m_defaultIdentity = defaultIdentity;
   m_profileEditor->setCurrentIdentity(m_defaultIdentity);
   m_nickName = nickName.toStdString();
-  m_handler->clearInterestFilter(m_inviteListenPrefix);
+  m_face->removeRegisteredPrefix(m_invitationListenerId);
   m_contactManager->setDefaultIdentity(m_defaultIdentity);
   setInvitationListener();
   collectEndorsement();
@@ -630,7 +728,7 @@
   for(; it != selectedList.end(); it++)
     {
       string alias =  m_contactListModel->data(*it, Qt::DisplayRole).toString().toStdString();
-      vector<Ptr<ContactItem> >::iterator contactIt = m_contactList.begin();
+      vector<shared_ptr<ContactItem> >::iterator contactIt = m_contactList.begin();
       for(; contactIt != m_contactList.end(); contactIt++)
         {
           if((*contactIt)->getAlias() == alias)
@@ -651,19 +749,20 @@
 void
 ContactPanel::addContactIntoPanelPolicy(const Name& contactNameSpace)
 {
-  Ptr<ContactItem> contact = m_contactManager->getContact(contactNameSpace);
-  if(contact != NULL)
-    m_panelPolicyManager->addTrustAnchor(contact->getSelfEndorseCertificate());
+  shared_ptr<ContactItem> contact = m_contactManager->getContact(contactNameSpace);
+  if(contact != CHRONOCHAT_NULL_CONTACTITEM_PTR)
+    m_policyManager->addTrustAnchor(contact->getSelfEndorseCertificate());
 }
 
 void
 ContactPanel::removeContactFromPanelPolicy(const Name& keyName)
-{ m_panelPolicyManager->removeTrustAnchor(keyName); }
+{ m_policyManager->removeTrustAnchor(keyName); }
 
 void
 ContactPanel::refreshContactList()
 {
-  m_contactList = m_contactManager->getContactItemList();
+  m_contactList.clear();
+  m_contactManager->getContactItemList(m_contactList);
   QStringList contactNameList;
   for(int i = 0; i < m_contactList.size(); i++)
     contactNameList << QString::fromStdString(m_contactList[i]->getAlias());
@@ -714,10 +813,10 @@
 void
 ContactPanel::startChatroom(const QString& chatroom, const QString& invitee, bool isIntroducer)
 {
-  Name chatroomName(chatroom.toUtf8().constData());
+  Name chatroomName(chatroom.toStdString());
 
   Name inviteeNamespace(invitee.toStdString());
-  Ptr<ContactItem> inviteeItem = m_contactManager->getContact(inviteeNamespace);
+  shared_ptr<ContactItem> inviteeItem = m_contactManager->getContact(inviteeNamespace);
 
   ChatDialog* chatDialog = new ChatDialog(m_contactManager, chatroomName, m_localPrefix, m_defaultIdentity, m_nickName);
   m_chatDialogs.insert(pair <Name, ChatDialog*> (chatroomName, chatDialog));
@@ -738,9 +837,9 @@
 // For Invitee
 void
 ContactPanel::startChatroom2(const ChronosInvitation& invitation, 
-                             const security::IdentityCertificate& identityCertificate)
+                             const IdentityCertificate& identityCertificate)
 {
-  Ptr<ContactItem> inviterItem = m_contactManager->getContact(invitation.getInviterNameSpace());
+  shared_ptr<ContactItem> inviterItem = m_contactManager->getContact(invitation.getInviterNameSpace());
 
   Name chatroomName("/ndn/broadcast/chronos");
   chatroomName.append(invitation.getChatroom());
@@ -766,18 +865,44 @@
 
 void
 ContactPanel::acceptInvitation(const ChronosInvitation& invitation, 
-                               const security::IdentityCertificate& identityCertificate)
+                               const IdentityCertificate& identityCertificate)
 {
-  string prefix = m_localPrefix.toUri();
-  m_handler->publishDataByIdentity (invitation.getInterestName(), prefix);
+  Data data(invitation.getInterestName());
+  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();
+  else
+    certificateName = m_identityManager->getDefaultCertificateNameForIdentity(inferredIdentity);   
+  m_identityManager->signByCertificate(data, certificateName);
+
+  m_transport->send(*data.wireEncode());
+
   startChatroom2(invitation, identityCertificate);
 }
 
 void
 ContactPanel::rejectInvitation(const ChronosInvitation& invitation)
 {
-  string empty("nack");
-  m_handler->publishDataByIdentity (invitation.getInterestName(), empty);
+  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();
+  else
+    certificateName = m_identityManager->getDefaultCertificateNameForIdentity(inferredIdentity);   
+  m_identityManager->signByCertificate(data, certificateName);
+
+  m_transport->send(*data.wireEncode());
 }
 
 void
@@ -842,7 +967,7 @@
   QSqlRecord record;
   QSqlField identityField("contact_namespace", QVariant::String);
   record.append(identityField);
-  record.setValue("contact_namespace", QString(m_currentSelectedContact->getNameSpace().toUri().c_str()));
+  record.setValue("contact_namespace", QString::fromStdString(m_currentSelectedContact->getNameSpace().toUri()));
   m_trustScopeModel->insertRow(rowCount);
   m_trustScopeModel->setRecord(rowCount, record);
 }
diff --git a/src/contactpanel.h b/src/contactpanel.h
index b171e54..1c2c9fc 100644
--- a/src/contactpanel.h
+++ b/src/contactpanel.h
@@ -49,6 +49,16 @@
   ~ContactPanel();
 
 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);
+
   void
   createAction();
 
@@ -56,54 +66,93 @@
   openDB();
 
   void
-  setKeychain();
+  loadTrustAnchor();
 
   void
   setLocalPrefix(int retry = 10);
 
   void
-  onLocalPrefixVerified(ndn::Ptr<ndn::Data> data);
+  onLocalPrefix(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, 
+                const ndn::ptr_lib::shared_ptr<ndn::Data>& data);
   
   void
-  onLocalPrefixTimeout(ndn::Ptr<ndn::Closure> closure, 
-                       ndn::Ptr<ndn::Interest> interest,
+  onLocalPrefixTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
                        int retry);
 
   void
   setInvitationListener();
 
   void
-  onInvitation(ndn::Ptr<ndn::Interest> interest);
+  onInvitation(const ndn::ptr_lib::shared_ptr<const ndn::Name>& prefix, 
+               const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, 
+               ndn::Transport& transport, 
+               uint64_t registeredPrefixI);
 
   void
-  onUnverified(ndn::Ptr<ndn::Data> data);
-  
+  onInvitationRegisterFailed(const ndn::ptr_lib::shared_ptr<const ndn::Name>& prefix);
+
   void
-  onTimeout(ndn::Ptr<ndn::Closure> closure, 
-            ndn::Ptr<ndn::Interest> interest);
+  sendInterest(const ndn::Interest& interest,
+               const ndn::OnVerified& onVerified,
+               const ndn::OnVerifyFailed& onVerifyFailed,
+               const TimeoutNotify& timeoutNotify,
+               int retry = 1,
+               int stepCount = 0);
+
+  void
+  onTargetData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, 
+               const ndn::ptr_lib::shared_ptr<ndn::Data>& data,
+               int stepCount,
+               const ndn::OnVerified& onVerified,
+               const ndn::OnVerifyFailed& onVerifyFailed,
+               const TimeoutNotify& timeoutNotify);
+
+  void
+  onTargetTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, 
+                  int retry,
+                  int stepCount,
+                  const ndn::OnVerified& onVerified,
+                  const ndn::OnVerifyFailed& onVerifyFailed,
+                  const TimeoutNotify& timeoutNotify);
+
+
+  void
+  onCertData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, 
+             const ndn::ptr_lib::shared_ptr<ndn::Data>& cert,
+             ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> previousStep);
+
+  void
+  onCertTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
+                const ndn::OnVerifyFailed& onVerifyFailed,
+                const ndn::ptr_lib::shared_ptr<ndn::Data>& data,
+                ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> nextStep);
     
   void
-  onInvitationCertVerified(ndn::Ptr<ndn::Data> data,
-                           ndn::Ptr<ChronosInvitation> invitation);
+  onInvitationCertVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, 
+                           ndn::ptr_lib::shared_ptr<ChronosInvitation> invitation);
 
   void
-  popChatInvitation(ndn::Ptr<ChronosInvitation> invitation,
+  onInvitationCertVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data);
+
+  void
+  onInvitationCertTimeoutNotify();
+
+  void
+  popChatInvitation(ndn::ptr_lib::shared_ptr<ChronosInvitation> invitation,
                     const ndn::Name& inviterNameSpace,
-                    ndn::Ptr<ndn::security::IdentityCertificate> certificate);
+                    ndn::ptr_lib::shared_ptr<ndn::IdentityCertificate> certificate);
 
   void
   collectEndorsement();
 
   void
-  onDnsEndorseeVerified(ndn::Ptr<ndn::Data> data, int count);
+  onDnsEndorseeVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, int count);
 
   void
-  onDnsEndorseeTimeout(ndn::Ptr<ndn::Closure> closure, 
-                       ndn::Ptr<ndn::Interest> interest, 
-                       int count);
-  
+  onDnsEndorseeVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, int count);
+
   void
-  onDnsEndorseeUnverified(ndn::Ptr<ndn::Data> data, int count);
+  onDnsEndorseeTimeoutNotify(int count);
 
   void 
   updateCollectStatus(int count);
@@ -170,11 +219,11 @@
 
   void 
   startChatroom2(const ChronosInvitation& invitation, 
-                 const ndn::security::IdentityCertificate& identityCertificate);
+                 const ndn::IdentityCertificate& identityCertificate);
 
   void
   acceptInvitation(const ChronosInvitation& invitation, 
-                   const ndn::security::IdentityCertificate& identityCertificate);
+                   const ndn::IdentityCertificate& identityCertificate);
 
   void
   rejectInvitation(const ChronosInvitation& invitation);
@@ -207,7 +256,7 @@
 private:
   Ui::ContactPanel *ui;
   WarningDialog* m_warningDialog;
-  ndn::Ptr<ContactManager> m_contactManager;
+  ndn::ptr_lib::shared_ptr<ContactManager> m_contactManager;
   QStringListModel* m_contactListModel;
   ProfileEditor* m_profileEditor;
   AddContactPanel* m_addContactPanel;
@@ -216,22 +265,24 @@
   StartChatDialog* m_startChatDialog;
   InvitationDialog* m_invitationDialog;
   SettingDialog* m_settingDialog;
-  std::map<ndn::Name, ChatDialog*> m_chatDialogs;
+  std::map<ndn::Name, ChatDialog*, ndn::Name::BreadthFirstLess> m_chatDialogs;
   QAction* m_menuInvite;
   QAction* m_menuAlias;
-  std::vector<ndn::Ptr<ContactItem> > m_contactList;
-  ndn::Ptr<std::vector<bool> > m_collectStatus;
+  std::vector<ndn::ptr_lib::shared_ptr<ContactItem> > m_contactList;
+  ndn::ptr_lib::shared_ptr<std::vector<bool> > m_collectStatus;
 
-  ndn::Ptr<PanelPolicyManager> m_panelPolicyManager;
-  ndn::Ptr<ndn::security::Keychain> m_keychain;
-  ndn::Ptr<ndn::Wrapper> m_handler;
+  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::Face> m_face;
+  uint64_t m_invitationListenerId;
 
   ndn::Name m_defaultIdentity;
   std::string m_nickName;
   ndn::Name m_localPrefix;
   ndn::Name m_inviteListenPrefix;
 
-  ndn::Ptr<ContactItem> m_currentSelectedContact;
+  ndn::ptr_lib::shared_ptr<ContactItem> m_currentSelectedContact;
   QSqlTableModel* m_trustScopeModel;
   QSqlTableModel* m_endorseDataModel;
   EndorseComboBoxDelegate* m_endorseComboBoxDelegate;
diff --git a/src/dns-storage.cpp b/src/dns-storage.cpp
index 52a23b2..a5a9588 100644
--- a/src/dns-storage.cpp
+++ b/src/dns-storage.cpp
@@ -9,6 +9,7 @@
  */
 
 #include "dns-storage.h"
+#include "null-ptrs.h"
 #include "exception.h"
 
 #include <boost/filesystem.hpp>
@@ -17,6 +18,7 @@
 
 using namespace std;
 using namespace ndn;
+using namespace ndn::ptr_lib;
 namespace fs = boost::filesystem;
 
 INIT_LOGGER("DnsStorage");
@@ -85,7 +87,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, data.buf(), data.size(), SQLITE_TRANSIENT); 
+      sqlite3_bind_text(stmt, 4, (const char*)data.buf(), data.size(), SQLITE_TRANSIENT); 
       sqlite3_bind_text(stmt, 5, dataName.c_str(), dataName.size(), SQLITE_TRANSIENT);
       sqlite3_step(stmt);
       sqlite3_finalize(stmt);
@@ -94,7 +96,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, data.buf(), data.size(), SQLITE_TRANSIENT);
+      sqlite3_bind_text(stmt, 1, (const char*)data.buf(), 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);
@@ -110,9 +112,9 @@
   string dnsIdentity = identity.toUri();
   string dnsName("N/A");
   string dnsType("PROFILE");
-  Ptr<Blob> dnsValue = data.encodeToWire();
+  Blob dnsValue = data.wireEncode();
 
-  updateDnsData(*dnsValue, dnsIdentity, dnsName, dnsType, data.getName().toUri());
+  updateDnsData(dnsValue, dnsIdentity, dnsName, dnsType, data.getName().toUri());
 }
 
 void
@@ -121,9 +123,9 @@
   string dnsIdentity = identity.toUri();
   string dnsName = endorsee.toUri();
   string dnsType("ENDORSEE");
-  Ptr<Blob> dnsValue = data.encodeToWire();
+  Blob dnsValue = data.wireEncode();
 
-  updateDnsData(*dnsValue, dnsIdentity, dnsName, dnsType, data.getName().toUri());
+  updateDnsData(dnsValue, dnsIdentity, dnsName, dnsType, data.getName().toUri());
 }
   
 void
@@ -132,12 +134,12 @@
   string dnsIdentity = identity.toUri();
   string dnsName("N/A");
   string dnsType("ENDORSED");
-  Ptr<Blob> dnsValue = data.encodeToWire();
+  Blob dnsValue = data.wireEncode();
 
-  updateDnsData(*dnsValue, dnsIdentity, dnsName, dnsType, data.getName().toUri());
+  updateDnsData(dnsValue, dnsIdentity, dnsName, dnsType, data.getName().toUri());
 }
 
-Ptr<Data>
+shared_ptr<Data>
 DnsStorage::getData(const Name& dataName)
 {
   sqlite3_stmt *stmt;
@@ -146,13 +148,12 @@
   
   if(sqlite3_step (stmt) == SQLITE_ROW)
     {
-      Ptr<Blob> dnsDataBlob = Ptr<Blob>(new Blob(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0)));
-      // boost::iostreams::stream
-      //   <boost::iostreams::array_source> is (dnsDataBlob.buf(), dnsDataBlob.size());
+      shared_ptr<Data> data = make_shared<Data>();
+      data->wireDecode(reinterpret_cast<const uint8_t*>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0));
       sqlite3_finalize(stmt);
-      return Data::decodeFromWire(dnsDataBlob);
+      return data;
     }
   sqlite3_finalize(stmt);
 
-  return NULL;
+  return CHRONOCHAT_NULL_DATA_PTR;
 }
diff --git a/src/dns-storage.h b/src/dns-storage.h
index f6c19ce..0c7934b 100644
--- a/src/dns-storage.h
+++ b/src/dns-storage.h
@@ -12,7 +12,7 @@
 #define LINKNDN_DNS_STORAGE_H
 
 #include <sqlite3.h>
-#include <ndn.cxx/data.h>
+#include <ndn-cpp/data.hpp>
 
 class DnsStorage
 {
@@ -30,7 +30,7 @@
   void
   updateDnsOthersEndorse(const ndn::Data& data, const ndn::Name& identity);
 
-  ndn::Ptr<ndn::Data>
+  ndn::ptr_lib::shared_ptr<ndn::Data>
   getData(const ndn::Name& name);
 
 private:
diff --git a/src/endorse-certificate.cpp b/src/endorse-certificate.cpp
index 80ff165..8101eb3 100644
--- a/src/endorse-certificate.cpp
+++ b/src/endorse-certificate.cpp
@@ -10,93 +10,91 @@
 
 #include "endorse-certificate.h"
 #include "exception.h"
-#include <ndn.cxx/helpers/der/der.h>
-#include <ndn.cxx/helpers/der/visitor/simple-visitor.h>
-#include <ndn.cxx/security/certificate/certificate-subdescrpt.h>
+#include "endorse-extension.pb.h"
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/iostreams/stream.hpp>
 #include "logging.h"
 
 using namespace std;
 using namespace ndn;
-using namespace ndn::security;
+using namespace ndn::ptr_lib;
+using namespace boost::posix_time;
 
 INIT_LOGGER("EndorseCertificate");
 
 ProfileExtension::ProfileExtension(const ProfileData & profileData)
-  : CertificateExtension("1.3.6.1.5.32.2.1", true, *profileData.encodeToWire())
+  : CertificateExtension("1.3.6.1.5.32.2.1", true, profileData.wireEncode())
 {}
 
 ProfileExtension::ProfileExtension(const ProfileExtension& profileExtension)
-  : CertificateExtension("1.3.6.1.5.32.2.1", true, profileExtension.m_extnValue)
+  : CertificateExtension("1.3.6.1.5.32.2.1", true, profileExtension.extensionValue_)
 {}
 
 ProfileExtension::ProfileExtension(const CertificateExtension& extension)
-  : CertificateExtension(extension.getOID(), extension.getCritical(), extension.getValue())
+  : CertificateExtension(extension.getOid(), extension.getIsCritical(), extension.getValue())
 {
-  if(m_extnID != OID("1.3.6.1.5.32.2.1"))
+  if(extensionId_ != OID("1.3.6.1.5.32.2.1"))
     throw LnException("Wrong ProfileExtension Number!");
 }
 
-Ptr<ProfileData>
+shared_ptr<ProfileData>
 ProfileExtension::getProfileData()
 {
-  Ptr<Blob> dataBlob = Ptr<Blob>(new Blob(m_extnValue.buf (), m_extnValue.size ()));
-  return Ptr<ProfileData>(new ProfileData(*Data::decodeFromWire(dataBlob)));
+  Data data;
+  data.wireDecode(extensionValue_.buf(), extensionValue_.size());
+  return make_shared<ProfileData>(data);
 }
 
-EndorseExtension::EndorseExtension(const vector<string>& endorsedList)
-  : CertificateExtension("1.3.6.1.5.32.2.2", true, *EndorseExtension::prepareValue(endorsedList))
+EndorseExtension::EndorseExtension(const vector<string>& endorseList)
+  : CertificateExtension("1.3.6.1.5.32.2.2", true, EndorseExtension::encodeEndorseList(endorseList))
 {}
 
 EndorseExtension::EndorseExtension(const EndorseExtension& endorseExtension)
-  : CertificateExtension("1.3.6.1.5.32.2.2", true, endorseExtension.m_extnValue)
+  : CertificateExtension("1.3.6.1.5.32.2.2", true, endorseExtension.extensionValue_)
 {}
 
 EndorseExtension::EndorseExtension(const CertificateExtension& extension)
-  : CertificateExtension(extension.getOID(), extension.getCritical(), extension.getValue())
+  : CertificateExtension(extension.getOid(), extension.getIsCritical(), extension.getValue())
 {
-  if(m_extnID != OID("1.3.6.1.5.32.2.2"))
+  if(extensionId_ != OID("1.3.6.1.5.32.2.2"))
     throw LnException("Wrong EndorseExtension Number!");
 }
 
 vector<string>
-EndorseExtension::getEndorsedList()
+EndorseExtension::getEndorseList()
 {
-  vector<string> endorsedList;
+  Chronos::EndorseExtensionMsg endorseExtension;
 
   boost::iostreams::stream
-    <boost::iostreams::array_source> is (m_extnValue.buf(), m_extnValue.size());
+    <boost::iostreams::array_source> is ((const char*)extensionValue_.buf(), extensionValue_.size());
+
+  endorseExtension.ParseFromIstream(&is);
+
+  vector<string> endorseList;
+
+  for(int i = 0; i < endorseExtension.endorseentry_size(); i ++)
+    endorseList.push_back(endorseExtension.endorseentry(i).name());
   
-  Ptr<der::DerSequence> root = DynamicCast<der::DerSequence>(der::DerNode::parse(reinterpret_cast<InputIterator &>(is)));
-  const der::DerNodePtrList & children = root->getChildren();
-  der::SimpleVisitor simpleVisitor;
-
-  for(int i = 0; i < children.size(); i++)
-      endorsedList.push_back(boost::any_cast<string>(children[i]->accept(simpleVisitor)));
-
-  return endorsedList;
+  return endorseList;
 }
 
-Ptr<Blob>
-EndorseExtension::prepareValue(const vector<string>& endorsedList)
+Blob
+EndorseExtension::encodeEndorseList(const vector<string>& endorseList)
 {
-  Ptr<der::DerSequence> root = Ptr<der::DerSequence>::Create();
+  Chronos::EndorseExtensionMsg endorseExtension;
   
-  vector<string>::const_iterator it = endorsedList.begin();
-  for(; it != endorsedList.end(); it++)
-    {
-      Ptr<der::DerPrintableString> entry = Ptr<der::DerPrintableString>(new der::DerPrintableString(*it));
-      root->addChild(entry);
-    }
-  
-  blob_stream blobStream;
-  OutputIterator & start = reinterpret_cast<OutputIterator &> (blobStream);
-  root->encode(start);
+  vector<string>::const_iterator it = endorseList.begin();
+  for(; it != endorseList.end(); it++)
+    endorseExtension.add_endorseentry()->set_name(*it);
 
-  return blobStream.buf ();
+  string encoded;
+  endorseExtension.SerializeToString(&encoded);
+  
+  return Blob((const uint8_t*)encoded.c_str(), encoded.size());
 }
 
 EndorseCertificate::EndorseCertificate(const IdentityCertificate& kskCertificate,
-                                       Ptr<ProfileData> profileData,
+                                       const ProfileData& profileData,
                                        const vector<string>& endorseList)
   : Certificate()
   , m_keyName(kskCertificate.getPublicKeyName())
@@ -104,15 +102,18 @@
   , m_profileData(profileData)
   , m_endorseList(endorseList)
 {
+  time_duration now = microsec_clock::universal_time () - ptime(boost::gregorian::date (1970, boost::gregorian::Jan, 1));
+  uint64_t version = (now.total_seconds () << 12) | (0xFFF & (now.fractional_seconds () / 244));
+
   Name dataName = m_keyName;
-  dataName.append("PROFILE-CERT").append(m_signer).appendVersion();
+  dataName.append("PROFILE-CERT").append(m_signer).appendVersion(version);
   setName(dataName);
 
   setNotBefore(kskCertificate.getNotBefore());
   setNotAfter(kskCertificate.getNotAfter());
-  addSubjectDescription(CertificateSubDescrypt("2.5.4.41", m_keyName.toUri()));
+  addSubjectDescription(CertificateSubjectDescription("2.5.4.41", m_keyName.toUri()));
   setPublicKeyInfo(kskCertificate.getPublicKeyInfo());  
-  addExtension(ProfileExtension(*m_profileData));
+  addExtension(ProfileExtension(m_profileData));
   addExtension(EndorseExtension(m_endorseList));
   
   encode();
@@ -127,15 +128,18 @@
   , m_profileData(endorseCertificate.m_profileData)
   , m_endorseList(endorseList)
 {
+  time_duration now = microsec_clock::universal_time () - ptime(boost::gregorian::date (1970, boost::gregorian::Jan, 1));
+  uint64_t version = (now.total_seconds () << 12) | (0xFFF & (now.fractional_seconds () / 244));
+  
   Name dataName = m_keyName;
-  dataName.append("PROFILE-CERT").append(m_signer).appendVersion();
+  dataName.append("PROFILE-CERT").append(m_signer).appendVersion(version);
   setName(dataName);
   
   setNotBefore(endorseCertificate.getNotBefore());
   setNotAfter(endorseCertificate.getNotAfter());
-  addSubjectDescription(CertificateSubDescrypt("2.5.4.41", m_keyName.toUri()));
+  addSubjectDescription(CertificateSubjectDescription("2.5.4.41", m_keyName.toUri()));
   setPublicKeyInfo(endorseCertificate.getPublicKeyInfo());
-  addExtension(ProfileExtension(*m_profileData));
+  addExtension(ProfileExtension(m_profileData));
   addExtension(EndorseExtension(m_endorseList));
 
   encode();
@@ -153,7 +157,7 @@
   : Certificate(data)
 {
   const Name& dataName = data.getName();
-  name::Component certFlag(string("PROFILE-CERT"));  
+  Name::Component certFlag(Name::fromEscapedString("PROFILE-CERT"));  
   int profileIndex = -1;
   for(int i = 0; i < dataName.size(); i++)
     {
@@ -172,18 +176,18 @@
   OID profileExtensionOID("1.3.6.1.5.32.2.1");
   OID endorseExtensionOID("1.3.6.1.5.32.2.2");
 
-  ExtensionList::iterator it = m_extnList.begin();
-  for(; it != m_extnList.end(); it++)
+  ExtensionList::iterator it = extensionList_.begin();
+  for(; it != extensionList_.end(); it++)
     {
-      if(profileExtensionOID == it->getOID())
+      if(profileExtensionOID == it->getOid())
 	{
           ProfileExtension profileExtension(*it);
-	  m_profileData = profileExtension.getProfileData();
+	  m_profileData = *profileExtension.getProfileData();
 	}
-      if(endorseExtensionOID == it->getOID())
+      if(endorseExtensionOID == it->getOid())
         {
           EndorseExtension endorseExtension(*it);
-          m_endorseList = endorseExtension.getEndorsedList();
+          m_endorseList = endorseExtension.getEndorseList();
         }
     }
 }
diff --git a/src/endorse-certificate.h b/src/endorse-certificate.h
index 99d9d65..5f076f2 100644
--- a/src/endorse-certificate.h
+++ b/src/endorse-certificate.h
@@ -12,13 +12,13 @@
 #define LINKNDN_ENDORSE_CERTIFICATE_H
 
 #include <vector>
-#include <ndn.cxx/data.h>
-#include <ndn.cxx/security/certificate/identity-certificate.h>
-#include <ndn.cxx/security/certificate/certificate-extension.h>
+#include <ndn-cpp/data.hpp>
+#include <ndn-cpp/security/certificate/identity-certificate.hpp>
+#include <ndn-cpp/security/certificate/certificate-extension.hpp>
 
 #include "profile-data.h"
 
-class ProfileExtension : public ndn::security::CertificateExtension
+class ProfileExtension : public ndn::CertificateExtension
 {
 public:
   ProfileExtension(const ProfileData& profileData);
@@ -29,14 +29,14 @@
 
   ~ProfileExtension() {}
 
-  ndn::Ptr<ProfileData>
+  ndn::ptr_lib::shared_ptr<ProfileData>
   getProfileData();
 };
 
-class EndorseExtension : public ndn::security::CertificateExtension
+class EndorseExtension : public ndn::CertificateExtension
 {
 public:
-  EndorseExtension(const std::vector<std::string>& endorsedList);
+  EndorseExtension(const std::vector<std::string>& endorseList);
 
   EndorseExtension(const EndorseExtension& endorseExtension);
 
@@ -45,20 +45,20 @@
   ~EndorseExtension() {}
 
   std::vector<std::string>
-  getEndorsedList();
+  getEndorseList();
 
 private:
-  static ndn::Ptr<ndn::Blob>
-  prepareValue(const std::vector<std::string>& endorsedList);
+  static ndn::Blob
+  encodeEndorseList(const std::vector<std::string>& endorsedList);
 };
 
-class EndorseCertificate : public ndn::security::Certificate
+class EndorseCertificate : public ndn::Certificate
 {
 public:
   EndorseCertificate() {}
 
-  EndorseCertificate(const ndn::security::IdentityCertificate& kskCertificate,
-                     ndn::Ptr<ProfileData> profileData,
+  EndorseCertificate(const ndn::IdentityCertificate& kskCertificate,
+                     const ProfileData& profileData,
                      const std::vector<std::string>& endorseList = std::vector<std::string>());
 
   EndorseCertificate(const EndorseCertificate& endorseCertificate,
@@ -73,26 +73,26 @@
   ~EndorseCertificate()
   {}
 
-  inline const ndn::Name&
+  const ndn::Name&
   getSigner() const
   { return m_signer; }
 
-  inline ndn::Ptr<ProfileData>
+  const ProfileData&
   getProfileData() const
   { return m_profileData; }
 
-  inline const std::vector<std::string>&
+  const std::vector<std::string>&
   getEndorseList() const
   { return m_endorseList; }
 
-  inline virtual ndn::Name
+  virtual ndn::Name
   getPublicKeyName () const
   { return m_keyName; }
 
 protected:
   ndn::Name m_keyName;
   ndn::Name m_signer;
-  ndn::Ptr<ProfileData> m_profileData;
+  ProfileData m_profileData;
   std::vector<std::string> m_endorseList;
 };
 
diff --git a/src/endorse-collection.proto b/src/endorse-collection.proto
new file mode 100644
index 0000000..d3aa574
--- /dev/null
+++ b/src/endorse-collection.proto
@@ -0,0 +1,10 @@
+package Chronos;
+
+message EndorseCollection
+{
+  message Endorsement
+  {
+    required string blob = 1;
+  }
+  repeated Endorsement endorsement = 1;
+}
\ No newline at end of file
diff --git a/src/endorse-extension.proto b/src/endorse-extension.proto
new file mode 100644
index 0000000..5db625c
--- /dev/null
+++ b/src/endorse-extension.proto
@@ -0,0 +1,10 @@
+package Chronos;
+
+message EndorseExtensionMsg
+{
+  message EndorseEntry
+  {
+    required string name = 1;
+  }	
+  repeated EndorseEntry endorseEntry = 1;
+}
\ No newline at end of file
diff --git a/src/invitation-policy-manager.cpp b/src/invitation-policy-manager.cpp
index 58c9fcc..cd86cbd 100644
--- a/src/invitation-policy-manager.cpp
+++ b/src/invitation-policy-manager.cpp
@@ -9,40 +9,36 @@
  */
 
 #include "invitation-policy-manager.h"
-
-#include <ndn.cxx/security/cache/ttl-certificate-cache.h>
+#include "null-ptrs.h"
+#include <ndn-cpp/sha256-with-rsa-signature.hpp>
+#include <ndn-cpp/security/signature/sha256-with-rsa-handler.hpp>
 
 #include "logging.h"
 
 using namespace std;
 using namespace ndn;
-using namespace ndn::security;
+using namespace ndn::ptr_lib;
 
 INIT_LOGGER("InvitationPolicyManager");
 
 InvitationPolicyManager::InvitationPolicyManager(const string& chatroomName,
                                                  const Name& signingIdentity,
-                                                 int stepLimit,
-                                                 Ptr<CertificateCache> certificateCache)
+                                                 int stepLimit)
   : m_chatroomName(chatroomName)
   , m_signingIdentity(signingIdentity)
   , m_stepLimit(stepLimit)
-  , m_certificateCache(certificateCache)
 {
-  if(m_certificateCache == NULL)
-    m_certificateCache = Ptr<TTLCertificateCache>(new TTLCertificateCache());
+  m_invitationPolicyRule = make_shared<IdentityPolicyRule>("^<ndn><broadcast><chronos><invitation>([^<chatroom>]*)<chatroom>", 
+                                                           "^([^<KEY>]*)<KEY>(<>*)[<dsk-.*><ksk-.*>]<ID-CERT>$", 
+                                                           "==", "\\1", "\\1\\2", true);
 
-  m_invitationPolicyRule = Ptr<IdentityPolicyRule>(new IdentityPolicyRule("^<ndn><broadcast><chronos><invitation>([^<chatroom>]*)<chatroom>", 
-									  "^([^<KEY>]*)<KEY>(<>*)[<dsk-.*><ksk-.*>]<ID-CERT>$", 
-									  "==", "\\1", "\\1\\2", true));
+  m_kskRegex = make_shared<Regex>("^([^<KEY>]*)<KEY>(<>*<ksk-.*>)<ID-CERT><>$", "\\1\\2");
 
-  m_kskRegex = Ptr<Regex>(new Regex("^([^<KEY>]*)<KEY>(<>*<ksk-.*>)<ID-CERT><>$", "\\1\\2"));
+  m_dskRule = make_shared<IdentityPolicyRule>("^([^<KEY>]*)<KEY><dsk-.*><ID-CERT><>$", 
+                                              "^([^<KEY>]*)<KEY>(<>*)<ksk-.*><ID-CERT>$", 
+                                              "==", "\\1", "\\1\\2", true);
 
-  m_dskRule = Ptr<IdentityPolicyRule>(new IdentityPolicyRule("^([^<KEY>]*)<KEY><dsk-.*><ID-CERT><>$", 
-							     "^([^<KEY>]*)<KEY>(<>*)<ksk-.*><ID-CERT>$", 
-							     "==", "\\1", "\\1\\2", true));
-
-  m_keyNameRegex = Ptr<Regex>(new Regex("^([^<KEY>]*)<KEY>(<>*<ksk-.*>)<ID-CERT>$", "\\1\\2"));
+  m_keyNameRegex = make_shared<Regex>("^([^<KEY>]*)<KEY>(<>*<ksk-.*>)<ID-CERT>$", "\\1\\2");
 } 
 
 InvitationPolicyManager::~InvitationPolicyManager()
@@ -56,26 +52,26 @@
 InvitationPolicyManager::requireVerify (const Data& data)
 { return true; }
 
-Ptr<ValidationRequest>
-InvitationPolicyManager::checkVerificationPolicy(Ptr<Data> data, 
-					       const int& stepCount, 
-					       const DataCallback& verifiedCallback,
-					       const UnverifiedCallback& unverifiedCallback)
+shared_ptr<ValidationRequest>
+InvitationPolicyManager::checkVerificationPolicy(const shared_ptr<Data>& data, 
+                                                 int stepCount, 
+                                                 const OnVerified& onVerified,
+                                                 const OnVerifyFailed& onVerifyFailed)
 {
   if(m_stepLimit == stepCount)
     {
       _LOG_ERROR("Reach the maximum steps of verification!");
-      unverifiedCallback(data);
-      return NULL;
+      onVerifyFailed(data);
+      return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;
     }
 
-  Ptr<const signature::Sha256WithRsa> sha256sig = boost::dynamic_pointer_cast<const signature::Sha256WithRsa> (data->getSignature());    
+  const Sha256WithRsaSignature* sha256sig = dynamic_cast<const Sha256WithRsaSignature*> (data->getSignature());    
 
-  if(KeyLocator::KEYNAME != sha256sig->getKeyLocator().getType())
+  if(ndn_KeyLocatorType_KEYNAME != sha256sig->getKeyLocator().getType())
     {
       _LOG_ERROR("KeyLocator is not name!");
-      unverifiedCallback(data);
-      return NULL;
+      onVerifyFailed(data);
+      return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;
     }
 
   const Name & keyLocatorName = sha256sig->getKeyLocator().getKeyName();
@@ -94,60 +90,59 @@
       //     return NULL;
       //   }
 
-      Ptr<const IdentityCertificate> trustedCert = m_certificateCache->getCertificate(keyLocatorName);
+      shared_ptr<const Certificate> trustedCert = m_certificateCache.getCertificate(keyLocatorName);
       
-      if(NULL != trustedCert){
-	if(verifySignature(*data, trustedCert->getPublicKeyInfo()))
-	  verifiedCallback(data);
+      if(!trustedCert){
+	if(Sha256WithRsaHandler::verifySignature(*data, trustedCert->getPublicKeyInfo()))
+	  onVerified(data);
 	else
-	  unverifiedCallback(data);
+	  onVerifyFailed(data);
 
-	return NULL;
+	return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;
       }
 
-      DataCallback recursiveVerifiedCallback = boost::bind(&InvitationPolicyManager::onDskCertificateVerified, 
-                                                           this, 
-                                                           _1, 
-                                                           data, 
-                                                           verifiedCallback, 
-                                                           unverifiedCallback);
+      OnVerified recursiveVerifiedCallback = boost::bind(&InvitationPolicyManager::onDskCertificateVerified, 
+                                                         this, 
+                                                         _1, 
+                                                         data, 
+                                                         onVerified, 
+                                                         onVerifyFailed);
       
-      UnverifiedCallback recursiveUnverifiedCallback = boost::bind(&InvitationPolicyManager::onDskCertificateUnverified, 
-                                                                   this, 
-                                                                   _1, 
-                                                                   data, 
-                                                                   unverifiedCallback);
+      OnVerifyFailed recursiveUnverifiedCallback = boost::bind(&InvitationPolicyManager::onDskCertificateVerifyFailed, 
+                                                               this, 
+                                                               _1, 
+                                                               data, 
+                                                               onVerifyFailed);
 
 
-      Ptr<Interest> interest = Ptr<Interest>(new Interest(keyLocatorName));
+      shared_ptr<Interest> interest = make_shared<Interest>(keyLocatorName);
       
-      Ptr<ValidationRequest> nextStep = Ptr<ValidationRequest>(new ValidationRequest(interest, 
-                                                                                     recursiveVerifiedCallback,
-                                                                                     recursiveUnverifiedCallback,
-                                                                                     0,
-                                                                                     stepCount + 1)
-                                                               );
+      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);
+      map<Name, PublicKey>::iterator it = m_trustAnchors.find(keyName);
       if(m_trustAnchors.end() != it)
         {
-          Ptr<IdentityCertificate> identityCertificate = Ptr<IdentityCertificate>(new IdentityCertificate(*data));
-          if(it->second.getKeyBlob() == identityCertificate->getPublicKeyInfo().getKeyBlob())
+          IdentityCertificate identityCertificate(*data);
+          if(isSameKey(it->second.getKeyDer(), identityCertificate.getPublicKeyInfo().getKeyDer()))
             {
-              verifiedCallback(data);
+              onVerified(data);
             }
           else
-            unverifiedCallback(data);
+            onVerifyFailed(data);
         }
       else
-        unverifiedCallback(data);
+        onVerifyFailed(data);
 
-      return NULL;
+      return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;
     }
 
   if(m_dskRule->satisfy(*data))
@@ -156,23 +151,23 @@
       Name keyName = m_keyNameRegex->expand();
 
       if(m_trustAnchors.end() != m_trustAnchors.find(keyName))
-        if(verifySignature(*data, m_trustAnchors[keyName]))
-          verifiedCallback(data);
+        if(Sha256WithRsaHandler::verifySignature(*data, m_trustAnchors[keyName]))
+          onVerified(data);
         else
-          unverifiedCallback(data);
+          onVerifyFailed(data);
       else
-        unverifiedCallback(data);
+        onVerifyFailed(data);
 
-      return NULL;	
+      return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;	
     }
 
-  unverifiedCallback(data);
-  return NULL;
+  onVerifyFailed(data);
+  return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;
 }
 
 bool 
 InvitationPolicyManager::checkSigningPolicy(const Name& dataName, 
-					  const Name& certificateName)
+                                            const Name& certificateName)
 {
   return true;
 }
@@ -185,7 +180,7 @@
 
 void
 InvitationPolicyManager::addTrustAnchor(const EndorseCertificate& selfEndorseCertificate)
-{ m_trustAnchors.insert(pair <Name, Publickey > (selfEndorseCertificate.getPublicKeyName(), selfEndorseCertificate.getPublicKeyInfo())); }
+{ m_trustAnchors.insert(pair <Name, PublicKey > (selfEndorseCertificate.getPublicKeyName(), selfEndorseCertificate.getPublicKeyInfo())); }
 
 
 // void
@@ -209,45 +204,66 @@
 
 
 void 
-InvitationPolicyManager::onDskCertificateVerified(Ptr<Data> certData, 
-                                                  Ptr<Data> originalData,
-                                                  const DataCallback& verifiedCallback, 
-                                                  const UnverifiedCallback& unverifiedCallback)
+InvitationPolicyManager::onDskCertificateVerified(const shared_ptr<Data>& certData, 
+                                                  shared_ptr<Data> originalData,
+                                                  const OnVerified& onVerified, 
+                                                  const OnVerifyFailed& onVerifyFailed)
 {
-  Ptr<IdentityCertificate> certificate = Ptr<IdentityCertificate>(new IdentityCertificate(*certData));
+  shared_ptr<IdentityCertificate> certificate = make_shared<IdentityCertificate>(*certData);
 
   if(!certificate->isTooLate() && !certificate->isTooEarly())
     {
-      Name certName = certificate->getName().getPrefix(certificate->getName().size()-1);
-      map<Name, Ptr<IdentityCertificate> >::iterator it = m_dskCertificates.find(certName);
+      Name certName = certificate->getName().getPrefix(-1);
+      map<Name, shared_ptr<IdentityCertificate> >::iterator it = m_dskCertificates.find(certName);
       if(it == m_dskCertificates.end())
-        m_dskCertificates.insert(pair <Name, Ptr<IdentityCertificate> > (certName, certificate));
+        m_dskCertificates.insert(pair <Name, shared_ptr<IdentityCertificate> > (certName, certificate));
 
-      if(verifySignature(*originalData, certificate->getPublicKeyInfo()))
+      if(Sha256WithRsaHandler::verifySignature(*originalData, certificate->getPublicKeyInfo()))
         {
-          verifiedCallback(originalData);
+          onVerified(originalData);
           return;
         }
     }
   else
     {
-      unverifiedCallback(originalData);
+      onVerifyFailed(originalData);
       return;
     }
 }
 
 void
-InvitationPolicyManager::onDskCertificateUnverified(Ptr<Data> certData, 
-                                                  Ptr<Data> originalData,
-                                                  const UnverifiedCallback& unverifiedCallback)
-{ unverifiedCallback(originalData); }
+InvitationPolicyManager::onDskCertificateVerifyFailed(const shared_ptr<Data>& certData, 
+                                                      shared_ptr<Data> originalData,
+                                                      const OnVerifyFailed& onVerifyFailed)
+{ onVerifyFailed(originalData); }
 
-Ptr<IdentityCertificate> 
+shared_ptr<IdentityCertificate> 
 InvitationPolicyManager::getValidatedDskCertificate(const ndn::Name& certName)
 {
-  map<Name, Ptr<IdentityCertificate> >::iterator it = m_dskCertificates.find(certName);
+  map<Name, shared_ptr<IdentityCertificate> >::iterator it = m_dskCertificates.find(certName);
   if(m_dskCertificates.end() != it)
     return it->second;
   else
-    return NULL;
+    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 f2cfc1c..a49124f 100644
--- a/src/invitation-policy-manager.h
+++ b/src/invitation-policy-manager.h
@@ -11,22 +11,21 @@
 #ifndef INVITATION_POLICY_MANAGER_H
 #define INVITATION_POLICY_MANAGER_H
 
-#include <ndn.cxx/security/policy/policy-manager.h>
-#include <ndn.cxx/security/policy/identity-policy-rule.h>
-#include <ndn.cxx/security/cache/certificate-cache.h>
-#include <ndn.cxx/regex/regex.h>
+#include <ndn-cpp/security/policy/policy-manager.hpp>
+#include <ndn-cpp-et/policy-manager/identity-policy-rule.hpp>
+#include <ndn-cpp-et/cache/ttl-certificate-cache.hpp>
+#include <ndn-cpp-et/regex/regex.hpp>
 #include <map>
 
 #include "endorse-certificate.h"
 #include "chat-policy-rule.h"
 
-class InvitationPolicyManager : public ndn::security::PolicyManager
+class InvitationPolicyManager : public ndn::PolicyManager
 {
 public:
   InvitationPolicyManager(const std::string& chatroomName,
                           const ndn::Name& signingIdentity,
-                          int stepLimit = 10,
-                          ndn::Ptr<ndn::security::CertificateCache> certificateCache = NULL);
+                          int stepLimit = 10);
   
   virtual
   ~InvitationPolicyManager();
@@ -37,11 +36,11 @@
   bool
   requireVerify (const ndn::Data& data);
 
-  ndn::Ptr<ndn::security::ValidationRequest>
-  checkVerificationPolicy(ndn::Ptr<ndn::Data> data, 
-                          const int& stepCount, 
-                          const ndn::DataCallback& verifiedCallback,
-                          const ndn::UnverifiedCallback& unverifiedCallback);
+  ndn::ptr_lib::shared_ptr<ndn::ValidationRequest>
+  checkVerificationPolicy(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, 
+                          int stepCount, 
+                          const ndn::OnVerified& onVerified,
+                          const ndn::OnVerifyFailed& onVerifyFailed);
 
   bool 
   checkSigningPolicy(const ndn::Name& dataName, 
@@ -57,20 +56,23 @@
   // addChatDataRule(const ndn::Name& prefix, 
   //                 const ndn::security::IdentityCertificate identityCertificate);
 
-  ndn::Ptr<ndn::security::IdentityCertificate> 
+  ndn::ptr_lib::shared_ptr<ndn::IdentityCertificate> 
   getValidatedDskCertificate(const ndn::Name& certName);
 
 private:
   void 
-  onDskCertificateVerified(ndn::Ptr<ndn::Data> certData, 
-                        ndn::Ptr<ndn::Data> originalData,
-                        const ndn::DataCallback& verifiedCallback, 
-                        const ndn::UnverifiedCallback& unverifiedCallback);
+  onDskCertificateVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& certData, 
+                           ndn::ptr_lib::shared_ptr<ndn::Data> originalData,
+                           const ndn::OnVerified& onVerified, 
+                           const ndn::OnVerifyFailed& onVerifyFailed);
 
   void
-  onDskCertificateUnverified(ndn::Ptr<ndn::Data> certData, 
-                          ndn::Ptr<ndn::Data> originalData,
-                          const ndn::UnverifiedCallback& unverifiedCallback);
+  onDskCertificateVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& certData, 
+                               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;
@@ -78,18 +80,18 @@
 
   int m_stepLimit;
 
-  ndn::Ptr<ndn::security::CertificateCache> m_certificateCache;
+  ndn::TTLCertificateCache m_certificateCache;
 
-  ndn::Ptr<ndn::security::IdentityPolicyRule> m_invitationPolicyRule;
-  ndn::Ptr<ndn::security::IdentityPolicyRule> m_dskRule;
-  std::map<ndn::Name, ChatPolicyRule> m_chatDataRules;
+  ndn::ptr_lib::shared_ptr<ndn::IdentityPolicyRule> m_invitationPolicyRule;
+  ndn::ptr_lib::shared_ptr<ndn::IdentityPolicyRule> m_dskRule;
+  std::map<ndn::Name, ChatPolicyRule, ndn::Name::BreadthFirstLess> m_chatDataRules;
 
-  ndn::Ptr<ndn::Regex> m_kskRegex;
-  ndn::Ptr<ndn::Regex> m_keyNameRegex;
+  ndn::ptr_lib::shared_ptr<ndn::Regex> m_kskRegex;
+  ndn::ptr_lib::shared_ptr<ndn::Regex> m_keyNameRegex;
 
-  std::map<ndn::Name, ndn::security::Publickey> m_trustAnchors;
+  std::map<ndn::Name, ndn::PublicKey, ndn::Name::BreadthFirstLess> m_trustAnchors;
 
-  std::map<ndn::Name, ndn::Ptr<ndn::security::IdentityCertificate> > m_dskCertificates;
+  std::map<ndn::Name, ndn::ptr_lib::shared_ptr<ndn::IdentityCertificate>, ndn::Name::BreadthFirstLess> m_dskCertificates;
 
 };
 
diff --git a/src/invitationdialog.cpp b/src/invitationdialog.cpp
index f909a00..c142014 100644
--- a/src/invitationdialog.cpp
+++ b/src/invitationdialog.cpp
@@ -14,6 +14,7 @@
 
 using namespace std;
 using namespace ndn;
+using namespace ndn::ptr_lib;
 
 InvitationDialog::InvitationDialog(QWidget *parent) :
     QDialog(parent),
@@ -34,8 +35,8 @@
 
 void
 InvitationDialog::setInvitation(const string& alias,
-                                Ptr<ChronosInvitation> invitation, 
-                                Ptr<security::IdentityCertificate> identityCertificate)
+                                shared_ptr<ChronosInvitation> invitation, 
+                                shared_ptr<IdentityCertificate> identityCertificate)
 {
   m_inviterAlias = alias;
   string msg = alias;
@@ -43,7 +44,7 @@
   ui->msgLabel->setText(QString::fromStdString(msg));
 
   m_invitation = invitation;
-  ui->chatroomLine->setText(QString::fromStdString(invitation->getChatroom().get(0).toUri()));
+  ui->chatroomLine->setText(QString::fromStdString(invitation->getChatroom().get(0).toEscapedString()));
 
   m_identityCertificate = identityCertificate;
 }
@@ -63,8 +64,8 @@
 
   emit invitationRejected(*m_invitation); 
 
-  m_invitation = NULL;
-  m_identityCertificate = NULL;
+  m_invitation = make_shared<ChronosInvitation>();
+  m_identityCertificate = make_shared<IdentityCertificate>();
   m_inviterAlias.clear();
 
   this->close();
diff --git a/src/invitationdialog.h b/src/invitationdialog.h
index d90b80e..271b207 100644
--- a/src/invitationdialog.h
+++ b/src/invitationdialog.h
@@ -14,8 +14,8 @@
 #include <QDialog>
 
 #ifndef Q_MOC_RUN
-#include <ndn.cxx/data.h>
-#include <ndn.cxx/security/certificate/identity-certificate.h>
+#include <ndn-cpp/data.hpp>
+#include <ndn-cpp/security/certificate/identity-certificate.hpp>
 #include "chronos-invitation.h"
 #endif
 
@@ -33,13 +33,13 @@
 
   void
   setInvitation(const std::string& alias,
-                ndn::Ptr<ChronosInvitation> invitation, 
-                ndn::Ptr<ndn::security::IdentityCertificate> identityCertificate);
+                ndn::ptr_lib::shared_ptr<ChronosInvitation> invitation, 
+                ndn::ptr_lib::shared_ptr<ndn::IdentityCertificate> identityCertificate);
 
 signals:
   void
   invitationAccepted(const ChronosInvitation& invitation, 
-                     const ndn::security::IdentityCertificate& identityCertificate);
+                     const ndn::IdentityCertificate& identityCertificate);
   
   void
   invitationRejected(const ChronosInvitation& invitation);
@@ -55,8 +55,8 @@
 private:
   Ui::InvitationDialog *ui;
   std::string m_inviterAlias;
-  ndn::Ptr<ChronosInvitation> m_invitation;
-  ndn::Ptr<ndn::security::IdentityCertificate> m_identityCertificate;
+  ndn::ptr_lib::shared_ptr<ChronosInvitation> m_invitation;
+  ndn::ptr_lib::shared_ptr<ndn::IdentityCertificate> m_identityCertificate;
 };
 
 #endif // INVITATIONDIALOG_H
diff --git a/src/invitelistdialog.cpp b/src/invitelistdialog.cpp
index c3d12af..ea6b790 100644
--- a/src/invitelistdialog.cpp
+++ b/src/invitelistdialog.cpp
@@ -13,7 +13,7 @@
 
 using namespace std;
 
-InviteListDialog::InviteListDialog(ndn::Ptr<ContactManager> contactManager,
+InviteListDialog::InviteListDialog(ndn::ptr_lib::shared_ptr<ContactManager> contactManager,
 				   QWidget *parent) 
   :QDialog(parent)
   , ui(new Ui::InviteListDialog)
@@ -50,7 +50,8 @@
 void
 InviteListDialog::refreshContactList()
 {
-  m_contactList = m_contactManager->getContactItemList();
+  m_contactList.clear();
+  m_contactManager->getContactItemList(m_contactList);
   QStringList contactNameList;
   for(int i = 0; i < m_contactList.size(); i++)
     {
diff --git a/src/invitelistdialog.h b/src/invitelistdialog.h
index cda26e5..dc91c7a 100644
--- a/src/invitelistdialog.h
+++ b/src/invitelistdialog.h
@@ -27,7 +27,7 @@
   Q_OBJECT
 
 public:
-  explicit InviteListDialog(ndn::Ptr<ContactManager> contactManager,
+  explicit InviteListDialog(ndn::ptr_lib::shared_ptr<ContactManager> contactManager,
                             QWidget *parent = 0);
   ~InviteListDialog();
 
@@ -50,9 +50,9 @@
 
 private:
   Ui::InviteListDialog *ui;
-  ndn::Ptr<ContactManager> m_contactManager;
+  ndn::ptr_lib::shared_ptr<ContactManager> m_contactManager;
   QStringListModel* m_contactListModel;
-  std::vector<ndn::Ptr<ContactItem> > m_contactList;
+  std::vector<ndn::ptr_lib::shared_ptr<ContactItem> > m_contactList;
   std::vector<std::string> m_invitedContacts;
 };
 
diff --git a/src/main.cpp b/src/main.cpp
index df4511b..219151e 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -16,7 +16,6 @@
 #include "dns-storage.h"
 #include "contact-manager.h"
 #include "logging.h"
-#include <ndn.cxx/wrapper/wrapper.h>
 
 INIT_LOGGER("MAIN");
 
@@ -34,12 +33,8 @@
     try {
         return QApplication::notify(receiver, event);
     } 
-    catch(ndn::Error::ndnOperation& e){
-      std::cerr << "Canno connect to ndnd!" << endl;
-      return false;
-    }
     catch(std::exception& e){
-      std::cerr << "Exception thrown:" << e.what() << endl;
+      std::cerr << "Exception thrown:" << e.what() << std::endl;
       return false;
     }
     
diff --git a/src/null-ptrs.h b/src/null-ptrs.h
new file mode 100644
index 0000000..0dfd3f2
--- /dev/null
+++ b/src/null-ptrs.h
@@ -0,0 +1,35 @@
+/* -*- 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 NULL_PTRS_H
+#define NULL_PTRS_H
+
+#include <string>
+#include <ndn-cpp/util/blob.hpp>
+#include <ndn-cpp/data.hpp>
+#include "contact-item.h"
+#include "endorse-certificate.h"
+#include "profile.h"
+#include <ndn-cpp/security/certificate/identity-certificate.hpp>
+#include <ndn-cpp/security/policy/validation-request.hpp>
+
+
+static std::string CHRONOCHAT_NULL_STR;
+static ndn::Blob CHRONOCHAT_NULL_BLOB;
+
+static ndn::ptr_lib::shared_ptr<ContactItem> CHRONOCHAT_NULL_CONTACTITEM_PTR;
+static ndn::ptr_lib::shared_ptr<ndn::Data> CHRONOCHAT_NULL_DATA_PTR;
+static ndn::ptr_lib::shared_ptr<EndorseCertificate> CHRONOCHAT_NULL_ENDORSECERTIFICATE_PTR;
+static ndn::ptr_lib::shared_ptr<ndn::IdentityCertificate> CHRONOCHAT_NULL_IDENTITYCERTIFICATE_PTR;
+static ndn::ptr_lib::shared_ptr<Profile> CHRONOCHAT_NULL_PROFILE_PTR;
+static ndn::ptr_lib::shared_ptr<ndn::PublicKey> CHRONOCHAT_NULL_PUBLICKEY_PTR;
+static ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;
+
+#endif
diff --git a/src/panel-policy-manager.cpp b/src/panel-policy-manager.cpp
index 96900e7..8d6300d 100644
--- a/src/panel-policy-manager.cpp
+++ b/src/panel-policy-manager.cpp
@@ -9,45 +9,42 @@
  */
 
 #include "panel-policy-manager.h"
-
-#include <ndn.cxx/security/certificate/identity-certificate.h>
-#include <ndn.cxx/security/cache/ttl-certificate-cache.h>
-#include <boost/bind.hpp>
+#include "null-ptrs.h"
+#include <ndn-cpp/sha256-with-rsa-signature.hpp>
+#include <ndn-cpp/security/signature/sha256-with-rsa-handler.hpp>
+// #include <boost/bind.hpp>
 
 #include "logging.h"
 
 using namespace std;
 using namespace ndn;
-using namespace ndn::security;
+using namespace ndn::ptr_lib;
 
 INIT_LOGGER("PanelPolicyManager");
 
-PanelPolicyManager::PanelPolicyManager(const int & stepLimit,
-                                       Ptr<CertificateCache> certificateCache)
+PanelPolicyManager::PanelPolicyManager(const int & stepLimit)
   : m_stepLimit(stepLimit)
-  , m_certificateCache(certificateCache)
-  , m_localPrefixRegex(Ptr<Regex>(new Regex("^<local><ndn><prefix><><>$")))
+  , m_certificateCache()
 {
-  if(NULL == m_certificateCache)
-    m_certificateCache = Ptr<security::CertificateCache>(new security::TTLCertificateCache());
+  m_localPrefixRegex = make_shared<Regex>("^<local><ndn><prefix><><>$");
 
-  m_invitationDataSigningRule = Ptr<IdentityPolicyRule>(new IdentityPolicyRule("^<ndn><broadcast><chronos><invitation>([^<chatroom>]*)<chatroom>", 
-                                                                               "^([^<KEY>]*)<KEY>(<>*)<><ID-CERT><>$", 
-                                                                               "==", "\\1", "\\1\\2", true));
+  m_invitationDataSigningRule = make_shared<IdentityPolicyRule>("^<ndn><broadcast><chronos><invitation>([^<chatroom>]*)<chatroom>", 
+                                                                "^([^<KEY>]*)<KEY>(<>*)<><ID-CERT><>$", 
+                                                                "==", "\\1", "\\1\\2", true);
   
-  m_dskRule = Ptr<IdentityPolicyRule>(new IdentityPolicyRule("^([^<KEY>]*)<KEY><dsk-.*><ID-CERT><>$", 
-							     "^([^<KEY>]*)<KEY>(<>*)<ksk-.*><ID-CERT>$", 
-							     "==", "\\1", "\\1\\2", true));
+  m_dskRule = make_shared<IdentityPolicyRule>("^([^<KEY>]*)<KEY><dsk-.*><ID-CERT><>$", 
+                                              "^([^<KEY>]*)<KEY>(<>*)<ksk-.*><ID-CERT>$", 
+                                              "==", "\\1", "\\1\\2", true);
   
-  m_endorseeRule = Ptr<IdentityPolicyRule>(new IdentityPolicyRule("^([^<DNS>]*)<DNS><>*<ENDORSEE><>$", 
-                                                                  "^([^<KEY>]*)<KEY>(<>*)<ksk-.*><ID-CERT>$", 
-                                                                  "==", "\\1", "\\1\\2", true));
+  m_endorseeRule = make_shared<IdentityPolicyRule>("^([^<DNS>]*)<DNS><>*<ENDORSEE><>$", 
+                                                   "^([^<KEY>]*)<KEY>(<>*)<ksk-.*><ID-CERT>$", 
+                                                   "==", "\\1", "\\1\\2", true);
   
-  m_kskRegex = Ptr<Regex>(new Regex("^([^<KEY>]*)<KEY>(<>*<ksk-.*>)<ID-CERT><>$", "\\1\\2"));
+  m_kskRegex = make_shared<Regex>("^([^<KEY>]*)<KEY>(<>*<ksk-.*>)<ID-CERT><>$", "\\1\\2");
 
-  m_keyNameRegex = Ptr<Regex>(new Regex("^([^<KEY>]*)<KEY>(<>*<ksk-.*>)<ID-CERT>$", "\\1\\2"));
+  m_keyNameRegex = make_shared<Regex>("^([^<KEY>]*)<KEY>(<>*<ksk-.*>)<ID-CERT>$", "\\1\\2");
 
-  m_signingCertificateRegex = Ptr<Regex>(new Regex("^<ndn><broadcast><chronos><invitation>([^<chatroom>]*)<chatroom>", "\\1"));
+  m_signingCertificateRegex = make_shared<Regex>("^<ndn><broadcast><chronos><invitation>([^<chatroom>]*)<chatroom>", "\\1");
 }
 
 bool 
@@ -76,26 +73,26 @@
   return false;
 }
 
-Ptr<ValidationRequest>
-PanelPolicyManager::checkVerificationPolicy(Ptr<Data> data, 
-						 const int & stepCount, 
-						 const DataCallback& verifiedCallback,
-						 const UnverifiedCallback& unverifiedCallback)
+shared_ptr<ValidationRequest>
+PanelPolicyManager::checkVerificationPolicy(const shared_ptr<Data>& data, 
+                                            int stepCount, 
+                                            const OnVerified& onVerified,
+                                            const OnVerifyFailed& onVerifyFailed)
 {
   if(m_stepLimit == stepCount)
     {
       _LOG_ERROR("Reach the maximum steps of verification!");
-      unverifiedCallback(data);
-      return NULL;
+      onVerifyFailed(data);
+      return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;
     }
 
-  Ptr<const signature::Sha256WithRsa> sha256sig = boost::dynamic_pointer_cast<const signature::Sha256WithRsa> (data->getSignature());    
+  const Sha256WithRsaSignature* sha256sig = dynamic_cast<const Sha256WithRsaSignature*>(data->getSignature());    
 
-  if(KeyLocator::KEYNAME != sha256sig->getKeyLocator().getType())
+  if(ndn_KeyLocatorType_KEYNAME != sha256sig->getKeyLocator().getType())
     {
       _LOG_ERROR("Keylocator is not name!");
-      unverifiedCallback(data);
-      return NULL;
+      onVerifyFailed(data);
+      return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;
     }
 
   const Name & keyLocatorName = sha256sig->getKeyLocator().getKeyName();
@@ -103,22 +100,20 @@
   if(m_kskRegex->match(data->getName()))
     {
       Name keyName = m_kskRegex->expand();
-      map<Name, Publickey>::iterator it = m_trustAnchors.find(keyName);
+      map<Name, PublicKey>::iterator it = m_trustAnchors.find(keyName);
       if(m_trustAnchors.end() != it)
         {
           // _LOG_DEBUG("found key!");
-          Ptr<IdentityCertificate> identityCertificate = Ptr<IdentityCertificate>(new IdentityCertificate(*data));
-          if(it->second.getKeyBlob() == identityCertificate->getPublicKeyInfo().getKeyBlob())
-            {
-              verifiedCallback(data);
-            }
+          IdentityCertificate identityCertificate(*data);
+          if(isSameKey(it->second.getKeyDer(), identityCertificate.getPublicKeyInfo().getKeyDer()))
+            onVerified(data);
           else
-            unverifiedCallback(data);
+            onVerifyFailed(data);
         }
       else
-        unverifiedCallback(data);
+        onVerifyFailed(data);
 
-      return NULL;
+      return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;
     }
 
   if(m_dskRule->satisfy(*data))
@@ -127,14 +122,14 @@
       Name keyName = m_keyNameRegex->expand();
 
       if(m_trustAnchors.end() != m_trustAnchors.find(keyName))
-        if(verifySignature(*data, m_trustAnchors[keyName]))
-          verifiedCallback(data);
+        if(Sha256WithRsaHandler::verifySignature(*data, m_trustAnchors[keyName]))
+          onVerified(data);
         else
-          unverifiedCallback(data);
+          onVerifyFailed(data);
       else
-        unverifiedCallback(data);
+        onVerifyFailed(data);
 
-      return NULL;	
+      return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;	
     }
 
   if(m_endorseeRule->satisfy(*data))
@@ -142,20 +137,20 @@
       m_keyNameRegex->match(keyLocatorName);
       Name keyName = m_keyNameRegex->expand();
       if(m_trustAnchors.end() != m_trustAnchors.find(keyName))
-        if(verifySignature(*data, m_trustAnchors[keyName]))
-          verifiedCallback(data);
+        if(Sha256WithRsaHandler::verifySignature(*data, m_trustAnchors[keyName]))
+          onVerified(data);
         else
-          unverifiedCallback(data);
+          onVerifyFailed(data);
       else
-        unverifiedCallback(data);
+        onVerifyFailed(data);
 
-      return NULL;
+      return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;
     }
 
   _LOG_DEBUG("Unverified!");
 
-  unverifiedCallback(data);
-  return NULL;
+  onVerifyFailed(data);
+  return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR;
 }
 
 bool 
@@ -177,7 +172,7 @@
 PanelPolicyManager::addTrustAnchor(const EndorseCertificate& selfEndorseCertificate)
 { 
   // _LOG_DEBUG("Add Anchor: " << selfEndorseCertificate.getPublicKeyName().toUri());
-  m_trustAnchors.insert(pair <Name, Publickey > (selfEndorseCertificate.getPublicKeyName(), selfEndorseCertificate.getPublicKeyInfo())); 
+  m_trustAnchors.insert(pair <Name, PublicKey > (selfEndorseCertificate.getPublicKeyName(), selfEndorseCertificate.getPublicKeyInfo())); 
 }
 
 void
@@ -186,14 +181,34 @@
   m_trustAnchors.erase(keyName); 
 }
 
-Ptr<Publickey>
-PanelPolicyManager::getTrustedKey(const ndn::Name& inviterCertName)
+shared_ptr<PublicKey>
+PanelPolicyManager::getTrustedKey(const Name& inviterCertName)
 {
-  Name keyLocatorName = inviterCertName.getPrefix(inviterCertName.size()-1);
+  Name keyLocatorName = inviterCertName.getPrefix(-1);
   m_keyNameRegex->match(keyLocatorName);
   Name keyName = m_keyNameRegex->expand();
 
   if(m_trustAnchors.end() != m_trustAnchors.find(keyName))
-    return Ptr<Publickey>(new Publickey(m_trustAnchors[keyName]));
-  return NULL;
+    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 f38e0e8..712f9e5 100644
--- a/src/panel-policy-manager.h
+++ b/src/panel-policy-manager.h
@@ -11,18 +11,17 @@
 #ifndef PANEL_POLICY_MANAGER_H
 #define PANEL_POLICY_MANAGER_H
 
-#include <ndn.cxx/security/policy/policy-manager.h>
-#include <ndn.cxx/security/policy/identity-policy-rule.h>
-#include <ndn.cxx/security/cache/certificate-cache.h>
+#include <ndn-cpp/security/policy/policy-manager.hpp>
+#include <ndn-cpp-et/policy-manager/identity-policy-rule.hpp>
+#include <ndn-cpp-et/cache/ttl-certificate-cache.hpp>
 #include <map>
 
 #include "endorse-certificate.h"
 
-class PanelPolicyManager : public ndn::security::PolicyManager
+class PanelPolicyManager : public ndn::PolicyManager
 {
 public:
-  PanelPolicyManager(const int & stepLimit = 10,                        
-                     ndn::Ptr<ndn::security::CertificateCache> certificateCache = NULL);
+  PanelPolicyManager(const int & stepLimit = 10);
 
   ~PanelPolicyManager()
   {}
@@ -51,11 +50,11 @@
    * @param unverifiedCallback the callback function that will be called if the received data packet cannot be validated
    * @return the indication of next verification step, NULL if there is no further step
    */
-  ndn::Ptr<ndn::security::ValidationRequest>
-  checkVerificationPolicy(ndn::Ptr<ndn::Data> data, 
-                          const int & stepCount, 
-                          const ndn::DataCallback& verifiedCallback,
-                          const ndn::UnverifiedCallback& unverifiedCallback);
+  ndn::ptr_lib::shared_ptr<ndn::ValidationRequest>
+  checkVerificationPolicy(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, 
+                          int stepCount, 
+                          const ndn::OnVerified& onVerified,
+                          const ndn::OnVerifyFailed& onVerifyFailed);
 
     
   /**
@@ -82,32 +81,24 @@
   void
   removeTrustAnchor(const ndn::Name& keyName);
 
-// private:
-//   void 
-//   onCertificateVerified(ndn::Ptr<ndn::Data> certData, 
-//                         ndn::Ptr<ndn::Data> originalData,
-//                         const ndn::DataCallback& verifiedCallback, 
-//                         const ndn::UnverifiedCallback& unverifiedCallback);
-
-//   void
-//   onCertificateUnverified(ndn::Ptr<ndn::Data> certData, 
-//                           ndn::Ptr<ndn::Data> originalData,
-//                           const ndn::UnverifiedCallback& unverifiedCallback);
-
-  ndn::Ptr<ndn::security::Publickey>
+  ndn::ptr_lib::shared_ptr<ndn::PublicKey>
   getTrustedKey(const ndn::Name& inviterCertName);
 
 private:
+  static bool
+  isSameKey(const ndn::Blob& keyA, const ndn::Blob& keyB);
+
+private:
   int m_stepLimit;
-  ndn::Ptr<ndn::security::CertificateCache> m_certificateCache;
-  ndn::Ptr<ndn::Regex> m_localPrefixRegex;
-  ndn::Ptr<ndn::security::IdentityPolicyRule> m_invitationDataSigningRule;
-  ndn::Ptr<ndn::Regex> m_kskRegex;
-  ndn::Ptr<ndn::security::IdentityPolicyRule> m_dskRule;
-  ndn::Ptr<ndn::security::IdentityPolicyRule> m_endorseeRule;
-  ndn::Ptr<ndn::Regex> m_keyNameRegex;
-  ndn::Ptr<ndn::Regex> m_signingCertificateRegex;
-  std::map<ndn::Name, ndn::security::Publickey> m_trustAnchors;
+  ndn::TTLCertificateCache m_certificateCache;
+  ndn::ptr_lib::shared_ptr<ndn::Regex> m_localPrefixRegex;
+  ndn::ptr_lib::shared_ptr<ndn::IdentityPolicyRule> m_invitationDataSigningRule;
+  ndn::ptr_lib::shared_ptr<ndn::Regex> m_kskRegex;
+  ndn::ptr_lib::shared_ptr<ndn::IdentityPolicyRule> m_dskRule;
+  ndn::ptr_lib::shared_ptr<ndn::IdentityPolicyRule> m_endorseeRule;
+  ndn::ptr_lib::shared_ptr<ndn::Regex> m_keyNameRegex;
+  ndn::ptr_lib::shared_ptr<ndn::Regex> m_signingCertificateRegex;
+  std::map<ndn::Name, ndn::PublicKey, ndn::Name::BreadthFirstLess> m_trustAnchors;
   
 };
 
diff --git a/src/profile-data.cpp b/src/profile-data.cpp
index e839f0f..6bb70cc 100644
--- a/src/profile-data.cpp
+++ b/src/profile-data.cpp
@@ -9,56 +9,52 @@
  */
 
 #include "profile-data.h"
+#include <boost/date_time/posix_time/posix_time.hpp>
 #include "exception.h"
-#include <ndn.cxx/fields/signature-sha256-with-rsa.h>
 #include "logging.h"
 
 
 using namespace ndn;
 using namespace std;
+using namespace boost::posix_time;
 
 INIT_LOGGER("ProfileData");
 
+ProfileData::ProfileData()
+  : Data()
+{}
+
 ProfileData::ProfileData(const Profile& profile)
   : Data()
   , m_identity(profile.getIdentityName())
   , m_profile(profile)
 {
   Name dataName = m_identity;
-
-  dataName.append("PROFILE").appendVersion();
+  
+  time_duration now = microsec_clock::universal_time () - ptime(boost::gregorian::date (1970, boost::gregorian::Jan, 1));
+  uint64_t version = (now.total_seconds () << 12) | (0xFFF & (now.fractional_seconds () / 244));
+  dataName.append("PROFILE").appendVersion(version);
   setName(dataName);
-  Ptr<Blob> profileBlob = profile.toDerBlob();
-  setContent(Content(profileBlob->buf(), profileBlob->size()));
+
+  string content;
+  profile.encode(&content);
+  setContent((const uint8_t *)&content[0], content.size());
+
+  getMetaInfo().setTimestampMilliseconds(time(NULL) * 1000.0);
+
 }
 
 ProfileData::ProfileData(const ProfileData& profileData)
-  : Data()
+  : Data(profileData)
   , m_identity(profileData.m_identity)
   , m_profile(profileData.m_profile)
-{
-  Ptr<const signature::Sha256WithRsa> dataSig = boost::dynamic_pointer_cast<const signature::Sha256WithRsa>(profileData.getSignature());
-  Ptr<signature::Sha256WithRsa> newSig = Ptr<signature::Sha256WithRsa>::Create();
-
-  Ptr<SignedBlob> newSignedBlob = NULL;
-  if(profileData.getSignedBlob() != NULL)
-    newSignedBlob = Ptr<SignedBlob>(new SignedBlob(*profileData.getSignedBlob()));
-  
-  newSig->setKeyLocator(dataSig->getKeyLocator());
-  newSig->setPublisherKeyDigest(dataSig->getPublisherKeyDigest());
-  newSig->setSignatureBits(dataSig->getSignatureBits());
-  
-  setName(profileData.getName());
-  setSignature(newSig);
-  setContent(profileData.getContent());
-  setSignedBlob(newSignedBlob);
-}
+{}
 
 ProfileData::ProfileData(const Data& data)
-  : Data()
+  : Data(data)
 {
   const Name& dataName = data.getName();
-  name::Component appFlag(string("PROFILE"));  
+  Name::Component appFlag(Name::fromEscapedString("PROFILE"));  
 
   int profileIndex = -1;
   for(int i = 0; i < dataName.size(); i++)
@@ -73,24 +69,8 @@
   if(profileIndex < 0)
     throw LnException("No PROFILE component in data name!");
 
-  m_identity = dataName.getSubName(0, profileIndex);
+  m_identity = dataName.getPrefix(profileIndex);
 
-  Ptr<const signature::Sha256WithRsa> dataSig = boost::dynamic_pointer_cast<const signature::Sha256WithRsa>(data.getSignature());
-  Ptr<signature::Sha256WithRsa> newSig = Ptr<signature::Sha256WithRsa>::Create();
-  
-  Ptr<SignedBlob> newSignedBlob = NULL;
-  if(data.getSignedBlob() != NULL)
-    newSignedBlob = Ptr<SignedBlob>(new SignedBlob(*data.getSignedBlob()));
-    
-  newSig->setKeyLocator(dataSig->getKeyLocator());
-  newSig->setPublisherKeyDigest(dataSig->getPublisherKeyDigest());
-  newSig->setSignatureBits(dataSig->getSignatureBits());
-  
-  setName(data.getName());
-  setSignature(newSig);
-  setContent(data.getContent());
-  setSignedBlob(newSignedBlob);
-
-  m_profile = *Profile::fromDerBlob(data.content());
-
+  string encoded((const char*)data.getContent().buf(), data.getContent().size());
+  m_profile = *Profile::decode(encoded);
 }
diff --git a/src/profile-data.h b/src/profile-data.h
index 9c8e184..dcde0d8 100644
--- a/src/profile-data.h
+++ b/src/profile-data.h
@@ -11,12 +11,14 @@
 #ifndef LINKNDN_PROFILE_DATA_H
 #define LINKNDN_PROFILE_DATA_H
 
-#include <ndn.cxx/data.h>
+#include <ndn-cpp/data.hpp>
 #include "profile.h"
 
 class ProfileData : public ndn::Data
 {
 public:
+  ProfileData();
+
   ProfileData(const Profile& profile);
 
   ProfileData(const ProfileData& profileData);
@@ -25,11 +27,11 @@
 
   ~ProfileData() {}
 
-  inline const ndn::Name& 
+  const ndn::Name& 
   getIdentityName() const
   { return m_identity; }
 
-  inline const Profile&
+  const Profile&
   getProfile() const
   { return m_profile; }
 
diff --git a/src/profile.cpp b/src/profile.cpp
index 24372a4..af805b0 100644
--- a/src/profile.cpp
+++ b/src/profile.cpp
@@ -9,13 +9,12 @@
  */
 
 #include "profile.h"
-#include <ndn.cxx/helpers/der/der.h>
-#include <ndn.cxx/helpers/der/visitor/print-visitor.h>
-#include <ndn.cxx/helpers/der/visitor/simple-visitor.h>
+#include "null-ptrs.h"
 #include "logging.h"
 
 using namespace std;
 using namespace ndn;
+using namespace ndn::ptr_lib;
 
 INIT_LOGGER("Profile");
 
@@ -26,47 +25,44 @@
 static string advisor("2.5.4.80");
 static string emailOid("1.2.840.113549.1.9.1");
 
-Profile::Profile(const security::IdentityCertificate& oldIdentityCertificate)
+Profile::Profile(const IdentityCertificate& oldIdentityCertificate)
 {
-  using namespace ndn::security;
-  security::IdentityCertificate identityCertificate(oldIdentityCertificate);
+  IdentityCertificate identityCertificate(oldIdentityCertificate);
 
   Name keyName = identityCertificate.getPublicKeyName();
-  m_identityName = keyName.getPrefix(keyName.size()-1);
+  m_identityName = keyName.getPrefix(-1);
 
   const string& identityString = m_identityName.toUri();
-  Blob identityBlob (identityString.c_str(), identityString.size());
-  m_entries[string("IDENTITY")] = identityBlob;
+  m_entries[string("IDENTITY")] = identityString;
   
-  const vector<CertificateSubDescrypt>& subList = identityCertificate.getSubjectDescriptionList();
-  vector<CertificateSubDescrypt>::const_iterator it = subList.begin();
+  const vector<CertificateSubjectDescription>& subList = identityCertificate.getSubjectDescriptionList();
+  vector<CertificateSubjectDescription>::const_iterator it = subList.begin();
   for(; it != subList.end(); it++)
     {
-      string oidStr = it->getOidStr();
-      Blob blob (it->getValue().c_str(), it->getValue().size());
+      const string oidStr = it->getOidString();
+      string valueStr = it->getValue();
       if(oidStr == nameOid)
-        m_entries[string("name")] = blob;
+        m_entries[string("name")] = valueStr;
       else if(oidStr == orgOid)
-        m_entries[string("institution")] = blob;
+        m_entries[string("institution")] = valueStr;
       else if(oidStr == groupOid)
-        m_entries[string("group")] = blob;
+        m_entries[string("group")] = valueStr;
       else if(oidStr == homepageOid)
-        m_entries[string("homepage")] = blob;
+        m_entries[string("homepage")] = valueStr;
       else if(oidStr == advisor)
-        m_entries[string("advisor")] = blob;
+        m_entries[string("advisor")] = valueStr;
       else if(oidStr == emailOid)
-        m_entries[string("email")] = blob;
+        m_entries[string("email")] = valueStr;
       else
-        m_entries[oidStr] = blob;
+        m_entries[oidStr] = valueStr;
     }
 }
 
 Profile::Profile(const Name& identityName)
   : m_identityName(identityName)
 {
-  const string& nameString = identityName.toUri();
-  Blob identityBlob (nameString.c_str(), nameString.size());
-  m_entries[string("IDENTITY")] = identityBlob;
+  const string& identityString = identityName.toUri();
+  m_entries[string("IDENTITY")] = identityString;
 }
 
 Profile::Profile(const Name& identityName,
@@ -74,15 +70,11 @@
 		 const string& institution)
   : m_identityName(identityName)
 {
-  const string& nameString = identityName.toUri();
-  Blob identityBlob (nameString.c_str(), nameString.size());
-  m_entries[string("IDENTITY")] = identityBlob;
+  const string& identityString = identityName.toUri();
+  m_entries[string("IDENTITY")] = identityString;
 
-  Blob nameBlob (name.c_str(), name.size());
-  Blob institutionBlob (institution.c_str(), institution.size());
-
-  m_entries[string("name")] = nameBlob;
-  m_entries[string("institution")] = institutionBlob;
+  m_entries[string("name")] = name;
+  m_entries[string("institution")] = institution;
 }
 
 Profile::Profile(const Profile& profile)
@@ -92,63 +84,50 @@
 
 void
 Profile::setProfileEntry(const string& profileType,
-			 const Blob& profileValue)
+			 const string& profileValue)
 { m_entries[profileType] = profileValue; }
 
-Ptr<const Blob>
+string
 Profile::getProfileEntry(const string& profileType) const
 {
   if(m_entries.find(profileType) != m_entries.end())
-    return Ptr<Blob>(new Blob(m_entries.at(profileType).buf(), m_entries.at(profileType).size()));
+    return m_entries.at(profileType);
 
-  return NULL;
+  return CHRONOCHAT_NULL_STR;
 }
 
-Ptr<Blob>
-Profile::toDerBlob() const
+void
+Profile::encode(string* output) const
 {
-  Ptr<der::DerSequence> root = Ptr<der::DerSequence>::Create();
-  
-  Ptr<der::DerPrintableString> identityName = Ptr<der::DerPrintableString>(new der::DerPrintableString(m_identityName.toUri()));
-  root->addChild(identityName);
 
-  map<string, Blob>::const_iterator it = m_entries.begin();
+  Chronos::ProfileMsg profileMsg;
+
+  profileMsg.set_identityname(m_identityName.toUri());
+  
+  map<string, string>::const_iterator it = m_entries.begin();
   for(; it != m_entries.end(); it++)
     {
-      Ptr<der::DerSequence> entry = Ptr<der::DerSequence>::Create();
-      Ptr<der::DerPrintableString> type = Ptr<der::DerPrintableString>(new der::DerPrintableString(it->first));
-      Ptr<der::DerOctetString> value = Ptr<der::DerOctetString>(new der::DerOctetString(it->second));
-      entry->addChild(type);
-      entry->addChild(value);
-      root->addChild(entry);
+      Chronos::ProfileMsg::ProfileEntry* profileEntry = profileMsg.add_entry();
+      profileEntry->set_oid(it->first);
+      profileEntry->set_data(it->second);
     }
-  
-  blob_stream blobStream;
-  OutputIterator & start = reinterpret_cast<OutputIterator &> (blobStream);
-  root->encode(start);
 
-  return blobStream.buf ();
+  profileMsg.SerializeToString(output);
 }
 
-Ptr<Profile>
-Profile::fromDerBlob(const Blob& derBlob)
+shared_ptr<Profile>
+Profile::decode(const string& input)
 {
-  boost::iostreams::stream
-    <boost::iostreams::array_source> is (derBlob.buf(), derBlob.size());
+  Chronos::ProfileMsg profileMsg;
+    
+  profileMsg.ParseFromString(input);
 
-  Ptr<der::DerSequence> root = DynamicCast<der::DerSequence>(der::DerNode::parse(reinterpret_cast<InputIterator &>(is)));
-  const der::DerNodePtrList & children = root->getChildren();
-  der::SimpleVisitor simpleVisitor;
-  string identityName = boost::any_cast<string>(children[0]->accept(simpleVisitor));
-  Ptr<Profile> profile = Ptr<Profile>(new Profile(identityName));
+  shared_ptr<Profile> profile = make_shared<Profile>(profileMsg.identityname());
 
-  for(int i = 1; i < children.size(); i++)
+  for(int i = 0; i < profileMsg.entry_size(); i++)
     {
-      Ptr<der::DerSequence> entry = DynamicCast<der::DerSequence>(children[i]);
-      const der::DerNodePtrList & tuple = entry->getChildren();
-      string type = boost::any_cast<string>(tuple[0]->accept(simpleVisitor));
-      Ptr<Blob> value = boost::any_cast<Ptr<Blob> >(tuple[1]->accept(simpleVisitor));
-      profile->setProfileEntry(type, *value);
+      const Chronos::ProfileMsg::ProfileEntry& profileEntry = profileMsg.entry(i);
+      profile->setProfileEntry(profileEntry.oid(), profileEntry.data());
     }
 
   return profile;
diff --git a/src/profile.h b/src/profile.h
index 7a65553..cbd504d 100644
--- a/src/profile.h
+++ b/src/profile.h
@@ -11,22 +11,21 @@
 #ifndef LINKNDN_PROFILE_H
 #define LINKNDN_PROFILE_H
 
-#include <ndn.cxx/common.h>
-#include <ndn.cxx/fields/name.h>
-#include <ndn.cxx/fields/blob.h>
-#include <ndn.cxx/security/certificate/identity-certificate.h>
+#include <ndn-cpp/name.hpp>
+#include <ndn-cpp/security/certificate/identity-certificate.hpp>
 #include <map>
 #include <string>
+#include "profile.pb.h"
 
 class Profile
 {
 public:
-  typedef std::map<std::string, ndn::Blob>::iterator iterator;
-  typedef std::map<std::string, ndn::Blob>::const_iterator const_iterator;
+  typedef std::map<std::string, std::string>::iterator iterator;
+  typedef std::map<std::string, std::string>::const_iterator const_iterator;
 public:
   Profile() {}
 
-  Profile(const ndn::security::IdentityCertificate& identityCertificate);
+  Profile(const ndn::IdentityCertificate& identityCertificate);
 
   Profile(const ndn::Name& identityName);
 
@@ -41,9 +40,9 @@
 
   void
   setProfileEntry(const std::string& profileType,
-                  const ndn::Blob& profileValue);
+                  const std::string& profileValue);
   
-  ndn::Ptr<const ndn::Blob>
+  std::string
   getProfileEntry(const std::string& profileType) const;
 
   inline Profile::iterator
@@ -62,25 +61,23 @@
   end() const
   { return m_entries.end(); }
 
-  ndn::Ptr<ndn::Blob>
-  toDerBlob() const;
+  void
+  encode(std::string* output) const;
 
-  static ndn::Ptr<Profile>
-  fromDerBlob(const ndn::Blob& derBlob);
+  static ndn::ptr_lib::shared_ptr<Profile>
+  decode(const std::string& input);
 
-  inline const std::map<std::string, ndn::Blob>&
+  const std::map<std::string, std::string>&
   getEntries() const
   { return m_entries; }
 
-  inline const ndn::Name&
+  const ndn::Name&
   getIdentityName() const
   { return m_identityName; }
 
 protected:
   ndn::Name m_identityName;
-  std::map<std::string, ndn::Blob> m_entries;
+  std::map<std::string, std::string> m_entries;
 };
 
-
-
 #endif
diff --git a/src/profile.proto b/src/profile.proto
new file mode 100644
index 0000000..34f79da
--- /dev/null
+++ b/src/profile.proto
@@ -0,0 +1,12 @@
+package Chronos;
+
+message ProfileMsg
+{
+  required string identityName = 1;
+  message ProfileEntry
+  {
+    required string oid = 1;
+    required string data = 2;
+  }
+  repeated ProfileEntry entry = 2;
+}
\ No newline at end of file
diff --git a/src/profileeditor.cpp b/src/profileeditor.cpp
index 4804431..4abad5a 100644
--- a/src/profileeditor.cpp
+++ b/src/profileeditor.cpp
@@ -20,16 +20,18 @@
 #endif
 
 using namespace ndn;
+using namespace std;
+using namespace ndn::ptr_lib;
 
 INIT_LOGGER("ProfileEditor");
 
-ProfileEditor::ProfileEditor(Ptr<ContactManager> contactManager, 
+ProfileEditor::ProfileEditor(shared_ptr<ContactManager> contactManager, 
                              QWidget *parent) 
     : QDialog(parent)
     , ui(new Ui::ProfileEditor)
     , m_tableModel(new QSqlTableModel())
     , m_contactManager(contactManager)
-    , m_identityManager(ndn::Ptr<ndn::security::IdentityManager>::Create())
+    , m_identityManager(contactManager->getIdentityManager())
 {
   ui->setupUi(this);
   
@@ -83,14 +85,7 @@
 void
 ProfileEditor::onOkClicked()
 {
-  Name defaultKeyName = m_identityManager->getPublicStorage()->getDefaultKeyNameForIdentity(m_currentIdentity);
-  if(defaultKeyName.size() == 0)
-    {
-      emit noKeyOrCert(QString::fromStdString("Corresponding key is missing!\nHave you created the key?"));
-      return;
-    }
-
-  Name defaultCertName = m_identityManager->getPublicStorage()->getDefaultCertificateNameForKey(defaultKeyName);
+  Name defaultCertName = m_identityManager->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 7a5c6f7..6f8477c 100644
--- a/src/profileeditor.h
+++ b/src/profileeditor.h
@@ -16,7 +16,7 @@
 
 #ifndef Q_MOC_RUN
 #include "contact-manager.h"
-#include <ndn.cxx/security/identity/identity-manager.h>
+#include <ndn-cpp/security/identity/identity-manager.hpp>
 #endif
 
 namespace Ui {
@@ -28,12 +28,12 @@
     Q_OBJECT
 
 public:
-  explicit ProfileEditor(ndn::Ptr<ContactManager> contactManager, 
+  explicit ProfileEditor(ndn::ptr_lib::shared_ptr<ContactManager> contactManager, 
                          QWidget *parent = 0);
   
   ~ProfileEditor();
 
-  inline void
+  void
   setCurrentIdentity(const ndn::Name& name)
   { m_currentIdentity = name; }
   
@@ -57,8 +57,8 @@
 private:
   Ui::ProfileEditor *ui;
   QSqlTableModel* m_tableModel;
-  ndn::Ptr<ContactManager> m_contactManager;
-  ndn::Ptr<ndn::security::IdentityManager> m_identityManager;
+  ndn::ptr_lib::shared_ptr<ContactManager> m_contactManager;
+  ndn::ptr_lib::shared_ptr<ndn::IdentityManager> m_identityManager;
   ndn::Name m_currentIdentity;
 };
 
diff --git a/src/setaliasdialog.cpp b/src/setaliasdialog.cpp
index c615127..42d8b2d 100644
--- a/src/setaliasdialog.cpp
+++ b/src/setaliasdialog.cpp
@@ -13,9 +13,10 @@
 
 
 using namespace ndn;
+using namespace ndn::ptr_lib;
 using namespace std;
 
-SetAliasDialog::SetAliasDialog(Ptr<ContactManager> contactManager,
+SetAliasDialog::SetAliasDialog(shared_ptr<ContactManager> contactManager,
 			       QWidget *parent) 
   : QDialog(parent)
   , ui(new Ui::SetAliasDialog)
diff --git a/src/setaliasdialog.h b/src/setaliasdialog.h
index 1e24963..4de2255 100644
--- a/src/setaliasdialog.h
+++ b/src/setaliasdialog.h
@@ -26,7 +26,7 @@
   Q_OBJECT
 
 public:
-  explicit SetAliasDialog(ndn::Ptr<ContactManager> contactManager,
+  explicit SetAliasDialog(ndn::ptr_lib::shared_ptr<ContactManager> contactManager,
 			  QWidget *parent = 0);
   ~SetAliasDialog();
 
@@ -46,7 +46,7 @@
 
 private:
   Ui::SetAliasDialog *ui;
-  ndn::Ptr<ContactManager> m_contactManager;
+  ndn::ptr_lib::shared_ptr<ContactManager> m_contactManager;
   std::string m_target;
 };