blob: b7ec40293f108b89c7f9b9059911e0dda73ac225 [file] [log] [blame]
Yingdi Yu43e71612013-10-30 22:19:31 -07001/* -*- 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 Yu46c9f1a2013-12-18 15:15:46 +080014#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 Yu43e71612013-10-30 22:19:31 -070022#include "specific-policy-rule.h"
23
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080024static ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> SYNC_POLICY_MANAGER_NULL_VALIDATION_REQUEST_PTR;
Yingdi Yu43e71612013-10-30 22:19:31 -070025
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080026class SyncPolicyManager : public ndn::PolicyManager
Yingdi Yu43e71612013-10-30 22:19:31 -070027{
28public:
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 Yu46c9f1a2013-12-18 15:15:46 +080043 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 Yu43e71612013-10-30 22:19:31 -070048
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 Yu46c9f1a2013-12-18 15:15:46 +080057 addTrustAnchor(const ndn::IdentityCertificate& identityCertificate, bool isIntroducer);
Yingdi Yu43e71612013-10-30 22:19:31 -070058
59 void
60 addChatDataRule(const ndn::Name& prefix,
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080061 const ndn::IdentityCertificate& identityCertificate,
Yingdi Yu43e71612013-10-30 22:19:31 -070062 bool isIntroducer);
63
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080064 // inline void
65 // setFace(ndn::ndn::ptr_lib::shared_ptr<Face> face)
66 // { face_ = face; }
Yingdi Yu43e71612013-10-30 22:19:31 -070067
68private:
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080069 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 Yu43e71612013-10-30 22:19:31 -070080 prepareIntroducerRequest(const ndn::Name& keyName,
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080081 ndn::ptr_lib::shared_ptr<ndn::Data> data,
Yingdi Yu43e71612013-10-30 22:19:31 -070082 const int & stepCount,
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080083 const ndn::OnVerified& onVerified,
84 const ndn::OnVerifyFailed& onVerifyFailed);
Yingdi Yu43e71612013-10-30 22:19:31 -070085
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080086 ndn::ptr_lib::shared_ptr<const std::vector<ndn::Name> >
Yingdi Yu43e71612013-10-30 22:19:31 -070087 getAllIntroducerName();
88
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080089 ndn::ptr_lib::shared_ptr<ndn::ValidationRequest>
Yingdi Yu43e71612013-10-30 22:19:31 -070090 prepareRequest(const ndn::Name& keyName,
91 bool forIntroducer,
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080092 ndn::ptr_lib::shared_ptr<ndn::Data> data,
Yingdi Yu43e71612013-10-30 22:19:31 -070093 const int & stepCount,
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080094 const ndn::OnVerified& onVerified,
95 const ndn::OnVerifyFailed& onVerifyFailed);
Yingdi Yu43e71612013-10-30 22:19:31 -070096
97 void
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080098 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 Yu43e71612013-10-30 22:19:31 -0700108 bool forIntroducer,
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800109 ndn::ptr_lib::shared_ptr<ndn::Data> originalData,
110 const ndn::OnVerified& onVerified,
111 const ndn::OnVerifyFailed& onVerifyFailed);
Yingdi Yu43e71612013-10-30 22:19:31 -0700112
113 void
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800114 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 Yu43e71612013-10-30 22:19:31 -0700131
132 void
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800133 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 Yu43e71612013-10-30 22:19:31 -0700140
141
142
143private:
144 ndn::Name m_signingIdentity;
145 ndn::Name m_signingCertificateName;
146 ndn::Name m_syncPrefix;
147 int m_stepLimit;
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800148 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 Yu43e71612013-10-30 22:19:31 -0700155
Yingdi Yu46c9f1a2013-12-18 15:15:46 +0800156 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 Yu43e71612013-10-30 22:19:31 -0700160};
161
162#endif