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 | |
| 14 | #include <ndn.cxx/security/policy/policy-manager.h> |
| 15 | #include <ndn.cxx/security/policy/identity-policy-rule.h> |
| 16 | #include <ndn.cxx/security/certificate/identity-certificate.h> |
| 17 | #include <ndn.cxx/regex/regex.h> |
| 18 | #include <ndn.cxx/wrapper/wrapper.h> |
| 19 | #include "specific-policy-rule.h" |
| 20 | |
| 21 | |
| 22 | class SyncPolicyManager : public ndn::security::PolicyManager |
| 23 | { |
| 24 | public: |
| 25 | SyncPolicyManager(const ndn::Name& signingIdentity, |
| 26 | const ndn::Name& signingCertificateName, |
| 27 | const ndn::Name& syncPrefix, |
| 28 | int m_stepLimit = 3); |
| 29 | |
| 30 | virtual |
| 31 | ~SyncPolicyManager(); |
| 32 | |
| 33 | bool |
| 34 | skipVerifyAndTrust (const ndn::Data& data); |
| 35 | |
| 36 | bool |
| 37 | requireVerify (const ndn::Data& data); |
| 38 | |
| 39 | ndn::Ptr<ndn::security::ValidationRequest> |
| 40 | checkVerificationPolicy(ndn::Ptr<ndn::Data> data, |
| 41 | const int& stepCount, |
| 42 | const ndn::DataCallback& verifiedCallback, |
| 43 | const ndn::UnverifiedCallback& unverifiedCallback); |
| 44 | |
| 45 | bool |
| 46 | checkSigningPolicy(const ndn::Name& dataName, |
| 47 | const ndn::Name& certificateName); |
| 48 | |
| 49 | ndn::Name |
| 50 | inferSigningIdentity(const ndn::Name& dataName); |
| 51 | |
| 52 | void |
| 53 | addTrustAnchor(const ndn::security::IdentityCertificate& identityCertificate, bool isIntroducer); |
| 54 | |
| 55 | void |
| 56 | addChatDataRule(const ndn::Name& prefix, |
| 57 | const ndn::security::IdentityCertificate& identityCertificate, |
| 58 | bool isIntroducer); |
| 59 | |
| 60 | inline void |
| 61 | setWrapper(ndn::Wrapper* handler) |
| 62 | { m_handler = handler; } |
| 63 | |
| 64 | private: |
| 65 | ndn::Ptr<ndn::security::ValidationRequest> |
| 66 | prepareIntroducerRequest(const ndn::Name& keyName, |
| 67 | ndn::Ptr<ndn::Data> data, |
| 68 | const int & stepCount, |
| 69 | const ndn::DataCallback& verifiedCallback, |
| 70 | const ndn::UnverifiedCallback& unverifiedCallback); |
| 71 | |
| 72 | ndn::Ptr<const std::vector<ndn::Name> > |
| 73 | getAllIntroducerName(); |
| 74 | |
| 75 | ndn::Ptr<ndn::security::ValidationRequest> |
| 76 | prepareRequest(const ndn::Name& keyName, |
| 77 | bool forIntroducer, |
| 78 | ndn::Ptr<ndn::Data> data, |
| 79 | const int & stepCount, |
| 80 | const ndn::DataCallback& verifiedCallback, |
| 81 | const ndn::UnverifiedCallback& unverifiedCallback); |
| 82 | |
| 83 | void |
| 84 | onIntroCertVerified(ndn::Ptr<ndn::Data> introCertificateData, |
| 85 | bool forIntroducer, |
| 86 | ndn::Ptr<ndn::Data> originalData, |
| 87 | const ndn::DataCallback& verifiedCallback, |
| 88 | const ndn::UnverifiedCallback& unverifiedCallback); |
| 89 | |
| 90 | void |
| 91 | onIntroCertUnverified(ndn::Ptr<ndn::Data> introCertificateData, |
| 92 | ndn::Ptr<ndn::Name> interestPrefixName, |
| 93 | bool forIntroducer, |
| 94 | ndn::Ptr<const std::vector<ndn::Name> > introNameList, |
| 95 | const int& nextIntroducerIndex, |
| 96 | ndn::Ptr<ndn::Data> originalData, |
| 97 | const ndn::DataCallback& verifiedCallback, |
| 98 | const ndn::UnverifiedCallback& unverifiedCallback); |
| 99 | |
| 100 | void |
| 101 | onIntroCertTimeOut(ndn::Ptr<ndn::Closure> closure, |
| 102 | ndn::Ptr<ndn::Interest> interest, |
| 103 | int retry, |
| 104 | const ndn::UnverifiedCallback& unverifiedCallback, |
| 105 | ndn::Ptr<ndn::Data> data); |
| 106 | |
| 107 | |
| 108 | |
| 109 | private: |
| 110 | ndn::Name m_signingIdentity; |
| 111 | ndn::Name m_signingCertificateName; |
| 112 | ndn::Name m_syncPrefix; |
| 113 | int m_stepLimit; |
| 114 | ndn::Ptr<ndn::Regex> m_syncPrefixRegex; |
| 115 | ndn::Ptr<ndn::Regex> m_wotPrefixRegex; |
| 116 | ndn::Ptr<ndn::security::IdentityPolicyRule> m_chatDataPolicy; |
| 117 | std::map<ndn::Name, ndn::security::Publickey> m_trustedIntroducers; |
| 118 | std::map<ndn::Name, ndn::security::Publickey> m_trustedProducers; |
| 119 | std::map<ndn::Name, SpecificPolicyRule> m_chatDataRules; |
| 120 | |
| 121 | ndn::Wrapper* m_handler; |
| 122 | }; |
| 123 | |
| 124 | #endif |