blob: 12529091cbeb71e7130f791baa3e488ab41e2554 [file] [log] [blame]
Yingdi Yuadadb712015-04-15 17:23:56 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Yingdi Yu6ee2d362015-07-16 21:48:05 -07003 * Copyright (c) 2013-2017 Regents of the University of California.
Yingdi Yuadadb712015-04-15 17:23:56 -07004 *
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 Afanasyev97709c02016-08-25 19:58:30 -070022#ifndef NDN_SECURITY_PIB_PIB_MEMORY_HPP
23#define NDN_SECURITY_PIB_PIB_MEMORY_HPP
Yingdi Yuadadb712015-04-15 17:23:56 -070024
25#include "pib-impl.hpp"
26
27namespace ndn {
28namespace security {
Yingdi Yu6ee2d362015-07-16 21:48:05 -070029namespace pib {
Yingdi Yuadadb712015-04-15 17:23:56 -070030
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 Yu3bf91f52015-06-12 19:39:40 -070037class PibMemory : public PibImpl
Yingdi Yuadadb712015-04-15 17:23:56 -070038{
39public:
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
50public:
Yingdi Yufe4733a2015-10-22 14:24:12 -070051 /**
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 Yuadadb712015-04-15 17:23:56 -070060
61public: // TpmLocator management
Davide Pesavento57c07df2016-12-11 18:41:45 -050062 void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020063 setTpmLocator(const std::string& tpmLocator) override;
Yingdi Yuadadb712015-04-15 17:23:56 -070064
Davide Pesavento57c07df2016-12-11 18:41:45 -050065 std::string
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020066 getTpmLocator() const override;
Yingdi Yuadadb712015-04-15 17:23:56 -070067
68public: // Identity management
Davide Pesavento57c07df2016-12-11 18:41:45 -050069 bool
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020070 hasIdentity(const Name& identity) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -070071
Davide Pesavento57c07df2016-12-11 18:41:45 -050072 void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020073 addIdentity(const Name& identity) override;
Yingdi Yuadadb712015-04-15 17:23:56 -070074
Davide Pesavento57c07df2016-12-11 18:41:45 -050075 void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020076 removeIdentity(const Name& identity) override;
Yingdi Yuadadb712015-04-15 17:23:56 -070077
Yingdi Yu7b3b5e92015-08-13 19:52:35 -070078 void
79 clearIdentities() override;
80
Davide Pesavento57c07df2016-12-11 18:41:45 -050081 std::set<Name>
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020082 getIdentities() const override;
Yingdi Yuadadb712015-04-15 17:23:56 -070083
Davide Pesavento57c07df2016-12-11 18:41:45 -050084 void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020085 setDefaultIdentity(const Name& identityName) override;
Yingdi Yuadadb712015-04-15 17:23:56 -070086
Davide Pesavento57c07df2016-12-11 18:41:45 -050087 Name
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020088 getDefaultIdentity() const override;
Yingdi Yuadadb712015-04-15 17:23:56 -070089
90public: // Key management
Davide Pesavento57c07df2016-12-11 18:41:45 -050091 bool
Yingdi Yu6ee2d362015-07-16 21:48:05 -070092 hasKey(const Name& keyName) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -070093
Davide Pesavento57c07df2016-12-11 18:41:45 -050094 void
Yingdi Yu6ee2d362015-07-16 21:48:05 -070095 addKey(const Name& identity, const Name& keyName, const uint8_t* key, size_t keyLen) override;
Yingdi Yuadadb712015-04-15 17:23:56 -070096
Davide Pesavento57c07df2016-12-11 18:41:45 -050097 void
Yingdi Yu6ee2d362015-07-16 21:48:05 -070098 removeKey(const Name& keyName) override;
Yingdi Yuadadb712015-04-15 17:23:56 -070099
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700100 Buffer
101 getKeyBits(const Name& keyName) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700102
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700103 std::set<Name>
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200104 getKeysOfIdentity(const Name& identity) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700105
Davide Pesavento57c07df2016-12-11 18:41:45 -0500106 void
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700107 setDefaultKeyOfIdentity(const Name& identity, const Name& keyName) override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700108
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700109 Name
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200110 getDefaultKeyOfIdentity(const Name& identity) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700111
112public: // Certificate management
Davide Pesavento57c07df2016-12-11 18:41:45 -0500113 bool
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200114 hasCertificate(const Name& certName) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700115
Davide Pesavento57c07df2016-12-11 18:41:45 -0500116 void
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700117 addCertificate(const v2::Certificate& certificate) override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700118
Davide Pesavento57c07df2016-12-11 18:41:45 -0500119 void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200120 removeCertificate(const Name& certName) override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700121
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700122 v2::Certificate
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200123 getCertificate(const Name& certName) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700124
Davide Pesavento57c07df2016-12-11 18:41:45 -0500125 std::set<Name>
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700126 getCertificatesOfKey(const Name& keyName) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700127
Davide Pesavento57c07df2016-12-11 18:41:45 -0500128 void
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700129 setDefaultCertificateOfKey(const Name& keyName, const Name& certName) override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700130
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700131 v2::Certificate
132 getDefaultCertificateOfKey(const Name& keyName) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700133
134private:
Yingdi Yu7b3b5e92015-08-13 19:52:35 -0700135 std::string m_tpmLocator;
136
Yingdi Yuadadb712015-04-15 17:23:56 -0700137 bool m_hasDefaultIdentity;
138 Name m_defaultIdentity;
139
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700140 std::set<Name> m_identities;
Yingdi Yuadadb712015-04-15 17:23:56 -0700141
142 /// @brief identity => default key Name
Yingdi Yu03997682015-11-23 16:41:38 -0800143 std::map<Name, Name> m_defaultKeys;
Yingdi Yuadadb712015-04-15 17:23:56 -0700144
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700145 /// @brief keyName => keyBits
146 std::map<Name, Buffer> m_keys;
Yingdi Yuadadb712015-04-15 17:23:56 -0700147
148 /// @brief keyName => default certificate Name
Yingdi Yu03997682015-11-23 16:41:38 -0800149 std::map<Name, Name> m_defaultCerts;
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700150
151 /// @brief certificate Name => certificate
152 std::map<Name, v2::Certificate> m_certs;
Yingdi Yuadadb712015-04-15 17:23:56 -0700153};
154
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700155} // namespace pib
Yingdi Yuadadb712015-04-15 17:23:56 -0700156} // namespace security
157} // namespace ndn
158
Alexander Afanasyev97709c02016-08-25 19:58:30 -0700159#endif // NDN_SECURITY_PIB_PIB_MEMORY_HPP