compile: Change includes and wscript to compile against ndn-cpp-dev

Change-Id: Ie51f5377690ccaf1fd3ffe90df68ce3f537b029d
diff --git a/src/addcontactpanel.cpp b/src/addcontactpanel.cpp
index dd933cd..52f5483 100644
--- a/src/addcontactpanel.cpp
+++ b/src/addcontactpanel.cpp
@@ -13,7 +13,7 @@
 #include <QMessageBox>
 
 #ifndef Q_MOC_RUN
-#include <ndn-cpp/security/verifier.hpp>
+#include <ndn-cpp-dev/security/verifier.hpp>
 #include <boost/iostreams/stream.hpp>
 #include "endorse-collection.pb.h"
 #include "logging.h"
diff --git a/src/browsecontactdialog.cpp b/src/browsecontactdialog.cpp
index c84b5f9..281ecba 100644
--- a/src/browsecontactdialog.cpp
+++ b/src/browsecontactdialog.cpp
@@ -144,7 +144,7 @@
   
   if(filter)
     {
-      map<Name, Name, Name::BreadthFirstLess> certificateMap;
+      map<Name, Name> certificateMap;
 
       vector<string>::iterator it = certNameList.begin();
   
diff --git a/src/browsecontactdialog.h b/src/browsecontactdialog.h
index 2edaa2d..bab431d 100644
--- a/src/browsecontactdialog.h
+++ b/src/browsecontactdialog.h
@@ -19,7 +19,7 @@
 
 
 #ifndef Q_MOC_RUN
-#include <ndn-cpp/security/identity-certificate.hpp>
+#include <ndn-cpp-dev/security/identity-certificate.hpp>
 #include <boost/thread/locks.hpp>
 #include <boost/thread/recursive_mutex.hpp>
 #include "profile.h"
@@ -103,8 +103,8 @@
   QStringList m_contactList;  
   std::vector<ndn::Name> m_contactNameList;
   std::vector<ndn::Name> m_certificateNameList;
-  std::map<ndn::Name, ndn::IdentityCertificate, ndn::Name::BreadthFirstLess> m_certificateMap;
-  std::map<ndn::Name, Profile, ndn::Name::BreadthFirstLess> m_profileMap;
+  std::map<ndn::Name, ndn::IdentityCertificate> m_certificateMap;
+  std::map<ndn::Name, Profile> m_profileMap;
 
   RecLock m_mutex;
 
diff --git a/src/chatdialog.cpp b/src/chatdialog.cpp
index dad2b6b..14dd7a5 100644
--- a/src/chatdialog.cpp
+++ b/src/chatdialog.cpp
@@ -19,9 +19,10 @@
 
 #ifndef Q_MOC_RUN
 #include <sync-intro-certificate.h>
+#include "chronos-invitation.h"
 #include <boost/random/random_device.hpp>
 #include <boost/random/uniform_int_distribution.hpp>
-#include <ndn-cpp/security/signature-sha256-with-rsa.hpp>
+#include <ndn-cpp-dev/security/signature-sha256-with-rsa.hpp>
 #include "logging.h"
 #endif
 
@@ -274,26 +275,16 @@
 
   ndn::Name certificateName = m_keyChain->getDefaultCertificateNameForIdentity(m_defaultIdentity);
 
-  ndn::Name interestName("/ndn/broadcast/chronos/invitation");
-  interestName.append(contact->getNameSpace());
-  interestName.append("chatroom");
-  interestName.append(m_chatroomPrefix.get(-1));
-  interestName.append("inviter-prefix");
-  interestName.append(m_localPrefix);
-  interestName.append("inviter");
-  interestName.append(certificateName);
+  ChronosInvitation invitation(contact->getNameSpace(),
+                               m_chatroomPrefix.getSubName(m_chatroomPrefix.size()-1, 1), //!!Should be changed!
+                               m_localPrefix,
+                               certificateName);
 
-  string signedUri = interestName.toUri();
+  const ndn::Buffer &signedBlob = invitation.getSignedBlob();
+  ndn::Signature sig = m_keyChain->sign(signedBlob.buf(), signedBlob.size(), certificateName);
+  invitation.setSignatureValue(sig.getValue());
 
-  ndn::Signature sig = m_keyChain->sign(reinterpret_cast<const uint8_t*>(signedUri.c_str()), signedUri.size(), certificateName);
-  const ndn::Block& sigValue = sig.getValue();
-
-  interestName.append(sigValue);
-
-  //TODO... remove version from invitation interest
-  //  interestName.appendVersion();
-
-  ndn::Interest interest(interestName);
+  ndn::Interest interest(invitation.getInterestName());
   ndn::OnVerified onVerified = boost::bind(&ChatDialog::onInviteReplyVerified,
                                            this,
                                            _1,
@@ -358,7 +349,7 @@
   ndn::SignatureSha256WithRsa sig(data->getSignature());
   const ndn::Name & keyLocatorName = sig.getKeyLocator().getName();
   ndn::ptr_lib::shared_ptr<ndn::IdentityCertificate> dskCertificate = m_invitationPolicy->getValidatedDskCertificate(keyLocatorName);
-  m_syncPolicy->addChatDataRule(inviteePrefix, *dskCertificate, isIntroducer);
+  m_syncPolicy->addSyncDataRule(inviteePrefix, *dskCertificate, isIntroducer);
   publishIntroCert(*dskCertificate, isIntroducer);
 }
 
@@ -386,7 +377,7 @@
 ChatDialog::addChatDataRule(const ndn::Name& prefix, 
                             const ndn::IdentityCertificate& identityCertificate,
                             bool isIntroducer)
-{ m_syncPolicy->addChatDataRule(prefix, identityCertificate, isIntroducer); }
+{ m_syncPolicy->addSyncDataRule(prefix, identityCertificate, isIntroducer); }
 
  
 
diff --git a/src/chatdialog.h b/src/chatdialog.h
index bdcd070..4dc5061 100644
--- a/src/chatdialog.h
+++ b/src/chatdialog.h
@@ -23,9 +23,9 @@
 #include "invitelistdialog.h"
 
 #ifndef Q_MOC_RUN
-#include <ndn-cpp/data.hpp>
-#include <ndn-cpp/face.hpp>
-#include <ndn-cpp/security/key-chain.hpp>
+#include <ndn-cpp-dev/data.hpp>
+#include <ndn-cpp-dev/face.hpp>
+#include <ndn-cpp-dev/security/key-chain.hpp>
 #include "sec-policy-chrono-chat-invitation.h"
 #include "contact-item.h"
 
diff --git a/src/chronos-invitation.cpp b/src/chronos-invitation.cpp
index b49c08b..b6084ab 100644
--- a/src/chronos-invitation.cpp
+++ b/src/chronos-invitation.cpp
@@ -10,7 +10,9 @@
 
 #include "chronos-invitation.h"
 
-#include <ndn-cpp/security/identity-certificate.hpp>
+#include <ndn-cpp-dev/security/identity-certificate.hpp>
+#include <ndn-cpp-dev/security/signature-sha256-with-rsa.hpp>
+
 #include "logging.h"
 
 using namespace std;
@@ -18,68 +20,95 @@
 
 INIT_LOGGER("ChronosInvitation");
 
-ChronosInvitation::ChronosInvitation(const ndn::Name& originalInterestName)
+
+const size_t ChronosInvitation::NAME_SIZE_MIN = 8;
+const size_t ChronosInvitation::INVITEE_START = 4;
+const ssize_t SIGNATURE      = -1;
+const ssize_t KEY_LOCATOR    = -2;
+const ssize_t INVITER_PREFIX = -3;
+const ssize_t CHATROOM       = -4;
+const Name ChronosInvitation::INVITATION_PREFIX("/ndn/broadcast/chronos/chat-invitation");
+
+
+ChronosInvitation::ChronosInvitation(const Name& originalInterestName)
   : m_interestName(originalInterestName)
 {
-  Name interestName = originalInterestName;
-  if(interestName.get(0).toEscapedString() != string("ndn")
-     || interestName.get(1).toEscapedString() != string("broadcast")
-     || interestName.get(2).toEscapedString() != string("chronos")
-     || interestName.get(3).toEscapedString() != string("invitation"))
-    throw Error("Wrong ChronosInvitation Name");
-    
-  int i = 4;
-  int size = interestName.size();
 
-  string chatroomStr("chatroom");
-  int inviteeBegin = 4;
-  for(; i < size; i++)
-    if(interestName.get(i).toEscapedString() == chatroomStr)
-      break;
+  size_t nameSize = originalInterestName.size();
 
-  if(i >= size)
-    throw Error("Wrong ChronosInvitation Name, No chatroom tag");
-  m_inviteeNameSpace = interestName.getSubName(inviteeBegin, i - inviteeBegin);
-
-  string inviterPrefixStr("inviter-prefix");
-  int chatroomBegin = (++i);
-  for(; i < size;  i++)
-    if(interestName.get(i).toEscapedString() == inviterPrefixStr)
-      break;
-
-  if(i > size)
-    throw Error("Wrong ChronosInvitation Name, No inviter-prefix tag");
-  m_chatroom = interestName.getSubName(chatroomBegin, i - chatroomBegin);
-
-  string inviterStr("inviter");
-  int inviterPrefixBegin = (++i);
-  for(; i < size; i++)
-    if(interestName.get(i).toEscapedString() == inviterStr)
-      break;
-  
-  if(i > size)
-    throw Error("Wrong ChronosInvitation Name, No inviter tag");
-  m_inviterPrefix = interestName.getSubName(inviterPrefixBegin, i - inviterPrefixBegin);
-
-  int inviterCertBegin = (++i);
-  m_inviterCertificateName = interestName.getSubName(inviterCertBegin, size - 1 - inviterCertBegin);
-  
-  m_signatureBits = interestName.get(-1).getValue();
+  if(nameSize < NAME_SIZE_MIN)
+    throw Error("Wrong ChronosInvitation Name: Wrong length"); 
  
-  Name keyName = IdentityCertificate::certificateNameToPublicKeyName(m_inviterCertificateName);
-  m_inviterNameSpace = keyName.getPrefix(-1);
+  if(!INVITATION_PREFIX.isPrefixOf(originalInterestName))
+    throw Error("Wrong ChronosInvitation Name: Wrong invitation prefix");
 
-  string signedName = interestName.getSubName(0, size - 1).toUri();
-  m_signedBlob = Buffer(signedName.c_str(), signedName.size());
+  //hack! should be more efficient.
+  Name signedName = originalInterestName.getPrefix(-1);
+  m_signedBlob = Buffer(signedName.wireEncode().value(), signedName.wireEncode().value_size());
+
+  Block signatureBlock(originalInterestName.get(SIGNATURE).getValue().buf(),
+                       originalInterestName.get(SIGNATURE).getValue().size());
+  Block signatureInfo(originalInterestName.get(KEY_LOCATOR).getValue().buf(),
+                      originalInterestName.get(KEY_LOCATOR).getValue().size());
+  m_signature = Signature(Signature(signatureInfo, signatureBlock));
+
+  SignatureSha256WithRsa sha256RsaSig(m_signature); 
+  m_inviterCertificateName = sha256RsaSig.getKeyLocator().getName();
+  
+  m_inviterNameSpace = IdentityCertificate::certificateNameToPublicKeyName(m_inviterCertificateName).getPrefix(-1);
+
+  m_inviterRoutingPrefix.wireDecode(Block(originalInterestName.get(INVITER_PREFIX).getValue().buf(),
+                                          originalInterestName.get(INVITER_PREFIX).getValue().size()));
+  
+  m_chatroom.wireDecode(Block(originalInterestName.get(CHATROOM).getValue().buf(),
+                              originalInterestName.get(CHATROOM).getValue().size()));
+
+  m_inviteeNameSpace = originalInterestName.getSubName(INVITEE_START, nameSize - NAME_SIZE_MIN);  
+  
+  m_isSigned = true;
+}
+
+ChronosInvitation::ChronosInvitation(const Name &inviteeNameSpace,
+                                     const Name &chatroom,
+                                     const Name &inviterRoutingPrefix,
+                                     const Name &inviterCertificateName)
+  : m_inviteeNameSpace(inviteeNameSpace)
+  , m_chatroom(chatroom)
+  , m_inviterRoutingPrefix(inviterRoutingPrefix)
+  , m_inviterCertificateName(inviterCertificateName)
+{
+  //implicit conversion, we do not keep version number in KeyLocator;
+  SignatureSha256WithRsa sha256RsaSig; 
+  sha256RsaSig.setKeyLocator(KeyLocator(inviterCertificateName.getPrefix(-1)));
+  m_signature.setInfo(sha256RsaSig.getInfo());
+  m_inviterNameSpace = IdentityCertificate::certificateNameToPublicKeyName(m_inviterCertificateName).getPrefix(-1);
+  
+  m_interestName = INVITATION_PREFIX;
+  m_interestName.append(inviteeNameSpace).append(chatroom.wireEncode()).append(inviterRoutingPrefix.wireEncode()).append(m_signature.getInfo());
+
+  m_signedBlob = Buffer(m_interestName.wireEncode().value(), m_interestName.wireEncode().value_size());
+  m_isSigned = false;
 }
 
 ChronosInvitation::ChronosInvitation(const ChronosInvitation& invitation)
   : m_interestName(invitation.m_interestName)
+  , m_signedBlob(invitation.m_signedBlob)
   , m_inviteeNameSpace(invitation.m_inviteeNameSpace)
   , m_chatroom(invitation.m_chatroom)
-  , m_inviterPrefix(invitation.m_inviterPrefix)
+  , m_inviterRoutingPrefix(invitation.m_inviterRoutingPrefix)
   , m_inviterCertificateName(invitation.m_inviterCertificateName)
-  , m_signatureBits(invitation.m_signatureBits)
+  , m_signature(invitation.m_signature)
   , m_inviterNameSpace(invitation.m_inviterNameSpace)
-  , m_signedBlob(invitation.m_signedBlob)
+  , m_isSigned(invitation.m_isSigned)
 {}
+
+void
+ChronosInvitation::setSignatureValue(const ndn::Block &signatureValue)
+{
+  if(m_isSigned)
+    return;
+
+  m_interestName.append(signatureValue);
+  m_signature.setValue(signatureValue);
+  m_isSigned = true;
+}
diff --git a/src/chronos-invitation.h b/src/chronos-invitation.h
index 98380e8..d17a144 100644
--- a/src/chronos-invitation.h
+++ b/src/chronos-invitation.h
@@ -12,10 +12,22 @@
 #define CHRONOS_INVITATION_H
 
 
-#include <ndn-cpp/name.hpp>
+#include <ndn-cpp-dev/name.hpp>
+#include <ndn-cpp-dev/signature.hpp>
 
 class ChronosInvitation
 {
+/*
+ * /ndn/broadcast/chronos/invitation/[invitee_namespace]/<chatroom_name>/<inviter_routing_prefix>/<keylocator>/<signature>
+ */
+  static const size_t NAME_SIZE_MIN;
+  static const size_t INVITEE_START;
+  static const ssize_t SIGNATURE;
+  static const ssize_t KEY_LOCATOR;
+  static const ssize_t INVITER_PREFIX;
+  static const ssize_t CHATROOM;
+  static const ndn::Name INVITATION_PREFIX;
+
 public:
   struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
 
@@ -23,6 +35,11 @@
 
   ChronosInvitation(const ndn::Name& interestName);
 
+  ChronosInvitation(const ndn::Name &inviteeNameSpace,
+                    const ndn::Name &chatroom,
+                    const ndn::Name &inviterRoutingPrefix,
+                    const ndn::Name &inviterCertificateName);
+
   ChronosInvitation(const ChronosInvitation& invitation);
 
   virtual
@@ -37,16 +54,16 @@
   { return m_chatroom; }
 
   const ndn::Name&
-  getInviterPrefix() const
-  { return m_inviterPrefix; }
+  getInviterRoutingPrefix() const
+  { return m_inviterRoutingPrefix; }
 
   const ndn::Name&
   getInviterCertificateName() const
   { return m_inviterCertificateName; }
 
-  const ndn::Buffer&
-  getSignatureBits() const
-  { return m_signatureBits; }
+  const ndn::Signature&
+  getSignature() const
+  { return m_signature; }
 
   const ndn::Name&
   getInviterNameSpace() const
@@ -58,19 +75,29 @@
   
   const ndn::Name&
   getInterestName() const
-  { return m_interestName; }
+  {
+    if(m_isSigned)
+      return m_interestName; 
+    else
+      throw Error("Invitation is not signed!");
+  }
+
+  void
+  setSignatureValue(const ndn::Block &signatureValue);
 
 private:
   ndn::Name m_interestName;
+  ndn::Buffer m_signedBlob;
 
   ndn::Name m_inviteeNameSpace;
   ndn::Name m_chatroom;
-  ndn::Name m_inviterPrefix;
+  ndn::Name m_inviterRoutingPrefix;
   ndn::Name m_inviterCertificateName;
-  ndn::Buffer m_signatureBits;
+  ndn::Signature m_signature;
+
   ndn::Name m_inviterNameSpace;
 
-  ndn::Buffer m_signedBlob;
+  bool m_isSigned;
 };
 
 #endif
diff --git a/src/contact-item.h b/src/contact-item.h
index 238f647..4442ada 100644
--- a/src/contact-item.h
+++ b/src/contact-item.h
@@ -11,7 +11,7 @@
 #ifndef LINKNDN_CONTACT_ITEM_H
 #define LINKNDN_CONTACT_ITEM_H
 
-#include <ndn-cpp/data.hpp>
+#include <ndn-cpp-dev/data.hpp>
 #include <ndn-cpp-et/regex/regex.hpp>
 #include <vector>
 #include "endorse-certificate.h"
diff --git a/src/contact-manager.cpp b/src/contact-manager.cpp
index a70be49..f2ff6cc 100644
--- a/src/contact-manager.cpp
+++ b/src/contact-manager.cpp
@@ -24,11 +24,11 @@
 #include "contact-manager.h"
 
 #ifndef Q_MOC_RUN
-#include <ndn-cpp/face.hpp>
-#include <ndn-cpp/security/signature-sha256-with-rsa.hpp>
-#include <ndn-cpp/security/verifier.hpp>
+#include <ndn-cpp-dev/face.hpp>
+#include <ndn-cpp-dev/security/signature-sha256-with-rsa.hpp>
+#include <ndn-cpp-dev/security/verifier.hpp>
 #include <cryptopp/base64.h>
-#include <ndn-cpp-et/policy/sec-rule-identity.hpp>
+#include <ndn-cpp-et/policy/sec-rule-relative.hpp>
 #include <ndn-cpp-et/policy/sec-policy-simple.hpp>
 #include <fstream>
 #include "endorse-collection.pb.h"
@@ -64,27 +64,27 @@
   m_verifier = make_shared<Verifier>(policy);
   m_verifier->setFace(m_face);
 
-  policy->addVerificationPolicyRule(make_shared<SecRuleIdentity>("^([^<DNS>]*)<DNS><ENDORSED>",
+  policy->addVerificationPolicyRule(make_shared<SecRuleRelative>("^([^<DNS>]*)<DNS><ENDORSED>",
                                                                  "^([^<KEY>]*)<KEY>(<>*)[<ksk-.*><dsk-.*>]<ID-CERT>$",
                                                                  "==", "\\1", "\\1\\2", true));
-  policy->addVerificationPolicyRule(make_shared<SecRuleIdentity>("^([^<DNS>]*)<DNS><PROFILE>",
+  policy->addVerificationPolicyRule(make_shared<SecRuleRelative>("^([^<DNS>]*)<DNS><PROFILE>",
                                                                  "^([^<KEY>]*)<KEY>(<>*)[<ksk-.*><dsk-.*>]<ID-CERT>$",
                                                                  "==", "\\1", "\\1\\2", true));
-  policy->addVerificationPolicyRule(make_shared<SecRuleIdentity>("^([^<PROFILE-CERT>]*)<PROFILE-CERT>",
+  policy->addVerificationPolicyRule(make_shared<SecRuleRelative>("^([^<PROFILE-CERT>]*)<PROFILE-CERT>",
                                                                  "^([^<KEY>]*)<KEY>(<>*<ksk-.*>)<ID-CERT>$", 
                                                                  "==", "\\1", "\\1\\2", true));
-  policy->addVerificationPolicyRule(make_shared<SecRuleIdentity>("^([^<KEY>]*)<KEY>(<>*)<ksk-.*><ID-CERT>",
+  policy->addVerificationPolicyRule(make_shared<SecRuleRelative>("^([^<KEY>]*)<KEY>(<>*)<ksk-.*><ID-CERT>",
                                                                  "^([^<KEY>]*)<KEY><dsk-.*><ID-CERT>$",
                                                                  ">", "\\1\\2", "\\1", true));
-  policy->addVerificationPolicyRule(make_shared<SecRuleIdentity>("^([^<KEY>]*)<KEY><dsk-.*><ID-CERT>",
+  policy->addVerificationPolicyRule(make_shared<SecRuleRelative>("^([^<KEY>]*)<KEY><dsk-.*><ID-CERT>",
                                                                  "^([^<KEY>]*)<KEY>(<>*)<ksk-.*><ID-CERT>$",
                                                                  "==", "\\1", "\\1\\2", true));
-  policy->addVerificationPolicyRule(make_shared<SecRuleIdentity>("^(<>*)$", 
+  policy->addVerificationPolicyRule(make_shared<SecRuleRelative>("^(<>*)$", 
                                                                  "^([^<KEY>]*)<KEY>(<>*)<ksk-.*><ID-CERT>$", 
                                                                  ">", "\\1", "\\1\\2", true));
   
 
-  policy->addSigningPolicyRule(make_shared<SecRuleIdentity>("^([^<DNS>]*)<DNS><PROFILE>",
+  policy->addSigningPolicyRule(make_shared<SecRuleRelative>("^([^<DNS>]*)<DNS><PROFILE>",
                                                             "^([^<KEY>]*)<KEY>(<>*)<><ID-CERT>",
                                                             "==", "\\1", "\\1\\2", true));
 
diff --git a/src/contact-manager.h b/src/contact-manager.h
index a188fdb..84f1d22 100644
--- a/src/contact-manager.h
+++ b/src/contact-manager.h
@@ -18,9 +18,9 @@
 #include "dns-storage.h"
 #include "endorse-certificate.h"
 #include "profile.h"
-#include <ndn-cpp/face.hpp>
-#include <ndn-cpp/security/key-chain.hpp>
-#include <ndn-cpp/security/verifier.hpp>
+#include <ndn-cpp-dev/face.hpp>
+#include <ndn-cpp-dev/security/key-chain.hpp>
+#include <ndn-cpp-dev/security/verifier.hpp>
 #endif
 
 typedef ndn::func_lib::function<void()> TimeoutNotify;
diff --git a/src/contactpanel.cpp b/src/contactpanel.cpp
index 27978da..0c0c5b8 100644
--- a/src/contactpanel.cpp
+++ b/src/contactpanel.cpp
@@ -21,8 +21,8 @@
 #include <QtSql/QSqlError>
 
 #ifndef Q_MOC_RUN
-#include <ndn-cpp/security/verifier.hpp>
-#include <ndn-cpp/security/signature-sha256-with-rsa.hpp>
+#include <ndn-cpp-dev/security/verifier.hpp>
+#include <ndn-cpp-dev/security/signature-sha256-with-rsa.hpp>
 #include <boost/filesystem.hpp>
 #include <boost/random/random_device.hpp>
 #include <boost/random/uniform_int_distribution.hpp>
@@ -417,15 +417,13 @@
       return;
     }
 
+  const SignatureSha256WithRsa& invitationSig = invitation->getSignature();
   shared_ptr<PublicKey> keyPtr = m_policy->getTrustedKey(invitation->getInviterCertificateName());
 
-  SignatureSha256WithRsa invitationSig;
-  Block sigBlock(invitation->getSignatureBits().buf(), invitation->getSignatureBits().size());
-  invitationSig.setValue(sigBlock);
   if(static_cast<bool>(keyPtr) && Verifier::verifySignature(invitation->getSignedBlob(), invitationSig, *keyPtr))
     {
       shared_ptr<IdentityCertificate> certificate = make_shared<IdentityCertificate>();
-      // hack: incomplete certificate, we don't send it to the wire nor store it anywhere, we only use it to carry information
+      // hack: incomplete certificate, we don't send it to the wire nor store it anywhere, we only use it to pass information
       certificate->setName(invitation->getInviterCertificateName());
       bool findCert = false;
       vector<shared_ptr<ContactItem> >::const_iterator it = m_contactList.begin();
@@ -465,9 +463,7 @@
 {
   shared_ptr<IdentityCertificate> certificate = make_shared<IdentityCertificate>(*data);
 
-  SignatureSha256WithRsa invitationSig;
-  Block sigBlock(invitation->getSignatureBits().buf(), invitation->getSignatureBits().size());
-  invitationSig.setValue(sigBlock);
+  SignatureSha256WithRsa invitationSig(invitation->getSignature());
   
   if(Verifier::verifySignature(invitation->getSignedBlob(), invitationSig, certificate->getPublicKeyInfo()))
     {
@@ -842,7 +838,7 @@
   connect(chatDialog, SIGNAL(inivationRejection(const QString&)),
           this, SLOT(showWarning(const QString&)));
 
-  chatDialog->addChatDataRule(invitation.getInviterPrefix(), identityCertificate, true);
+  chatDialog->addChatDataRule(invitation.getInviterRoutingPrefix(), identityCertificate, true);
   chatDialog->publishIntroCert(identityCertificate, true);
 
   chatDialog->addTrustAnchor(inviterItem->getSelfEndorseCertificate());
diff --git a/src/contactpanel.h b/src/contactpanel.h
index 8bc08e5..4d9eb8d 100644
--- a/src/contactpanel.h
+++ b/src/contactpanel.h
@@ -275,7 +275,7 @@
   StartChatDialog* m_startChatDialog;
   InvitationDialog* m_invitationDialog;
   SettingDialog* m_settingDialog;
-  std::map<ndn::Name, ChatDialog*, ndn::Name::BreadthFirstLess> m_chatDialogs;
+  std::map<ndn::Name, ChatDialog*> m_chatDialogs;
   QAction* m_menuInvite;
   QAction* m_menuAlias;
   std::vector<ndn::ptr_lib::shared_ptr<ContactItem> > m_contactList;
diff --git a/src/dns-storage.h b/src/dns-storage.h
index de37540..8b0880d 100644
--- a/src/dns-storage.h
+++ b/src/dns-storage.h
@@ -12,7 +12,7 @@
 #define LINKNDN_DNS_STORAGE_H
 
 #include <sqlite3.h>
-#include <ndn-cpp/data.hpp>
+#include <ndn-cpp-dev/data.hpp>
 
 class DnsStorage
 {
diff --git a/src/endorse-certificate.cpp b/src/endorse-certificate.cpp
index ae07796..0fd6ba0 100644
--- a/src/endorse-certificate.cpp
+++ b/src/endorse-certificate.cpp
@@ -10,14 +10,12 @@
 
 #include "endorse-certificate.h"
 #include "endorse-extension.pb.h"
-#include <boost/date_time/posix_time/posix_time.hpp>
 #include <boost/iostreams/stream.hpp>
 #include "logging.h"
 
 using namespace std;
 using namespace ndn;
 using namespace ndn::ptr_lib;
-using namespace boost::posix_time;
 
 INIT_LOGGER("EndorseCertificate");
 
@@ -101,11 +99,8 @@
   , m_profileData(profileData)
   , m_endorseList(endorseList)
 {
-  time_duration now = microsec_clock::universal_time () - ptime(boost::gregorian::date (1970, boost::gregorian::Jan, 1));
-  uint64_t version = (now.total_seconds () << 12) | (0xFFF & (now.fractional_seconds () / 244));
-
   Name dataName = m_keyName;
-  dataName.append("PROFILE-CERT").append(m_signer).appendVersion(version);
+  dataName.append("PROFILE-CERT").append(m_signer.wireEncode()).appendVersion();
   setName(dataName);
 
   setNotBefore(kskCertificate.getNotBefore());
@@ -126,12 +121,9 @@
   , m_signer(signer)
   , m_profileData(endorseCertificate.m_profileData)
   , m_endorseList(endorseList)
-{
-  time_duration now = microsec_clock::universal_time () - ptime(boost::gregorian::date (1970, boost::gregorian::Jan, 1));
-  uint64_t version = (now.total_seconds () << 12) | (0xFFF & (now.fractional_seconds () / 244));
-  
+{  
   Name dataName = m_keyName;
-  dataName.append("PROFILE-CERT").append(m_signer).appendVersion(version);
+  dataName.append("PROFILE-CERT").append(m_signer.wireEncode()).appendVersion();
   setName(dataName);
   
   setNotBefore(endorseCertificate.getNotBefore());
@@ -156,21 +148,13 @@
   : Certificate(data)
 {
   const Name& dataName = data.getName();
-  Name::Component certFlag(Name::fromEscapedString("PROFILE-CERT"));  
-  int profileIndex = -1;
-  for(int i = 0; i < dataName.size(); i++)
-    {
-      if(0 == dataName.get(i).compare(certFlag))
-	{
-	  profileIndex = i;
-	  break;
-	}
-    }
-  if(profileIndex < 0)
-    throw Error("No PROFILE-CERT component in data name!");
 
-  m_keyName = dataName.getSubName(0, profileIndex);
-  m_signer = dataName.getSubName(profileIndex + 1, dataName.size() - profileIndex - 2);
+  if(dataName.size() < 3 || !dataName.get(-3).equals("PROFILE-CERT"))
+    throw Error("No PROFILE-CERT component in data name!");    
+
+  m_keyName = dataName.getPrefix(-3);
+  m_signer.wireDecode(Block(dataName.get(-2).getValue().buf(),
+                            dataName.get(-2).getValue().size()));
 
   OID profileExtensionOID("1.3.6.1.5.32.2.1");
   OID endorseExtensionOID("1.3.6.1.5.32.2.2");
diff --git a/src/endorse-certificate.h b/src/endorse-certificate.h
index c1ebcf5..4d011d6 100644
--- a/src/endorse-certificate.h
+++ b/src/endorse-certificate.h
@@ -12,9 +12,9 @@
 #define LINKNDN_ENDORSE_CERTIFICATE_H
 
 #include <vector>
-#include <ndn-cpp/data.hpp>
-#include <ndn-cpp/security/identity-certificate.hpp>
-#include <ndn-cpp/security/certificate-extension.hpp>
+#include <ndn-cpp-dev/data.hpp>
+#include <ndn-cpp-dev/security/identity-certificate.hpp>
+#include <ndn-cpp-dev/security/certificate-extension.hpp>
 
 #include "profile-data.h"
 
diff --git a/src/invitationdialog.h b/src/invitationdialog.h
index 9326cf6..2e01fd9 100644
--- a/src/invitationdialog.h
+++ b/src/invitationdialog.h
@@ -14,8 +14,8 @@
 #include <QDialog>
 
 #ifndef Q_MOC_RUN
-#include <ndn-cpp/data.hpp>
-#include <ndn-cpp/security/identity-certificate.hpp>
+#include <ndn-cpp-dev/data.hpp>
+#include <ndn-cpp-dev/security/identity-certificate.hpp>
 #include "chronos-invitation.h"
 #endif
 
diff --git a/src/profile-data.h b/src/profile-data.h
index 92353a1..46a926d 100644
--- a/src/profile-data.h
+++ b/src/profile-data.h
@@ -11,7 +11,7 @@
 #ifndef LINKNDN_PROFILE_DATA_H
 #define LINKNDN_PROFILE_DATA_H
 
-#include <ndn-cpp/data.hpp>
+#include <ndn-cpp-dev/data.hpp>
 #include "profile.h"
 
 class ProfileData : public ndn::Data
diff --git a/src/profile.h b/src/profile.h
index 1d1390d..2afef31 100644
--- a/src/profile.h
+++ b/src/profile.h
@@ -11,8 +11,8 @@
 #ifndef LINKNDN_PROFILE_H
 #define LINKNDN_PROFILE_H
 
-#include <ndn-cpp/name.hpp>
-#include <ndn-cpp/security/identity-certificate.hpp>
+#include <ndn-cpp-dev/name.hpp>
+#include <ndn-cpp-dev/security/identity-certificate.hpp>
 #include <map>
 #include <string>
 #include "profile.pb.h"
diff --git a/src/profileeditor.h b/src/profileeditor.h
index 5446be9..0bf1b30 100644
--- a/src/profileeditor.h
+++ b/src/profileeditor.h
@@ -16,7 +16,7 @@
 
 #ifndef Q_MOC_RUN
 #include "contact-manager.h"
-#include <ndn-cpp/security/key-chain.hpp>
+#include <ndn-cpp-dev/security/key-chain.hpp>
 #endif
 
 namespace Ui {
diff --git a/src/sec-policy-chrono-chat-invitation.cpp b/src/sec-policy-chrono-chat-invitation.cpp
index 23d2b10..f0daf90 100644
--- a/src/sec-policy-chrono-chat-invitation.cpp
+++ b/src/sec-policy-chrono-chat-invitation.cpp
@@ -9,8 +9,8 @@
  */
 
 #include "sec-policy-chrono-chat-invitation.h"
-#include <ndn-cpp/security/verifier.hpp>
-#include <ndn-cpp/security/signature-sha256-with-rsa.hpp>
+#include <ndn-cpp-dev/security/verifier.hpp>
+#include <ndn-cpp-dev/security/signature-sha256-with-rsa.hpp>
 
 #include "logging.h"
 
@@ -27,13 +27,13 @@
   , m_signingIdentity(signingIdentity)
   , m_stepLimit(stepLimit)
 {
-  m_invitationPolicyRule = make_shared<SecRuleIdentity>("^<ndn><broadcast><chronos><invitation>([^<chatroom>]*)<chatroom>", 
+  m_invitationPolicyRule = make_shared<SecRuleRelative>("^<ndn><broadcast><chronos><invitation>([^<chatroom>]*)<chatroom>", 
                                                            "^([^<KEY>]*)<KEY>(<>*)[<dsk-.*><ksk-.*>]<ID-CERT>$", 
                                                            "==", "\\1", "\\1\\2", true);
 
   m_kskRegex = make_shared<Regex>("^([^<KEY>]*)<KEY>(<>*<ksk-.*>)<ID-CERT><>$", "\\1\\2");
 
-  m_dskRule = make_shared<SecRuleIdentity>("^([^<KEY>]*)<KEY><dsk-.*><ID-CERT><>$", 
+  m_dskRule = make_shared<SecRuleRelative>("^([^<KEY>]*)<KEY><dsk-.*><ID-CERT><>$", 
                                               "^([^<KEY>]*)<KEY>(<>*)<ksk-.*><ID-CERT>$", 
                                               "==", "\\1", "\\1\\2", true);
 
diff --git a/src/sec-policy-chrono-chat-invitation.h b/src/sec-policy-chrono-chat-invitation.h
index 8d9e898..28b5903 100644
--- a/src/sec-policy-chrono-chat-invitation.h
+++ b/src/sec-policy-chrono-chat-invitation.h
@@ -11,14 +11,14 @@
 #ifndef SEC_POLICY_CHRONO_CHAT_INVITATION_H
 #define SEC_POLICY_CHRONO_CHAT_INVITATION_H
 
-#include <ndn-cpp/security/sec-policy.hpp>
-#include <ndn-cpp-et/policy/sec-rule-identity.hpp>
+#include <ndn-cpp-dev/security/sec-policy.hpp>
+#include <ndn-cpp-et/policy/sec-rule-relative.hpp>
+#include <ndn-cpp-et/policy/sec-rule-specific.hpp>
 #include <ndn-cpp-et/cache/ttl-certificate-cache.hpp>
 #include <ndn-cpp-et/regex/regex.hpp>
 #include <map>
 
 #include "endorse-certificate.h"
-#include "sec-rule-chrono-chat.h"
 
 class SecPolicyChronoChatInvitation : public ndn::SecPolicy
 {
@@ -79,16 +79,16 @@
 
   ndn::TTLCertificateCache m_certificateCache;
 
-  ndn::ptr_lib::shared_ptr<ndn::SecRuleIdentity> m_invitationPolicyRule;
-  ndn::ptr_lib::shared_ptr<ndn::SecRuleIdentity> m_dskRule;
-  std::map<ndn::Name, SecRuleChronoChat, ndn::Name::BreadthFirstLess> m_chatDataRules;
+  ndn::ptr_lib::shared_ptr<ndn::SecRuleRelative> m_invitationPolicyRule;
+  ndn::ptr_lib::shared_ptr<ndn::SecRuleRelative> m_dskRule;
+  std::map<ndn::Name, ndn::SecRuleSpecific> m_chatDataRules;
 
   ndn::ptr_lib::shared_ptr<ndn::Regex> m_kskRegex;
   ndn::ptr_lib::shared_ptr<ndn::Regex> m_keyNameRegex;
 
-  std::map<ndn::Name, ndn::PublicKey, ndn::Name::BreadthFirstLess> m_trustAnchors;
+  std::map<ndn::Name, ndn::PublicKey> m_trustAnchors;
 
-  std::map<ndn::Name, ndn::ptr_lib::shared_ptr<ndn::IdentityCertificate>, ndn::Name::BreadthFirstLess> m_dskCertificates;
+  std::map<ndn::Name, ndn::ptr_lib::shared_ptr<ndn::IdentityCertificate> > m_dskCertificates;
 
 };
 
diff --git a/src/sec-policy-chrono-chat-panel.cpp b/src/sec-policy-chrono-chat-panel.cpp
index c71e023..4ecc799 100644
--- a/src/sec-policy-chrono-chat-panel.cpp
+++ b/src/sec-policy-chrono-chat-panel.cpp
@@ -9,8 +9,8 @@
  */
 
 #include "sec-policy-chrono-chat-panel.h"
-#include <ndn-cpp/security/verifier.hpp>
-#include <ndn-cpp/security/signature-sha256-with-rsa.hpp>
+#include <ndn-cpp-dev/security/verifier.hpp>
+#include <ndn-cpp-dev/security/signature-sha256-with-rsa.hpp>
 // #include <boost/bind.hpp>
 
 #include "logging.h"
@@ -27,15 +27,15 @@
 {
   m_localPrefixRegex = make_shared<Regex>("^<local><ndn><prefix><><>$");
 
-  m_invitationDataSigningRule = make_shared<SecRuleIdentity>("^<ndn><broadcast><chronos><invitation>([^<chatroom>]*)<chatroom>", 
+  m_invitationDataSigningRule = make_shared<SecRuleRelative>("^<ndn><broadcast><chronos><invitation>([^<chatroom>]*)<chatroom>", 
                                                                 "^([^<KEY>]*)<KEY>(<>*)<><ID-CERT><>$", 
                                                                 "==", "\\1", "\\1\\2", true);
   
-  m_dskRule = make_shared<SecRuleIdentity>("^([^<KEY>]*)<KEY><dsk-.*><ID-CERT><>$", 
+  m_dskRule = make_shared<SecRuleRelative>("^([^<KEY>]*)<KEY><dsk-.*><ID-CERT><>$", 
                                               "^([^<KEY>]*)<KEY>(<>*)<ksk-.*><ID-CERT>$", 
                                               "==", "\\1", "\\1\\2", true);
   
-  m_endorseeRule = make_shared<SecRuleIdentity>("^([^<DNS>]*)<DNS><>*<ENDORSEE><>$", 
+  m_endorseeRule = make_shared<SecRuleRelative>("^([^<DNS>]*)<DNS><>*<ENDORSEE><>$", 
                                                    "^([^<KEY>]*)<KEY>(<>*)<ksk-.*><ID-CERT>$", 
                                                    "==", "\\1", "\\1\\2", true);
   
diff --git a/src/sec-policy-chrono-chat-panel.h b/src/sec-policy-chrono-chat-panel.h
index 991195f..221e943 100644
--- a/src/sec-policy-chrono-chat-panel.h
+++ b/src/sec-policy-chrono-chat-panel.h
@@ -11,8 +11,8 @@
 #ifndef SEC_POLICY_CHRONO_CHAT_PANEL_H
 #define SEC_POLICY_CHRONO_CHAT_PANEL_H
 
-#include <ndn-cpp/security/sec-policy.hpp>
-#include <ndn-cpp-et/policy/sec-rule-identity.hpp>
+#include <ndn-cpp-dev/security/sec-policy.hpp>
+#include <ndn-cpp-et/policy/sec-rule-relative.hpp>
 #include <ndn-cpp-et/cache/ttl-certificate-cache.hpp>
 #include <map>
 
@@ -88,13 +88,13 @@
   int m_stepLimit;
   ndn::TTLCertificateCache m_certificateCache;
   ndn::ptr_lib::shared_ptr<ndn::Regex> m_localPrefixRegex;
-  ndn::ptr_lib::shared_ptr<ndn::SecRuleIdentity> m_invitationDataSigningRule;
+  ndn::ptr_lib::shared_ptr<ndn::SecRuleRelative> m_invitationDataSigningRule;
   ndn::ptr_lib::shared_ptr<ndn::Regex> m_kskRegex;
-  ndn::ptr_lib::shared_ptr<ndn::SecRuleIdentity> m_dskRule;
-  ndn::ptr_lib::shared_ptr<ndn::SecRuleIdentity> m_endorseeRule;
+  ndn::ptr_lib::shared_ptr<ndn::SecRuleRelative> m_dskRule;
+  ndn::ptr_lib::shared_ptr<ndn::SecRuleRelative> m_endorseeRule;
   ndn::ptr_lib::shared_ptr<ndn::Regex> m_keyNameRegex;
   ndn::ptr_lib::shared_ptr<ndn::Regex> m_signingCertificateRegex;
-  std::map<ndn::Name, ndn::PublicKey, ndn::Name::BreadthFirstLess> m_trustAnchors;
+  std::map<ndn::Name, ndn::PublicKey> m_trustAnchors;
   
 };
 
diff --git a/src/sec-rule-chrono-chat.cpp b/src/sec-rule-chrono-chat.cpp
deleted file mode 100644
index b62b6a8..0000000
--- a/src/sec-rule-chrono-chat.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013, Regents of the University of California
- *                     Yingdi Yu
- *
- * BSD license, See the LICENSE file for more information
- *
- * Author: Yingdi Yu <yingdi@cs.ucla.edu>
- */
-
-#include "sec-rule-chrono-chat.h"
-#include <ndn-cpp/security/signature-sha256-with-rsa.hpp>
-
-using namespace ndn;
-using namespace std;
-using namespace ndn::ptr_lib;
-
-
-SecRuleChronoChat::SecRuleChronoChat(shared_ptr<Regex> dataRegex,
-                                     shared_ptr<Regex> signerRegex)
-  : SecRule(SecRule::IDENTITY_RULE, true)
-  , m_dataRegex(dataRegex)
-  , m_signerRegex(signerRegex)
-{}
-
-SecRuleChronoChat::SecRuleChronoChat(const SecRuleChronoChat& rule)
-  : SecRule(SecRule::IDENTITY_RULE, true)
-  , m_dataRegex(rule.m_dataRegex)
-  , m_signerRegex(rule.m_signerRegex)
-{}
-
-bool 
-SecRuleChronoChat::matchDataName(const Data & data)
-{ return m_dataRegex->match(data.getName()); }
-
-bool 
-SecRuleChronoChat::matchSignerName(const Data & data)
-{ 
-  try{
-    SignatureSha256WithRsa sig(data.getSignature());
-    Name signerName = sig.getKeyLocator().getName ();
-    return m_signerRegex->match(signerName); 
-  }catch(SignatureSha256WithRsa::Error &e){
-    return false;
-  }catch(KeyLocator::Error &e){
-    return false;
-  }
-}
-
-bool
-SecRuleChronoChat::satisfy(const Data & data)
-{ return (matchDataName(data) && matchSignerName(data)) ? true : false ; }
-
-bool
-SecRuleChronoChat::satisfy(const Name & dataName, const Name & signerName)
-{ return (m_dataRegex->match(dataName) && m_signerRegex->match(signerName)); }
diff --git a/src/sec-rule-chrono-chat.h b/src/sec-rule-chrono-chat.h
deleted file mode 100644
index d165122..0000000
--- a/src/sec-rule-chrono-chat.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013, Regents of the University of California
- *                     Yingdi Yu
- *
- * BSD license, See the LICENSE file for more information
- *
- * Author: Yingdi Yu <yingdi@cs.ucla.edu>
- */
-
-#ifndef SEC_RULE_CHRONO_CHAT_H
-#define SEC_RULE_CHRONO_CHAT_H
-
-#include <ndn-cpp-et/policy/sec-rule.hpp>
-#include <ndn-cpp-et/regex/regex.hpp>
-
-class SecRuleChronoChat : public ndn::SecRule
-{
-  
-public:
-  SecRuleChronoChat(ndn::ptr_lib::shared_ptr<ndn::Regex> dataRegex,
-                    ndn::ptr_lib::shared_ptr<ndn::Regex> signerRegex);
-
-  SecRuleChronoChat(const SecRuleChronoChat& rule);
-
-  virtual
-  ~SecRuleChronoChat() {};
-
-  bool 
-  matchDataName(const ndn::Data & data);
-
-  bool 
-  matchSignerName(const ndn::Data & data);
-
-  bool
-  satisfy(const ndn::Data & data);
-
-  bool
-  satisfy(const ndn::Name & dataName, const ndn::Name & signerName);
-  
-private:
-  ndn::ptr_lib::shared_ptr<ndn::Regex> m_dataRegex;
-  ndn::ptr_lib::shared_ptr<ndn::Regex> m_signerRegex;
-};
-
-#endif //CHAT_POLICY_RULE_H