blob: 4afee08e259abca72926d3be19945f1bd9813a48 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Yingdi Yu31b4af22014-01-14 14:13:00 -08002/**
Alexander Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * 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.
Yingdi Yu31b4af22014-01-14 14:13:00 -080020 */
21
Yingdi Yufc40d872014-02-18 12:56:04 -080022#ifndef NDN_SECURITY_SEC_PUBLIC_INFO_HPP
23#define NDN_SECURITY_SEC_PUBLIC_INFO_HPP
Yingdi Yu31b4af22014-01-14 14:13:00 -080024
Yingdi Yu4f324632014-01-15 18:10:03 -080025#include "../name.hpp"
26#include "security-common.hpp"
27#include "public-key.hpp"
28#include "identity-certificate.hpp"
Yingdi Yu31b4af22014-01-14 14:13:00 -080029
Yingdi Yu88663af2014-01-15 15:21:38 -080030
Yingdi Yu31b4af22014-01-14 14:13:00 -080031namespace ndn {
32
33/**
Yingdi Yu2e57a582014-02-20 23:34:43 -080034 * @brief SecPublicInfo is a base class for the storage of public information.
35 *
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070036 * It specify interfaces related to public information, such as identity, public keys and
37 * certificates.
Yingdi Yu31b4af22014-01-14 14:13:00 -080038 */
Yingdi Yuf56c68f2014-04-24 21:50:13 -070039class SecPublicInfo : noncopyable
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070040{
Yingdi Yu31b4af22014-01-14 14:13:00 -080041public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070042 class Error : public std::runtime_error
43 {
44 public:
45 explicit
46 Error(const std::string& what)
47 : std::runtime_error(what)
48 {
49 }
50 };
Yingdi Yu31b4af22014-01-14 14:13:00 -080051
Yingdi Yu41546342014-11-30 23:37:53 -080052 explicit
53 SecPublicInfo(const std::string& location);
54
Yingdi Yu31b4af22014-01-14 14:13:00 -080055 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -070056 * @brief The virtual Destructor
Yingdi Yu31b4af22014-01-14 14:13:00 -080057 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070058 virtual
Yingdi Yu41546342014-11-30 23:37:53 -080059 ~SecPublicInfo();
60
61 /**
62 * @brief Set the corresponding TPM information to @p tpmLocator
63 *
64 * If the provided @p tpmLocator is different from the existing one, the PIB will be reset,
65 * otherwise nothing will be changed.
66 *
67 * For legacy issue, the TPM info may not exist (some old PIB content may not have this info),
68 * this method will simply set the TPM info as provided without changing anything else. Thus an
69 * ideal process of handling old PIB is to check if TPM info exists. If it does not exist,
70 * then set it to the default value according to configuration.
71 */
72 virtual void
73 setTpmLocator(const std::string& tpmLocator) = 0;
74
75 /**
76 * @brief Get TPM Locator
77 *
78 * @throws SecPublicInfo::Error if the TPM info does not exist
79 */
80 virtual std::string
81 getTpmLocator() = 0;
82
83 /**
84 * @brief Get PIB Locator
85 */
86 std::string
87 getPibLocator();
Yingdi Yu31b4af22014-01-14 14:13:00 -080088
89 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -070090 * @brief Check if the specified identity already exists
Yingdi Yu2e57a582014-02-20 23:34:43 -080091 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -070092 * @param identityName The identity name
93 * @return true if the identity exists, otherwise false
Yingdi Yu31b4af22014-01-14 14:13:00 -080094 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070095 virtual bool
Yingdi Yu31b4af22014-01-14 14:13:00 -080096 doesIdentityExist(const Name& identityName) = 0;
97
98 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -070099 * @brief Add a new identity
Yingdi Yu2e57a582014-02-20 23:34:43 -0800100 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700101 * if identity already exist, do not add it again
Yingdi Yu2e57a582014-02-20 23:34:43 -0800102 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700103 * @param identityName The identity name to be added
Yingdi Yu31b4af22014-01-14 14:13:00 -0800104 */
105 virtual void
106 addIdentity(const Name& identityName) = 0;
107
108 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700109 * @brief Revoke the identity
Yingdi Yu2e57a582014-02-20 23:34:43 -0800110 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700111 * @return true if the identity was revoked, otherwise false
Yingdi Yu31b4af22014-01-14 14:13:00 -0800112 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700113 virtual bool
Yingdi Yu31b4af22014-01-14 14:13:00 -0800114 revokeIdentity() = 0;
115
116 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700117 * @brief Check if the specified key already exists
Yingdi Yu2e57a582014-02-20 23:34:43 -0800118 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700119 * @param keyName The name of the key
120 * @return true if the key exists, otherwise false
Yingdi Yu31b4af22014-01-14 14:13:00 -0800121 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700122 virtual bool
Yingdi Yu31b4af22014-01-14 14:13:00 -0800123 doesPublicKeyExist(const Name& keyName) = 0;
124
125 /**
Yingdi Yu2e57a582014-02-20 23:34:43 -0800126 * @brief Add a public key to the identity storage.
127 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700128 * @param keyName The name of the public key to be added
129 * @param keyType Type of the public key to be added
130 * @param publicKey Reference to the PublicKey object
Yingdi Yu41546342014-11-30 23:37:53 -0800131 * @deprecated Use addKey instead
Yingdi Yu31b4af22014-01-14 14:13:00 -0800132 */
Yingdi Yu41546342014-11-30 23:37:53 -0800133 DEPRECATED(
Yingdi Yu40b53092014-06-17 17:10:02 -0700134 void
Yingdi Yu41546342014-11-30 23:37:53 -0800135 addPublicKey(const Name& keyName, KeyType keyType, const PublicKey& publicKey));
Yingdi Yu40b53092014-06-17 17:10:02 -0700136
137 /**
138 * @brief Add a public key to the identity storage.
139 *
140 * @param keyName The name of the public key to be added
141 * @param publicKey Reference to the PublicKey object
142 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700143 virtual void
Yingdi Yu40b53092014-06-17 17:10:02 -0700144 addKey(const Name& keyName, const PublicKey& publicKey) = 0;
Yingdi Yu31b4af22014-01-14 14:13:00 -0800145
146 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700147 * @brief Get shared pointer to PublicKey object from the identity storage
Yingdi Yu2e57a582014-02-20 23:34:43 -0800148 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700149 * @param keyName The name of the requested public key
150 * @throws SecPublicInfo::Error if public key does not exist
Yingdi Yu31b4af22014-01-14 14:13:00 -0800151 */
Yingdi Yu2e57a582014-02-20 23:34:43 -0800152 virtual shared_ptr<PublicKey>
Yingdi Yu31b4af22014-01-14 14:13:00 -0800153 getPublicKey(const Name& keyName) = 0;
154
155 /**
Yingdi Yu40b53092014-06-17 17:10:02 -0700156 * @brief Get the type of the queried public key
157 *
158 * @note KeyType is also available from PublicKey instance.
159 * This method is more efficient if only KeyType is needed.
160 *
161 * @param keyName The name of the requested public key
162 * @return the type of the key. If the queried key does not exist, KEY_TYPE_NULL will be returned
163 */
164 virtual KeyType
165 getPublicKeyType(const Name& keyName) = 0;
166
167 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700168 * @brief Check if the specified certificate already exists
Yingdi Yu2e57a582014-02-20 23:34:43 -0800169 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700170 * @param certificateName The name of the certificate
Yingdi Yu31b4af22014-01-14 14:13:00 -0800171 */
172 virtual bool
173 doesCertificateExist(const Name& certificateName) = 0;
174
175 /**
Yingdi Yu2e57a582014-02-20 23:34:43 -0800176 * @brief Add a certificate to the identity storage.
177 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700178 * It will add the corresponding public key and identity if they do not exist
Yingdi Yu2e57a582014-02-20 23:34:43 -0800179 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700180 * @param certificate The certificate to be added
Yingdi Yu31b4af22014-01-14 14:13:00 -0800181 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700182 virtual void
Yingdi Yu31b4af22014-01-14 14:13:00 -0800183 addCertificate(const IdentityCertificate& certificate) = 0;
184
185 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700186 * @brief Get a shared pointer to identity certificate object from the identity storage
Yingdi Yu2e57a582014-02-20 23:34:43 -0800187 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700188 * @param certificateName The name of the requested certificate
189 * @throws SecPublicInfo::Error if the certificate does not exist
Yingdi Yu31b4af22014-01-14 14:13:00 -0800190 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700191 virtual shared_ptr<IdentityCertificate>
192 getCertificate(const Name& certificateName) = 0;
Yingdi Yu31b4af22014-01-14 14:13:00 -0800193
194
195 /*****************************************
196 * Default Getter *
197 *****************************************/
198
199 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700200 * @brief Get name of the default identity
Yingdi Yu2e57a582014-02-20 23:34:43 -0800201 *
Yingdi Yu2e57a582014-02-20 23:34:43 -0800202 * @throws SecPublicInfo::Error if there is no default.
Yingdi Yu31b4af22014-01-14 14:13:00 -0800203 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700204 virtual Name
Yingdi Yu31b4af22014-01-14 14:13:00 -0800205 getDefaultIdentity() = 0;
206
207 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700208 * @brief Get name of the default key name for the specified identity
Yingdi Yu2e57a582014-02-20 23:34:43 -0800209 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700210 * @param identityName The identity name
211 * @throws SecPublicInfo::Error if there is no default
Yingdi Yu31b4af22014-01-14 14:13:00 -0800212 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700213 virtual Name
Yingdi Yu31b4af22014-01-14 14:13:00 -0800214 getDefaultKeyNameForIdentity(const Name& identityName) = 0;
215
216 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700217 * @brief Get name of the default certificate name for the specified key
Yingdi Yu2e57a582014-02-20 23:34:43 -0800218 *
Yingdi Yu31b4af22014-01-14 14:13:00 -0800219 * @param keyName The key name.
Yingdi Yu2e57a582014-02-20 23:34:43 -0800220 * @throws SecPublicInfo::Error if there is no default.
Yingdi Yu31b4af22014-01-14 14:13:00 -0800221 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700222 virtual Name
Yingdi Yu31b4af22014-01-14 14:13:00 -0800223 getDefaultCertificateNameForKey(const Name& keyName) = 0;
224
Yingdi Yu2e57a582014-02-20 23:34:43 -0800225 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700226 * @brief Get all the identities from public info
Yingdi Yu2e57a582014-02-20 23:34:43 -0800227 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700228 * @param [out] nameList On return, the identity list
229 * @param isDefault If specified, only the default identity is returned
Yingdi Yu2e57a582014-02-20 23:34:43 -0800230 */
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800231 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700232 getAllIdentities(std::vector<Name>& nameList, bool isDefault) = 0;
Yingdi Yu31b4af22014-01-14 14:13:00 -0800233
Yingdi Yu2e57a582014-02-20 23:34:43 -0800234 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700235 * @brief Get all the key names from public info
Yingdi Yu2e57a582014-02-20 23:34:43 -0800236 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700237 * @param [out] nameList On return, the key name list.
238 * @param isDefault If specified, only the default keys are returned
Yingdi Yu2e57a582014-02-20 23:34:43 -0800239 */
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800240 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700241 getAllKeyNames(std::vector<Name>& nameList, bool isDefault) = 0;
Yingdi Yu31b4af22014-01-14 14:13:00 -0800242
Yingdi Yu2e57a582014-02-20 23:34:43 -0800243 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700244 * @brief Get all the key names of a particular identity
Yingdi Yu2e57a582014-02-20 23:34:43 -0800245 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700246 * @param identity The specified identity name
247 * @param [out] nameList On return, the key name list
248 * @param isDefault If specified, only the default key is returned
Yingdi Yu2e57a582014-02-20 23:34:43 -0800249 */
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800250 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700251 getAllKeyNamesOfIdentity(const Name& identity, std::vector<Name>& nameList, bool isDefault) = 0;
Yingdi Yu2e57a582014-02-20 23:34:43 -0800252
253 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700254 * @brief Get all the certificate name in public info
Yingdi Yu2e57a582014-02-20 23:34:43 -0800255 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700256 * @param [out] nameList On return, the certificate name list
257 * @param isDefault If specified, only the default certificates are returned
Yingdi Yu2e57a582014-02-20 23:34:43 -0800258 */
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800259 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700260 getAllCertificateNames(std::vector<Name>& nameList, bool isDefault) = 0;
261
Yingdi Yu2e57a582014-02-20 23:34:43 -0800262 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700263 * @brief Get all the certificate name of a particular key name
Yingdi Yu2e57a582014-02-20 23:34:43 -0800264 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700265 * @param keyName The specified key name
266 * @param [out] nameList On return, the certificate name list
267 * @param isDefault If specified, only the default certificate is returned
Yingdi Yu2e57a582014-02-20 23:34:43 -0800268 */
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800269 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700270 getAllCertificateNamesOfKey(const Name& keyName, std::vector<Name>& nameList, bool isDefault) = 0;
Yingdi Yu31b4af22014-01-14 14:13:00 -0800271
Yingdi Yuf56c68f2014-04-24 21:50:13 -0700272 /*****************************************
273 * Delete Methods *
274 *****************************************/
275
276 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700277 * @brief Delete a certificate
Yingdi Yuf56c68f2014-04-24 21:50:13 -0700278 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700279 * @param certificateName The certificate name
Yingdi Yuf56c68f2014-04-24 21:50:13 -0700280 */
281 virtual void
282 deleteCertificateInfo(const Name& certificateName) = 0;
283
284 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700285 * @brief Delete a public key and related certificates
Yingdi Yuf56c68f2014-04-24 21:50:13 -0700286 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700287 * @param keyName The key name
Yingdi Yuf56c68f2014-04-24 21:50:13 -0700288 */
289 virtual void
290 deletePublicKeyInfo(const Name& keyName) = 0;
291
292 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700293 * @brief Delete an identity and related public keys and certificates
Yingdi Yuf56c68f2014-04-24 21:50:13 -0700294 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700295 * @param identity The identity name
Yingdi Yuf56c68f2014-04-24 21:50:13 -0700296 */
297 virtual void
298 deleteIdentityInfo(const Name& identity) = 0;
299
Yingdi Yu31b4af22014-01-14 14:13:00 -0800300protected:
301
302 /*****************************************
303 * Default Setter *
304 *****************************************/
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700305
Yingdi Yu31b4af22014-01-14 14:13:00 -0800306 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700307 * @brief Set the default identity
Yingdi Yu2e57a582014-02-20 23:34:43 -0800308 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700309 * @param identityName The default identity name
Yingdi Yu31b4af22014-01-14 14:13:00 -0800310 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700311 virtual void
Yingdi Yu31b4af22014-01-14 14:13:00 -0800312 setDefaultIdentityInternal(const Name& identityName) = 0;
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700313
Yingdi Yu31b4af22014-01-14 14:13:00 -0800314 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700315 * @brief Set the default key name for the corresponding identity
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700316 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700317 * @param keyName The key name
318 * @throws SecPublicInfo::Error if the key does not exist
Yingdi Yu31b4af22014-01-14 14:13:00 -0800319 */
320 virtual void
321 setDefaultKeyNameForIdentityInternal(const Name& keyName) = 0;
322
323 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700324 * @brief Set the default certificate name for the corresponding key
Yingdi Yu2e57a582014-02-20 23:34:43 -0800325 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700326 * @param certificateName The certificate name
327 * @throws SecPublicInfo::Error if the certificate does not exist
Yingdi Yu31b4af22014-01-14 14:13:00 -0800328 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700329 virtual void
330 setDefaultCertificateNameForKeyInternal(const Name& certificateName) = 0;
Yingdi Yu31b4af22014-01-14 14:13:00 -0800331
Yingdi Yu41546342014-11-30 23:37:53 -0800332 /**
333 * @brief return the scheme of the PibLocator
334 */
335 virtual std::string
336 getScheme() = 0;
337
Yingdi Yu31b4af22014-01-14 14:13:00 -0800338public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700339
Yingdi Yu31b4af22014-01-14 14:13:00 -0800340 /*****************************************
341 * Helper Methods *
342 *****************************************/
343
344 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700345 * @brief Set the default identity
Yingdi Yu2e57a582014-02-20 23:34:43 -0800346 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700347 * @param identityName The default identity name
348 * @throws SecPublicInfo::Error if the identity does not exist
Yingdi Yu31b4af22014-01-14 14:13:00 -0800349 */
Alexander Afanasyevaab79662014-07-07 17:35:34 -0700350 void
Yingdi Yu31b4af22014-01-14 14:13:00 -0800351 setDefaultIdentity(const Name& identityName);
352
353 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700354 * @brief Set the default key name for the corresponding identity
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700355 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700356 * @param keyName The key name
357 * @throws SecPublicInfo::Error if either the identity or key does not exist
Yingdi Yu31b4af22014-01-14 14:13:00 -0800358 */
Alexander Afanasyevaab79662014-07-07 17:35:34 -0700359 void
Yingdi Yu31b4af22014-01-14 14:13:00 -0800360 setDefaultKeyNameForIdentity(const Name& keyName);
361
362 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700363 * @brief Set the default certificate name for the corresponding key
Yingdi Yu2e57a582014-02-20 23:34:43 -0800364 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700365 * @param certificateName The certificate name
366 * @throws SecPublicInfo::Error if either the certificate or key does not exist
Yingdi Yu31b4af22014-01-14 14:13:00 -0800367 */
Alexander Afanasyevaab79662014-07-07 17:35:34 -0700368 void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700369 setDefaultCertificateNameForKey(const Name& certificateName);
Yingdi Yu31b4af22014-01-14 14:13:00 -0800370
371 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700372 * @brief Generate a key name for the identity
Yingdi Yu2e57a582014-02-20 23:34:43 -0800373 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700374 * @param identityName The identity name
375 * @param useKsk If true, generate a KSK name, otherwise a DSK name
376 * @return The generated key name
Yingdi Yu31b4af22014-01-14 14:13:00 -0800377 */
Alexander Afanasyevaab79662014-07-07 17:35:34 -0700378 Name
Yingdi Yu31b4af22014-01-14 14:13:00 -0800379 getNewKeyName(const Name& identityName, bool useKsk);
380
Yingdi Yu2e57a582014-02-20 23:34:43 -0800381 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700382 * @brief Get the default certificate name for the specified identity
Yingdi Yu2e57a582014-02-20 23:34:43 -0800383 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700384 * @param identityName The identity name
385 * @return The default certificate name
386 * @throws SecPublicInfo::Error if no certificate is found
Yingdi Yu31b4af22014-01-14 14:13:00 -0800387 */
Alexander Afanasyevaab79662014-07-07 17:35:34 -0700388 Name
Yingdi Yu31b4af22014-01-14 14:13:00 -0800389 getDefaultCertificateNameForIdentity(const Name& identityName);
390
391 /**
Yingdi Yu2e57a582014-02-20 23:34:43 -0800392 * @brief Get the default certificate name of the default identity
393 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700394 * @return The requested certificate name
395 * @throws SecPublicInfo::Error if no certificate is found
Yingdi Yu31b4af22014-01-14 14:13:00 -0800396 */
Alexander Afanasyevaab79662014-07-07 17:35:34 -0700397 Name
Yingdi Yu31b4af22014-01-14 14:13:00 -0800398 getDefaultCertificateName();
399
400 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700401 * @brief Add a certificate and set the certificate as the default one of its corresponding key
Yingdi Yu2e57a582014-02-20 23:34:43 -0800402 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700403 * @param certificate The certificate to be added
Yingdi Yu2e57a582014-02-20 23:34:43 -0800404 * @throws SecPublicInfo::Error if the certificate cannot be added (though it is really rare)
Yingdi Yu31b4af22014-01-14 14:13:00 -0800405 */
Alexander Afanasyevaab79662014-07-07 17:35:34 -0700406 void
Yingdi Yu31b4af22014-01-14 14:13:00 -0800407 addCertificateAsKeyDefault(const IdentityCertificate& certificate);
408
409 /**
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700410 * @brief Add a certificate into the public key identity storage and set the certificate as the
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700411 * default one of its corresponding identity
Yingdi Yu2e57a582014-02-20 23:34:43 -0800412 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700413 * @param certificate The certificate to be added
Yingdi Yu2e57a582014-02-20 23:34:43 -0800414 * @throws SecPublicInfo::Error if the certificate cannot be added (though it is really rare)
Yingdi Yu31b4af22014-01-14 14:13:00 -0800415 */
Alexander Afanasyevaab79662014-07-07 17:35:34 -0700416 void
Yingdi Yu31b4af22014-01-14 14:13:00 -0800417 addCertificateAsIdentityDefault(const IdentityCertificate& certificate);
418
Yingdi Yu2e57a582014-02-20 23:34:43 -0800419 /**
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700420 * @brief Add a certificate into the public key identity storage and set the certificate as the
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700421 * default one of the default identity
Yingdi Yu2e57a582014-02-20 23:34:43 -0800422 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700423 * @param certificate The certificate to be added
Yingdi Yu2e57a582014-02-20 23:34:43 -0800424 * @throws SecPublicInfo::Error if the certificate cannot be added (though it is really rare)
425 */
Alexander Afanasyevaab79662014-07-07 17:35:34 -0700426 void
Yingdi Yu88663af2014-01-15 15:21:38 -0800427 addCertificateAsSystemDefault(const IdentityCertificate& certificate);
428
Yingdi Yu2e57a582014-02-20 23:34:43 -0800429 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700430 * @brief Get cached default certificate of the default identity
Yingdi Yu2e57a582014-02-20 23:34:43 -0800431 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700432 * @return The certificate which might be empty shared_ptr<IdentityCertificate>()
Alexander Afanasyevaab79662014-07-07 17:35:34 -0700433 * @deprecated Use getDefaultCertificate instead
Yingdi Yu2e57a582014-02-20 23:34:43 -0800434 */
Alexander Afanasyevaab79662014-07-07 17:35:34 -0700435 DEPRECATED(
436 shared_ptr<IdentityCertificate>
437 defaultCertificate());
438
439 /**
440 * @brief Get cached default certificate of the default identity
441 *
442 * @return The certificate which might be empty shared_ptr<IdentityCertificate>()
443 */
444 shared_ptr<IdentityCertificate>
445 getDefaultCertificate();
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700446
Yingdi Yu2e57a582014-02-20 23:34:43 -0800447 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700448 * @brief try to get the default certificate of the default identity from the public info
Yingdi Yu2e57a582014-02-20 23:34:43 -0800449 */
Alexander Afanasyevaab79662014-07-07 17:35:34 -0700450 void
Yingdi Yu31b4af22014-01-14 14:13:00 -0800451 refreshDefaultCertificate();
452
453protected:
Yingdi Yu2e57a582014-02-20 23:34:43 -0800454 shared_ptr<IdentityCertificate> m_defaultCertificate;
Yingdi Yu41546342014-11-30 23:37:53 -0800455 std::string m_location;
Yingdi Yu31b4af22014-01-14 14:13:00 -0800456};
457
Yingdi Yufc40d872014-02-18 12:56:04 -0800458} // namespace ndn
Yingdi Yu31b4af22014-01-14 14:13:00 -0800459
Yingdi Yu41546342014-11-30 23:37:53 -0800460#endif // NDN_SECURITY_SEC_PUBLIC_INFO_HPP