Alexander Afanasyev | e96538a | 2018-06-13 20:32:53 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014-2018, Regents of the University of California |
| 4 | * |
| 5 | * NAC library is free software: you can redistribute it and/or modify it under the |
| 6 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 7 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * NAC library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 11 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 12 | * |
| 13 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 14 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 15 | * <http://www.gnu.org/licenses/>. |
| 16 | * |
| 17 | * See AUTHORS.md for complete list of NAC library authors and contributors. |
| 18 | */ |
| 19 | |
| 20 | #ifndef NDN_NAC_ACCESS_MANAGER_HPP |
| 21 | #define NDN_NAC_ACCESS_MANAGER_HPP |
| 22 | |
| 23 | #include "common.hpp" |
| 24 | |
| 25 | #include <ndn-cxx/face.hpp> |
| 26 | |
| 27 | namespace ndn { |
| 28 | namespace nac { |
| 29 | |
| 30 | /** |
| 31 | * @brief Access Manager |
| 32 | * |
| 33 | * Access Manager controls decryption policy by publishing granular per-namespace access |
| 34 | * policies in the form of key encryption (KEK, plaintext public) and key decryption (KDK, |
Alexander Afanasyev | 1a21e10 | 2018-06-13 20:33:21 -0400 | [diff] [blame^] | 35 | * encrypted private key) key pair. |
Alexander Afanasyev | e96538a | 2018-06-13 20:32:53 -0400 | [diff] [blame] | 36 | * |
Alexander Afanasyev | 1a21e10 | 2018-06-13 20:33:21 -0400 | [diff] [blame^] | 37 | * @todo Rolling KEK |
Alexander Afanasyev | e96538a | 2018-06-13 20:32:53 -0400 | [diff] [blame] | 38 | */ |
| 39 | class AccessManager |
| 40 | { |
| 41 | public: |
| 42 | class Error : public std::runtime_error |
| 43 | { |
| 44 | public: |
| 45 | using std::runtime_error::runtime_error; |
| 46 | }; |
| 47 | |
| 48 | public: |
| 49 | /** |
| 50 | * @param identity Identity of the namespace (i.e., public and private keys) |
| 51 | * |
| 52 | * @param identity Data owner's namespace identity (will be used to sign KEK and KDK) |
| 53 | * @param dataset Name of dataset that this manager is controlling |
| 54 | * @param keyChain KeyChain |
| 55 | * @param face Face that will be used to publish KEK and KDKs |
| 56 | * |
Alexander Afanasyev | 1a21e10 | 2018-06-13 20:33:21 -0400 | [diff] [blame^] | 57 | * KEK and KDK naming: |
Alexander Afanasyev | e96538a | 2018-06-13 20:32:53 -0400 | [diff] [blame] | 58 | * |
Alexander Afanasyev | 1a21e10 | 2018-06-13 20:33:21 -0400 | [diff] [blame^] | 59 | * [identity]/NAC/[dataset]/KEK /[key-id] (== KEK, public key) |
Alexander Afanasyev | e96538a | 2018-06-13 20:32:53 -0400 | [diff] [blame] | 60 | * |
Alexander Afanasyev | 1a21e10 | 2018-06-13 20:33:21 -0400 | [diff] [blame^] | 61 | * [identity]/NAC/[dataset]/KDK/[key-id] /ENCRYPTED-BY/[user]/KEY/[key-id] (== KDK, encrypted private key) |
Alexander Afanasyev | e96538a | 2018-06-13 20:32:53 -0400 | [diff] [blame] | 62 | * |
| 63 | * \_____________ ______________/ |
| 64 | * \/ |
| 65 | * registered with NFD |
| 66 | * |
| 67 | * AccessManager serves NAC public key for data producers to fetch and encrypted versions of |
| 68 | * private keys (as safe bags) for authorized consumers to fetch. |
| 69 | */ |
| 70 | AccessManager(const Identity& identity, const Name& dataset, |
| 71 | KeyChain& keyChain, Face& face); |
| 72 | |
| 73 | ~AccessManager(); |
| 74 | |
| 75 | /** |
| 76 | * @brief Authorize a member identified by its certificate @p memberCert to decrypt data |
| 77 | * under the policy |
| 78 | */ |
| 79 | void |
| 80 | addMember(const Certificate& memberCert); |
| 81 | |
| 82 | // void |
| 83 | // addMemberWithKey(const Name& keyName); |
| 84 | |
| 85 | // void |
| 86 | // addMemberWithIdentity(const Name& identityName); |
| 87 | |
| 88 | /** |
| 89 | * @brief Remove member with name @p identity from the group |
| 90 | */ |
| 91 | void |
| 92 | removeMember(const Name& identity); |
| 93 | |
| 94 | public: // accessor interface for published data packets |
| 95 | |
| 96 | /** @return{ number of packets stored in in-memory storage } |
| 97 | */ |
| 98 | size_t |
| 99 | size() const |
| 100 | { |
| 101 | return m_ims.size(); |
| 102 | } |
| 103 | |
Alexander Afanasyev | 1a21e10 | 2018-06-13 20:33:21 -0400 | [diff] [blame^] | 104 | /** @brief Returns begin iterator of the in-memory storage ordered by |
Alexander Afanasyev | e96538a | 2018-06-13 20:32:53 -0400 | [diff] [blame] | 105 | * name with digest |
| 106 | * |
Alexander Afanasyev | 1a21e10 | 2018-06-13 20:33:21 -0400 | [diff] [blame^] | 107 | * @return{ const_iterator pointing to the beginning of m_cache } |
Alexander Afanasyev | e96538a | 2018-06-13 20:32:53 -0400 | [diff] [blame] | 108 | */ |
| 109 | InMemoryStorage::const_iterator |
| 110 | begin() const |
| 111 | { |
| 112 | return m_ims.begin(); |
| 113 | } |
| 114 | |
Alexander Afanasyev | 1a21e10 | 2018-06-13 20:33:21 -0400 | [diff] [blame^] | 115 | /** @brief Returns end iterator of the in-memory storage ordered by |
Alexander Afanasyev | e96538a | 2018-06-13 20:32:53 -0400 | [diff] [blame] | 116 | * name with digest |
| 117 | * |
Alexander Afanasyev | 1a21e10 | 2018-06-13 20:33:21 -0400 | [diff] [blame^] | 118 | * @return{ const_iterator pointing to the end of m_cache } |
Alexander Afanasyev | e96538a | 2018-06-13 20:32:53 -0400 | [diff] [blame] | 119 | */ |
| 120 | InMemoryStorage::const_iterator |
| 121 | end() const |
| 122 | { |
| 123 | return m_ims.end(); |
| 124 | } |
| 125 | |
| 126 | private: |
| 127 | Identity m_identity; |
| 128 | Key m_nacKey; |
| 129 | KeyChain& m_keyChain; |
| 130 | Face& m_face; |
| 131 | |
Alexander Afanasyev | 1a21e10 | 2018-06-13 20:33:21 -0400 | [diff] [blame^] | 132 | InMemoryStoragePersistent m_ims; // for KEK and KDKs |
Alexander Afanasyev | e96538a | 2018-06-13 20:32:53 -0400 | [diff] [blame] | 133 | const RegisteredPrefixId* m_kekRegId; |
| 134 | const RegisteredPrefixId* m_kdkRegId; |
| 135 | }; |
| 136 | |
| 137 | } // namespace nac |
| 138 | } // namespace ndn |
| 139 | |
| 140 | #endif // NDN_NAC_ACCESS_MANAGER_HPP |