blob: 34937dae6b3f62abb72b2d399ee62dd11d535c2c [file] [log] [blame]
Zhiyi Zhang84986cc2015-09-21 00:26:07 +08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2015, Regents of the University of California
4 *
5 * This file is part of ndn-group-encrypt (Group-based Encryption Protocol for NDN).
6 * See AUTHORS.md for complete list of ndn-group-encrypt authors and contributors.
7 *
8 * ndn-group-encrypt is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * ndn-group-encrypt is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * ndn-group-encrypt, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * @author Zhiyi Zhang <dreamerbarrychang@gmail.com>
20 */
21
22#ifndef NDN_GEP_GROUP_MANAGER_HPP
23#define NDN_GEP_GROUP_MANAGER_HPP
24
25#include "group-manager-db.hpp"
26#include "algo/rsa.hpp"
27
28#include <ndn-cxx/security/key-chain.hpp>
29
30namespace ndn {
31namespace gep {
32
33class GroupManager
34{
35public:
36 class Error : public std::runtime_error
37 {
38 public:
39 explicit
40 Error(const std::string& what)
41 : std::runtime_error(what)
42 {
43 }
44 };
45
46public:
47 /// @brief Create group manager using @p managedNamespace
48 GroupManager(const Name& managedNamespace, const std::string& dbDir,
49 const int paramLength, const int freshPeriod);
50
51 /**
52 * @brief Create a group key for interval which
53 * @p timeslot falls into
54 *
55 * This method creates a group key if it does not
56 * exist, and encrypts the key using public key of
57 * all eligible members
58 *
59 * @returns The group key (the first one is the
60 * public key, and the rest are encrypted
61 * private key.
62 */
63 std::list<Data>
64 getGroupKey(const TimeStamp& timeslot);
65
66 /// @brief Add @p schedule with @p scheduleName
67 void
68 addSchedule(const std::string& scheduleName, const Schedule& schedule);
69
70 /// @brief Delete schedule with name @p scheduleName
71 void
72 deleteSchedule(const std::string& scheduleName);
73
74 /// @brief Update a schedule by name @p scheduleName with a new @p schedule
75 void
76 updateSchedule(const std::string& scheduleName, const Schedule& schedule);
77
78 /// @brief Add @p memCert with @p scheduleName
79 void
80 addMember(const std::string& scheduleName, const Data& memCert);
81
82 /// @brief Remove member with name @p identity from the group.
83 void
84 removeMember(const Name& identity);
85
86 /// @brief Update @p member with a schedule of @p schedule Name.
87 void
88 updateMemberSchedule(const Name& identity, const std::string& scheduleName);
89
90PUBLIC_WITH_TESTS_ELSE_PRIVATE:
91 /**
92 * @brief Calculate interval that covers @p timeslot
93 * and fill @p memberKeys with the info of members who is allowed to access the interval.
94 */
95 Interval
96 calculateInterval(const TimeStamp& timeslot, std::map<Name, Buffer>& certMap);
97
98 /**
99 * @brief Generate rsa key pairs according to the member variable m_paramLength.
100 * @p priKeyBuf The generated private key buffer
101 * @p pubKeyBuf The generated public key buffer
102 */
103 void
104 generateKeyPairs(Buffer& priKeyBuf, Buffer& pubKeyBuf) const;
105
106 /// @brief Create E-KEY data.
107 Data
108 createEKeyData(const std::string& startTs, const std::string& endTs,
109 const Buffer& pubKeyBuf);
110
111 /// @brief Create D-KEY data.
112 Data
113 createDKeyData(const std::string& startTs, const std::string& endTs, const Name& keyName,
114 const Buffer& priKeyBuf, const Buffer& certKey);
115
116private:
117 Name m_namespace;
118 GroupManagerDB m_db;
119 int m_paramLength;
120 int m_freshPeriod;
121
122 KeyChain m_keyChain;
123};
124
125} // namespace gep
126} // namespace ndn
127
128#endif // NDN_GEP_GROUP_MANAGER_HPP