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 | #ifndef LINKNDN_CONTACT_MANAGER_H |
| 12 | #define LINKNDN_CONTACT_MANAGER_H |
| 13 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 14 | #include <QObject> |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 15 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 16 | #ifndef Q_MOC_RUN |
| 17 | #include "contact-storage.h" |
| 18 | #include "dns-storage.h" |
| 19 | #include "endorse-certificate.h" |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 20 | #include "profile.h" |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 21 | #include <ndn-cpp/face.hpp> |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 22 | #include <ndn-cpp/security/key-chain.hpp> |
Yingdi Yu | eaa84e2 | 2014-01-16 10:30:26 -0800 | [diff] [blame^] | 23 | #include <ndn-cpp/security/validation-request.hpp> |
| 24 | #include <ndn-cpp-et/policy/sec-policy-simple.hpp> |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 25 | #endif |
| 26 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 27 | typedef ndn::func_lib::function<void()> TimeoutNotify; |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 28 | |
| 29 | class ContactManager : public QObject |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 30 | { |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 31 | Q_OBJECT |
| 32 | |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 33 | public: |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 34 | ContactManager(ndn::ptr_lib::shared_ptr<ndn::KeyChain> keyChain, |
Yingdi Yu | accbda9 | 2013-12-27 08:44:12 +0800 | [diff] [blame] | 35 | ndn::ptr_lib::shared_ptr<ndn::Face> m_face, |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 36 | QObject* parent = 0); |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 37 | |
| 38 | ~ContactManager(); |
| 39 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 40 | void |
| 41 | fetchSelfEndorseCertificate(const ndn::Name& identity); |
| 42 | |
| 43 | void |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 44 | fetchKey(const ndn::Name& identity); |
| 45 | |
| 46 | void |
| 47 | fetchCollectEndorse(const ndn::Name& identity); |
| 48 | |
| 49 | void |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 50 | fetchIdCertificate(const ndn::Name& certName); |
| 51 | |
| 52 | void |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 53 | updateProfileData(const ndn::Name& identity); |
| 54 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 55 | void |
| 56 | updateEndorseCertificate(const ndn::Name& identity, const ndn::Name& signerIdentity); |
| 57 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 58 | void |
| 59 | getContactItemList(std::vector<ndn::ptr_lib::shared_ptr<ContactItem> >& contacts); |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 60 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 61 | ndn::ptr_lib::shared_ptr<ContactStorage> |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 62 | getContactStorage() |
| 63 | { return m_contactStorage; } |
| 64 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 65 | ndn::ptr_lib::shared_ptr<ContactItem> |
Yingdi Yu | d40226b | 2013-10-23 14:05:12 -0700 | [diff] [blame] | 66 | getContact(const ndn::Name& contactNamespace); |
| 67 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 68 | ndn::ptr_lib::shared_ptr<DnsStorage> |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 69 | getDnsStorage() |
| 70 | { return m_dnsStorage; } |
| 71 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 72 | ndn::Name |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 73 | getDefaultIdentity() |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 74 | { return m_keyChain->getDefaultIdentity(); } |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 75 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 76 | void |
| 77 | publishEndorsedDataInDns(const ndn::Name& identity); |
| 78 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 79 | void |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 80 | setDefaultIdentity(const ndn::Name& identity) |
| 81 | { m_defaultIdentity = identity; } |
| 82 | |
| 83 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 84 | addContact(const ndn::IdentityCertificate& idCert, const Profile& profile); |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 85 | |
Yingdi Yu | 6ea54e4 | 2013-11-12 17:50:21 -0800 | [diff] [blame] | 86 | void |
| 87 | removeContact(const ndn::Name& contactNameSpace); |
| 88 | |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 89 | // ndn::ptr_lib::shared_ptr<ndn::KeyChain> |
| 90 | // getKeyChain() |
| 91 | // { return m_keyChain; } |
Yingdi Yu | 6ea54e4 | 2013-11-12 17:50:21 -0800 | [diff] [blame] | 92 | |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 93 | private: |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 94 | void |
| 95 | initializeSecurity(); |
| 96 | |
| 97 | ndn::ptr_lib::shared_ptr<EndorseCertificate> |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 98 | getSignedSelfEndorseCertificate(const ndn::Name& identity, const Profile& profile); |
| 99 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 100 | ndn::ptr_lib::shared_ptr<EndorseCertificate> |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 101 | generateEndorseCertificate(const ndn::Name& identity, const ndn::Name& signerIdentity); |
| 102 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 103 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 104 | publishSelfEndorseCertificateInDNS(const EndorseCertificate& selfEndorseCertificate); |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 105 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 106 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 107 | publishEndorseCertificateInDNS(const EndorseCertificate& endorseCertificate, const ndn::Name& signerIdentity); |
| 108 | |
| 109 | void |
| 110 | sendInterest(const ndn::Interest& interest, |
| 111 | const ndn::OnVerified& onVerified, |
| 112 | const ndn::OnVerifyFailed& onVerifyFailed, |
| 113 | const TimeoutNotify& timeoutNotify, |
| 114 | int retry = 1, |
| 115 | int stepCount = 0); |
| 116 | |
| 117 | void |
| 118 | onTargetData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, |
| 119 | const ndn::ptr_lib::shared_ptr<ndn::Data>& data, |
| 120 | int stepCount, |
| 121 | const ndn::OnVerified& onVerified, |
| 122 | const ndn::OnVerifyFailed& onVerifyFailed, |
| 123 | const TimeoutNotify& timeoutNotify); |
| 124 | |
| 125 | void |
| 126 | onTargetTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, |
| 127 | int retry, |
| 128 | int stepCount, |
| 129 | const ndn::OnVerified& onVerified, |
| 130 | const ndn::OnVerifyFailed& onVerifyFailed, |
| 131 | const TimeoutNotify& timeoutNotify); |
| 132 | |
| 133 | |
| 134 | void |
| 135 | onCertData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, |
| 136 | const ndn::ptr_lib::shared_ptr<ndn::Data>& cert, |
| 137 | ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> previousStep); |
| 138 | |
| 139 | void |
| 140 | onCertTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, |
| 141 | const ndn::OnVerifyFailed& onVerifyFailed, |
| 142 | const ndn::ptr_lib::shared_ptr<ndn::Data>& data, |
| 143 | ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> nextStep); |
| 144 | |
| 145 | |
| 146 | void |
| 147 | onDnsSelfEndorseCertificateTimeoutNotify(const ndn::Name& identity); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 148 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 149 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 150 | onDnsSelfEndorseCertificateVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& selfEndorseCertificate, const ndn::Name& identity); |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 151 | |
| 152 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 153 | onDnsSelfEndorseCertificateVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& selfEndorseCertificate, const ndn::Name& identity); |
| 154 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 155 | |
| 156 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 157 | onDnsCollectEndorseVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity); |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 158 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 159 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 160 | onDnsCollectEndorseVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 161 | |
| 162 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 163 | onDnsCollectEndorseTimeoutNotify(const ndn::Name& identity); |
| 164 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 165 | |
| 166 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 167 | onKeyVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 168 | |
| 169 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 170 | onKeyVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 171 | |
| 172 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 173 | onKeyTimeoutNotify(const ndn::Name& identity); |
| 174 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 175 | |
| 176 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 177 | onIdCertificateVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 178 | |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 179 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 180 | onIdCertificateVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity); |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 181 | |
| 182 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 183 | onIdCertificateTimeoutNotify(const ndn::Name& identity); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 184 | |
| 185 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 186 | signals: |
Yingdi Yu | b29f78c | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 187 | void |
| 188 | noNdnConnection(const QString& msg); |
| 189 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 190 | void |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 191 | contactFetched(const EndorseCertificate& endorseCertificate); |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 192 | |
| 193 | void |
| 194 | contactFetchFailed(const ndn::Name& identity); |
| 195 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 196 | void |
| 197 | contactKeyFetched(const EndorseCertificate& endorseCertificate); |
| 198 | |
| 199 | void |
| 200 | contactKeyFetchFailed(const ndn::Name& identity); |
| 201 | |
| 202 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 203 | contactCertificateFetched(const ndn::IdentityCertificate& identityCertificate); |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 204 | |
| 205 | void |
| 206 | contactCertificateFetchFailed(const ndn::Name& identity); |
| 207 | |
| 208 | void |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 209 | collectEndorseFetched(const ndn::Data& data); |
| 210 | |
| 211 | void |
| 212 | collectEndorseFetchFailed(const ndn::Name& identity); |
| 213 | |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 214 | void |
| 215 | warning(QString msg); |
| 216 | |
Yingdi Yu | 6ea54e4 | 2013-11-12 17:50:21 -0800 | [diff] [blame] | 217 | void |
| 218 | contactRemoved(const ndn::Name& identity); |
| 219 | |
| 220 | void |
| 221 | contactAdded(const ndn::Name& identity); |
| 222 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 223 | private slots: |
| 224 | |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 225 | |
| 226 | private: |
Yingdi Yu | eaa84e2 | 2014-01-16 10:30:26 -0800 | [diff] [blame^] | 227 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 228 | ndn::ptr_lib::shared_ptr<ContactStorage> m_contactStorage; |
| 229 | ndn::ptr_lib::shared_ptr<DnsStorage> m_dnsStorage; |
Yingdi Yu | eaa84e2 | 2014-01-16 10:30:26 -0800 | [diff] [blame^] | 230 | ndn::ptr_lib::shared_ptr<ndn::SecPolicySimple> m_policy; |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 231 | ndn::ptr_lib::shared_ptr<ndn::KeyChain> m_keyChain; |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 232 | ndn::ptr_lib::shared_ptr<ndn::Face> m_face; |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 233 | ndn::Name m_defaultIdentity; |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 234 | }; |
| 235 | |
| 236 | #endif |