blob: 71b9ea25b58fa63e54583d988f323fac729c2344 [file] [log] [blame]
Yingdi Yu0b82a4e2013-10-18 11:29:25 -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
11#include "contact-manager.h"
12
Yingdi Yuaa8d7692013-10-18 17:05:02 -070013#ifndef Q_MOC_RUN
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070014#include <ndn.cxx/wrapper/wrapper.h>
15#include <ndn.cxx/security/keychain.h>
16#include <ndn.cxx/security/identity/basic-identity-storage.h>
17#include <ndn.cxx/security/identity/osx-privatekey-storage.h>
18#include <ndn.cxx/security/policy/simple-policy-manager.h>
19#include <ndn.cxx/security/policy/identity-policy-rule.h>
20#include <ndn.cxx/security/cache/ttl-certificate-cache.h>
21#include <ndn.cxx/security/encryption/basic-encryption-manager.h>
Yingdi Yu8dacdf22013-11-05 23:06:43 -080022#include <ndn.cxx/helpers/der/der.h>
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070023#include <fstream>
Yingdi Yu590fa5d2013-10-18 18:35:09 -070024#include "logging.h"
Yingdi Yuaa8d7692013-10-18 17:05:02 -070025#endif
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070026
27using namespace ndn;
28using namespace ndn::security;
29
Yingdi Yu590fa5d2013-10-18 18:35:09 -070030INIT_LOGGER("ContactManager");
31
Yingdi Yuaa8d7692013-10-18 17:05:02 -070032ContactManager::ContactManager(Ptr<ContactStorage> contactStorage,
Yingdi Yu590fa5d2013-10-18 18:35:09 -070033 Ptr<DnsStorage> dnsStorage,
34 QObject* parent)
35 : QObject(parent)
36 , m_contactStorage(contactStorage)
Yingdi Yuaa8d7692013-10-18 17:05:02 -070037 , m_dnsStorage(dnsStorage)
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070038{
Yingdi Yuaa8d7692013-10-18 17:05:02 -070039 setKeychain();
40
41 m_wrapper = Ptr<Wrapper>(new Wrapper(m_keychain));
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070042}
43
44ContactManager::~ContactManager()
45{
46}
47
Yingdi Yuaa8d7692013-10-18 17:05:02 -070048void
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070049ContactManager::setKeychain()
50{
51 Ptr<OSXPrivatekeyStorage> privateStorage = Ptr<OSXPrivatekeyStorage>::Create();
52 Ptr<IdentityManager> identityManager = Ptr<IdentityManager>(new IdentityManager(Ptr<BasicIdentityStorage>::Create(), privateStorage));
53 Ptr<TTLCertificateCache> certificateCache = Ptr<TTLCertificateCache>(new TTLCertificateCache());
54 Ptr<SimplePolicyManager> policyManager = Ptr<SimplePolicyManager>(new SimplePolicyManager(10, certificateCache));
55 Ptr<EncryptionManager> encryptionManager = Ptr<EncryptionManager>(new BasicEncryptionManager(privateStorage, "/tmp/encryption.db"));
56 Ptr<Keychain> keychain = Ptr<Keychain>(new Keychain(identityManager, policyManager, encryptionManager));
57
Yingdi Yu8dacdf22013-11-05 23:06:43 -080058 policyManager->addVerificationPolicyRule(Ptr<IdentityPolicyRule>(new IdentityPolicyRule("^([^<DNS>]*)<DNS><ENDORSED>",
59 "^([^<KEY>]*)<KEY>(<>*)[<ksk-.*><dsk-.*>]<ID-CERT>$",
60 "==", "\\1", "\\1\\2", true)));
Yingdi Yuaa8d7692013-10-18 17:05:02 -070061 policyManager->addVerificationPolicyRule(Ptr<IdentityPolicyRule>(new IdentityPolicyRule("^([^<DNS>]*)<DNS><PROFILE>",
Yingdi Yued8cfc42013-11-01 17:37:51 -070062 "^([^<KEY>]*)<KEY>(<>*)[<ksk-.*><dsk-.*>]<ID-CERT>$",
Yingdi Yuaa8d7692013-10-18 17:05:02 -070063 "==", "\\1", "\\1\\2", true)));
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070064 policyManager->addVerificationPolicyRule(Ptr<IdentityPolicyRule>(new IdentityPolicyRule("^([^<PROFILE-CERT>]*)<PROFILE-CERT>",
Yingdi Yued8cfc42013-11-01 17:37:51 -070065 "^([^<KEY>]*)<KEY>(<>*<ksk-.*>)<ID-CERT>$",
Yingdi Yuaa8d7692013-10-18 17:05:02 -070066 "==", "\\1", "\\1\\2", true)));
Yingdi Yu42f66462013-10-31 17:38:22 -070067 policyManager->addVerificationPolicyRule(Ptr<IdentityPolicyRule>(new IdentityPolicyRule("^([^<KEY>]*)<KEY>(<>*)<ksk-.*><ID-CERT>",
Yingdi Yued8cfc42013-11-01 17:37:51 -070068 "^([^<KEY>]*)<KEY><dsk-.*><ID-CERT>$",
Yingdi Yuaa8d7692013-10-18 17:05:02 -070069 ">", "\\1\\2", "\\1", true)));
Yingdi Yu42f66462013-10-31 17:38:22 -070070 policyManager->addVerificationPolicyRule(Ptr<IdentityPolicyRule>(new IdentityPolicyRule("^([^<KEY>]*)<KEY><dsk-.*><ID-CERT>",
Yingdi Yued8cfc42013-11-01 17:37:51 -070071 "^([^<KEY>]*)<KEY>(<>*)<ksk-.*><ID-CERT>$",
Yingdi Yuaa8d7692013-10-18 17:05:02 -070072 "==", "\\1", "\\1\\2", true)));
73
74 policyManager->addSigningPolicyRule(Ptr<IdentityPolicyRule>(new IdentityPolicyRule("^([^<DNS>]*)<DNS><PROFILE>",
75 "^([^<KEY>]*)<KEY>(<>*)<><ID-CERT>",
76 "==", "\\1", "\\1\\2", true)));
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070077
78 ifstream is ("trust-anchor.data", ios::binary);
79 is.seekg (0, ios::end);
80 ifstream::pos_type size = is.tellg();
81 char * memblock = new char [size];
82 is.seekg (0, ios::beg);
83 is.read (memblock, size);
84 is.close();
85
86 Ptr<Blob> readBlob = Ptr<Blob>(new Blob(memblock, size));
87 Ptr<Data> readData = Data::decodeFromWire (readBlob);
88 Ptr<IdentityCertificate> anchor = Ptr<IdentityCertificate>(new IdentityCertificate(*readData));
89 policyManager->addTrustAnchor(anchor);
90
91 delete memblock;
92
Yingdi Yuaa8d7692013-10-18 17:05:02 -070093 m_keychain = keychain;
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070094}
Yingdi Yuaa8d7692013-10-18 17:05:02 -070095
96
97void
98ContactManager::fetchSelfEndorseCertificate(const ndn::Name& identity)
99{
100 Name interestName = identity;
101 interestName.append("DNS").append("PROFILE");
102
103 Ptr<Interest> interestPtr = Ptr<Interest>(new Interest(interestName));
Yingdi Yu42f66462013-10-31 17:38:22 -0700104 interestPtr->setChildSelector(Interest::CHILD_RIGHT);
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700105 Ptr<Closure> closure = Ptr<Closure> (new Closure(boost::bind(&ContactManager::onDnsSelfEndorseCertificateVerified,
106 this,
107 _1,
108 identity),
109 boost::bind(&ContactManager::onDnsSelfEndorseCertificateTimeout,
110 this,
111 _1,
112 _2,
113 identity,
114 0),
115 boost::bind(&ContactManager::onDnsSelfEndorseCertificateUnverified,
116 this,
117 _1,
118 identity)));
119 m_wrapper->sendInterest(interestPtr, closure);
120}
121
122void
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800123ContactManager::fetchCollectEndorse(const ndn::Name& identity)
124{
125 Name interestName = identity;
126 interestName.append("DNS").append("ENDORSED");
127
128 Ptr<Interest> interestPtr = Ptr<Interest>(new Interest(interestName));
129 interestPtr->setChildSelector(Interest::CHILD_RIGHT);
130 interestPtr->setInterestLifetime(1);
131 Ptr<Closure> closure = Ptr<Closure> (new Closure(boost::bind(&ContactManager::onDnsCollectEndorseVerified,
132 this,
133 _1,
134 identity),
135 boost::bind(&ContactManager::onDnsCollectEndorseTimeout,
136 this,
137 _1,
138 _2,
139 identity,
140 0),
141 boost::bind(&ContactManager::onDnsCollectEndorseUnverified,
142 this,
143 _1,
144 identity)));
145 m_wrapper->sendInterest(interestPtr, closure);
146}
147
148void
149ContactManager::fetchKey(const ndn::Name& certName)
150{
151 Name interestName = certName;
152
153 Ptr<Interest> interestPtr = Ptr<Interest>(new Interest(interestName));
154 interestPtr->setChildSelector(Interest::CHILD_RIGHT);
155 Ptr<Closure> closure = Ptr<Closure> (new Closure(boost::bind(&ContactManager::onKeyVerified,
156 this,
157 _1,
158 certName),
159 boost::bind(&ContactManager::onKeyTimeout,
160 this,
161 _1,
162 _2,
163 certName,
164 0),
165 boost::bind(&ContactManager::onKeyUnverified,
166 this,
167 _1,
168 certName)));
169 m_wrapper->sendInterest(interestPtr, closure);
170}
171
172void
173ContactManager::onDnsCollectEndorseVerified(Ptr<Data> data, const Name& identity)
174{ emit collectEndorseFetched (*data); }
175
176void
177ContactManager::onDnsCollectEndorseTimeout(Ptr<Closure> closure, Ptr<Interest> interest, const Name& identity, int retry)
178{ emit collectEndorseFetchFailed (identity); }
179
180void
181ContactManager::onDnsCollectEndorseUnverified(Ptr<Data> data, const Name& identity)
182{ emit collectEndorseFetchFailed (identity); }
183
184void
185ContactManager::onKeyVerified(Ptr<Data> data, const Name& identity)
186{
187 IdentityCertificate identityCertificate(*data);
Yingdi Yue9ea5c92013-11-06 18:42:34 -0800188
189 Ptr<ProfileData> profileData = Ptr<ProfileData>(new ProfileData(Profile(identityCertificate)));
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800190
191 Ptr<IdentityManager> identityManager = m_keychain->getIdentityManager();
192 Name certificateName = identityManager->getDefaultCertificateName ();
193 identityManager->signByCertificate(*profileData, certificateName);
194
195 EndorseCertificate endorseCertificate(identityCertificate, profileData);
196
197 identityManager->signByCertificate(endorseCertificate, certificateName);
198
199 emit contactKeyFetched (endorseCertificate);
200}
201
202void
203ContactManager::onKeyUnverified(Ptr<Data> data, const Name& identity)
204{ emit contactKeyFetchFailed (identity); }
205
206void
207ContactManager::onKeyTimeout(Ptr<Closure> closure, Ptr<Interest> interest, const Name& identity, int retry)
208{ emit contactKeyFetchFailed(identity); }
209
210void
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700211ContactManager::updateProfileData(const Name& identity)
212{
Yingdi Yued8cfc42013-11-01 17:37:51 -0700213 _LOG_DEBUG("updateProfileData: " << identity.toUri());
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700214 // Get current profile;
215 Ptr<Profile> newProfile = m_contactStorage->getSelfProfile(identity);
216 if(NULL == newProfile)
217 return;
218 Ptr<Blob> newProfileBlob = newProfile->toDerBlob();
219
220 // Check if profile exists
221 Ptr<Blob> profileDataBlob = m_contactStorage->getSelfEndorseCertificate(identity);
222 if(NULL != profileDataBlob)
223 {
224 Ptr<Data> plainData = Data::decodeFromWire(profileDataBlob);
225 EndorseCertificate oldEndorseCertificate(*plainData);
226 // _LOG_DEBUG("Certificate converted!");
227 const Blob& oldProfileBlob = oldEndorseCertificate.getProfileData()->content();
228
229 if(oldProfileBlob == *newProfileBlob)
230 return;
231
232 Ptr<EndorseCertificate> newEndorseCertificate = getSignedSelfEndorseCertificate(identity, *newProfile);
233 // _LOG_DEBUG("Signing DONE!");
234 if(NULL == newEndorseCertificate)
235 return;
Yingdi Yu590fa5d2013-10-18 18:35:09 -0700236 _LOG_DEBUG("About to update");
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700237 m_contactStorage->updateSelfEndorseCertificate(newEndorseCertificate, identity);
238
239 publishSelfEndorseCertificateInDNS(newEndorseCertificate);
240 }
241 else
242 {
243 Ptr<EndorseCertificate> newEndorseCertificate = getSignedSelfEndorseCertificate(identity, *newProfile);
244 // _LOG_DEBUG("Signing DONE!");
245 if(NULL == newEndorseCertificate)
246 return;
Yingdi Yu590fa5d2013-10-18 18:35:09 -0700247 _LOG_DEBUG("About to Insert");
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700248 m_contactStorage->addSelfEndorseCertificate(newEndorseCertificate, identity);
249
250 publishSelfEndorseCertificateInDNS(newEndorseCertificate);
251 }
252}
253
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800254void
255ContactManager::updateEndorseCertificate(const ndn::Name& identity, const ndn::Name& signerIdentity)
256{
257 Ptr<Blob> oldEndorseCertificateBlob = m_contactStorage->getEndorseCertificate(identity);
258 Ptr<EndorseCertificate> newEndorseCertificate = generateEndorseCertificate(identity, signerIdentity);
259 if(NULL != oldEndorseCertificateBlob)
260 {
261 Ptr<Data> plainData = Data::decodeFromWire(oldEndorseCertificateBlob);
262 EndorseCertificate oldEndorseCertificate(*plainData);
263 const Blob& oldEndorseContent = oldEndorseCertificate.content();
264 const Blob& newEndorseContent = newEndorseCertificate->content();
265 if(oldEndorseContent == newEndorseContent)
266 return;
267 }
268 else
269 {
270 if(NULL == newEndorseCertificate)
271 return;
272 }
273 m_contactStorage->addEndorseCertificate(newEndorseCertificate, identity);
274 publishEndorseCertificateInDNS(newEndorseCertificate, signerIdentity);
275}
276
277Ptr<EndorseCertificate>
278ContactManager::generateEndorseCertificate(const Name& identity, const Name& signerIdentity)
279{
280 Ptr<ContactItem> contact = getContact(identity);
281
282 Ptr<IdentityManager> identityManager = m_keychain->getIdentityManager();
283 Name signerKeyName = identityManager->getDefaultKeyNameForIdentity(signerIdentity);
284 Name signerCertName = identityManager->getDefaultCertificateNameByIdentity(signerIdentity);
285
286 vector<string> endorseList = m_contactStorage->getEndorseList(identity);
287
288 Ptr<EndorseCertificate> cert = Ptr<EndorseCertificate>(new EndorseCertificate(contact->getSelfEndorseCertificate(), signerKeyName, endorseList));
289 identityManager->signByCertificate(*cert, signerCertName);
290
291 return cert;
292}
293
Yingdi Yu79c25a22013-10-21 13:38:38 -0700294vector<Ptr<ContactItem> >
295ContactManager::getContactItemList()
Yingdi Yu813d4e92013-11-03 16:22:05 -0800296{ return m_contactStorage->getAllContacts(); }
Yingdi Yu79c25a22013-10-21 13:38:38 -0700297
Yingdi Yud40226b2013-10-23 14:05:12 -0700298Ptr<ContactItem>
299ContactManager::getContact(const ndn::Name& contactNamespace)
Yingdi Yu813d4e92013-11-03 16:22:05 -0800300{ return m_contactStorage->getContact(contactNamespace); }
Yingdi Yud40226b2013-10-23 14:05:12 -0700301
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700302Ptr<EndorseCertificate>
303ContactManager::getSignedSelfEndorseCertificate(const Name& identity,
304 const Profile& profile)
305{
306 Ptr<IdentityManager> identityManager = m_keychain->getIdentityManager();
307 Name certificateName = identityManager->getDefaultCertificateNameByIdentity(identity);
308 if(0 == certificateName.size())
309 return NULL;
310
Yingdi Yue9ea5c92013-11-06 18:42:34 -0800311 Ptr<ProfileData> profileData = Ptr<ProfileData>(new ProfileData(profile));
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700312 identityManager->signByCertificate(*profileData, certificateName);
313
Yingdi Yued8cfc42013-11-01 17:37:51 -0700314 Ptr<security::IdentityCertificate> signingCert = identityManager->getCertificate(certificateName);
315 Name signingKeyName = security::IdentityCertificate::certificateNameToPublicKeyName(signingCert->getName(), true);
316
317 Ptr<security::IdentityCertificate> kskCert;
318 if(signingKeyName.get(-1).toUri().substr(0,4) == string("dsk-"))
319 {
320 Ptr<const signature::Sha256WithRsa> dskCertSig = DynamicCast<const signature::Sha256WithRsa>(signingCert->getSignature());
321 // HACK! KSK certificate should be retrieved from network.
322 _LOG_DEBUG("keyLocator: " << dskCertSig->getKeyLocator().getKeyName());
323 Name keyName = security::IdentityCertificate::certificateNameToPublicKeyName(dskCertSig->getKeyLocator().getKeyName());
324 _LOG_DEBUG("keyName: " << keyName.toUri());
325 Name kskCertName = identityManager->getPublicStorage()->getDefaultCertificateNameForKey(keyName);
326 _LOG_DEBUG("ksk cert name: " << kskCertName);
327 kskCert = identityManager->getCertificate(kskCertName);
328
329 }
330 else
331 {
332 kskCert = signingCert;
333 _LOG_DEBUG("ksk cert name: " << kskCert->getName().toUri());
334 }
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700335
336 vector<string> endorseList;
337 Profile::const_iterator it = profile.begin();
338 for(; it != profile.end(); it++)
339 endorseList.push_back(it->first);
340
341 Ptr<EndorseCertificate> selfEndorseCertificate = Ptr<EndorseCertificate>(new EndorseCertificate(*kskCert,
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700342 profileData,
343 endorseList));
344 identityManager->signByCertificate(*selfEndorseCertificate, kskCert->getName());
345
346 return selfEndorseCertificate;
347}
348
349
350void
351ContactManager::onDnsSelfEndorseCertificateVerified(Ptr<Data> data, const Name& identity)
352{
Yingdi Yuc29fb982013-10-20 19:43:10 -0700353 Ptr<Blob> dataContentBlob = Ptr<Blob>(new Blob(data->content().buf(), data->content().size()));
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700354
Yingdi Yuc29fb982013-10-20 19:43:10 -0700355 Ptr<Data> plainData = Data::decodeFromWire(dataContentBlob);
356
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700357 Ptr<EndorseCertificate> selfEndorseCertificate = Ptr<EndorseCertificate>(new EndorseCertificate(*plainData));
Yingdi Yuc29fb982013-10-20 19:43:10 -0700358
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700359 const security::Publickey& ksk = selfEndorseCertificate->getPublicKeyInfo();
Yingdi Yuc29fb982013-10-20 19:43:10 -0700360
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700361 if(security::PolicyManager::verifySignature(*plainData, ksk))
Yingdi Yuc29fb982013-10-20 19:43:10 -0700362 {
Yingdi Yu79c25a22013-10-21 13:38:38 -0700363 // Profile profile = selfEndorseCertificate->getProfileData()->getProfile();
364 // Profile::const_iterator it = profile.getEntries().begin();
365 // it++;
366 // _LOG_DEBUG("Entry Size: " << it->first);
367
Yingdi Yuc29fb982013-10-20 19:43:10 -0700368 emit contactFetched (*selfEndorseCertificate);
369 }
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700370 else
Yingdi Yuc29fb982013-10-20 19:43:10 -0700371 {
372 emit contactFetchFailed (identity);
373 }
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700374}
375
376void
377ContactManager::onDnsSelfEndorseCertificateUnverified(Ptr<Data> data, const Name& identity)
378{ emit contactFetchFailed (identity); }
379
380void
381ContactManager::onDnsSelfEndorseCertificateTimeout(Ptr<Closure> closure, Ptr<Interest> interest, const Name& identity, int retry)
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800382{ emit contactFetchFailed(identity); }
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700383
384void
385ContactManager::publishSelfEndorseCertificateInDNS(Ptr<EndorseCertificate> selfEndorseCertificate)
386{
387 Ptr<Data> data = Ptr<Data>::Create();
388
389 Name keyName = selfEndorseCertificate->getPublicKeyName();
390 Name identity = keyName.getSubName(0, keyName.size()-1);
391
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700392
393 Name dnsName = identity;
Yingdi Yu42f66462013-10-31 17:38:22 -0700394 dnsName.append("DNS").append("PROFILE").appendVersion();
Yingdi Yuc29fb982013-10-20 19:43:10 -0700395
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700396 data->setName(dnsName);
397 Ptr<Blob> blob = selfEndorseCertificate->encodeToWire();
Yingdi Yuc29fb982013-10-20 19:43:10 -0700398
399 // string encoded;
400 // CryptoPP::StringSource ss(reinterpret_cast<const unsigned char *>(blob->buf()), blob->size(), true,
401 // new CryptoPP::Base64Encoder(new CryptoPP::StringSink(encoded), false));
402
403 // Content content(encoded.c_str(), encoded.size());
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700404 Content content(blob->buf(), blob->size());
405 data->setContent(content);
406
407 m_keychain->signByIdentity(*data, identity);
Yingdi Yu590fa5d2013-10-18 18:35:09 -0700408
409 m_dnsStorage->updateDnsSelfProfileData(*data, identity);
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700410
411 Ptr<Blob> dnsBlob = data->encodeToWire();
412
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700413 m_wrapper->putToNdnd(*dnsBlob);
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700414}
415
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800416void
417ContactManager::publishEndorseCertificateInDNS(Ptr<EndorseCertificate> endorseCertificate, const Name& signerIdentity)
418{
419 Ptr<Data> data = Ptr<Data>::Create();
420
421 Name keyName = endorseCertificate->getPublicKeyName();
422 Name endorsee = keyName.getSubName(0, keyName.size()-1);
423
424
425 Name dnsName = signerIdentity;
426 dnsName.append("DNS").append(endorsee).append("ENDORSEE").appendVersion();
427
428 data->setName(dnsName);
429 Ptr<Blob> blob = endorseCertificate->encodeToWire();
430
431 Content content(blob->buf(), blob->size());
432 data->setContent(content);
433
434 Name signCertName = m_keychain->getIdentityManager()->getDefaultCertificateNameByIdentity(signerIdentity);
435 m_keychain->getIdentityManager()->signByCertificate(*data, signCertName);
436
437 m_dnsStorage->updateDnsEndorseOthers(*data, signerIdentity, endorsee);
438
439 Ptr<Blob> dnsBlob = data->encodeToWire();
440
441 m_wrapper->putToNdnd(*dnsBlob);
442}
443
444void
445ContactManager::publishEndorsedDataInDns(const Name& identity)
446{
447 Ptr<Data> data = Ptr<Data>::Create();
448
449 Name dnsName = identity;
450 dnsName.append("DNS").append("ENDORSED").appendVersion();
451 data->setName(dnsName);
452
453 Ptr<vector<Blob> > collectEndorseList = m_contactStorage->getCollectEndorseList(identity);
454
455 Ptr<der::DerSequence> root = Ptr<der::DerSequence>::Create();
456
457 vector<Blob>::const_iterator it = collectEndorseList->begin();
458 for(; it != collectEndorseList->end(); it++)
459 {
460 Ptr<der::DerOctetString> entry = Ptr<der::DerOctetString>(new der::DerOctetString(*it));
461 root->addChild(entry);
462 }
463
464 blob_stream blobStream;
465 OutputIterator & start = reinterpret_cast<OutputIterator &> (blobStream);
466 root->encode(start);
467
468 Content content(blobStream.buf()->buf(), blobStream.buf()->size());
469 data->setContent(content);
470
471 Name signCertName = m_keychain->getIdentityManager()->getDefaultCertificateNameByIdentity(identity);
472 m_keychain->getIdentityManager()->signByCertificate(*data, signCertName);
473
474 m_dnsStorage->updateDnsOthersEndorse(*data, identity);
475
476 Ptr<Blob> dnsBlob = data->encodeToWire();
477
478 m_wrapper->putToNdnd(*dnsBlob);
479}
480
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700481
482#if WAF
483#include "contact-manager.moc"
484#include "contact-manager.cpp.moc"
485#endif