Zhiyi Zhang | 84986cc | 2015-09-21 00:26:07 +0800 | [diff] [blame] | 1 | /* -*- 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 | |
| 30 | namespace ndn { |
| 31 | namespace gep { |
| 32 | |
| 33 | class GroupManager |
| 34 | { |
| 35 | public: |
| 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 | |
| 46 | public: |
Yingdi Yu | 4467c11 | 2015-10-19 09:27:45 -0700 | [diff] [blame] | 47 | /** |
| 48 | * @brief Create group manager |
| 49 | * |
Alexander Afanasyev | 9d7f8fe | 2016-08-05 11:28:06 -0700 | [diff] [blame^] | 50 | * The namespace of group manager is /[prefix]/read/[dataType]/ |
Yingdi Yu | 4467c11 | 2015-10-19 09:27:45 -0700 | [diff] [blame] | 51 | * The group management information (including user cert, schedule) is stored in a database |
Yingdi Yu | 8c43fcc | 2016-03-09 18:23:57 -0800 | [diff] [blame] | 52 | * at @p dbPath. |
| 53 | * The group key will be an RSA key with @p paramLength bits. |
| 54 | * The FreshnessPeriod of data packet carrying the keys will be set to @p freshPeriod hours. |
Yingdi Yu | 4467c11 | 2015-10-19 09:27:45 -0700 | [diff] [blame] | 55 | */ |
Yingdi Yu | 8c43fcc | 2016-03-09 18:23:57 -0800 | [diff] [blame] | 56 | GroupManager(const Name& prefix, const Name& dataType, const std::string& dbPath, |
Zhiyi Zhang | 84986cc | 2015-09-21 00:26:07 +0800 | [diff] [blame] | 57 | const int paramLength, const int freshPeriod); |
| 58 | |
| 59 | /** |
| 60 | * @brief Create a group key for interval which |
| 61 | * @p timeslot falls into |
| 62 | * |
| 63 | * This method creates a group key if it does not |
| 64 | * exist, and encrypts the key using public key of |
| 65 | * all eligible members |
| 66 | * |
| 67 | * @returns The group key (the first one is the |
| 68 | * public key, and the rest are encrypted |
| 69 | * private key. |
| 70 | */ |
| 71 | std::list<Data> |
| 72 | getGroupKey(const TimeStamp& timeslot); |
| 73 | |
| 74 | /// @brief Add @p schedule with @p scheduleName |
| 75 | void |
| 76 | addSchedule(const std::string& scheduleName, const Schedule& schedule); |
| 77 | |
| 78 | /// @brief Delete schedule with name @p scheduleName |
| 79 | void |
| 80 | deleteSchedule(const std::string& scheduleName); |
| 81 | |
| 82 | /// @brief Update a schedule by name @p scheduleName with a new @p schedule |
| 83 | void |
| 84 | updateSchedule(const std::string& scheduleName, const Schedule& schedule); |
| 85 | |
| 86 | /// @brief Add @p memCert with @p scheduleName |
| 87 | void |
| 88 | addMember(const std::string& scheduleName, const Data& memCert); |
| 89 | |
| 90 | /// @brief Remove member with name @p identity from the group. |
| 91 | void |
| 92 | removeMember(const Name& identity); |
| 93 | |
| 94 | /// @brief Update @p member with a schedule of @p schedule Name. |
| 95 | void |
| 96 | updateMemberSchedule(const Name& identity, const std::string& scheduleName); |
| 97 | |
| 98 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 99 | /** |
| 100 | * @brief Calculate interval that covers @p timeslot |
| 101 | * and fill @p memberKeys with the info of members who is allowed to access the interval. |
| 102 | */ |
| 103 | Interval |
| 104 | calculateInterval(const TimeStamp& timeslot, std::map<Name, Buffer>& certMap); |
| 105 | |
| 106 | /** |
| 107 | * @brief Generate rsa key pairs according to the member variable m_paramLength. |
| 108 | * @p priKeyBuf The generated private key buffer |
| 109 | * @p pubKeyBuf The generated public key buffer |
| 110 | */ |
| 111 | void |
| 112 | generateKeyPairs(Buffer& priKeyBuf, Buffer& pubKeyBuf) const; |
| 113 | |
| 114 | /// @brief Create E-KEY data. |
| 115 | Data |
| 116 | createEKeyData(const std::string& startTs, const std::string& endTs, |
| 117 | const Buffer& pubKeyBuf); |
| 118 | |
| 119 | /// @brief Create D-KEY data. |
| 120 | Data |
| 121 | createDKeyData(const std::string& startTs, const std::string& endTs, const Name& keyName, |
| 122 | const Buffer& priKeyBuf, const Buffer& certKey); |
| 123 | |
| 124 | private: |
| 125 | Name m_namespace; |
| 126 | GroupManagerDB m_db; |
| 127 | int m_paramLength; |
| 128 | int m_freshPeriod; |
| 129 | |
| 130 | KeyChain m_keyChain; |
| 131 | }; |
| 132 | |
| 133 | } // namespace gep |
| 134 | } // namespace ndn |
| 135 | |
| 136 | #endif // NDN_GEP_GROUP_MANAGER_HPP |