Yingdi Yu | 53b8a9c | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 1 | /* -*- 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-item.h" |
| 12 | #include "exception.h" |
| 13 | |
| 14 | #include <ndn.cxx/fields/signature-sha256-with-rsa.h> |
| 15 | |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 16 | #include "logging.h" |
| 17 | |
Yingdi Yu | 53b8a9c | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 18 | using namespace std; |
| 19 | using namespace ndn; |
| 20 | using namespace ndn::security; |
| 21 | |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 22 | INIT_LOGGER("ContactItem"); |
| 23 | |
Yingdi Yu | 53b8a9c | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 24 | ContactItem::ContactItem(const EndorseCertificate& selfEndorseCertificate, |
| 25 | const string& alias) |
| 26 | : m_selfEndorseCertificate(selfEndorseCertificate) |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame^] | 27 | , m_isIntroducer(false) |
Yingdi Yu | 53b8a9c | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 28 | { |
| 29 | Name endorsedkeyName = selfEndorseCertificate.getPublicKeyName(); |
| 30 | Ptr<const signature::Sha256WithRsa> endorseSig = boost::dynamic_pointer_cast<const signature::Sha256WithRsa>(selfEndorseCertificate.getSignature()); |
| 31 | const Name& signingKeyName = endorseSig->getKeyLocator().getKeyName(); |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 32 | |
| 33 | int i = 0; |
| 34 | int j = -1; |
| 35 | string keyString("KEY"); |
| 36 | string idString("ID-CERT"); |
| 37 | for(; i < signingKeyName.size(); i++) |
| 38 | { |
| 39 | if(keyString == signingKeyName.get(i).toUri()) |
| 40 | j = i; |
| 41 | if(idString == signingKeyName.get(i).toUri()) |
| 42 | break; |
| 43 | } |
Yingdi Yu | 53b8a9c | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 44 | |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 45 | if(i >= signingKeyName.size() || j < 0) |
| 46 | throw LnException("Wrong name!"); |
| 47 | |
| 48 | Name subName = signingKeyName.getSubName(0, j); |
| 49 | subName.append(signingKeyName.getSubName(j+1, i-j-1)); |
| 50 | |
| 51 | |
| 52 | |
| 53 | // _LOG_DEBUG("endorsedkeyName " << endorsedkeyName.toUri()); |
| 54 | // _LOG_DEBUG("subKeyName " << subName.toUri()); |
| 55 | |
| 56 | if(endorsedkeyName != subName) |
Yingdi Yu | 53b8a9c | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 57 | throw LnException("not a self-claimed"); |
| 58 | |
| 59 | m_namespace = endorsedkeyName.getSubName(0, endorsedkeyName.size() - 1); |
| 60 | m_alias = alias.empty() ? m_namespace.toUri() : alias; |
| 61 | |
| 62 | Ptr<ProfileData> profileData = selfEndorseCertificate.getProfileData(); |
| 63 | Ptr<const Blob> nameBlob = profileData->getProfile().getProfileEntry("name"); |
| 64 | m_name = string(nameBlob->buf(), nameBlob->size()); |
| 65 | Ptr<const Blob> institutionBlob = profileData->getProfile().getProfileEntry("institution"); |
| 66 | m_institution = string(institutionBlob->buf(), institutionBlob->size()); |
| 67 | } |
| 68 | |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame^] | 69 | ContactItem::ContactItem(const ContactItem& contactItem) |
| 70 | : m_selfEndorseCertificate(contactItem.m_selfEndorseCertificate) |
| 71 | , m_namespace(contactItem.m_namespace) |
| 72 | , m_alias(contactItem.m_alias) |
| 73 | , m_name(contactItem.m_name) |
| 74 | , m_institution(contactItem.m_institution) |
| 75 | , m_isIntroducer(false) |
| 76 | {} |
| 77 | |