Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 3 | * Copyright (c) 2013-2017 Regents of the University of California. |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 20 | */ |
| 21 | |
Alexander Afanasyev | 97709c0 | 2016-08-25 19:58:30 -0700 | [diff] [blame] | 22 | #ifndef NDN_SECURITY_PIB_PIB_MEMORY_HPP |
| 23 | #define NDN_SECURITY_PIB_PIB_MEMORY_HPP |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 24 | |
| 25 | #include "pib-impl.hpp" |
| 26 | |
| 27 | namespace ndn { |
| 28 | namespace security { |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 29 | namespace pib { |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * @brief An in-memory implementation of Pib |
| 33 | * |
| 34 | * All the contents in Pib are stored in memory |
| 35 | * and have the same lifetime as the implementation instance. |
| 36 | */ |
Yingdi Yu | 3bf91f5 | 2015-06-12 19:39:40 -0700 | [diff] [blame] | 37 | class PibMemory : public PibImpl |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 38 | { |
| 39 | public: |
| 40 | class Error : public PibImpl::Error |
| 41 | { |
| 42 | public: |
| 43 | explicit |
| 44 | Error(const std::string& what) |
| 45 | : PibImpl::Error(what) |
| 46 | { |
| 47 | } |
| 48 | }; |
| 49 | |
| 50 | public: |
Yingdi Yu | fe4733a | 2015-10-22 14:24:12 -0700 | [diff] [blame] | 51 | /** |
| 52 | * @brief Create memory based PIB backend |
| 53 | * @param location Not used (required by the PIB-registration interface) |
| 54 | */ |
| 55 | explicit |
| 56 | PibMemory(const std::string& location = ""); |
| 57 | |
| 58 | static const std::string& |
| 59 | getScheme(); |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 60 | |
| 61 | public: // TpmLocator management |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 62 | void |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 63 | setTpmLocator(const std::string& tpmLocator) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 64 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 65 | std::string |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 66 | getTpmLocator() const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 67 | |
| 68 | public: // Identity management |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 69 | bool |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 70 | hasIdentity(const Name& identity) const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 71 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 72 | void |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 73 | addIdentity(const Name& identity) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 74 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 75 | void |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 76 | removeIdentity(const Name& identity) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 77 | |
Yingdi Yu | 7b3b5e9 | 2015-08-13 19:52:35 -0700 | [diff] [blame] | 78 | void |
| 79 | clearIdentities() override; |
| 80 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 81 | std::set<Name> |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 82 | getIdentities() const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 83 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 84 | void |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 85 | setDefaultIdentity(const Name& identityName) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 86 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 87 | Name |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 88 | getDefaultIdentity() const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 89 | |
| 90 | public: // Key management |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 91 | bool |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 92 | hasKey(const Name& keyName) const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 93 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 94 | void |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 95 | addKey(const Name& identity, const Name& keyName, const uint8_t* key, size_t keyLen) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 96 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 97 | void |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 98 | removeKey(const Name& keyName) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 99 | |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 100 | Buffer |
| 101 | getKeyBits(const Name& keyName) const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 102 | |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 103 | std::set<Name> |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 104 | getKeysOfIdentity(const Name& identity) const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 105 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 106 | void |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 107 | setDefaultKeyOfIdentity(const Name& identity, const Name& keyName) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 108 | |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 109 | Name |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 110 | getDefaultKeyOfIdentity(const Name& identity) const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 111 | |
| 112 | public: // Certificate management |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 113 | bool |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 114 | hasCertificate(const Name& certName) const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 115 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 116 | void |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 117 | addCertificate(const v2::Certificate& certificate) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 118 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 119 | void |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 120 | removeCertificate(const Name& certName) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 121 | |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 122 | v2::Certificate |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 123 | getCertificate(const Name& certName) const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 124 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 125 | std::set<Name> |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 126 | getCertificatesOfKey(const Name& keyName) const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 127 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 128 | void |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 129 | setDefaultCertificateOfKey(const Name& keyName, const Name& certName) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 130 | |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 131 | v2::Certificate |
| 132 | getDefaultCertificateOfKey(const Name& keyName) const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 133 | |
| 134 | private: |
Yingdi Yu | 7b3b5e9 | 2015-08-13 19:52:35 -0700 | [diff] [blame] | 135 | std::string m_tpmLocator; |
| 136 | |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 137 | bool m_hasDefaultIdentity; |
| 138 | Name m_defaultIdentity; |
| 139 | |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 140 | std::set<Name> m_identities; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 141 | |
| 142 | /// @brief identity => default key Name |
Yingdi Yu | 0399768 | 2015-11-23 16:41:38 -0800 | [diff] [blame] | 143 | std::map<Name, Name> m_defaultKeys; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 144 | |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 145 | /// @brief keyName => keyBits |
| 146 | std::map<Name, Buffer> m_keys; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 147 | |
| 148 | /// @brief keyName => default certificate Name |
Yingdi Yu | 0399768 | 2015-11-23 16:41:38 -0800 | [diff] [blame] | 149 | std::map<Name, Name> m_defaultCerts; |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 150 | |
| 151 | /// @brief certificate Name => certificate |
| 152 | std::map<Name, v2::Certificate> m_certs; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 153 | }; |
| 154 | |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 155 | } // namespace pib |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 156 | } // namespace security |
| 157 | } // namespace ndn |
| 158 | |
Alexander Afanasyev | 97709c0 | 2016-08-25 19:58:30 -0700 | [diff] [blame] | 159 | #endif // NDN_SECURITY_PIB_PIB_MEMORY_HPP |