Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 2 | /** |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 3 | * Copyright (c) 2013-2017 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 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. |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 20 | */ |
| 21 | |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 22 | #ifndef NDN_SECURITY_V1_SEC_PUBLIC_INFO_HPP |
| 23 | #define NDN_SECURITY_V1_SEC_PUBLIC_INFO_HPP |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 24 | |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 25 | #include "../../name.hpp" |
| 26 | #include "../security-common.hpp" |
| 27 | #include "public-key.hpp" |
| 28 | #include "identity-certificate.hpp" |
Yingdi Yu | 88663af | 2014-01-15 15:21:38 -0800 | [diff] [blame] | 29 | |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 30 | namespace ndn { |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 31 | namespace security { |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 32 | namespace v1 { |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 33 | |
| 34 | /** |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 35 | * @brief SecPublicInfo is a base class for the storage of public information. |
| 36 | * |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 37 | * It specify interfaces related to public information, such as identity, public keys and |
| 38 | * certificates. |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 39 | */ |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 40 | class SecPublicInfo : noncopyable |
Alexander Afanasyev | 2a7f720 | 2014-04-23 14:25:29 -0700 | [diff] [blame] | 41 | { |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 42 | public: |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 43 | 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 Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 52 | |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 53 | explicit |
| 54 | SecPublicInfo(const std::string& location); |
| 55 | |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 56 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 57 | * @brief The virtual Destructor |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 58 | */ |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 59 | virtual |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 60 | ~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 Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 89 | |
| 90 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 91 | * @brief Check if the specified identity already exists |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 92 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 93 | * @param identityName The identity name |
| 94 | * @return true if the identity exists, otherwise false |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 95 | */ |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 96 | virtual bool |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 97 | doesIdentityExist(const Name& identityName) = 0; |
| 98 | |
| 99 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 100 | * @brief Add a new identity |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 101 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 102 | * if identity already exist, do not add it again |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 103 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 104 | * @param identityName The identity name to be added |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 105 | */ |
| 106 | virtual void |
| 107 | addIdentity(const Name& identityName) = 0; |
| 108 | |
| 109 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 110 | * @brief Revoke the identity |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 111 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 112 | * @return true if the identity was revoked, otherwise false |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 113 | */ |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 114 | virtual bool |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 115 | revokeIdentity() = 0; |
| 116 | |
| 117 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 118 | * @brief Check if the specified key already exists |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 119 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 120 | * @param keyName The name of the key |
| 121 | * @return true if the key exists, otherwise false |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 122 | */ |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 123 | virtual bool |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 124 | doesPublicKeyExist(const Name& keyName) = 0; |
| 125 | |
| 126 | /** |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 127 | * @brief Add a public key to the identity storage. |
| 128 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 129 | * @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 Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 132 | * @deprecated Use addKey instead |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 133 | */ |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 134 | DEPRECATED( |
Yingdi Yu | 40b5309 | 2014-06-17 17:10:02 -0700 | [diff] [blame] | 135 | void |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 136 | addPublicKey(const Name& keyName, KeyType keyType, const PublicKey& publicKey)); |
Yingdi Yu | 40b5309 | 2014-06-17 17:10:02 -0700 | [diff] [blame] | 137 | |
| 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 Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 144 | virtual void |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 145 | addKey(const Name& keyName, const PublicKey& publicKey) = 0; |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 146 | |
| 147 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 148 | * @brief Get shared pointer to PublicKey object from the identity storage |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 149 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 150 | * @param keyName The name of the requested public key |
| 151 | * @throws SecPublicInfo::Error if public key does not exist |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 152 | */ |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 153 | virtual shared_ptr<PublicKey> |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 154 | getPublicKey(const Name& keyName) = 0; |
| 155 | |
| 156 | /** |
Yingdi Yu | 40b5309 | 2014-06-17 17:10:02 -0700 | [diff] [blame] | 157 | * @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 Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 163 | * @return the type of the key. If the queried key does not exist, KeyType::NONE will be returned |
Yingdi Yu | 40b5309 | 2014-06-17 17:10:02 -0700 | [diff] [blame] | 164 | */ |
| 165 | virtual KeyType |
| 166 | getPublicKeyType(const Name& keyName) = 0; |
| 167 | |
| 168 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 169 | * @brief Check if the specified certificate already exists |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 170 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 171 | * @param certificateName The name of the certificate |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 172 | */ |
| 173 | virtual bool |
| 174 | doesCertificateExist(const Name& certificateName) = 0; |
| 175 | |
| 176 | /** |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 177 | * @brief Add a certificate to the identity storage. |
| 178 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 179 | * It will add the corresponding public key and identity if they do not exist |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 180 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 181 | * @param certificate The certificate to be added |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 182 | */ |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 183 | virtual void |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 184 | addCertificate(const IdentityCertificate& certificate) = 0; |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 185 | |
| 186 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 187 | * @brief Get a shared pointer to identity certificate object from the identity storage |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 188 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 189 | * @param certificateName The name of the requested certificate |
| 190 | * @throws SecPublicInfo::Error if the certificate does not exist |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 191 | */ |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 192 | virtual shared_ptr<IdentityCertificate> |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 193 | getCertificate(const Name& certificateName) = 0; |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 194 | |
| 195 | |
| 196 | /***************************************** |
| 197 | * Default Getter * |
| 198 | *****************************************/ |
| 199 | |
| 200 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 201 | * @brief Get name of the default identity |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 202 | * |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 203 | * @throws SecPublicInfo::Error if there is no default. |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 204 | */ |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 205 | virtual Name |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 206 | getDefaultIdentity() = 0; |
| 207 | |
| 208 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 209 | * @brief Get name of the default key name for the specified identity |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 210 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 211 | * @param identityName The identity name |
| 212 | * @throws SecPublicInfo::Error if there is no default |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 213 | */ |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 214 | virtual Name |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 215 | getDefaultKeyNameForIdentity(const Name& identityName) = 0; |
| 216 | |
| 217 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 218 | * @brief Get name of the default certificate name for the specified key |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 219 | * |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 220 | * @param keyName The key name. |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 221 | * @throws SecPublicInfo::Error if there is no default. |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 222 | */ |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 223 | virtual Name |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 224 | getDefaultCertificateNameForKey(const Name& keyName) = 0; |
| 225 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 226 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 227 | * @brief Get all the identities from public info |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 228 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 229 | * @param [out] nameList On return, the identity list |
| 230 | * @param isDefault If specified, only the default identity is returned |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 231 | */ |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 232 | virtual void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 233 | getAllIdentities(std::vector<Name>& nameList, bool isDefault) = 0; |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 234 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 235 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 236 | * @brief Get all the key names from public info |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 237 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 238 | * @param [out] nameList On return, the key name list. |
| 239 | * @param isDefault If specified, only the default keys are returned |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 240 | */ |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 241 | virtual void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 242 | getAllKeyNames(std::vector<Name>& nameList, bool isDefault) = 0; |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 243 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 244 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 245 | * @brief Get all the key names of a particular identity |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 246 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 247 | * @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 Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 250 | */ |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 251 | virtual void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 252 | getAllKeyNamesOfIdentity(const Name& identity, std::vector<Name>& nameList, bool isDefault) = 0; |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 253 | |
| 254 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 255 | * @brief Get all the certificate name in public info |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 256 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 257 | * @param [out] nameList On return, the certificate name list |
| 258 | * @param isDefault If specified, only the default certificates are returned |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 259 | */ |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 260 | virtual void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 261 | getAllCertificateNames(std::vector<Name>& nameList, bool isDefault) = 0; |
| 262 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 263 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 264 | * @brief Get all the certificate name of a particular key name |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 265 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 266 | * @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 Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 269 | */ |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 270 | virtual void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 271 | getAllCertificateNamesOfKey(const Name& keyName, std::vector<Name>& nameList, bool isDefault) = 0; |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 272 | |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 273 | /***************************************** |
| 274 | * Delete Methods * |
| 275 | *****************************************/ |
| 276 | |
| 277 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 278 | * @brief Delete a certificate |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 279 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 280 | * @param certificateName The certificate name |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 281 | */ |
| 282 | virtual void |
| 283 | deleteCertificateInfo(const Name& certificateName) = 0; |
| 284 | |
| 285 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 286 | * @brief Delete a public key and related certificates |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 287 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 288 | * @param keyName The key name |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 289 | */ |
| 290 | virtual void |
| 291 | deletePublicKeyInfo(const Name& keyName) = 0; |
| 292 | |
| 293 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 294 | * @brief Delete an identity and related public keys and certificates |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 295 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 296 | * @param identity The identity name |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 297 | */ |
| 298 | virtual void |
| 299 | deleteIdentityInfo(const Name& identity) = 0; |
| 300 | |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 301 | protected: |
| 302 | |
| 303 | /***************************************** |
| 304 | * Default Setter * |
| 305 | *****************************************/ |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 306 | |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 307 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 308 | * @brief Set the default identity |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 309 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 310 | * @param identityName The default identity name |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 311 | */ |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 312 | virtual void |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 313 | setDefaultIdentityInternal(const Name& identityName) = 0; |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 314 | |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 315 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 316 | * @brief Set the default key name for the corresponding identity |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 317 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 318 | * @param keyName The key name |
| 319 | * @throws SecPublicInfo::Error if the key does not exist |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 320 | */ |
| 321 | virtual void |
| 322 | setDefaultKeyNameForIdentityInternal(const Name& keyName) = 0; |
| 323 | |
| 324 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 325 | * @brief Set the default certificate name for the corresponding key |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 326 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 327 | * @param certificateName The certificate name |
| 328 | * @throws SecPublicInfo::Error if the certificate does not exist |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 329 | */ |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 330 | virtual void |
| 331 | setDefaultCertificateNameForKeyInternal(const Name& certificateName) = 0; |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 332 | |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 333 | /** |
| 334 | * @brief return the scheme of the PibLocator |
| 335 | */ |
| 336 | virtual std::string |
| 337 | getScheme() = 0; |
| 338 | |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 339 | public: |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 340 | |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 341 | /***************************************** |
| 342 | * Helper Methods * |
| 343 | *****************************************/ |
| 344 | |
| 345 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 346 | * @brief Set the default identity |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 347 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 348 | * @param identityName The default identity name |
| 349 | * @throws SecPublicInfo::Error if the identity does not exist |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 350 | */ |
Alexander Afanasyev | aab7966 | 2014-07-07 17:35:34 -0700 | [diff] [blame] | 351 | void |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 352 | setDefaultIdentity(const Name& identityName); |
| 353 | |
| 354 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 355 | * @brief Set the default key name for the corresponding identity |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 356 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 357 | * @param keyName The key name |
| 358 | * @throws SecPublicInfo::Error if either the identity or key does not exist |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 359 | */ |
Alexander Afanasyev | aab7966 | 2014-07-07 17:35:34 -0700 | [diff] [blame] | 360 | void |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 361 | setDefaultKeyNameForIdentity(const Name& keyName); |
| 362 | |
| 363 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 364 | * @brief Set the default certificate name for the corresponding key |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 365 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 366 | * @param certificateName The certificate name |
| 367 | * @throws SecPublicInfo::Error if either the certificate or key does not exist |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 368 | */ |
Alexander Afanasyev | aab7966 | 2014-07-07 17:35:34 -0700 | [diff] [blame] | 369 | void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 370 | setDefaultCertificateNameForKey(const Name& certificateName); |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 371 | |
| 372 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 373 | * @brief Generate a key name for the identity |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 374 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 375 | * @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 Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 378 | */ |
Alexander Afanasyev | aab7966 | 2014-07-07 17:35:34 -0700 | [diff] [blame] | 379 | Name |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 380 | getNewKeyName(const Name& identityName, bool useKsk); |
| 381 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 382 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 383 | * @brief Get the default certificate name for the specified identity |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 384 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 385 | * @param identityName The identity name |
| 386 | * @return The default certificate name |
| 387 | * @throws SecPublicInfo::Error if no certificate is found |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 388 | */ |
Alexander Afanasyev | aab7966 | 2014-07-07 17:35:34 -0700 | [diff] [blame] | 389 | Name |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 390 | getDefaultCertificateNameForIdentity(const Name& identityName); |
| 391 | |
| 392 | /** |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 393 | * @brief Get the default certificate name of the default identity |
| 394 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 395 | * @return The requested certificate name |
| 396 | * @throws SecPublicInfo::Error if no certificate is found |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 397 | */ |
Alexander Afanasyev | aab7966 | 2014-07-07 17:35:34 -0700 | [diff] [blame] | 398 | Name |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 399 | getDefaultCertificateName(); |
| 400 | |
| 401 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 402 | * @brief Add a certificate and set the certificate as the default one of its corresponding key |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 403 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 404 | * @param certificate The certificate to be added |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 405 | * @throws SecPublicInfo::Error if the certificate cannot be added (though it is really rare) |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 406 | */ |
Alexander Afanasyev | aab7966 | 2014-07-07 17:35:34 -0700 | [diff] [blame] | 407 | void |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 408 | addCertificateAsKeyDefault(const IdentityCertificate& certificate); |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 409 | |
| 410 | /** |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 411 | * @brief Add a certificate into the public key identity storage and set the certificate as the |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 412 | * default one of its corresponding identity |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 413 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 414 | * @param certificate The certificate to be added |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 415 | * @throws SecPublicInfo::Error if the certificate cannot be added (though it is really rare) |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 416 | */ |
Alexander Afanasyev | aab7966 | 2014-07-07 17:35:34 -0700 | [diff] [blame] | 417 | void |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 418 | addCertificateAsIdentityDefault(const IdentityCertificate& certificate); |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 419 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 420 | /** |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 421 | * @brief Add a certificate into the public key identity storage and set the certificate as the |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 422 | * default one of the default identity |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 423 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 424 | * @param certificate The certificate to be added |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 425 | * @throws SecPublicInfo::Error if the certificate cannot be added (though it is really rare) |
| 426 | */ |
Alexander Afanasyev | aab7966 | 2014-07-07 17:35:34 -0700 | [diff] [blame] | 427 | void |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 428 | addCertificateAsSystemDefault(const IdentityCertificate& certificate); |
Yingdi Yu | 88663af | 2014-01-15 15:21:38 -0800 | [diff] [blame] | 429 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 430 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 431 | * @brief Get cached default certificate of the default identity |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 432 | * |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 433 | * @return The certificate which might be empty shared_ptr<IdentityCertificate>() |
Alexander Afanasyev | aab7966 | 2014-07-07 17:35:34 -0700 | [diff] [blame] | 434 | * @deprecated Use getDefaultCertificate instead |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 435 | */ |
Alexander Afanasyev | aab7966 | 2014-07-07 17:35:34 -0700 | [diff] [blame] | 436 | DEPRECATED( |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 437 | shared_ptr<IdentityCertificate> |
Alexander Afanasyev | aab7966 | 2014-07-07 17:35:34 -0700 | [diff] [blame] | 438 | defaultCertificate()); |
| 439 | |
| 440 | /** |
| 441 | * @brief Get cached default certificate of the default identity |
| 442 | * |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 443 | * @return The certificate which might be empty shared_ptr<IdentityCertificate>() |
Alexander Afanasyev | aab7966 | 2014-07-07 17:35:34 -0700 | [diff] [blame] | 444 | */ |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 445 | shared_ptr<IdentityCertificate> |
Alexander Afanasyev | aab7966 | 2014-07-07 17:35:34 -0700 | [diff] [blame] | 446 | getDefaultCertificate(); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 447 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 448 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 449 | * @brief try to get the default certificate of the default identity from the public info |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 450 | */ |
Alexander Afanasyev | aab7966 | 2014-07-07 17:35:34 -0700 | [diff] [blame] | 451 | void |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 452 | refreshDefaultCertificate(); |
| 453 | |
| 454 | protected: |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 455 | shared_ptr<IdentityCertificate> m_defaultCertificate; |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 456 | std::string m_location; |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 457 | }; |
| 458 | |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 459 | } // namespace v1 |
| 460 | |
| 461 | #ifdef NDN_CXX_KEEP_SECURITY_V1_ALIASES |
| 462 | using v1::SecPublicInfo; |
| 463 | #endif // NDN_CXX_KEEP_SECURITY_V1_ALIASES |
| 464 | |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 465 | } // namespace security |
| 466 | |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 467 | #ifdef NDN_CXX_KEEP_SECURITY_V1_ALIASES |
| 468 | using security::v1::SecPublicInfo; |
| 469 | #endif // NDN_CXX_KEEP_SECURITY_V1_ALIASES |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 470 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 471 | } // namespace ndn |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 472 | |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 473 | #endif // NDN_SECURITY_V1_SEC_PUBLIC_INFO_HPP |