compile: Change includes and wscript to compile against ndn-cpp-dev
Change-Id: Ie51f5377690ccaf1fd3ffe90df68ce3f537b029d
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;
+}