Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 7838cfd | 2020-06-03 14:16:43 -0400 | [diff] [blame] | 3 | * Copyright (c) 2017-2020, Regents of the University of California. |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndncert, a certificate management system based on NDN. |
| 6 | * |
| 7 | * ndncert is free software: you can redistribute it and/or modify it under the terms |
| 8 | * of the GNU General Public License as published by the Free Software Foundation, either |
| 9 | * version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndncert 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 General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License along with |
| 16 | * ndncert, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
| 18 | * See AUTHORS.md for complete list of ndncert authors and contributors. |
| 19 | */ |
| 20 | |
| 21 | #ifndef NDNCERT_CA_CONFIG_HPP |
| 22 | #define NDNCERT_CA_CONFIG_HPP |
| 23 | |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 24 | #include <ndn-cxx/security/v2/certificate.hpp> |
| 25 | |
Zhiyi Zhang | 5ebeb69 | 2017-03-10 14:13:01 -0800 | [diff] [blame] | 26 | #include "certificate-request.hpp" |
Zhiyi Zhang | ad6cf93 | 2017-10-26 16:19:15 -0700 | [diff] [blame] | 27 | #include "client-config.hpp" |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 28 | |
| 29 | namespace ndn { |
| 30 | namespace ndncert { |
| 31 | |
Zhiyi Zhang | 7420cf5 | 2017-12-18 18:59:21 +0800 | [diff] [blame] | 32 | /** |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 33 | * @brief The name assignment function provided by the CA operator to generate available |
| 34 | * namecomponents. |
Zhiyi Zhang | f6c5d27 | 2020-09-28 10:17:32 -0700 | [diff] [blame^] | 35 | * The function does not guarantee that all the returned names are available. Therefore the |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 36 | * CA should further check the availability of each returned name and remove unavailable results. |
Zhiyi Zhang | 7420cf5 | 2017-12-18 18:59:21 +0800 | [diff] [blame] | 37 | * |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 38 | * @p vector, input, a list of parameter key-value pair used for name assignment. |
| 39 | * @return a vector containing the possible namespaces derived from the parameters. |
Zhiyi Zhang | 7420cf5 | 2017-12-18 18:59:21 +0800 | [diff] [blame] | 40 | */ |
Zhiyi Zhang | f6c5d27 | 2020-09-28 10:17:32 -0700 | [diff] [blame^] | 41 | // using ProbeHandler = function<std::string /*identity name*/ (const Block& tlv /*requester input*/)>; |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 42 | using NameAssignmentFunc = function<std::vector<std::string>(const std::vector<std::tuple<std::string, std::string>>)>; |
Zhiyi Zhang | 7420cf5 | 2017-12-18 18:59:21 +0800 | [diff] [blame] | 43 | |
| 44 | /** |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 45 | * @brief The function would be invoked whenever the certificate request status is updated. |
Zhiyi Zhang | 343cdfb | 2018-01-17 12:04:28 -0800 | [diff] [blame] | 46 | * The callback is used to notice the CA application or CA command line tool. The callback is |
| 47 | * fired whenever a request instance is created, challenge status is updated, and when certificate |
| 48 | * is issued. |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 49 | * |
| 50 | * @p CertificateRequest, input, the state of the certificate request whose status is updated. |
Zhiyi Zhang | 7420cf5 | 2017-12-18 18:59:21 +0800 | [diff] [blame] | 51 | */ |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 52 | using StatusUpdateCallback = function<void(const CertificateRequest&)>; |
Zhiyi Zhang | 7420cf5 | 2017-12-18 18:59:21 +0800 | [diff] [blame] | 53 | |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 54 | /** |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 55 | * @brief CA's configuration on NDNCERT. |
Zhiyi Zhang | ad6cf93 | 2017-10-26 16:19:15 -0700 | [diff] [blame] | 56 | * For CA configuration format, please refer to: |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 57 | * https://github.com/named-data/ndncert/wiki/NDNCERT-Protocol-0.3#213-ca-profile |
Zhiyi Zhang | ad6cf93 | 2017-10-26 16:19:15 -0700 | [diff] [blame] | 58 | * |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 59 | * The format of CA configuration in JSON |
| 60 | * { |
| 61 | * "ca-prefix": "", |
| 62 | * "ca-info": "", |
| 63 | * "max-validity-period": "", |
| 64 | * "probe-parameters": |
| 65 | * [ |
| 66 | * {"probe-parameter-key": ""}, |
| 67 | * {"probe-parameter-key": ""} |
| 68 | * ] |
| 69 | * "supported-challenges": |
| 70 | * [ |
| 71 | * {"challenge": ""}, |
| 72 | * {"challenge": ""} |
| 73 | * ] |
| 74 | * } |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 75 | */ |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 76 | class CaConfig { |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 77 | public: |
| 78 | /** |
| 79 | * @brief Error that can be thrown from CaConfig |
| 80 | */ |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 81 | class Error : public std::runtime_error { |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 82 | public: |
Zhiyi Zhang | 06d6ae9 | 2017-03-08 14:59:45 -0800 | [diff] [blame] | 83 | using std::runtime_error::runtime_error; |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | public: |
Zhiyi Zhang | 8da54d6 | 2019-11-21 00:03:05 -0800 | [diff] [blame] | 87 | /** |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 88 | * Load CA configuration from the file. |
| 89 | * |
| 90 | * @param fileName, the configuration file name. |
| 91 | * @throw CaConfig::Error when config file does not exist or the configuration |
| 92 | * in the file cannot be parsed correctly. |
| 93 | * @throw CaConfig::Error when the ca-prefix attribute in JSON text is empty. |
| 94 | * @throw CaConfig::Error when the challenge is not specified or is not supported. |
Zhiyi Zhang | 8da54d6 | 2019-11-21 00:03:05 -0800 | [diff] [blame] | 95 | */ |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 96 | void |
Zhiyi Zhang | 06d6ae9 | 2017-03-08 14:59:45 -0800 | [diff] [blame] | 97 | load(const std::string& fileName); |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 98 | |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 99 | /** |
| 100 | * Set the NameAssignmentFunction. |
| 101 | */ |
Zhiyi Zhang | f6c5d27 | 2020-09-28 10:17:32 -0700 | [diff] [blame^] | 102 | // void |
| 103 | // setNameAssignmentFunc(const NameAssignmentFunc& nameAssignmentFunc) { |
| 104 | // m_nameAssignmentFunc = nameAssignmentFunc; |
| 105 | // } |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 106 | |
| 107 | /** |
| 108 | * Set the StatusUpdateCallback. |
| 109 | */ |
| 110 | void |
| 111 | setStatusUpdateCallback(const StatusUpdateCallback& statusUpdateCallback) { |
| 112 | m_statusUpdateCallback = statusUpdateCallback; |
| 113 | } |
| 114 | |
Zhiyi Zhang | 06d6ae9 | 2017-03-08 14:59:45 -0800 | [diff] [blame] | 115 | private: |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 116 | void |
Zhiyi Zhang | ad6cf93 | 2017-10-26 16:19:15 -0700 | [diff] [blame] | 117 | parse(const JsonSection& configJson); |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 118 | |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 119 | void |
| 120 | parseProbeParameters(const JsonSection& section); |
| 121 | |
| 122 | void |
Zhiyi Zhang | 5ebeb69 | 2017-03-10 14:13:01 -0800 | [diff] [blame] | 123 | parseChallengeList(const JsonSection& configSection); |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 124 | |
| 125 | public: |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 126 | /** |
| 127 | * CA Name prefix (without /CA suffix). |
| 128 | */ |
| 129 | Name m_caPrefix; |
| 130 | /** |
| 131 | * CA Information. |
| 132 | */ |
| 133 | std::string m_caInfo; |
| 134 | /** |
| 135 | * A list of parameter-keys for PROBE. |
| 136 | */ |
| 137 | std::list<std::string> m_probeParameterKeys; |
| 138 | /** |
| 139 | * Maximum allowed validity period of the certificate being requested. |
| 140 | * The value is in the unit of second. |
| 141 | */ |
| 142 | time::seconds m_maxValidityPeriod; |
| 143 | /** |
| 144 | * A list of supported challenges. |
| 145 | */ |
| 146 | std::list<std::string> m_supportedChallenges; |
| 147 | /** |
| 148 | * NameAssignmentFunc Callback function |
| 149 | */ |
| 150 | NameAssignmentFunc m_nameAssignmentFunc; |
| 151 | /** |
| 152 | * StatusUpdate Callback function |
| 153 | */ |
| 154 | StatusUpdateCallback m_statusUpdateCallback; |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 155 | }; |
| 156 | |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 157 | } // namespace ndncert |
| 158 | } // namespace ndn |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 159 | |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 160 | #endif // NDNCERT_CA_CONFIG_HPP |