blob: bba5af4f70fb637565f8e7b0cbb108f2ead70033 [file] [log] [blame]
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev7838cfd2020-06-03 14:16:43 -04003 * Copyright (c) 2017-2020, Regents of the University of California.
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -08004 *
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 Zhange232a742020-09-29 17:34:17 -070024#include "request-state.hpp"
Zhiyi Zhangad6cf932017-10-26 16:19:15 -070025#include "client-config.hpp"
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080026
27namespace ndn {
28namespace ndncert {
29
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080030/**
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070031 * @brief The name assignment function provided by the CA operator to generate available
32 * namecomponents.
Zhiyi Zhangf6c5d272020-09-28 10:17:32 -070033 * The function does not guarantee that all the returned names are available. Therefore the
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070034 * CA should further check the availability of each returned name and remove unavailable results.
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080035 *
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070036 * @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 Zhang7420cf52017-12-18 18:59:21 +080038 */
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070039using NameAssignmentFunc = function<std::vector<std::string>(const std::vector<std::tuple<std::string, std::string>>)>;
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080040
41/**
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070042 * @brief The function would be invoked whenever the certificate request status is updated.
Zhiyi Zhang343cdfb2018-01-17 12:04:28 -080043 * 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 Zhang0453dbb2020-04-28 22:39:17 -070046 *
Zhiyi Zhange232a742020-09-29 17:34:17 -070047 * @p RequestState, input, the state of the certificate request whose status is updated.
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080048 */
Zhiyi Zhange232a742020-09-29 17:34:17 -070049using StatusUpdateCallback = function<void(const RequestState&)>;
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080050
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080051/**
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070052 * @brief CA's configuration on NDNCERT.
Zhiyi Zhangad6cf932017-10-26 16:19:15 -070053 * For CA configuration format, please refer to:
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070054 * https://github.com/named-data/ndncert/wiki/NDNCERT-Protocol-0.3#213-ca-profile
Zhiyi Zhangad6cf932017-10-26 16:19:15 -070055 *
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070056 * The format of CA configuration in JSON
57 * {
58 * "ca-prefix": "",
59 * "ca-info": "",
60 * "max-validity-period": "",
Zhiyi Zhang48f23782020-09-28 12:11:24 -070061 * "max-suffix-length": "",
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070062 * "probe-parameters":
63 * [
64 * {"probe-parameter-key": ""},
65 * {"probe-parameter-key": ""}
66 * ]
67 * "supported-challenges":
68 * [
69 * {"challenge": ""},
70 * {"challenge": ""}
71 * ]
72 * }
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080073 */
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070074class CaConfig {
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080075public:
76 /**
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070077 * Load CA configuration from the file.
78 *
79 * @param fileName, the configuration file name.
Zhiyi Zhangb2f8b942020-09-28 10:37:02 -070080 * @throw std::runtime_error when config file does not exist or the configuration
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070081 * in the file cannot be parsed correctly.
Zhiyi Zhangb2f8b942020-09-28 10:37:02 -070082 * @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 Zhang8da54d62019-11-21 00:03:05 -080084 */
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080085 void
Zhiyi Zhang06d6ae92017-03-08 14:59:45 -080086 load(const std::string& fileName);
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080087
Zhiyi Zhang06d6ae92017-03-08 14:59:45 -080088private:
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080089 void
Zhiyi Zhangad6cf932017-10-26 16:19:15 -070090 parse(const JsonSection& configJson);
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080091
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070092 void
93 parseProbeParameters(const JsonSection& section);
94
95 void
Zhiyi Zhang5ebeb692017-03-10 14:13:01 -080096 parseChallengeList(const JsonSection& configSection);
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080097
98public:
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070099 /**
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 Zhang48f23782020-09-28 12:11:24 -0700117 * 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 Zhang0453dbb2020-04-28 22:39:17 -0700122 * 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 Zhangdaf2fd72017-01-19 11:31:35 -0800133};
134
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -0700135} // namespace ndncert
136} // namespace ndn
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800137
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -0700138#endif // NDNCERT_CA_CONFIG_HPP