blob: d0850b68f0c5a3b8342d26fb0d7097f0b7a08820 [file] [log] [blame]
Yingdi Yu43e71612013-10-30 22:19:31 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013, Regents of the University of California
4 * Yingdi Yu
5 *
6 * BSD license, See the LICENSE file for more information
7 *
8 * Author: Yingdi Yu <yingdi@cs.ucla.edu>
9 */
10
Yingdi Yu43e71612013-10-30 22:19:31 -070011#include "sync-intro-certificate.h"
12#include "sync-logging.h"
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080013#include <ndn-cpp/security/identity/basic-identity-storage.hpp>
14#include <ndn-cpp/security/identity/osx-private-key-storage.hpp>
15#include <ndn-cpp/sha256-with-rsa-signature.hpp>
16#include <ndn-cpp/security/signature/sha256-with-rsa-handler.hpp>
17
18#include "sync-policy-manager.h"
Yingdi Yu43e71612013-10-30 22:19:31 -070019
20using namespace ndn;
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080021using namespace ndn::ptr_lib;
Yingdi Yu43e71612013-10-30 22:19:31 -070022using namespace std;
23
24INIT_LOGGER("SyncPolicyManager");
25
26SyncPolicyManager::SyncPolicyManager(const Name& signingIdentity,
27 const Name& signingCertificateName,
28 const Name& syncPrefix,
29 int stepLimit)
30 : m_signingIdentity(signingIdentity)
31 , m_signingCertificateName(signingCertificateName.getPrefix(signingCertificateName.size()-1))
32 , m_syncPrefix(syncPrefix)
33 , m_stepLimit(stepLimit)
34{
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080035 m_transport = make_shared<TcpTransport>();
36 m_face = make_shared<Face>(m_transport, make_shared<TcpTransport::ConnectionInfo>("localhost"));
37
38 connectToDaemon();
39
40 shared_ptr<IdentityStorage> publicStorage = make_shared<BasicIdentityStorage>();
41 shared_ptr<PrivateKeyStorage> privateStorage = make_shared<OSXPrivateKeyStorage>();
42 m_identityManager = make_shared<IdentityManager>(publicStorage, privateStorage);
43
Yingdi Yu43e71612013-10-30 22:19:31 -070044 Name wotPrefix = syncPrefix;
45 wotPrefix.append("WOT");
46 m_syncPrefixRegex = Regex::fromName(syncPrefix);
47 m_wotPrefixRegex = Regex::fromName(wotPrefix);
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080048 m_chatDataPolicy = make_shared<IdentityPolicyRule>("^[^<%F0.>]*<%F0.>([^<chronos>]*)<chronos><>",
49 "^([^<KEY>]*)<KEY>(<>*)[<dsk-.*><ksk-.*>]<ID-CERT>$",
50 "==", "\\1", "\\1", true);
Yingdi Yu43e71612013-10-30 22:19:31 -070051}
52
53SyncPolicyManager::~SyncPolicyManager()
54{}
55
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080056void
57SyncPolicyManager::connectToDaemon()
58{
59 //Hack! transport does not connect to daemon unless an interest is expressed.
60 Name name("/ndn");
61 shared_ptr<ndn::Interest> interest = make_shared<ndn::Interest>(name);
62 m_face->expressInterest(*interest,
63 bind(&SyncPolicyManager::onConnectionData, this, _1, _2),
64 bind(&SyncPolicyManager::onConnectionDataTimeout, this, _1));
65}
66
67void
68SyncPolicyManager::onConnectionData(const shared_ptr<const ndn::Interest>& interest,
69 const shared_ptr<Data>& data)
70{
71 _LOG_DEBUG("onConnectionData");
72}
73
74void
75SyncPolicyManager::onConnectionDataTimeout(const shared_ptr<const ndn::Interest>& interest)
76{
77 _LOG_DEBUG("onConnectionDataTimeout");
78}
79
Yingdi Yu43e71612013-10-30 22:19:31 -070080bool
81SyncPolicyManager::skipVerifyAndTrust (const Data& data)
82{ return false; }
83
84bool
85SyncPolicyManager::requireVerify (const Data& data)
86{ return true; }
87
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080088shared_ptr<ValidationRequest>
89SyncPolicyManager::checkVerificationPolicy(const shared_ptr<Data>& data,
90 int stepCount,
91 const OnVerified& onVerified,
92 const OnVerifyFailed& onVerifyFailed)
Yingdi Yu43e71612013-10-30 22:19:31 -070093{
Yingdi Yu43e71612013-10-30 22:19:31 -070094 if(stepCount > m_stepLimit)
95 {
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080096 onVerifyFailed(data);
97 return SYNC_POLICY_MANAGER_NULL_VALIDATION_REQUEST_PTR;
Yingdi Yu43e71612013-10-30 22:19:31 -070098 }
99
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800100 const Sha256WithRsaSignature* sigPtr = dynamic_cast<const Sha256WithRsaSignature*> (data->getSignature());
101 if(ndn_KeyLocatorType_KEYNAME != sigPtr->getKeyLocator().getType())
Yingdi Yu43e71612013-10-30 22:19:31 -0700102 {
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800103 onVerifyFailed(data);
104 return SYNC_POLICY_MANAGER_NULL_VALIDATION_REQUEST_PTR;
Yingdi Yu43e71612013-10-30 22:19:31 -0700105 }
106
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800107 const Name& keyLocatorName = sigPtr->getKeyLocator().getKeyName();
Yingdi Yu43e71612013-10-30 22:19:31 -0700108
109 // if data is intro cert
110 if(m_wotPrefixRegex->match(data->getName()))
111 {
Yingdi Yu1baf6e02013-11-07 11:35:32 -0800112 // _LOG_DEBUG("Intro Cert");
Yingdi Yu43e71612013-10-30 22:19:31 -0700113 Name keyName = IdentityCertificate::certificateNameToPublicKeyName(keyLocatorName);
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800114 map<string, PublicKey>::const_iterator it = m_trustedIntroducers.find(keyName.toUri());
Yingdi Yu43e71612013-10-30 22:19:31 -0700115 if(m_trustedIntroducers.end() != it)
116 {
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800117 if(Sha256WithRsaHandler::verifySignature(*data, it->second))
118 onVerified(data);
Yingdi Yu43e71612013-10-30 22:19:31 -0700119 else
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800120 onVerifyFailed(data);
121 return SYNC_POLICY_MANAGER_NULL_VALIDATION_REQUEST_PTR;
Yingdi Yu43e71612013-10-30 22:19:31 -0700122 }
123 else
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800124 return prepareRequest(keyName, true, data, stepCount, onVerified, onVerifyFailed);
Yingdi Yu43e71612013-10-30 22:19:31 -0700125 }
126
127 // if data is sync data or chat data
128 if(m_syncPrefixRegex->match(data->getName()) || m_chatDataPolicy->satisfy(*data))
129 {
130 Name keyName = IdentityCertificate::certificateNameToPublicKeyName(keyLocatorName);
131
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800132 map<string, PublicKey>::const_iterator it = m_trustedIntroducers.find(keyName.toUri());
Yingdi Yu43e71612013-10-30 22:19:31 -0700133 if(m_trustedIntroducers.end() != it)
134 {
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800135 if(Sha256WithRsaHandler::verifySignature(*data, it->second))
136 onVerified(data);
Yingdi Yu43e71612013-10-30 22:19:31 -0700137 else
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800138 onVerifyFailed(data);
139 return SYNC_POLICY_MANAGER_NULL_VALIDATION_REQUEST_PTR;
Yingdi Yu43e71612013-10-30 22:19:31 -0700140 }
141
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800142 it = m_trustedProducers.find(keyName.toUri());
Yingdi Yu43e71612013-10-30 22:19:31 -0700143 if(m_trustedProducers.end() != it)
144 {
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800145 if(Sha256WithRsaHandler::verifySignature(*data, it->second))
146 onVerified(data);
Yingdi Yu43e71612013-10-30 22:19:31 -0700147 else
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800148 onVerifyFailed(data);
149 return SYNC_POLICY_MANAGER_NULL_VALIDATION_REQUEST_PTR;
Yingdi Yu43e71612013-10-30 22:19:31 -0700150 }
Yingdi Yu0b3bd482013-11-01 16:11:20 -0700151
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800152 return prepareRequest(keyName, false, data, stepCount, onVerified, onVerifyFailed);
Yingdi Yu43e71612013-10-30 22:19:31 -0700153 }
154
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800155 onVerifyFailed(data);
156 return SYNC_POLICY_MANAGER_NULL_VALIDATION_REQUEST_PTR;
Yingdi Yu43e71612013-10-30 22:19:31 -0700157}
158
159bool
160SyncPolicyManager::checkSigningPolicy(const Name& dataName,
161 const Name& certificateName)
162{
Yingdi Yu43e71612013-10-30 22:19:31 -0700163 return true;
Yingdi Yu43e71612013-10-30 22:19:31 -0700164}
165
166Name
167SyncPolicyManager::inferSigningIdentity(const ndn::Name& dataName)
168{ return m_signingIdentity; }
169
170void
171SyncPolicyManager::addTrustAnchor(const IdentityCertificate& identityCertificate, bool isIntroducer)
172{
Yingdi Yu1baf6e02013-11-07 11:35:32 -0800173 // _LOG_DEBUG("Add intro/producer: " << identityCertificate.getPublicKeyName());
Yingdi Yu43e71612013-10-30 22:19:31 -0700174 if(isIntroducer)
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800175 m_trustedIntroducers.insert(pair <string, PublicKey > (identityCertificate.getPublicKeyName().toUri(),
176 identityCertificate.getPublicKeyInfo()));
Yingdi Yu43e71612013-10-30 22:19:31 -0700177 else
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800178 m_trustedProducers.insert(pair <string, PublicKey > (identityCertificate.getPublicKeyName().toUri(),
179 identityCertificate.getPublicKeyInfo()));
Yingdi Yu43e71612013-10-30 22:19:31 -0700180}
181
182void
183SyncPolicyManager::addChatDataRule(const Name& prefix,
184 const IdentityCertificate& identityCertificate,
185 bool isIntroducer)
186{
187 // Name dataPrefix = prefix;
188 // dataPrefix.append("chronos").append(m_syncPrefix.get(-1));
189 // Ptr<Regex> dataRegex = Regex::fromName(prefix);
190 // Name certName = identityCertificate.getName();
191 // Name signerName = certName.getPrefix(certName.size()-1);
192 // Ptr<Regex> signerRegex = Regex::fromName(signerName, true);
193
194 // SpecificPolicyRule rule(dataRegex, signerRegex);
195 // map<Name, SpecificPolicyRule>::iterator it = m_chatDataRules.find(dataPrefix);
196 // if(it != m_chatDataRules.end())
197 // it->second = rule;
198 // else
199 // m_chatDataRules.insert(pair <Name, SpecificPolicyRule > (dataPrefix, rule));
200
201 addTrustAnchor(identityCertificate, isIntroducer);
202}
203
204
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800205shared_ptr<const vector<Name> >
Yingdi Yu43e71612013-10-30 22:19:31 -0700206SyncPolicyManager::getAllIntroducerName()
207{
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800208 shared_ptr<vector<Name> > nameList = make_shared<vector<Name> >();
Yingdi Yu43e71612013-10-30 22:19:31 -0700209
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800210 map<string, PublicKey>::iterator it = m_trustedIntroducers.begin();
Yingdi Yu43e71612013-10-30 22:19:31 -0700211 for(; it != m_trustedIntroducers.end(); it++)
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800212 nameList->push_back(Name(it->first));
Yingdi Yu43e71612013-10-30 22:19:31 -0700213
214 return nameList;
215}
216
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800217shared_ptr<ValidationRequest>
Yingdi Yu43e71612013-10-30 22:19:31 -0700218SyncPolicyManager::prepareRequest(const Name& keyName,
219 bool forIntroducer,
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800220 shared_ptr<Data> data,
Yingdi Yu43e71612013-10-30 22:19:31 -0700221 const int & stepCount,
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800222 const OnVerified& onVerified,
223 const OnVerifyFailed& onVerifyFailed)
Yingdi Yu43e71612013-10-30 22:19:31 -0700224{
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800225 shared_ptr<Name> interestPrefixName = make_shared<Name>(m_syncPrefix);
Yingdi Yu43e71612013-10-30 22:19:31 -0700226 interestPrefixName->append("WOT").append(keyName).append("INTRO-CERT");
227
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800228 shared_ptr<const vector<Name> > nameList = getAllIntroducerName();
Yingdi Yu0b3bd482013-11-01 16:11:20 -0700229 if(0 == nameList->size())
230 {
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800231 onVerifyFailed(data);
232 return SYNC_POLICY_MANAGER_NULL_VALIDATION_REQUEST_PTR;
Yingdi Yu0b3bd482013-11-01 16:11:20 -0700233 }
Yingdi Yu43e71612013-10-30 22:19:31 -0700234
235 Name interestName = *interestPrefixName;
236 interestName.append(nameList->at(0));
237
238 if(forIntroducer)
239 interestName.append("INTRODUCER");
240
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800241 shared_ptr<ndn::Interest> interest = make_shared<ndn::Interest>(interestName);
Yingdi Yu1baf6e02013-11-07 11:35:32 -0800242 // _LOG_DEBUG("send interest for intro cert: " << interest->getName());
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800243 interest->setChildSelector(ndn_Interest_CHILD_SELECTOR_RIGHT);
Yingdi Yu43e71612013-10-30 22:19:31 -0700244
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800245 OnVerified requestedCertVerifiedCallback = boost::bind(&SyncPolicyManager::onIntroCertVerified,
246 this,
247 _1,
248 forIntroducer,
249 data,
250 onVerified,
251 onVerifyFailed);
Yingdi Yu43e71612013-10-30 22:19:31 -0700252
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800253 OnVerifyFailed requestedCertUnverifiedCallback = boost::bind(&SyncPolicyManager::onIntroCertVerifyFailed,
254 this,
255 _1,
256 interestPrefixName,
257 forIntroducer,
258 nameList,
259 1,
260 data,
261 onVerified,
262 onVerifyFailed);
Yingdi Yu43e71612013-10-30 22:19:31 -0700263
264
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800265 shared_ptr<ValidationRequest> nextStep = make_shared<ValidationRequest>(interest,
266 requestedCertVerifiedCallback,
267 requestedCertUnverifiedCallback,
268 1,
269 m_stepLimit-1);
Yingdi Yu43e71612013-10-30 22:19:31 -0700270 return nextStep;
271}
272
273void
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800274SyncPolicyManager::OnIntroCertInterest(const shared_ptr<const Name>& prefix,
275 const shared_ptr<const ndn::Interest>& interest,
276 Transport& transport,
277 uint64_t registeredPrefixId)
Yingdi Yu43e71612013-10-30 22:19:31 -0700278{
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800279 map<string, Data>::const_iterator it = m_introCert.find(prefix->toUri());
280
281 if(m_introCert.end() != it)
282 {
283 Blob encodedData = it->second.wireEncode();
284 transport.send(*encodedData);
285 }
286}
287
288void
289SyncPolicyManager::OnIntroCertRegisterFailed(const shared_ptr<const Name>& prefix)
290{
291}
292
293void
294SyncPolicyManager::onIntroCertVerified(const shared_ptr<Data>& introCertificateData,
295 bool forIntroducer,
296 shared_ptr<Data> originalData,
297 const OnVerified& onVerified,
298 const OnVerifyFailed& onVerifyFailed)
299{
300 shared_ptr<SyncIntroCertificate> introCertificate = make_shared<SyncIntroCertificate>(*introCertificateData);
Yingdi Yu43e71612013-10-30 22:19:31 -0700301 if(forIntroducer)
Yingdi Yu7bfcd652013-11-12 13:15:33 -0800302 {
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800303 m_trustedIntroducers.insert(pair <string, PublicKey > (introCertificate->getPublicKeyName().toUri(),
304 introCertificate->getPublicKeyInfo()));
Yingdi Yu7bfcd652013-11-12 13:15:33 -0800305 SyncIntroCertificate syncIntroCertificate(m_syncPrefix,
306 introCertificate->getPublicKeyName(),
307 m_identityManager->getDefaultKeyNameForIdentity(m_signingIdentity),
308 introCertificate->getNotBefore(),
309 introCertificate->getNotAfter(),
310 introCertificate->getPublicKeyInfo(),
311 SyncIntroCertificate::INTRODUCER);
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800312
313 Name certName = m_identityManager->getDefaultCertificateNameForIdentity(m_signingIdentity);
Yingdi Yu7bfcd652013-11-12 13:15:33 -0800314 _LOG_DEBUG("Publish Intro Certificate on Verified: " << syncIntroCertificate.getName());
315 m_identityManager->signByCertificate(syncIntroCertificate, certName);
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800316
317 m_transport->send(*syncIntroCertificate.wireEncode());
318
319 // Name prefix = syncIntroCertificate.getName().getPrefix(syncIntroCertificate.getName().size()-1);
320
321 // map<string, Data>::const_iterator it = m_introCert.find(prefix.toEscapedString());
322 // if(m_introCert.end() != it)
323 // {
324 // it->second = syncIntroCertificate;
325 // }
326 // else
327 // {
328 // m_introCert.insert(pair <string, Data> (prefix.toEscapedString(), syncIntroCertificate));
329 // m_face->registerPrefix(prefix,
330 // boost::bind(&SyncPolicyManager::onIntroCertInterest, this, _1, _2, _3, _4),
331 // boost::bind(&SyncPolicyManager::onIntroCertRegisterFailed, this, _1));
332 // }
Yingdi Yu7bfcd652013-11-12 13:15:33 -0800333 }
Yingdi Yu43e71612013-10-30 22:19:31 -0700334 else
Yingdi Yu7bfcd652013-11-12 13:15:33 -0800335 {
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800336 m_trustedProducers.insert(pair <string, PublicKey > (introCertificate->getPublicKeyName().toUri(),
337 introCertificate->getPublicKeyInfo()));
Yingdi Yu7bfcd652013-11-12 13:15:33 -0800338 SyncIntroCertificate syncIntroCertificate(m_syncPrefix,
339 introCertificate->getPublicKeyName(),
340 m_identityManager->getDefaultKeyNameForIdentity(m_signingIdentity),
341 introCertificate->getNotBefore(),
342 introCertificate->getNotAfter(),
343 introCertificate->getPublicKeyInfo(),
344 SyncIntroCertificate::PRODUCER);
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800345
346 Name certName = m_identityManager->getDefaultCertificateNameForIdentity(m_signingIdentity);
Yingdi Yu7bfcd652013-11-12 13:15:33 -0800347 _LOG_DEBUG("Publish Intro Certificate on Verified: " << syncIntroCertificate.getName());
348 m_identityManager->signByCertificate(syncIntroCertificate, certName);
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800349
350 m_transport->send(*syncIntroCertificate.wireEncode());
351
352 // Name prefix = syncIntroCertificate.getName().getPrefix(syncIntroCertificate.getName().size()-1);
353
354 // map<string, Data>::const_iterator it = m_introCert.find(prefix.toEscapedString());
355 // if(m_introCert.end() != it)
356 // {
357 // it->second = syncIntroCertificate;
358 // }
359 // else
360 // {
361 // m_introCert.insert(pair <string, Data> (prefix.toEscapedString(), syncIntroCertificate));
362 // m_face->registerPrefix(prefix,
363 // boost::bind(&SyncPolicyManager::onIntroCertInterest, this, _1, _2, _3, _4),
364 // boost::bind(&SyncPolicyManager::onIntroCertRegisterFailed, this, _1));
365 // }
Yingdi Yu7bfcd652013-11-12 13:15:33 -0800366 }
Yingdi Yu43e71612013-10-30 22:19:31 -0700367
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800368 if(Sha256WithRsaHandler::verifySignature(*originalData, introCertificate->getPublicKeyInfo()))
369 onVerified(originalData);
Yingdi Yu43e71612013-10-30 22:19:31 -0700370 else
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800371 onVerifyFailed(originalData);
Yingdi Yu43e71612013-10-30 22:19:31 -0700372}
373
374void
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800375SyncPolicyManager::onIntroCertVerifyFailed(const shared_ptr<Data>& introCertificateData,
376 shared_ptr<Name> interestPrefixName,
377 bool forIntroducer,
378 shared_ptr<const vector<Name> > introNameList,
379 int nextIntroducerIndex,
380 shared_ptr<Data> originalData,
381 const OnVerified& onVerified,
382 const OnVerifyFailed& onVerifyFailed)
Yingdi Yu43e71612013-10-30 22:19:31 -0700383{
384 Name interestName = *interestPrefixName;
385 if(nextIntroducerIndex < introNameList->size())
386 interestName.append(introNameList->at(nextIntroducerIndex));
387 else
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800388 onVerifyFailed(originalData);
Yingdi Yu43e71612013-10-30 22:19:31 -0700389
390 if(forIntroducer)
391 interestName.append("INTRODUCER");
392
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800393 shared_ptr<ndn::Interest> interest = make_shared<ndn::Interest>(interestName);
394 interest->setChildSelector(ndn_Interest_CHILD_SELECTOR_RIGHT);
Yingdi Yu43e71612013-10-30 22:19:31 -0700395
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800396 OnVerified onRecursiveVerified = boost::bind(&SyncPolicyManager::onIntroCertVerified,
397 this,
398 _1,
399 forIntroducer,
400 originalData,
401 onVerified,
402 onVerifyFailed);
403
404 OnVerifyFailed onRecursiveVerifyFailed = boost::bind(&SyncPolicyManager::onIntroCertVerifyFailed,
405 this,
406 _1,
407 interestPrefixName,
408 forIntroducer,
409 introNameList,
410 nextIntroducerIndex + 1,
411 originalData,
412 onVerified,
413 onVerifyFailed);
414
415 m_face->expressInterest(*interest,
416 boost::bind(&SyncPolicyManager::onIntroCertData,
417 this,
418 _1,
419 _2,
420 m_stepLimit-1,
421 onRecursiveVerified,
422 onRecursiveVerifyFailed,
423 originalData,
424 onVerifyFailed),
425 boost::bind(&SyncPolicyManager::onIntroCertTimeout,
426 this,
427 _1,
428 1,
429 m_stepLimit-1,
430 onRecursiveVerified,
431 onRecursiveVerifyFailed,
432 originalData,
433 onVerifyFailed));
Yingdi Yu43e71612013-10-30 22:19:31 -0700434}
435
436void
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800437SyncPolicyManager::onIntroCertData(const shared_ptr<const ndn::Interest> &interest,
438 const shared_ptr<Data>& introCertificateData,
439 int stepCount,
440 const OnVerified& onRecursiveVerified,
441 const OnVerifyFailed& onRecursiveVerifyFailed,
442 shared_ptr<Data> originalData,
443 const OnVerifyFailed& onVerifyFailed)
444{
445 shared_ptr<ValidationRequest> nextStep = checkVerificationPolicy(introCertificateData, stepCount, onRecursiveVerified, onRecursiveVerifyFailed);
446 if (nextStep)
447 m_face->expressInterest
448 (*nextStep->interest_,
449 boost::bind(&SyncPolicyManager::onIntroCertData,
450 this,
451 _1,
452 _2,
453 nextStep->stepCount_,
454 nextStep->onVerified_,
455 nextStep->onVerifyFailed_,
456 introCertificateData,
457 onRecursiveVerifyFailed),
458 boost::bind(&SyncPolicyManager::onIntroCertTimeout,
459 this,
460 _1,
461 nextStep->retry_,
462 nextStep->stepCount_,
463 nextStep->onVerified_,
464 nextStep->onVerifyFailed_,
465 introCertificateData,
466 onRecursiveVerifyFailed));
467}
468
469void
470SyncPolicyManager::onIntroCertTimeout(const shared_ptr<const ndn::Interest>& interest,
Yingdi Yu43e71612013-10-30 22:19:31 -0700471 int retry,
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800472 int stepCount,
473 const OnVerified& onRecursiveVerified,
474 const OnVerifyFailed& onRecursiveVerifyFailed,
475 shared_ptr<Data> originalData,
476 const OnVerifyFailed& onVerifyFailed)
Yingdi Yu43e71612013-10-30 22:19:31 -0700477{
478 if(retry > 0)
479 {
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800480 m_face->expressInterest(*interest,
481 boost::bind(&SyncPolicyManager::onIntroCertData,
482 this,
483 _1,
484 _2,
485 stepCount,
486 onRecursiveVerified,
487 onRecursiveVerifyFailed,
488 originalData,
489 onVerifyFailed),
490 boost::bind(&SyncPolicyManager::onIntroCertTimeout,
491 this,
492 _1,
493 retry - 1,
494 stepCount,
495 onRecursiveVerified,
496 onRecursiveVerifyFailed,
497 originalData,
498 onVerifyFailed));
Yingdi Yu43e71612013-10-30 22:19:31 -0700499 }
500 else
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800501 onVerifyFailed(originalData);
Yingdi Yu43e71612013-10-30 22:19:31 -0700502}