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

Change-Id: Ie51f5377690ccaf1fd3ffe90df68ce3f537b029d
diff --git a/ChronoSync b/ChronoSync
index 5e0af3e..531803b 160000
--- a/ChronoSync
+++ b/ChronoSync
@@ -1 +1 @@
-Subproject commit 5e0af3eccea6958e51d148f6a2d168a309398d38
+Subproject commit 531803bae995976d913c323c454e26f18994daa7
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
diff --git a/test/endorse-certificate-test.cc b/test/endorse-certificate-test.cc
new file mode 100644
index 0000000..23075e3
--- /dev/null
+++ b/test/endorse-certificate-test.cc
@@ -0,0 +1,115 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/**
+ * Copyright (C) 2013 Regents of the University of California.
+ * @author: Yingdi Yu <yingdi@cs.ucla.edu>
+ * See COPYING for copyright and distribution information.
+ */
+
+#if __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wreorder"
+#pragma clang diagnostic ignored "-Wtautological-compare"
+#pragma clang diagnostic ignored "-Wunused-variable"
+#pragma clang diagnostic ignored "-Wunused-function"
+#elif __GNUC__
+#pragma GCC diagnostic ignored "-Wreorder"
+#pragma GCC diagnostic ignored "-Wunused-variable"
+#pragma GCC diagnostic ignored "-Wunused-function"
+#endif
+
+#include <boost/test/unit_test.hpp>
+
+#include <iostream>
+#include <iomanip>
+#include <cryptopp/base64.h>
+#include <ndn-cpp/security/key-chain.hpp>
+#include "endorse-certificate.h"
+
+using namespace ndn;
+using namespace ndn::ptr_lib;
+using namespace std;
+
+BOOST_AUTO_TEST_SUITE(EndorseCertificateTests)
+
+const string aliceCert("BIICqgOyEIUBbIk+NUYUb6QYOBmPyWrhj9WiEKgoAzXAjQ+gz6iAmeX4srvcH3dQ\
+a/Y1H4Vf/LmNrXUsqbEJn1tmGoxGoQlkMtuKZ9K9X40R2SbH8d01IOIHILodRdG3\
+KXlsXS13vBkuGB8RwhMCh3RCBc6K10LQ87TkkpLdYpIjS8n2stQn2HgiHPsIUGyE\
+yLXqJ8ght2ZLVUYzHcpW4D0asckiQGXJuFmkGnbQVNHEBuirY8R1Zak6uDopoZi1\
+xvFCH6UkUXBzh3FhXrk/GA5Y6sZTKTDqo1fwz6GRubyhPq1+nHOM7ud5k4DoC6zI\
+Xstlhi5LSrCInSBItBaSNd2RPO3dbp0QAADy+p1uZG4A+sV1Y2xhLmVkdQD6nUtF\
+WQD6rWFsaWNlAPr1a3NrLTEzODI5MzQyMDEA+r1JRC1DRVJUAPrN/f/////ea6GX\
+AAABogPiAoX4UXq6YdztiNp79l71bcPBOBnRKOJBPKxDZTeC3YrfSgACurUFJt5r\
+oZgAAeIB6vL6nW5kbgD6xXVjbGEuZWR1APqdS0VZAPr1ZHNrLTEzODI5MzQyMDAA\
++r1JRC1DRVJUAAAAAAABmhfdMIIBdzAiGA8yMDEzMTAyODAwMDAwMFoYDzIwMzMx\
+MDI4MDAwMDAwWjArMCkGA1UEKRMiL25kbi91Y2xhLmVkdS9hbGljZS9rc2stMTM4\
+MjkzNDIwMTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJ9b5S6MJIDz\
+EyYDYL6/1PeeM1ZIr9lyDJojyLBa/nxvCkTykdeUEIEsQb0+B5UDcyS9iGZRlBUf\
+CXOjRlnbo5BtD0IWw2aR048RT3pDh2U+dsOsJQMdPwTAaegwv+BEBvWVX+A93xya\
+qoYQcJF56q6ktvxfFj5c4G6vuuuf8ZSGbIeesXy1P5wYdSu1ceTL8mnawR0+Nj2D\
+VG71gn1A9NiIBKKQcT0rUgxo3NOaPHBUdQP67qLdfBOj0HrktGndVDxD5pWbnxKU\
+V3zd/aD1DJuP826RJ8b/7eftdIF7/8gVRN5fz3wbjFtNzAE5RLmXP+ik8MhnHMx+\
+B2QkdwR+8gcCAwEAAQAA");
+
+KeyChain keyChain;
+
+BOOST_AUTO_TEST_CASE(ProfileDataEncodeDecode)
+{
+  string decoded;
+  CryptoPP::StringSource ss(reinterpret_cast<const unsigned char *>(aliceCert.c_str()), 
+                            aliceCert.size(), 
+                            true,
+                            new CryptoPP::Base64Decoder(new CryptoPP::StringSink(decoded)));
+  Data data;
+  data.wireDecode(Block(decoded.c_str(), decoded.size()));
+  IdentityCertificate identityCertificate(data);
+  
+  Profile profile(identityCertificate);
+  ProfileData profileData(profile);
+
+  Name certificateName = keyChain.getDefaultCertificateName();
+  keyChain.sign(profileData, certificateName);
+
+  const Block& profileDataBlock = profileData.wireEncode();
+  Data decodedProfileData;
+  
+  decodedProfileData.wireDecode(profileDataBlock);
+  ProfileData decodedProfile(decodedProfileData);
+  BOOST_CHECK_EQUAL(decodedProfile.getProfile().getProfileEntry("IDENTITY"), string("/ndn/ucla.edu/alice"));
+  BOOST_CHECK_EQUAL(decodedProfile.getProfile().getProfileEntry("name"), string("/ndn/ucla.edu/alice/ksk-1382934201"));
+}
+
+BOOST_AUTO_TEST_CASE(EndorseCertifiicateEncodeDecode)
+{
+  string decoded;
+  CryptoPP::StringSource ss(reinterpret_cast<const unsigned char *>(aliceCert.c_str()), 
+                            aliceCert.size(), 
+                            true,
+                            new CryptoPP::Base64Decoder(new CryptoPP::StringSink(decoded)));
+  Data data;
+  data.wireDecode(Block(decoded.c_str(), decoded.size()));
+  IdentityCertificate identityCertificate(data);
+
+  Profile profile(identityCertificate);
+  ProfileData profileData(profile);
+  
+  Name certificateName = keyChain.getDefaultCertificateName();
+  keyChain.sign(profileData, certificateName);
+
+  EndorseCertificate endorseCertificate(identityCertificate, profileData);
+
+  keyChain.sign(endorseCertificate, certificateName);
+  
+  const Block& endorseDataBlock = endorseCertificate.wireEncode();
+
+  Data decodedEndorseData;
+
+  decodedEndorseData.wireDecode(endorseDataBlock);
+  EndorseCertificate decodedEndorse(decodedEndorseData);
+  BOOST_CHECK_EQUAL(decodedEndorse.getProfileData().getProfile().getProfileEntry("IDENTITY"), string("/ndn/ucla.edu/alice"));
+  BOOST_CHECK_EQUAL(decodedEndorse.getProfileData().getProfile().getProfileEntry("name"), string("/ndn/ucla.edu/alice/ksk-1382934201"));
+}
+
+
+
+BOOST_AUTO_TEST_SUITE_END()
+
diff --git a/test/profile-test.cc b/test/profile-test.cc
new file mode 100644
index 0000000..b50f024
--- /dev/null
+++ b/test/profile-test.cc
@@ -0,0 +1,35 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/**
+ * Copyright (C) 2013 Regents of the University of California.
+ * @author: Yingdi Yu <yingdi@cs.ucla.edu>
+ * See COPYING for copyright and distribution information.
+ */
+
+#include <profile.h>
+
+#define BOOST_TEST_MODULE ChronoChat
+#include <boost/test/unit_test.hpp>
+
+using namespace ndn;
+using namespace std;
+
+BOOST_AUTO_TEST_SUITE(ProfileTests)
+
+BOOST_AUTO_TEST_CASE(WriteRead)
+{
+  Name identity("/ndn/ucla/yingdi");
+  Profile profile(identity);
+  profile.setProfileEntry(string("name"), string("Yingdi Yu"));
+  profile.setProfileEntry(string("school"), string("UCLA"));
+
+  string encoded;
+  profile.encode(&encoded);
+
+  ptr_lib::shared_ptr<Profile> decodedProfile = Profile::decode(encoded);
+  
+  BOOST_CHECK_EQUAL(decodedProfile->getIdentityName().toUri(), string("/ndn/ucla/yingdi"));
+  BOOST_CHECK_EQUAL(decodedProfile->getProfileEntry(string("name")), string("Yingdi Yu"));
+  BOOST_CHECK_EQUAL(decodedProfile->getProfileEntry(string("school")), string("UCLA"));
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/wscript b/wscript
index e147a74..9f65988 100644
--- a/wscript
+++ b/wscript
@@ -1,5 +1,5 @@
 # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
-VERSION='0.4'
+VERSION='0.5'
 APPNAME='ChronoChat'
 
 from waflib import Configure, Utils
@@ -7,122 +7,118 @@
 def options(opt):
     opt.add_option('--debug',action='store_true',default=False,dest='debug',help='''debugging mode''')
     opt.add_option('--log4cxx',action='store_true',default=False,dest='log4cxx',help='''Enable log4cxx''')
-    opt.add_option('--test', action='store_true',default=False,dest='_test',help='''build unit tests''')
+    opt.add_option('--with-test', action='store_true',default=False,dest='with_tests',help='''build unit tests''')
     
     opt.load('compiler_c compiler_cxx qt4')
 
     if Utils.unversioned_sys_platform () != "darwin":
         opt.load('gnu_dirs');
 
-    opt.load('boost protoc cryptopp ndn_cpp', tooldir=['waf-tools'])
+    opt.load('boost protoc', tooldir=['waf-tools'])
     
 def configure(conf):
-    conf.load("compiler_c compiler_cxx boost protoc qt4 cryptopp ndn_cpp")
+    conf.load("compiler_c compiler_cxx boost protoc qt4")
 
     if Utils.unversioned_sys_platform () != "darwin":
         conf.load('gnu_dirs');
 
     if conf.options.debug:
         conf.define ('_DEBUG', 1)
-        conf.env.DEBUG = 1
-        conf.add_supported_cxxflags (cxxflags = ['-O0',
-                                                 '-Wall',
-                                                 '-Wno-unused-variable',
-                                                 '-g3',
-                                                 '-Wno-unused-private-field', # only clang supports
-                                                 '-fcolor-diagnostics',       # only clang supports
-                                                 '-Qunused-arguments',        # only clang supports
-                                                 ])
+        flags = ['-O0',
+                 '-Wall',
+                 '-Wno-unused-variable',
+                 '-g3',
+                 '-Wno-unused-private-field', # only clang supports
+                 '-fcolor-diagnostics',       # only clang supports
+                 '-Qunused-arguments',        # only clang supports
+                 '-Wno-deprecated-declarations',
+                 ]
+
+        conf.add_supported_cxxflags (cxxflags = flags)
     else:
-        conf.add_supported_cxxflags (cxxflags = ['-O3', '-g', '-Wno-tautological-compare', '-Wno-unused-function'])
-        
-    conf.check_ndncpp (path=conf.options.ndn_cpp_dir)
-    conf.check_cfg(package='libndn-cpp-et', args=['--cflags', '--libs'], uselib_store='NDN-CPP-ET', mandatory=True)
+        flags = ['-O3', '-g', '-Wno-tautological-compare', '-Wno-unused-function', '-Wno-deprecated-declarations']
+        conf.add_supported_cxxflags (cxxflags = flags)
+
+    conf.check_cfg(package='libndn-cpp-dev', args=['--cflags', '--libs'], uselib_store='NDN_CPP', mandatory=True)
     
-    conf.check_cfg(package='sqlite3', args=['--cflags', '--libs'], uselib_store='SQLITE3', mandatory=True)
+    
     if conf.options.log4cxx:
         conf.check_cfg(package='liblog4cxx', args=['--cflags', '--libs'], uselib_store='LOG4CXX', mandatory=True)
+        conf.define ("HAVE_LOG4CXX", 1)
+        
     conf.check_cfg (package='ChronoSync', args=['ChronoSync >= 0.1', '--cflags', '--libs'], uselib_store='SYNC', mandatory=True)
 
-    conf.check_cryptopp(path=conf.options.cryptopp_dir)
-
-    conf.check_boost(lib='system random thread filesystem test')
+    conf.check_boost(lib='system random thread filesystem unit_test_framework')
 
     conf.write_config_header('config.h')
 
-    if conf.options._test:
-      conf.define('_TEST', 1)
+    if conf.options.with_tests:
+      conf.define('WITH_TESTS', 1)
 		
 def build (bld):
     qt = bld (
         target = "ChronoChat",
-        # features = "qt4 cxx cxxprogram",
-        features= "qt4 cxx cxxshlib",
+        features = "qt4 cxx cxxprogram",
+        #        features= "qt4 cxx cxxshlib",
         defines = "WAF",
         source = bld.path.ant_glob(['src/*.cpp', 'src/*.ui', '*.qrc', 'logging.cc', 'src/*.proto']),
         includes = "src .",
-        use = "QTCORE QTGUI QTWIDGETS QTSQL SQLITE3 NDNCPP NDN-CPP-ET BOOST BOOST_FILESYSTEM LOG4CXX CRYPTOPP SYNC",
+        use = "QTCORE QTGUI QTWIDGETS QTSQL SQLITE3 NDN_CPP BOOST LOG4CXX SYNC",
         )
 
     # Unit tests
-    if bld.get_define("_TEST"):
-      unittests = bld.program (
-          target="unit-tests",
-          source = bld.path.ant_glob(['test/**/*.cc']),
-          features=['cxx', 'cxxprogram'],
-          use = 'BOOST_TEST ChronoChat',
-          includes = ['src'],
-          )
+    # if bld.get_define("WITH_TESTS"):
+    #   unittests = bld.program (
+    #       target="unit-tests",
+    #       source = bld.path.ant_glob(['test/**/*.cc']),
+    #       features=['cxx', 'cxxprogram'],
+    #       use = 'BOOST ChronoChat',
+    #       install_path = None,
+    #       )
       # Tmp disable
-#     if Utils.unversioned_sys_platform () == "darwin":
-#         app_plist = '''<?xml version="1.0" encoding="UTF-8"?>
-# <!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
-# <plist version="0.9">
-# <dict>
-#     <key>CFBundlePackageType</key>
-#     <string>APPL</string>
-#     <key>CFBundleIconFile</key>
-#     <string>demo.icns</string>
-#     <key>CFBundleGetInfoString</key>
-#     <string>Created by Waf</string>
-#     <key>CFBundleIdentifier</key>
-#     <string>edu.ucla.cs.irl.ChronoChat</string>
-#     <key>CFBundleSignature</key>
-#     <string>????</string>
-#     <key>NOTE</key>
-#     <string>THIS IS A GENERATED FILE, DO NOT MODIFY</string>
-#     <key>CFBundleExecutable</key>
-#     <string>%s</string>
-#     <key>SUPublicDSAKeyFile</key>
-#     <string>dsa_pub.pem</string>
-#     <key>CFBundleIconFile</key>
-#     <string>demo.icns</string>
-# </dict>
-# </plist>'''
+    if Utils.unversioned_sys_platform () == "darwin":
+        app_plist = '''<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
+<plist version="0.9">
+<dict>
+    <key>CFBundlePackageType</key>
+    <string>APPL</string>
+    <key>CFBundleIconFile</key>
+    <string>demo.icns</string>
+    <key>CFBundleGetInfoString</key>
+    <string>Created by Waf</string>
+    <key>CFBundleIdentifier</key>
+    <string>edu.ucla.cs.irl.ChronoChat</string>
+    <key>CFBundleSignature</key>
+    <string>????</string>
+    <key>NOTE</key>
+    <string>THIS IS A GENERATED FILE, DO NOT MODIFY</string>
+    <key>CFBundleExecutable</key>
+    <string>%s</string>
+    <key>SUPublicDSAKeyFile</key>
+    <string>dsa_pub.pem</string>
+    <key>CFBundleIconFile</key>
+    <string>demo.icns</string>
+</dict>
+</plist>'''
 
-#     # <key>LSUIElement</key>
-#     # <string>1</string>
+    # <key>LSUIElement</key>
+    # <string>1</string>
 
-#         qt.mac_app = "ChronoChat.app"
-#         qt.mac_plist = app_plist % "ChronoChat"
-#         qt.mac_resources = 'demo.icns'
-#     else:
-#         bld (features = "subst",
-#              source = 'linux/chronochat.desktop.in',
-#              target = 'linux/chronochat.desktop',
-#              BINARY = "ChronoChat",
-#              install_path = "${DATAROOTDIR}/applications"
-#             )
-#         bld.install_files("${DATAROOTDIR}/chronochat",
-#                           bld.path.ant_glob(['linux/Resources/*']))
+        qt.mac_app = "ChronoChat.app"
+        qt.mac_plist = app_plist % "ChronoChat"
+        qt.mac_resources = 'demo.icns'
+    else:
+        bld (features = "subst",
+             source = 'linux/chronochat.desktop.in',
+             target = 'linux/chronochat.desktop',
+             BINARY = "ChronoChat",
+             install_path = "${DATAROOTDIR}/applications"
+            )
+        bld.install_files("${DATAROOTDIR}/chronochat",
+                          bld.path.ant_glob(['linux/Resources/*']))
 
 
-from waflib import TaskGen
-@TaskGen.extension('.mm')
-def m_hook(self, node):
-    """Alias .mm files to be compiled the same as .cc files, gcc/clang will do the right thing."""
-    return self.create_compiled_task('cxx', node)
-
 @Configure.conf
 def add_supported_cxxflags(self, cxxflags):
     """