blob: 7ed6ef400ff410c73346d7d43e63008da5701a1c [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 Afanasyev4c9a3d52017-01-03 17:45:19 -08003 * Copyright (c) 2013-2017 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
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -080022#ifndef NDN_SECURITY_V1_SEC_PUBLIC_INFO_HPP
23#define NDN_SECURITY_V1_SEC_PUBLIC_INFO_HPP
Yingdi Yu31b4af22014-01-14 14:13:00 -080024
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -080025#include "../../name.hpp"
26#include "../security-common.hpp"
27#include "public-key.hpp"
28#include "identity-certificate.hpp"
Yingdi Yu88663af2014-01-15 15:21:38 -080029
Yingdi Yu31b4af22014-01-14 14:13:00 -080030namespace ndn {
Alexander Afanasyev2fa59392016-07-29 17:24:23 -070031namespace security {
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -080032namespace v1 {
Yingdi Yu31b4af22014-01-14 14:13:00 -080033
34/**
Yingdi Yu2e57a582014-02-20 23:34:43 -080035 * @brief SecPublicInfo is a base class for the storage of public information.
36 *
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070037 * It specify interfaces related to public information, such as identity, public keys and
38 * certificates.
Yingdi Yu31b4af22014-01-14 14:13:00 -080039 */
Yingdi Yuf56c68f2014-04-24 21:50:13 -070040class SecPublicInfo : noncopyable
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070041{
Yingdi Yu31b4af22014-01-14 14:13:00 -080042public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070043 class Error : public std::runtime_error
44 {
45 public:
46 explicit
47 Error(const std::string& what)
48 : std::runtime_error(what)
49 {
50 }
51 };
Yingdi Yu31b4af22014-01-14 14:13:00 -080052
Yingdi Yu41546342014-11-30 23:37:53 -080053 explicit
54 SecPublicInfo(const std::string& location);
55
Yingdi Yu31b4af22014-01-14 14:13:00 -080056 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -070057 * @brief The virtual Destructor
Yingdi Yu31b4af22014-01-14 14:13:00 -080058 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070059 virtual
Yingdi Yu41546342014-11-30 23:37:53 -080060 ~SecPublicInfo();
61
62 /**
63 * @brief Set the corresponding TPM information to @p tpmLocator
64 *
65 * If the provided @p tpmLocator is different from the existing one, the PIB will be reset,
66 * otherwise nothing will be changed.
67 *
68 * For legacy issue, the TPM info may not exist (some old PIB content may not have this info),
69 * this method will simply set the TPM info as provided without changing anything else. Thus an
70 * ideal process of handling old PIB is to check if TPM info exists. If it does not exist,
71 * then set it to the default value according to configuration.
72 */
73 virtual void
74 setTpmLocator(const std::string& tpmLocator) = 0;
75
76 /**
77 * @brief Get TPM Locator
78 *
79 * @throws SecPublicInfo::Error if the TPM info does not exist
80 */
81 virtual std::string
82 getTpmLocator() = 0;
83
84 /**
85 * @brief Get PIB Locator
86 */
87 std::string
88 getPibLocator();
Yingdi Yu31b4af22014-01-14 14:13:00 -080089
90 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -070091 * @brief Check if the specified identity already exists
Yingdi Yu2e57a582014-02-20 23:34:43 -080092 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -070093 * @param identityName The identity name
94 * @return true if the identity exists, otherwise false
Yingdi Yu31b4af22014-01-14 14:13:00 -080095 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070096 virtual bool
Yingdi Yu31b4af22014-01-14 14:13:00 -080097 doesIdentityExist(const Name& identityName) = 0;
98
99 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700100 * @brief Add a new identity
Yingdi Yu2e57a582014-02-20 23:34:43 -0800101 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700102 * if identity already exist, do not add it again
Yingdi Yu2e57a582014-02-20 23:34:43 -0800103 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700104 * @param identityName The identity name to be added
Yingdi Yu31b4af22014-01-14 14:13:00 -0800105 */
106 virtual void
107 addIdentity(const Name& identityName) = 0;
108
109 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700110 * @brief Revoke the identity
Yingdi Yu2e57a582014-02-20 23:34:43 -0800111 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700112 * @return true if the identity was revoked, otherwise false
Yingdi Yu31b4af22014-01-14 14:13:00 -0800113 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700114 virtual bool
Yingdi Yu31b4af22014-01-14 14:13:00 -0800115 revokeIdentity() = 0;
116
117 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700118 * @brief Check if the specified key already exists
Yingdi Yu2e57a582014-02-20 23:34:43 -0800119 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700120 * @param keyName The name of the key
121 * @return true if the key exists, otherwise false
Yingdi Yu31b4af22014-01-14 14:13:00 -0800122 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700123 virtual bool
Yingdi Yu31b4af22014-01-14 14:13:00 -0800124 doesPublicKeyExist(const Name& keyName) = 0;
125
126 /**
Yingdi Yu2e57a582014-02-20 23:34:43 -0800127 * @brief Add a public key to the identity storage.
128 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700129 * @param keyName The name of the public key to be added
130 * @param keyType Type of the public key to be added
131 * @param publicKey Reference to the PublicKey object
Yingdi Yu41546342014-11-30 23:37:53 -0800132 * @deprecated Use addKey instead
Yingdi Yu31b4af22014-01-14 14:13:00 -0800133 */
Yingdi Yu41546342014-11-30 23:37:53 -0800134 DEPRECATED(
Yingdi Yu40b53092014-06-17 17:10:02 -0700135 void
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -0800136 addPublicKey(const Name& keyName, KeyType keyType, const PublicKey& publicKey));
Yingdi Yu40b53092014-06-17 17:10:02 -0700137
138 /**
139 * @brief Add a public key to the identity storage.
140 *
141 * @param keyName The name of the public key to be added
142 * @param publicKey Reference to the PublicKey object
143 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700144 virtual void
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -0800145 addKey(const Name& keyName, const PublicKey& publicKey) = 0;
Yingdi Yu31b4af22014-01-14 14:13:00 -0800146
147 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700148 * @brief Get shared pointer to PublicKey object from the identity storage
Yingdi Yu2e57a582014-02-20 23:34:43 -0800149 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700150 * @param keyName The name of the requested public key
151 * @throws SecPublicInfo::Error if public key does not exist
Yingdi Yu31b4af22014-01-14 14:13:00 -0800152 */
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -0800153 virtual shared_ptr<PublicKey>
Yingdi Yu31b4af22014-01-14 14:13:00 -0800154 getPublicKey(const Name& keyName) = 0;
155
156 /**
Yingdi Yu40b53092014-06-17 17:10:02 -0700157 * @brief Get the type of the queried public key
158 *
159 * @note KeyType is also available from PublicKey instance.
160 * This method is more efficient if only KeyType is needed.
161 *
162 * @param keyName The name of the requested public key
Yingdi Yu99b2a002015-08-12 12:47:44 -0700163 * @return the type of the key. If the queried key does not exist, KeyType::NONE will be returned
Yingdi Yu40b53092014-06-17 17:10:02 -0700164 */
165 virtual KeyType
166 getPublicKeyType(const Name& keyName) = 0;
167
168 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700169 * @brief Check if the specified certificate already exists
Yingdi Yu2e57a582014-02-20 23:34:43 -0800170 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700171 * @param certificateName The name of the certificate
Yingdi Yu31b4af22014-01-14 14:13:00 -0800172 */
173 virtual bool
174 doesCertificateExist(const Name& certificateName) = 0;
175
176 /**
Yingdi Yu2e57a582014-02-20 23:34:43 -0800177 * @brief Add a certificate to the identity storage.
178 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700179 * It will add the corresponding public key and identity if they do not exist
Yingdi Yu2e57a582014-02-20 23:34:43 -0800180 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700181 * @param certificate The certificate to be added
Yingdi Yu31b4af22014-01-14 14:13:00 -0800182 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700183 virtual void
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -0800184 addCertificate(const IdentityCertificate& certificate) = 0;
Yingdi Yu31b4af22014-01-14 14:13:00 -0800185
186 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700187 * @brief Get a shared pointer to identity certificate object from the identity storage
Yingdi Yu2e57a582014-02-20 23:34:43 -0800188 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700189 * @param certificateName The name of the requested certificate
190 * @throws SecPublicInfo::Error if the certificate does not exist
Yingdi Yu31b4af22014-01-14 14:13:00 -0800191 */
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -0800192 virtual shared_ptr<IdentityCertificate>
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700193 getCertificate(const Name& certificateName) = 0;
Yingdi Yu31b4af22014-01-14 14:13:00 -0800194
195
196 /*****************************************
197 * Default Getter *
198 *****************************************/
199
200 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700201 * @brief Get name of the default identity
Yingdi Yu2e57a582014-02-20 23:34:43 -0800202 *
Yingdi Yu2e57a582014-02-20 23:34:43 -0800203 * @throws SecPublicInfo::Error if there is no default.
Yingdi Yu31b4af22014-01-14 14:13:00 -0800204 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700205 virtual Name
Yingdi Yu31b4af22014-01-14 14:13:00 -0800206 getDefaultIdentity() = 0;
207
208 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700209 * @brief Get name of the default key name for the specified identity
Yingdi Yu2e57a582014-02-20 23:34:43 -0800210 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700211 * @param identityName The identity name
212 * @throws SecPublicInfo::Error if there is no default
Yingdi Yu31b4af22014-01-14 14:13:00 -0800213 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700214 virtual Name
Yingdi Yu31b4af22014-01-14 14:13:00 -0800215 getDefaultKeyNameForIdentity(const Name& identityName) = 0;
216
217 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700218 * @brief Get name of the default certificate name for the specified key
Yingdi Yu2e57a582014-02-20 23:34:43 -0800219 *
Yingdi Yu31b4af22014-01-14 14:13:00 -0800220 * @param keyName The key name.
Yingdi Yu2e57a582014-02-20 23:34:43 -0800221 * @throws SecPublicInfo::Error if there is no default.
Yingdi Yu31b4af22014-01-14 14:13:00 -0800222 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700223 virtual Name
Yingdi Yu31b4af22014-01-14 14:13:00 -0800224 getDefaultCertificateNameForKey(const Name& keyName) = 0;
225
Yingdi Yu2e57a582014-02-20 23:34:43 -0800226 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700227 * @brief Get all the identities from public info
Yingdi Yu2e57a582014-02-20 23:34:43 -0800228 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700229 * @param [out] nameList On return, the identity list
230 * @param isDefault If specified, only the default identity is returned
Yingdi Yu2e57a582014-02-20 23:34:43 -0800231 */
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800232 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700233 getAllIdentities(std::vector<Name>& nameList, bool isDefault) = 0;
Yingdi Yu31b4af22014-01-14 14:13:00 -0800234
Yingdi Yu2e57a582014-02-20 23:34:43 -0800235 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700236 * @brief Get all the key names from public info
Yingdi Yu2e57a582014-02-20 23:34:43 -0800237 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700238 * @param [out] nameList On return, the key name list.
239 * @param isDefault If specified, only the default keys are returned
Yingdi Yu2e57a582014-02-20 23:34:43 -0800240 */
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800241 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700242 getAllKeyNames(std::vector<Name>& nameList, bool isDefault) = 0;
Yingdi Yu31b4af22014-01-14 14:13:00 -0800243
Yingdi Yu2e57a582014-02-20 23:34:43 -0800244 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700245 * @brief Get all the key names of a particular identity
Yingdi Yu2e57a582014-02-20 23:34:43 -0800246 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700247 * @param identity The specified identity name
248 * @param [out] nameList On return, the key name list
249 * @param isDefault If specified, only the default key is returned
Yingdi Yu2e57a582014-02-20 23:34:43 -0800250 */
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800251 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700252 getAllKeyNamesOfIdentity(const Name& identity, std::vector<Name>& nameList, bool isDefault) = 0;
Yingdi Yu2e57a582014-02-20 23:34:43 -0800253
254 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700255 * @brief Get all the certificate name in public info
Yingdi Yu2e57a582014-02-20 23:34:43 -0800256 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700257 * @param [out] nameList On return, the certificate name list
258 * @param isDefault If specified, only the default certificates are returned
Yingdi Yu2e57a582014-02-20 23:34:43 -0800259 */
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800260 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700261 getAllCertificateNames(std::vector<Name>& nameList, bool isDefault) = 0;
262
Yingdi Yu2e57a582014-02-20 23:34:43 -0800263 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700264 * @brief Get all the certificate name of a particular key name
Yingdi Yu2e57a582014-02-20 23:34:43 -0800265 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700266 * @param keyName The specified key name
267 * @param [out] nameList On return, the certificate name list
268 * @param isDefault If specified, only the default certificate is returned
Yingdi Yu2e57a582014-02-20 23:34:43 -0800269 */
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800270 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700271 getAllCertificateNamesOfKey(const Name& keyName, std::vector<Name>& nameList, bool isDefault) = 0;
Yingdi Yu31b4af22014-01-14 14:13:00 -0800272
Yingdi Yuf56c68f2014-04-24 21:50:13 -0700273 /*****************************************
274 * Delete Methods *
275 *****************************************/
276
277 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700278 * @brief Delete a certificate
Yingdi Yuf56c68f2014-04-24 21:50:13 -0700279 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700280 * @param certificateName The certificate name
Yingdi Yuf56c68f2014-04-24 21:50:13 -0700281 */
282 virtual void
283 deleteCertificateInfo(const Name& certificateName) = 0;
284
285 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700286 * @brief Delete a public key and related certificates
Yingdi Yuf56c68f2014-04-24 21:50:13 -0700287 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700288 * @param keyName The key name
Yingdi Yuf56c68f2014-04-24 21:50:13 -0700289 */
290 virtual void
291 deletePublicKeyInfo(const Name& keyName) = 0;
292
293 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700294 * @brief Delete an identity and related public keys and certificates
Yingdi Yuf56c68f2014-04-24 21:50:13 -0700295 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700296 * @param identity The identity name
Yingdi Yuf56c68f2014-04-24 21:50:13 -0700297 */
298 virtual void
299 deleteIdentityInfo(const Name& identity) = 0;
300
Yingdi Yu31b4af22014-01-14 14:13:00 -0800301protected:
302
303 /*****************************************
304 * Default Setter *
305 *****************************************/
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700306
Yingdi Yu31b4af22014-01-14 14:13:00 -0800307 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700308 * @brief Set the default identity
Yingdi Yu2e57a582014-02-20 23:34:43 -0800309 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700310 * @param identityName The default identity name
Yingdi Yu31b4af22014-01-14 14:13:00 -0800311 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700312 virtual void
Yingdi Yu31b4af22014-01-14 14:13:00 -0800313 setDefaultIdentityInternal(const Name& identityName) = 0;
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700314
Yingdi Yu31b4af22014-01-14 14:13:00 -0800315 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700316 * @brief Set the default key name for the corresponding identity
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700317 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700318 * @param keyName The key name
319 * @throws SecPublicInfo::Error if the key does not exist
Yingdi Yu31b4af22014-01-14 14:13:00 -0800320 */
321 virtual void
322 setDefaultKeyNameForIdentityInternal(const Name& keyName) = 0;
323
324 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700325 * @brief Set the default certificate name for the corresponding key
Yingdi Yu2e57a582014-02-20 23:34:43 -0800326 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700327 * @param certificateName The certificate name
328 * @throws SecPublicInfo::Error if the certificate does not exist
Yingdi Yu31b4af22014-01-14 14:13:00 -0800329 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700330 virtual void
331 setDefaultCertificateNameForKeyInternal(const Name& certificateName) = 0;
Yingdi Yu31b4af22014-01-14 14:13:00 -0800332
Yingdi Yu41546342014-11-30 23:37:53 -0800333 /**
334 * @brief return the scheme of the PibLocator
335 */
336 virtual std::string
337 getScheme() = 0;
338
Yingdi Yu31b4af22014-01-14 14:13:00 -0800339public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700340
Yingdi Yu31b4af22014-01-14 14:13:00 -0800341 /*****************************************
342 * Helper Methods *
343 *****************************************/
344
345 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700346 * @brief Set the default identity
Yingdi Yu2e57a582014-02-20 23:34:43 -0800347 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700348 * @param identityName The default identity name
349 * @throws SecPublicInfo::Error if the identity does not exist
Yingdi Yu31b4af22014-01-14 14:13:00 -0800350 */
Alexander Afanasyevaab79662014-07-07 17:35:34 -0700351 void
Yingdi Yu31b4af22014-01-14 14:13:00 -0800352 setDefaultIdentity(const Name& identityName);
353
354 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700355 * @brief Set the default key name for the corresponding identity
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700356 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700357 * @param keyName The key name
358 * @throws SecPublicInfo::Error if either the identity or key does not exist
Yingdi Yu31b4af22014-01-14 14:13:00 -0800359 */
Alexander Afanasyevaab79662014-07-07 17:35:34 -0700360 void
Yingdi Yu31b4af22014-01-14 14:13:00 -0800361 setDefaultKeyNameForIdentity(const Name& keyName);
362
363 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700364 * @brief Set the default certificate name for the corresponding key
Yingdi Yu2e57a582014-02-20 23:34:43 -0800365 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700366 * @param certificateName The certificate name
367 * @throws SecPublicInfo::Error if either the certificate or key does not exist
Yingdi Yu31b4af22014-01-14 14:13:00 -0800368 */
Alexander Afanasyevaab79662014-07-07 17:35:34 -0700369 void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700370 setDefaultCertificateNameForKey(const Name& certificateName);
Yingdi Yu31b4af22014-01-14 14:13:00 -0800371
372 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700373 * @brief Generate a key name for the identity
Yingdi Yu2e57a582014-02-20 23:34:43 -0800374 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700375 * @param identityName The identity name
376 * @param useKsk If true, generate a KSK name, otherwise a DSK name
377 * @return The generated key name
Yingdi Yu31b4af22014-01-14 14:13:00 -0800378 */
Alexander Afanasyevaab79662014-07-07 17:35:34 -0700379 Name
Yingdi Yu31b4af22014-01-14 14:13:00 -0800380 getNewKeyName(const Name& identityName, bool useKsk);
381
Yingdi Yu2e57a582014-02-20 23:34:43 -0800382 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700383 * @brief Get the default certificate name for the specified identity
Yingdi Yu2e57a582014-02-20 23:34:43 -0800384 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700385 * @param identityName The identity name
386 * @return The default certificate name
387 * @throws SecPublicInfo::Error if no certificate is found
Yingdi Yu31b4af22014-01-14 14:13:00 -0800388 */
Alexander Afanasyevaab79662014-07-07 17:35:34 -0700389 Name
Yingdi Yu31b4af22014-01-14 14:13:00 -0800390 getDefaultCertificateNameForIdentity(const Name& identityName);
391
392 /**
Yingdi Yu2e57a582014-02-20 23:34:43 -0800393 * @brief Get the default certificate name of the default identity
394 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700395 * @return The requested certificate name
396 * @throws SecPublicInfo::Error if no certificate is found
Yingdi Yu31b4af22014-01-14 14:13:00 -0800397 */
Alexander Afanasyevaab79662014-07-07 17:35:34 -0700398 Name
Yingdi Yu31b4af22014-01-14 14:13:00 -0800399 getDefaultCertificateName();
400
401 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700402 * @brief Add a certificate and set the certificate as the default one of its corresponding key
Yingdi Yu2e57a582014-02-20 23:34:43 -0800403 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700404 * @param certificate The certificate to be added
Yingdi Yu2e57a582014-02-20 23:34:43 -0800405 * @throws SecPublicInfo::Error if the certificate cannot be added (though it is really rare)
Yingdi Yu31b4af22014-01-14 14:13:00 -0800406 */
Alexander Afanasyevaab79662014-07-07 17:35:34 -0700407 void
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -0800408 addCertificateAsKeyDefault(const IdentityCertificate& certificate);
Yingdi Yu31b4af22014-01-14 14:13:00 -0800409
410 /**
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700411 * @brief Add a certificate into the public key identity storage and set the certificate as the
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700412 * default one of its corresponding identity
Yingdi Yu2e57a582014-02-20 23:34:43 -0800413 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700414 * @param certificate The certificate to be added
Yingdi Yu2e57a582014-02-20 23:34:43 -0800415 * @throws SecPublicInfo::Error if the certificate cannot be added (though it is really rare)
Yingdi Yu31b4af22014-01-14 14:13:00 -0800416 */
Alexander Afanasyevaab79662014-07-07 17:35:34 -0700417 void
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -0800418 addCertificateAsIdentityDefault(const IdentityCertificate& certificate);
Yingdi Yu31b4af22014-01-14 14:13:00 -0800419
Yingdi Yu2e57a582014-02-20 23:34:43 -0800420 /**
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700421 * @brief Add a certificate into the public key identity storage and set the certificate as the
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700422 * default one of the default identity
Yingdi Yu2e57a582014-02-20 23:34:43 -0800423 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700424 * @param certificate The certificate to be added
Yingdi Yu2e57a582014-02-20 23:34:43 -0800425 * @throws SecPublicInfo::Error if the certificate cannot be added (though it is really rare)
426 */
Alexander Afanasyevaab79662014-07-07 17:35:34 -0700427 void
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -0800428 addCertificateAsSystemDefault(const IdentityCertificate& certificate);
Yingdi Yu88663af2014-01-15 15:21:38 -0800429
Yingdi Yu2e57a582014-02-20 23:34:43 -0800430 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700431 * @brief Get cached default certificate of the default identity
Yingdi Yu2e57a582014-02-20 23:34:43 -0800432 *
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -0800433 * @return The certificate which might be empty shared_ptr<IdentityCertificate>()
Alexander Afanasyevaab79662014-07-07 17:35:34 -0700434 * @deprecated Use getDefaultCertificate instead
Yingdi Yu2e57a582014-02-20 23:34:43 -0800435 */
Alexander Afanasyevaab79662014-07-07 17:35:34 -0700436 DEPRECATED(
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -0800437 shared_ptr<IdentityCertificate>
Alexander Afanasyevaab79662014-07-07 17:35:34 -0700438 defaultCertificate());
439
440 /**
441 * @brief Get cached default certificate of the default identity
442 *
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -0800443 * @return The certificate which might be empty shared_ptr<IdentityCertificate>()
Alexander Afanasyevaab79662014-07-07 17:35:34 -0700444 */
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -0800445 shared_ptr<IdentityCertificate>
Alexander Afanasyevaab79662014-07-07 17:35:34 -0700446 getDefaultCertificate();
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700447
Yingdi Yu2e57a582014-02-20 23:34:43 -0800448 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700449 * @brief try to get the default certificate of the default identity from the public info
Yingdi Yu2e57a582014-02-20 23:34:43 -0800450 */
Alexander Afanasyevaab79662014-07-07 17:35:34 -0700451 void
Yingdi Yu31b4af22014-01-14 14:13:00 -0800452 refreshDefaultCertificate();
453
454protected:
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -0800455 shared_ptr<IdentityCertificate> m_defaultCertificate;
Yingdi Yu41546342014-11-30 23:37:53 -0800456 std::string m_location;
Yingdi Yu31b4af22014-01-14 14:13:00 -0800457};
458
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -0800459} // namespace v1
460
461#ifdef NDN_CXX_KEEP_SECURITY_V1_ALIASES
462using v1::SecPublicInfo;
463#endif // NDN_CXX_KEEP_SECURITY_V1_ALIASES
464
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700465} // namespace security
466
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -0800467#ifdef NDN_CXX_KEEP_SECURITY_V1_ALIASES
468using security::v1::SecPublicInfo;
469#endif // NDN_CXX_KEEP_SECURITY_V1_ALIASES
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700470
Yingdi Yufc40d872014-02-18 12:56:04 -0800471} // namespace ndn
Yingdi Yu31b4af22014-01-14 14:13:00 -0800472
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -0800473#endif // NDN_SECURITY_V1_SEC_PUBLIC_INFO_HPP