security: Add signing and validating process
Change-Id: Ic9edfcf56f044821e167d7e49b75a9023b67fbcd
diff --git a/src/nlsr.hpp b/src/nlsr.hpp
index 8db25c2..b0d5126 100644
--- a/src/nlsr.hpp
+++ b/src/nlsr.hpp
@@ -28,6 +28,7 @@
#include <ndn-cxx/face.hpp>
#include <ndn-cxx/security/key-chain.hpp>
+#include <ndn-cxx/security/certificate-cache-ttl.hpp>
#include <ndn-cxx/util/scheduler.hpp>
#include "conf-parameter.hpp"
@@ -41,9 +42,13 @@
#include "communication/sync-logic-handler.hpp"
#include "hello-protocol.hpp"
+#include "validator.hpp"
+
namespace nlsr {
+static ndn::Name DEFAULT_BROADCAST_PREFIX("/ndn/broadcast");
+
class Nlsr
{
class Error : public std::runtime_error
@@ -75,6 +80,9 @@
, m_namePrefixTable(*this)
, m_syncLogicHandler(m_nlsrFace.getIoService())
, m_helloProtocol(*this)
+
+ , m_certificateCache(new ndn::CertificateCacheTtl(m_nlsrFace.getIoService()))
+ , m_validator(m_nlsrFace, DEFAULT_BROADCAST_PREFIX, m_certificateCache)
{}
void
@@ -255,11 +263,71 @@
void
initialize();
+ void
+ intializeKey();
+
+ void
+ loadValidator(boost::property_tree::ptree section,
+ const std::string& filename)
+ {
+ m_validator.load(section, filename);
+ }
+
+ Validator&
+ getValidator()
+ {
+ return m_validator;
+ }
+
+ void
+ loadCertToPublish(ndn::shared_ptr<ndn::IdentityCertificate> certificate)
+ {
+ if (static_cast<bool>(certificate))
+ m_certToPublish[certificate->getName().getPrefix(-1)] = certificate; // key is cert name
+ // without version
+ }
+
+ ndn::shared_ptr<const ndn::IdentityCertificate>
+ getCertificate(const ndn::Name& certificateNameWithoutVersion)
+ {
+ CertMap::iterator it = m_certToPublish.find(certificateNameWithoutVersion);
+
+ if (it != m_certToPublish.end())
+ {
+ return it->second;
+ }
+
+ return m_certificateCache->getCertificate(certificateNameWithoutVersion);
+ }
+
+ ndn::KeyChain&
+ getKeyChain()
+ {
+ return m_keyChain;
+ }
+
+ const ndn::Name&
+ getDefaultCertName()
+ {
+ return m_defaultCertName;
+ }
+
private:
void
registerPrefixes();
+ void
+ registerKeyPrefix();
+
+ void
+ onKeyInterest(const ndn::Name& name, const ndn::Interest& interest);
+
+ void
+ onKeyPrefixRegSuccess(const ndn::Name& name);
+
private:
+ typedef std::map<ndn::Name, ndn::shared_ptr<ndn::IdentityCertificate> > CertMap;
+
ndn::Face m_nlsrFace;
ndn::Scheduler m_scheduler;
ConfParameter m_confParam;
@@ -279,6 +347,13 @@
SyncLogicHandler m_syncLogicHandler;
int32_t m_apiPort;
HelloProtocol m_helloProtocol;
+
+ ndn::shared_ptr<ndn::CertificateCacheTtl> m_certificateCache;
+ CertMap m_certToPublish;
+ Validator m_validator;
+ ndn::KeyChain m_keyChain;
+ ndn::Name m_defaultIdentity;
+ ndn::Name m_defaultCertName;
};
} //namespace nlsr