blob: de3a9ca2e0dcc10b0af2d67c268e74db8c4e2c21 [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);
188 Name keyName = identityCertificate.getPublicKeyName();
189 Profile profile(keyName.getPrefix(keyName.size()-1),
190 keyName.get(-2).toUri(),
191 keyName.getPrefix(keyName.size()-2).toUri());
192
193 Ptr<ProfileData> profileData = Ptr<ProfileData>(new ProfileData(keyName.getPrefix(keyName.size()-1),
194 profile));
195
196 Ptr<IdentityManager> identityManager = m_keychain->getIdentityManager();
197 Name certificateName = identityManager->getDefaultCertificateName ();
198 identityManager->signByCertificate(*profileData, certificateName);
199
200 EndorseCertificate endorseCertificate(identityCertificate, profileData);
201
202 identityManager->signByCertificate(endorseCertificate, certificateName);
203
204 emit contactKeyFetched (endorseCertificate);
205}
206
207void
208ContactManager::onKeyUnverified(Ptr<Data> data, const Name& identity)
209{ emit contactKeyFetchFailed (identity); }
210
211void
212ContactManager::onKeyTimeout(Ptr<Closure> closure, Ptr<Interest> interest, const Name& identity, int retry)
213{ emit contactKeyFetchFailed(identity); }
214
215void
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700216ContactManager::updateProfileData(const Name& identity)
217{
Yingdi Yued8cfc42013-11-01 17:37:51 -0700218 _LOG_DEBUG("updateProfileData: " << identity.toUri());
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700219 // Get current profile;
220 Ptr<Profile> newProfile = m_contactStorage->getSelfProfile(identity);
221 if(NULL == newProfile)
222 return;
223 Ptr<Blob> newProfileBlob = newProfile->toDerBlob();
224
225 // Check if profile exists
226 Ptr<Blob> profileDataBlob = m_contactStorage->getSelfEndorseCertificate(identity);
227 if(NULL != profileDataBlob)
228 {
229 Ptr<Data> plainData = Data::decodeFromWire(profileDataBlob);
230 EndorseCertificate oldEndorseCertificate(*plainData);
231 // _LOG_DEBUG("Certificate converted!");
232 const Blob& oldProfileBlob = oldEndorseCertificate.getProfileData()->content();
233
234 if(oldProfileBlob == *newProfileBlob)
235 return;
236
237 Ptr<EndorseCertificate> newEndorseCertificate = getSignedSelfEndorseCertificate(identity, *newProfile);
238 // _LOG_DEBUG("Signing DONE!");
239 if(NULL == newEndorseCertificate)
240 return;
Yingdi Yu590fa5d2013-10-18 18:35:09 -0700241 _LOG_DEBUG("About to update");
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700242 m_contactStorage->updateSelfEndorseCertificate(newEndorseCertificate, identity);
243
244 publishSelfEndorseCertificateInDNS(newEndorseCertificate);
245 }
246 else
247 {
248 Ptr<EndorseCertificate> newEndorseCertificate = getSignedSelfEndorseCertificate(identity, *newProfile);
249 // _LOG_DEBUG("Signing DONE!");
250 if(NULL == newEndorseCertificate)
251 return;
Yingdi Yu590fa5d2013-10-18 18:35:09 -0700252 _LOG_DEBUG("About to Insert");
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700253 m_contactStorage->addSelfEndorseCertificate(newEndorseCertificate, identity);
254
255 publishSelfEndorseCertificateInDNS(newEndorseCertificate);
256 }
257}
258
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800259void
260ContactManager::updateEndorseCertificate(const ndn::Name& identity, const ndn::Name& signerIdentity)
261{
262 Ptr<Blob> oldEndorseCertificateBlob = m_contactStorage->getEndorseCertificate(identity);
263 Ptr<EndorseCertificate> newEndorseCertificate = generateEndorseCertificate(identity, signerIdentity);
264 if(NULL != oldEndorseCertificateBlob)
265 {
266 Ptr<Data> plainData = Data::decodeFromWire(oldEndorseCertificateBlob);
267 EndorseCertificate oldEndorseCertificate(*plainData);
268 const Blob& oldEndorseContent = oldEndorseCertificate.content();
269 const Blob& newEndorseContent = newEndorseCertificate->content();
270 if(oldEndorseContent == newEndorseContent)
271 return;
272 }
273 else
274 {
275 if(NULL == newEndorseCertificate)
276 return;
277 }
278 m_contactStorage->addEndorseCertificate(newEndorseCertificate, identity);
279 publishEndorseCertificateInDNS(newEndorseCertificate, signerIdentity);
280}
281
282Ptr<EndorseCertificate>
283ContactManager::generateEndorseCertificate(const Name& identity, const Name& signerIdentity)
284{
285 Ptr<ContactItem> contact = getContact(identity);
286
287 Ptr<IdentityManager> identityManager = m_keychain->getIdentityManager();
288 Name signerKeyName = identityManager->getDefaultKeyNameForIdentity(signerIdentity);
289 Name signerCertName = identityManager->getDefaultCertificateNameByIdentity(signerIdentity);
290
291 vector<string> endorseList = m_contactStorage->getEndorseList(identity);
292
293 Ptr<EndorseCertificate> cert = Ptr<EndorseCertificate>(new EndorseCertificate(contact->getSelfEndorseCertificate(), signerKeyName, endorseList));
294 identityManager->signByCertificate(*cert, signerCertName);
295
296 return cert;
297}
298
Yingdi Yu79c25a22013-10-21 13:38:38 -0700299vector<Ptr<ContactItem> >
300ContactManager::getContactItemList()
Yingdi Yu813d4e92013-11-03 16:22:05 -0800301{ return m_contactStorage->getAllContacts(); }
Yingdi Yu79c25a22013-10-21 13:38:38 -0700302
Yingdi Yud40226b2013-10-23 14:05:12 -0700303Ptr<ContactItem>
304ContactManager::getContact(const ndn::Name& contactNamespace)
Yingdi Yu813d4e92013-11-03 16:22:05 -0800305{ return m_contactStorage->getContact(contactNamespace); }
Yingdi Yud40226b2013-10-23 14:05:12 -0700306
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700307Ptr<EndorseCertificate>
308ContactManager::getSignedSelfEndorseCertificate(const Name& identity,
309 const Profile& profile)
310{
311 Ptr<IdentityManager> identityManager = m_keychain->getIdentityManager();
312 Name certificateName = identityManager->getDefaultCertificateNameByIdentity(identity);
313 if(0 == certificateName.size())
314 return NULL;
315
316 Ptr<ProfileData> profileData = Ptr<ProfileData>(new ProfileData(identity, profile));
317 identityManager->signByCertificate(*profileData, certificateName);
318
Yingdi Yued8cfc42013-11-01 17:37:51 -0700319 Ptr<security::IdentityCertificate> signingCert = identityManager->getCertificate(certificateName);
320 Name signingKeyName = security::IdentityCertificate::certificateNameToPublicKeyName(signingCert->getName(), true);
321
322 Ptr<security::IdentityCertificate> kskCert;
323 if(signingKeyName.get(-1).toUri().substr(0,4) == string("dsk-"))
324 {
325 Ptr<const signature::Sha256WithRsa> dskCertSig = DynamicCast<const signature::Sha256WithRsa>(signingCert->getSignature());
326 // HACK! KSK certificate should be retrieved from network.
327 _LOG_DEBUG("keyLocator: " << dskCertSig->getKeyLocator().getKeyName());
328 Name keyName = security::IdentityCertificate::certificateNameToPublicKeyName(dskCertSig->getKeyLocator().getKeyName());
329 _LOG_DEBUG("keyName: " << keyName.toUri());
330 Name kskCertName = identityManager->getPublicStorage()->getDefaultCertificateNameForKey(keyName);
331 _LOG_DEBUG("ksk cert name: " << kskCertName);
332 kskCert = identityManager->getCertificate(kskCertName);
333
334 }
335 else
336 {
337 kskCert = signingCert;
338 _LOG_DEBUG("ksk cert name: " << kskCert->getName().toUri());
339 }
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700340
341 vector<string> endorseList;
342 Profile::const_iterator it = profile.begin();
343 for(; it != profile.end(); it++)
344 endorseList.push_back(it->first);
345
346 Ptr<EndorseCertificate> selfEndorseCertificate = Ptr<EndorseCertificate>(new EndorseCertificate(*kskCert,
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700347 profileData,
348 endorseList));
349 identityManager->signByCertificate(*selfEndorseCertificate, kskCert->getName());
350
351 return selfEndorseCertificate;
352}
353
354
355void
356ContactManager::onDnsSelfEndorseCertificateVerified(Ptr<Data> data, const Name& identity)
357{
Yingdi Yuc29fb982013-10-20 19:43:10 -0700358 Ptr<Blob> dataContentBlob = Ptr<Blob>(new Blob(data->content().buf(), data->content().size()));
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700359
Yingdi Yuc29fb982013-10-20 19:43:10 -0700360 Ptr<Data> plainData = Data::decodeFromWire(dataContentBlob);
361
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700362 Ptr<EndorseCertificate> selfEndorseCertificate = Ptr<EndorseCertificate>(new EndorseCertificate(*plainData));
Yingdi Yuc29fb982013-10-20 19:43:10 -0700363
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700364 const security::Publickey& ksk = selfEndorseCertificate->getPublicKeyInfo();
Yingdi Yuc29fb982013-10-20 19:43:10 -0700365
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700366 if(security::PolicyManager::verifySignature(*plainData, ksk))
Yingdi Yuc29fb982013-10-20 19:43:10 -0700367 {
Yingdi Yu79c25a22013-10-21 13:38:38 -0700368 // Profile profile = selfEndorseCertificate->getProfileData()->getProfile();
369 // Profile::const_iterator it = profile.getEntries().begin();
370 // it++;
371 // _LOG_DEBUG("Entry Size: " << it->first);
372
Yingdi Yuc29fb982013-10-20 19:43:10 -0700373 emit contactFetched (*selfEndorseCertificate);
374 }
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700375 else
Yingdi Yuc29fb982013-10-20 19:43:10 -0700376 {
377 emit contactFetchFailed (identity);
378 }
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700379}
380
381void
382ContactManager::onDnsSelfEndorseCertificateUnverified(Ptr<Data> data, const Name& identity)
383{ emit contactFetchFailed (identity); }
384
385void
386ContactManager::onDnsSelfEndorseCertificateTimeout(Ptr<Closure> closure, Ptr<Interest> interest, const Name& identity, int retry)
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800387{ emit contactFetchFailed(identity); }
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700388
389void
390ContactManager::publishSelfEndorseCertificateInDNS(Ptr<EndorseCertificate> selfEndorseCertificate)
391{
392 Ptr<Data> data = Ptr<Data>::Create();
393
394 Name keyName = selfEndorseCertificate->getPublicKeyName();
395 Name identity = keyName.getSubName(0, keyName.size()-1);
396
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700397
398 Name dnsName = identity;
Yingdi Yu42f66462013-10-31 17:38:22 -0700399 dnsName.append("DNS").append("PROFILE").appendVersion();
Yingdi Yuc29fb982013-10-20 19:43:10 -0700400
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700401 data->setName(dnsName);
402 Ptr<Blob> blob = selfEndorseCertificate->encodeToWire();
Yingdi Yuc29fb982013-10-20 19:43:10 -0700403
404 // string encoded;
405 // CryptoPP::StringSource ss(reinterpret_cast<const unsigned char *>(blob->buf()), blob->size(), true,
406 // new CryptoPP::Base64Encoder(new CryptoPP::StringSink(encoded), false));
407
408 // Content content(encoded.c_str(), encoded.size());
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700409 Content content(blob->buf(), blob->size());
410 data->setContent(content);
411
412 m_keychain->signByIdentity(*data, identity);
Yingdi Yu590fa5d2013-10-18 18:35:09 -0700413
414 m_dnsStorage->updateDnsSelfProfileData(*data, identity);
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700415
416 Ptr<Blob> dnsBlob = data->encodeToWire();
417
Yingdi Yuc4d08d22013-10-23 23:07:29 -0700418 m_wrapper->putToNdnd(*dnsBlob);
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700419}
420
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800421void
422ContactManager::publishEndorseCertificateInDNS(Ptr<EndorseCertificate> endorseCertificate, const Name& signerIdentity)
423{
424 Ptr<Data> data = Ptr<Data>::Create();
425
426 Name keyName = endorseCertificate->getPublicKeyName();
427 Name endorsee = keyName.getSubName(0, keyName.size()-1);
428
429
430 Name dnsName = signerIdentity;
431 dnsName.append("DNS").append(endorsee).append("ENDORSEE").appendVersion();
432
433 data->setName(dnsName);
434 Ptr<Blob> blob = endorseCertificate->encodeToWire();
435
436 Content content(blob->buf(), blob->size());
437 data->setContent(content);
438
439 Name signCertName = m_keychain->getIdentityManager()->getDefaultCertificateNameByIdentity(signerIdentity);
440 m_keychain->getIdentityManager()->signByCertificate(*data, signCertName);
441
442 m_dnsStorage->updateDnsEndorseOthers(*data, signerIdentity, endorsee);
443
444 Ptr<Blob> dnsBlob = data->encodeToWire();
445
446 m_wrapper->putToNdnd(*dnsBlob);
447}
448
449void
450ContactManager::publishEndorsedDataInDns(const Name& identity)
451{
452 Ptr<Data> data = Ptr<Data>::Create();
453
454 Name dnsName = identity;
455 dnsName.append("DNS").append("ENDORSED").appendVersion();
456 data->setName(dnsName);
457
458 Ptr<vector<Blob> > collectEndorseList = m_contactStorage->getCollectEndorseList(identity);
459
460 Ptr<der::DerSequence> root = Ptr<der::DerSequence>::Create();
461
462 vector<Blob>::const_iterator it = collectEndorseList->begin();
463 for(; it != collectEndorseList->end(); it++)
464 {
465 Ptr<der::DerOctetString> entry = Ptr<der::DerOctetString>(new der::DerOctetString(*it));
466 root->addChild(entry);
467 }
468
469 blob_stream blobStream;
470 OutputIterator & start = reinterpret_cast<OutputIterator &> (blobStream);
471 root->encode(start);
472
473 Content content(blobStream.buf()->buf(), blobStream.buf()->size());
474 data->setContent(content);
475
476 Name signCertName = m_keychain->getIdentityManager()->getDefaultCertificateNameByIdentity(identity);
477 m_keychain->getIdentityManager()->signByCertificate(*data, signCertName);
478
479 m_dnsStorage->updateDnsOthersEndorse(*data, identity);
480
481 Ptr<Blob> dnsBlob = data->encodeToWire();
482
483 m_wrapper->putToNdnd(*dnsBlob);
484}
485
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700486
487#if WAF
488#include "contact-manager.moc"
489#include "contact-manager.cpp.moc"
490#endif