blob: 5a07b5c1a9caf51123fc0bf3d992dc13ee33fc15 [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>
Yingdi Yu5e0af3e2014-01-15 19:33:25 -080014#include <ndn-cpp/security/signature-sha256-with-rsa.hpp>
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080015
Yingdi Yu5e0af3e2014-01-15 19:33:25 -080016#include "sec-policy-sync.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
Yingdi Yu5e0af3e2014-01-15 19:33:25 -080022INIT_LOGGER("SecPolicySync");
Yingdi Yu43e71612013-10-30 22:19:31 -070023
Yingdi Yu5e0af3e2014-01-15 19:33:25 -080024SecPolicySync::SecPolicySync(const Name& signingIdentity,
Yingdi Yu43e71612013-10-30 22:19:31 -070025 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 Yu5e0af3e2014-01-15 19:33:25 -080039 m_chatDataPolicy = make_shared<SecRuleIdentity>("^[^<%F0.>]*<%F0.>([^<chronos>]*)<chronos><>",
40 "^([^<KEY>]*)<KEY>(<>*)[<dsk-.*><ksk-.*>]<ID-CERT>$",
41 "==", "\\1", "\\1", true);
Yingdi Yu43e71612013-10-30 22:19:31 -070042}
43
Yingdi Yu5e0af3e2014-01-15 19:33:25 -080044SecPolicySync::~SecPolicySync()
Yingdi Yu43e71612013-10-30 22:19:31 -070045{}
46
47bool
Yingdi Yu5e0af3e2014-01-15 19:33:25 -080048SecPolicySync::skipVerifyAndTrust (const Data& data)
Yingdi Yu43e71612013-10-30 22:19:31 -070049{ return false; }
50
51bool
Yingdi Yu5e0af3e2014-01-15 19:33:25 -080052SecPolicySync::requireVerify (const Data& data)
Yingdi Yu43e71612013-10-30 22:19:31 -070053{ return true; }
54
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080055shared_ptr<ValidationRequest>
Yingdi Yu5e0af3e2014-01-15 19:33:25 -080056SecPolicySync::checkVerificationPolicy(const shared_ptr<Data>& data,
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080057 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);
Yingdi Yu5e0af3e2014-01-15 19:33:25 -080064 return shared_ptr<ValidationRequest>();
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);
Yingdi Yu5e0af3e2014-01-15 19:33:25 -080084 return shared_ptr<ValidationRequest>();
Yingdi Yu0cb0f2b2014-01-09 13:51:16 -080085 }
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);
Yingdi Yu5e0af3e2014-01-15 19:33:25 -0800102 return shared_ptr<ValidationRequest>();
Yingdi Yu0cb0f2b2014-01-09 13:51:16 -0800103 }
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);
Yingdi Yu5e0af3e2014-01-15 19:33:25 -0800112 return shared_ptr<ValidationRequest>();
Yingdi Yu0cb0f2b2014-01-09 13:51:16 -0800113 }
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){
Yingdi Yu5e0af3e2014-01-15 19:33:25 -0800118 _LOG_DEBUG("SecPolicySync Error: " << e.what());
Yingdi Yu0cb0f2b2014-01-09 13:51:16 -0800119 onVerifyFailed(data);
Yingdi Yu5e0af3e2014-01-15 19:33:25 -0800120 return shared_ptr<ValidationRequest>();
Yingdi Yu0cb0f2b2014-01-09 13:51:16 -0800121 }catch(KeyLocator::Error &e){
Yingdi Yu5e0af3e2014-01-15 19:33:25 -0800122 _LOG_DEBUG("SecPolicySync Error: " << e.what());
Yingdi Yu0cb0f2b2014-01-09 13:51:16 -0800123 onVerifyFailed(data);
Yingdi Yu5e0af3e2014-01-15 19:33:25 -0800124 return shared_ptr<ValidationRequest>();
Yingdi Yu0cb0f2b2014-01-09 13:51:16 -0800125 }
126
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800127 onVerifyFailed(data);
Yingdi Yu5e0af3e2014-01-15 19:33:25 -0800128 return shared_ptr<ValidationRequest>();
Yingdi Yu43e71612013-10-30 22:19:31 -0700129}
130
131bool
Yingdi Yu5e0af3e2014-01-15 19:33:25 -0800132SecPolicySync::checkSigningPolicy(const Name& dataName,
Yingdi Yu43e71612013-10-30 22:19:31 -0700133 const Name& certificateName)
134{
Yingdi Yu43e71612013-10-30 22:19:31 -0700135 return true;
Yingdi Yu43e71612013-10-30 22:19:31 -0700136}
137
138Name
Yingdi Yu5e0af3e2014-01-15 19:33:25 -0800139SecPolicySync::inferSigningIdentity(const ndn::Name& dataName)
Yingdi Yu43e71612013-10-30 22:19:31 -0700140{ return m_signingIdentity; }
141
142void
Yingdi Yu5e0af3e2014-01-15 19:33:25 -0800143SecPolicySync::addTrustAnchor(const IdentityCertificate& identityCertificate, bool isIntroducer)
Yingdi Yu43e71612013-10-30 22:19:31 -0700144{
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
Yingdi Yu5e0af3e2014-01-15 19:33:25 -0800155SecPolicySync::addChatDataRule(const Name& prefix,
Yingdi Yu43e71612013-10-30 22:19:31 -0700156 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 Yu5e0af3e2014-01-15 19:33:25 -0800164SecPolicySync::getAllIntroducerName()
Yingdi Yu43e71612013-10-30 22:19:31 -0700165{
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 Yu5e0af3e2014-01-15 19:33:25 -0800176SecPolicySync::prepareRequest(const Name& keyName,
Yingdi Yu43e71612013-10-30 22:19:31 -0700177 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);
Yingdi Yu5e0af3e2014-01-15 19:33:25 -0800190 return shared_ptr<ValidationRequest>();
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 Yu5e0af3e2014-01-15 19:33:25 -0800202 OnVerified requestedCertVerifiedCallback = boost::bind(&SecPolicySync::onIntroCertVerified,
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800203 this,
204 _1,
205 forIntroducer,
206 data,
207 onVerified,
208 onVerifyFailed);
Yingdi Yu43e71612013-10-30 22:19:31 -0700209
Yingdi Yu5e0af3e2014-01-15 19:33:25 -0800210 OnVerifyFailed requestedCertUnverifiedCallback = boost::bind(&SecPolicySync::onIntroCertVerifyFailed,
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800211 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 Yu5e0af3e2014-01-15 19:33:25 -0800231SecPolicySync::OnIntroCertInterest(const shared_ptr<const Name>& prefix,
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800232 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
Yingdi Yu5e0af3e2014-01-15 19:33:25 -0800243SecPolicySync::OnIntroCertRegisterFailed(const shared_ptr<const Name>& prefix)
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800244{
245}
246
247void
Yingdi Yu5e0af3e2014-01-15 19:33:25 -0800248SecPolicySync::onIntroCertVerified(const shared_ptr<Data>& introCertificateData,
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800249 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,
Yingdi Yu5e0af3e2014-01-15 19:33:25 -0800284 // boost::bind(&SecPolicySync::onIntroCertInterest, this, _1, _2, _3, _4),
285 // boost::bind(&SecPolicySync::onIntroCertRegisterFailed, this, _1));
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800286 // }
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,
Yingdi Yu5e0af3e2014-01-15 19:33:25 -0800317 // boost::bind(&SecPolicySync::onIntroCertInterest, this, _1, _2, _3, _4),
318 // boost::bind(&SecPolicySync::onIntroCertRegisterFailed, this, _1));
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800319 // }
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 Yu5e0af3e2014-01-15 19:33:25 -0800336SecPolicySync::onIntroCertVerifyFailed(const shared_ptr<Data>& introCertificateData,
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800337 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 Yu5e0af3e2014-01-15 19:33:25 -0800356 OnVerified onRecursiveVerified = boost::bind(&SecPolicySync::onIntroCertVerified,
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800357 this,
358 _1,
359 forIntroducer,
360 originalData,
361 onVerified,
362 onVerifyFailed);
363
Yingdi Yu5e0af3e2014-01-15 19:33:25 -0800364 OnVerifyFailed onRecursiveVerifyFailed = boost::bind(&SecPolicySync::onIntroCertVerifyFailed,
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800365 this,
366 _1,
367 interestPrefixName,
368 forIntroducer,
369 introNameList,
370 nextIntroducerIndex + 1,
371 originalData,
372 onVerified,
373 onVerifyFailed);
374
375 m_face->expressInterest(*interest,
Yingdi Yu5e0af3e2014-01-15 19:33:25 -0800376 boost::bind(&SecPolicySync::onIntroCertData,
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800377 this,
378 _1,
379 _2,
380 m_stepLimit-1,
381 onRecursiveVerified,
382 onRecursiveVerifyFailed,
383 originalData,
384 onVerifyFailed),
Yingdi Yu5e0af3e2014-01-15 19:33:25 -0800385 boost::bind(&SecPolicySync::onIntroCertTimeout,
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800386 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 Yu5e0af3e2014-01-15 19:33:25 -0800397SecPolicySync::onIntroCertData(const shared_ptr<const ndn::Interest> &interest,
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800398 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_,
Yingdi Yu5e0af3e2014-01-15 19:33:25 -0800409 boost::bind(&SecPolicySync::onIntroCertData,
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800410 this,
411 _1,
412 _2,
413 nextStep->stepCount_,
414 nextStep->onVerified_,
415 nextStep->onVerifyFailed_,
416 introCertificateData,
417 onRecursiveVerifyFailed),
Yingdi Yu5e0af3e2014-01-15 19:33:25 -0800418 boost::bind(&SecPolicySync::onIntroCertTimeout,
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800419 this,
420 _1,
421 nextStep->retry_,
422 nextStep->stepCount_,
423 nextStep->onVerified_,
424 nextStep->onVerifyFailed_,
425 introCertificateData,
426 onRecursiveVerifyFailed));
427}
428
429void
Yingdi Yu5e0af3e2014-01-15 19:33:25 -0800430SecPolicySync::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,
Yingdi Yu5e0af3e2014-01-15 19:33:25 -0800441 boost::bind(&SecPolicySync::onIntroCertData,
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800442 this,
443 _1,
444 _2,
445 stepCount,
446 onRecursiveVerified,
447 onRecursiveVerifyFailed,
448 originalData,
449 onVerifyFailed),
Yingdi Yu5e0af3e2014-01-15 19:33:25 -0800450 boost::bind(&SecPolicySync::onIntroCertTimeout,
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800451 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}