security: Add security switch in SyncSocket

Change-Id: I65b8fb17ff1794cfdb0ffc6e724b743e6b1945bb
This commit is contained in:
Yingdi Yu committed 2014-02-28 14:54:16 -08:00
1 parent 3da10fe5a7
commit aed0f3e954
4 files changed
+91 -28

No files matched your search

+30 -15
View File
@@ -33,9 +33,9 @@ using ndn::shared_ptr;
SyncSocket::SyncSocket (const Name& syncPrefix,
const ndn::Name& dataPrefix,
uint64_t dataSession,
shared_ptr<Face> face,
const IdentityCertificate& myCertificate,
shared_ptr<SecRuleRelative> dataRule,
shared_ptr<Face> face,
NewDataCallback dataCallback,
RemoveCallback rmCallback )
: m_dataPrefix(dataPrefix)
@@ -44,18 +44,30 @@ SyncSocket::SyncSocket (const Name& syncPrefix,
, m_myCertificate(myCertificate)
, m_face(face)
, m_ioService(face->ioService())
, m_syncValidator(new SyncValidator(syncPrefix,
m_myCertificate,
m_face,
bind(&SyncSocket::publishData, this, _1, _2, _3, true),
dataRule))
, m_syncLogic (syncPrefix,
myCertificate,
m_syncValidator,
face,
bind(&SyncSocket::passCallback, this, _1),
rmCallback)
{}
{
if(static_cast<bool>(dataRule))
{
m_withSecurity = true;
m_syncValidator = shared_ptr<Validator>(new SyncValidator(syncPrefix,
m_myCertificate,
m_face,
bind(&SyncSocket::publishData, this, _1, _2, _3, true),
dataRule));
}
else
{
m_withSecurity = false;
m_syncValidator = shared_ptr<Validator>(new ValidatorNull());
}
m_syncLogic = shared_ptr<SyncLogic>(new SyncLogic(syncPrefix,
myCertificate,
m_syncValidator,
m_face,
bind(&SyncSocket::passCallback, this, _1),
rmCallback));
}
SyncSocket::~SyncSocket()
{
@@ -88,7 +100,7 @@ SyncSocket::publishDataInternal(shared_ptr<Data> data, const Name &prefix, uint6
SeqNo s(session, sequence + 1);
m_sequenceLog[prefix] = s;
m_syncLogic.addLocalNames (prefix, session, sequence);
m_syncLogic->addLocalNames (prefix, session, sequence);
}
void
@@ -153,10 +165,13 @@ SyncSocket::onDataValidated(const shared_ptr<const Data>& data,
if(data->getName().size() > interestNameSize
&& data->getName().get(interestNameSize).toEscapedString() == "INTRO-CERT")
{
if(!m_withSecurity)
return;
Data rawData;
rawData.wireDecode(data->getContent().blockFromValue());
IntroCertificate introCert(rawData);
m_syncValidator->addParticipant(introCert);
dynamic_pointer_cast<SyncValidator>(m_syncValidator)->addParticipant(introCert);
}
else
{
+42 -7
View File
@@ -23,6 +23,7 @@
#include <ndn-cpp-dev/face.hpp>
#include <ndn-cpp-dev/security/validator.hpp>
#include <ndn-cpp-dev/security/validator-null.hpp>
#include <ndn-cpp-dev/security/key-chain.hpp>
#include "sync-logic.h"
@@ -43,15 +44,17 @@ namespace Sync {
class SyncSocket
{
public:
struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
typedef ndn::function< void (const std::vector<MissingDataInfo> &, SyncSocket * ) > NewDataCallback;
typedef ndn::function< void (const std::string &/*prefix*/ ) > RemoveCallback;
SyncSocket (const ndn::Name& syncPrefix,
const ndn::Name& dataPrefix,
uint64_t dataSession,
ndn::shared_ptr<ndn::Face> face,
const ndn::IdentityCertificate& myCertificate,
ndn::shared_ptr<ndn::SecRuleRelative> dataRule,
ndn::shared_ptr<ndn::Face> face,
NewDataCallback dataCallback,
RemoveCallback rmCallback);
@@ -63,7 +66,7 @@ public:
void
remove (const ndn::Name &prefix)
{
m_syncLogic.remove(prefix);
m_syncLogic->remove(prefix);
}
void
@@ -72,7 +75,7 @@ public:
std::string
getRootDigest()
{
return m_syncLogic.getRootDigest();
return m_syncLogic->getRootDigest();
}
uint64_t
@@ -92,13 +95,44 @@ public:
SyncLogic &
getLogic ()
{
return m_syncLogic;
return *m_syncLogic;
}
void
addParticipant(const ndn::IdentityCertificate& introducee)
{
ndn::shared_ptr<const IntroCertificate> introCert = m_syncValidator->addParticipant(introducee);
if(m_withSecurity)
{
ndn::dynamic_pointer_cast<SyncValidator>(m_syncValidator)->addParticipant(introducee);
}
}
void
addParticipant(const IntroCertificate& introCert)
{
if(m_withSecurity)
{
ndn::dynamic_pointer_cast<SyncValidator>(m_syncValidator)->addParticipant(introCert);
}
}
void
getIntroCertNames(std::vector<ndn::Name>& list)
{
if(m_withSecurity)
{
ndn::dynamic_pointer_cast<SyncValidator>(m_syncValidator)->getIntroCertNames(list);
}
}
const IntroCertificate&
getIntroCertificate(const ndn::Name& name)
{
if(m_withSecurity)
{
return ndn::dynamic_pointer_cast<SyncValidator>(m_syncValidator)->getIntroCertificate(name);
}
throw Error("You are running SyncSocket without security!");
}
// // make this a static function so we don't have to create socket instance without
@@ -150,8 +184,9 @@ private:
ndn::KeyChain m_keyChain;
ndn::shared_ptr<ndn::Face> m_face;
ndn::shared_ptr<boost::asio::io_service> m_ioService;
ndn::shared_ptr<SyncValidator> m_syncValidator;
SyncLogic m_syncLogic;
bool m_withSecurity;
ndn::shared_ptr<ndn::Validator> m_syncValidator;
ndn::shared_ptr<SyncLogic> m_syncLogic;
};
} // Sync
+13
View File
@@ -80,6 +80,9 @@ public:
inline void
getIntroCertNames(std::vector<ndn::Name>& list);
inline const IntroCertificate&
getIntroCertificate(const ndn::Name& name);
#ifdef _TEST
bool
canTrust(const ndn::Name& certName)
@@ -312,6 +315,16 @@ SyncValidator::getIntroCertNames(std::vector<ndn::Name>& list)
list.push_back(it->first);
}
inline const IntroCertificate&
SyncValidator::getIntroCertificate(const ndn::Name& name)
{
Edges::const_iterator it = m_introCerts.find(name);
if(it != m_introCerts.end())
return it->second;
else
throw Error("No cert");
}
} // namespace Sync
#endif //SYNC_VALIDATOR_H
+6 -6
View File
@@ -163,9 +163,9 @@ public:
m_s1 = ndn::make_shared<SyncSocket>("/let/us/sync",
"/irl.cs.ucla.edu",
0,
m_face1,
*m_id1,
m_rule,
m_face1,
bind(&TestSocketApp::fetchAll, &m_a1, _1, _2),
bind(&TestSocketApp::pass, &m_a1, _1));
m_s1->addParticipant(*m_id2);
@@ -179,9 +179,9 @@ public:
m_s2 = ndn::make_shared<SyncSocket>("/let/us/sync",
"/yakshi.org",
0,
m_face2,
*m_id2,
m_rule,
m_face2,
bind(&TestSocketApp::fetchAll, &m_a2, _1, _2),
bind(&TestSocketApp::pass, &m_a2, _1));
m_s2->addParticipant(*m_id1);
@@ -196,9 +196,9 @@ public:
m_s3 = ndn::make_shared<SyncSocket>("/let/us/sync",
"/google.com",
0,
m_face3,
*m_id3,
m_rule,
m_face3,
m_rule,
bind(&TestSocketApp::fetchAll, &m_a3, _1, _2),
bind(&TestSocketApp::pass, &m_a3, _1));
m_s3->addParticipant(*m_id2);
@@ -306,9 +306,9 @@ public:
m_s1 = ndn::make_shared<SyncSocket>("/this/is/the/prefix",
"/xiaonei.com",
0,
m_face1,
*m_id1,
m_rule,
m_face1,
bind(&TestSocketApp::fetchNumbers, &m_a1, _1, _2),
bind(&TestSocketApp::pass, &m_a1, _1));
@@ -323,9 +323,9 @@ public:
m_s2 = ndn::make_shared<SyncSocket>("/this/is/the/prefix",
"/mitbbs.com",
0,
m_face2,
*m_id2,
m_rule,
m_face2,
bind(&TestSocketApp::fetchNumbers, &m_a2, _1, _2),
bind(&TestSocketApp::pass, &m_a2, _1));