Alexander Afanasyev | e96538a | 2018-06-13 20:32:53 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | d51d960 | 2019-07-20 23:33:06 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | bde084f | 2022-04-17 00:21:35 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, Regents of the University of California |
Alexander Afanasyev | e96538a | 2018-06-13 20:32:53 -0400 | [diff] [blame] | 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 | |
Davide Pesavento | bde084f | 2022-04-17 00:21:35 -0400 | [diff] [blame] | 27 | namespace ndn::nac { |
Alexander Afanasyev | e96538a | 2018-06-13 20:32:53 -0400 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * @brief Access Manager |
| 31 | * |
| 32 | * Access Manager controls decryption policy by publishing granular per-namespace access |
| 33 | * 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] | 34 | * encrypted private key) key pair. |
Alexander Afanasyev | e96538a | 2018-06-13 20:32:53 -0400 | [diff] [blame] | 35 | * |
Alexander Afanasyev | 1a21e10 | 2018-06-13 20:33:21 -0400 | [diff] [blame] | 36 | * @todo Rolling KEK |
Alexander Afanasyev | e96538a | 2018-06-13 20:32:53 -0400 | [diff] [blame] | 37 | */ |
| 38 | class AccessManager |
| 39 | { |
| 40 | public: |
| 41 | class Error : public std::runtime_error |
| 42 | { |
| 43 | public: |
| 44 | using std::runtime_error::runtime_error; |
| 45 | }; |
| 46 | |
| 47 | public: |
| 48 | /** |
Alexander Afanasyev | e96538a | 2018-06-13 20:32:53 -0400 | [diff] [blame] | 49 | * @param identity Data owner's namespace identity (will be used to sign KEK and KDK) |
| 50 | * @param dataset Name of dataset that this manager is controlling |
| 51 | * @param keyChain KeyChain |
| 52 | * @param face Face that will be used to publish KEK and KDKs |
| 53 | * |
Alexander Afanasyev | 1a21e10 | 2018-06-13 20:33:21 -0400 | [diff] [blame] | 54 | * KEK and KDK naming: |
Alexander Afanasyev | e96538a | 2018-06-13 20:32:53 -0400 | [diff] [blame] | 55 | * |
Alexander Afanasyev | 1a21e10 | 2018-06-13 20:33:21 -0400 | [diff] [blame] | 56 | * [identity]/NAC/[dataset]/KEK /[key-id] (== KEK, public key) |
Alexander Afanasyev | e96538a | 2018-06-13 20:32:53 -0400 | [diff] [blame] | 57 | * |
Alexander Afanasyev | 1a21e10 | 2018-06-13 20:33:21 -0400 | [diff] [blame] | 58 | * [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] | 59 | * |
| 60 | * \_____________ ______________/ |
| 61 | * \/ |
| 62 | * registered with NFD |
| 63 | * |
| 64 | * AccessManager serves NAC public key for data producers to fetch and encrypted versions of |
| 65 | * private keys (as safe bags) for authorized consumers to fetch. |
| 66 | */ |
| 67 | AccessManager(const Identity& identity, const Name& dataset, |
| 68 | KeyChain& keyChain, Face& face); |
| 69 | |
Alexander Afanasyev | e96538a | 2018-06-13 20:32:53 -0400 | [diff] [blame] | 70 | /** |
| 71 | * @brief Authorize a member identified by its certificate @p memberCert to decrypt data |
| 72 | * under the policy |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 73 | * @return published KDK |
Alexander Afanasyev | e96538a | 2018-06-13 20:32:53 -0400 | [diff] [blame] | 74 | */ |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 75 | Data |
Alexander Afanasyev | e96538a | 2018-06-13 20:32:53 -0400 | [diff] [blame] | 76 | addMember(const Certificate& memberCert); |
| 77 | |
| 78 | // void |
| 79 | // addMemberWithKey(const Name& keyName); |
| 80 | |
| 81 | // void |
| 82 | // addMemberWithIdentity(const Name& identityName); |
| 83 | |
| 84 | /** |
| 85 | * @brief Remove member with name @p identity from the group |
| 86 | */ |
| 87 | void |
| 88 | removeMember(const Name& identity); |
| 89 | |
| 90 | public: // accessor interface for published data packets |
| 91 | |
| 92 | /** @return{ number of packets stored in in-memory storage } |
| 93 | */ |
| 94 | size_t |
| 95 | size() const |
| 96 | { |
| 97 | return m_ims.size(); |
| 98 | } |
| 99 | |
Alexander Afanasyev | 1a21e10 | 2018-06-13 20:33:21 -0400 | [diff] [blame] | 100 | /** @brief Returns begin iterator of the in-memory storage ordered by |
Alexander Afanasyev | e96538a | 2018-06-13 20:32:53 -0400 | [diff] [blame] | 101 | * name with digest |
| 102 | * |
Alexander Afanasyev | 1a21e10 | 2018-06-13 20:33:21 -0400 | [diff] [blame] | 103 | * @return{ const_iterator pointing to the beginning of m_cache } |
Alexander Afanasyev | e96538a | 2018-06-13 20:32:53 -0400 | [diff] [blame] | 104 | */ |
| 105 | InMemoryStorage::const_iterator |
| 106 | begin() const |
| 107 | { |
| 108 | return m_ims.begin(); |
| 109 | } |
| 110 | |
Alexander Afanasyev | 1a21e10 | 2018-06-13 20:33:21 -0400 | [diff] [blame] | 111 | /** @brief Returns end iterator of the in-memory storage ordered by |
Alexander Afanasyev | e96538a | 2018-06-13 20:32:53 -0400 | [diff] [blame] | 112 | * name with digest |
| 113 | * |
Alexander Afanasyev | 1a21e10 | 2018-06-13 20:33:21 -0400 | [diff] [blame] | 114 | * @return{ const_iterator pointing to the end of m_cache } |
Alexander Afanasyev | e96538a | 2018-06-13 20:32:53 -0400 | [diff] [blame] | 115 | */ |
| 116 | InMemoryStorage::const_iterator |
| 117 | end() const |
| 118 | { |
| 119 | return m_ims.end(); |
| 120 | } |
| 121 | |
| 122 | private: |
| 123 | Identity m_identity; |
| 124 | Key m_nacKey; |
| 125 | KeyChain& m_keyChain; |
| 126 | Face& m_face; |
| 127 | |
Alexander Afanasyev | 1a21e10 | 2018-06-13 20:33:21 -0400 | [diff] [blame] | 128 | InMemoryStoragePersistent m_ims; // for KEK and KDKs |
Davide Pesavento | d51d960 | 2019-07-20 23:33:06 -0400 | [diff] [blame] | 129 | ScopedRegisteredPrefixHandle m_kekReg; |
| 130 | ScopedRegisteredPrefixHandle m_kdkReg; |
Alexander Afanasyev | e96538a | 2018-06-13 20:32:53 -0400 | [diff] [blame] | 131 | }; |
| 132 | |
Davide Pesavento | bde084f | 2022-04-17 00:21:35 -0400 | [diff] [blame] | 133 | } // namespace ndn::nac |
Alexander Afanasyev | e96538a | 2018-06-13 20:32:53 -0400 | [diff] [blame] | 134 | |
| 135 | #endif // NDN_NAC_ACCESS_MANAGER_HPP |