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 | 3bf91f5 | 2015-06-12 19:39:40 -0700 | [diff] [blame] | 51 | PibMemory(); |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 52 | |
| 53 | public: // TpmLocator management |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 54 | void |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 55 | setTpmLocator(const std::string& tpmLocator) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 56 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 57 | std::string |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 58 | getTpmLocator() const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 59 | |
| 60 | public: // Identity management |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 61 | bool |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 62 | hasIdentity(const Name& identity) const 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 | addIdentity(const Name& identity) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 66 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 67 | void |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 68 | removeIdentity(const Name& identity) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 69 | |
Yingdi Yu | 7b3b5e9 | 2015-08-13 19:52:35 -0700 | [diff] [blame] | 70 | void |
| 71 | clearIdentities() override; |
| 72 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 73 | std::set<Name> |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 74 | getIdentities() const 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 | void |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 77 | setDefaultIdentity(const Name& identityName) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 78 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 79 | Name |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 80 | getDefaultIdentity() const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 81 | |
| 82 | public: // Key management |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 83 | bool |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 84 | hasKey(const Name& keyName) const 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 | 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] | 88 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 89 | void |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 90 | removeKey(const Name& keyName) 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 | Buffer |
| 93 | getKeyBits(const Name& keyName) const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 94 | |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 95 | std::set<Name> |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 96 | getKeysOfIdentity(const Name& identity) const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 97 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 98 | void |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 99 | setDefaultKeyOfIdentity(const Name& identity, const Name& keyName) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 100 | |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 101 | Name |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 102 | getDefaultKeyOfIdentity(const Name& identity) const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 103 | |
| 104 | public: // Certificate management |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 105 | bool |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 106 | hasCertificate(const Name& certName) const 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 |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 109 | addCertificate(const v2::Certificate& certificate) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 110 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 111 | void |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 112 | removeCertificate(const Name& certName) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 113 | |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 114 | v2::Certificate |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 115 | getCertificate(const Name& certName) 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 | std::set<Name> |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 118 | getCertificatesOfKey(const Name& keyName) const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 119 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 120 | void |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 121 | setDefaultCertificateOfKey(const Name& keyName, const Name& certName) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 122 | |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 123 | v2::Certificate |
| 124 | getDefaultCertificateOfKey(const Name& keyName) const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 125 | |
| 126 | private: |
Yingdi Yu | 7b3b5e9 | 2015-08-13 19:52:35 -0700 | [diff] [blame] | 127 | std::string m_tpmLocator; |
| 128 | |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 129 | bool m_hasDefaultIdentity; |
| 130 | Name m_defaultIdentity; |
| 131 | |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 132 | std::set<Name> m_identities; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 133 | |
| 134 | /// @brief identity => default key Name |
Yingdi Yu | 0399768 | 2015-11-23 16:41:38 -0800 | [diff] [blame^] | 135 | std::map<Name, Name> m_defaultKeys; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 136 | |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 137 | /// @brief keyName => keyBits |
| 138 | std::map<Name, Buffer> m_keys; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 139 | |
| 140 | /// @brief keyName => default certificate Name |
Yingdi Yu | 0399768 | 2015-11-23 16:41:38 -0800 | [diff] [blame^] | 141 | std::map<Name, Name> m_defaultCerts; |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 142 | |
| 143 | /// @brief certificate Name => certificate |
| 144 | std::map<Name, v2::Certificate> m_certs; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 145 | }; |
| 146 | |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame] | 147 | } // namespace pib |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 148 | } // namespace security |
| 149 | } // namespace ndn |
| 150 | |
Alexander Afanasyev | 97709c0 | 2016-08-25 19:58:30 -0700 | [diff] [blame] | 151 | #endif // NDN_SECURITY_PIB_PIB_MEMORY_HPP |