Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 3 | * Copyright (c) 2013-2016 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 | |
Yingdi Yu | 3bf91f5 | 2015-06-12 19:39:40 -0700 | [diff] [blame] | 22 | #ifndef NDN_SECURITY_PIB_MEMORY_HPP |
| 23 | #define NDN_SECURITY_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 { |
| 29 | |
| 30 | /** |
| 31 | * @brief An in-memory implementation of Pib |
| 32 | * |
| 33 | * All the contents in Pib are stored in memory |
| 34 | * and have the same lifetime as the implementation instance. |
| 35 | */ |
Yingdi Yu | 3bf91f5 | 2015-06-12 19:39:40 -0700 | [diff] [blame] | 36 | class PibMemory : public PibImpl |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 37 | { |
| 38 | public: |
| 39 | class Error : public PibImpl::Error |
| 40 | { |
| 41 | public: |
| 42 | explicit |
| 43 | Error(const std::string& what) |
| 44 | : PibImpl::Error(what) |
| 45 | { |
| 46 | } |
| 47 | }; |
| 48 | |
| 49 | public: |
Yingdi Yu | 3bf91f5 | 2015-06-12 19:39:40 -0700 | [diff] [blame] | 50 | PibMemory(); |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 51 | |
| 52 | public: // TpmLocator management |
| 53 | |
| 54 | virtual 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 | |
| 57 | virtual 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 |
| 61 | |
| 62 | virtual bool |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 63 | hasIdentity(const Name& identity) const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 64 | |
| 65 | virtual void |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 66 | addIdentity(const Name& identity) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 67 | |
| 68 | virtual void |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 69 | removeIdentity(const Name& identity) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 70 | |
| 71 | virtual std::set<Name> |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 72 | getIdentities() const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 73 | |
| 74 | virtual void |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 75 | setDefaultIdentity(const Name& identityName) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 76 | |
| 77 | virtual Name |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 78 | getDefaultIdentity() const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 79 | |
| 80 | public: // Key management |
| 81 | |
| 82 | virtual bool |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 83 | hasKey(const Name& identity, const name::Component& keyId) const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 84 | |
| 85 | virtual void |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 86 | addKey(const Name& identity, const name::Component& keyId, const v1::PublicKey& publicKey) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 87 | |
| 88 | virtual void |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 89 | removeKey(const Name& identity, const name::Component& keyId) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 90 | |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 91 | virtual v1::PublicKey |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 92 | getKeyBits(const Name& identity, const name::Component& keyId) const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 93 | |
| 94 | virtual std::set<name::Component> |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 95 | getKeysOfIdentity(const Name& identity) const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 96 | |
| 97 | virtual void |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 98 | setDefaultKeyOfIdentity(const Name& identity, const name::Component& keyId) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 99 | |
| 100 | virtual name::Component |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 101 | getDefaultKeyOfIdentity(const Name& identity) const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 102 | |
| 103 | public: // Certificate management |
| 104 | |
| 105 | virtual 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 | |
| 108 | virtual void |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 109 | addCertificate(const v1::IdentityCertificate& certificate) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 110 | |
| 111 | virtual 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 | |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 114 | virtual v1::IdentityCertificate |
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 | |
| 117 | virtual std::set<Name> |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 118 | getCertificatesOfKey(const Name& identity, const name::Component& keyId) const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 119 | |
| 120 | virtual void |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 121 | setDefaultCertificateOfKey(const Name& identity, const name::Component& keyId, const Name& certName) override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 122 | |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 123 | virtual v1::IdentityCertificate |
Davide Pesavento | aa82eb6 | 2016-04-22 19:08:40 +0200 | [diff] [blame] | 124 | getDefaultCertificateOfKey(const Name& identity, const name::Component& keyId) const override; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 125 | |
| 126 | private: // Key management |
| 127 | |
| 128 | Name |
| 129 | getKeyName(const Name& identity, const name::Component& keyId) const; |
| 130 | |
| 131 | private: |
| 132 | |
| 133 | std::set<Name> m_identities; |
| 134 | bool m_hasDefaultIdentity; |
| 135 | Name m_defaultIdentity; |
| 136 | |
| 137 | /// @brief keyName => keyBits |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 138 | std::map<Name, v1::PublicKey> m_keys; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 139 | |
| 140 | /// @brief identity => default key Name |
| 141 | std::map<Name, Name> m_defaultKey; |
| 142 | |
| 143 | /// @brief certificate Name => certificate |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 144 | std::map<Name, v1::IdentityCertificate> m_certs; |
Yingdi Yu | adadb71 | 2015-04-15 17:23:56 -0700 | [diff] [blame] | 145 | |
| 146 | /// @brief keyName => default certificate Name |
| 147 | std::map<Name, Name> m_defaultCert; |
| 148 | }; |
| 149 | |
| 150 | } // namespace security |
| 151 | } // namespace ndn |
| 152 | |
Yingdi Yu | 3bf91f5 | 2015-06-12 19:39:40 -0700 | [diff] [blame] | 153 | #endif // NDN_SECURITY_PIB_MEMORY_HPP |