Changing API from ndn.cxx to ndn-cpp
diff --git a/src/specific-policy-rule.cc b/src/specific-policy-rule.cc
index 9fbd23a..7057ba5 100644
--- a/src/specific-policy-rule.cc
+++ b/src/specific-policy-rule.cc
@@ -9,15 +9,15 @@
  */
 
 #include "specific-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 ndn::ptr_lib;
 using namespace std;
-using namespace ndn::security;
 
 
-SpecificPolicyRule::SpecificPolicyRule(Ptr<Regex> dataRegex,
-				       Ptr<Regex> signerRegex)
+SpecificPolicyRule::SpecificPolicyRule(shared_ptr<Regex> dataRegex,
+				       shared_ptr<Regex> signerRegex)
   : PolicyRule(PolicyRule::IDENTITY_POLICY, true)
   , m_dataRegex(dataRegex)
   , m_signerRegex(signerRegex)
@@ -30,14 +30,14 @@
 {}
 
 bool 
-SpecificPolicyRule::matchDataName(const Data & data)
+SpecificPolicyRule::matchDataName(const Data& data)
 { return m_dataRegex->match(data.getName()); }
 
 bool 
-SpecificPolicyRule::matchSignerName(const Data & data)
+SpecificPolicyRule::matchSignerName(const Data& data)
 { 
-  Ptr<const signature::Sha256WithRsa> sigPtr = DynamicCast<const signature::Sha256WithRsa> (data.getSignature());
-  Name signerName = sigPtr->getKeyLocator ().getKeyName ();
+  const Sha256WithRsaSignature* sigPtr = dynamic_cast<const Sha256WithRsaSignature*> (data.getSignature());
+  Name signerName = sigPtr->getKeyLocator().getKeyName ();
   return m_signerRegex->match(signerName); 
 }
 
diff --git a/src/specific-policy-rule.h b/src/specific-policy-rule.h
index e2b859b..429eff7 100644
--- a/src/specific-policy-rule.h
+++ b/src/specific-policy-rule.h
@@ -11,15 +11,15 @@
 #ifndef SPECIFIC_POLICY_RULE_H
 #define SPECIFIC_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 SpecificPolicyRule : public ndn::security::PolicyRule
+class SpecificPolicyRule : public ndn::PolicyRule
 {
   
 public:
-  SpecificPolicyRule(ndn::Ptr<ndn::Regex> dataRegex,
-                     ndn::Ptr<ndn::Regex> signerRegex);
+  SpecificPolicyRule(ndn::ptr_lib::shared_ptr<ndn::Regex> dataRegex,
+                     ndn::ptr_lib::shared_ptr<ndn::Regex> signerRegex);
 
   SpecificPolicyRule(const SpecificPolicyRule& rule);
 
@@ -27,20 +27,20 @@
   ~SpecificPolicyRule() {};
 
   bool 
-  matchDataName(const ndn::Data & data);
+  matchDataName(const ndn::Data& data);
 
   bool 
-  matchSignerName(const ndn::Data & data);
+  matchSignerName(const ndn::Data& data);
 
   bool
-  satisfy(const ndn::Data & data);
+  satisfy(const ndn::Data& data);
 
   bool
-  satisfy(const ndn::Name & dataName, const ndn::Name & signerName);
+  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/sync-intro-certificate.cc b/src/sync-intro-certificate.cc
index e9587e9..d7e75f8 100644
--- a/src/sync-intro-certificate.cc
+++ b/src/sync-intro-certificate.cc
@@ -9,11 +9,13 @@
  */
 
 #include "sync-intro-certificate.h"
-#include <ndn.cxx/security/exception.h>
+#include <ndn-cpp/security/security-exception.hpp>
+
+#include <boost/date_time/posix_time/posix_time.hpp>
 
 using namespace ndn;
-using namespace ndn::security;
 using namespace std;
+using namespace boost;
 
 SyncIntroCertificate::SyncIntroCertificate ()
   : Certificate()
@@ -22,9 +24,9 @@
 SyncIntroCertificate::SyncIntroCertificate (const Name& nameSpace,
 					    const Name& keyName,
 					    const Name& signerName,
-					    const Time& notBefore,
-					    const Time& notAfter,
-					    const Publickey& key,
+					    const MillisecondsSince1970& notBefore,
+					    const MillisecondsSince1970& notAfter,
+					    const PublicKey& key,
 					    const IntroType& introType)
   : m_keyName(keyName)
   , m_introType(introType)
@@ -40,15 +42,18 @@
       certificateName.append("INTRODUCER");
       break;
     default:
-      throw SecException("Wrong Introduction Type!");
+      throw SecurityException("Wrong Introduction Type!");
     }
-  certificateName.appendVersion();
+
+  posix_time::time_duration now = posix_time::microsec_clock::universal_time () - posix_time::ptime(gregorian::date (1970, boost::gregorian::Jan, 1));
+  uint64_t version = (now.total_seconds () << 12) | (0xFFF & (now.fractional_seconds () / 244));
+  certificateName.appendVersion(version);
  
   Data::setName(certificateName);
   setNotBefore(notBefore);
   setNotAfter(notAfter);
   setPublicKeyInfo(key);
-  addSubjectDescription(CertificateSubDescrypt("2.5.4.41", keyName.toUri()));
+  addSubjectDescription(CertificateSubjectDescription("2.5.4.41", keyName.toUri()));
   encode();
 }
 
@@ -71,15 +76,17 @@
       certificateName.append("INTRODUCER");
       break;
     default:
-      throw SecException("Wrong Introduction Type!");
+      throw SecurityException("Wrong Introduction Type!");
     }
-  certificateName.appendVersion();
+  posix_time::time_duration now = posix_time::microsec_clock::universal_time () - posix_time::ptime(gregorian::date (1970, boost::gregorian::Jan, 1));
+  uint64_t version = (now.total_seconds () << 12) | (0xFFF & (now.fractional_seconds () / 244));
+  certificateName.appendVersion(version);
  
   setName(certificateName);
   setNotBefore(identityCertificate.getNotBefore());
   setNotAfter(identityCertificate.getNotAfter());
   setPublicKeyInfo(identityCertificate.getPublicKeyInfo());
-  addSubjectDescription(CertificateSubDescrypt("2.5.4.41", m_keyName.toUri()));
+  addSubjectDescription(CertificateSubjectDescription("2.5.4.41", m_keyName.toUri()));
 }
   
 SyncIntroCertificate::SyncIntroCertificate (const Data& data)
@@ -91,7 +98,7 @@
   int keyNameEnd = 0;
   for(; i < certificateName.size(); i++)
     {
-      if(certificateName.get(i).toUri() == string("WOT"))
+      if(certificateName.get(i).toEscapedString() == string("WOT"))
 	{
 	  keyNameStart = i + 1;
 	  break;
@@ -99,11 +106,11 @@
     }
   
   if(i >= certificateName.size())
-    throw SecException("Wrong SyncIntroCertificate Name!");
+    throw SecurityException("Wrong SyncIntroCertificate Name!");
     
   for(; i< certificateName.size(); i++)
     {
-      if(certificateName.get(i).toUri() == string("INTRO-CERT"))
+      if(certificateName.get(i).toEscapedString() == string("INTRO-CERT"))
 	{
 	  keyNameEnd = i;
 	  break;
@@ -111,17 +118,17 @@
     }
 
   if(i >= certificateName.size())
-    throw SecException("Wrong SyncIntroCertificate Name!");
+    throw SecurityException("Wrong SyncIntroCertificate Name!");
 
   m_keyName = certificateName.getSubName(keyNameStart, keyNameEnd - keyNameStart);
 
-  string typeComponent = certificateName.get(certificateName.size() - 2).toUri();
+  string typeComponent = certificateName.get(certificateName.size() - 2).toEscapedString();
   if(typeComponent == string("PRODUCER"))
     m_introType = PRODUCER;
   else if(typeComponent == string("INTRODUCER"))
     m_introType = INTRODUCER;
   else
-    throw SecException("Wrong SyncIntroCertificate Name!");
+    throw SecurityException("Wrong SyncIntroCertificate Name!");
 }
 
 SyncIntroCertificate::SyncIntroCertificate (const SyncIntroCertificate& chronosIntroCertificate)
@@ -138,7 +145,7 @@
   int keyNameEnd = 0;
   for(; i < certificateName.size(); i++)
     {
-      if(certificateName.get(i).toUri() == string("WOT"))
+      if(certificateName.get(i).toEscapedString() == string("WOT"))
 	{
 	  keyNameStart = i + 1;
 	  break;
@@ -146,11 +153,11 @@
     }
     
   if(i >= certificateName.size())
-    throw SecException("Wrong SyncIntroCertificate Name!");
+    throw SecurityException("Wrong SyncIntroCertificate Name!");
   
   for(; i< certificateName.size(); i++)
     {
-      if(certificateName.get(i).toUri() == string("INTRO-CERT"))
+      if(certificateName.get(i).toEscapedString() == string("INTRO-CERT"))
 	{
 	  keyNameEnd = i;
 	  break;
@@ -158,17 +165,17 @@
     }
 
   if(i >= certificateName.size())
-    throw SecException("Wrong SyncIntroCertificate Name!");
+    throw SecurityException("Wrong SyncIntroCertificate Name!");
 
-  m_keyName = certificateName.getSubName(keyNameStart, keyNameEnd);
+  m_keyName = certificateName.getSubName(keyNameStart, keyNameEnd - keyNameStart);
 
-  string typeComponent = certificateName.get(certificateName.size() - 2).toUri();
+  string typeComponent = certificateName.get(certificateName.size() - 2).toEscapedString();
   if(typeComponent == string("PRODUCER"))
     m_introType = PRODUCER;
   else if(typeComponent == string("INTRODUCER"))
     m_introType = INTRODUCER;
   else
-    throw SecException("Wrong SyncIntroCertificate Name!");
+    throw SecurityException("Wrong SyncIntroCertificate Name!");
     
   return *this;
 }
@@ -177,7 +184,7 @@
 SyncIntroCertificate::isSyncIntroCertificate(const Certificate& certificate)
 {
   const Name& certificateName = certificate.getName();
-  string introType = certificateName.get(certificateName.size() - 2).toUri();
+  string introType = certificateName.get(certificateName.size() - 2).toEscapedString();
   if(introType != string("PRODUCER") && introType != string("INTRODUCER"))
     return false;
 
@@ -186,7 +193,7 @@
   bool findIntroCert = false;
   for(; i < certificateName.size(); i++)
     {
-      if(certificateName.get(i).toUri() == string("WOT"))
+      if(certificateName.get(i).toEscapedString() == string("WOT"))
 	{
 	  findWot = true;
 	  break;
@@ -198,7 +205,7 @@
   
   for(; i < certificateName.size(); i++)
     {
-      if(certificateName.get(i).toUri() == string("INTRO-CERT"))
+      if(certificateName.get(i).toEscapedString() == string("INTRO-CERT"))
 	{
 	  findIntroCert = true;
 	  break;
diff --git a/src/sync-intro-certificate.h b/src/sync-intro-certificate.h
index db41627..cfc5596 100644
--- a/src/sync-intro-certificate.h
+++ b/src/sync-intro-certificate.h
@@ -11,10 +11,10 @@
 #ifndef SYNC_INTRO_CERTIFICATE_H
 #define SYNC_INTRO_CERTIFICATE_H
 
-#include <ndn.cxx/security/certificate/certificate.h>
-#include <ndn.cxx/security/certificate/identity-certificate.h>
+#include <ndn-cpp/security/certificate/certificate.hpp>
+#include <ndn-cpp/security/certificate/identity-certificate.hpp>
 
-class SyncIntroCertificate : public ndn::security::Certificate
+class SyncIntroCertificate : public ndn::Certificate
 {
 public:
   enum IntroType{
@@ -28,13 +28,13 @@
   SyncIntroCertificate (const ndn::Name& nameSpace,
                         const ndn::Name& keyName,
                         const ndn::Name& signerName,
-                        const ndn::Time& notBefore,
-                        const ndn::Time& notAfter,
-                        const ndn::security::Publickey& key,
+                        const ndn::MillisecondsSince1970& notBefore,
+                        const ndn::MillisecondsSince1970& notAfter,
+                        const ndn::PublicKey& key,
                         const IntroType& introType = PRODUCER);
   
   SyncIntroCertificate (const ndn::Name& nameSpace,
-                        const ndn::security::IdentityCertificate& identityCertificate,
+                        const ndn::IdentityCertificate& identityCertificate,
                         const ndn::Name& signerName,
                         const IntroType& introType);
   
@@ -47,7 +47,7 @@
   ~SyncIntroCertificate ()
   {}
   
-  ndn::Data &
+  ndn::Data&
   setName (const ndn::Name& name);
   
   inline virtual ndn::Name 
@@ -59,7 +59,7 @@
   { return m_introType; }
 
   static bool
-  isSyncIntroCertificate(const ndn::security::Certificate& certificate);
+  isSyncIntroCertificate(const ndn::Certificate& certificate);
 
 protected:
   ndn::Name m_keyName;
diff --git a/src/sync-logic.cc b/src/sync-logic.cc
index 06d142a..eccb3fa 100644
--- a/src/sync-logic.cc
+++ b/src/sync-logic.cc
@@ -31,6 +31,9 @@
 #include "sync-logging.h"
 #include "sync-state.h"
 
+#include <ndn-cpp/security/identity/basic-identity-storage.hpp>
+#include <ndn-cpp/security/identity/osx-private-key-storage.hpp>
+
 #include <boost/make_shared.hpp>
 #include <boost/foreach.hpp>
 #include <boost/lexical_cast.hpp>
@@ -39,6 +42,8 @@
 using namespace std;
 using namespace boost;
 using namespace ndn;
+using namespace ndn::ptr_lib;
+using namespace ndn::func_lib;
 
 INIT_LOGGER ("SyncLogic");
 
@@ -59,8 +64,7 @@
 {
 
   SyncLogic::SyncLogic (const Name& syncPrefix,
-                        Ptr<SyncPolicyManager> syncPolicyManager, 
-                        Ptr<Wrapper> handler,
+                        shared_ptr<SyncPolicyManager> syncPolicyManager, 
                         LogicUpdateCallback onUpdate,
                         LogicRemoveCallback onRemove)
     : m_state (new FullState)
@@ -70,7 +74,6 @@
     , m_onRemove (onRemove)
     , m_perBranch (false)
     , m_policyManager(syncPolicyManager)
-    , m_handler (handler)
 #ifndef NS3_MODULE
     , m_randomGenerator (static_cast<unsigned int> (std::time (0)))
     , m_rangeUniformRandom (m_randomGenerator, uniform_int<> (200,1000))
@@ -84,8 +87,19 @@
 #ifndef NS3_MODULE
   // In NS3 module these functions are moved to StartApplication method
 
-  m_handler->setInterestFilter (m_syncPrefix, 
-                                bind (&SyncLogic::respondSyncInterest, this, _1));
+  m_transport = make_shared<TcpTransport>();
+  m_face = make_shared<Face>(m_transport, make_shared<TcpTransport::ConnectionInfo>("localhost"));
+
+  connectToDaemon();
+
+  shared_ptr<BasicIdentityStorage> publicStorage = make_shared<BasicIdentityStorage>();
+  shared_ptr<OSXPrivateKeyStorage> privateStorage = make_shared<OSXPrivateKeyStorage>();
+  m_identityManager = make_shared<IdentityManager>(publicStorage, privateStorage);
+
+  m_syncRegisteredPrefixId = m_face->registerPrefix(m_syncPrefix, 
+                                                    bind(&SyncLogic::onSyncInterest, this, _1, _2, _3, _4), 
+                                                    bind(&SyncLogic::onSyncRegisterFailed, this, _1));
+
 
   m_scheduler.schedule (TIME_SECONDS (0), // no need to add jitter
                         bind (&SyncLogic::sendSyncInterest, this),
@@ -94,8 +108,7 @@
 }
 
 SyncLogic::SyncLogic (const Name& syncPrefix,
-                      Ptr<SyncPolicyManager> syncPolicyManager,
-                      Ptr<Wrapper> handler,
+                      shared_ptr<SyncPolicyManager> syncPolicyManager,
                       LogicPerBranchCallback onUpdateBranch)
   : m_state (new FullState)
   , m_syncInterestTable (TIME_SECONDS (m_syncInterestReexpress))
@@ -103,7 +116,6 @@
   , m_onUpdateBranch (onUpdateBranch)
   , m_perBranch(true)
   , m_policyManager(syncPolicyManager)
-  , m_handler (handler)
 #ifndef NS3_MODULE
   , m_randomGenerator (static_cast<unsigned int> (std::time (0)))
   , m_rangeUniformRandom (m_randomGenerator, uniform_int<> (200,1000))
@@ -116,9 +128,19 @@
 { 
 #ifndef NS3_MODULE
   // In NS3 module these functions are moved to StartApplication method
+
+  m_transport = make_shared<TcpTransport>();
+  m_face = make_shared<Face>(m_transport, make_shared<TcpTransport::ConnectionInfo>("localhost"));
+
+  connectToDaemon();
+
+  shared_ptr<BasicIdentityStorage> publicStorage = make_shared<BasicIdentityStorage>();
+  shared_ptr<OSXPrivateKeyStorage> privateStorage = make_shared<OSXPrivateKeyStorage>();
+  m_identityManager = make_shared<IdentityManager>(publicStorage, privateStorage);
   
-  m_handler->setInterestFilter (m_syncPrefix,
-                                bind (&SyncLogic::respondSyncInterest, this, _1));
+  m_syncRegisteredPrefixId = m_face->registerPrefix(m_syncPrefix, 
+                                                    bind(&SyncLogic::onSyncInterest, this, _1, _2, _3, _4), 
+                                                    bind(&SyncLogic::onSyncRegisterFailed, this, _1));
 
   m_scheduler.schedule (TIME_SECONDS (0), // no need to add jitter
                         bind (&SyncLogic::sendSyncInterest, this),
@@ -128,8 +150,32 @@
 
 SyncLogic::~SyncLogic ()
 {
-  m_handler->clearInterestFilter (Name(m_syncPrefix));
-  m_handler->shutdown();
+  m_face->removeRegisteredPrefix(m_syncRegisteredPrefixId);
+  m_face->shutdown();
+}
+
+void
+SyncLogic::connectToDaemon()
+{
+  //Hack! transport does not connect to daemon unless an interest is expressed.
+  Name name("/ndn");
+  shared_ptr<ndn::Interest> interest = make_shared<ndn::Interest>(name);
+  m_face->expressInterest(*interest, 
+                          bind(&SyncLogic::onConnectionData, this, _1, _2),
+                          bind(&SyncLogic::onConnectionDataTimeout, this, _1));
+}
+
+void
+SyncLogic::onConnectionData(const shared_ptr<const ndn::Interest>& interest,
+                            const shared_ptr<Data>& data)
+{
+  _LOG_DEBUG("onConnectionData");
+}
+
+void
+SyncLogic::onConnectionDataTimeout(const shared_ptr<const ndn::Interest>& interest)
+{
+  _LOG_DEBUG("onConnectionDataTimeout");
 }
 
 #ifdef NS3_MODULE
@@ -160,7 +206,7 @@
 void
 SyncLogic::stop()
 {
-  m_handler->clearInterestFilter (Name(m_syncPrefix));
+  m_face->removeRegisteredPrefix(m_syncRegisteredPrefixId);
   m_scheduler.cancel (REEXPRESSING_INTEREST);
   m_scheduler.cancel (DELAYED_INTEREST_PROCESSING);
 }
@@ -198,7 +244,10 @@
 }
 
 void
-SyncLogic::respondSyncInterest (ndn::Ptr<ndn::Interest> interest)
+SyncLogic::onSyncInterest (const shared_ptr<const Name>& prefix, 
+                           const shared_ptr<const ndn::Interest>& interest, 
+                           Transport& transport, 
+                           uint64_t registeredPrefixId)
 {
   _LOG_DEBUG("respondSyncInterest: " << interest->getName().toUri());
   string name = interest->getName().toUri();
@@ -228,11 +277,68 @@
 }
 
 void
-SyncLogic::respondSyncData (Ptr<Data> data)
+SyncLogic::onSyncRegisterFailed(const shared_ptr<const Name>& prefix)
+{
+  _LOG_DEBUG("Sync prefix registration failed!");
+}
+
+void
+SyncLogic::onSyncData(const shared_ptr<const ndn::Interest>& interest, 
+                      const shared_ptr<Data>& data,
+                      int stepCount,
+                      const OnVerified& onVerified,
+                      const OnVerifyFailed& onVerifyFailed)
+{
+  shared_ptr<ValidationRequest> nextStep = m_policyManager->checkVerificationPolicy(data, stepCount, onVerified, onVerifyFailed);
+
+  if (nextStep)
+    m_face->expressInterest
+      (*nextStep->interest_, 
+       bind(&SyncLogic::onSyncCert, this, _1, _2, nextStep), 
+       bind(&SyncLogic::onSyncCertTimeout, this, _1, onVerifyFailed, data, nextStep));
+}
+
+void
+SyncLogic::onSyncDataTimeout(const shared_ptr<const ndn::Interest>& interest, 
+                             int retry,
+                             int stepCount,
+                             const OnVerified& onVerified,
+                             const OnVerifyFailed& onVerifyFailed)
+{
+  if(retry > 0)
+    {
+      m_face->expressInterest(*interest, 
+                              bind(&SyncLogic::onSyncData,
+                                   this,
+                                   _1,
+                                   _2,     
+                                   stepCount,
+                                   onVerified,
+                                   onVerifyFailed),
+                              bind(&SyncLogic::onSyncDataTimeout, 
+                                   this,
+                                   _1,
+                                   retry - 1,
+                                   stepCount,
+                                   onVerified,
+                                   onVerifyFailed));
+    }
+  else
+    _LOG_DEBUG("Sync interest eventually times out!");
+}
+
+void
+SyncLogic::onSyncDataVerifyFailed(const shared_ptr<Data>& data)
+{
+  _LOG_DEBUG("Sync data cannot be verified!");
+}
+
+void
+SyncLogic::onSyncDataVerified(const shared_ptr<Data>& data)
 {
   string name = data->getName().toUri();
-  const char *wireData = data->content().buf();
-  size_t len = data->content().size();
+  const char* wireData = (const char*)data->getContent().buf();
+  size_t len = data->getContent().size();
 
   try
     {
@@ -262,26 +368,44 @@
 }
 
 void
-SyncLogic::onSyncDataTimeout(Ptr<Closure> closure, Ptr<ndn::Interest> interest, int retry)
+SyncLogic::onSyncCert(const shared_ptr<const ndn::Interest>& interest, 
+                      const shared_ptr<Data>& cert,
+                      shared_ptr<ValidationRequest> previousStep)
 {
-  if(retry > 0)
-    {
-      Ptr<Closure> newClosure = Ptr<Closure>(new Closure(closure->m_dataCallback,
-                                                         boost::bind(&SyncLogic::onSyncDataTimeout, 
-                                                                     this, 
-                                                                     _1, 
-                                                                     _2, 
-                                                                     retry - 1),
-                                                         closure->m_unverifiedCallback,
-                                                         closure->m_stepCount)
-                                             );
-      m_handler->sendInterest(interest, newClosure);
-    }
+  shared_ptr<ValidationRequest> nextStep = m_policyManager->checkVerificationPolicy(cert, 
+                                                                                    previousStep->stepCount_, 
+                                                                                    previousStep->onVerified_, 
+                                                                                    previousStep->onVerifyFailed_);
+
+  if (nextStep)
+    m_face->expressInterest
+      (*nextStep->interest_, 
+       bind(&SyncLogic::onSyncCert, this, _1, _2, nextStep), 
+       bind(&SyncLogic::onSyncCertTimeout, this, _1, previousStep->onVerifyFailed_, cert, nextStep));
 }
 
 void
-SyncLogic::onSyncDataUnverified()
-{}
+SyncLogic::onSyncCertTimeout(const ptr_lib::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(&SyncLogic::onSyncCert,
+                                   this,
+                                   _1,
+                                   _2,
+                                   nextStep),
+                              bind(&SyncLogic::onSyncCertTimeout,
+                                   this,
+                                   _1,
+                                   onVerifyFailed,
+                                   data,
+                                   nextStep));
+  else
+    onVerifyFailed(data);
+}
 
 void
 SyncLogic::processSyncInterest (const std::string &name, DigestConstPtr digest, bool timedProcessing/*=false*/)
@@ -506,7 +630,7 @@
       uint32_t counter = 0;
       while (m_syncInterestTable.size () > 0)
         {
-          Interest interest = m_syncInterestTable.pop ();
+          Sync::Interest interest = m_syncInterestTable.pop ();
 
           if (!interest.m_unknown)
             {
@@ -618,18 +742,14 @@
                         bind (&SyncLogic::sendSyncInterest, this),
                         REEXPRESSING_INTEREST);
 
-  Ptr<ndn::Interest> interestPtr = Ptr<ndn::Interest>(new ndn::Interest(os.str()));
-  Ptr<Closure> closure = Ptr<Closure> (new Closure(boost::bind(&SyncLogic::respondSyncData, 
-                                                               this, 
-                                                               _1),
-						   boost::bind(&SyncLogic::onSyncDataTimeout,
-                                                               this,
-                                                               _1, 
-                                                               _2,
-                                                               0),
-						   boost::bind(&SyncLogic::onSyncDataUnverified,
-                                                               this)));
-  m_handler->sendInterest(interestPtr, closure);
+  shared_ptr<ndn::Interest> interest = make_shared<ndn::Interest>(os.str());
+
+  OnVerified onVerified = bind(&SyncLogic::onSyncDataVerified, this, _1);
+  OnVerifyFailed onVerifyFailed = bind(&SyncLogic::onSyncDataVerifyFailed, this, _1);
+
+  m_face->expressInterest(*interest,
+                          bind(&SyncLogic::onSyncData, this, _1, _2, 0, onVerified, onVerifyFailed),
+                          bind(&SyncLogic::onSyncDataTimeout, this, _1, 1, 0, onVerified, onVerifyFailed));
 }
 
 void
@@ -650,18 +770,14 @@
                             REEXPRESSING_RECOVERY_INTEREST);
     }
 
-  Ptr<ndn::Interest> interestPtr = Ptr<ndn::Interest>(new ndn::Interest(os.str()));
-  Ptr<Closure> closure = Ptr<Closure> (new Closure(boost::bind(&SyncLogic::respondSyncData, 
-                                                               this, 
-                                                               _1),
-						   boost::bind(&SyncLogic::onSyncDataTimeout,
-                                                               this,
-                                                               _1, 
-                                                               _2,
-                                                               0),
-						   boost::bind(&SyncLogic::onSyncDataUnverified,
-                                                               this)));
-  m_handler->sendInterest (interestPtr, closure);
+  shared_ptr<ndn::Interest> interest = make_shared<ndn::Interest>(os.str());
+
+  OnVerified onVerified = bind(&SyncLogic::onSyncDataVerified, this, _1);
+  OnVerifyFailed onVerifyFailed = bind(&SyncLogic::onSyncDataVerifyFailed, this, _1);
+
+  m_face->expressInterest(*interest,
+                          bind(&SyncLogic::onSyncData, this, _1, _2, 0, onVerified, onVerifyFailed),
+                          bind(&SyncLogic::onSyncDataTimeout, this, _1, 1, 0, onVerified, onVerifyFailed));
 }
 
 
@@ -682,13 +798,19 @@
   int size = ssm.ByteSize();
   char *wireData = new char[size];
   ssm.SerializeToArray(wireData, size);
-  Blob blob(wireData, size);
+  Blob blob((const uint8_t*)wireData, size);
   Name dataName(name);
   Name signingIdentity = m_policyManager->inferSigningIdentity(dataName);
-  m_handler->publishDataByIdentity (dataName,
-                                    blob,
-                                    signingIdentity,
-                                    m_syncResponseFreshness); // in NS-3 it doesn't have any effect... yet
+
+  shared_ptr<Data> syncData = make_shared<Data>(dataName);
+  syncData->setContent(blob.buf(), blob.size());
+  syncData->getMetaInfo().setTimestampMilliseconds(time(NULL) * 1000.0);
+  
+  Name certificateName = m_identityManager->getDefaultCertificateNameForIdentity(signingIdentity);
+  m_identityManager->signByCertificate(*syncData, certificateName);
+  
+  m_transport->send(*syncData->wireEncode());
+  
   delete []wireData;
 
   // checking if our own interest got satisfied
diff --git a/src/sync-logic.h b/src/sync-logic.h
index 3b7df8c..b9b3057 100644
--- a/src/sync-logic.h
+++ b/src/sync-logic.h
@@ -29,7 +29,9 @@
 #include <memory>
 #include <map>
 
-#include <ndn.cxx/wrapper/wrapper.h>
+#include <ndn-cpp/face.hpp>
+#include <ndn-cpp/security/identity/identity-manager.hpp>
+
 #include "sync-interest-table.h"
 #include "sync-diff-state.h"
 #include "sync-full-state.h"
@@ -84,14 +86,12 @@
    * the app data when new remote names are learned
    */
   SyncLogic (const ndn::Name& syncPrefix,
-             ndn::Ptr<SyncPolicyManager> syncPolicyManager,
-             ndn::Ptr<ndn::Wrapper> handler,
+             ndn::ptr_lib::shared_ptr<SyncPolicyManager> syncPolicyManager,
              LogicUpdateCallback onUpdate,
              LogicRemoveCallback onRemove);
 
   SyncLogic (const ndn::Name& syncPrefix,
-             ndn::Ptr<SyncPolicyManager> syncPolicyManager,
-             ndn::Ptr<ndn::Wrapper> handler,
+             ndn::ptr_lib::shared_ptr<SyncPolicyManager> syncPolicyManager,
              LogicPerBranchCallback onUpdateBranch);
 
   ~SyncLogic ();
@@ -105,14 +105,14 @@
    * @brief respond to the Sync Interest; a lot of logic needs to go in here
    * @param interest the Sync Interest in string format
    */
-  void respondSyncInterest (ndn::Ptr<ndn::Interest>);
+  void respondSyncInterest (ndn::ptr_lib::shared_ptr<ndn::Interest> interest);
 
   /**
    * @brief process the fetched sync data
    * @param name the data name
    * @param dataBuffer the sync data
    */
-  void respondSyncData (ndn::Ptr<ndn::Data> data);
+  void respondSyncData (ndn::ptr_lib::shared_ptr<ndn::Data> data);
 
   /**
    * @brief remove a participant's subtree from the sync tree
@@ -144,13 +144,57 @@
 
 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
   delayedChecksLoop ();
 
   void
-  onSyncDataTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest, int retry);
+  onSyncInterest (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 registeredPrefixId);
 
   void
-  onSyncDataUnverified();
+  onSyncRegisterFailed(const ndn::ptr_lib::shared_ptr<const ndn::Name>& prefix);
+
+  void
+  onSyncData(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);
+
+  void
+  onSyncDataTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, 
+                    int retry,
+                    int stepCount,
+                    const ndn::OnVerified& onVerified,
+                    const ndn::OnVerifyFailed& onVerifyFailed);
+
+  void
+  onSyncDataVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data);
+
+  void
+  onSyncDataVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data);
+
+  void
+  onSyncCert(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
+  onSyncCertTimeout(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
   processSyncInterest (const std::string &name,
@@ -203,8 +247,11 @@
   LogicRemoveCallback m_onRemove;
   LogicPerBranchCallback m_onUpdateBranch;
   bool m_perBranch;
-  ndn::Ptr<SyncPolicyManager> m_policyManager;
-  ndn::Ptr<ndn::Wrapper> m_handler;
+  ndn::ptr_lib::shared_ptr<SyncPolicyManager> 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;
+  uint64_t m_syncRegisteredPrefixId;
 
   Scheduler m_scheduler;
 
diff --git a/src/sync-policy-manager.cc b/src/sync-policy-manager.cc
index a788b66..d0850b6 100644
--- a/src/sync-policy-manager.cc
+++ b/src/sync-policy-manager.cc
@@ -8,14 +8,17 @@
  * Author: Yingdi Yu <yingdi@cs.ucla.edu>
  */
 
-#include "sync-policy-manager.h"
-
 #include "sync-intro-certificate.h"
 #include "sync-logging.h"
-#include <ndn.cxx/security/identity/identity-manager.h>
+#include <ndn-cpp/security/identity/basic-identity-storage.hpp>
+#include <ndn-cpp/security/identity/osx-private-key-storage.hpp>
+#include <ndn-cpp/sha256-with-rsa-signature.hpp>
+#include <ndn-cpp/security/signature/sha256-with-rsa-handler.hpp>
+
+#include "sync-policy-manager.h"
 
 using namespace ndn;
-using namespace ndn::security;
+using namespace ndn::ptr_lib;
 using namespace std;
 
 INIT_LOGGER("SyncPolicyManager");
@@ -28,20 +31,52 @@
   , m_signingCertificateName(signingCertificateName.getPrefix(signingCertificateName.size()-1))
   , m_syncPrefix(syncPrefix)
   , m_stepLimit(stepLimit)
-  , m_identityManager(Ptr<security::IdentityManager>::Create())
 {
+  m_transport = make_shared<TcpTransport>();
+  m_face = make_shared<Face>(m_transport, make_shared<TcpTransport::ConnectionInfo>("localhost"));
+
+  connectToDaemon();
+  
+  shared_ptr<IdentityStorage> publicStorage = make_shared<BasicIdentityStorage>();
+  shared_ptr<PrivateKeyStorage> privateStorage = make_shared<OSXPrivateKeyStorage>();
+  m_identityManager = make_shared<IdentityManager>(publicStorage, privateStorage);
+
   Name wotPrefix = syncPrefix;
   wotPrefix.append("WOT");
   m_syncPrefixRegex = Regex::fromName(syncPrefix);
   m_wotPrefixRegex = Regex::fromName(wotPrefix);
-  m_chatDataPolicy = Ptr<IdentityPolicyRule>(new IdentityPolicyRule("^[^<%F0.>]*<%F0.>([^<chronos>]*)<chronos><>",
-                                                                    "^([^<KEY>]*)<KEY>(<>*)[<dsk-.*><ksk-.*>]<ID-CERT>$",
-                                                                    "==", "\\1", "\\1", true));  
+  m_chatDataPolicy = make_shared<IdentityPolicyRule>("^[^<%F0.>]*<%F0.>([^<chronos>]*)<chronos><>",
+                                                              "^([^<KEY>]*)<KEY>(<>*)[<dsk-.*><ksk-.*>]<ID-CERT>$",
+                                                              "==", "\\1", "\\1", true);  
 }
   
 SyncPolicyManager::~SyncPolicyManager()
 {}
 
+void
+SyncPolicyManager::connectToDaemon()
+{
+  //Hack! transport does not connect to daemon unless an interest is expressed.
+  Name name("/ndn");
+  shared_ptr<ndn::Interest> interest = make_shared<ndn::Interest>(name);
+  m_face->expressInterest(*interest, 
+                          bind(&SyncPolicyManager::onConnectionData, this, _1, _2),
+                          bind(&SyncPolicyManager::onConnectionDataTimeout, this, _1));
+}
+
+void
+SyncPolicyManager::onConnectionData(const shared_ptr<const ndn::Interest>& interest,
+                                    const shared_ptr<Data>& data)
+{
+  _LOG_DEBUG("onConnectionData");
+}
+
+void
+SyncPolicyManager::onConnectionDataTimeout(const shared_ptr<const ndn::Interest>& interest)
+{
+  _LOG_DEBUG("onConnectionDataTimeout");
+}
+
 bool 
 SyncPolicyManager::skipVerifyAndTrust (const Data& data)
 { return false; }
@@ -50,104 +85,82 @@
 SyncPolicyManager::requireVerify (const Data& data)
 { return true; }
 
-Ptr<ValidationRequest>
-SyncPolicyManager::checkVerificationPolicy(Ptr<Data> data, 
-					   const int& stepCount, 
-					   const DataCallback& verifiedCallback,
-					   const UnverifiedCallback& unverifiedCallback)
+shared_ptr<ValidationRequest>
+SyncPolicyManager::checkVerificationPolicy(const shared_ptr<Data>& data, 
+					   int stepCount, 
+					   const OnVerified& onVerified,
+					   const OnVerifyFailed& onVerifyFailed)
 {
-// #ifdef _DEBUG
-//   _LOG_DEBUG("checkVerificationPolicy");
-//   verifiedCallback(data);
-//   return NULL;
-// #else
-  //TODO:
   if(stepCount > m_stepLimit)
     {
-      unverifiedCallback(data);
-      return NULL;
+      onVerifyFailed(data);
+      return SYNC_POLICY_MANAGER_NULL_VALIDATION_REQUEST_PTR;
     }
 
-  Ptr<const signature::Sha256WithRsa> sha256sig = DynamicCast<const signature::Sha256WithRsa> (data->getSignature());
-  if(KeyLocator::KEYNAME != sha256sig->getKeyLocator().getType())
+  const Sha256WithRsaSignature* sigPtr = dynamic_cast<const Sha256WithRsaSignature*> (data->getSignature());
+  if(ndn_KeyLocatorType_KEYNAME != sigPtr->getKeyLocator().getType())
     {
-      unverifiedCallback(data);
-      return NULL;
+      onVerifyFailed(data);
+      return SYNC_POLICY_MANAGER_NULL_VALIDATION_REQUEST_PTR;
     }
 
-  const Name& keyLocatorName = sha256sig->getKeyLocator().getKeyName();
-  // _LOG_DEBUG("data name: " << data->getName());
-  // _LOG_DEBUG("signer name: " << keyLocatorName);
+  const Name& keyLocatorName = sigPtr->getKeyLocator().getKeyName();
   
   // if data is intro cert
   if(m_wotPrefixRegex->match(data->getName()))
     {
       // _LOG_DEBUG("Intro Cert");
       Name keyName = IdentityCertificate::certificateNameToPublicKeyName(keyLocatorName);
-      map<Name, Publickey>::const_iterator it = m_trustedIntroducers.find(keyName);
+      map<string, PublicKey>::const_iterator it = m_trustedIntroducers.find(keyName.toUri());
       if(m_trustedIntroducers.end() != it)
 	{
-	  if(verifySignature(*data, it->second))
-	    verifiedCallback(data);
+	  if(Sha256WithRsaHandler::verifySignature(*data, it->second))
+	    onVerified(data);
 	  else
-	    unverifiedCallback(data);
-	  return NULL;
+	    onVerifyFailed(data);
+	  return SYNC_POLICY_MANAGER_NULL_VALIDATION_REQUEST_PTR;
 	}
       else
-	return prepareRequest(keyName, true, data, stepCount, verifiedCallback, unverifiedCallback);
+	return prepareRequest(keyName, true, data, stepCount, onVerified, onVerifyFailed);
     }
 
   // if data is sync data or chat data
   if(m_syncPrefixRegex->match(data->getName()) || m_chatDataPolicy->satisfy(*data))
     {
-      // _LOG_DEBUG("Sync/Chat Data");
       Name keyName = IdentityCertificate::certificateNameToPublicKeyName(keyLocatorName);
-      // _LOG_DEBUG("keyName: " << keyName.toUri());
 
-      map<Name, Publickey>::const_iterator it = m_trustedIntroducers.find(keyName);
+      map<string, PublicKey>::const_iterator it = m_trustedIntroducers.find(keyName.toUri());
       if(m_trustedIntroducers.end() != it)
 	{
-          // _LOG_DEBUG("Find trusted introducer!");
-	  if(verifySignature(*data, it->second))
-	    verifiedCallback(data);
+	  if(Sha256WithRsaHandler::verifySignature(*data, it->second))
+	    onVerified(data);
 	  else
-	    unverifiedCallback(data);
-	  return NULL;
+	    onVerifyFailed(data);
+	  return SYNC_POLICY_MANAGER_NULL_VALIDATION_REQUEST_PTR;
 	}
 
-      it = m_trustedProducers.find(keyName);
+      it = m_trustedProducers.find(keyName.toUri());
       if(m_trustedProducers.end() != it)
 	{
-          // _LOG_DEBUG("Find trusted producer!");
-	  if(verifySignature(*data, it->second))
-	    verifiedCallback(data);
+	  if(Sha256WithRsaHandler::verifySignature(*data, it->second))
+	    onVerified(data);
 	  else
-	    unverifiedCallback(data);
-	  return NULL;
+	    onVerifyFailed(data);
+	  return SYNC_POLICY_MANAGER_NULL_VALIDATION_REQUEST_PTR;
 	}
 
-      // _LOG_DEBUG("Did not find any trusted one!");
-      return prepareRequest(keyName, false, data, stepCount, verifiedCallback, unverifiedCallback);
+      return prepareRequest(keyName, false, data, stepCount, onVerified, onVerifyFailed);
     }
   
-  unverifiedCallback(data);
-  return NULL;
-// #endif
+  onVerifyFailed(data);
+  return SYNC_POLICY_MANAGER_NULL_VALIDATION_REQUEST_PTR;
 }
 
 bool 
 SyncPolicyManager::checkSigningPolicy(const Name& dataName, 
 				      const Name& certificateName)
 { 
-
   return true;
-
-// #ifdef _DEBUG
-//   _LOG_DEBUG("checkSigningPolicy");
-//   return true;
-// #else
-  // return (m_syncPrefixRegex->match(dataName) && certificateName.getPrefix(certificateName.size()-1) == m_signingCertificateName) ? true : false; 
-// #endif
 }
     
 Name 
@@ -159,9 +172,11 @@
 {
   // _LOG_DEBUG("Add intro/producer: " << identityCertificate.getPublicKeyName());
   if(isIntroducer)
-    m_trustedIntroducers.insert(pair <Name, Publickey > (identityCertificate.getPublicKeyName(), identityCertificate.getPublicKeyInfo()));
+    m_trustedIntroducers.insert(pair <string, PublicKey > (identityCertificate.getPublicKeyName().toUri(),
+                                                           identityCertificate.getPublicKeyInfo()));
   else
-    m_trustedProducers.insert(pair <Name, Publickey > (identityCertificate.getPublicKeyName(), identityCertificate.getPublicKeyInfo()));
+    m_trustedProducers.insert(pair <string, PublicKey > (identityCertificate.getPublicKeyName().toUri(),
+                                                         identityCertificate.getPublicKeyInfo()));
 }
 
 void
@@ -187,34 +202,34 @@
 }
 
 
-Ptr<const vector<Name> >
+shared_ptr<const vector<Name> >
 SyncPolicyManager::getAllIntroducerName()
 {
-  Ptr<vector<Name> > nameList = Ptr<vector<Name> >(new vector<Name>);
+  shared_ptr<vector<Name> > nameList = make_shared<vector<Name> >();
   
-  map<Name, Publickey>::iterator it =  m_trustedIntroducers.begin();
+  map<string, PublicKey>::iterator it =  m_trustedIntroducers.begin();
   for(; it != m_trustedIntroducers.end(); it++)
-    nameList->push_back(it->first);
+    nameList->push_back(Name(it->first));
   
   return nameList;
 }
 
-Ptr<ValidationRequest>
+shared_ptr<ValidationRequest>
 SyncPolicyManager::prepareRequest(const Name& keyName, 
 				  bool forIntroducer,
-				  Ptr<Data> data,
+				  shared_ptr<Data> data,
 				  const int & stepCount, 
-				  const DataCallback& verifiedCallback,
-				  const UnverifiedCallback& unverifiedCallback)
+				  const OnVerified& onVerified,
+				  const OnVerifyFailed& onVerifyFailed)
 {
-  Ptr<Name> interestPrefixName = Ptr<Name>(new Name(m_syncPrefix));
+  shared_ptr<Name> interestPrefixName = make_shared<Name>(m_syncPrefix);
   interestPrefixName->append("WOT").append(keyName).append("INTRO-CERT");
 
-  Ptr<const std::vector<ndn::Name> > nameList = getAllIntroducerName();
+  shared_ptr<const vector<Name> > nameList = getAllIntroducerName();
   if(0 == nameList->size())
     {
-      unverifiedCallback(data);
-      return NULL;
+      onVerifyFailed(data);
+      return SYNC_POLICY_MANAGER_NULL_VALIDATION_REQUEST_PTR;
     }
 
   Name interestName = *interestPrefixName;
@@ -223,50 +238,70 @@
   if(forIntroducer)
     interestName.append("INTRODUCER");
 
-  Ptr<Interest> interest = Ptr<Interest>(new Interest(interestName));
+  shared_ptr<ndn::Interest> interest = make_shared<ndn::Interest>(interestName);
   // _LOG_DEBUG("send interest for intro cert: " << interest->getName());
-  interest->setChildSelector(Interest::CHILD_RIGHT);
+  interest->setChildSelector(ndn_Interest_CHILD_SELECTOR_RIGHT);
 
-  DataCallback requestedCertVerifiedCallback = boost::bind(&SyncPolicyManager::onIntroCertVerified, 
-							   this, 
-							   _1,
-							   forIntroducer, 
-							   data,
-							   verifiedCallback,
-							   unverifiedCallback);
+  OnVerified requestedCertVerifiedCallback = boost::bind(&SyncPolicyManager::onIntroCertVerified, 
+                                                         this, 
+                                                         _1,
+                                                         forIntroducer, 
+                                                         data,
+                                                         onVerified,
+                                                         onVerifyFailed);
                                                              
-  UnverifiedCallback requestedCertUnverifiedCallback = boost::bind(&SyncPolicyManager::onIntroCertUnverified, 
-								   this, 
-								   _1, 
-								   interestPrefixName,
-								   forIntroducer,
-								   nameList,
-								   1,
-								   data,
-								   verifiedCallback,
-								   unverifiedCallback);
+  OnVerifyFailed requestedCertUnverifiedCallback = boost::bind(&SyncPolicyManager::onIntroCertVerifyFailed, 
+                                                               this, 
+                                                               _1, 
+                                                               interestPrefixName,
+                                                               forIntroducer,
+                                                               nameList,
+                                                               1,
+                                                               data,
+                                                               onVerified,
+                                                               onVerifyFailed);
 
     
-  Ptr<ValidationRequest> nextStep = Ptr<ValidationRequest>(new ValidationRequest(interest, 
-										 requestedCertVerifiedCallback,
-										 requestedCertUnverifiedCallback,
-										 1,
-										 m_stepLimit-1)
-							   );
+  shared_ptr<ValidationRequest> nextStep = make_shared<ValidationRequest>(interest, 
+                                                                          requestedCertVerifiedCallback,
+                                                                          requestedCertUnverifiedCallback,
+                                                                          1,
+                                                                          m_stepLimit-1);
   return nextStep;
 }
 
 void
-SyncPolicyManager::onIntroCertVerified(Ptr<Data> introCertificateData,
-				       bool forIntroducer,
-				       Ptr<Data> originalData,
-				       const DataCallback& verifiedCallback,
-				       const UnverifiedCallback& unverifiedCallback)
+SyncPolicyManager::OnIntroCertInterest(const shared_ptr<const Name>& prefix, 
+                                       const shared_ptr<const ndn::Interest>& interest, 
+                                       Transport& transport, 
+                                       uint64_t registeredPrefixId)
 {
-  Ptr<SyncIntroCertificate> introCertificate = Ptr<SyncIntroCertificate>(new SyncIntroCertificate(*introCertificateData));
+  map<string, Data>::const_iterator it = m_introCert.find(prefix->toUri());
+
+  if(m_introCert.end() != it)
+    {
+      Blob encodedData = it->second.wireEncode();
+      transport.send(*encodedData);
+    }
+}
+
+void
+SyncPolicyManager::OnIntroCertRegisterFailed(const shared_ptr<const Name>& prefix)
+{
+}
+
+void
+SyncPolicyManager::onIntroCertVerified(const shared_ptr<Data>& introCertificateData,
+				       bool forIntroducer,
+				       shared_ptr<Data> originalData,
+				       const OnVerified& onVerified,
+				       const OnVerifyFailed& onVerifyFailed)
+{
+  shared_ptr<SyncIntroCertificate> introCertificate = make_shared<SyncIntroCertificate>(*introCertificateData);
   if(forIntroducer)
     {
-      m_trustedIntroducers.insert(pair <Name, Publickey > (introCertificate->getPublicKeyName(), introCertificate->getPublicKeyInfo()));
+      m_trustedIntroducers.insert(pair <string, PublicKey > (introCertificate->getPublicKeyName().toUri(),
+                                                             introCertificate->getPublicKeyInfo()));
       SyncIntroCertificate syncIntroCertificate(m_syncPrefix,
                                                 introCertificate->getPublicKeyName(),
                                                 m_identityManager->getDefaultKeyNameForIdentity(m_signingIdentity),
@@ -274,15 +309,32 @@
                                                 introCertificate->getNotAfter(),
                                                 introCertificate->getPublicKeyInfo(),
                                                 SyncIntroCertificate::INTRODUCER);
-                                                // : SyncIntroCertificate::PRODUCER)
-      ndn::Name certName = m_identityManager->getDefaultCertificateNameByIdentity(m_signingIdentity);
+
+      Name certName = m_identityManager->getDefaultCertificateNameForIdentity(m_signingIdentity);
       _LOG_DEBUG("Publish Intro Certificate on Verified: " << syncIntroCertificate.getName());
       m_identityManager->signByCertificate(syncIntroCertificate, certName);
-      m_handler->putToNdnd(*syncIntroCertificate.encodeToWire());
+
+      m_transport->send(*syncIntroCertificate.wireEncode());
+
+      // Name prefix = syncIntroCertificate.getName().getPrefix(syncIntroCertificate.getName().size()-1);
+
+      // map<string, Data>::const_iterator it = m_introCert.find(prefix.toEscapedString());
+      // if(m_introCert.end() != it)
+      //   {
+      //     it->second = syncIntroCertificate;
+      //   }
+      // else
+      //   {         
+      //     m_introCert.insert(pair <string, Data> (prefix.toEscapedString(), syncIntroCertificate));
+      //     m_face->registerPrefix(prefix, 
+      //                           boost::bind(&SyncPolicyManager::onIntroCertInterest, this, _1, _2, _3, _4), 
+      //                           boost::bind(&SyncPolicyManager::onIntroCertRegisterFailed, this, _1));
+      //   }
     }
   else
     {
-      m_trustedProducers.insert(pair <Name, Publickey > (introCertificate->getPublicKeyName(), introCertificate->getPublicKeyInfo()));
+      m_trustedProducers.insert(pair <string, PublicKey > (introCertificate->getPublicKeyName().toUri(), 
+                                                           introCertificate->getPublicKeyInfo()));
       SyncIntroCertificate syncIntroCertificate(m_syncPrefix,
                                                 introCertificate->getPublicKeyName(),
                                                 m_identityManager->getDefaultKeyNameForIdentity(m_signingIdentity),
@@ -290,99 +342,161 @@
                                                 introCertificate->getNotAfter(),
                                                 introCertificate->getPublicKeyInfo(),
                                                 SyncIntroCertificate::PRODUCER);
-      // : SyncIntroCertificate::PRODUCER)
-      ndn::Name certName = m_identityManager->getDefaultCertificateNameByIdentity(m_signingIdentity);
+
+      Name certName = m_identityManager->getDefaultCertificateNameForIdentity(m_signingIdentity);
       _LOG_DEBUG("Publish Intro Certificate on Verified: " << syncIntroCertificate.getName());
       m_identityManager->signByCertificate(syncIntroCertificate, certName);
-      m_handler->putToNdnd(*syncIntroCertificate.encodeToWire());
+      
+      m_transport->send(*syncIntroCertificate.wireEncode());
+
+      // Name prefix = syncIntroCertificate.getName().getPrefix(syncIntroCertificate.getName().size()-1);
+
+      // map<string, Data>::const_iterator it = m_introCert.find(prefix.toEscapedString());
+      // if(m_introCert.end() != it)
+      //   {
+      //     it->second = syncIntroCertificate;
+      //   }
+      // else
+      //   {
+      //     m_introCert.insert(pair <string, Data> (prefix.toEscapedString(), syncIntroCertificate));
+      //     m_face->registerPrefix(prefix, 
+      //                           boost::bind(&SyncPolicyManager::onIntroCertInterest, this, _1, _2, _3, _4), 
+      //                           boost::bind(&SyncPolicyManager::onIntroCertRegisterFailed, this, _1));
+      //   }
     }
 
-  if(verifySignature(*originalData, introCertificate->getPublicKeyInfo()))      
-    verifiedCallback(originalData);    
+  if(Sha256WithRsaHandler::verifySignature(*originalData, introCertificate->getPublicKeyInfo()))      
+    onVerified(originalData);    
   else
-    unverifiedCallback(originalData);
+    onVerifyFailed(originalData);
 }
 
 void 
-SyncPolicyManager::onIntroCertUnverified(Ptr<Data> introCertificateData,
-					 Ptr<Name> interestPrefixName,
-					 bool forIntroducer,
-					 Ptr<const std::vector<ndn::Name> > introNameList,
-					 const int& nextIntroducerIndex,
-					 Ptr<Data> originalData,
-					 const DataCallback& verifiedCallback,
-					 const UnverifiedCallback& unverifiedCallback)
+SyncPolicyManager::onIntroCertVerifyFailed(const shared_ptr<Data>& introCertificateData,
+                                           shared_ptr<Name> interestPrefixName,
+                                           bool forIntroducer,
+                                           shared_ptr<const vector<Name> > introNameList,
+                                           int nextIntroducerIndex,
+                                           shared_ptr<Data> originalData,
+                                           const OnVerified& onVerified,
+                                           const OnVerifyFailed& onVerifyFailed)
 {
   Name interestName = *interestPrefixName;
   if(nextIntroducerIndex < introNameList->size())
     interestName.append(introNameList->at(nextIntroducerIndex));
   else
-    unverifiedCallback(originalData);
+    onVerifyFailed(originalData);
 
   if(forIntroducer)
     interestName.append("INTRODUCER");
   
-  Ptr<Interest> interest = Ptr<Interest>(new Interest(interestName));
-  interest->setChildSelector(Interest::CHILD_RIGHT);
+  shared_ptr<ndn::Interest> interest = make_shared<ndn::Interest>(interestName);
+  interest->setChildSelector(ndn_Interest_CHILD_SELECTOR_RIGHT);
 
-  DataCallback requestedCertVerifiedCallback = boost::bind(&SyncPolicyManager::onIntroCertVerified, 
-							   this, 
-							   _1,
-							   forIntroducer, 
-							   originalData,
-							   verifiedCallback,
-							   unverifiedCallback);
-    
-  UnverifiedCallback requestedCertUnverifiedCallback = boost::bind(&SyncPolicyManager::onIntroCertUnverified, 
-								   this, 
-								   _1,
-								   interestPrefixName,
-								   forIntroducer,
-								   introNameList,
-								   nextIntroducerIndex + 1,
-								   originalData, 
-								   verifiedCallback,
-								   unverifiedCallback);
-  
-  TimeoutCallback requestedCertTimeoutCallback = boost::bind(&SyncPolicyManager::onIntroCertTimeOut, 
-							     this, 
-							     _1, 
-							     _2, 
-							     1,
-							     requestedCertUnverifiedCallback,
-							     originalData);
-      
-  Ptr<Closure> closure = Ptr<Closure> (new Closure(requestedCertVerifiedCallback,
-						   requestedCertTimeoutCallback,
-						   requestedCertUnverifiedCallback,
-						   m_stepLimit-1)
-				       );
-    
-  m_handler->sendInterest(interest, closure);
+  OnVerified onRecursiveVerified = boost::bind(&SyncPolicyManager::onIntroCertVerified, 
+                                      this, 
+                                      _1,
+                                      forIntroducer, 
+                                      originalData,
+                                      onVerified,
+                                      onVerifyFailed);
+
+  OnVerifyFailed onRecursiveVerifyFailed = boost::bind(&SyncPolicyManager::onIntroCertVerifyFailed, 
+                                              this, 
+                                              _1,
+                                              interestPrefixName,
+                                              forIntroducer,
+                                              introNameList,
+                                              nextIntroducerIndex + 1,
+                                              originalData, 
+                                              onVerified,
+                                              onVerifyFailed);
+        
+  m_face->expressInterest(*interest, 
+                          boost::bind(&SyncPolicyManager::onIntroCertData,
+                                      this,
+                                      _1,
+                                      _2,     
+                                      m_stepLimit-1,
+                                      onRecursiveVerified,
+                                      onRecursiveVerifyFailed,
+                                      originalData,
+                                      onVerifyFailed),
+                          boost::bind(&SyncPolicyManager::onIntroCertTimeout, 
+                                      this,
+                                      _1,
+                                      1,
+                                      m_stepLimit-1,
+                                      onRecursiveVerified,
+                                      onRecursiveVerifyFailed,
+                                      originalData,
+                                      onVerifyFailed));
 }
 
 void
-SyncPolicyManager::onIntroCertTimeOut(Ptr<Closure> closure, 
-				      Ptr<Interest> interest, 
+SyncPolicyManager::onIntroCertData(const shared_ptr<const ndn::Interest> &interest,
+                                   const shared_ptr<Data>& introCertificateData,
+                                   int stepCount,
+                                   const OnVerified& onRecursiveVerified,
+                                   const OnVerifyFailed& onRecursiveVerifyFailed,
+                                   shared_ptr<Data> originalData,
+                                   const OnVerifyFailed& onVerifyFailed)
+{
+  shared_ptr<ValidationRequest> nextStep = checkVerificationPolicy(introCertificateData, stepCount, onRecursiveVerified, onRecursiveVerifyFailed);
+  if (nextStep)
+    m_face->expressInterest
+      (*nextStep->interest_, 
+       boost::bind(&SyncPolicyManager::onIntroCertData, 
+                   this, 
+                   _1, 
+                   _2,
+                   nextStep->stepCount_,
+                   nextStep->onVerified_, 
+                   nextStep->onVerifyFailed_,
+                   introCertificateData,
+                   onRecursiveVerifyFailed), 
+       boost::bind(&SyncPolicyManager::onIntroCertTimeout, 
+                   this, 
+                   _1, 
+                   nextStep->retry_, 
+                   nextStep->stepCount_, 
+                   nextStep->onVerified_, 
+                   nextStep->onVerifyFailed_,
+                   introCertificateData,
+                   onRecursiveVerifyFailed));
+}
+
+void
+SyncPolicyManager::onIntroCertTimeout(const shared_ptr<const ndn::Interest>& interest, 
 				      int retry, 
-				      const UnverifiedCallback& unverifiedCallback,
-				      Ptr<Data> data)
+                                      int stepCount,
+                                      const OnVerified& onRecursiveVerified,
+                                      const OnVerifyFailed& onRecursiveVerifyFailed,
+                                      shared_ptr<Data> originalData,
+                                      const OnVerifyFailed& onVerifyFailed)
 {
   if(retry > 0)
     {
-      Ptr<Closure> newClosure = Ptr<Closure>(new Closure(closure->m_dataCallback,
-							 boost::bind(&SyncPolicyManager::onIntroCertTimeOut, 
-								     this, 
-								     _1, 
-								     _2, 
-								     retry - 1, 
-								     unverifiedCallback,
-								     data),
-							 closure->m_unverifiedCallback,
-							 closure->m_stepCount)
-					     );
-      m_handler->sendInterest(interest, newClosure);
+      m_face->expressInterest(*interest, 
+                              boost::bind(&SyncPolicyManager::onIntroCertData, 
+                                          this,
+                                          _1,
+                                          _2,
+                                          stepCount,
+                                          onRecursiveVerified,
+                                          onRecursiveVerifyFailed,
+                                          originalData,
+                                          onVerifyFailed),
+                              boost::bind(&SyncPolicyManager::onIntroCertTimeout, 
+                                          this,
+                                          _1,
+                                          retry - 1,
+                                          stepCount,
+                                          onRecursiveVerified,
+                                          onRecursiveVerifyFailed,
+                                          originalData,
+                                          onVerifyFailed));
     }
   else
-    unverifiedCallback(data);
+    onVerifyFailed(originalData);
 }
diff --git a/src/sync-policy-manager.h b/src/sync-policy-manager.h
index ad4345a..b7ec402 100644
--- a/src/sync-policy-manager.h
+++ b/src/sync-policy-manager.h
@@ -11,15 +11,19 @@
 #ifndef SYNC_POLICY_MANAGER_H
 #define SYNC_POLICY_MANAGER_H
 
-#include <ndn.cxx/security/policy/policy-manager.h>
-#include <ndn.cxx/security/policy/identity-policy-rule.h>
-#include <ndn.cxx/security/certificate/identity-certificate.h>
-#include <ndn.cxx/regex/regex.h>
-#include <ndn.cxx/wrapper/wrapper.h>
+#include <ndn-cpp/face.hpp>
+#include <ndn-cpp/security/identity/identity-manager.hpp>
+#include <ndn-cpp/security/policy/policy-manager.hpp>
+#include <ndn-cpp/security/certificate/identity-certificate.hpp>
+#include <ndn-cpp-et/regex/regex.hpp>
+#include <ndn-cpp-et/policy-manager/identity-policy-rule.hpp>
+#include <map>
+
 #include "specific-policy-rule.h"
 
+static ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> SYNC_POLICY_MANAGER_NULL_VALIDATION_REQUEST_PTR;
 
-class SyncPolicyManager : public ndn::security::PolicyManager
+class SyncPolicyManager : public ndn::PolicyManager
 {
 public:
   SyncPolicyManager(const ndn::Name& signingIdentity,
@@ -36,11 +40,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, 
@@ -50,59 +54,89 @@
   inferSigningIdentity(const ndn::Name& dataName);
 
   void
-  addTrustAnchor(const ndn::security::IdentityCertificate& identityCertificate, bool isIntroducer);
+  addTrustAnchor(const ndn::IdentityCertificate& identityCertificate, bool isIntroducer);
 
   void
   addChatDataRule(const ndn::Name& prefix, 
-                  const ndn::security::IdentityCertificate& identityCertificate,
+                  const ndn::IdentityCertificate& identityCertificate,
                   bool isIntroducer);
 
-  inline void 
-  setWrapper(ndn::Ptr<ndn::Wrapper> handler)
-  { m_handler = handler; }
+  // inline void 
+  // setFace(ndn::ndn::ptr_lib::shared_ptr<Face> face) 
+  // { face_ = face; }
 
 private:
-  ndn::Ptr<ndn::security::ValidationRequest>
+  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);
+
+  ndn::ptr_lib::shared_ptr<ndn::ValidationRequest>
   prepareIntroducerRequest(const ndn::Name& keyName,
-                           ndn::Ptr<ndn::Data> data, 
+                           ndn::ptr_lib::shared_ptr<ndn::Data> data, 
                            const int & stepCount, 
-                           const ndn::DataCallback& verifiedCallback,
-                           const ndn::UnverifiedCallback& unverifiedCallback);
+                           const ndn::OnVerified& onVerified,
+                           const ndn::OnVerifyFailed& onVerifyFailed);
   
-  ndn::Ptr<const std::vector<ndn::Name> >
+  ndn::ptr_lib::shared_ptr<const std::vector<ndn::Name> >
   getAllIntroducerName();
 
-  ndn::Ptr<ndn::security::ValidationRequest>
+  ndn::ptr_lib::shared_ptr<ndn::ValidationRequest>
   prepareRequest(const ndn::Name& keyName, 
                  bool forIntroducer,
-                 ndn::Ptr<ndn::Data> data,
+                 ndn::ptr_lib::shared_ptr<ndn::Data> data,
                  const int & stepCount, 
-                 const ndn::DataCallback& verifiedCallback,
-                 const ndn::UnverifiedCallback& unverifiedCallback);
+                 const ndn::OnVerified& onVerified,
+                 const ndn::OnVerifyFailed& onVerifyFailed);
 
   void
-  onIntroCertVerified(ndn::Ptr<ndn::Data> introCertificateData,
+  OnIntroCertInterest(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 registeredPrefixId);
+
+  void
+  OnIntroCertRegisterFailed(const ndn::ptr_lib::shared_ptr<const ndn::Name>& prefix);
+
+  void
+  onIntroCertVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& introCertificateData,
                       bool forIntroducer,
-                      ndn::Ptr<ndn::Data> originalData,
-                      const ndn::DataCallback& verifiedCallback,
-                      const ndn::UnverifiedCallback& unverifiedCallback);
+                      ndn::ptr_lib::shared_ptr<ndn::Data> originalData,
+                      const ndn::OnVerified& onVerified,
+                      const ndn::OnVerifyFailed& onVerifyFailed);
 
   void 
-  onIntroCertUnverified(ndn::Ptr<ndn::Data> introCertificateData,
-                        ndn::Ptr<ndn::Name> interestPrefixName,
-                        bool forIntroducer,
-                        ndn::Ptr<const std::vector<ndn::Name> > introNameList,
-                        const int& nextIntroducerIndex,
-                        ndn::Ptr<ndn::Data> originalData,
-                        const ndn::DataCallback& verifiedCallback,
-                        const ndn::UnverifiedCallback& unverifiedCallback);
+  onIntroCertVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& introCertificateData,
+                          ndn::ptr_lib::shared_ptr<ndn::Name> interestPrefixName,
+                          bool forIntroducer,
+                          ndn::ptr_lib::shared_ptr<const std::vector<ndn::Name> > introNameList,
+                          int nextIntroducerIndex,
+                          ndn::ptr_lib::shared_ptr<ndn::Data> originalData,
+                          const ndn::OnVerified& onVerified,
+                          const ndn::OnVerifyFailed& onVerifyFailed);
+
+  void 
+  onIntroCertData(const ndn::ptr_lib::shared_ptr<const ndn::Interest> &interest,
+                  const ndn::ptr_lib::shared_ptr<ndn::Data>& introCertificateData,                  
+                  int stepCount,
+                  const ndn::OnVerified& onRecursiveVerified,
+                  const ndn::OnVerifyFailed& onRecursiveVerifyFailed,
+                  ndn::ptr_lib::shared_ptr<ndn::Data> originalData,
+                  const ndn::OnVerifyFailed& onVerifyFailed);
 
   void
-  onIntroCertTimeOut(ndn::Ptr<ndn::Closure> closure, 
-                     ndn::Ptr<ndn::Interest> interest, 
-                     int retry, 
-                     const ndn::UnverifiedCallback& unverifiedCallback,
-                     ndn::Ptr<ndn::Data> data);
+  onIntroCertTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, 
+                     int retry,                      
+                     int stepCount,
+                     const ndn::OnVerified& onRecursiveVerified,
+                     const ndn::OnVerifyFailed& onRecursiveVerifyFailed,
+                     ndn::ptr_lib::shared_ptr<ndn::Data> originalData,
+                     const ndn::OnVerifyFailed& onVerifyFailed);
 
 
 
@@ -111,15 +145,18 @@
   ndn::Name m_signingCertificateName;
   ndn::Name m_syncPrefix;
   int m_stepLimit;
-  ndn::Ptr<ndn::Regex> m_syncPrefixRegex;
-  ndn::Ptr<ndn::Regex> m_wotPrefixRegex;
-  ndn::Ptr<ndn::security::IdentityPolicyRule> m_chatDataPolicy; 
-  std::map<ndn::Name, ndn::security::Publickey> m_trustedIntroducers;
-  std::map<ndn::Name, ndn::security::Publickey> m_trustedProducers;
-  std::map<ndn::Name, SpecificPolicyRule> m_chatDataRules;
+  ndn::ptr_lib::shared_ptr<ndn::Regex> m_syncPrefixRegex;
+  ndn::ptr_lib::shared_ptr<ndn::Regex> m_wotPrefixRegex;
+  ndn::ptr_lib::shared_ptr<ndn::IdentityPolicyRule> m_chatDataPolicy; 
+  std::map<std::string, ndn::PublicKey> m_trustedIntroducers;
+  std::map<std::string, ndn::PublicKey> m_trustedProducers;
+  std::map<std::string, SpecificPolicyRule> m_chatDataRules;
+  std::map<std::string, ndn::Data> m_introCert;
 
-  ndn::Ptr<ndn::security::IdentityManager> m_identityManager;
-  ndn::Ptr<ndn::Wrapper> m_handler;
+  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;
+
 };
 
 #endif
diff --git a/src/sync-socket.cc b/src/sync-socket.cc
index f70f6ba..42612e0 100644
--- a/src/sync-socket.cc
+++ b/src/sync-socket.cc
@@ -19,35 +19,67 @@
  */
 
 #include "sync-socket.h"
+#include "sync-logging.h"
+
+#include <ndn-cpp/security/identity/basic-identity-storage.hpp>
+#include <ndn-cpp/security/identity/osx-private-key-storage.hpp>
 
 using namespace std;
 using namespace ndn;
+using namespace ndn::ptr_lib;
+
+INIT_LOGGER ("SyncSocket");
 
 namespace Sync {
 
 SyncSocket::SyncSocket (const string &syncPrefix, 
-                        Ptr<SyncPolicyManager> syncPolicyManager, 
+                        shared_ptr<SyncPolicyManager> syncPolicyManager, 
                         NewDataCallback dataCallback, 
                         RemoveCallback rmCallback )
   : m_newDataCallback(dataCallback)
   , m_syncPolicyManager(syncPolicyManager)
-  , m_handler(Ptr<Wrapper>(new Wrapper(Ptr<security::Keychain>(new security::Keychain(Ptr<security::IdentityManager>::Create(), 
-                                                                                      m_syncPolicyManager, 
-                                                                                      NULL)))))
   , m_syncLogic (syncPrefix,
                  syncPolicyManager,
-                 m_handler,
                  bind(&SyncSocket::passCallback, this, _1),
                  rmCallback)
 {
-  // Ptr<security::Keychain> keychain = Ptr<security::Keychain>(new security::Keychain(Ptr<security::IdentityManager>::Create(), m_syncPolicyManager, NULL));
-  // m_handler = Ptr<Wrapper>(new Wrapper(keychain));
-  m_syncPolicyManager->setWrapper(m_handler);
+  m_transport = make_shared<TcpTransport>();
+  m_face = make_shared<Face>(m_transport, make_shared<TcpTransport::ConnectionInfo>("localhost"));
+
+  connectToDaemon();
+
+  shared_ptr<BasicIdentityStorage> publicStorage = make_shared<BasicIdentityStorage>();
+  shared_ptr<OSXPrivateKeyStorage> privateStorage = make_shared<OSXPrivateKeyStorage>();
+  m_identityManager = make_shared<IdentityManager>(publicStorage, privateStorage);
 }
 
 SyncSocket::~SyncSocket()
 {
-  m_handler->shutdown();
+  m_face->shutdown();
+}
+
+void
+SyncSocket::connectToDaemon()
+{
+  //Hack! transport does not connect to daemon unless an interest is expressed.
+  Name name("/ndn");
+  shared_ptr<ndn::Interest> interest = make_shared<ndn::Interest>(name);
+  m_face->expressInterest(*interest, 
+                          bind(&SyncSocket::onConnectionData, this, _1, _2),
+                          bind(&SyncSocket::onConnectionDataTimeout, this, _1));
+}
+
+void
+SyncSocket::onConnectionData(const shared_ptr<const ndn::Interest>& interest,
+                             const shared_ptr<Data>& data)
+{
+  _LOG_DEBUG("onConnectionData");
+}
+
+void
+SyncSocket::onConnectionDataTimeout(const shared_ptr<const ndn::Interest>& interest)
+{
+  _LOG_DEBUG("onConnectionDataTimeout");
 }
 
 bool 
@@ -58,13 +90,17 @@
   contentNameWithSeqno << prefix << "/" << session << "/" << sequence;
   
   Name dataName(contentNameWithSeqno.str ());
-  Blob blob(buf, len);
+  Blob blob((const uint8_t*)buf, len);
   Name signingIdentity = m_syncPolicyManager->inferSigningIdentity(dataName);
+
+  shared_ptr<Data> data = make_shared<Data>(dataName);
+  data->setContent(blob.buf(), blob.size());
+  data->getMetaInfo().setTimestampMilliseconds(time(NULL) * 1000.0);
+
+  Name certificateName = m_identityManager->getDefaultCertificateNameForIdentity(signingIdentity);
+  m_identityManager->signByCertificate(*data, certificateName);
   
-  m_handler->publishDataByIdentity (dataName, 
-                                    blob, 
-                                    signingIdentity, 
-                                    freshness);
+  m_transport->send(*data->wireEncode());
   
   SeqNo s(session, sequence + 1);
   m_sequenceLog[prefix] = s;
@@ -73,47 +109,109 @@
 }
 
 void 
-SyncSocket::fetchData(const string &prefix, const SeqNo &seq, const DataCallback& callback, int retry)
+SyncSocket::fetchData(const string &prefix, const SeqNo &seq, const OnVerified& onVerified, int retry)
 {
   ostringstream interestName;
   interestName << prefix << "/" << seq.getSession() << "/" << seq.getSeq();
   //std::cout << "Socket " << this << " Send Interest <" << interestName.str() << "> for raw data " << endl;
+
+  const OnVerifyFailed& onVerifyFailed = bind(&SyncSocket::onChatDataVerifyFailed, this, _1);
   
   
-  Ptr<ndn::Interest> interestPtr = Ptr<ndn::Interest>(new ndn::Interest(interestName.str()));
-  Ptr<Closure> closure = Ptr<Closure> (new Closure(callback,
-						   boost::bind(&SyncSocket::onChatDataTimeout,
-                                                               this,
-                                                               _1, 
-                                                               _2,
-                                                               retry),
-						   boost::bind(&SyncSocket::onChatDataUnverified,
-                                                               this,
-                                                               _1)));
-  m_handler->sendInterest(interestPtr, closure);
+  shared_ptr<ndn::Interest> interest = make_shared<ndn::Interest>(interestName.str());
+  m_face->expressInterest(*interest, 
+                          bind(&SyncSocket::onChatData, this, _1, _2, onVerified, onVerifyFailed), 
+                          bind(&SyncSocket::onChatDataTimeout, this, _1, retry, onVerified, onVerifyFailed));
+
 }
 
 void
-SyncSocket::onChatDataTimeout(Ptr<Closure> closure, Ptr<ndn::Interest> interest, int retry)
+SyncSocket::onChatCert(const shared_ptr<const ndn::Interest>& interest,
+                       const shared_ptr<Data>& cert,
+                       shared_ptr<ValidationRequest> previousStep)
+{
+  shared_ptr<ValidationRequest> nextStep = m_syncPolicyManager->checkVerificationPolicy(cert, 
+                                                                                        previousStep->stepCount_, 
+                                                                                        previousStep->onVerified_, 
+                                                                                        previousStep->onVerifyFailed_);
+  
+  if (nextStep)
+    m_face->expressInterest
+      (*nextStep->interest_, 
+       bind(&SyncSocket::onChatCert, this, _1, _2, nextStep), 
+       bind(&SyncSocket::onChatCertTimeout, this, _1, previousStep->onVerifyFailed_, cert, nextStep));
+}
+
+void
+SyncSocket::onChatCertTimeout(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(&SyncSocket::onChatCert,
+                                 this,
+                                 _1,
+                                 _2,
+                                 nextStep),
+                            bind(&SyncSocket::onChatCertTimeout,
+                                 this,
+                                 _1,
+                                 onVerifyFailed,
+                                 data,
+                                 nextStep));
+  else
+    onVerifyFailed(data);
+}
+
+void
+SyncSocket::onChatData(const shared_ptr<const ndn::Interest>& interest, 
+                       const shared_ptr<Data>& data,
+                       const OnVerified& onVerified,
+                       const OnVerifyFailed& onVerifyFailed)
+{
+  shared_ptr<ValidationRequest> nextStep = m_syncPolicyManager->checkVerificationPolicy(data, 0, onVerified, onVerifyFailed);
+
+  if (nextStep)
+    m_face->expressInterest
+      (*nextStep->interest_, 
+       bind(&SyncSocket::onChatCert, this, _1, _2, nextStep), 
+       bind(&SyncSocket::onChatCertTimeout, this, _1, onVerifyFailed, data, nextStep));
+}
+
+void
+SyncSocket::onChatDataTimeout(const shared_ptr<const ndn::Interest>& interest, 
+                              int retry,
+                              const OnVerified& onVerified,
+                              const OnVerifyFailed& onVerifyFailed)
 {
   if(retry > 0)
     {
-      Ptr<Closure> newClosure = Ptr<Closure>(new Closure(closure->m_dataCallback,
-                                                         boost::bind(&SyncSocket::onChatDataTimeout, 
-                                                                     this, 
-                                                                     _1, 
-                                                                     _2, 
-                                                                     retry - 1),
-                                                         closure->m_unverifiedCallback,
-                                                         closure->m_stepCount)
-                                             );
-      m_handler->sendInterest(interest, newClosure);
+      m_face->expressInterest(*interest,
+                              bind(&SyncSocket::onChatData,
+                                   this,
+                                   _1,
+                                   _2,
+                                   onVerified,
+                                   onVerifyFailed),
+                              bind(&SyncSocket::onChatDataTimeout, 
+                                   this,
+                                   _1,
+                                   retry - 1,
+                                   onVerified,
+                                   onVerifyFailed));
+                              
     }
+  else
+    _LOG_DEBUG("Chat interest eventually time out!");
 }
 
 void
-SyncSocket::onChatDataUnverified(Ptr<Data> data)
-{}
+SyncSocket::onChatDataVerifyFailed(const shared_ptr<Data>& data)
+{
+  _LOG_DEBUG("Chat data cannot be verified!");
+}
 
 
 uint32_t
diff --git a/src/sync-socket.h b/src/sync-socket.h
index a4530ba..170fde5 100644
--- a/src/sync-socket.h
+++ b/src/sync-socket.h
@@ -25,7 +25,8 @@
 #include <boost/function.hpp>
 #include <boost/unordered_map.hpp>
 #include "sync-seq-no.h"
-#include <ndn.cxx/wrapper/wrapper.h>
+#include <ndn-cpp/face.hpp>
+#include <ndn-cpp/security/identity/identity-manager.hpp>
 #include <utility>
 #include <map>
 #include <vector>
@@ -54,7 +55,7 @@
    * @param dataCallback the callback to process data
    */
   SyncSocket (const std::string &syncPrefix, 
-              ndn::Ptr<SyncPolicyManager> syncPolicyManager,
+              ndn::ptr_lib::shared_ptr<SyncPolicyManager> syncPolicyManager,
               NewDataCallback dataCallback, 
               RemoveCallback rmCallback);
 
@@ -68,7 +69,7 @@
   { m_syncLogic.remove(prefix); }
 
   void 
-  fetchData(const std::string &prefix, const SeqNo &seq, const ndn::DataCallback& callback, int retry = 0);
+  fetchData(const std::string &prefix, const SeqNo &seq, const ndn::OnVerified& onVerified, int retry = 0);
 
   std::string 
   getRootDigest() 
@@ -87,22 +88,54 @@
   GetLocalPrefix (); 
   
 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 
   passCallback(const std::vector<MissingDataInfo> &v) 
   { m_newDataCallback(v, this); }
 
   void
-  onChatDataTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest, int retry);
+  onChatCert(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
-  onChatDataUnverified(ndn::Ptr<ndn::Data> data);
+  onChatCertTimeout(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
+  onChatData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, 
+             const ndn::ptr_lib::shared_ptr<ndn::Data>& data,
+             const ndn::OnVerified& onVerified,
+             const ndn::OnVerifyFailed& onVerifyFailed);
+
+  void
+  onChatDataTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, 
+                    int retry,
+                    const ndn::OnVerified& onVerified,
+                    const ndn::OnVerifyFailed& onVerifyFailed);
+
+  void
+  onChatDataVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data);
 
 private:
   typedef boost::unordered_map<std::string, SeqNo> SequenceLog;
   NewDataCallback m_newDataCallback;
   SequenceLog m_sequenceLog;
-  ndn::Ptr<SyncPolicyManager> m_syncPolicyManager;
-  ndn::Ptr<ndn::Wrapper> m_handler;
+  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;
   SyncLogic      m_syncLogic;
 };