blob: 44c7df9e505e49de9d29be480227bbf4de944521 [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
tylerliu8704d032020-06-23 10:18:15 -070021#ifndef NDNCERT_CONFIGURATION_HPP
22#define NDNCERT_CONFIGURATION_HPP
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080023
tylerliu8704d032020-06-23 10:18:15 -070024#include "ca-state.hpp"
Zhiyi Zhang8683ec92020-10-07 18:18:35 -070025#include "name-assignments/assignment-funcs.hpp"
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080026
27namespace ndn {
28namespace ndncert {
29
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -070030struct CaProfile {
Zhiyi Zhang9829da92020-09-30 16:19:34 -070031 /**
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 */
tylerliua7bea662020-10-08 18:51:02 -070066 std::shared_ptr<security::Certificate> m_cert;
Zhiyi Zhang9829da92020-09-30 16:19:34 -070067
68 void
69 parse(const JsonSection& configJson);
70
71 JsonSection
72 toJson() const;
73
74private:
75 void
76 parseProbeParameters(const JsonSection& section);
77
78 void
79 parseChallengeList(const JsonSection& configSection);
80};
81
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080082/**
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070083 * @brief The function would be invoked whenever the certificate request status is updated.
Zhiyi Zhang343cdfb2018-01-17 12:04:28 -080084 * 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 Zhang0453dbb2020-04-28 22:39:17 -070087 *
tylerliu8704d032020-06-23 10:18:15 -070088 * @p CaState, input, the state of the certificate request whose status is updated.
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080089 */
tylerliu8704d032020-06-23 10:18:15 -070090using StatusUpdateCallback = function<void(const CaState&)>;
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080091
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080092/**
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070093 * @brief CA's configuration on NDNCERT.
Zhiyi Zhangad6cf932017-10-26 16:19:15 -070094 * For CA configuration format, please refer to:
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070095 * https://github.com/named-data/ndncert/wiki/NDNCERT-Protocol-0.3#213-ca-profile
Zhiyi Zhangad6cf932017-10-26 16:19:15 -070096 *
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070097 * The format of CA configuration in JSON
98 * {
99 * "ca-prefix": "",
100 * "ca-info": "",
101 * "max-validity-period": "",
Zhiyi Zhang48f23782020-09-28 12:11:24 -0700102 * "max-suffix-length": "",
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -0700103 * "probe-parameters":
104 * [
105 * {"probe-parameter-key": ""},
106 * {"probe-parameter-key": ""}
107 * ]
108 * "supported-challenges":
109 * [
110 * {"challenge": ""},
111 * {"challenge": ""}
112 * ]
113 * }
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800114 */
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -0700115class CaConfig {
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800116public:
117 /**
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -0700118 * Load CA configuration from the file.
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700119 * @throw std::runtime_error when config file cannot be correctly parsed.
Zhiyi Zhang8da54d62019-11-21 00:03:05 -0800120 */
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800121 void
Zhiyi Zhang06d6ae92017-03-08 14:59:45 -0800122 load(const std::string& fileName);
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800123
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700124 CaProfile m_caItem;
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -0700125 /**
Zhiyi Zhangfde50112020-10-01 16:36:33 -0700126 * 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 */
tylerliua7bea662020-10-08 18:51:02 -0700129 boost::optional<std::vector<std::shared_ptr<security::Certificate>>> m_redirection;
Zhiyi Zhangfde50112020-10-01 16:36:33 -0700130 /**
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -0700131 * StatusUpdate Callback function
132 */
133 StatusUpdateCallback m_statusUpdateCallback;
Zhiyi Zhang74c61142020-10-07 21:00:49 -0700134 /**
135 * Name Assignment Functions
136 */
137 std::vector<std::unique_ptr<NameAssignmentFunc>> m_nameAssignmentFuncs;
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800138};
139
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700140/**
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 Zhang1d3dcd22020-10-01 22:25:43 -0700146class RequesterCaCache {
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700147public:
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 Zhang1d3dcd22020-10-01 22:25:43 -0700164 removeCaProfile(const Name& caName);
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700165
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700166 /**
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 Zhang9829da92020-09-30 16:19:34 -0700173};
174
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -0700175} // namespace ndncert
176} // namespace ndn
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800177
tylerliu8704d032020-06-23 10:18:15 -0700178#endif // NDNCERT_CONFIGURATION_HPP