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 | e232a74 | 2020-09-29 17:34:17 -0700 | [diff] [blame] | 24 | #include "request-state.hpp" |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 25 | |
| 26 | namespace ndn { |
| 27 | namespace ndncert { |
| 28 | |
Zhiyi Zhang | 1d3dcd2 | 2020-10-01 22:25:43 -0700 | [diff] [blame] | 29 | struct CaProfile { |
Zhiyi Zhang | 9829da9 | 2020-09-30 16:19:34 -0700 | [diff] [blame] | 30 | /** |
| 31 | * CA Name prefix (without /CA suffix). |
| 32 | */ |
| 33 | Name m_caPrefix; |
| 34 | /** |
| 35 | * CA Information. |
| 36 | * Default: "". |
| 37 | */ |
| 38 | std::string m_caInfo; |
| 39 | /** |
| 40 | * A list of parameter-keys for PROBE. |
| 41 | * Default: empty list. |
| 42 | */ |
| 43 | std::list<std::string> m_probeParameterKeys; |
| 44 | /** |
| 45 | * Maximum allowed validity period of the certificate being requested. |
| 46 | * The value is in the unit of second. |
| 47 | * Default: one day (86400 seconds). |
| 48 | */ |
| 49 | time::seconds m_maxValidityPeriod; |
| 50 | /** |
| 51 | * Maximum allowed suffix length of requested name. |
| 52 | * E.g., When its value is 2, at most 2 name components can be assigned after m_caPrefix. |
| 53 | * Default: none. |
| 54 | */ |
| 55 | boost::optional<size_t> m_maxSuffixLength; |
| 56 | /** |
| 57 | * A list of supported challenges. Only CA side will have m_supportedChallenges. |
| 58 | * Default: empty list. |
| 59 | */ |
| 60 | std::list<std::string> m_supportedChallenges; |
| 61 | /** |
| 62 | * CA's certificate. Only Client side will have m_cert. |
| 63 | * Default: nullptr. |
| 64 | */ |
| 65 | std::shared_ptr<security::v2::Certificate> m_cert; |
| 66 | |
| 67 | void |
| 68 | parse(const JsonSection& configJson); |
| 69 | |
| 70 | JsonSection |
| 71 | toJson() const; |
| 72 | |
| 73 | private: |
| 74 | void |
| 75 | parseProbeParameters(const JsonSection& section); |
| 76 | |
| 77 | void |
| 78 | parseChallengeList(const JsonSection& configSection); |
| 79 | }; |
| 80 | |
Zhiyi Zhang | 7420cf5 | 2017-12-18 18:59:21 +0800 | [diff] [blame] | 81 | /** |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 82 | * @brief The name assignment function provided by the CA operator to generate available |
| 83 | * namecomponents. |
Zhiyi Zhang | f6c5d27 | 2020-09-28 10:17:32 -0700 | [diff] [blame] | 84 | * 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] | 85 | * 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] | 86 | * |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 87 | * @p vector, input, a list of parameter key-value pair used for name assignment. |
| 88 | * @return a vector containing the possible namespaces derived from the parameters. |
Zhiyi Zhang | 7420cf5 | 2017-12-18 18:59:21 +0800 | [diff] [blame] | 89 | */ |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 90 | 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] | 91 | |
| 92 | /** |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 93 | * @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] | 94 | * The callback is used to notice the CA application or CA command line tool. The callback is |
| 95 | * fired whenever a request instance is created, challenge status is updated, and when certificate |
| 96 | * is issued. |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 97 | * |
Zhiyi Zhang | e232a74 | 2020-09-29 17:34:17 -0700 | [diff] [blame] | 98 | * @p RequestState, input, the state of the certificate request whose status is updated. |
Zhiyi Zhang | 7420cf5 | 2017-12-18 18:59:21 +0800 | [diff] [blame] | 99 | */ |
Zhiyi Zhang | e232a74 | 2020-09-29 17:34:17 -0700 | [diff] [blame] | 100 | using StatusUpdateCallback = function<void(const RequestState&)>; |
Zhiyi Zhang | 7420cf5 | 2017-12-18 18:59:21 +0800 | [diff] [blame] | 101 | |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 102 | /** |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 103 | * @brief CA's configuration on NDNCERT. |
Zhiyi Zhang | ad6cf93 | 2017-10-26 16:19:15 -0700 | [diff] [blame] | 104 | * For CA configuration format, please refer to: |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 105 | * 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] | 106 | * |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 107 | * The format of CA configuration in JSON |
| 108 | * { |
| 109 | * "ca-prefix": "", |
| 110 | * "ca-info": "", |
| 111 | * "max-validity-period": "", |
Zhiyi Zhang | 48f2378 | 2020-09-28 12:11:24 -0700 | [diff] [blame] | 112 | * "max-suffix-length": "", |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 113 | * "probe-parameters": |
| 114 | * [ |
| 115 | * {"probe-parameter-key": ""}, |
| 116 | * {"probe-parameter-key": ""} |
| 117 | * ] |
| 118 | * "supported-challenges": |
| 119 | * [ |
| 120 | * {"challenge": ""}, |
| 121 | * {"challenge": ""} |
| 122 | * ] |
| 123 | * } |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 124 | */ |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 125 | class CaConfig { |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 126 | public: |
| 127 | /** |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 128 | * Load CA configuration from the file. |
Zhiyi Zhang | 9829da9 | 2020-09-30 16:19:34 -0700 | [diff] [blame] | 129 | * @throw std::runtime_error when config file cannot be correctly parsed. |
Zhiyi Zhang | 8da54d6 | 2019-11-21 00:03:05 -0800 | [diff] [blame] | 130 | */ |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 131 | void |
Zhiyi Zhang | 06d6ae9 | 2017-03-08 14:59:45 -0800 | [diff] [blame] | 132 | load(const std::string& fileName); |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 133 | |
Zhiyi Zhang | 1d3dcd2 | 2020-10-01 22:25:43 -0700 | [diff] [blame] | 134 | CaProfile m_caItem; |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 135 | /** |
Zhiyi Zhang | fde5011 | 2020-10-01 16:36:33 -0700 | [diff] [blame] | 136 | * Used for CA redirection as specified in |
| 137 | * https://github.com/named-data/ndncert/wiki/NDNCERT-Protocol-0.3-PROBE-Extensions#probe-extension-for-redirection |
| 138 | */ |
Zhiyi Zhang | e537dd5 | 2020-10-01 18:02:24 -0700 | [diff] [blame] | 139 | boost::optional<std::vector<std::shared_ptr<security::v2::Certificate>>> m_redirection; |
Zhiyi Zhang | fde5011 | 2020-10-01 16:36:33 -0700 | [diff] [blame] | 140 | /** |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 141 | * NameAssignmentFunc Callback function |
| 142 | */ |
| 143 | NameAssignmentFunc m_nameAssignmentFunc; |
| 144 | /** |
| 145 | * StatusUpdate Callback function |
| 146 | */ |
| 147 | StatusUpdateCallback m_statusUpdateCallback; |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 148 | }; |
| 149 | |
Zhiyi Zhang | 9829da9 | 2020-09-30 16:19:34 -0700 | [diff] [blame] | 150 | /** |
| 151 | * @brief Represents Client configuration |
| 152 | * |
| 153 | * For Client configuration format, please refer to: |
| 154 | * https://github.com/named-data/ndncert/wiki/Client-Configuration-Sample |
| 155 | */ |
Zhiyi Zhang | 1d3dcd2 | 2020-10-01 22:25:43 -0700 | [diff] [blame] | 156 | class RequesterCaCache { |
Zhiyi Zhang | 9829da9 | 2020-09-30 16:19:34 -0700 | [diff] [blame] | 157 | public: |
| 158 | /** |
| 159 | * @throw std::runtime_error when config file cannot be correctly parsed. |
| 160 | */ |
| 161 | void |
| 162 | load(const std::string& fileName); |
| 163 | |
| 164 | /** |
| 165 | * @throw std::runtime_error when config file cannot be correctly parsed. |
| 166 | */ |
| 167 | void |
| 168 | load(const JsonSection& configSection); |
| 169 | |
| 170 | void |
| 171 | save(const std::string& fileName) const; |
| 172 | |
| 173 | void |
Zhiyi Zhang | 1d3dcd2 | 2020-10-01 22:25:43 -0700 | [diff] [blame] | 174 | removeCaProfile(const Name& caName); |
Zhiyi Zhang | 9829da9 | 2020-09-30 16:19:34 -0700 | [diff] [blame] | 175 | |
Zhiyi Zhang | 1d3dcd2 | 2020-10-01 22:25:43 -0700 | [diff] [blame] | 176 | /** |
| 177 | * Be cautious. This will add a new trust anchor for requesters. |
| 178 | */ |
| 179 | void |
| 180 | addCaProfile(const CaProfile& profile); |
| 181 | |
| 182 | std::list<CaProfile> m_caItems; |
Zhiyi Zhang | 9829da9 | 2020-09-30 16:19:34 -0700 | [diff] [blame] | 183 | }; |
| 184 | |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 185 | } // namespace ndncert |
| 186 | } // namespace ndn |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 187 | |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 188 | #endif // NDNCERT_CA_CONFIG_HPP |