Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -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-manager.h" |
| 12 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 13 | #ifndef Q_MOC_RUN |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 14 | #include <ndn.cxx/wrapper/wrapper.h> |
| 15 | #include <ndn.cxx/security/keychain.h> |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 16 | #include <ndn.cxx/security/policy/simple-policy-manager.h> |
| 17 | #include <ndn.cxx/security/policy/identity-policy-rule.h> |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 18 | #include <ndn.cxx/helpers/der/der.h> |
Yingdi Yu | 6a5b9f6 | 2013-11-06 23:00:21 -0800 | [diff] [blame] | 19 | #include <cryptopp/base64.h> |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 20 | #include <fstream> |
Yingdi Yu | 590fa5d | 2013-10-18 18:35:09 -0700 | [diff] [blame] | 21 | #include "logging.h" |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 22 | #endif |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 23 | |
| 24 | using namespace ndn; |
| 25 | using namespace ndn::security; |
| 26 | |
Yingdi Yu | 590fa5d | 2013-10-18 18:35:09 -0700 | [diff] [blame] | 27 | INIT_LOGGER("ContactManager"); |
| 28 | |
Yingdi Yu | b29f78c | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 29 | ContactManager::ContactManager(QObject* parent) |
Yingdi Yu | 590fa5d | 2013-10-18 18:35:09 -0700 | [diff] [blame] | 30 | : QObject(parent) |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 31 | { |
Yingdi Yu | b29f78c | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 32 | m_contactStorage = Ptr<ContactStorage>::Create(); |
| 33 | m_dnsStorage = Ptr<DnsStorage>::Create(); |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 34 | |
Yingdi Yu | b29f78c | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 35 | setKeychain(); |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | ContactManager::~ContactManager() |
| 39 | { |
| 40 | } |
| 41 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 42 | void |
Yingdi Yu | b29f78c | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 43 | ContactManager::setWrapper() |
| 44 | { |
| 45 | try{ |
| 46 | m_wrapper = Ptr<Wrapper>(new Wrapper(m_keychain)); |
| 47 | }catch(ndn::Error::ndnOperation& e){ |
Yingdi Yu | eb98f7d | 2013-11-10 01:34:57 -0800 | [diff] [blame] | 48 | emit noNdnConnection(QString::fromStdString("Cannot conect to ndnd!\nHave you started your ndnd?")); |
Yingdi Yu | b29f78c | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 49 | } |
| 50 | } |
| 51 | |
| 52 | void |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 53 | ContactManager::setKeychain() |
| 54 | { |
Yingdi Yu | 6a5b9f6 | 2013-11-06 23:00:21 -0800 | [diff] [blame] | 55 | Ptr<IdentityManager> identityManager = Ptr<IdentityManager>::Create(); |
| 56 | Ptr<SimplePolicyManager> policyManager = Ptr<SimplePolicyManager>::Create(); |
| 57 | |
| 58 | Ptr<Keychain> keychain = Ptr<Keychain>(new Keychain(identityManager, policyManager, NULL)); |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 59 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 60 | policyManager->addVerificationPolicyRule(Ptr<IdentityPolicyRule>(new IdentityPolicyRule("^([^<DNS>]*)<DNS><ENDORSED>", |
| 61 | "^([^<KEY>]*)<KEY>(<>*)[<ksk-.*><dsk-.*>]<ID-CERT>$", |
| 62 | "==", "\\1", "\\1\\2", true))); |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 63 | policyManager->addVerificationPolicyRule(Ptr<IdentityPolicyRule>(new IdentityPolicyRule("^([^<DNS>]*)<DNS><PROFILE>", |
Yingdi Yu | ed8cfc4 | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 64 | "^([^<KEY>]*)<KEY>(<>*)[<ksk-.*><dsk-.*>]<ID-CERT>$", |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 65 | "==", "\\1", "\\1\\2", true))); |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 66 | policyManager->addVerificationPolicyRule(Ptr<IdentityPolicyRule>(new IdentityPolicyRule("^([^<PROFILE-CERT>]*)<PROFILE-CERT>", |
Yingdi Yu | ed8cfc4 | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 67 | "^([^<KEY>]*)<KEY>(<>*<ksk-.*>)<ID-CERT>$", |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 68 | "==", "\\1", "\\1\\2", true))); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 69 | policyManager->addVerificationPolicyRule(Ptr<IdentityPolicyRule>(new IdentityPolicyRule("^([^<KEY>]*)<KEY>(<>*)<ksk-.*><ID-CERT>", |
Yingdi Yu | ed8cfc4 | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 70 | "^([^<KEY>]*)<KEY><dsk-.*><ID-CERT>$", |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 71 | ">", "\\1\\2", "\\1", true))); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 72 | policyManager->addVerificationPolicyRule(Ptr<IdentityPolicyRule>(new IdentityPolicyRule("^([^<KEY>]*)<KEY><dsk-.*><ID-CERT>", |
Yingdi Yu | ed8cfc4 | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 73 | "^([^<KEY>]*)<KEY>(<>*)<ksk-.*><ID-CERT>$", |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 74 | "==", "\\1", "\\1\\2", true))); |
Yingdi Yu | 8fb16a4 | 2013-11-10 18:35:09 -0800 | [diff] [blame^] | 75 | policyManager->addVerificationPolicyRule(Ptr<IdentityPolicyRule>(new IdentityPolicyRule("^(<>*)$", |
| 76 | "^([^<KEY>]*)<KEY>(<>*)<ksk-.*><ID-CERT>$", |
| 77 | ">", "\\1", "\\1\\2", true))); |
| 78 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 79 | |
| 80 | policyManager->addSigningPolicyRule(Ptr<IdentityPolicyRule>(new IdentityPolicyRule("^([^<DNS>]*)<DNS><PROFILE>", |
| 81 | "^([^<KEY>]*)<KEY>(<>*)<><ID-CERT>", |
| 82 | "==", "\\1", "\\1\\2", true))); |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 83 | |
Yingdi Yu | 8fb16a4 | 2013-11-10 18:35:09 -0800 | [diff] [blame^] | 84 | |
Yingdi Yu | 6a5b9f6 | 2013-11-06 23:00:21 -0800 | [diff] [blame] | 85 | const string TrustAnchor("BIICqgOyEIWlKzDI2xX2hdq5Azheu9IVyewcV4uM7ylfh67Y8MIxF3tDCTx5JgEn\ |
| 86 | HYMuCaYQm6XuaXTlVfDdWff/K7Xebq8IgGxjNBeU9eMf7Gy9iIMrRAOdBG0dBHmo\ |
| 87 | 67biGs8F+P1oh1FwKu/FN1AE9vh8HSOJ94PWmjO+6PvITFIXuI3QbcCz8rhvbsfb\ |
| 88 | 5X/DmfbJ8n8c4X3nVxrBm6fd4z8kOFOvvhgJImvqsow69Uy+38m8gJrmrcWMoPBJ\ |
| 89 | WsNLcEriZCt/Dlg7EqqVrIn6ukylKCvVrxA9vm/cEB74J/N+T0JyMRDnTLm17gpq\ |
| 90 | Gd75rhj+bLmpOMOBT7Nb27wUKq8gcXzeAADy+p1uZG4A+p1LRVkA+vVrc2stMTM4\ |
| 91 | MzMyNTcyMAD6vUlELUNFUlQA+q39PgurHgAAAaID4gKF5vjua9EIr3/Fn8k1AdSc\ |
| 92 | nEryjVDW3ikvYoSwjK7egTkAArq1BSc+C6sdAAHiAery+p1uZG4A+p1LRVkA+vVr\ |
| 93 | c2stMTM4MzMyNTcyMAD6vUlELUNFUlQAAAAAAAGaFr0wggFjMCIYDzIwMTMxMTAx\ |
| 94 | MTcxMTIyWhgPMjAxNDExMDExNzExMjJaMBkwFwYDVQQpExBORE4gVGVzdGJlZCBS\ |
| 95 | b290MIIBIDANBgkqhkiG9w0BAQEFAAOCAQ0AMIIBCAKCAQEA06x+elwzWCHa4I3b\ |
| 96 | yrYCMAIVxQpRVLuOXp0h+BS+5GNgMVPi7+40o4zSJG+kiU8CIH1mtj8RQAzBX9hF\ |
| 97 | I5VAyOC8nS8D8YOfBwt2yRDZPgt1E5PpyYUBiDYuq/zmJDL8xjxAlxrMzVOqD/uj\ |
| 98 | /vkkcBM/T1t9Q6p1CpRyq+GMRbV4EAHvH7MFb6bDrH9t8DHEg7NPUCaSQBrd7PvL\ |
| 99 | 72P+QdiNH9zs/EiVzAkeMG4iniSXLuYM3z0gMqqcyUUUr6r1F9IBmDO+Kp97nZh8\ |
| 100 | VCL+cnIEwyzAFAupQH5GoXUWGiee8oKWwH2vGHX7u6sWZsCp15NMSG3OC4jUIZOE\ |
| 101 | iVUF1QIBEQAA"); |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 102 | |
Yingdi Yu | 6a5b9f6 | 2013-11-06 23:00:21 -0800 | [diff] [blame] | 103 | string decoded; |
| 104 | CryptoPP::StringSource ss(reinterpret_cast<const unsigned char *>(TrustAnchor.c_str()), |
| 105 | TrustAnchor.size(), |
| 106 | true, |
| 107 | new CryptoPP::Base64Decoder(new CryptoPP::StringSink(decoded))); |
| 108 | Ptr<Blob> blob = Ptr<Blob>(new Blob(decoded.c_str(), decoded.size())); |
| 109 | Ptr<Data> data = Data::decodeFromWire(blob); |
| 110 | Ptr<IdentityCertificate>anchor = Ptr<IdentityCertificate>(new IdentityCertificate(*data)); |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 111 | policyManager->addTrustAnchor(anchor); |
Yingdi Yu | 6a5b9f6 | 2013-11-06 23:00:21 -0800 | [diff] [blame] | 112 | |
| 113 | #ifdef _DEBUG |
| 114 | |
| 115 | const string FakeAnchor("BIICqgOyEIVAaoHnQZIx5osAuY2fKte4HBSrxyam7MY6/kp+w47O1bGdd2KjeZKV\ |
| 116 | zZzQd3EQorDC3KUPbB6ql30jYfspvo4OPSlIuDrkyROaoZ+MSKyzQYpB6CZcTjBa\ |
| 117 | qcWYFOfwUlcWvkbd00X4bkc5PkcWpVdRrx+NCTiq9EXes//hOHpEJHMNsJUi45O+\ |
| 118 | 6M4OE6/sNEqs/ryHn2w1vCqwPpG8xzcd0prQUdCH2MGE77F+H0XFDuWp8mrT37Uw\ |
| 119 | DUy7Ltm+7nDTHSQy2J3Zk4Q+0tjxCzSw4owEpwOHr+afdkuE3v9aB2NRQBBDCEmL\ |
| 120 | Ykz4sYX3XE8MVFqRn1HHWCkszjDg+F0UAADy+p1uZG4A+p1LRVkA+vVrc2stMTM4\ |
| 121 | MjkzNDE5OAD6vUlELUNFUlQA+s39/////95rc7MAAAGiA+IChaK1eVvzlkg6BJAw\ |
| 122 | qiOpxRoezQ0hAHOBbPRLeBllxMN7AAK6tQUm3mtztQAB4gHq8vqdbmRuAPqdS0VZ\ |
| 123 | APr1a3NrLTEzODI5MzQxOTgA+r1JRC1DRVJUAAAAAAABmhblMIIBaDAiGA8yMDEz\ |
| 124 | MTAyODAwMDAwMFoYDzIwMzMxMDI4MDAwMDAwWjAcMBoGA1UEKRMTL25kbi9rc2st\ |
| 125 | MTM4MjkzNDE5ODCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAK2htIFF\ |
| 126 | /PH+SJsGOA6jhpFT74xfLJlgZNJOnKzl27HI2gupE0mainWj/HqVzdGxD6jOOReI\ |
| 127 | sul+eQyEyBYq4e35pLmdJGlux/+UPQ51DD8jg04GrUPewV7+iGm6usp/7xEGHbah\ |
| 128 | H2Grv/bsGrt6aRA8cKmdIc+rehxZCVFtiwSEHTnOWzn3lfZR5xnjF9aGX+uGo1hA\ |
| 129 | gMwu1ECxg4H3O4z1tbTzji5+WH0RDsPRlgzQX6wAQH8btlQyoFJfljEA3QaOtDaB\ |
| 130 | OcfegIlClzutmgJnK9i5ZLz2Mjvx49dlCWAVKg65vOXMLC/33jD9F+V8urwsBlOb\ |
| 131 | F7Wh5ayeo8NBKDsCAwEAAQAA"); |
| 132 | |
| 133 | string decoded2; |
| 134 | CryptoPP::StringSource ss2(reinterpret_cast<const unsigned char *>(FakeAnchor.c_str()), |
| 135 | FakeAnchor.size(), |
| 136 | true, |
| 137 | new CryptoPP::Base64Decoder(new CryptoPP::StringSink(decoded2))); |
| 138 | Ptr<Blob> blob2 = Ptr<Blob>(new Blob(decoded2.c_str(), decoded2.size())); |
| 139 | Ptr<Data> data2 = Data::decodeFromWire(blob2); |
| 140 | Ptr<IdentityCertificate>anchor2 = Ptr<IdentityCertificate>(new IdentityCertificate(*data2)); |
| 141 | policyManager->addTrustAnchor(anchor2); |
| 142 | |
| 143 | #endif |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 144 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 145 | m_keychain = keychain; |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 146 | } |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 147 | |
| 148 | |
| 149 | void |
| 150 | ContactManager::fetchSelfEndorseCertificate(const ndn::Name& identity) |
| 151 | { |
| 152 | Name interestName = identity; |
| 153 | interestName.append("DNS").append("PROFILE"); |
| 154 | |
| 155 | Ptr<Interest> interestPtr = Ptr<Interest>(new Interest(interestName)); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 156 | interestPtr->setChildSelector(Interest::CHILD_RIGHT); |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 157 | Ptr<Closure> closure = Ptr<Closure> (new Closure(boost::bind(&ContactManager::onDnsSelfEndorseCertificateVerified, |
| 158 | this, |
| 159 | _1, |
| 160 | identity), |
| 161 | boost::bind(&ContactManager::onDnsSelfEndorseCertificateTimeout, |
| 162 | this, |
| 163 | _1, |
| 164 | _2, |
| 165 | identity, |
| 166 | 0), |
| 167 | boost::bind(&ContactManager::onDnsSelfEndorseCertificateUnverified, |
| 168 | this, |
| 169 | _1, |
| 170 | identity))); |
| 171 | m_wrapper->sendInterest(interestPtr, closure); |
| 172 | } |
| 173 | |
| 174 | void |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 175 | ContactManager::fetchCollectEndorse(const ndn::Name& identity) |
| 176 | { |
| 177 | Name interestName = identity; |
| 178 | interestName.append("DNS").append("ENDORSED"); |
| 179 | |
| 180 | Ptr<Interest> interestPtr = Ptr<Interest>(new Interest(interestName)); |
| 181 | interestPtr->setChildSelector(Interest::CHILD_RIGHT); |
| 182 | interestPtr->setInterestLifetime(1); |
| 183 | Ptr<Closure> closure = Ptr<Closure> (new Closure(boost::bind(&ContactManager::onDnsCollectEndorseVerified, |
| 184 | this, |
| 185 | _1, |
| 186 | identity), |
| 187 | boost::bind(&ContactManager::onDnsCollectEndorseTimeout, |
| 188 | this, |
| 189 | _1, |
| 190 | _2, |
| 191 | identity, |
| 192 | 0), |
| 193 | boost::bind(&ContactManager::onDnsCollectEndorseUnverified, |
| 194 | this, |
| 195 | _1, |
| 196 | identity))); |
| 197 | m_wrapper->sendInterest(interestPtr, closure); |
| 198 | } |
| 199 | |
| 200 | void |
| 201 | ContactManager::fetchKey(const ndn::Name& certName) |
| 202 | { |
| 203 | Name interestName = certName; |
| 204 | |
| 205 | Ptr<Interest> interestPtr = Ptr<Interest>(new Interest(interestName)); |
| 206 | interestPtr->setChildSelector(Interest::CHILD_RIGHT); |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 207 | interestPtr->setInterestLifetime(1); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 208 | Ptr<Closure> closure = Ptr<Closure> (new Closure(boost::bind(&ContactManager::onKeyVerified, |
| 209 | this, |
| 210 | _1, |
| 211 | certName), |
| 212 | boost::bind(&ContactManager::onKeyTimeout, |
| 213 | this, |
| 214 | _1, |
| 215 | _2, |
| 216 | certName, |
| 217 | 0), |
| 218 | boost::bind(&ContactManager::onKeyUnverified, |
| 219 | this, |
| 220 | _1, |
| 221 | certName))); |
| 222 | m_wrapper->sendInterest(interestPtr, closure); |
| 223 | } |
| 224 | |
| 225 | void |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 226 | ContactManager::fetchIdCertificate(const ndn::Name& certName) |
| 227 | { |
| 228 | Name interestName = certName; |
| 229 | |
| 230 | Ptr<Interest> interestPtr = Ptr<Interest>(new Interest(interestName)); |
| 231 | interestPtr->setChildSelector(Interest::CHILD_RIGHT); |
| 232 | interestPtr->setInterestLifetime(1); |
| 233 | Ptr<Closure> closure = Ptr<Closure> (new Closure(boost::bind(&ContactManager::onIdCertificateVerified, |
| 234 | this, |
| 235 | _1, |
| 236 | certName), |
| 237 | boost::bind(&ContactManager::onIdCertificateTimeout, |
| 238 | this, |
| 239 | _1, |
| 240 | _2, |
| 241 | certName, |
| 242 | 0), |
| 243 | boost::bind(&ContactManager::onIdCertificateUnverified, |
| 244 | this, |
| 245 | _1, |
| 246 | certName))); |
| 247 | m_wrapper->sendInterest(interestPtr, closure); |
| 248 | } |
| 249 | |
| 250 | void |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 251 | ContactManager::onDnsCollectEndorseVerified(Ptr<Data> data, const Name& identity) |
| 252 | { emit collectEndorseFetched (*data); } |
| 253 | |
| 254 | void |
| 255 | ContactManager::onDnsCollectEndorseTimeout(Ptr<Closure> closure, Ptr<Interest> interest, const Name& identity, int retry) |
| 256 | { emit collectEndorseFetchFailed (identity); } |
| 257 | |
| 258 | void |
| 259 | ContactManager::onDnsCollectEndorseUnverified(Ptr<Data> data, const Name& identity) |
| 260 | { emit collectEndorseFetchFailed (identity); } |
| 261 | |
| 262 | void |
| 263 | ContactManager::onKeyVerified(Ptr<Data> data, const Name& identity) |
| 264 | { |
| 265 | IdentityCertificate identityCertificate(*data); |
Yingdi Yu | e9ea5c9 | 2013-11-06 18:42:34 -0800 | [diff] [blame] | 266 | |
| 267 | Ptr<ProfileData> profileData = Ptr<ProfileData>(new ProfileData(Profile(identityCertificate))); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 268 | |
| 269 | Ptr<IdentityManager> identityManager = m_keychain->getIdentityManager(); |
| 270 | Name certificateName = identityManager->getDefaultCertificateName (); |
| 271 | identityManager->signByCertificate(*profileData, certificateName); |
| 272 | |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 273 | Ptr<EndorseCertificate> endorseCertificate = NULL; |
| 274 | try{ |
| 275 | endorseCertificate = Ptr<EndorseCertificate>(new EndorseCertificate(identityCertificate, profileData)); |
| 276 | }catch(exception& e){ |
| 277 | _LOG_ERROR("Exception: " << e.what()); |
| 278 | return; |
| 279 | } |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 280 | |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 281 | identityManager->signByCertificate(*endorseCertificate, certificateName); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 282 | |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 283 | emit contactKeyFetched (*endorseCertificate); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | void |
| 287 | ContactManager::onKeyUnverified(Ptr<Data> data, const Name& identity) |
Yingdi Yu | 8fb16a4 | 2013-11-10 18:35:09 -0800 | [diff] [blame^] | 288 | { |
| 289 | _LOG_DEBUG("Key cannot be verified!"); |
| 290 | emit contactKeyFetchFailed (identity); |
| 291 | } |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 292 | |
| 293 | void |
| 294 | ContactManager::onKeyTimeout(Ptr<Closure> closure, Ptr<Interest> interest, const Name& identity, int retry) |
Yingdi Yu | 8fb16a4 | 2013-11-10 18:35:09 -0800 | [diff] [blame^] | 295 | { |
| 296 | _LOG_DEBUG("Key timeout!"); |
| 297 | emit contactKeyFetchFailed(identity); |
| 298 | } |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 299 | |
| 300 | void |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 301 | ContactManager::onIdCertificateVerified(Ptr<Data> data, const Name& identity) |
| 302 | { |
| 303 | IdentityCertificate identityCertificate(*data); |
| 304 | emit contactCertificateFetched(identityCertificate); |
| 305 | } |
| 306 | |
| 307 | void |
| 308 | ContactManager::onIdCertificateUnverified(Ptr<Data> data, const Name& identity) |
| 309 | { emit contactCertificateFetchFailed (identity); } |
| 310 | |
| 311 | void |
| 312 | ContactManager::onIdCertificateTimeout(Ptr<Closure> closure, Ptr<Interest> interest, const Name& identity, int retry) |
| 313 | { emit contactCertificateFetchFailed (identity); } |
| 314 | |
| 315 | void |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 316 | ContactManager::updateProfileData(const Name& identity) |
| 317 | { |
| 318 | // Get current profile; |
| 319 | Ptr<Profile> newProfile = m_contactStorage->getSelfProfile(identity); |
| 320 | if(NULL == newProfile) |
| 321 | return; |
| 322 | Ptr<Blob> newProfileBlob = newProfile->toDerBlob(); |
| 323 | |
| 324 | // Check if profile exists |
| 325 | Ptr<Blob> profileDataBlob = m_contactStorage->getSelfEndorseCertificate(identity); |
| 326 | if(NULL != profileDataBlob) |
| 327 | { |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 328 | |
| 329 | Ptr<EndorseCertificate> oldEndorseCertificate = NULL; |
| 330 | try{ |
| 331 | Ptr<Data> plainData = Data::decodeFromWire(profileDataBlob); |
| 332 | oldEndorseCertificate = Ptr<EndorseCertificate>(new EndorseCertificate(*plainData)); |
| 333 | }catch(exception& e){ |
| 334 | _LOG_ERROR("Exception: " << e.what()); |
| 335 | return; |
| 336 | } |
| 337 | |
| 338 | const Blob& oldProfileBlob = oldEndorseCertificate->getProfileData()->content(); |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 339 | |
| 340 | if(oldProfileBlob == *newProfileBlob) |
| 341 | return; |
| 342 | |
| 343 | Ptr<EndorseCertificate> newEndorseCertificate = getSignedSelfEndorseCertificate(identity, *newProfile); |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 344 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 345 | if(NULL == newEndorseCertificate) |
| 346 | return; |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 347 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 348 | m_contactStorage->updateSelfEndorseCertificate(newEndorseCertificate, identity); |
| 349 | |
| 350 | publishSelfEndorseCertificateInDNS(newEndorseCertificate); |
| 351 | } |
| 352 | else |
| 353 | { |
| 354 | Ptr<EndorseCertificate> newEndorseCertificate = getSignedSelfEndorseCertificate(identity, *newProfile); |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 355 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 356 | if(NULL == newEndorseCertificate) |
| 357 | return; |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 358 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 359 | m_contactStorage->addSelfEndorseCertificate(newEndorseCertificate, identity); |
| 360 | |
| 361 | publishSelfEndorseCertificateInDNS(newEndorseCertificate); |
| 362 | } |
| 363 | } |
| 364 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 365 | void |
| 366 | ContactManager::updateEndorseCertificate(const ndn::Name& identity, const ndn::Name& signerIdentity) |
| 367 | { |
| 368 | Ptr<Blob> oldEndorseCertificateBlob = m_contactStorage->getEndorseCertificate(identity); |
| 369 | Ptr<EndorseCertificate> newEndorseCertificate = generateEndorseCertificate(identity, signerIdentity); |
| 370 | if(NULL != oldEndorseCertificateBlob) |
| 371 | { |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 372 | Ptr<EndorseCertificate> oldEndorseCertificate = NULL; |
| 373 | try{ |
| 374 | Ptr<Data> plainData = Data::decodeFromWire(oldEndorseCertificateBlob); |
| 375 | oldEndorseCertificate = Ptr<EndorseCertificate>(new EndorseCertificate(*plainData)); |
| 376 | }catch(exception& e){ |
| 377 | _LOG_ERROR("Exception: " << e.what()); |
| 378 | return; |
| 379 | } |
| 380 | const Blob& oldEndorseContent = oldEndorseCertificate->content(); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 381 | const Blob& newEndorseContent = newEndorseCertificate->content(); |
| 382 | if(oldEndorseContent == newEndorseContent) |
| 383 | return; |
| 384 | } |
| 385 | else |
| 386 | { |
| 387 | if(NULL == newEndorseCertificate) |
| 388 | return; |
| 389 | } |
| 390 | m_contactStorage->addEndorseCertificate(newEndorseCertificate, identity); |
| 391 | publishEndorseCertificateInDNS(newEndorseCertificate, signerIdentity); |
| 392 | } |
| 393 | |
| 394 | Ptr<EndorseCertificate> |
| 395 | ContactManager::generateEndorseCertificate(const Name& identity, const Name& signerIdentity) |
| 396 | { |
| 397 | Ptr<ContactItem> contact = getContact(identity); |
Yingdi Yu | 6a5b9f6 | 2013-11-06 23:00:21 -0800 | [diff] [blame] | 398 | if(contact == NULL) |
| 399 | return NULL; |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 400 | |
| 401 | Ptr<IdentityManager> identityManager = m_keychain->getIdentityManager(); |
| 402 | Name signerKeyName = identityManager->getDefaultKeyNameForIdentity(signerIdentity); |
| 403 | Name signerCertName = identityManager->getDefaultCertificateNameByIdentity(signerIdentity); |
| 404 | |
| 405 | vector<string> endorseList = m_contactStorage->getEndorseList(identity); |
| 406 | |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 407 | Ptr<EndorseCertificate> cert = NULL; |
| 408 | try{ |
| 409 | cert = Ptr<EndorseCertificate>(new EndorseCertificate(contact->getSelfEndorseCertificate(), signerKeyName, endorseList)); |
| 410 | }catch(exception& e){ |
| 411 | _LOG_ERROR("Exception: " << e.what()); |
| 412 | return NULL; |
| 413 | } |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 414 | identityManager->signByCertificate(*cert, signerCertName); |
| 415 | |
| 416 | return cert; |
| 417 | } |
| 418 | |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 419 | vector<Ptr<ContactItem> > |
| 420 | ContactManager::getContactItemList() |
Yingdi Yu | 813d4e9 | 2013-11-03 16:22:05 -0800 | [diff] [blame] | 421 | { return m_contactStorage->getAllContacts(); } |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 422 | |
Yingdi Yu | d40226b | 2013-10-23 14:05:12 -0700 | [diff] [blame] | 423 | Ptr<ContactItem> |
| 424 | ContactManager::getContact(const ndn::Name& contactNamespace) |
Yingdi Yu | 813d4e9 | 2013-11-03 16:22:05 -0800 | [diff] [blame] | 425 | { return m_contactStorage->getContact(contactNamespace); } |
Yingdi Yu | d40226b | 2013-10-23 14:05:12 -0700 | [diff] [blame] | 426 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 427 | Ptr<EndorseCertificate> |
| 428 | ContactManager::getSignedSelfEndorseCertificate(const Name& identity, |
| 429 | const Profile& profile) |
| 430 | { |
| 431 | Ptr<IdentityManager> identityManager = m_keychain->getIdentityManager(); |
| 432 | Name certificateName = identityManager->getDefaultCertificateNameByIdentity(identity); |
| 433 | if(0 == certificateName.size()) |
| 434 | return NULL; |
| 435 | |
Yingdi Yu | e9ea5c9 | 2013-11-06 18:42:34 -0800 | [diff] [blame] | 436 | Ptr<ProfileData> profileData = Ptr<ProfileData>(new ProfileData(profile)); |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 437 | identityManager->signByCertificate(*profileData, certificateName); |
| 438 | |
Yingdi Yu | ed8cfc4 | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 439 | Ptr<security::IdentityCertificate> signingCert = identityManager->getCertificate(certificateName); |
Yingdi Yu | 6a5b9f6 | 2013-11-06 23:00:21 -0800 | [diff] [blame] | 440 | if(NULL == signingCert) |
| 441 | return NULL; |
| 442 | |
Yingdi Yu | ed8cfc4 | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 443 | Name signingKeyName = security::IdentityCertificate::certificateNameToPublicKeyName(signingCert->getName(), true); |
| 444 | |
| 445 | Ptr<security::IdentityCertificate> kskCert; |
| 446 | if(signingKeyName.get(-1).toUri().substr(0,4) == string("dsk-")) |
| 447 | { |
| 448 | Ptr<const signature::Sha256WithRsa> dskCertSig = DynamicCast<const signature::Sha256WithRsa>(signingCert->getSignature()); |
| 449 | // HACK! KSK certificate should be retrieved from network. |
Yingdi Yu | ed8cfc4 | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 450 | Name keyName = security::IdentityCertificate::certificateNameToPublicKeyName(dskCertSig->getKeyLocator().getKeyName()); |
Yingdi Yu | 6a5b9f6 | 2013-11-06 23:00:21 -0800 | [diff] [blame] | 451 | |
Yingdi Yu | ed8cfc4 | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 452 | Name kskCertName = identityManager->getPublicStorage()->getDefaultCertificateNameForKey(keyName); |
Yingdi Yu | 6a5b9f6 | 2013-11-06 23:00:21 -0800 | [diff] [blame] | 453 | |
Yingdi Yu | ed8cfc4 | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 454 | kskCert = identityManager->getCertificate(kskCertName); |
| 455 | |
| 456 | } |
| 457 | else |
| 458 | { |
| 459 | kskCert = signingCert; |
Yingdi Yu | ed8cfc4 | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 460 | } |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 461 | |
Yingdi Yu | 6a5b9f6 | 2013-11-06 23:00:21 -0800 | [diff] [blame] | 462 | if(NULL == kskCert) |
| 463 | return NULL; |
| 464 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 465 | vector<string> endorseList; |
| 466 | Profile::const_iterator it = profile.begin(); |
| 467 | for(; it != profile.end(); it++) |
| 468 | endorseList.push_back(it->first); |
| 469 | |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 470 | Ptr<EndorseCertificate> selfEndorseCertificate = NULL; |
| 471 | try{ |
| 472 | selfEndorseCertificate = Ptr<EndorseCertificate>(new EndorseCertificate(*kskCert, |
| 473 | profileData, |
| 474 | endorseList)); |
| 475 | }catch(exception& e){ |
| 476 | _LOG_ERROR("Exception: " << e.what()); |
| 477 | return NULL; |
| 478 | } |
| 479 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 480 | identityManager->signByCertificate(*selfEndorseCertificate, kskCert->getName()); |
| 481 | |
| 482 | return selfEndorseCertificate; |
| 483 | } |
| 484 | |
| 485 | |
| 486 | void |
| 487 | ContactManager::onDnsSelfEndorseCertificateVerified(Ptr<Data> data, const Name& identity) |
| 488 | { |
Yingdi Yu | c29fb98 | 2013-10-20 19:43:10 -0700 | [diff] [blame] | 489 | Ptr<Blob> dataContentBlob = Ptr<Blob>(new Blob(data->content().buf(), data->content().size())); |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 490 | |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 491 | Ptr<Data> plainData = NULL; |
| 492 | Ptr<EndorseCertificate> selfEndorseCertificate = NULL; |
| 493 | try{ |
| 494 | plainData = Data::decodeFromWire(dataContentBlob); |
| 495 | selfEndorseCertificate = Ptr<EndorseCertificate>(new EndorseCertificate(*plainData)); |
| 496 | }catch(exception& e){ |
| 497 | _LOG_ERROR("Exception: " << e.what()); |
| 498 | return; |
| 499 | } |
Yingdi Yu | c29fb98 | 2013-10-20 19:43:10 -0700 | [diff] [blame] | 500 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 501 | const security::Publickey& ksk = selfEndorseCertificate->getPublicKeyInfo(); |
Yingdi Yu | c29fb98 | 2013-10-20 19:43:10 -0700 | [diff] [blame] | 502 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 503 | if(security::PolicyManager::verifySignature(*plainData, ksk)) |
Yingdi Yu | 6a5b9f6 | 2013-11-06 23:00:21 -0800 | [diff] [blame] | 504 | emit contactFetched (*selfEndorseCertificate); |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 505 | else |
Yingdi Yu | 6a5b9f6 | 2013-11-06 23:00:21 -0800 | [diff] [blame] | 506 | emit contactFetchFailed (identity); |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | void |
| 510 | ContactManager::onDnsSelfEndorseCertificateUnverified(Ptr<Data> data, const Name& identity) |
| 511 | { emit contactFetchFailed (identity); } |
| 512 | |
| 513 | void |
| 514 | ContactManager::onDnsSelfEndorseCertificateTimeout(Ptr<Closure> closure, Ptr<Interest> interest, const Name& identity, int retry) |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 515 | { emit contactFetchFailed(identity); } |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 516 | |
| 517 | void |
| 518 | ContactManager::publishSelfEndorseCertificateInDNS(Ptr<EndorseCertificate> selfEndorseCertificate) |
| 519 | { |
| 520 | Ptr<Data> data = Ptr<Data>::Create(); |
| 521 | |
| 522 | Name keyName = selfEndorseCertificate->getPublicKeyName(); |
| 523 | Name identity = keyName.getSubName(0, keyName.size()-1); |
| 524 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 525 | |
| 526 | Name dnsName = identity; |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 527 | dnsName.append("DNS").append("PROFILE").appendVersion(); |
Yingdi Yu | c29fb98 | 2013-10-20 19:43:10 -0700 | [diff] [blame] | 528 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 529 | data->setName(dnsName); |
| 530 | Ptr<Blob> blob = selfEndorseCertificate->encodeToWire(); |
Yingdi Yu | c29fb98 | 2013-10-20 19:43:10 -0700 | [diff] [blame] | 531 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 532 | Content content(blob->buf(), blob->size()); |
| 533 | data->setContent(content); |
| 534 | |
| 535 | m_keychain->signByIdentity(*data, identity); |
Yingdi Yu | 590fa5d | 2013-10-18 18:35:09 -0700 | [diff] [blame] | 536 | |
| 537 | m_dnsStorage->updateDnsSelfProfileData(*data, identity); |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 538 | |
| 539 | Ptr<Blob> dnsBlob = data->encodeToWire(); |
| 540 | |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 541 | m_wrapper->putToNdnd(*dnsBlob); |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 542 | } |
| 543 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 544 | void |
| 545 | ContactManager::publishEndorseCertificateInDNS(Ptr<EndorseCertificate> endorseCertificate, const Name& signerIdentity) |
| 546 | { |
| 547 | Ptr<Data> data = Ptr<Data>::Create(); |
| 548 | |
| 549 | Name keyName = endorseCertificate->getPublicKeyName(); |
| 550 | Name endorsee = keyName.getSubName(0, keyName.size()-1); |
| 551 | |
| 552 | |
| 553 | Name dnsName = signerIdentity; |
| 554 | dnsName.append("DNS").append(endorsee).append("ENDORSEE").appendVersion(); |
| 555 | |
| 556 | data->setName(dnsName); |
| 557 | Ptr<Blob> blob = endorseCertificate->encodeToWire(); |
| 558 | |
| 559 | Content content(blob->buf(), blob->size()); |
| 560 | data->setContent(content); |
| 561 | |
| 562 | Name signCertName = m_keychain->getIdentityManager()->getDefaultCertificateNameByIdentity(signerIdentity); |
| 563 | m_keychain->getIdentityManager()->signByCertificate(*data, signCertName); |
| 564 | |
| 565 | m_dnsStorage->updateDnsEndorseOthers(*data, signerIdentity, endorsee); |
| 566 | |
| 567 | Ptr<Blob> dnsBlob = data->encodeToWire(); |
| 568 | |
| 569 | m_wrapper->putToNdnd(*dnsBlob); |
| 570 | } |
| 571 | |
| 572 | void |
| 573 | ContactManager::publishEndorsedDataInDns(const Name& identity) |
| 574 | { |
| 575 | Ptr<Data> data = Ptr<Data>::Create(); |
| 576 | |
| 577 | Name dnsName = identity; |
| 578 | dnsName.append("DNS").append("ENDORSED").appendVersion(); |
| 579 | data->setName(dnsName); |
| 580 | |
| 581 | Ptr<vector<Blob> > collectEndorseList = m_contactStorage->getCollectEndorseList(identity); |
| 582 | |
| 583 | Ptr<der::DerSequence> root = Ptr<der::DerSequence>::Create(); |
| 584 | |
| 585 | vector<Blob>::const_iterator it = collectEndorseList->begin(); |
| 586 | for(; it != collectEndorseList->end(); it++) |
| 587 | { |
| 588 | Ptr<der::DerOctetString> entry = Ptr<der::DerOctetString>(new der::DerOctetString(*it)); |
| 589 | root->addChild(entry); |
| 590 | } |
| 591 | |
| 592 | blob_stream blobStream; |
| 593 | OutputIterator & start = reinterpret_cast<OutputIterator &> (blobStream); |
| 594 | root->encode(start); |
| 595 | |
| 596 | Content content(blobStream.buf()->buf(), blobStream.buf()->size()); |
| 597 | data->setContent(content); |
| 598 | |
| 599 | Name signCertName = m_keychain->getIdentityManager()->getDefaultCertificateNameByIdentity(identity); |
| 600 | m_keychain->getIdentityManager()->signByCertificate(*data, signCertName); |
| 601 | |
| 602 | m_dnsStorage->updateDnsOthersEndorse(*data, identity); |
| 603 | |
| 604 | Ptr<Blob> dnsBlob = data->encodeToWire(); |
| 605 | |
| 606 | m_wrapper->putToNdnd(*dnsBlob); |
| 607 | } |
| 608 | |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 609 | void |
| 610 | ContactManager::addContact(const IdentityCertificate& identityCertificate, const Profile& profile) |
| 611 | { |
| 612 | Ptr<ProfileData> profileData = Ptr<ProfileData>(new ProfileData(profile)); |
| 613 | |
| 614 | Ptr<IdentityManager> identityManager = m_keychain->getIdentityManager(); |
| 615 | Name certificateName = identityManager->getDefaultCertificateNameByIdentity (m_defaultIdentity); |
| 616 | identityManager->signByCertificate(*profileData, certificateName); |
| 617 | |
| 618 | Ptr<EndorseCertificate> endorseCertificate = NULL; |
| 619 | try{ |
| 620 | endorseCertificate = Ptr<EndorseCertificate>(new EndorseCertificate(identityCertificate, profileData)); |
| 621 | }catch(exception& e){ |
| 622 | _LOG_ERROR("Exception: " << e.what()); |
| 623 | return; |
| 624 | } |
| 625 | |
| 626 | identityManager->signByCertificate(*endorseCertificate, certificateName); |
| 627 | |
| 628 | ContactItem contactItem(*endorseCertificate); |
| 629 | |
| 630 | try{ |
| 631 | m_contactStorage->addContact(contactItem); |
| 632 | }catch(exception& e){ |
| 633 | emit warning(e.what()); |
| 634 | _LOG_ERROR("Exception: " << e.what()); |
| 635 | return; |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 640 | |
| 641 | #if WAF |
| 642 | #include "contact-manager.moc" |
| 643 | #include "contact-manager.cpp.moc" |
| 644 | #endif |