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 |
| 54 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 55 | void |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 56 | setTpmLocator(const std::string& tpmLocator) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 57 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 58 | std::string |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 59 | getTpmLocator() const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 60 | |
| 61 | public: // Identity management |
| 62 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 63 | bool |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 64 | hasIdentity(const Name& identity) const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 65 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 66 | void |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 67 | addIdentity(const Name& identity) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 68 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 69 | void |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 70 | removeIdentity(const Name& identity) 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 | std::set<Name> |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 73 | getIdentities() const 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 | setDefaultIdentity(const Name& identityName) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 77 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 78 | Name |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 79 | getDefaultIdentity() const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 80 | |
| 81 | public: // Key management |
| 82 | |
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 | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 127 | bool m_hasDefaultIdentity; |
| 128 | Name m_defaultIdentity; |
| 129 | |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame^] | 130 | std::set<Name> m_identities; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 131 | |
| 132 | /// @brief identity => default key Name |
| 133 | std::map<Name, Name> m_defaultKey; |
| 134 | |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame^] | 135 | /// @brief keyName => keyBits |
| 136 | std::map<Name, Buffer> m_keys; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 137 | |
| 138 | /// @brief keyName => default certificate Name |
| 139 | std::map<Name, Name> m_defaultCert; |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame^] | 140 | |
| 141 | /// @brief certificate Name => certificate |
| 142 | std::map<Name, v2::Certificate> m_certs; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 143 | }; |
| 144 | |
Yingdi Yu | 6ee2d36 | 2015-07-16 21:48:05 -0700 | [diff] [blame^] | 145 | } // namespace pib |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 146 | } // namespace security |
| 147 | } // namespace ndn |
| 148 | |
Alexander Afanasyev | 97709c0 | 2016-08-25 19:58:30 -0700 | [diff] [blame] | 149 | #endif // NDN_SECURITY_PIB_PIB_MEMORY_HPP |