security: using Verifier

Change-Id: I2e5d27204f8bc293f347b4a12839891ec7547643
diff --git a/src/chatdialog.cpp b/src/chatdialog.cpp
index 0903b27..dad2b6b 100644
--- a/src/chatdialog.cpp
+++ b/src/chatdialog.cpp
@@ -87,6 +87,8 @@
   m_timer = new QTimer(this);
 
   startFace();
+  m_verifier = ndn::ptr_lib::make_shared<ndn::Verifier>(m_invitationPolicy);
+  m_verifier->setFace(m_face);
 
   ndn::Name certificateName = m_keyChain->getDefaultCertificateNameForIdentity(m_defaultIdentity);
   m_syncPolicy = ndn::ptr_lib::make_shared<SecPolicySync>(m_defaultIdentity, certificateName, m_chatroomPrefix, m_face);
@@ -222,60 +224,42 @@
                          const ndn::OnVerified& onVerified,
                          const ndn::OnVerifyFailed& onVerifyFailed,
                          const OnEventualTimeout& timeoutNotify,
-                         const ndn::ptr_lib::shared_ptr<ndn::SecPolicy>& policy,
-                         int retry /* = 1 */,
-                         int stepCount /* = 0 */)
+                         int retry /* = 1 */)
 {
   m_face->expressInterest(interest, 
                           boost::bind(&ChatDialog::onTargetData, 
                                       this,
                                       _1,
                                       _2,
-                                      stepCount,
                                       onVerified, 
-                                      onVerifyFailed,
-                                      timeoutNotify,
-                                      policy),
+                                      onVerifyFailed),
                           boost::bind(&ChatDialog::onTargetTimeout,
                                       this,
                                       _1,
                                       retry,
-                                      stepCount,
                                       onVerified,
                                       onVerifyFailed,
-                                      timeoutNotify,
-                                      policy));
+                                      timeoutNotify));
 }
 
 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::SecPolicy>& policy)
+                         const ndn::OnVerifyFailed& onVerifyFailed)
 {
-  ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> nextStep = policy->checkVerificationPolicy(data, stepCount, onVerified, onVerifyFailed);
-
-  if (nextStep)
-    m_face->expressInterest
-      (*nextStep->interest_, 
-       boost::bind(&ChatDialog::onCertData, this, _1, _2, nextStep, policy), 
-       boost::bind(&ChatDialog::onCertTimeout, this, _1, onVerifyFailed, data, nextStep, policy));
+  m_verifier->verifyData(data, onVerified, onVerifyFailed);
 }
 
 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::SecPolicy>& policy)
+                            const OnEventualTimeout& timeoutNotify)
 {
   if(retry > 0)
-    sendInterest(*interest, onVerified, onVerifyFailed, timeoutNotify, policy, retry-1, stepCount);
+    sendInterest(*interest, onVerified, onVerifyFailed, timeoutNotify, retry-1);
   else
     {
       _LOG_DEBUG("Interest: " << interest->getName().toUri() << " eventually times out!");
@@ -284,50 +268,6 @@
 }
 
 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::SecPolicy>& policy)
-{
-  ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> nextStep = policy->checkVerificationPolicy(cert, 
-                                                                                                     previousStep->stepCount_, 
-                                                                                                     previousStep->onVerified_, 
-                                                                                                     previousStep->onVerifyFailed_);
-
-  if (nextStep)
-    m_face->expressInterest
-      (*nextStep->interest_, 
-       boost::bind(&ChatDialog::onCertData, this, _1, _2, nextStep, policy), 
-       boost::bind(&ChatDialog::onCertTimeout, this, _1, previousStep->onVerifyFailed_, cert, nextStep, policy));
-}
-
-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::SecPolicy>& policy)
-{
-  if(nextStep->retry_ > 0)
-    m_face->expressInterest(*interest, 
-                            boost::bind(&ChatDialog::onCertData,
-                                        this,
-                                        _1,
-                                        _2,
-                                        nextStep,
-                                        policy),
-                            boost::bind(&ChatDialog::onCertTimeout,
-                                        this,
-                                        _1,
-                                        onVerifyFailed,
-                                        data,
-                                        nextStep,
-                                        policy));
- else
-   onVerifyFailed(data);
-}
-
-void
 ChatDialog::sendInvitation(ndn::ptr_lib::shared_ptr<ContactItem> contact, bool isIntroducer)
 {
   m_invitationPolicy->addTrustAnchor(contact->getSelfEndorseCertificate());
@@ -370,7 +310,7 @@
                                                      contact->getNameSpace());
                                                  
 
-  sendInterest(interest, onVerified, onVerifyFailed, timeoutNotify, m_invitationPolicy);
+  sendInterest(interest, onVerified, onVerifyFailed, timeoutNotify);
 }
 
 void 
diff --git a/src/chatdialog.h b/src/chatdialog.h
index fad9ed4..bdcd070 100644
--- a/src/chatdialog.h
+++ b/src/chatdialog.h
@@ -148,42 +148,22 @@
   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 OnEventualTimeout& timeoutNotify,
-               const ndn::ptr_lib::shared_ptr<ndn::SecPolicy>& policy);
+               const ndn::OnVerifyFailed& onVerifyFailed);
 
   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::SecPolicy>& policy);
-  
-  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::SecPolicy>& policy);
-
-  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::SecPolicy>& policy);
+                  const OnEventualTimeout& timeoutNotify);
 
   void
   sendInterest(const ndn::Interest& interest,
                const ndn::OnVerified& onVerified,
                const ndn::OnVerifyFailed& onVerifyFailed,
                const OnEventualTimeout& timeoutNotify,
-               const ndn::ptr_lib::shared_ptr<ndn::SecPolicy>& policy,
-               int retry = 1,
-               int stepCount = 0);
+               int retry = 1);
   
   void 
   onInviteReplyVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, 
@@ -343,6 +323,7 @@
   ndn::Name m_defaultIdentity;
   ndn::ptr_lib::shared_ptr<SecPolicyChronoChatInvitation> m_invitationPolicy;
   ndn::ptr_lib::shared_ptr<SecPolicySync> m_syncPolicy; 
+  ndn::ptr_lib::shared_ptr<ndn::Verifier> m_verifier;
   ndn::ptr_lib::shared_ptr<ndn::KeyChain> m_keyChain;
   ndn::ptr_lib::shared_ptr<ndn::Face> m_face;
 
diff --git a/src/contact-manager.cpp b/src/contact-manager.cpp
index aea34fc..a70be49 100644
--- a/src/contact-manager.cpp
+++ b/src/contact-manager.cpp
@@ -29,6 +29,7 @@
 #include <ndn-cpp/security/verifier.hpp>
 #include <cryptopp/base64.h>
 #include <ndn-cpp-et/policy/sec-rule-identity.hpp>
+#include <ndn-cpp-et/policy/sec-policy-simple.hpp>
 #include <fstream>
 #include "endorse-collection.pb.h"
 #include "logging.h"
@@ -59,31 +60,33 @@
 void
 ContactManager::initializeSecurity()
 {
-  m_policy = make_shared<SecPolicySimple>();
+  shared_ptr<SecPolicySimple> policy = make_shared<SecPolicySimple>();
+  m_verifier = make_shared<Verifier>(policy);
+  m_verifier->setFace(m_face);
 
-  m_policy->addVerificationPolicyRule(make_shared<SecRuleIdentity>("^([^<DNS>]*)<DNS><ENDORSED>",
-                                                                             "^([^<KEY>]*)<KEY>(<>*)[<ksk-.*><dsk-.*>]<ID-CERT>$",
-                                                                             "==", "\\1", "\\1\\2", true));
-  m_policy->addVerificationPolicyRule(make_shared<SecRuleIdentity>("^([^<DNS>]*)<DNS><PROFILE>",
-                                                                             "^([^<KEY>]*)<KEY>(<>*)[<ksk-.*><dsk-.*>]<ID-CERT>$",
-                                                                             "==", "\\1", "\\1\\2", true));
-  m_policy->addVerificationPolicyRule(make_shared<SecRuleIdentity>("^([^<PROFILE-CERT>]*)<PROFILE-CERT>",
-                                                                             "^([^<KEY>]*)<KEY>(<>*<ksk-.*>)<ID-CERT>$", 
-                                                                             "==", "\\1", "\\1\\2", true));
-  m_policy->addVerificationPolicyRule(make_shared<SecRuleIdentity>("^([^<KEY>]*)<KEY>(<>*)<ksk-.*><ID-CERT>",
-                                                                             "^([^<KEY>]*)<KEY><dsk-.*><ID-CERT>$",
-                                                                             ">", "\\1\\2", "\\1", true));
-  m_policy->addVerificationPolicyRule(make_shared<SecRuleIdentity>("^([^<KEY>]*)<KEY><dsk-.*><ID-CERT>",
-                                                                             "^([^<KEY>]*)<KEY>(<>*)<ksk-.*><ID-CERT>$",
-                                                                             "==", "\\1", "\\1\\2", true));
-  m_policy->addVerificationPolicyRule(make_shared<SecRuleIdentity>("^(<>*)$", 
-                                                                             "^([^<KEY>]*)<KEY>(<>*)<ksk-.*><ID-CERT>$", 
-                                                                             ">", "\\1", "\\1\\2", true));
+  policy->addVerificationPolicyRule(make_shared<SecRuleIdentity>("^([^<DNS>]*)<DNS><ENDORSED>",
+                                                                 "^([^<KEY>]*)<KEY>(<>*)[<ksk-.*><dsk-.*>]<ID-CERT>$",
+                                                                 "==", "\\1", "\\1\\2", true));
+  policy->addVerificationPolicyRule(make_shared<SecRuleIdentity>("^([^<DNS>]*)<DNS><PROFILE>",
+                                                                 "^([^<KEY>]*)<KEY>(<>*)[<ksk-.*><dsk-.*>]<ID-CERT>$",
+                                                                 "==", "\\1", "\\1\\2", true));
+  policy->addVerificationPolicyRule(make_shared<SecRuleIdentity>("^([^<PROFILE-CERT>]*)<PROFILE-CERT>",
+                                                                 "^([^<KEY>]*)<KEY>(<>*<ksk-.*>)<ID-CERT>$", 
+                                                                 "==", "\\1", "\\1\\2", true));
+  policy->addVerificationPolicyRule(make_shared<SecRuleIdentity>("^([^<KEY>]*)<KEY>(<>*)<ksk-.*><ID-CERT>",
+                                                                 "^([^<KEY>]*)<KEY><dsk-.*><ID-CERT>$",
+                                                                 ">", "\\1\\2", "\\1", true));
+  policy->addVerificationPolicyRule(make_shared<SecRuleIdentity>("^([^<KEY>]*)<KEY><dsk-.*><ID-CERT>",
+                                                                 "^([^<KEY>]*)<KEY>(<>*)<ksk-.*><ID-CERT>$",
+                                                                 "==", "\\1", "\\1\\2", true));
+  policy->addVerificationPolicyRule(make_shared<SecRuleIdentity>("^(<>*)$", 
+                                                                 "^([^<KEY>]*)<KEY>(<>*)<ksk-.*><ID-CERT>$", 
+                                                                 ">", "\\1", "\\1\\2", true));
   
 
-  m_policy->addSigningPolicyRule(make_shared<SecRuleIdentity>("^([^<DNS>]*)<DNS><PROFILE>",
-                                                                        "^([^<KEY>]*)<KEY>(<>*)<><ID-CERT>",
-                                                                        "==", "\\1", "\\1\\2", true));
+  policy->addSigningPolicyRule(make_shared<SecRuleIdentity>("^([^<DNS>]*)<DNS><PROFILE>",
+                                                            "^([^<KEY>]*)<KEY>(<>*)<><ID-CERT>",
+                                                            "==", "\\1", "\\1\\2", true));
 
 
   const string TrustAnchor("BIICqgOyEIWlKzDI2xX2hdq5Azheu9IVyewcV4uM7ylfh67Y8MIxF3tDCTx5JgEn\
@@ -112,7 +115,7 @@
   Data data;
   data.wireDecode(Block(reinterpret_cast<const uint8_t*>(decoded.c_str()), decoded.size()));
   shared_ptr<IdentityCertificate> anchor = make_shared<IdentityCertificate>(data);
-  m_policy->addTrustAnchor(anchor);  
+  policy->addTrustAnchor(anchor);  
 
 #ifdef _DEBUG
 
@@ -142,7 +145,7 @@
   Data data2;
   data2.wireDecode(Block(reinterpret_cast<const uint8_t*>(decoded.c_str()), decoded.size()));
   shared_ptr<IdentityCertificate>anchor2 = make_shared<IdentityCertificate>(data2);
-  m_policy->addTrustAnchor(anchor2);  
+  policy->addTrustAnchor(anchor2);  
 
 #endif
 }
@@ -310,31 +313,21 @@
 void
 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)
+                             const OnVerifyFailed& onVerifyFailed)
 {
-  shared_ptr<ValidationRequest> nextStep = m_policy->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));
-
+  m_verifier->verifyData(data, onVerified, onVerifyFailed);
 }
 
 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);
+    sendInterest(*interest, onVerified, onVerifyFailed, timeoutNotify, retry-1);
   else
     {
       _LOG_DEBUG("Interest: " << interest->getName().toUri() << " eventually times out!");
@@ -343,67 +336,23 @@
 }
 
 void
-ContactManager::onCertData(const shared_ptr<const ndn::Interest>& interest, 
-                           const shared_ptr<Data>& cert,
-                           shared_ptr<ValidationRequest> previousStep)
-{
-  shared_ptr<ValidationRequest> nextStep = m_policy->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 */)
+                             int retry /* = 1 */)
 {
   uint64_t id = m_face->expressInterest(interest, 
                           boost::bind(&ContactManager::onTargetData, 
                                       this,
                                       _1,
                                       _2,
-                                      stepCount,
                                       onVerified, 
-                                      onVerifyFailed,
-                                      timeoutNotify),
+                                      onVerifyFailed),
                           boost::bind(&ContactManager::onTargetTimeout,
                                       this,
                                       _1,
                                       retry,
-                                      stepCount,
                                       onVerified,
                                       onVerifyFailed,
                                       timeoutNotify));
diff --git a/src/contact-manager.h b/src/contact-manager.h
index 67d4ac8..a188fdb 100644
--- a/src/contact-manager.h
+++ b/src/contact-manager.h
@@ -20,8 +20,7 @@
 #include "profile.h"
 #include <ndn-cpp/face.hpp>
 #include <ndn-cpp/security/key-chain.hpp>
-#include <ndn-cpp/security/validation-request.hpp>
-#include <ndn-cpp-et/policy/sec-policy-simple.hpp>
+#include <ndn-cpp/security/verifier.hpp>
 #endif
 
 typedef ndn::func_lib::function<void()> TimeoutNotify;
@@ -111,39 +110,23 @@
                const ndn::OnVerified& onVerified,
                const ndn::OnVerifyFailed& onVerifyFailed,
                const TimeoutNotify& timeoutNotify,
-               int retry = 1,
-               int stepCount = 0);
+               int retry = 1);
 
   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);
+               const ndn::OnVerifyFailed& onVerifyFailed);
 
   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 
@@ -227,7 +210,7 @@
 
   ndn::ptr_lib::shared_ptr<ContactStorage> m_contactStorage;
   ndn::ptr_lib::shared_ptr<DnsStorage> m_dnsStorage;
-  ndn::ptr_lib::shared_ptr<ndn::SecPolicySimple> m_policy;
+  ndn::ptr_lib::shared_ptr<ndn::Verifier> m_verifier;
   ndn::ptr_lib::shared_ptr<ndn::KeyChain> m_keyChain;
   ndn::ptr_lib::shared_ptr<ndn::Face> m_face;
   ndn::Name m_defaultIdentity;
diff --git a/src/contactpanel.cpp b/src/contactpanel.cpp
index cde6c55..27978da 100644
--- a/src/contactpanel.cpp
+++ b/src/contactpanel.cpp
@@ -58,6 +58,8 @@
   createAction();
 
   m_keyChain = make_shared<KeyChain>();
+  m_verifier = make_shared<Verifier>(m_policy);
+  m_verifier->setFace(m_face);
 
   m_contactManager = make_shared<ContactManager>(m_keyChain, m_face);
 
@@ -340,23 +342,19 @@
                            const OnVerified& onVerified,
                            const OnVerifyFailed& onVerifyFailed,
                            const TimeoutNotify& timeoutNotify,
-                           int retry /* = 1 */,
-                           int stepCount /* = 0 */)
+                           int retry /* = 1 */)
 {
   m_face->expressInterest(interest, 
                           func_lib::bind(&ContactPanel::onTargetData, 
                                       this,
                                       _1,
                                       _2,
-                                      stepCount,
                                       onVerified, 
-                                      onVerifyFailed,
-                                      timeoutNotify),
+                                      onVerifyFailed),
                           func_lib::bind(&ContactPanel::onTargetTimeout,
                                       this,
                                       _1,
                                       retry,
-                                      stepCount,
                                       onVerified,
                                       onVerifyFailed,
                                       timeoutNotify));
@@ -365,31 +363,21 @@
 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)
+                           const OnVerifyFailed& onVerifyFailed)
 {
-  shared_ptr<ValidationRequest> nextStep = m_policy->checkVerificationPolicy(data, stepCount, onVerified, onVerifyFailed);
-
-  if (nextStep)
-    m_face->expressInterest
-      (*nextStep->interest_, 
-       func_lib::bind(&ContactPanel::onCertData, this, _1, _2, nextStep), 
-       func_lib::bind(&ContactPanel::onCertTimeout, this, _1, onVerifyFailed, data, nextStep));
-
+  m_verifier->verifyData(data, onVerified, onVerifyFailed);
 }
 
 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);
+    sendInterest(*interest, onVerified, onVerifyFailed, timeoutNotify, retry-1);
   else
     {
       _LOG_DEBUG("Interest: " << interest->getName().toUri() << " eventually times out!");
@@ -398,46 +386,6 @@
 }
 
 void
-ContactPanel::onCertData(const shared_ptr<const ndn::Interest>& interest, 
-                         const shared_ptr<Data>& cert,
-                         shared_ptr<ValidationRequest> previousStep)
-{
-  shared_ptr<ValidationRequest> nextStep = m_policy->checkVerificationPolicy(cert, 
-                                                                                    previousStep->stepCount_, 
-                                                                                    previousStep->onVerified_, 
-                                                                                    previousStep->onVerifyFailed_);
-
-  if (nextStep)
-    m_face->expressInterest
-      (*nextStep->interest_, 
-       func_lib::bind(&ContactPanel::onCertData, this, _1, _2, nextStep), 
-       func_lib::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, 
-                            func_lib::bind(&ContactPanel::onCertData,
-                                 this,
-                                 _1,
-                                 _2,
-                                 nextStep),
-                            func_lib::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"));
diff --git a/src/contactpanel.h b/src/contactpanel.h
index 4d871a1..8bc08e5 100644
--- a/src/contactpanel.h
+++ b/src/contactpanel.h
@@ -109,21 +109,17 @@
                const ndn::OnVerified& onVerified,
                const ndn::OnVerifyFailed& onVerifyFailed,
                const TimeoutNotify& timeoutNotify,
-               int retry = 1,
-               int stepCount = 0);
+               int retry = 1);
 
   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);
+               const ndn::OnVerifyFailed& onVerifyFailed);
 
   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);
@@ -286,6 +282,7 @@
   ndn::ptr_lib::shared_ptr<std::vector<bool> > m_collectStatus;
 
   ndn::ptr_lib::shared_ptr<SecPolicyChronoChatPanel> m_policy;
+  ndn::ptr_lib::shared_ptr<ndn::Verifier> m_verifier;
   ndn::ptr_lib::shared_ptr<ndn::KeyChain> m_keyChain;
   ndn::ptr_lib::shared_ptr<ndn::Face> m_face;