Yingdi Yu | 43e7161 | 2013-10-30 22:19: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 | #ifndef SYNC_POLICY_MANAGER_H |
| 12 | #define SYNC_POLICY_MANAGER_H |
| 13 | |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame^] | 14 | #include <ndn-cpp/face.hpp> |
| 15 | #include <ndn-cpp/security/identity/identity-manager.hpp> |
| 16 | #include <ndn-cpp/security/policy/policy-manager.hpp> |
| 17 | #include <ndn-cpp/security/certificate/identity-certificate.hpp> |
| 18 | #include <ndn-cpp-et/regex/regex.hpp> |
| 19 | #include <ndn-cpp-et/policy-manager/identity-policy-rule.hpp> |
| 20 | #include <map> |
| 21 | |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 22 | #include "specific-policy-rule.h" |
| 23 | |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame^] | 24 | static ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> SYNC_POLICY_MANAGER_NULL_VALIDATION_REQUEST_PTR; |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 25 | |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame^] | 26 | class SyncPolicyManager : public ndn::PolicyManager |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 27 | { |
| 28 | public: |
| 29 | SyncPolicyManager(const ndn::Name& signingIdentity, |
| 30 | const ndn::Name& signingCertificateName, |
| 31 | const ndn::Name& syncPrefix, |
| 32 | int m_stepLimit = 3); |
| 33 | |
| 34 | virtual |
| 35 | ~SyncPolicyManager(); |
| 36 | |
| 37 | bool |
| 38 | skipVerifyAndTrust (const ndn::Data& data); |
| 39 | |
| 40 | bool |
| 41 | requireVerify (const ndn::Data& data); |
| 42 | |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame^] | 43 | ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> |
| 44 | checkVerificationPolicy(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, |
| 45 | int stepCount, |
| 46 | const ndn::OnVerified& onVerified, |
| 47 | const ndn::OnVerifyFailed& onVerifyFailed); |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 48 | |
| 49 | bool |
| 50 | checkSigningPolicy(const ndn::Name& dataName, |
| 51 | const ndn::Name& certificateName); |
| 52 | |
| 53 | ndn::Name |
| 54 | inferSigningIdentity(const ndn::Name& dataName); |
| 55 | |
| 56 | void |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame^] | 57 | addTrustAnchor(const ndn::IdentityCertificate& identityCertificate, bool isIntroducer); |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 58 | |
| 59 | void |
| 60 | addChatDataRule(const ndn::Name& prefix, |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame^] | 61 | const ndn::IdentityCertificate& identityCertificate, |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 62 | bool isIntroducer); |
| 63 | |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame^] | 64 | // inline void |
| 65 | // setFace(ndn::ndn::ptr_lib::shared_ptr<Face> face) |
| 66 | // { face_ = face; } |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 67 | |
| 68 | private: |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame^] | 69 | void |
| 70 | connectToDaemon(); |
| 71 | |
| 72 | void |
| 73 | onConnectionData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, |
| 74 | const ndn::ptr_lib::shared_ptr<ndn::Data>& data); |
| 75 | |
| 76 | void |
| 77 | onConnectionDataTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest); |
| 78 | |
| 79 | ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 80 | prepareIntroducerRequest(const ndn::Name& keyName, |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame^] | 81 | ndn::ptr_lib::shared_ptr<ndn::Data> data, |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 82 | const int & stepCount, |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame^] | 83 | const ndn::OnVerified& onVerified, |
| 84 | const ndn::OnVerifyFailed& onVerifyFailed); |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 85 | |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame^] | 86 | ndn::ptr_lib::shared_ptr<const std::vector<ndn::Name> > |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 87 | getAllIntroducerName(); |
| 88 | |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame^] | 89 | ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 90 | prepareRequest(const ndn::Name& keyName, |
| 91 | bool forIntroducer, |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame^] | 92 | ndn::ptr_lib::shared_ptr<ndn::Data> data, |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 93 | const int & stepCount, |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame^] | 94 | const ndn::OnVerified& onVerified, |
| 95 | const ndn::OnVerifyFailed& onVerifyFailed); |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 96 | |
| 97 | void |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame^] | 98 | OnIntroCertInterest(const ndn::ptr_lib::shared_ptr<const ndn::Name>& prefix, |
| 99 | const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, |
| 100 | ndn::Transport& transport, |
| 101 | uint64_t registeredPrefixId); |
| 102 | |
| 103 | void |
| 104 | OnIntroCertRegisterFailed(const ndn::ptr_lib::shared_ptr<const ndn::Name>& prefix); |
| 105 | |
| 106 | void |
| 107 | onIntroCertVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& introCertificateData, |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 108 | bool forIntroducer, |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame^] | 109 | ndn::ptr_lib::shared_ptr<ndn::Data> originalData, |
| 110 | const ndn::OnVerified& onVerified, |
| 111 | const ndn::OnVerifyFailed& onVerifyFailed); |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 112 | |
| 113 | void |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame^] | 114 | onIntroCertVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& introCertificateData, |
| 115 | ndn::ptr_lib::shared_ptr<ndn::Name> interestPrefixName, |
| 116 | bool forIntroducer, |
| 117 | ndn::ptr_lib::shared_ptr<const std::vector<ndn::Name> > introNameList, |
| 118 | int nextIntroducerIndex, |
| 119 | ndn::ptr_lib::shared_ptr<ndn::Data> originalData, |
| 120 | const ndn::OnVerified& onVerified, |
| 121 | const ndn::OnVerifyFailed& onVerifyFailed); |
| 122 | |
| 123 | void |
| 124 | onIntroCertData(const ndn::ptr_lib::shared_ptr<const ndn::Interest> &interest, |
| 125 | const ndn::ptr_lib::shared_ptr<ndn::Data>& introCertificateData, |
| 126 | int stepCount, |
| 127 | const ndn::OnVerified& onRecursiveVerified, |
| 128 | const ndn::OnVerifyFailed& onRecursiveVerifyFailed, |
| 129 | ndn::ptr_lib::shared_ptr<ndn::Data> originalData, |
| 130 | const ndn::OnVerifyFailed& onVerifyFailed); |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 131 | |
| 132 | void |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame^] | 133 | onIntroCertTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, |
| 134 | int retry, |
| 135 | int stepCount, |
| 136 | const ndn::OnVerified& onRecursiveVerified, |
| 137 | const ndn::OnVerifyFailed& onRecursiveVerifyFailed, |
| 138 | ndn::ptr_lib::shared_ptr<ndn::Data> originalData, |
| 139 | const ndn::OnVerifyFailed& onVerifyFailed); |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 140 | |
| 141 | |
| 142 | |
| 143 | private: |
| 144 | ndn::Name m_signingIdentity; |
| 145 | ndn::Name m_signingCertificateName; |
| 146 | ndn::Name m_syncPrefix; |
| 147 | int m_stepLimit; |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame^] | 148 | ndn::ptr_lib::shared_ptr<ndn::Regex> m_syncPrefixRegex; |
| 149 | ndn::ptr_lib::shared_ptr<ndn::Regex> m_wotPrefixRegex; |
| 150 | ndn::ptr_lib::shared_ptr<ndn::IdentityPolicyRule> m_chatDataPolicy; |
| 151 | std::map<std::string, ndn::PublicKey> m_trustedIntroducers; |
| 152 | std::map<std::string, ndn::PublicKey> m_trustedProducers; |
| 153 | std::map<std::string, SpecificPolicyRule> m_chatDataRules; |
| 154 | std::map<std::string, ndn::Data> m_introCert; |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 155 | |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame^] | 156 | ndn::ptr_lib::shared_ptr<ndn::IdentityManager> m_identityManager; |
| 157 | ndn::ptr_lib::shared_ptr<ndn::Transport> m_transport; |
| 158 | ndn::ptr_lib::shared_ptr<ndn::Face> m_face; |
| 159 | |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | #endif |