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 | |
Yingdi Yu | 5e0af3e | 2014-01-15 19:33:25 -0800 | [diff] [blame] | 11 | #ifndef SEC_POLICY_SYNC_H |
| 12 | #define SEC_POLICY_SYNC_H |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 13 | |
Yingdi Yu | e815471 | 2014-01-21 10:20:14 -0800 | [diff] [blame^] | 14 | #include <ndn-cpp-dev/face.hpp> |
| 15 | #include <ndn-cpp-dev/security/key-chain.hpp> |
| 16 | #include <ndn-cpp-dev/security/verifier.hpp> |
| 17 | #include <ndn-cpp-dev/security/sec-policy.hpp> |
| 18 | #include <ndn-cpp-dev/security/identity-certificate.hpp> |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame] | 19 | #include <ndn-cpp-et/regex/regex.hpp> |
Yingdi Yu | 5e0af3e | 2014-01-15 19:33:25 -0800 | [diff] [blame] | 20 | #include <ndn-cpp-et/policy/sec-rule-identity.hpp> |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame] | 21 | #include <map> |
| 22 | |
Yingdi Yu | 5e0af3e | 2014-01-15 19:33:25 -0800 | [diff] [blame] | 23 | #include "sec-rule-sync-specific.h" |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 24 | |
Yingdi Yu | 5e0af3e | 2014-01-15 19:33:25 -0800 | [diff] [blame] | 25 | class SecPolicySync : public ndn::SecPolicy |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 26 | { |
| 27 | public: |
Yingdi Yu | 5e0af3e | 2014-01-15 19:33:25 -0800 | [diff] [blame] | 28 | SecPolicySync(const ndn::Name& signingIdentity, |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 29 | const ndn::Name& signingCertificateName, |
| 30 | const ndn::Name& syncPrefix, |
Yingdi Yu | 6e235db | 2013-12-27 08:40:53 +0800 | [diff] [blame] | 31 | ndn::ptr_lib::shared_ptr<ndn::Face> face, |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 32 | int m_stepLimit = 3); |
| 33 | |
| 34 | virtual |
Yingdi Yu | 5e0af3e | 2014-01-15 19:33:25 -0800 | [diff] [blame] | 35 | ~SecPolicySync(); |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 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 | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 64 | private: |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame] | 65 | |
| 66 | ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 67 | prepareIntroducerRequest(const ndn::Name& keyName, |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame] | 68 | ndn::ptr_lib::shared_ptr<ndn::Data> data, |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 69 | const int & stepCount, |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame] | 70 | const ndn::OnVerified& onVerified, |
| 71 | const ndn::OnVerifyFailed& onVerifyFailed); |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 72 | |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame] | 73 | ndn::ptr_lib::shared_ptr<const std::vector<ndn::Name> > |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 74 | getAllIntroducerName(); |
| 75 | |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame] | 76 | ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 77 | prepareRequest(const ndn::Name& keyName, |
| 78 | bool forIntroducer, |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame] | 79 | ndn::ptr_lib::shared_ptr<ndn::Data> data, |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 80 | const int & stepCount, |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame] | 81 | const ndn::OnVerified& onVerified, |
| 82 | const ndn::OnVerifyFailed& onVerifyFailed); |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 83 | |
| 84 | void |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame] | 85 | OnIntroCertInterest(const ndn::ptr_lib::shared_ptr<const ndn::Name>& prefix, |
| 86 | const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, |
| 87 | ndn::Transport& transport, |
| 88 | uint64_t registeredPrefixId); |
| 89 | |
| 90 | void |
| 91 | OnIntroCertRegisterFailed(const ndn::ptr_lib::shared_ptr<const ndn::Name>& prefix); |
| 92 | |
| 93 | void |
| 94 | onIntroCertVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& introCertificateData, |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 95 | bool forIntroducer, |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame] | 96 | ndn::ptr_lib::shared_ptr<ndn::Data> originalData, |
| 97 | const ndn::OnVerified& onVerified, |
| 98 | const ndn::OnVerifyFailed& onVerifyFailed); |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 99 | |
| 100 | void |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame] | 101 | onIntroCertVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& introCertificateData, |
| 102 | ndn::ptr_lib::shared_ptr<ndn::Name> interestPrefixName, |
| 103 | bool forIntroducer, |
| 104 | ndn::ptr_lib::shared_ptr<const std::vector<ndn::Name> > introNameList, |
| 105 | int nextIntroducerIndex, |
| 106 | ndn::ptr_lib::shared_ptr<ndn::Data> originalData, |
| 107 | const ndn::OnVerified& onVerified, |
| 108 | const ndn::OnVerifyFailed& onVerifyFailed); |
| 109 | |
| 110 | void |
| 111 | onIntroCertData(const ndn::ptr_lib::shared_ptr<const ndn::Interest> &interest, |
| 112 | const ndn::ptr_lib::shared_ptr<ndn::Data>& introCertificateData, |
| 113 | int stepCount, |
| 114 | const ndn::OnVerified& onRecursiveVerified, |
| 115 | const ndn::OnVerifyFailed& onRecursiveVerifyFailed, |
| 116 | ndn::ptr_lib::shared_ptr<ndn::Data> originalData, |
| 117 | const ndn::OnVerifyFailed& onVerifyFailed); |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 118 | |
| 119 | void |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame] | 120 | onIntroCertTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, |
| 121 | int retry, |
| 122 | int stepCount, |
| 123 | const ndn::OnVerified& onRecursiveVerified, |
| 124 | const ndn::OnVerifyFailed& onRecursiveVerifyFailed, |
| 125 | ndn::ptr_lib::shared_ptr<ndn::Data> originalData, |
| 126 | const ndn::OnVerifyFailed& onVerifyFailed); |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 127 | |
| 128 | |
| 129 | |
| 130 | private: |
| 131 | ndn::Name m_signingIdentity; |
| 132 | ndn::Name m_signingCertificateName; |
| 133 | ndn::Name m_syncPrefix; |
| 134 | int m_stepLimit; |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame] | 135 | ndn::ptr_lib::shared_ptr<ndn::Regex> m_syncPrefixRegex; |
| 136 | ndn::ptr_lib::shared_ptr<ndn::Regex> m_wotPrefixRegex; |
Yingdi Yu | 5e0af3e | 2014-01-15 19:33:25 -0800 | [diff] [blame] | 137 | ndn::ptr_lib::shared_ptr<ndn::SecRuleIdentity> m_chatDataPolicy; |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame] | 138 | std::map<std::string, ndn::PublicKey> m_trustedIntroducers; |
| 139 | std::map<std::string, ndn::PublicKey> m_trustedProducers; |
Yingdi Yu | 5e0af3e | 2014-01-15 19:33:25 -0800 | [diff] [blame] | 140 | std::map<std::string, SecRuleSyncSpecific> m_chatDataRules; |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame] | 141 | std::map<std::string, ndn::Data> m_introCert; |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 142 | |
Yingdi Yu | 0cb0f2b | 2014-01-09 13:51:16 -0800 | [diff] [blame] | 143 | ndn::ptr_lib::shared_ptr<ndn::KeyChain> m_keyChain; |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame] | 144 | ndn::ptr_lib::shared_ptr<ndn::Face> m_face; |
| 145 | |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | #endif |