Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 68b5385 | 2018-07-25 13:56:38 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013-2018 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: |
Yingdi Yu | fe4733a | 2015-10-22 14:24:12 -0700 | [diff] [blame] | 40 | /** |
| 41 | * @brief Create memory based PIB backend |
| 42 | * @param location Not used (required by the PIB-registration interface) |
| 43 | */ |
| 44 | explicit |
| 45 | PibMemory(const std::string& location = ""); |
| 46 | |
| 47 | static const std::string& |
| 48 | getScheme(); |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 49 | |
| 50 | public: // TpmLocator management |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 51 | void |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 52 | setTpmLocator(const std::string& tpmLocator) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 53 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 54 | std::string |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 55 | getTpmLocator() const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 56 | |
| 57 | public: // Identity management |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 58 | bool |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 59 | hasIdentity(const Name& identity) const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 60 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 61 | void |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 62 | addIdentity(const Name& identity) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 63 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 64 | void |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 65 | removeIdentity(const Name& identity) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 66 | |
Yingdi Yu | 7b3b5e9 | 2015-08-13 19:52:35 -0700 | [diff] [blame] | 67 | void |
| 68 | clearIdentities() override; |
| 69 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 70 | std::set<Name> |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 71 | getIdentities() const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 72 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 73 | void |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 74 | setDefaultIdentity(const Name& identityName) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 75 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 76 | Name |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 77 | getDefaultIdentity() const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 78 | |
| 79 | public: // Key management |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 80 | bool |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 81 | hasKey(const Name& keyName) const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 82 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 83 | void |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 84 | 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] | 85 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 86 | void |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 87 | removeKey(const Name& keyName) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 88 | |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 89 | Buffer |
| 90 | getKeyBits(const Name& keyName) const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 91 | |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 92 | std::set<Name> |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 93 | getKeysOfIdentity(const Name& identity) const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 94 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 95 | void |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 96 | setDefaultKeyOfIdentity(const Name& identity, const Name& keyName) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 97 | |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 98 | Name |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 99 | getDefaultKeyOfIdentity(const Name& identity) const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 100 | |
| 101 | public: // Certificate management |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 102 | bool |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 103 | hasCertificate(const Name& certName) const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 104 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 105 | void |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 106 | addCertificate(const v2::Certificate& certificate) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 107 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 108 | void |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 109 | removeCertificate(const Name& certName) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 110 | |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 111 | v2::Certificate |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 112 | getCertificate(const Name& certName) const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 113 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 114 | std::set<Name> |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 115 | getCertificatesOfKey(const Name& keyName) const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 116 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 117 | void |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 118 | setDefaultCertificateOfKey(const Name& keyName, const Name& certName) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 119 | |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 120 | v2::Certificate |
| 121 | getDefaultCertificateOfKey(const Name& keyName) const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 122 | |
| 123 | private: |
Yingdi Yu | 7b3b5e9 | 2015-08-13 19:52:35 -0700 | [diff] [blame] | 124 | std::string m_tpmLocator; |
| 125 | |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 126 | bool m_hasDefaultIdentity; |
| 127 | Name m_defaultIdentity; |
| 128 | |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 129 | std::set<Name> m_identities; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 130 | |
| 131 | /// @brief identity => default key Name |
Yingdi Yu | 0399768 | 2015-11-23 16:41:38 -0800 | [diff] [blame] | 132 | std::map<Name, Name> m_defaultKeys; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 133 | |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 134 | /// @brief keyName => keyBits |
| 135 | std::map<Name, Buffer> m_keys; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 136 | |
| 137 | /// @brief keyName => default certificate Name |
Yingdi Yu | 0399768 | 2015-11-23 16:41:38 -0800 | [diff] [blame] | 138 | std::map<Name, Name> m_defaultCerts; |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 139 | |
| 140 | /// @brief certificate Name => certificate |
| 141 | std::map<Name, v2::Certificate> m_certs; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 142 | }; |
| 143 | |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 144 | } // namespace pib |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 145 | } // namespace security |
| 146 | } // namespace ndn |
| 147 | |
Alexander Afanasyev | 97709c0 | 2016-08-25 19:58:30 -0700 | [diff] [blame] | 148 | #endif // NDN_SECURITY_PIB_PIB_MEMORY_HPP |