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 | ad6cf93 | 2017-10-26 16:19:15 -0700 | [diff] [blame] | 25 | #include "client-config.hpp" |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 26 | |
| 27 | namespace ndn { |
| 28 | namespace ndncert { |
| 29 | |
Zhiyi Zhang | 7420cf5 | 2017-12-18 18:59:21 +0800 | [diff] [blame] | 30 | /** |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 31 | * @brief The name assignment function provided by the CA operator to generate available |
| 32 | * namecomponents. |
Zhiyi Zhang | f6c5d27 | 2020-09-28 10:17:32 -0700 | [diff] [blame] | 33 | * 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] | 34 | * 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] | 35 | * |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 36 | * @p vector, input, a list of parameter key-value pair used for name assignment. |
| 37 | * @return a vector containing the possible namespaces derived from the parameters. |
Zhiyi Zhang | 7420cf5 | 2017-12-18 18:59:21 +0800 | [diff] [blame] | 38 | */ |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 39 | 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] | 40 | |
| 41 | /** |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 42 | * @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] | 43 | * The callback is used to notice the CA application or CA command line tool. The callback is |
| 44 | * fired whenever a request instance is created, challenge status is updated, and when certificate |
| 45 | * is issued. |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 46 | * |
Zhiyi Zhang | e232a74 | 2020-09-29 17:34:17 -0700 | [diff] [blame^] | 47 | * @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] | 48 | */ |
Zhiyi Zhang | e232a74 | 2020-09-29 17:34:17 -0700 | [diff] [blame^] | 49 | using StatusUpdateCallback = function<void(const RequestState&)>; |
Zhiyi Zhang | 7420cf5 | 2017-12-18 18:59:21 +0800 | [diff] [blame] | 50 | |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 51 | /** |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 52 | * @brief CA's configuration on NDNCERT. |
Zhiyi Zhang | ad6cf93 | 2017-10-26 16:19:15 -0700 | [diff] [blame] | 53 | * For CA configuration format, please refer to: |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 54 | * 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] | 55 | * |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 56 | * The format of CA configuration in JSON |
| 57 | * { |
| 58 | * "ca-prefix": "", |
| 59 | * "ca-info": "", |
| 60 | * "max-validity-period": "", |
Zhiyi Zhang | 48f2378 | 2020-09-28 12:11:24 -0700 | [diff] [blame] | 61 | * "max-suffix-length": "", |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 62 | * "probe-parameters": |
| 63 | * [ |
| 64 | * {"probe-parameter-key": ""}, |
| 65 | * {"probe-parameter-key": ""} |
| 66 | * ] |
| 67 | * "supported-challenges": |
| 68 | * [ |
| 69 | * {"challenge": ""}, |
| 70 | * {"challenge": ""} |
| 71 | * ] |
| 72 | * } |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 73 | */ |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 74 | class CaConfig { |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 75 | public: |
| 76 | /** |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 77 | * Load CA configuration from the file. |
| 78 | * |
| 79 | * @param fileName, the configuration file name. |
Zhiyi Zhang | b2f8b94 | 2020-09-28 10:37:02 -0700 | [diff] [blame] | 80 | * @throw std::runtime_error when config file does not exist or the configuration |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 81 | * in the file cannot be parsed correctly. |
Zhiyi Zhang | b2f8b94 | 2020-09-28 10:37:02 -0700 | [diff] [blame] | 82 | * @throw std::runtime_error when the ca-prefix attribute in JSON text is empty. |
| 83 | * @throw std::runtime_error when the challenge is not specified or is not supported. |
Zhiyi Zhang | 8da54d6 | 2019-11-21 00:03:05 -0800 | [diff] [blame] | 84 | */ |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 85 | void |
Zhiyi Zhang | 06d6ae9 | 2017-03-08 14:59:45 -0800 | [diff] [blame] | 86 | load(const std::string& fileName); |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 87 | |
Zhiyi Zhang | 06d6ae9 | 2017-03-08 14:59:45 -0800 | [diff] [blame] | 88 | private: |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 89 | void |
Zhiyi Zhang | ad6cf93 | 2017-10-26 16:19:15 -0700 | [diff] [blame] | 90 | parse(const JsonSection& configJson); |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 91 | |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 92 | void |
| 93 | parseProbeParameters(const JsonSection& section); |
| 94 | |
| 95 | void |
Zhiyi Zhang | 5ebeb69 | 2017-03-10 14:13:01 -0800 | [diff] [blame] | 96 | parseChallengeList(const JsonSection& configSection); |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 97 | |
| 98 | public: |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 99 | /** |
| 100 | * CA Name prefix (without /CA suffix). |
| 101 | */ |
| 102 | Name m_caPrefix; |
| 103 | /** |
| 104 | * CA Information. |
| 105 | */ |
| 106 | std::string m_caInfo; |
| 107 | /** |
| 108 | * A list of parameter-keys for PROBE. |
| 109 | */ |
| 110 | std::list<std::string> m_probeParameterKeys; |
| 111 | /** |
| 112 | * Maximum allowed validity period of the certificate being requested. |
| 113 | * The value is in the unit of second. |
| 114 | */ |
| 115 | time::seconds m_maxValidityPeriod; |
| 116 | /** |
Zhiyi Zhang | 48f2378 | 2020-09-28 12:11:24 -0700 | [diff] [blame] | 117 | * Maximum allowed suffix length of requested name. |
| 118 | * E.g., When its value is 2, at most 2 name components can be assigned after m_caPrefix. |
| 119 | */ |
| 120 | size_t m_maxSuffixLength; |
| 121 | /** |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 122 | * A list of supported challenges. |
| 123 | */ |
| 124 | std::list<std::string> m_supportedChallenges; |
| 125 | /** |
| 126 | * NameAssignmentFunc Callback function |
| 127 | */ |
| 128 | NameAssignmentFunc m_nameAssignmentFunc; |
| 129 | /** |
| 130 | * StatusUpdate Callback function |
| 131 | */ |
| 132 | StatusUpdateCallback m_statusUpdateCallback; |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 133 | }; |
| 134 | |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 135 | } // namespace ndncert |
| 136 | } // namespace ndn |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 137 | |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 138 | #endif // NDNCERT_CA_CONFIG_HPP |