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