Data Packet Verification Added
diff --git a/src/security/nlsr_cert_store.cpp b/src/security/nlsr_cert_store.cpp
new file mode 100644
index 0000000..108d0c6
--- /dev/null
+++ b/src/security/nlsr_cert_store.cpp
@@ -0,0 +1,139 @@
+#include "nlsr_cert_store.hpp"
+
+namespace nlsr
+{
+ static bool
+ nlsrCertificateStoreEntryCompare(NlsrCertificateStoreEntry& ncse1,
+ NlsrCertificateStoreEntry& ncse2)
+
+ {
+ return ncse1.getCert()->getName().toUri() ==
+ ncse2.getCert()->getName().toUri() ;
+ }
+
+ static bool
+ nlsrCertificateStoreEntryCompareByName(NlsrCertificateStoreEntry& ncse1,
+ std::string compCertName)
+
+ {
+ return ncse1.getCert()->getName().toUri() == compCertName ;
+ }
+
+ bool
+ NlsrCertificateStore::addCertificate(NlsrCertificateStoreEntry & ncse)
+ {
+ std::list<NlsrCertificateStoreEntry>::iterator it =
+ std::find_if( certTable.begin(), certTable.end(),
+ bind(&nlsrCertificateStoreEntryCompare, _1, ncse));
+ if(it == certTable.end())
+ {
+ certTable.push_back(ncse);
+ return true;
+ }
+
+ if( it != certTable.end() )
+ {
+ if ( (*it).getCertSeqNum() < ncse.getCertSeqNum() )
+ {
+ certTable.erase(it);
+ certTable.push_back(ncse);
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ bool
+ NlsrCertificateStore::addCertificate(
+ ndn::shared_ptr<ndn::IdentityCertificate> pcert, uint32_t csn, bool isv)
+ {
+ NlsrCertificateStoreEntry ncse(pcert, csn, isv);
+ return addCertificate(ncse);
+ }
+
+ std::pair<ndn::shared_ptr<ndn::IdentityCertificate>, bool>
+ NlsrCertificateStore::getCertificateFromStore(const std::string certName)
+ {
+ std::list<NlsrCertificateStoreEntry>::iterator it =
+ std::find_if( certTable.begin(), certTable.end(),
+ bind(&nlsrCertificateStoreEntryCompareByName, _1, certName));
+ if(it == certTable.end())
+ {
+ ndn::shared_ptr<ndn::IdentityCertificate> cert=
+ ndn::make_shared<ndn::IdentityCertificate>();
+
+ return std::make_pair(cert,false);
+ }
+
+ return std::make_pair((*it).getCert(),true);
+ }
+
+ std::pair<ndn::shared_ptr<ndn::IdentityCertificate>, bool>
+ NlsrCertificateStore::getCertificateFromStore(
+ const std::string certName, int checkSeqNum)
+ {
+ std::list<NlsrCertificateStoreEntry>::iterator it =
+ std::find_if( certTable.begin(), certTable.end(),
+ bind(&nlsrCertificateStoreEntryCompareByName, _1, certName));
+ if(it == certTable.end())
+ {
+ ndn::shared_ptr<ndn::IdentityCertificate> cert=
+ ndn::make_shared<ndn::IdentityCertificate>();
+
+ return std::make_pair(cert,false);
+ }
+ else
+ {
+ if( (*it).getCertSeqNum() == checkSeqNum )
+ {
+ return std::make_pair((*it).getCert(),true);
+ }
+ }
+
+ return std::make_pair((*it).getCert(),false);
+
+ }
+
+ bool
+ NlsrCertificateStore::isCertificateNewInStore(const std::string certName,
+ int checkSeqNo)
+ {
+ std::list<NlsrCertificateStoreEntry>::iterator it =
+ std::find_if( certTable.begin(), certTable.end(),
+ bind(&nlsrCertificateStoreEntryCompareByName, _1, certName));
+ if(it != certTable.end())
+ {
+ return (*it).getCertSeqNum() < checkSeqNo ;
+ }
+
+ return true;
+
+ }
+
+ bool
+ NlsrCertificateStore::removeCertificateFromStroe(const std::string certName)
+ {
+ std::list<NlsrCertificateStoreEntry>::iterator it =
+ std::find_if( certTable.begin(), certTable.end(),
+ bind(&nlsrCertificateStoreEntryCompareByName, _1, certName));
+ if(it != certTable.end())
+ {
+ certTable.erase(it);
+ return true;
+ }
+
+ return false;
+ }
+
+ void
+ NlsrCertificateStore::printCertStore()
+ {
+ std::list<NlsrCertificateStoreEntry>::iterator it;
+ for(it=certTable.begin(); it!=certTable.end(); ++it)
+ {
+ std::cout<<(*it)<<std::endl;
+ }
+
+ }
+}
diff --git a/src/security/nlsr_cse.cpp b/src/security/nlsr_cse.cpp
new file mode 100644
index 0000000..f52fdc9
--- /dev/null
+++ b/src/security/nlsr_cse.cpp
@@ -0,0 +1,18 @@
+#include <ndn-cpp-dev/security/signature-sha256-with-rsa.hpp>
+#include "nlsr_cse.hpp"
+
+namespace nlsr
+{
+ std::ostream&
+ operator <<(std::ostream& os, const NlsrCertificateStoreEntry& ncse)
+ {
+ os<<"------Certificate Entry---------------"<<std::endl;
+ os<<*(ncse.getCert())<<std::endl;
+ ndn::SignatureSha256WithRsa sig(ncse.getCert()->getSignature());
+ ndn::Name keyName=sig.getKeyLocator().getName();
+ os<<"Signee : "<<keyName.toUri()<<std::endl;
+ os<<"Cert Seq Num: "<<ncse.getCertSeqNum()<<std::endl;
+ os<<"Is Signer Verified: "<<ncse.getIsSignerVerified()<<std::endl;
+ return os;
+ }
+}
diff --git a/src/security/nlsr_cse.hpp b/src/security/nlsr_cse.hpp
new file mode 100644
index 0000000..27b992a
--- /dev/null
+++ b/src/security/nlsr_cse.hpp
@@ -0,0 +1,66 @@
+#ifndef NLSR_CERT_STORE_ENTRY_HPP
+#define NLSR_CERT_STORE_ENTRY_HPP
+
+#include <iostream>
+#include <ndn-cpp-dev/face.hpp>
+#include <ndn-cpp-dev/security/identity-certificate.hpp>
+
+namespace nlsr
+{
+ class NlsrCertificateStoreEntry
+ {
+ public:
+ NlsrCertificateStoreEntry()
+ : cert(ndn::make_shared<ndn::IdentityCertificate>())
+ , certSeqNum(0)
+ , isSignerVerified(false)
+ {}
+
+ NlsrCertificateStoreEntry(ndn::shared_ptr<ndn::IdentityCertificate> pcert
+ , uint32_t csn, bool isv)
+ : cert(pcert)
+ , certSeqNum(csn)
+ , isSignerVerified(isv)
+ {}
+
+ ndn::shared_ptr<ndn::IdentityCertificate> getCert() const
+ {
+ return cert;
+ }
+
+ void setCert(ndn::shared_ptr<ndn::IdentityCertificate> pcert)
+ {
+ cert=pcert;
+ }
+
+ uint32_t getCertSeqNum() const
+ {
+ return certSeqNum;
+ }
+
+ void setCertSeqNum(uint32_t csn)
+ {
+ certSeqNum=csn;
+ }
+
+ bool getIsSignerVerified() const
+ {
+ return isSignerVerified;
+ }
+
+ void setIsSignerVerified(bool isv)
+ {
+ isSignerVerified=isv;
+ }
+
+ private:
+ ndn::shared_ptr<ndn::IdentityCertificate> cert;
+ uint32_t certSeqNum;
+ bool isSignerVerified;
+ };
+ /* Debugging Purpose */
+ std::ostream&
+ operator <<(std::ostream& os, const NlsrCertificateStoreEntry& ncse);
+}
+
+#endif