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 | |
Zhiyi Zhang | 34f03f0 | 2020-10-29 18:34:42 -0700 | [diff] [blame] | 24 | #include "detail/ca-request-state.hpp" |
Zhiyi Zhang | c2c4ed2 | 2020-10-14 17:16:28 -0700 | [diff] [blame] | 25 | #include "name-assignment/assignment-func.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 | */ |
Zhiyi Zhang | 997669a | 2020-10-28 21:15:40 -0700 | [diff] [blame] | 56 | optional<size_t> m_maxSuffixLength = nullopt; |
Zhiyi Zhang | 9829da9 | 2020-09-30 16:19:34 -0700 | [diff] [blame] | 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 | 32d4b4e | 2020-10-28 22:10:49 -0700 | [diff] [blame] | 82 | namespace ca { |
| 83 | |
Zhiyi Zhang | 7420cf5 | 2017-12-18 18:59:21 +0800 | [diff] [blame] | 84 | /** |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 85 | * @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] | 86 | * The callback is used to notice the CA application or CA command line tool. The callback is |
| 87 | * fired whenever a request instance is created, challenge status is updated, and when certificate |
| 88 | * is issued. |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 89 | * |
Zhiyi Zhang | 32d4b4e | 2020-10-28 22:10:49 -0700 | [diff] [blame] | 90 | * @param RequestState The state of the certificate request whose status is updated. |
Zhiyi Zhang | 7420cf5 | 2017-12-18 18:59:21 +0800 | [diff] [blame] | 91 | */ |
Zhiyi Zhang | 32d4b4e | 2020-10-28 22:10:49 -0700 | [diff] [blame] | 92 | using StatusUpdateCallback = function<void(const RequestState&)>; |
Zhiyi Zhang | 7420cf5 | 2017-12-18 18:59:21 +0800 | [diff] [blame] | 93 | |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 94 | /** |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 95 | * @brief CA's configuration on NDNCERT. |
Zhiyi Zhang | ad6cf93 | 2017-10-26 16:19:15 -0700 | [diff] [blame] | 96 | * For CA configuration format, please refer to: |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 97 | * 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] | 98 | * |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 99 | * The format of CA configuration in JSON |
| 100 | * { |
| 101 | * "ca-prefix": "", |
| 102 | * "ca-info": "", |
| 103 | * "max-validity-period": "", |
Zhiyi Zhang | 48f2378 | 2020-09-28 12:11:24 -0700 | [diff] [blame] | 104 | * "max-suffix-length": "", |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 105 | * "probe-parameters": |
| 106 | * [ |
| 107 | * {"probe-parameter-key": ""}, |
| 108 | * {"probe-parameter-key": ""} |
| 109 | * ] |
| 110 | * "supported-challenges": |
| 111 | * [ |
| 112 | * {"challenge": ""}, |
| 113 | * {"challenge": ""} |
| 114 | * ] |
| 115 | * } |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 116 | */ |
Zhiyi Zhang | 684c67c | 2020-10-12 14:28:17 -0700 | [diff] [blame] | 117 | class CaConfig |
| 118 | { |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 119 | public: |
| 120 | /** |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 121 | * Load CA configuration from the file. |
Zhiyi Zhang | 9829da9 | 2020-09-30 16:19:34 -0700 | [diff] [blame] | 122 | * @throw std::runtime_error when config file cannot be correctly parsed. |
Zhiyi Zhang | 8da54d6 | 2019-11-21 00:03:05 -0800 | [diff] [blame] | 123 | */ |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 124 | void |
Zhiyi Zhang | 06d6ae9 | 2017-03-08 14:59:45 -0800 | [diff] [blame] | 125 | load(const std::string& fileName); |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 126 | |
Zhiyi Zhang | 1d3dcd2 | 2020-10-01 22:25:43 -0700 | [diff] [blame] | 127 | CaProfile m_caItem; |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 128 | /** |
Zhiyi Zhang | fde5011 | 2020-10-01 16:36:33 -0700 | [diff] [blame] | 129 | * Used for CA redirection as specified in |
| 130 | * https://github.com/named-data/ndncert/wiki/NDNCERT-Protocol-0.3-PROBE-Extensions#probe-extension-for-redirection |
| 131 | */ |
Zhiyi Zhang | 997669a | 2020-10-28 21:15:40 -0700 | [diff] [blame] | 132 | optional<std::vector<std::shared_ptr<security::Certificate>>> m_redirection = nullopt; |
Zhiyi Zhang | fde5011 | 2020-10-01 16:36:33 -0700 | [diff] [blame] | 133 | /** |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 134 | * StatusUpdate Callback function |
| 135 | */ |
| 136 | StatusUpdateCallback m_statusUpdateCallback; |
Zhiyi Zhang | 74c6114 | 2020-10-07 21:00:49 -0700 | [diff] [blame] | 137 | /** |
| 138 | * Name Assignment Functions |
| 139 | */ |
| 140 | std::vector<std::unique_ptr<NameAssignmentFunc>> m_nameAssignmentFuncs; |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 141 | }; |
| 142 | |
Zhiyi Zhang | 32d4b4e | 2020-10-28 22:10:49 -0700 | [diff] [blame] | 143 | } // namespace ca |
| 144 | |
Zhiyi Zhang | 3002e6b | 2020-10-29 18:54:07 -0700 | [diff] [blame] | 145 | namespace requester { |
| 146 | |
Zhiyi Zhang | 9829da9 | 2020-09-30 16:19:34 -0700 | [diff] [blame] | 147 | /** |
| 148 | * @brief Represents Client configuration |
| 149 | * |
| 150 | * For Client configuration format, please refer to: |
| 151 | * https://github.com/named-data/ndncert/wiki/Client-Configuration-Sample |
| 152 | */ |
Zhiyi Zhang | a16b758 | 2020-10-29 18:59:46 -0700 | [diff] [blame] | 153 | class ProfileStorage |
Zhiyi Zhang | 684c67c | 2020-10-12 14:28:17 -0700 | [diff] [blame] | 154 | { |
Zhiyi Zhang | 9829da9 | 2020-09-30 16:19:34 -0700 | [diff] [blame] | 155 | public: |
| 156 | /** |
| 157 | * @throw std::runtime_error when config file cannot be correctly parsed. |
| 158 | */ |
| 159 | void |
| 160 | load(const std::string& fileName); |
| 161 | |
| 162 | /** |
| 163 | * @throw std::runtime_error when config file cannot be correctly parsed. |
| 164 | */ |
| 165 | void |
| 166 | load(const JsonSection& configSection); |
| 167 | |
| 168 | void |
| 169 | save(const std::string& fileName) const; |
| 170 | |
| 171 | void |
Zhiyi Zhang | 1d3dcd2 | 2020-10-01 22:25:43 -0700 | [diff] [blame] | 172 | removeCaProfile(const Name& caName); |
Zhiyi Zhang | 9829da9 | 2020-09-30 16:19:34 -0700 | [diff] [blame] | 173 | |
Zhiyi Zhang | 1d3dcd2 | 2020-10-01 22:25:43 -0700 | [diff] [blame] | 174 | /** |
| 175 | * Be cautious. This will add a new trust anchor for requesters. |
| 176 | */ |
| 177 | void |
| 178 | addCaProfile(const CaProfile& profile); |
| 179 | |
| 180 | std::list<CaProfile> m_caItems; |
Zhiyi Zhang | 9829da9 | 2020-09-30 16:19:34 -0700 | [diff] [blame] | 181 | }; |
| 182 | |
Zhiyi Zhang | 3002e6b | 2020-10-29 18:54:07 -0700 | [diff] [blame] | 183 | } // namespace requester |
Zhiyi Zhang | e4891b7 | 2020-10-10 15:11:57 -0700 | [diff] [blame] | 184 | } // namespace ndncert |
| 185 | } // namespace ndn |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 186 | |
Zhiyi Zhang | e4891b7 | 2020-10-10 15:11:57 -0700 | [diff] [blame] | 187 | #endif // NDNCERT_CONFIGURATION_HPP |