blob: fd8d7cb8214c5af1df7ce12882d3c884829e3e0b [file] [log] [blame]
Yingdi Yu151b5572015-04-27 11:07:37 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2015 Regents of the University of California.
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
22#ifndef NDN_SECURITY_PIB_HPP
23#define NDN_SECURITY_PIB_HPP
24
Yingdi Yub8f8b342015-04-27 11:06:42 -070025#include "identity-container.hpp"
Yingdi Yu151b5572015-04-27 11:07:37 -070026
27namespace ndn {
Yingdi Yub8f8b342015-04-27 11:06:42 -070028class KeyChain;
29
Yingdi Yu151b5572015-04-27 11:07:37 -070030namespace security {
31
Yingdi Yub8f8b342015-04-27 11:06:42 -070032class PibImpl;
33
Yingdi Yu151b5572015-04-27 11:07:37 -070034/**
35 * @brief represents the PIB
36 *
37 * The PIB (Public Information Base) stores the public portion of a user's cryptography keys.
38 * The format and location of stored information is indicated by the PibLocator.
39 * The PIB is designed to work with a TPM (Trusted Platform Module) which stores private keys.
40 * There is a one-to-one association between PIB and TPM, and therefore the TpmLocator is recorded
41 * by the PIB to enforce this association and prevent one from operating on mismatched PIB and TPM.
42 *
43 * Information in the PIB is organized in a hierarchy of Identity-Key-Certificate. At the top level,
44 * the Pib class provides access to identities, and allows setting a default identity. Properties of
45 * an identity can be accessed after obtaining an Identity object.
46 *
47 * @throw PibImpl::Error when underlying implementation has non-semantic error.
48 */
49class Pib : noncopyable
50{
51public:
Yingdi Yub8f8b342015-04-27 11:06:42 -070052 friend class KeyChain;
53
54public:
Yingdi Yu151b5572015-04-27 11:07:37 -070055 /// @brief represents a semantic error
56 class Error : public std::runtime_error
57 {
58 public:
59 explicit
60 Error(const std::string& what)
61 : std::runtime_error(what)
62 {
63 }
64 };
65
Yingdi Yub8f8b342015-04-27 11:06:42 -070066public:
67
68 ~Pib();
69
70 /**
71 * @brief return the scheme of the PibLocator
72 */
73 std::string
74 getScheme() const
75 {
76 return m_scheme;
77 }
78
79 /**
80 * @brief Get PIB Locator
81 */
82 std::string
83 getPibLocator() const;
84
85 /**
86 * @brief Set the corresponding TPM information to @p tpmLocator.
87 *
88 * If the provided @p tpmLocator is different from the existing one, the
89 * PIB will be reset, otherwise nothing will be changed.
90 *
91 * @param tmpLocator The name for the new tmpLocator
92 */
93 void
94 setTpmLocator(const std::string& tpmLocator);
95
96 /**
97 * @brief Get TPM Locator
98 */
99 std::string
100 getTpmLocator() const;
101
102 /*
103 * @brief Create an identity with name @p identityName and return a reference to it.
104 *
105 * If there already exists an identity for the name @p identityName, then it is returned.
106 * If no default identity is set, the newly created identity will be set as the default.
107 *
108 * @param identityName The name for the identity to be added
109 */
110 Identity
111 addIdentity(const Name& identityName);
112
113 /*
114 * @brief Remove an identity with name @p identityName.
115 *
116 * @param identityName The name for the identity to be deleted
117 */
118 void
119 removeIdentity(const Name& identityName);
120
121 /**
122 * @brief Get an identity with name @p identityName.
123 *
124 * @param identityName The name for the identity to get.
125 * @throw Pib::Error if the identity does not exist.
126 */
127 Identity
128 getIdentity(const Name& identityName);
129
130 /// @brief Get all the identities
131 IdentityContainer
132 getIdentities() const;
133
134 /**
135 * @brief Set an identity with name @p identityName as the default identity.
136 *
137 * Also create the identity if it does not exist.
138 *
139 * @param identityName The name for the default identity.
140 * @return the default identity
141 */
142 Identity
143 setDefaultIdentity(const Name& identityName);
144
145 /**
146 * @brief Get the default identity.
147 *
148 * @return the default identity.
149 * @throws Pib::Error if no default identity.
150 */
151 Identity
152 getDefaultIdentity();
153
154NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
155 /*
156 * @brief Create a new Pib with the specified @p location
157 *
158 * @param scheme The scheme for the Pib
159 * @param location The location for the Pib
160 * @param impl The backend implementation
161 */
162 Pib(const std::string scheme, const std::string& location, shared_ptr<PibImpl> impl);
163
164 shared_ptr<PibImpl>
165 getImpl()
166 {
167 return m_impl;
168 }
169
170protected:
171 std::string m_scheme;
172 std::string m_location;
173 shared_ptr<PibImpl> m_impl;
Yingdi Yu151b5572015-04-27 11:07:37 -0700174};
175
176} // namespace security
177} // namespace ndn
178
179#endif // NDN_SECURITY_PIB_HPP