group-manager.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
23 #ifndef NDN_GROUP_MANAGER_HPP
24 #define NDN_GROUP_MANAGER_HPP
25 
26 #include "../security/certificate/identity-certificate.hpp"
27 #include "group-manager-db.hpp"
28 
29 // Give friend access to the tests.
30 class TestGroupManager_CreateDKeyData_Test;
31 class TestGroupManager_CreateEKeyData_Test;
32 class TestGroupManager_CalculateInterval_Test;
33 
34 namespace ndn {
35 
36 class KeyChain;
37 
43 class GroupManager {
44 public:
60  (const Name& prefix, const Name& dataType,
61  const ptr_lib::shared_ptr<GroupManagerDb>& database, uint32_t keySize,
62  int freshnessHours, KeyChain* keyChain);
63 
76  void
78  (MillisecondsSince1970 timeSlot,
79  std::vector<ptr_lib::shared_ptr<Data> >& result);
80 
88  void
89  addSchedule(const std::string& scheduleName, const Schedule& schedule)
90  {
91  database_->addSchedule(scheduleName, schedule);
92  }
93 
100  void
101  deleteSchedule(const std::string& scheduleName)
102  {
103  database_->deleteSchedule(scheduleName);
104  }
105 
114  void
115  updateSchedule(const std::string& scheduleName, const Schedule& schedule)
116  {
117  database_->updateSchedule(scheduleName, schedule);
118  }
119 
131  void
132  addMember(const std::string& scheduleName, const Data& memberCertificate)
133  {
134  IdentityCertificate cert(memberCertificate);
135  database_->addMember
136  (scheduleName, cert.getPublicKeyName(), cert.getPublicKeyInfo().getKeyDer());
137  }
138 
145  void
146  removeMember(const Name& identity)
147  {
148  database_->deleteMember(identity);
149  }
150 
158  void
159  updateMemberSchedule(const Name& identity, const std::string& scheduleName)
160  {
161  database_->updateMemberSchedule(identity, scheduleName);
162  }
163 
164 private:
165  // Give friend access to the tests.
166  friend TestGroupManager_CreateDKeyData_Test;
167  friend TestGroupManager_CreateEKeyData_Test;
168  friend TestGroupManager_CalculateInterval_Test;
169 
179  Interval
180  calculateInterval
181  (MillisecondsSince1970 timeSlot, std::map<Name, Blob>& memberKeys);
182 
190  void
191  generateKeyPair(Blob& privateKeyBlob, Blob& publicKeyBlob);
192 
201  ptr_lib::shared_ptr<Data>
202  createEKeyData
203  (const std::string& startTimeStamp, const std::string& endTimeStamp,
204  const Blob& publicKeyBlob);
205 
219  ptr_lib::shared_ptr<Data>
220  createDKeyData
221  (const std::string& startTimeStamp, const std::string& endTimeStamp,
222  const Name& keyName, const Blob& privateKeyBlob, const Blob& certificateKey);
223 
224  Name namespace_;
225  ptr_lib::shared_ptr<GroupManagerDb> database_;
226  uint32_t keySize_;
227  int freshnessHours_;
228  KeyChain* keyChain_;
229  static const uint64_t MILLISECONDS_IN_HOUR = 3600 * 1000;
230 };
231 
232 }
233 
234 #endif
A GroupManager manages keys and schedules for group members in a particular namespace.
Definition: group-manager.hpp:43
An Interval defines a time duration which contains a start timestamp and an end timestamp.
Definition: interval.hpp:36
void deleteSchedule(const std::string &scheduleName)
Delete the schedule with the given scheduleName.
Definition: group-manager.hpp:101
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:36
void updateMemberSchedule(const Name &identity, const std::string &scheduleName)
Change the name of the schedule for the given member's identity name.
Definition: group-manager.hpp:159
Schedule is used to manage the times when a member can access data using two sets of RepetitiveInterv...
Definition: schedule.hpp:43
Definition: data.hpp:37
void removeMember(const Name &identity)
Remove a member with the given identity name.
Definition: group-manager.hpp:146
Definition: identity-certificate.hpp:30
void addSchedule(const std::string &scheduleName, const Schedule &schedule)
Add a schedule with the given scheduleName.
Definition: group-manager.hpp:89
KeyChain is the main class of the security library.
Definition: key-chain.hpp:45
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:40
A Blob holds a pointer to an immutable byte array implemented as const std::vector.
Definition: blob.hpp:42
GroupManager(const Name &prefix, const Name &dataType, const ptr_lib::shared_ptr< GroupManagerDb > &database, uint32_t keySize, int freshnessHours, KeyChain *keyChain)
Create a group manager with the given values.
Definition: group-manager.cpp:34
double MillisecondsSince1970
The calendar time represented as the number of milliseconds since 1/1/1970.
Definition: common.hpp:117
void addMember(const std::string &scheduleName, const Data &memberCertificate)
Add a new member with the given memberCertificate into a schedule named scheduleName.
Definition: group-manager.hpp:132
void updateSchedule(const std::string &scheduleName, const Schedule &schedule)
Update the schedule with scheduleName and replace the old object with the given schedule.
Definition: group-manager.hpp:115
void getGroupKey(MillisecondsSince1970 timeSlot, std::vector< ptr_lib::shared_ptr< Data > > &result)
Create a group key for the interval into which timeSlot falls.
Definition: group-manager.cpp:48