blob: b737daa1ecc1b562176ed0e50a619839aa60c27c [file] [log] [blame]
Yingdi Yu53b8a9c2013-10-14 09:36: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
11#include "contact-item.h"
12#include "exception.h"
13
14#include <ndn.cxx/fields/signature-sha256-with-rsa.h>
15
Yingdi Yu79c25a22013-10-21 13:38:38 -070016#include "logging.h"
17
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070018using namespace std;
19using namespace ndn;
20using namespace ndn::security;
21
Yingdi Yu79c25a22013-10-21 13:38:38 -070022INIT_LOGGER("ContactItem");
23
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070024ContactItem::ContactItem(const EndorseCertificate& selfEndorseCertificate,
25 const string& alias)
26 : m_selfEndorseCertificate(selfEndorseCertificate)
Yingdi Yua50c3252013-11-03 15:05:26 -080027 , m_isIntroducer(false)
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070028{
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 Yu79c25a22013-10-21 13:38:38 -070032
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 Yu53b8a9c2013-10-14 09:36:31 -070044
Yingdi Yu79c25a22013-10-21 13:38:38 -070045 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 Yu53b8a9c2013-10-14 09:36:31 -070057 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 Yua50c3252013-11-03 15:05:26 -080069ContactItem::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