blob: 8b34856c55519172af4d77a1534af2864cd85778 [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 Yu0cb0f2b2014-01-09 13:51:16 -080013#include <ndn-cpp/security/verifier.hpp>
14#include <ndn-cpp/security/signature/signature-sha256-with-rsa.hpp>
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080015
16#include "sync-policy-manager.h"
Yingdi Yu43e71612013-10-30 22:19:31 -070017
18using namespace ndn;
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080019using namespace ndn::ptr_lib;
Yingdi Yu43e71612013-10-30 22:19:31 -070020using namespace std;
21
22INIT_LOGGER("SyncPolicyManager");
23
24SyncPolicyManager::SyncPolicyManager(const Name& signingIdentity,
25 const Name& signingCertificateName,
26 const Name& syncPrefix,
Yingdi Yu6e235db2013-12-27 08:40:53 +080027 shared_ptr<Face> face,
Yingdi Yu43e71612013-10-30 22:19:31 -070028 int stepLimit)
29 : m_signingIdentity(signingIdentity)
30 , m_signingCertificateName(signingCertificateName.getPrefix(signingCertificateName.size()-1))
31 , m_syncPrefix(syncPrefix)
32 , m_stepLimit(stepLimit)
Yingdi Yu0cb0f2b2014-01-09 13:51:16 -080033 , m_keyChain(new KeyChain())
34{
Yingdi Yu43e71612013-10-30 22:19:31 -070035 Name wotPrefix = syncPrefix;
36 wotPrefix.append("WOT");
37 m_syncPrefixRegex = Regex::fromName(syncPrefix);
38 m_wotPrefixRegex = Regex::fromName(wotPrefix);
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080039 m_chatDataPolicy = make_shared<IdentityPolicyRule>("^[^<%F0.>]*<%F0.>([^<chronos>]*)<chronos><>",
40 "^([^<KEY>]*)<KEY>(<>*)[<dsk-.*><ksk-.*>]<ID-CERT>$",
41 "==", "\\1", "\\1", true);
Yingdi Yu43e71612013-10-30 22:19:31 -070042}
43
44SyncPolicyManager::~SyncPolicyManager()
45{}
46
47bool
48SyncPolicyManager::skipVerifyAndTrust (const Data& data)
49{ return false; }
50
51bool
52SyncPolicyManager::requireVerify (const Data& data)
53{ return true; }
54
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080055shared_ptr<ValidationRequest>
56SyncPolicyManager::checkVerificationPolicy(const shared_ptr<Data>& data,
57 int stepCount,
58 const OnVerified& onVerified,
59 const OnVerifyFailed& onVerifyFailed)
Yingdi Yu43e71612013-10-30 22:19:31 -070060{
Yingdi Yu43e71612013-10-30 22:19:31 -070061 if(stepCount > m_stepLimit)
62 {
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080063 onVerifyFailed(data);
64 return SYNC_POLICY_MANAGER_NULL_VALIDATION_REQUEST_PTR;
Yingdi Yu43e71612013-10-30 22:19:31 -070065 }
66
Yingdi Yu0cb0f2b2014-01-09 13:51:16 -080067 try{
68 SignatureSha256WithRsa sig(data->getSignature());
Yingdi Yu43e71612013-10-30 22:19:31 -070069
Yingdi Yu0cb0f2b2014-01-09 13:51:16 -080070 const Name& keyLocatorName = sig.getKeyLocator().getName();
Yingdi Yu43e71612013-10-30 22:19:31 -070071
Yingdi Yu0cb0f2b2014-01-09 13:51:16 -080072 // if data is intro cert
73 if(m_wotPrefixRegex->match(data->getName()))
74 {
75 // _LOG_DEBUG("Intro Cert");
76 Name keyName = IdentityCertificate::certificateNameToPublicKeyName(keyLocatorName);
77 map<string, PublicKey>::const_iterator it = m_trustedIntroducers.find(keyName.toUri());
78 if(m_trustedIntroducers.end() != it)
79 {
80 if(Verifier::verifySignature(*data, sig, it->second))
81 onVerified(data);
82 else
83 onVerifyFailed(data);
84 return SYNC_POLICY_MANAGER_NULL_VALIDATION_REQUEST_PTR;
85 }
86 else
87 return prepareRequest(keyName, true, data, stepCount, onVerified, onVerifyFailed);
88 }
Yingdi Yu43e71612013-10-30 22:19:31 -070089
Yingdi Yu0cb0f2b2014-01-09 13:51:16 -080090 // if data is sync data or chat data
91 if(m_syncPrefixRegex->match(data->getName()) || m_chatDataPolicy->satisfy(*data))
92 {
93 Name keyName = IdentityCertificate::certificateNameToPublicKeyName(keyLocatorName);
Yingdi Yu43e71612013-10-30 22:19:31 -070094
Yingdi Yu0cb0f2b2014-01-09 13:51:16 -080095 map<string, PublicKey>::const_iterator it = m_trustedIntroducers.find(keyName.toUri());
96 if(m_trustedIntroducers.end() != it)
97 {
98 if(Verifier::verifySignature(*data, sig, it->second))
99 onVerified(data);
100 else
101 onVerifyFailed(data);
102 return SYNC_POLICY_MANAGER_NULL_VALIDATION_REQUEST_PTR;
103 }
Yingdi Yu43e71612013-10-30 22:19:31 -0700104
Yingdi Yu0cb0f2b2014-01-09 13:51:16 -0800105 it = m_trustedProducers.find(keyName.toUri());
106 if(m_trustedProducers.end() != it)
107 {
108 if(Verifier::verifySignature(*data, sig, it->second))
109 onVerified(data);
110 else
111 onVerifyFailed(data);
112 return SYNC_POLICY_MANAGER_NULL_VALIDATION_REQUEST_PTR;
113 }
Yingdi Yu0b3bd482013-11-01 16:11:20 -0700114
Yingdi Yu0cb0f2b2014-01-09 13:51:16 -0800115 return prepareRequest(keyName, false, data, stepCount, onVerified, onVerifyFailed);
116 }
117 }catch(SignatureSha256WithRsa::Error &e){
118 _LOG_DEBUG("SyncPolicyManager Error: " << e.what());
119 onVerifyFailed(data);
120 return SYNC_POLICY_MANAGER_NULL_VALIDATION_REQUEST_PTR;
121 }catch(KeyLocator::Error &e){
122 _LOG_DEBUG("SyncPolicyManager Error: " << e.what());
123 onVerifyFailed(data);
124 return SYNC_POLICY_MANAGER_NULL_VALIDATION_REQUEST_PTR;
125 }
126
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800127 onVerifyFailed(data);
128 return SYNC_POLICY_MANAGER_NULL_VALIDATION_REQUEST_PTR;
Yingdi Yu43e71612013-10-30 22:19:31 -0700129}
130
131bool
132SyncPolicyManager::checkSigningPolicy(const Name& dataName,
133 const Name& certificateName)
134{
Yingdi Yu43e71612013-10-30 22:19:31 -0700135 return true;
Yingdi Yu43e71612013-10-30 22:19:31 -0700136}
137
138Name
139SyncPolicyManager::inferSigningIdentity(const ndn::Name& dataName)
140{ return m_signingIdentity; }
141
142void
143SyncPolicyManager::addTrustAnchor(const IdentityCertificate& identityCertificate, bool isIntroducer)
144{
Yingdi Yu1baf6e02013-11-07 11:35:32 -0800145 // _LOG_DEBUG("Add intro/producer: " << identityCertificate.getPublicKeyName());
Yingdi Yu43e71612013-10-30 22:19:31 -0700146 if(isIntroducer)
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800147 m_trustedIntroducers.insert(pair <string, PublicKey > (identityCertificate.getPublicKeyName().toUri(),
148 identityCertificate.getPublicKeyInfo()));
Yingdi Yu43e71612013-10-30 22:19:31 -0700149 else
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800150 m_trustedProducers.insert(pair <string, PublicKey > (identityCertificate.getPublicKeyName().toUri(),
151 identityCertificate.getPublicKeyInfo()));
Yingdi Yu43e71612013-10-30 22:19:31 -0700152}
153
154void
155SyncPolicyManager::addChatDataRule(const Name& prefix,
156 const IdentityCertificate& identityCertificate,
157 bool isIntroducer)
158{
Yingdi Yu43e71612013-10-30 22:19:31 -0700159 addTrustAnchor(identityCertificate, isIntroducer);
160}
161
162
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800163shared_ptr<const vector<Name> >
Yingdi Yu43e71612013-10-30 22:19:31 -0700164SyncPolicyManager::getAllIntroducerName()
165{
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800166 shared_ptr<vector<Name> > nameList = make_shared<vector<Name> >();
Yingdi Yu43e71612013-10-30 22:19:31 -0700167
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800168 map<string, PublicKey>::iterator it = m_trustedIntroducers.begin();
Yingdi Yu43e71612013-10-30 22:19:31 -0700169 for(; it != m_trustedIntroducers.end(); it++)
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800170 nameList->push_back(Name(it->first));
Yingdi Yu43e71612013-10-30 22:19:31 -0700171
172 return nameList;
173}
174
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800175shared_ptr<ValidationRequest>
Yingdi Yu43e71612013-10-30 22:19:31 -0700176SyncPolicyManager::prepareRequest(const Name& keyName,
177 bool forIntroducer,
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800178 shared_ptr<Data> data,
Yingdi Yu43e71612013-10-30 22:19:31 -0700179 const int & stepCount,
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800180 const OnVerified& onVerified,
181 const OnVerifyFailed& onVerifyFailed)
Yingdi Yu43e71612013-10-30 22:19:31 -0700182{
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800183 shared_ptr<Name> interestPrefixName = make_shared<Name>(m_syncPrefix);
Yingdi Yu43e71612013-10-30 22:19:31 -0700184 interestPrefixName->append("WOT").append(keyName).append("INTRO-CERT");
185
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800186 shared_ptr<const vector<Name> > nameList = getAllIntroducerName();
Yingdi Yu0b3bd482013-11-01 16:11:20 -0700187 if(0 == nameList->size())
188 {
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800189 onVerifyFailed(data);
190 return SYNC_POLICY_MANAGER_NULL_VALIDATION_REQUEST_PTR;
Yingdi Yu0b3bd482013-11-01 16:11:20 -0700191 }
Yingdi Yu43e71612013-10-30 22:19:31 -0700192
193 Name interestName = *interestPrefixName;
194 interestName.append(nameList->at(0));
195
196 if(forIntroducer)
197 interestName.append("INTRODUCER");
198
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800199 shared_ptr<ndn::Interest> interest = make_shared<ndn::Interest>(interestName);
Yingdi Yu1baf6e02013-11-07 11:35:32 -0800200 // _LOG_DEBUG("send interest for intro cert: " << interest->getName());
Yingdi Yu43e71612013-10-30 22:19:31 -0700201
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800202 OnVerified requestedCertVerifiedCallback = boost::bind(&SyncPolicyManager::onIntroCertVerified,
203 this,
204 _1,
205 forIntroducer,
206 data,
207 onVerified,
208 onVerifyFailed);
Yingdi Yu43e71612013-10-30 22:19:31 -0700209
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800210 OnVerifyFailed requestedCertUnverifiedCallback = boost::bind(&SyncPolicyManager::onIntroCertVerifyFailed,
211 this,
212 _1,
213 interestPrefixName,
214 forIntroducer,
215 nameList,
216 1,
217 data,
218 onVerified,
219 onVerifyFailed);
Yingdi Yu43e71612013-10-30 22:19:31 -0700220
221
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800222 shared_ptr<ValidationRequest> nextStep = make_shared<ValidationRequest>(interest,
223 requestedCertVerifiedCallback,
224 requestedCertUnverifiedCallback,
225 1,
226 m_stepLimit-1);
Yingdi Yu43e71612013-10-30 22:19:31 -0700227 return nextStep;
228}
229
230void
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800231SyncPolicyManager::OnIntroCertInterest(const shared_ptr<const Name>& prefix,
232 const shared_ptr<const ndn::Interest>& interest,
233 Transport& transport,
234 uint64_t registeredPrefixId)
Yingdi Yu43e71612013-10-30 22:19:31 -0700235{
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800236 map<string, Data>::const_iterator it = m_introCert.find(prefix->toUri());
237
238 if(m_introCert.end() != it)
Yingdi Yu0cb0f2b2014-01-09 13:51:16 -0800239 m_face->put(it->second);
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800240}
241
242void
243SyncPolicyManager::OnIntroCertRegisterFailed(const shared_ptr<const Name>& prefix)
244{
245}
246
247void
248SyncPolicyManager::onIntroCertVerified(const shared_ptr<Data>& introCertificateData,
249 bool forIntroducer,
250 shared_ptr<Data> originalData,
251 const OnVerified& onVerified,
252 const OnVerifyFailed& onVerifyFailed)
253{
254 shared_ptr<SyncIntroCertificate> introCertificate = make_shared<SyncIntroCertificate>(*introCertificateData);
Yingdi Yu43e71612013-10-30 22:19:31 -0700255 if(forIntroducer)
Yingdi Yu7bfcd652013-11-12 13:15:33 -0800256 {
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800257 m_trustedIntroducers.insert(pair <string, PublicKey > (introCertificate->getPublicKeyName().toUri(),
258 introCertificate->getPublicKeyInfo()));
Yingdi Yu7bfcd652013-11-12 13:15:33 -0800259 SyncIntroCertificate syncIntroCertificate(m_syncPrefix,
260 introCertificate->getPublicKeyName(),
Yingdi Yu0cb0f2b2014-01-09 13:51:16 -0800261 m_keyChain->getDefaultKeyNameForIdentity(m_signingIdentity),
Yingdi Yu7bfcd652013-11-12 13:15:33 -0800262 introCertificate->getNotBefore(),
263 introCertificate->getNotAfter(),
264 introCertificate->getPublicKeyInfo(),
265 SyncIntroCertificate::INTRODUCER);
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800266
Yingdi Yu0cb0f2b2014-01-09 13:51:16 -0800267 Name certName = m_keyChain->getDefaultCertificateNameForIdentity(m_signingIdentity);
Yingdi Yu7bfcd652013-11-12 13:15:33 -0800268 _LOG_DEBUG("Publish Intro Certificate on Verified: " << syncIntroCertificate.getName());
Yingdi Yu0cb0f2b2014-01-09 13:51:16 -0800269 m_keyChain->sign(syncIntroCertificate, certName);
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800270
Yingdi Yu0cb0f2b2014-01-09 13:51:16 -0800271 m_face->put(syncIntroCertificate);
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800272
273 // Name prefix = syncIntroCertificate.getName().getPrefix(syncIntroCertificate.getName().size()-1);
274
275 // map<string, Data>::const_iterator it = m_introCert.find(prefix.toEscapedString());
276 // if(m_introCert.end() != it)
277 // {
278 // it->second = syncIntroCertificate;
279 // }
280 // else
281 // {
282 // m_introCert.insert(pair <string, Data> (prefix.toEscapedString(), syncIntroCertificate));
283 // m_face->registerPrefix(prefix,
284 // boost::bind(&SyncPolicyManager::onIntroCertInterest, this, _1, _2, _3, _4),
285 // boost::bind(&SyncPolicyManager::onIntroCertRegisterFailed, this, _1));
286 // }
Yingdi Yu7bfcd652013-11-12 13:15:33 -0800287 }
Yingdi Yu43e71612013-10-30 22:19:31 -0700288 else
Yingdi Yu7bfcd652013-11-12 13:15:33 -0800289 {
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800290 m_trustedProducers.insert(pair <string, PublicKey > (introCertificate->getPublicKeyName().toUri(),
291 introCertificate->getPublicKeyInfo()));
Yingdi Yu7bfcd652013-11-12 13:15:33 -0800292 SyncIntroCertificate syncIntroCertificate(m_syncPrefix,
293 introCertificate->getPublicKeyName(),
Yingdi Yu0cb0f2b2014-01-09 13:51:16 -0800294 m_keyChain->getDefaultKeyNameForIdentity(m_signingIdentity),
Yingdi Yu7bfcd652013-11-12 13:15:33 -0800295 introCertificate->getNotBefore(),
296 introCertificate->getNotAfter(),
297 introCertificate->getPublicKeyInfo(),
298 SyncIntroCertificate::PRODUCER);
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800299
Yingdi Yu0cb0f2b2014-01-09 13:51:16 -0800300 Name certName = m_keyChain->getDefaultCertificateNameForIdentity(m_signingIdentity);
Yingdi Yu7bfcd652013-11-12 13:15:33 -0800301 _LOG_DEBUG("Publish Intro Certificate on Verified: " << syncIntroCertificate.getName());
Yingdi Yu0cb0f2b2014-01-09 13:51:16 -0800302 m_keyChain->sign(syncIntroCertificate, certName);
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800303
Yingdi Yu0cb0f2b2014-01-09 13:51:16 -0800304 m_face->put(syncIntroCertificate);
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800305
306 // Name prefix = syncIntroCertificate.getName().getPrefix(syncIntroCertificate.getName().size()-1);
307
308 // map<string, Data>::const_iterator it = m_introCert.find(prefix.toEscapedString());
309 // if(m_introCert.end() != it)
310 // {
311 // it->second = syncIntroCertificate;
312 // }
313 // else
314 // {
315 // m_introCert.insert(pair <string, Data> (prefix.toEscapedString(), syncIntroCertificate));
316 // m_face->registerPrefix(prefix,
317 // boost::bind(&SyncPolicyManager::onIntroCertInterest, this, _1, _2, _3, _4),
318 // boost::bind(&SyncPolicyManager::onIntroCertRegisterFailed, this, _1));
319 // }
Yingdi Yu7bfcd652013-11-12 13:15:33 -0800320 }
Yingdi Yu43e71612013-10-30 22:19:31 -0700321
Yingdi Yu0cb0f2b2014-01-09 13:51:16 -0800322 try{
323 SignatureSha256WithRsa sig(originalData->getSignature());
324 if(Verifier::verifySignature(*originalData, sig, introCertificate->getPublicKeyInfo()))
325 onVerified(originalData);
326 else
327 onVerifyFailed(originalData);
328 }catch(SignatureSha256WithRsa::Error &e){
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800329 onVerifyFailed(originalData);
Yingdi Yu0cb0f2b2014-01-09 13:51:16 -0800330 }catch(KeyLocator::Error &e){
331 onVerifyFailed(originalData);
332 }
Yingdi Yu43e71612013-10-30 22:19:31 -0700333}
334
335void
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800336SyncPolicyManager::onIntroCertVerifyFailed(const shared_ptr<Data>& introCertificateData,
337 shared_ptr<Name> interestPrefixName,
338 bool forIntroducer,
339 shared_ptr<const vector<Name> > introNameList,
340 int nextIntroducerIndex,
341 shared_ptr<Data> originalData,
342 const OnVerified& onVerified,
343 const OnVerifyFailed& onVerifyFailed)
Yingdi Yu43e71612013-10-30 22:19:31 -0700344{
345 Name interestName = *interestPrefixName;
346 if(nextIntroducerIndex < introNameList->size())
347 interestName.append(introNameList->at(nextIntroducerIndex));
348 else
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800349 onVerifyFailed(originalData);
Yingdi Yu43e71612013-10-30 22:19:31 -0700350
351 if(forIntroducer)
352 interestName.append("INTRODUCER");
353
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800354 shared_ptr<ndn::Interest> interest = make_shared<ndn::Interest>(interestName);
Yingdi Yu43e71612013-10-30 22:19:31 -0700355
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800356 OnVerified onRecursiveVerified = boost::bind(&SyncPolicyManager::onIntroCertVerified,
357 this,
358 _1,
359 forIntroducer,
360 originalData,
361 onVerified,
362 onVerifyFailed);
363
364 OnVerifyFailed onRecursiveVerifyFailed = boost::bind(&SyncPolicyManager::onIntroCertVerifyFailed,
365 this,
366 _1,
367 interestPrefixName,
368 forIntroducer,
369 introNameList,
370 nextIntroducerIndex + 1,
371 originalData,
372 onVerified,
373 onVerifyFailed);
374
375 m_face->expressInterest(*interest,
376 boost::bind(&SyncPolicyManager::onIntroCertData,
377 this,
378 _1,
379 _2,
380 m_stepLimit-1,
381 onRecursiveVerified,
382 onRecursiveVerifyFailed,
383 originalData,
384 onVerifyFailed),
385 boost::bind(&SyncPolicyManager::onIntroCertTimeout,
386 this,
387 _1,
388 1,
389 m_stepLimit-1,
390 onRecursiveVerified,
391 onRecursiveVerifyFailed,
392 originalData,
393 onVerifyFailed));
Yingdi Yu43e71612013-10-30 22:19:31 -0700394}
395
396void
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800397SyncPolicyManager::onIntroCertData(const shared_ptr<const ndn::Interest> &interest,
398 const shared_ptr<Data>& introCertificateData,
399 int stepCount,
400 const OnVerified& onRecursiveVerified,
401 const OnVerifyFailed& onRecursiveVerifyFailed,
402 shared_ptr<Data> originalData,
403 const OnVerifyFailed& onVerifyFailed)
404{
405 shared_ptr<ValidationRequest> nextStep = checkVerificationPolicy(introCertificateData, stepCount, onRecursiveVerified, onRecursiveVerifyFailed);
406 if (nextStep)
407 m_face->expressInterest
408 (*nextStep->interest_,
409 boost::bind(&SyncPolicyManager::onIntroCertData,
410 this,
411 _1,
412 _2,
413 nextStep->stepCount_,
414 nextStep->onVerified_,
415 nextStep->onVerifyFailed_,
416 introCertificateData,
417 onRecursiveVerifyFailed),
418 boost::bind(&SyncPolicyManager::onIntroCertTimeout,
419 this,
420 _1,
421 nextStep->retry_,
422 nextStep->stepCount_,
423 nextStep->onVerified_,
424 nextStep->onVerifyFailed_,
425 introCertificateData,
426 onRecursiveVerifyFailed));
427}
428
429void
430SyncPolicyManager::onIntroCertTimeout(const shared_ptr<const ndn::Interest>& interest,
Yingdi Yu43e71612013-10-30 22:19:31 -0700431 int retry,
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800432 int stepCount,
433 const OnVerified& onRecursiveVerified,
434 const OnVerifyFailed& onRecursiveVerifyFailed,
435 shared_ptr<Data> originalData,
436 const OnVerifyFailed& onVerifyFailed)
Yingdi Yu43e71612013-10-30 22:19:31 -0700437{
438 if(retry > 0)
439 {
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800440 m_face->expressInterest(*interest,
441 boost::bind(&SyncPolicyManager::onIntroCertData,
442 this,
443 _1,
444 _2,
445 stepCount,
446 onRecursiveVerified,
447 onRecursiveVerifyFailed,
448 originalData,
449 onVerifyFailed),
450 boost::bind(&SyncPolicyManager::onIntroCertTimeout,
451 this,
452 _1,
453 retry - 1,
454 stepCount,
455 onRecursiveVerified,
456 onRecursiveVerifyFailed,
457 originalData,
458 onVerifyFailed));
Yingdi Yu43e71612013-10-30 22:19:31 -0700459 }
460 else
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800461 onVerifyFailed(originalData);
Yingdi Yu43e71612013-10-30 22:19:31 -0700462}