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