security: Fix compile problem caused by changes in Validator constructor
Change-Id: Ia0132ef46e1894c4468d922f6dd4a802d23c9d7f
Refs: #1481
diff --git a/src/sync-socket.cc b/src/sync-socket.cc
index f5e378f..b18f64c 100644
--- a/src/sync-socket.cc
+++ b/src/sync-socket.cc
@@ -37,11 +37,11 @@
const Name& dataPrefix,
uint64_t dataSession,
bool withRoutingPrefix,
- const Name& routingPrefix,
+ const Name& routingPrefix,
shared_ptr<Face> face,
const IdentityCertificate& myCertificate,
shared_ptr<SecRuleRelative> dataRule,
- NewDataCallback dataCallback,
+ NewDataCallback dataCallback,
RemoveCallback rmCallback )
: m_dataPrefix(dataPrefix)
, m_dataSession(dataSession)
@@ -61,9 +61,9 @@
if(static_cast<bool>(dataRule))
{
m_withSecurity = true;
- m_syncValidator = shared_ptr<Validator>(new SyncValidator(syncPrefix,
- m_myCertificate,
- m_face,
+ m_syncValidator = shared_ptr<Validator>(new SyncValidator(syncPrefix,
+ m_myCertificate,
+ *m_face,
bind(&SyncSocket::publishData, this, _1, _2, _3, true),
dataRule));
}
@@ -73,7 +73,7 @@
m_syncValidator = shared_ptr<Validator>(new ValidatorNull());
}
-
+
m_syncLogic = shared_ptr<SyncLogic>(new SyncLogic(syncPrefix,
myCertificate,
m_syncValidator,
@@ -93,7 +93,7 @@
data->setContent(reinterpret_cast<const uint8_t*>(buf), len);
data->setFreshnessPeriod(time::milliseconds(1000*freshness));
- m_ioService->post(bind(&SyncSocket::publishDataInternal, this,
+ m_ioService->post(bind(&SyncSocket::publishDataInternal, this,
data, isCert));
}
@@ -136,7 +136,7 @@
m_syncLogic->addLocalNames (dataPrefix, m_dataSession, sequence); // If DNS works, we should use pure m_dataprefix rather than the one with routing prefix.
}
-void
+void
SyncSocket::fetchData(const Name& prefix, const SeqNo& seq, const OnDataValidated& dataCallback, int retry)
{
Name interestName = prefix;
@@ -145,8 +145,8 @@
ndn::Interest interest(interestName);
interest.setMustBeFresh(true);
- m_face->expressInterest(interest,
- bind(&SyncSocket::onData, this, _1, _2, dataCallback),
+ m_face->expressInterest(interest,
+ bind(&SyncSocket::onData, this, _1, _2, dataCallback),
bind(&SyncSocket::onDataTimeout, this, _1, retry, dataCallback));
}
@@ -198,12 +198,12 @@
_1,
_2,
dataCallback),
- bind(&SyncSocket::onDataTimeout,
+ bind(&SyncSocket::onDataTimeout,
this,
_1,
retry - 1,
dataCallback));
-
+
}
else
_LOG_DEBUG("interest eventually time out!");
@@ -214,10 +214,10 @@
size_t interestNameSize,
const OnDataValidated& onValidated)
{
- if(data->getName().size() > interestNameSize
+ if(data->getName().size() > interestNameSize
&& data->getName().get(interestNameSize).toEscapedString() == "INTRO-CERT")
{
- if(!m_withSecurity)
+ if(!m_withSecurity)
return;
Data rawData;
diff --git a/src/sync-validator.cc b/src/sync-validator.cc
index f2c05bb..69e9232 100644
--- a/src/sync-validator.cc
+++ b/src/sync-validator.cc
@@ -26,10 +26,10 @@
SyncValidator::SyncValidator(const Name& prefix,
const IdentityCertificate& anchor,
- shared_ptr<Face> face,
+ Face& face,
const PublishCertCallback& publishCertCallback,
shared_ptr<SecRuleRelative> rule,
- shared_ptr<CertificateCache> certificateCache,
+ shared_ptr<CertificateCache> certificateCache,
const int stepLimit)
: Validator(face)
, m_prefix(prefix)
@@ -39,16 +39,13 @@
, m_publishCertCallback(publishCertCallback)
, m_dataRule(rule)
{
- if(!static_cast<bool>(face))
- throw Error("Face is not set!");
-
if(!static_cast<bool>(m_certificateCache))
- m_certificateCache = make_shared<CertificateCacheTtl>(m_face->ioService());
+ m_certificateCache = make_shared<CertificateCacheTtl>(m_face.ioService());
Name certPrefix = prefix;
certPrefix.append("CHRONOS-INTRO-CERT");
- m_prefixId = m_face->setInterestFilter(certPrefix,
- bind(&SyncValidator::onCertInterest, this, _1, _2),
+ m_prefixId = m_face.setInterestFilter(certPrefix,
+ bind(&SyncValidator::onCertInterest, this, _1, _2),
bind(&SyncValidator::onCertRegisterFailed, this, _1, _2));
setAnchor(m_anchor);
@@ -83,7 +80,7 @@
{
// Check the nodes introduced by the trusted node.
Edges::const_iterator edgeIt = m_introCerts.find(*eeIt);
- if(edgeIt != m_introCerts.end()
+ if(edgeIt != m_introCerts.end()
&& m_trustedNodes.find(edgeIt->second.getIntroduceeCertName()) == m_trustedNodes.end()
&& verifySignature(edgeIt->second, publicKey))
{
@@ -98,14 +95,14 @@
}
void
-SyncValidator::checkPolicy (const Data& data,
- int stepCount,
- const OnDataValidated& onValidated,
+SyncValidator::checkPolicy (const Data& data,
+ int stepCount,
+ const OnDataValidated& onValidated,
const OnDataValidationFailed& onValidationFailed,
std::vector<shared_ptr<ValidationRequest> >& nextSteps)
{
if(m_stepLimit == stepCount)
- return onValidationFailed(data.shared_from_this(),
+ return onValidationFailed(data.shared_from_this(),
"Maximum steps of validation reached: " + data.getName().toUri());
if(m_prefix.isPrefixOf(data.getName()) || (static_cast<bool>(m_dataRule) && m_dataRule->satisfy(data)))
@@ -121,25 +118,25 @@
if(verifySignature(data, sig, it->second))
return onValidated(data.shared_from_this());
else
- return onValidationFailed(data.shared_from_this(),
+ return onValidationFailed(data.shared_from_this(),
"Cannot verify signature: " + data.getName().toUri());
}
else
{
- _LOG_DEBUG("I am: " << m_anchor.getName().get(0).toEscapedString() << " for " << data.getName());
+ _LOG_DEBUG("I am: " << m_anchor.getName().get(0).toEscapedString() << " for " << data.getName());
Name interestName = m_prefix;
interestName.append("CHRONOS-INTRO-CERT").append(keyLocatorName.wireEncode());
Interest interest(interestName);
interest.setInterestLifetime(time::milliseconds(500));
- OnDataValidated onKeyValidated = bind(&SyncValidator::onCertificateValidated, this,
+ OnDataValidated onKeyValidated = bind(&SyncValidator::onCertificateValidated, this,
_1, data.shared_from_this(), onValidated, onValidationFailed);
-
- OnDataValidationFailed onKeyValidationFailed = bind(&SyncValidator::onCertificateValidationFailed, this,
- _1, _2, data.shared_from_this(), onValidationFailed);
- shared_ptr<ValidationRequest> nextStep = make_shared<ValidationRequest>(interest,
+ OnDataValidationFailed onKeyValidationFailed = bind(&SyncValidator::onCertificateValidationFailed, this,
+ _1, _2, data.shared_from_this(), onValidationFailed);
+
+ shared_ptr<ValidationRequest> nextStep = make_shared<ValidationRequest>(interest,
onKeyValidated,
onKeyValidationFailed,
1,
@@ -151,7 +148,7 @@
}
catch(SignatureSha256WithRsa::Error& e)
{
- return onValidationFailed(data.shared_from_this(),
+ return onValidationFailed(data.shared_from_this(),
"Not SignatureSha256WithRsa signature: " + std::string(e.what()));
}
catch(KeyLocator::Error& e)
@@ -166,9 +163,9 @@
}
void
-SyncValidator::checkPolicy (const Interest& interest,
- int stepCount,
- const OnInterestValidated& onValidated,
+SyncValidator::checkPolicy (const Interest& interest,
+ int stepCount,
+ const OnInterestValidated& onValidated,
const OnInterestValidationFailed& onValidationFailed,
std::vector<shared_ptr<ValidationRequest> >& nextSteps)
{
@@ -176,33 +173,33 @@
}
void
-SyncValidator::onCertificateValidated(const shared_ptr<const Data>& signCertificate,
- const shared_ptr<const Data>& data,
- const OnDataValidated& onValidated,
+SyncValidator::onCertificateValidated(const shared_ptr<const Data>& signCertificate,
+ const shared_ptr<const Data>& data,
+ const OnDataValidated& onValidated,
const OnDataValidationFailed& onValidationFailed)
{
try
{
IntroCertificate introCert(*signCertificate);
addParticipant(introCert);
-
+
if(verifySignature(*data, introCert.getIntroduceeCert().getPublicKeyInfo()))
return onValidated(data);
else
- return onValidationFailed(data,
+ return onValidationFailed(data,
"Cannot verify signature: " + data->getName().toUri());
}
catch(IntroCertificate::Error& e)
{
- return onValidationFailed(data,
+ return onValidationFailed(data,
"Intro cert decoding error: " + std::string(e.what()));
}
}
void
-SyncValidator::onCertificateValidationFailed(const shared_ptr<const Data>& signCertificate,
+SyncValidator::onCertificateValidationFailed(const shared_ptr<const Data>& signCertificate,
const std::string& failureInfo,
- const shared_ptr<const Data>& data,
+ const shared_ptr<const Data>& data,
const OnDataValidationFailed& onValidationFailed)
{
onValidationFailed(data, failureInfo);
@@ -211,13 +208,13 @@
void
SyncValidator::onCertInterest(const Name& prefix, const Interest& interest)
{
- Name name = interest.getName();
+ Name name = interest.getName();
Edges::const_iterator it = m_introCerts.begin();
for(; it != m_introCerts.end(); it++)
{
if(name.isPrefixOf(it->first))
{
- m_face->put(it->second);
+ m_face.put(it->second);
return;
}
}
diff --git a/src/sync-validator.h b/src/sync-validator.h
index 00c92c8..65f14a3 100644
--- a/src/sync-validator.h
+++ b/src/sync-validator.h
@@ -32,16 +32,16 @@
SyncValidator(const ndn::Name& prefix,
const ndn::IdentityCertificate& anchor,
- ndn::shared_ptr<ndn::Face> face,
+ ndn::Face& face,
const PublishCertCallback& publishCertCallback,
ndn::shared_ptr<ndn::SecRuleRelative> rule = DefaultDataRule,
- ndn::shared_ptr<ndn::CertificateCache> certificateCache = DefaultCertificateCache,
+ ndn::shared_ptr<ndn::CertificateCache> certificateCache = DefaultCertificateCache,
const int stepLimit = 10);
virtual
~SyncValidator()
{
- m_face->unsetInterestFilter(m_prefixId);
+ m_face.unsetInterestFilter(m_prefixId);
}
/**
@@ -50,7 +50,7 @@
* The anchor should be the participant's own certificate.
* This anchor node is the origin of the derived trust graph.
* Once the new anchor is set, derive the TrustNode set.
- *
+ *
* @param anchor.
*/
inline void
@@ -58,7 +58,7 @@
/**
* @brief Add a node into the trust graph.
- *
+ *
* The method also create an edge from trust anchor to the node.
*
* @param introducee.
@@ -90,39 +90,39 @@
return (m_trustedNodes.find(certName.getPrefix(-1)) != m_trustedNodes.end());
}
#endif //_DEBUG
-
+
protected:
/***********************
* From ndn::Validator *
***********************/
virtual void
- checkPolicy (const ndn::Data& data,
- int stepCount,
- const ndn::OnDataValidated& onValidated,
+ checkPolicy (const ndn::Data& data,
+ int stepCount,
+ const ndn::OnDataValidated& onValidated,
const ndn::OnDataValidationFailed& onValidationFailed,
std::vector<ndn::shared_ptr<ndn::ValidationRequest> >& nextSteps);
virtual void
- checkPolicy (const ndn::Interest& interest,
- int stepCount,
- const ndn::OnInterestValidated& onValidated,
+ checkPolicy (const ndn::Interest& interest,
+ int stepCount,
+ const ndn::OnInterestValidated& onValidated,
const ndn::OnInterestValidationFailed& onValidationFailed,
std::vector<ndn::shared_ptr<ndn::ValidationRequest> >& nextSteps);
private:
void
deriveTrustNodes();
-
+
void
- onCertificateValidated(const ndn::shared_ptr<const ndn::Data>& signCertificate,
- const ndn::shared_ptr<const ndn::Data>& data,
- const ndn::OnDataValidated& onValidated,
+ onCertificateValidated(const ndn::shared_ptr<const ndn::Data>& signCertificate,
+ const ndn::shared_ptr<const ndn::Data>& data,
+ const ndn::OnDataValidated& onValidated,
const ndn::OnDataValidationFailed& onValidationFailed);
-
+
void
onCertificateValidationFailed(const ndn::shared_ptr<const ndn::Data>& signCertificate,
const std::string& failureInfo,
- const ndn::shared_ptr<const ndn::Data>& data,
+ const ndn::shared_ptr<const ndn::Data>& data,
const ndn::OnDataValidationFailed& onValidationFailed);
void
@@ -136,7 +136,7 @@
// Syncprefix
ndn::Name m_prefix;
-
+
// The map
typedef std::map<const ndn::Name, IntroNode> Nodes;
typedef std::map<const ndn::Name, IntroCertificate> Edges;
@@ -147,7 +147,7 @@
typedef std::map<const ndn::Name, ndn::PublicKey> TrustNodes;
ndn::IdentityCertificate m_anchor;
TrustNodes m_trustedNodes;
-
+
// others
int m_stepLimit;
ndn::shared_ptr<ndn::CertificateCache> m_certificateCache;
@@ -167,7 +167,7 @@
IntroNode(const ndn::IdentityCertificate& idCert)
: m_nodeName(idCert.getName().getPrefix(-1))
{}
-
+
IntroNode(const IntroCertificate& introCert, bool isIntroducer)
{
if(isIntroducer)
@@ -180,8 +180,8 @@
m_nodeName = introCert.getIntroduceeCertName();
m_introducerCerts.push_back(introCert.getName());
}
- }
-
+ }
+
~IntroNode()
{}
@@ -221,14 +221,14 @@
if(std::find(m_introduceeCerts.begin(), m_introduceeCerts.end(), introCertName) == m_introduceeCerts.end())
m_introduceeCerts.push_back(introCertName);
}
-
+
void
addIntroCertAsIntroducee(const ndn::Name& introCertName)
{
if(std::find(m_introducerCerts.begin(), m_introducerCerts.end(), introCertName) == m_introducerCerts.end())
m_introducerCerts.push_back(introCertName);
}
-
+
private:
ndn::Name m_nodeName;
std::vector<ndn::Name> m_introducerCerts;
@@ -241,7 +241,7 @@
SyncValidator::setAnchor(const ndn::IdentityCertificate& anchor)
{
m_anchor = anchor;
-
+
// Add anchor into trust graph if it does not exist.
IntroNode origin(m_anchor);
Nodes::const_iterator nodeIt = m_introNodes.find(origin.name());
@@ -296,7 +296,7 @@
= ndn::shared_ptr<IntroCertificate>(new IntroCertificate(m_prefix, introducee, m_anchor.getName().getPrefix(-1)));
m_keychain.sign(*introCert, m_anchor.getName());
-
+
addParticipant(*introCert);
// Publish certificate as normal data.
diff --git a/tests/test-sync-validator.cc b/tests/test-sync-validator.cc
index 6f77f86..ec50717 100644
--- a/tests/test-sync-validator.cc
+++ b/tests/test-sync-validator.cc
@@ -8,33 +8,33 @@
BOOST_AUTO_TEST_SUITE(TestSyncValidator)
-void
+void
onValidated(const ndn::shared_ptr<const ndn::Data>& data)
{
BOOST_CHECK(true);
}
-void
+void
onValidationFailed(const ndn::shared_ptr<const ndn::Data>& data,
const std::string& failureInfo)
{
BOOST_CHECK(false);
}
-void
+void
onValidated2(const ndn::shared_ptr<const ndn::Data>& data)
{
BOOST_CHECK(false);
}
-void
+void
onValidationFailed2(const ndn::shared_ptr<const ndn::Data>& data,
const std::string& failureInfo)
{
BOOST_CHECK(true);
}
-void
+void
publishData(const uint8_t* buf, size_t len, int freshness)
{
}
@@ -70,13 +70,13 @@
shared_ptr<boost::asio::io_service> ioService = make_shared<boost::asio::io_service>();
shared_ptr<Face> face = make_shared<Face>(ioService);
shared_ptr<SecRuleRelative> rule;
- SyncValidator validator(prefix, *anchor, face,
+ SyncValidator validator(prefix, *anchor, *face,
bind(&publishData, _1, _2, _3),
rule);
validator.addParticipant(*introducer);
BOOST_CHECK(validator.canTrust(certName2));
-
+
IntroCertificate introCert(prefix, *introducee, certName2.getPrefix(-1));
keychain.sign(introCert, certName2);
validator.addParticipant(introCert);
@@ -108,7 +108,7 @@
BOOST_CHECK(validator.canTrust(certName3));
BOOST_CHECK(validator.canTrust(certName4) == false);
BOOST_CHECK(validator.canTrust(certName5));
-
+
keychain.deleteIdentity(identity1);
keychain.deleteIdentity(identity2);
@@ -153,13 +153,13 @@
shared_ptr<boost::asio::io_service> ioService = make_shared<boost::asio::io_service>();
shared_ptr<Face> face = make_shared<Face>(ioService);
shared_ptr<SecRuleRelative> rule;
- SyncValidator validator(prefix, *anchor, face,
+ SyncValidator validator(prefix, *anchor, *face,
bind(&publishData, _1, _2, _3),
rule);
validator.addParticipant(*introducer);
BOOST_CHECK(validator.canTrust(certName2));
-
+
IntroCertificate introCert(prefix, *introducee, certName2.getPrefix(-1));
keychain.sign(introCert, certName2);
validator.addParticipant(introCert);
@@ -211,7 +211,7 @@
: regPrefixId(0)
, regPrefixId2(0)
{}
-
+
void
onInterest(ndn::shared_ptr<ndn::Face> face, ndn::shared_ptr<ndn::Data> data)
{
@@ -231,7 +231,7 @@
{}
void
- validate(ndn::shared_ptr<Sync::SyncValidator> validator, ndn::shared_ptr<ndn::Data> data,
+ validate(ndn::shared_ptr<Sync::SyncValidator> validator, ndn::shared_ptr<ndn::Data> data,
const ndn::Name& certName3, const ndn::Name& certName4)
{
validator->validate(*data,
@@ -261,17 +261,17 @@
Name prefix("/Sync/TestSyncValidator/OnlineValidate");
KeyChain keychain;
- Name identity1("/TestSyncValidator/OnlineValidate-1/"
+ Name identity1("/TestSyncValidator/OnlineValidate-1/"
+ boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
Name certName1 = keychain.createIdentity(identity1);
shared_ptr<IdentityCertificate> anchor = keychain.getCertificate(certName1);
- Name identity2("/TestSyncValidator/OnlineValidate-2/"
+ Name identity2("/TestSyncValidator/OnlineValidate-2/"
+ boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
Name certName2 = keychain.createIdentity(identity2);
shared_ptr<IdentityCertificate> introducer = keychain.getCertificate(certName2);
- Name identity3("/TestSyncValidator/OnlineValidate-3/"
+ Name identity3("/TestSyncValidator/OnlineValidate-3/"
+ boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
Name certName3 = keychain.createIdentity(identity3);
shared_ptr<IdentityCertificate> introducee = keychain.getCertificate(certName3);
@@ -287,11 +287,11 @@
shared_ptr<SecRuleRelative> rule;
shared_ptr<SyncValidator> validator = shared_ptr<SyncValidator>
- (new SyncValidator(prefix, *anchor, face2, bind(&publishData, _1, _2, _3), rule));
+ (new SyncValidator(prefix, *anchor, *face2, bind(&publishData, _1, _2, _3), rule));
validator->addParticipant(*introducer);
BOOST_CHECK(validator->canTrust(certName2));
-
+
shared_ptr<IntroCertificate> introCert = shared_ptr<IntroCertificate>(new IntroCertificate(prefix, *introducee, certName2.getPrefix(-1)));
keychain.sign(*introCert, certName2);
BOOST_CHECK(validator->canTrust(certName3) == false);
@@ -313,7 +313,7 @@
regPrefixId = face->setInterestFilter(introCert->getName().getPrefix(-1),
bind(&FacesFixture::onInterest, this, face, introCert),
bind(&FacesFixture::onRegFailed, this));
-
+
regPrefixId2 = face->setInterestFilter(introCert2->getName().getPrefix(-1),
bind(&FacesFixture::onInterest2, this, face, introCert2),
bind(&FacesFixture::onRegFailed, this));