blob: 22dc2cceecba04c68bd735ceefeaedd33f1617ea [file] [log] [blame]
Alexander Afanasyeve96538a2018-06-13 20:32:53 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventod51d9602019-07-20 23:33:06 -04002/*
Davide Pesavento3c7f6452021-10-02 04:06:26 -04003 * Copyright (c) 2014-2021, Regents of the University of California
Alexander Afanasyeve96538a2018-06-13 20:32:53 -04004 *
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
27namespace ndn {
28namespace 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 Afanasyev1a21e102018-06-13 20:33:21 -040035 * encrypted private key) key pair.
Alexander Afanasyeve96538a2018-06-13 20:32:53 -040036 *
Alexander Afanasyev1a21e102018-06-13 20:33:21 -040037 * @todo Rolling KEK
Alexander Afanasyeve96538a2018-06-13 20:32:53 -040038 */
39class AccessManager
40{
41public:
42 class Error : public std::runtime_error
43 {
44 public:
45 using std::runtime_error::runtime_error;
46 };
47
48public:
49 /**
Alexander Afanasyeve96538a2018-06-13 20:32:53 -040050 * @param identity Data owner's namespace identity (will be used to sign KEK and KDK)
51 * @param dataset Name of dataset that this manager is controlling
52 * @param keyChain KeyChain
53 * @param face Face that will be used to publish KEK and KDKs
54 *
Alexander Afanasyev1a21e102018-06-13 20:33:21 -040055 * KEK and KDK naming:
Alexander Afanasyeve96538a2018-06-13 20:32:53 -040056 *
Alexander Afanasyev1a21e102018-06-13 20:33:21 -040057 * [identity]/NAC/[dataset]/KEK /[key-id] (== KEK, public key)
Alexander Afanasyeve96538a2018-06-13 20:32:53 -040058 *
Alexander Afanasyev1a21e102018-06-13 20:33:21 -040059 * [identity]/NAC/[dataset]/KDK/[key-id] /ENCRYPTED-BY/[user]/KEY/[key-id] (== KDK, encrypted private key)
Alexander Afanasyeve96538a2018-06-13 20:32:53 -040060 *
61 * \_____________ ______________/
62 * \/
63 * registered with NFD
64 *
65 * AccessManager serves NAC public key for data producers to fetch and encrypted versions of
66 * private keys (as safe bags) for authorized consumers to fetch.
67 */
68 AccessManager(const Identity& identity, const Name& dataset,
69 KeyChain& keyChain, Face& face);
70
Alexander Afanasyeve96538a2018-06-13 20:32:53 -040071 /**
72 * @brief Authorize a member identified by its certificate @p memberCert to decrypt data
73 * under the policy
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040074 * @return published KDK
Alexander Afanasyeve96538a2018-06-13 20:32:53 -040075 */
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040076 Data
Alexander Afanasyeve96538a2018-06-13 20:32:53 -040077 addMember(const Certificate& memberCert);
78
79 // void
80 // addMemberWithKey(const Name& keyName);
81
82 // void
83 // addMemberWithIdentity(const Name& identityName);
84
85 /**
86 * @brief Remove member with name @p identity from the group
87 */
88 void
89 removeMember(const Name& identity);
90
91public: // accessor interface for published data packets
92
93 /** @return{ number of packets stored in in-memory storage }
94 */
95 size_t
96 size() const
97 {
98 return m_ims.size();
99 }
100
Alexander Afanasyev1a21e102018-06-13 20:33:21 -0400101 /** @brief Returns begin iterator of the in-memory storage ordered by
Alexander Afanasyeve96538a2018-06-13 20:32:53 -0400102 * name with digest
103 *
Alexander Afanasyev1a21e102018-06-13 20:33:21 -0400104 * @return{ const_iterator pointing to the beginning of m_cache }
Alexander Afanasyeve96538a2018-06-13 20:32:53 -0400105 */
106 InMemoryStorage::const_iterator
107 begin() const
108 {
109 return m_ims.begin();
110 }
111
Alexander Afanasyev1a21e102018-06-13 20:33:21 -0400112 /** @brief Returns end iterator of the in-memory storage ordered by
Alexander Afanasyeve96538a2018-06-13 20:32:53 -0400113 * name with digest
114 *
Alexander Afanasyev1a21e102018-06-13 20:33:21 -0400115 * @return{ const_iterator pointing to the end of m_cache }
Alexander Afanasyeve96538a2018-06-13 20:32:53 -0400116 */
117 InMemoryStorage::const_iterator
118 end() const
119 {
120 return m_ims.end();
121 }
122
123private:
124 Identity m_identity;
125 Key m_nacKey;
126 KeyChain& m_keyChain;
127 Face& m_face;
128
Alexander Afanasyev1a21e102018-06-13 20:33:21 -0400129 InMemoryStoragePersistent m_ims; // for KEK and KDKs
Davide Pesaventod51d9602019-07-20 23:33:06 -0400130 ScopedRegisteredPrefixHandle m_kekReg;
131 ScopedRegisteredPrefixHandle m_kdkReg;
Alexander Afanasyeve96538a2018-06-13 20:32:53 -0400132};
133
134} // namespace nac
135} // namespace ndn
136
137#endif // NDN_NAC_ACCESS_MANAGER_HPP